@stamhoofd/structures 2.107.3 → 2.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/src/BalanceItem.d.ts +5 -0
  2. package/dist/src/BalanceItem.d.ts.map +1 -1
  3. package/dist/src/BalanceItem.js +10 -1
  4. package/dist/src/BalanceItem.js.map +1 -1
  5. package/dist/src/Document.d.ts +1 -0
  6. package/dist/src/Document.d.ts.map +1 -1
  7. package/dist/src/Document.js +3 -0
  8. package/dist/src/Document.js.map +1 -1
  9. package/dist/src/GenericBalance.d.ts.map +1 -1
  10. package/dist/src/GenericBalance.js +2 -1
  11. package/dist/src/GenericBalance.js.map +1 -1
  12. package/dist/src/GroupType.d.ts +1 -0
  13. package/dist/src/GroupType.d.ts.map +1 -1
  14. package/dist/src/GroupType.js +11 -0
  15. package/dist/src/GroupType.js.map +1 -1
  16. package/dist/src/Version.d.ts +1 -1
  17. package/dist/src/Version.js +1 -1
  18. package/dist/src/billing/Invoice.d.ts +51 -4
  19. package/dist/src/billing/Invoice.d.ts.map +1 -1
  20. package/dist/src/billing/Invoice.js +119 -2
  21. package/dist/src/billing/Invoice.js.map +1 -1
  22. package/dist/src/billing/InvoicedBalanceItem.d.ts +35 -6
  23. package/dist/src/billing/InvoicedBalanceItem.d.ts.map +1 -1
  24. package/dist/src/billing/InvoicedBalanceItem.js +79 -12
  25. package/dist/src/billing/InvoicedBalanceItem.js.map +1 -1
  26. package/dist/src/billing/InvoicedBalanceItem.test.d.ts +2 -0
  27. package/dist/src/billing/InvoicedBalanceItem.test.d.ts.map +1 -0
  28. package/dist/src/billing/InvoicedBalanceItem.test.js +195 -0
  29. package/dist/src/billing/InvoicedBalanceItem.test.js.map +1 -0
  30. package/dist/src/billing/STBillingStatus.d.ts +2 -1
  31. package/dist/src/billing/STBillingStatus.d.ts.map +1 -1
  32. package/dist/src/billing/STBillingStatus.js +2 -1
  33. package/dist/src/billing/STBillingStatus.js.map +1 -1
  34. package/dist/src/billing/STInvoice.d.ts +2 -125
  35. package/dist/src/billing/STInvoice.d.ts.map +1 -1
  36. package/dist/src/billing/STInvoice.js +3 -400
  37. package/dist/src/billing/STInvoice.js.map +1 -1
  38. package/dist/src/billing/STInvoiceItem.d.ts +32 -0
  39. package/dist/src/billing/STInvoiceItem.d.ts.map +1 -0
  40. package/dist/src/billing/STInvoiceItem.js +169 -0
  41. package/dist/src/billing/STInvoiceItem.js.map +1 -0
  42. package/dist/src/billing/STInvoiceMeta.d.ts +63 -0
  43. package/dist/src/billing/STInvoiceMeta.d.ts.map +1 -0
  44. package/dist/src/billing/STInvoiceMeta.js +152 -0
  45. package/dist/src/billing/STInvoiceMeta.js.map +1 -0
  46. package/dist/src/billing/STInvoicePrivate.d.ts +10 -0
  47. package/dist/src/billing/STInvoicePrivate.d.ts.map +1 -0
  48. package/dist/src/billing/STInvoicePrivate.js +51 -0
  49. package/dist/src/billing/STInvoicePrivate.js.map +1 -0
  50. package/dist/src/billing/STInvoiceStatus.d.ts +7 -0
  51. package/dist/src/billing/STInvoiceStatus.d.ts.map +1 -0
  52. package/dist/src/billing/STInvoiceStatus.js +11 -0
  53. package/dist/src/billing/STInvoiceStatus.js.map +1 -0
  54. package/dist/src/billing/STPendingInvoice.d.ts +15 -0
  55. package/dist/src/billing/STPendingInvoice.d.ts.map +1 -0
  56. package/dist/src/billing/STPendingInvoice.js +40 -0
  57. package/dist/src/billing/STPendingInvoice.js.map +1 -0
  58. package/dist/src/billing/index.d.ts +5 -0
  59. package/dist/src/billing/index.d.ts.map +1 -1
  60. package/dist/src/billing/index.js +5 -0
  61. package/dist/src/billing/index.js.map +1 -1
  62. package/dist/src/email/EmailTemplate.js +2 -2
  63. package/dist/src/email/EmailTemplate.js.map +1 -1
  64. package/dist/src/members/Registration.d.ts +1 -0
  65. package/dist/src/members/Registration.d.ts.map +1 -1
  66. package/dist/src/members/Registration.js +4 -0
  67. package/dist/src/members/Registration.js.map +1 -1
  68. package/dist/src/members/checkout/RegisterItem.d.ts +5 -0
  69. package/dist/src/members/checkout/RegisterItem.d.ts.map +1 -1
  70. package/dist/src/members/checkout/RegisterItem.js +60 -5
  71. package/dist/src/members/checkout/RegisterItem.js.map +1 -1
  72. package/dist/src/webshops/Checkout.d.ts.map +1 -1
  73. package/dist/src/webshops/Checkout.js +10 -1
  74. package/dist/src/webshops/Checkout.js.map +1 -1
  75. package/esm/dist/src/BalanceItem.d.ts +5 -0
  76. package/esm/dist/src/BalanceItem.d.ts.map +1 -1
  77. package/esm/dist/src/BalanceItem.js +10 -1
  78. package/esm/dist/src/BalanceItem.js.map +1 -1
  79. package/esm/dist/src/Document.d.ts +1 -0
  80. package/esm/dist/src/Document.d.ts.map +1 -1
  81. package/esm/dist/src/Document.js +3 -0
  82. package/esm/dist/src/Document.js.map +1 -1
  83. package/esm/dist/src/GenericBalance.d.ts.map +1 -1
  84. package/esm/dist/src/GenericBalance.js +2 -1
  85. package/esm/dist/src/GenericBalance.js.map +1 -1
  86. package/esm/dist/src/GroupType.d.ts +1 -0
  87. package/esm/dist/src/GroupType.d.ts.map +1 -1
  88. package/esm/dist/src/GroupType.js +10 -0
  89. package/esm/dist/src/GroupType.js.map +1 -1
  90. package/esm/dist/src/Version.d.ts +1 -1
  91. package/esm/dist/src/Version.js +1 -1
  92. package/esm/dist/src/billing/Invoice.d.ts +51 -4
  93. package/esm/dist/src/billing/Invoice.d.ts.map +1 -1
  94. package/esm/dist/src/billing/Invoice.js +118 -2
  95. package/esm/dist/src/billing/Invoice.js.map +1 -1
  96. package/esm/dist/src/billing/InvoicedBalanceItem.d.ts +35 -6
  97. package/esm/dist/src/billing/InvoicedBalanceItem.d.ts.map +1 -1
  98. package/esm/dist/src/billing/InvoicedBalanceItem.js +79 -12
  99. package/esm/dist/src/billing/InvoicedBalanceItem.js.map +1 -1
  100. package/esm/dist/src/billing/STBillingStatus.d.ts +2 -1
  101. package/esm/dist/src/billing/STBillingStatus.d.ts.map +1 -1
  102. package/esm/dist/src/billing/STBillingStatus.js +2 -1
  103. package/esm/dist/src/billing/STBillingStatus.js.map +1 -1
  104. package/esm/dist/src/billing/STInvoice.d.ts +2 -125
  105. package/esm/dist/src/billing/STInvoice.d.ts.map +1 -1
  106. package/esm/dist/src/billing/STInvoice.js +3 -394
  107. package/esm/dist/src/billing/STInvoice.js.map +1 -1
  108. package/esm/dist/src/billing/STInvoiceItem.d.ts +32 -0
  109. package/esm/dist/src/billing/STInvoiceItem.d.ts.map +1 -0
  110. package/esm/dist/src/billing/STInvoiceItem.js +165 -0
  111. package/esm/dist/src/billing/STInvoiceItem.js.map +1 -0
  112. package/esm/dist/src/billing/STInvoiceMeta.d.ts +63 -0
  113. package/esm/dist/src/billing/STInvoiceMeta.d.ts.map +1 -0
  114. package/esm/dist/src/billing/STInvoiceMeta.js +148 -0
  115. package/esm/dist/src/billing/STInvoiceMeta.js.map +1 -0
  116. package/esm/dist/src/billing/STInvoicePrivate.d.ts +10 -0
  117. package/esm/dist/src/billing/STInvoicePrivate.d.ts.map +1 -0
  118. package/esm/dist/src/billing/STInvoicePrivate.js +47 -0
  119. package/esm/dist/src/billing/STInvoicePrivate.js.map +1 -0
  120. package/esm/dist/src/billing/STInvoiceStatus.d.ts +7 -0
  121. package/esm/dist/src/billing/STInvoiceStatus.d.ts.map +1 -0
  122. package/esm/dist/src/billing/STInvoiceStatus.js +8 -0
  123. package/esm/dist/src/billing/STInvoiceStatus.js.map +1 -0
  124. package/esm/dist/src/billing/STPendingInvoice.d.ts +15 -0
  125. package/esm/dist/src/billing/STPendingInvoice.d.ts.map +1 -0
  126. package/esm/dist/src/billing/STPendingInvoice.js +35 -0
  127. package/esm/dist/src/billing/STPendingInvoice.js.map +1 -0
  128. package/esm/dist/src/billing/index.d.ts +5 -0
  129. package/esm/dist/src/billing/index.d.ts.map +1 -1
  130. package/esm/dist/src/billing/index.js +5 -0
  131. package/esm/dist/src/billing/index.js.map +1 -1
  132. package/esm/dist/src/email/EmailTemplate.js +2 -2
  133. package/esm/dist/src/email/EmailTemplate.js.map +1 -1
  134. package/esm/dist/src/members/Registration.d.ts +1 -0
  135. package/esm/dist/src/members/Registration.d.ts.map +1 -1
  136. package/esm/dist/src/members/Registration.js +4 -0
  137. package/esm/dist/src/members/Registration.js.map +1 -1
  138. package/esm/dist/src/members/checkout/RegisterItem.d.ts +5 -0
  139. package/esm/dist/src/members/checkout/RegisterItem.d.ts.map +1 -1
  140. package/esm/dist/src/members/checkout/RegisterItem.js +60 -5
  141. package/esm/dist/src/members/checkout/RegisterItem.js.map +1 -1
  142. package/esm/dist/src/webshops/Checkout.d.ts.map +1 -1
  143. package/esm/dist/src/webshops/Checkout.js +10 -1
  144. package/esm/dist/src/webshops/Checkout.js.map +1 -1
  145. package/package.json +2 -2
@@ -1,324 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STInvoiceResponse = exports.STPendingInvoicePrivate = exports.STPendingInvoice = exports.STInvoicePrivate = exports.STInvoice = exports.STInvoiceMeta = exports.STInvoiceItem = exports.STInvoiceStatus = void 0;
3
+ exports.STInvoice = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const simple_encoding_1 = require("@simonbackx/simple-encoding");
6
- const utility_1 = require("@stamhoofd/utility");
7
6
  const uuid_1 = require("uuid");
8
- const Address_js_1 = require("../addresses/Address.js");
9
- const File_js_1 = require("../files/File.js");
10
7
  const Payment_js_1 = require("../members/Payment.js");
11
- const OrganizationSimple_js_1 = require("../OrganizationSimple.js");
12
- const STPackage_js_1 = require("./STPackage.js");
13
- const upgradePriceFrom2To4DecimalPlaces_js_1 = require("../upgradePriceFrom2To4DecimalPlaces.js");
14
- var STInvoiceStatus;
15
- (function (STInvoiceStatus) {
16
- STInvoiceStatus["Created"] = "Created";
17
- STInvoiceStatus["Prepared"] = "Prepared";
18
- STInvoiceStatus["Completed"] = "Completed";
19
- STInvoiceStatus["Canceled"] = "Canceled";
20
- })(STInvoiceStatus || (exports.STInvoiceStatus = STInvoiceStatus = {}));
21
- /**
22
- * @deprecated use Invoice
23
- */
24
- class STInvoiceItem extends simple_encoding_1.AutoEncoder {
25
- constructor() {
26
- super(...arguments);
27
- this.name = '';
28
- this.description = '';
29
- this.amount = 1;
30
- this.unitPrice = 0;
31
- this.canUseCredits = true;
32
- this.firstFailedPayment = null;
33
- this.paymentFailedCount = 0;
34
- }
35
- get price() {
36
- return this.unitPrice * this.amount;
37
- }
38
- /**
39
- * Convertable into STInvoiceItem (or the diffence if amount is increased)
40
- * Use this to calculate prices or create an invoice
41
- * This will calculate the price to expand the package to the given amount.
42
- * If you want to renew a package, you need to create a new package first
43
- */
44
- static fromPackage(pack, amount = 1, pendingAmount = 0, date) {
45
- let unitPrice = Math.round(pack.meta.unitPrice);
46
- if (amount < pack.meta.minimumAmount) {
47
- // Minimum should get applied first, because we might already have paid for the minimum (paid amount)
48
- amount = pack.meta.minimumAmount;
49
- }
50
- amount -= pendingAmount;
51
- amount -= pack.meta.paidAmount;
52
- if (amount <= 0) {
53
- amount = 0;
54
- }
55
- /// When pricing type is memebrs, the price is calculated per year.
56
- /// If a shorter period is remaining, we give a discount in order
57
- /// to no need to handle it more complicated
58
- let now = date !== null && date !== void 0 ? date : new Date();
59
- if (now < pack.meta.startDate) {
60
- // When creating a new package, we sometimes buy it for the future, so use that date instead of now
61
- now = pack.meta.startDate;
62
- }
63
- if (pack.validUntil && pack.meta.pricingType !== STPackage_js_1.STPricingType.Fixed) {
64
- const totalDays = Math.round((pack.validUntil.getTime() - pack.meta.startDate.getTime()) / (1000 * 60 * 60 * 24));
65
- let remainingDays = Math.round((pack.validUntil.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
66
- /// First 3 months are full price
67
- const paidDays = 30 * 3;
68
- if (remainingDays > totalDays) {
69
- remainingDays = totalDays;
70
- }
71
- if (totalDays > 366) {
72
- // Increase unit price
73
- unitPrice = unitPrice * (totalDays / 365);
74
- }
75
- if (pack.meta.pricingType === STPackage_js_1.STPricingType.PerMember) {
76
- unitPrice = Math.round(Math.min(unitPrice, unitPrice * remainingDays / (Math.max(365, totalDays) - paidDays)));
77
- }
78
- else {
79
- unitPrice = Math.round(unitPrice);
80
- }
81
- }
82
- const item = STInvoiceItem.create({
83
- name: pack.meta.name,
84
- description: pack.validUntil ? ('Van ' + utility_1.Formatter.date(now, true) + ' tot ' + utility_1.Formatter.date(pack.validUntil, true)) : ('Vanaf ' + utility_1.Formatter.date(pack.meta.startDate, true)),
85
- package: pack,
86
- date: now,
87
- unitPrice: unitPrice,
88
- amount: amount,
89
- });
90
- return item;
91
- }
92
- canMerge(other) {
93
- // Mergeable if both don't have a packege, or both have the same package
94
- if (other.package && !this.package) {
95
- return false;
96
- }
97
- if (!other.package && this.package) {
98
- return false;
99
- }
100
- if (other.package && this.package && other.package.id !== this.package.id) {
101
- return false;
102
- }
103
- if (this.name === other.name && this.description === other.description) {
104
- if (this.unitPrice === other.unitPrice) {
105
- return true;
106
- }
107
- if (this.amount === 1 && other.amount === 1) {
108
- return true;
109
- }
110
- }
111
- return false;
112
- }
113
- merge(other) {
114
- if (other.paymentFailedCount > this.paymentFailedCount) {
115
- this.paymentFailedCount = other.paymentFailedCount;
116
- }
117
- if (other.firstFailedPayment && (!this.firstFailedPayment || other.firstFailedPayment < this.firstFailedPayment)) {
118
- this.firstFailedPayment = other.firstFailedPayment;
119
- }
120
- if (other.unitPrice !== this.unitPrice) {
121
- if (other.amount === 1 && this.amount === 1) {
122
- this.unitPrice += other.unitPrice;
123
- this.package = other.package;
124
- return;
125
- }
126
- throw new Error('Cannot merge items with different unit prices and amount greater than 1');
127
- }
128
- this.amount += other.amount;
129
- }
130
- /// Only compress an invoice when it is marked as paid and for a pending invoice when it doesn't has an invoice
131
- /// Else you'll lose the ID's!
132
- static compress(items) {
133
- const copy = items.slice();
134
- for (let index = 0; index < copy.length; index++) {
135
- // Create a copy to prevent changing the original one
136
- const item = STInvoiceItem.create(copy[index]);
137
- copy[index] = item;
138
- // Loop further (in reverse order to be able to delete items)
139
- for (let j = copy.length - 1; j > index; j--) {
140
- const other = copy[j];
141
- if (item.canMerge(other)) {
142
- // Delete other
143
- item.merge(other);
144
- copy.splice(j, 1);
145
- }
146
- }
147
- }
148
- return copy;
149
- }
150
- }
151
- exports.STInvoiceItem = STInvoiceItem;
152
- tslib_1.__decorate([
153
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, defaultValue: () => (0, uuid_1.v4)() })
154
- ], STInvoiceItem.prototype, "id", void 0);
155
- tslib_1.__decorate([
156
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder })
157
- ], STInvoiceItem.prototype, "name", void 0);
158
- tslib_1.__decorate([
159
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder })
160
- ], STInvoiceItem.prototype, "description", void 0);
161
- tslib_1.__decorate([
162
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.IntegerDecoder })
163
- ], STInvoiceItem.prototype, "amount", void 0);
164
- tslib_1.__decorate([
165
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.IntegerDecoder }),
166
- (0, simple_encoding_1.field)({ ...upgradePriceFrom2To4DecimalPlaces_js_1.upgradePriceFrom2To4DecimalPlaces })
167
- ], STInvoiceItem.prototype, "unitPrice", void 0);
168
- tslib_1.__decorate([
169
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.BooleanDecoder, version: 155 })
170
- ], STInvoiceItem.prototype, "canUseCredits", void 0);
171
- tslib_1.__decorate([
172
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.DateDecoder, nullable: true, optional: true })
173
- ], STInvoiceItem.prototype, "firstFailedPayment", void 0);
174
- tslib_1.__decorate([
175
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.IntegerDecoder, optional: true })
176
- ], STInvoiceItem.prototype, "paymentFailedCount", void 0);
177
- tslib_1.__decorate([
178
- (0, simple_encoding_1.field)({ decoder: STPackage_js_1.STPackage, optional: true })
179
- ], STInvoiceItem.prototype, "package", void 0);
180
- tslib_1.__decorate([
181
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.DateDecoder, optional: true })
182
- ], STInvoiceItem.prototype, "date", void 0);
183
- /**
184
- * @deprecated use Invoice
185
- */
186
- class STInvoiceMeta extends simple_encoding_1.AutoEncoder {
187
- constructor() {
188
- super(...arguments);
189
- /**
190
- * VATPercentage should be zero in countries outside Belgium in EU
191
- */
192
- this.VATPercentage = 21;
193
- this.items = [];
194
- /**
195
- * Sometimes we need to calculate an invoice in reverse when we have a fixed price including VAT,
196
- * but need to calculatle the price excluding VAT.
197
- */
198
- this.areItemsIncludingVAT = false;
199
- this.companyVATNumber = null;
200
- this.companyNumber = null;
201
- this.ipAddress = null;
202
- this.userAgent = null;
203
- this.stripeAccountId = null;
204
- }
205
- /**
206
- * @deprecated
207
- * Depending on areItemsIncludingVAT, this can either be including or excluding VAT
208
- */
209
- get itemPrice() {
210
- return this.items.reduce((price, item) => price + item.price, 0);
211
- }
212
- includingVATToExcludingVAT(price) {
213
- // Always only round the VAT, not other prices
214
- return price - this.getVATOnIncludingVATAmount(price);
215
- }
216
- excludingVATToIncludingVAT(price) {
217
- // Always only round the VAT, not other prices
218
- return price + this.getVATOnExcludingVATAmount(price);
219
- }
220
- getVATOnIncludingVATAmount(price) {
221
- return Math.round(price * this.VATPercentage / (100 + this.VATPercentage));
222
- }
223
- getVATOnExcludingVATAmount(price) {
224
- // Make sure price result doesn't depend on the sign of the price
225
- return Math.round(Math.abs(price) * this.VATPercentage / 100) * Math.sign(price);
226
- }
227
- get useLegacyRounding() {
228
- // In the past we didn't round the price without VAT if we calculated starting from a price inclusive VAT
229
- // in that case, we only rounded the VAT
230
- // todo: based on number!
231
- return false;
232
- }
233
- get priceWithoutVAT() {
234
- if (this.useLegacyRounding) {
235
- const itemPrice = this.itemPrice;
236
- if (this.areItemsIncludingVAT) {
237
- return itemPrice - this.VAT;
238
- }
239
- return itemPrice;
240
- }
241
- if (this.areItemsIncludingVAT) {
242
- // We round at individual item level
243
- // because PEPPOL requires prices with max 2 decimals on every line level, meaning we need to round.
244
- return this.items.reduce((price, item) => price + this.includingVATToExcludingVAT(item.price), 0);
245
- }
246
- return this.items.reduce((price, item) => price + item.price, 0);
247
- }
248
- get VAT() {
249
- if (this.useLegacyRounding && this.areItemsIncludingVAT) {
250
- // Subtract VAT and round
251
- // Need to be careful with circular calls
252
- return this.getVATOnIncludingVATAmount(this.itemPrice);
253
- }
254
- return this.getVATOnExcludingVATAmount(this.priceWithoutVAT);
255
- }
256
- get priceWithVAT() {
257
- return this.priceWithoutVAT + this.VAT;
258
- }
259
- /**
260
- * How much to add or remove to priceWithVAT to get to the payable amount. We can get a rounding error of 1 cent positive or negative if we calculate from a given price inclusive VAT.
261
- *
262
- * 1 cent if we need to add 1 cent
263
- * -1 cent if we need to remove 1 cent from the priceWithVAT to get to the payable amount
264
- */
265
- get payableRoundingAmount() {
266
- return this.totalPrice - this.priceWithVAT;
267
- }
268
- get totalPrice() {
269
- const itemPrice = this.itemPrice;
270
- if (this.areItemsIncludingVAT) {
271
- return itemPrice;
272
- }
273
- return itemPrice + this.VAT;
274
- }
275
- }
276
- exports.STInvoiceMeta = STInvoiceMeta;
277
- tslib_1.__decorate([
278
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.DateDecoder, optional: true })
279
- ], STInvoiceMeta.prototype, "date", void 0);
280
- tslib_1.__decorate([
281
- (0, simple_encoding_1.field)({ decoder: File_js_1.File, optional: true })
282
- ], STInvoiceMeta.prototype, "pdf", void 0);
283
- tslib_1.__decorate([
284
- (0, simple_encoding_1.field)({ decoder: File_js_1.File, optional: true })
285
- ], STInvoiceMeta.prototype, "xml", void 0);
286
- tslib_1.__decorate([
287
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.IntegerDecoder })
288
- ], STInvoiceMeta.prototype, "VATPercentage", void 0);
289
- tslib_1.__decorate([
290
- (0, simple_encoding_1.field)({ decoder: new simple_encoding_1.ArrayDecoder(STInvoiceItem) })
291
- ], STInvoiceMeta.prototype, "items", void 0);
292
- tslib_1.__decorate([
293
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.BooleanDecoder, version: 186 })
294
- ], STInvoiceMeta.prototype, "areItemsIncludingVAT", void 0);
295
- tslib_1.__decorate([
296
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder })
297
- ], STInvoiceMeta.prototype, "companyName", void 0);
298
- tslib_1.__decorate([
299
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder })
300
- ], STInvoiceMeta.prototype, "companyContact", void 0);
301
- tslib_1.__decorate([
302
- (0, simple_encoding_1.field)({ decoder: Address_js_1.Address })
303
- ], STInvoiceMeta.prototype, "companyAddress", void 0);
304
- tslib_1.__decorate([
305
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, nullable: true })
306
- ], STInvoiceMeta.prototype, "companyVATNumber", void 0);
307
- tslib_1.__decorate([
308
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, nullable: true, optional: true })
309
- ], STInvoiceMeta.prototype, "companyNumber", void 0);
310
- tslib_1.__decorate([
311
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, nullable: true, version: 133 })
312
- ], STInvoiceMeta.prototype, "ipAddress", void 0);
313
- tslib_1.__decorate([
314
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, nullable: true, version: 133 })
315
- ], STInvoiceMeta.prototype, "userAgent", void 0);
316
- tslib_1.__decorate([
317
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, nullable: true, version: 210 })
318
- ], STInvoiceMeta.prototype, "stripeAccountId", void 0);
319
- /**
320
- * @deprecated use Invoice
321
- */
8
+ const STInvoiceMeta_js_1 = require("./STInvoiceMeta.js");
322
9
  class STInvoice extends simple_encoding_1.AutoEncoder {
323
10
  constructor() {
324
11
  super(...arguments);
@@ -342,7 +29,7 @@ tslib_1.__decorate([
342
29
  (0, simple_encoding_1.field)({ decoder: Payment_js_1.Payment, nullable: true })
343
30
  ], STInvoice.prototype, "payment", void 0);
344
31
  tslib_1.__decorate([
345
- (0, simple_encoding_1.field)({ decoder: STInvoiceMeta })
32
+ (0, simple_encoding_1.field)({ decoder: STInvoiceMeta_js_1.STInvoiceMeta })
346
33
  ], STInvoice.prototype, "meta", void 0);
347
34
  tslib_1.__decorate([
348
35
  (0, simple_encoding_1.field)({ decoder: simple_encoding_1.IntegerDecoder, nullable: true })
@@ -362,88 +49,4 @@ tslib_1.__decorate([
362
49
  tslib_1.__decorate([
363
50
  (0, simple_encoding_1.field)({ decoder: simple_encoding_1.BooleanDecoder, optional: true })
364
51
  ], STInvoice.prototype, "didSendPeppol", void 0);
365
- /**
366
- * @deprecated use Invoice
367
- */
368
- class STInvoicePrivate extends STInvoice {
369
- constructor() {
370
- super(...arguments);
371
- this.settlement = null;
372
- this.reference = null;
373
- }
374
- matchQuery(query) {
375
- var _a;
376
- if (query === ((_a = this.number) === null || _a === void 0 ? void 0 : _a.toString()) || query === this.id) {
377
- return true;
378
- }
379
- if (utility_1.StringCompare.contains(this.meta.companyName, query)
380
- || utility_1.StringCompare.typoCount(this.meta.companyAddress.city, query) < 2
381
- || utility_1.StringCompare.contains(this.meta.companyContact, query)
382
- || (this.meta.companyVATNumber && utility_1.StringCompare.typoCount(this.meta.companyVATNumber, query) < 2)
383
- || utility_1.StringCompare.typoCount(this.meta.companyAddress.street, query) < 2) {
384
- return true;
385
- }
386
- if (!this.organization) {
387
- return false;
388
- }
389
- if (utility_1.StringCompare.typoCount(this.organization.name, query) < 2
390
- || utility_1.StringCompare.typoCount(this.organization.address.city, query) < 2
391
- || utility_1.StringCompare.typoCount(this.organization.address.street, query) < 2
392
- || utility_1.StringCompare.typoCount(this.meta.companyName, query) < 2
393
- || utility_1.StringCompare.typoCount(this.meta.companyName, query) < 2) {
394
- return true;
395
- }
396
- return false;
397
- }
398
- }
399
- exports.STInvoicePrivate = STInvoicePrivate;
400
- tslib_1.__decorate([
401
- (0, simple_encoding_1.field)({ decoder: OrganizationSimple_js_1.OrganizationSimple, optional: true })
402
- ], STInvoicePrivate.prototype, "organization", void 0);
403
- tslib_1.__decorate([
404
- (0, simple_encoding_1.field)({ decoder: Payment_js_1.Settlement, nullable: true })
405
- ], STInvoicePrivate.prototype, "settlement", void 0);
406
- tslib_1.__decorate([
407
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, nullable: true, version: 186 })
408
- ], STInvoicePrivate.prototype, "reference", void 0);
409
- class STPendingInvoice extends simple_encoding_1.AutoEncoder {
410
- constructor() {
411
- super(...arguments);
412
- this.id = null;
413
- this.invoice = null;
414
- this.createdAt = null;
415
- this.updatedAt = null;
416
- }
417
- }
418
- exports.STPendingInvoice = STPendingInvoice;
419
- tslib_1.__decorate([
420
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, nullable: true, optional: true })
421
- ], STPendingInvoice.prototype, "id", void 0);
422
- tslib_1.__decorate([
423
- (0, simple_encoding_1.field)({ decoder: STInvoiceMeta })
424
- ], STPendingInvoice.prototype, "meta", void 0);
425
- tslib_1.__decorate([
426
- (0, simple_encoding_1.field)({ decoder: STInvoice, nullable: true })
427
- ], STPendingInvoice.prototype, "invoice", void 0);
428
- tslib_1.__decorate([
429
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.DateDecoder, nullable: true })
430
- ], STPendingInvoice.prototype, "createdAt", void 0);
431
- tslib_1.__decorate([
432
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.DateDecoder, nullable: true })
433
- ], STPendingInvoice.prototype, "updatedAt", void 0);
434
- class STPendingInvoicePrivate extends STPendingInvoice {
435
- }
436
- exports.STPendingInvoicePrivate = STPendingInvoicePrivate;
437
- tslib_1.__decorate([
438
- (0, simple_encoding_1.field)({ decoder: OrganizationSimple_js_1.OrganizationSimple, optional: true })
439
- ], STPendingInvoicePrivate.prototype, "organization", void 0);
440
- class STInvoiceResponse extends simple_encoding_1.AutoEncoder {
441
- }
442
- exports.STInvoiceResponse = STInvoiceResponse;
443
- tslib_1.__decorate([
444
- (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, optional: true })
445
- ], STInvoiceResponse.prototype, "paymentUrl", void 0);
446
- tslib_1.__decorate([
447
- (0, simple_encoding_1.field)({ decoder: STInvoice, optional: true })
448
- ], STInvoiceResponse.prototype, "invoice", void 0);
449
52
  //# sourceMappingURL=STInvoice.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"STInvoice.js","sourceRoot":"","sources":["../../../src/billing/STInvoice.ts"],"names":[],"mappings":";;;;AAAA,iEAA2I;AAC3I,gDAA8D;AAC9D,+BAAoC;AAEpC,wDAAkD;AAClD,8CAAwC;AACxC,sDAA4D;AAC5D,oEAA8D;AAC9D,iDAA0D;AAC1D,kGAA4F;AAE5F,IAAY,eAKX;AALD,WAAY,eAAe;IACvB,sCAAmB,CAAA;IACnB,wCAAqB,CAAA;IACrB,0CAAuB,CAAA;IACvB,wCAAqB,CAAA;AACzB,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B;AAED;;GAEG;AACH,MAAa,aAAc,SAAQ,6BAAW;IAA9C;;QAKI,SAAI,GAAG,EAAE,CAAC;QAGV,gBAAW,GAAG,EAAE,CAAC;QAGjB,WAAM,GAAG,CAAC,CAAC;QAIX,cAAS,GAAG,CAAC,CAAC;QAGd,kBAAa,GAAG,IAAI,CAAC;QAGrB,uBAAkB,GAAgB,IAAI,CAAC;QAGvC,uBAAkB,GAAG,CAAC,CAAC;IAkJ3B,CAAC;IAhJG,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;IACxC,CAAC;IAcD;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,IAAe,EAAE,MAAM,GAAG,CAAC,EAAE,aAAa,GAAG,CAAC,EAAE,IAAW;QAC1E,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC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C,IAAA,uBAAK,EAAC,EAAE,OAAO,EAAE,oBAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;0CACb;AAG/B;IADC,IAAA,uBAAK,EAAC,EAAE,OAAO,EAAE,gCAAa,EAAE,CAAC;uCACd;AAMpB;IADC,IAAA,uBAAK,EAAC,EAAE,OAAO,EAAE,gCAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;yCACtB;AAG7B;IADC,IAAA,uBAAK,EAAC,EAAE,OAAO,EAAE,6BAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;4CAClB;AAG9B;IADC,IAAA,uBAAK,EAAC,EAAE,OAAO,EAAE,6BAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;4CAClB;AAG9B;IADC,IAAA,uBAAK,EAAC,EAAE,OAAO,EAAE,6BAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;yCACrB;AAG3B;IADC,IAAA,uBAAK,EAAC,EAAE,OAAO,EAAE,+BAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;oDACxB;AAGxC;IADC,IAAA,uBAAK,EAAC,EAAE,OAAO,EAAE,gCAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gDAC7B"}
@@ -0,0 +1,32 @@
1
+ import { AutoEncoder } from '@simonbackx/simple-encoding';
2
+ import { STPackage } from './STPackage.js';
3
+ export declare class STInvoiceItem extends AutoEncoder {
4
+ id: string;
5
+ name: string;
6
+ description: string;
7
+ amount: number;
8
+ unitPrice: number;
9
+ canUseCredits: boolean;
10
+ firstFailedPayment: Date | null;
11
+ paymentFailedCount: number;
12
+ get price(): number;
13
+ /**
14
+ * All data of the original package that is linked to this item
15
+ */
16
+ package?: STPackage;
17
+ /**
18
+ * Date the item was created/bought
19
+ */
20
+ date?: Date;
21
+ /**
22
+ * Convertable into STInvoiceItem (or the diffence if amount is increased)
23
+ * Use this to calculate prices or create an invoice
24
+ * This will calculate the price to expand the package to the given amount.
25
+ * If you want to renew a package, you need to create a new package first
26
+ */
27
+ static fromPackage(pack: STPackage, amount?: number, pendingAmount?: number, date?: Date): STInvoiceItem;
28
+ canMerge(other: STInvoiceItem): boolean;
29
+ merge(other: STInvoiceItem): void;
30
+ static compress(items: STInvoiceItem[]): STInvoiceItem[];
31
+ }
32
+ //# sourceMappingURL=STInvoiceItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STInvoiceItem.d.ts","sourceRoot":"","sources":["../../../src/billing/STInvoiceItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqE,MAAM,6BAA6B,CAAC;AAK7H,OAAO,EAAE,SAAS,EAAiB,MAAM,gBAAgB,CAAC;AAE1D,qBAAa,aAAc,SAAQ,WAAW;IAE1C,EAAE,EAAE,MAAM,CAAC;IAGX,IAAI,SAAM;IAGV,WAAW,SAAM;IAGjB,MAAM,SAAK;IAIX,SAAS,SAAK;IAGd,aAAa,UAAQ;IAGrB,kBAAkB,EAAE,IAAI,GAAG,IAAI,CAAQ;IAGvC,kBAAkB,SAAK;IAEvB,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IAEH,OAAO,CAAC,EAAE,SAAS,CAAC;IAEpB;;OAEG;IAEH,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,SAAI,EAAE,aAAa,SAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,aAAa;IA2D9F,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO;IAuBvC,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAoBjC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE;CAoBzC"}
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STInvoiceItem = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const simple_encoding_1 = require("@simonbackx/simple-encoding");
6
+ const utility_1 = require("@stamhoofd/utility");
7
+ const uuid_1 = require("uuid");
8
+ const upgradePriceFrom2To4DecimalPlaces_js_1 = require("../upgradePriceFrom2To4DecimalPlaces.js");
9
+ const STPackage_js_1 = require("./STPackage.js");
10
+ class STInvoiceItem extends simple_encoding_1.AutoEncoder {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.name = '';
14
+ this.description = '';
15
+ this.amount = 1;
16
+ this.unitPrice = 0;
17
+ this.canUseCredits = true;
18
+ this.firstFailedPayment = null;
19
+ this.paymentFailedCount = 0;
20
+ }
21
+ get price() {
22
+ return this.unitPrice * this.amount;
23
+ }
24
+ /**
25
+ * Convertable into STInvoiceItem (or the diffence if amount is increased)
26
+ * Use this to calculate prices or create an invoice
27
+ * This will calculate the price to expand the package to the given amount.
28
+ * If you want to renew a package, you need to create a new package first
29
+ */
30
+ static fromPackage(pack, amount = 1, pendingAmount = 0, date) {
31
+ let unitPrice = Math.round(pack.meta.unitPrice);
32
+ if (amount < pack.meta.minimumAmount) {
33
+ // Minimum should get applied first, because we might already have paid for the minimum (paid amount)
34
+ amount = pack.meta.minimumAmount;
35
+ }
36
+ amount -= pendingAmount;
37
+ amount -= pack.meta.paidAmount;
38
+ if (amount <= 0) {
39
+ amount = 0;
40
+ }
41
+ /// When pricing type is memebrs, the price is calculated per year.
42
+ /// If a shorter period is remaining, we give a discount in order
43
+ /// to no need to handle it more complicated
44
+ let now = date !== null && date !== void 0 ? date : new Date();
45
+ if (now < pack.meta.startDate) {
46
+ // When creating a new package, we sometimes buy it for the future, so use that date instead of now
47
+ now = pack.meta.startDate;
48
+ }
49
+ if (pack.validUntil && pack.meta.pricingType !== STPackage_js_1.STPricingType.Fixed) {
50
+ const totalDays = Math.round((pack.validUntil.getTime() - pack.meta.startDate.getTime()) / (1000 * 60 * 60 * 24));
51
+ let remainingDays = Math.round((pack.validUntil.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
52
+ /// First 3 months are full price
53
+ const paidDays = 30 * 3;
54
+ if (remainingDays > totalDays) {
55
+ remainingDays = totalDays;
56
+ }
57
+ if (totalDays > 366) {
58
+ // Increase unit price
59
+ unitPrice = unitPrice * (totalDays / 365);
60
+ }
61
+ if (pack.meta.pricingType === STPackage_js_1.STPricingType.PerMember) {
62
+ unitPrice = Math.round(Math.min(unitPrice, unitPrice * remainingDays / (Math.max(365, totalDays) - paidDays)));
63
+ }
64
+ else {
65
+ unitPrice = Math.round(unitPrice);
66
+ }
67
+ }
68
+ const item = STInvoiceItem.create({
69
+ name: pack.meta.name,
70
+ description: pack.validUntil ? ('Van ' + utility_1.Formatter.date(now, true) + ' tot ' + utility_1.Formatter.date(pack.validUntil, true)) : ('Vanaf ' + utility_1.Formatter.date(pack.meta.startDate, true)),
71
+ package: pack,
72
+ date: now,
73
+ unitPrice: unitPrice,
74
+ amount: amount,
75
+ });
76
+ return item;
77
+ }
78
+ canMerge(other) {
79
+ // Mergeable if both don't have a packege, or both have the same package
80
+ if (other.package && !this.package) {
81
+ return false;
82
+ }
83
+ if (!other.package && this.package) {
84
+ return false;
85
+ }
86
+ if (other.package && this.package && other.package.id !== this.package.id) {
87
+ return false;
88
+ }
89
+ if (this.name === other.name && this.description === other.description) {
90
+ if (this.unitPrice === other.unitPrice) {
91
+ return true;
92
+ }
93
+ if (this.amount === 1 && other.amount === 1) {
94
+ return true;
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+ merge(other) {
100
+ if (other.paymentFailedCount > this.paymentFailedCount) {
101
+ this.paymentFailedCount = other.paymentFailedCount;
102
+ }
103
+ if (other.firstFailedPayment && (!this.firstFailedPayment || other.firstFailedPayment < this.firstFailedPayment)) {
104
+ this.firstFailedPayment = other.firstFailedPayment;
105
+ }
106
+ if (other.unitPrice !== this.unitPrice) {
107
+ if (other.amount === 1 && this.amount === 1) {
108
+ this.unitPrice += other.unitPrice;
109
+ this.package = other.package;
110
+ return;
111
+ }
112
+ throw new Error('Cannot merge items with different unit prices and amount greater than 1');
113
+ }
114
+ this.amount += other.amount;
115
+ }
116
+ /// Only compress an invoice when it is marked as paid and for a pending invoice when it doesn't has an invoice
117
+ /// Else you'll lose the ID's!
118
+ static compress(items) {
119
+ const copy = items.slice();
120
+ for (let index = 0; index < copy.length; index++) {
121
+ // Create a copy to prevent changing the original one
122
+ const item = STInvoiceItem.create(copy[index]);
123
+ copy[index] = item;
124
+ // Loop further (in reverse order to be able to delete items)
125
+ for (let j = copy.length - 1; j > index; j--) {
126
+ const other = copy[j];
127
+ if (item.canMerge(other)) {
128
+ // Delete other
129
+ item.merge(other);
130
+ copy.splice(j, 1);
131
+ }
132
+ }
133
+ }
134
+ return copy;
135
+ }
136
+ }
137
+ exports.STInvoiceItem = STInvoiceItem;
138
+ tslib_1.__decorate([
139
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder, defaultValue: () => (0, uuid_1.v4)() })
140
+ ], STInvoiceItem.prototype, "id", void 0);
141
+ tslib_1.__decorate([
142
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder })
143
+ ], STInvoiceItem.prototype, "name", void 0);
144
+ tslib_1.__decorate([
145
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.StringDecoder })
146
+ ], STInvoiceItem.prototype, "description", void 0);
147
+ tslib_1.__decorate([
148
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.IntegerDecoder })
149
+ ], STInvoiceItem.prototype, "amount", void 0);
150
+ tslib_1.__decorate([
151
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.IntegerDecoder }),
152
+ (0, simple_encoding_1.field)({ ...upgradePriceFrom2To4DecimalPlaces_js_1.upgradePriceFrom2To4DecimalPlaces })
153
+ ], STInvoiceItem.prototype, "unitPrice", void 0);
154
+ tslib_1.__decorate([
155
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.BooleanDecoder, version: 155 })
156
+ ], STInvoiceItem.prototype, "canUseCredits", void 0);
157
+ tslib_1.__decorate([
158
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.DateDecoder, nullable: true, optional: true })
159
+ ], STInvoiceItem.prototype, "firstFailedPayment", void 0);
160
+ tslib_1.__decorate([
161
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.IntegerDecoder, optional: true })
162
+ ], STInvoiceItem.prototype, "paymentFailedCount", void 0);
163
+ tslib_1.__decorate([
164
+ (0, simple_encoding_1.field)({ decoder: STPackage_js_1.STPackage, optional: true })
165
+ ], STInvoiceItem.prototype, "package", void 0);
166
+ tslib_1.__decorate([
167
+ (0, simple_encoding_1.field)({ decoder: simple_encoding_1.DateDecoder, optional: true })
168
+ ], STInvoiceItem.prototype, "date", void 0);
169
+ //# sourceMappingURL=STInvoiceItem.js.map