@stamhoofd/structures 2.107.3 → 2.108.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 (87) hide show
  1. package/dist/src/GenericBalance.d.ts.map +1 -1
  2. package/dist/src/GenericBalance.js +2 -1
  3. package/dist/src/GenericBalance.js.map +1 -1
  4. package/dist/src/billing/STBillingStatus.d.ts +2 -1
  5. package/dist/src/billing/STBillingStatus.d.ts.map +1 -1
  6. package/dist/src/billing/STBillingStatus.js +2 -1
  7. package/dist/src/billing/STBillingStatus.js.map +1 -1
  8. package/dist/src/billing/STInvoice.d.ts +2 -125
  9. package/dist/src/billing/STInvoice.d.ts.map +1 -1
  10. package/dist/src/billing/STInvoice.js +3 -400
  11. package/dist/src/billing/STInvoice.js.map +1 -1
  12. package/dist/src/billing/STInvoiceItem.d.ts +32 -0
  13. package/dist/src/billing/STInvoiceItem.d.ts.map +1 -0
  14. package/dist/src/billing/STInvoiceItem.js +169 -0
  15. package/dist/src/billing/STInvoiceItem.js.map +1 -0
  16. package/dist/src/billing/STInvoiceMeta.d.ts +63 -0
  17. package/dist/src/billing/STInvoiceMeta.d.ts.map +1 -0
  18. package/dist/src/billing/STInvoiceMeta.js +152 -0
  19. package/dist/src/billing/STInvoiceMeta.js.map +1 -0
  20. package/dist/src/billing/STInvoicePrivate.d.ts +10 -0
  21. package/dist/src/billing/STInvoicePrivate.d.ts.map +1 -0
  22. package/dist/src/billing/STInvoicePrivate.js +51 -0
  23. package/dist/src/billing/STInvoicePrivate.js.map +1 -0
  24. package/dist/src/billing/STInvoiceStatus.d.ts +7 -0
  25. package/dist/src/billing/STInvoiceStatus.d.ts.map +1 -0
  26. package/dist/src/billing/STInvoiceStatus.js +11 -0
  27. package/dist/src/billing/STInvoiceStatus.js.map +1 -0
  28. package/dist/src/billing/STPendingInvoice.d.ts +15 -0
  29. package/dist/src/billing/STPendingInvoice.d.ts.map +1 -0
  30. package/dist/src/billing/STPendingInvoice.js +40 -0
  31. package/dist/src/billing/STPendingInvoice.js.map +1 -0
  32. package/dist/src/billing/index.d.ts +5 -0
  33. package/dist/src/billing/index.d.ts.map +1 -1
  34. package/dist/src/billing/index.js +5 -0
  35. package/dist/src/billing/index.js.map +1 -1
  36. package/dist/src/email/EmailTemplate.js +2 -2
  37. package/dist/src/email/EmailTemplate.js.map +1 -1
  38. package/dist/src/members/checkout/RegisterItem.d.ts.map +1 -1
  39. package/dist/src/members/checkout/RegisterItem.js +1 -3
  40. package/dist/src/members/checkout/RegisterItem.js.map +1 -1
  41. package/dist/src/webshops/Checkout.d.ts.map +1 -1
  42. package/dist/src/webshops/Checkout.js +10 -1
  43. package/dist/src/webshops/Checkout.js.map +1 -1
  44. package/esm/dist/src/GenericBalance.d.ts.map +1 -1
  45. package/esm/dist/src/GenericBalance.js +2 -1
  46. package/esm/dist/src/GenericBalance.js.map +1 -1
  47. package/esm/dist/src/billing/STBillingStatus.d.ts +2 -1
  48. package/esm/dist/src/billing/STBillingStatus.d.ts.map +1 -1
  49. package/esm/dist/src/billing/STBillingStatus.js +2 -1
  50. package/esm/dist/src/billing/STBillingStatus.js.map +1 -1
  51. package/esm/dist/src/billing/STInvoice.d.ts +2 -125
  52. package/esm/dist/src/billing/STInvoice.d.ts.map +1 -1
  53. package/esm/dist/src/billing/STInvoice.js +3 -394
  54. package/esm/dist/src/billing/STInvoice.js.map +1 -1
  55. package/esm/dist/src/billing/STInvoiceItem.d.ts +32 -0
  56. package/esm/dist/src/billing/STInvoiceItem.d.ts.map +1 -0
  57. package/esm/dist/src/billing/STInvoiceItem.js +165 -0
  58. package/esm/dist/src/billing/STInvoiceItem.js.map +1 -0
  59. package/esm/dist/src/billing/STInvoiceMeta.d.ts +63 -0
  60. package/esm/dist/src/billing/STInvoiceMeta.d.ts.map +1 -0
  61. package/esm/dist/src/billing/STInvoiceMeta.js +148 -0
  62. package/esm/dist/src/billing/STInvoiceMeta.js.map +1 -0
  63. package/esm/dist/src/billing/STInvoicePrivate.d.ts +10 -0
  64. package/esm/dist/src/billing/STInvoicePrivate.d.ts.map +1 -0
  65. package/esm/dist/src/billing/STInvoicePrivate.js +47 -0
  66. package/esm/dist/src/billing/STInvoicePrivate.js.map +1 -0
  67. package/esm/dist/src/billing/STInvoiceStatus.d.ts +7 -0
  68. package/esm/dist/src/billing/STInvoiceStatus.d.ts.map +1 -0
  69. package/esm/dist/src/billing/STInvoiceStatus.js +8 -0
  70. package/esm/dist/src/billing/STInvoiceStatus.js.map +1 -0
  71. package/esm/dist/src/billing/STPendingInvoice.d.ts +15 -0
  72. package/esm/dist/src/billing/STPendingInvoice.d.ts.map +1 -0
  73. package/esm/dist/src/billing/STPendingInvoice.js +35 -0
  74. package/esm/dist/src/billing/STPendingInvoice.js.map +1 -0
  75. package/esm/dist/src/billing/index.d.ts +5 -0
  76. package/esm/dist/src/billing/index.d.ts.map +1 -1
  77. package/esm/dist/src/billing/index.js +5 -0
  78. package/esm/dist/src/billing/index.js.map +1 -1
  79. package/esm/dist/src/email/EmailTemplate.js +2 -2
  80. package/esm/dist/src/email/EmailTemplate.js.map +1 -1
  81. package/esm/dist/src/members/checkout/RegisterItem.d.ts.map +1 -1
  82. package/esm/dist/src/members/checkout/RegisterItem.js +1 -3
  83. package/esm/dist/src/members/checkout/RegisterItem.js.map +1 -1
  84. package/esm/dist/src/webshops/Checkout.d.ts.map +1 -1
  85. package/esm/dist/src/webshops/Checkout.js +10 -1
  86. package/esm/dist/src/webshops/Checkout.js.map +1 -1
  87. package/package.json +2 -2
@@ -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,165 @@
1
+ import { __decorate } from "tslib";
2
+ import { AutoEncoder, BooleanDecoder, DateDecoder, field, IntegerDecoder, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import { Formatter } from '@stamhoofd/utility';
4
+ import { v4 as uuidv4 } from 'uuid';
5
+ import { upgradePriceFrom2To4DecimalPlaces } from '../upgradePriceFrom2To4DecimalPlaces.js';
6
+ import { STPackage, STPricingType } from './STPackage.js';
7
+ export class STInvoiceItem extends AutoEncoder {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.name = '';
11
+ this.description = '';
12
+ this.amount = 1;
13
+ this.unitPrice = 0;
14
+ this.canUseCredits = true;
15
+ this.firstFailedPayment = null;
16
+ this.paymentFailedCount = 0;
17
+ }
18
+ get price() {
19
+ return this.unitPrice * this.amount;
20
+ }
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, amount = 1, pendingAmount = 0, date) {
28
+ let unitPrice = Math.round(pack.meta.unitPrice);
29
+ if (amount < pack.meta.minimumAmount) {
30
+ // Minimum should get applied first, because we might already have paid for the minimum (paid amount)
31
+ amount = pack.meta.minimumAmount;
32
+ }
33
+ amount -= pendingAmount;
34
+ amount -= pack.meta.paidAmount;
35
+ if (amount <= 0) {
36
+ amount = 0;
37
+ }
38
+ /// When pricing type is memebrs, the price is calculated per year.
39
+ /// If a shorter period is remaining, we give a discount in order
40
+ /// to no need to handle it more complicated
41
+ let now = date !== null && date !== void 0 ? date : new Date();
42
+ if (now < pack.meta.startDate) {
43
+ // When creating a new package, we sometimes buy it for the future, so use that date instead of now
44
+ now = pack.meta.startDate;
45
+ }
46
+ if (pack.validUntil && pack.meta.pricingType !== STPricingType.Fixed) {
47
+ const totalDays = Math.round((pack.validUntil.getTime() - pack.meta.startDate.getTime()) / (1000 * 60 * 60 * 24));
48
+ let remainingDays = Math.round((pack.validUntil.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
49
+ /// First 3 months are full price
50
+ const paidDays = 30 * 3;
51
+ if (remainingDays > totalDays) {
52
+ remainingDays = totalDays;
53
+ }
54
+ if (totalDays > 366) {
55
+ // Increase unit price
56
+ unitPrice = unitPrice * (totalDays / 365);
57
+ }
58
+ if (pack.meta.pricingType === STPricingType.PerMember) {
59
+ unitPrice = Math.round(Math.min(unitPrice, unitPrice * remainingDays / (Math.max(365, totalDays) - paidDays)));
60
+ }
61
+ else {
62
+ unitPrice = Math.round(unitPrice);
63
+ }
64
+ }
65
+ const item = STInvoiceItem.create({
66
+ name: pack.meta.name,
67
+ description: pack.validUntil ? ('Van ' + Formatter.date(now, true) + ' tot ' + Formatter.date(pack.validUntil, true)) : ('Vanaf ' + Formatter.date(pack.meta.startDate, true)),
68
+ package: pack,
69
+ date: now,
70
+ unitPrice: unitPrice,
71
+ amount: amount,
72
+ });
73
+ return item;
74
+ }
75
+ canMerge(other) {
76
+ // Mergeable if both don't have a packege, or both have the same package
77
+ if (other.package && !this.package) {
78
+ return false;
79
+ }
80
+ if (!other.package && this.package) {
81
+ return false;
82
+ }
83
+ if (other.package && this.package && other.package.id !== this.package.id) {
84
+ return false;
85
+ }
86
+ if (this.name === other.name && this.description === other.description) {
87
+ if (this.unitPrice === other.unitPrice) {
88
+ return true;
89
+ }
90
+ if (this.amount === 1 && other.amount === 1) {
91
+ return true;
92
+ }
93
+ }
94
+ return false;
95
+ }
96
+ merge(other) {
97
+ if (other.paymentFailedCount > this.paymentFailedCount) {
98
+ this.paymentFailedCount = other.paymentFailedCount;
99
+ }
100
+ if (other.firstFailedPayment && (!this.firstFailedPayment || other.firstFailedPayment < this.firstFailedPayment)) {
101
+ this.firstFailedPayment = other.firstFailedPayment;
102
+ }
103
+ if (other.unitPrice !== this.unitPrice) {
104
+ if (other.amount === 1 && this.amount === 1) {
105
+ this.unitPrice += other.unitPrice;
106
+ this.package = other.package;
107
+ return;
108
+ }
109
+ throw new Error('Cannot merge items with different unit prices and amount greater than 1');
110
+ }
111
+ this.amount += other.amount;
112
+ }
113
+ /// Only compress an invoice when it is marked as paid and for a pending invoice when it doesn't has an invoice
114
+ /// Else you'll lose the ID's!
115
+ static compress(items) {
116
+ const copy = items.slice();
117
+ for (let index = 0; index < copy.length; index++) {
118
+ // Create a copy to prevent changing the original one
119
+ const item = STInvoiceItem.create(copy[index]);
120
+ copy[index] = item;
121
+ // Loop further (in reverse order to be able to delete items)
122
+ for (let j = copy.length - 1; j > index; j--) {
123
+ const other = copy[j];
124
+ if (item.canMerge(other)) {
125
+ // Delete other
126
+ item.merge(other);
127
+ copy.splice(j, 1);
128
+ }
129
+ }
130
+ }
131
+ return copy;
132
+ }
133
+ }
134
+ __decorate([
135
+ field({ decoder: StringDecoder, defaultValue: () => uuidv4() })
136
+ ], STInvoiceItem.prototype, "id", void 0);
137
+ __decorate([
138
+ field({ decoder: StringDecoder })
139
+ ], STInvoiceItem.prototype, "name", void 0);
140
+ __decorate([
141
+ field({ decoder: StringDecoder })
142
+ ], STInvoiceItem.prototype, "description", void 0);
143
+ __decorate([
144
+ field({ decoder: IntegerDecoder })
145
+ ], STInvoiceItem.prototype, "amount", void 0);
146
+ __decorate([
147
+ field({ decoder: IntegerDecoder }),
148
+ field({ ...upgradePriceFrom2To4DecimalPlaces })
149
+ ], STInvoiceItem.prototype, "unitPrice", void 0);
150
+ __decorate([
151
+ field({ decoder: BooleanDecoder, version: 155 })
152
+ ], STInvoiceItem.prototype, "canUseCredits", void 0);
153
+ __decorate([
154
+ field({ decoder: DateDecoder, nullable: true, optional: true })
155
+ ], STInvoiceItem.prototype, "firstFailedPayment", void 0);
156
+ __decorate([
157
+ field({ decoder: IntegerDecoder, optional: true })
158
+ ], STInvoiceItem.prototype, "paymentFailedCount", void 0);
159
+ __decorate([
160
+ field({ decoder: STPackage, optional: true })
161
+ ], STInvoiceItem.prototype, "package", void 0);
162
+ __decorate([
163
+ field({ decoder: DateDecoder, optional: true })
164
+ ], STInvoiceItem.prototype, "date", void 0);
165
+ //# sourceMappingURL=STInvoiceItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STInvoiceItem.js","sourceRoot":"","sources":["../../../../src/billing/STInvoiceItem.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC7H,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,OAAO,aAAc,SAAQ,WAAW;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,IAAI,CAAC,SAAS,CAAC,CAAC;QAEhD,IAAI,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,C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CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;kDACjB;AAGjB;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;6CACxB;AAIX;IAFC,KAAK,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;IAClC,KAAK,CAAC,EAAE,GAAG,iCAAiC,EAAE,CAAC;gDAClC;AAGd;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;oDAC5B;AAGrB;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;yDACzB;AAGvC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;yDAC5B;AAUvB;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;8CAC1B;AAMpB;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;2CACpC"}
@@ -0,0 +1,63 @@
1
+ import { AutoEncoder } from '@simonbackx/simple-encoding';
2
+ import { Address } from '../addresses/Address.js';
3
+ import { File } from '../files/File.js';
4
+ import { STInvoiceItem } from './STInvoiceItem.js';
5
+ export declare class STInvoiceMeta extends AutoEncoder {
6
+ /**
7
+ * Date the invoice was valid and given a number.
8
+ */
9
+ date?: Date;
10
+ /**
11
+ * Only set if the invoice is officially generated and send
12
+ */
13
+ pdf?: File;
14
+ /**
15
+ * Only set if the invoice is officially generated and send + company has VAT number
16
+ */
17
+ xml?: File;
18
+ /**
19
+ * Has this been charged automatically via outstanding amount?
20
+ */
21
+ backgroundCharge: boolean;
22
+ /**
23
+ * VATPercentage should be zero in countries outside Belgium in EU
24
+ */
25
+ VATPercentage: number;
26
+ items: STInvoiceItem[];
27
+ /**
28
+ * Sometimes we need to calculate an invoice in reverse when we have a fixed price including VAT,
29
+ * but need to calculatle the price excluding VAT.
30
+ */
31
+ areItemsIncludingVAT: boolean;
32
+ companyName: string;
33
+ companyContact: string;
34
+ companyEmail: string | null;
35
+ companyAddress: Address;
36
+ companyVATNumber: string | null;
37
+ companyNumber: string | null;
38
+ ipAddress: string | null;
39
+ userAgent: string | null;
40
+ stripeAccountId: string | null;
41
+ /**
42
+ * @deprecated
43
+ * Depending on areItemsIncludingVAT, this can either be including or excluding VAT
44
+ */
45
+ private get itemPrice();
46
+ includingVATToExcludingVAT(price: number): number;
47
+ excludingVATToIncludingVAT(price: number): number;
48
+ getVATOnIncludingVATAmount(price: number): number;
49
+ getVATOnExcludingVATAmount(price: number): number;
50
+ get useLegacyRounding(): boolean | undefined;
51
+ get priceWithoutVAT(): number;
52
+ get VAT(): number;
53
+ get priceWithVAT(): number;
54
+ /**
55
+ * 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.
56
+ *
57
+ * 1 cent if we need to add 1 cent
58
+ * -1 cent if we need to remove 1 cent from the priceWithVAT to get to the payable amount
59
+ */
60
+ get payableRoundingAmount(): number;
61
+ get totalPrice(): number;
62
+ }
63
+ //# sourceMappingURL=STInvoiceMeta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STInvoiceMeta.d.ts","sourceRoot":"","sources":["../../../../src/billing/STInvoiceMeta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAqE,MAAM,6BAA6B,CAAC;AAE3I,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAa,aAAc,SAAQ,WAAW;IAC1C;;OAEG;IAEH,IAAI,CAAC,EAAE,IAAI,CAAC;IAEZ;;OAEG;IAEH,GAAG,CAAC,EAAE,IAAI,CAAC;IAEX;;OAEG;IAEH,GAAG,CAAC,EAAE,IAAI,CAAC;IAEX;;OAEG;IAEH,gBAAgB,UAAS;IAEzB;;OAEG;IAEH,aAAa,SAAM;IAGnB,KAAK,EAAE,aAAa,EAAE,CAAM;IAE5B;;;OAGG;IAEH,oBAAoB,UAAS;IAI7B,WAAW,EAAE,MAAM,CAAC;IAGpB,cAAc,EAAE,MAAM,CAAC;IAGvB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGnC,cAAc,EAAE,OAAO,CAAC;IAGxB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGvC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGpC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGhC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGhC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEtC;;;OAGG;IACH,OAAO,KAAK,SAAS,GAEpB;IAED,0BAA0B,CAAC,KAAK,EAAE,MAAM;IAKxC,0BAA0B,CAAC,KAAK,EAAE,MAAM;IAKxC,0BAA0B,CAAC,KAAK,EAAE,MAAM;IAIxC,0BAA0B,CAAC,KAAK,EAAE,MAAM;IAKxC,IAAI,iBAAiB,wBAIpB;IAED,IAAI,eAAe,IAAI,MAAM,CAe5B;IAED,IAAI,GAAG,IAAI,MAAM,CAQhB;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;;;;OAKG;IACH,IAAI,qBAAqB,WAExB;IAED,IAAI,UAAU,WAMb;CACJ"}
@@ -0,0 +1,148 @@
1
+ import { __decorate } from "tslib";
2
+ import { ArrayDecoder, AutoEncoder, BooleanDecoder, DateDecoder, field, IntegerDecoder, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import { Address } from '../addresses/Address.js';
4
+ import { File } from '../files/File.js';
5
+ import { STInvoiceItem } from './STInvoiceItem.js';
6
+ export class STInvoiceMeta extends AutoEncoder {
7
+ constructor() {
8
+ super(...arguments);
9
+ /**
10
+ * Has this been charged automatically via outstanding amount?
11
+ */
12
+ this.backgroundCharge = false;
13
+ /**
14
+ * VATPercentage should be zero in countries outside Belgium in EU
15
+ */
16
+ this.VATPercentage = 21;
17
+ this.items = [];
18
+ /**
19
+ * Sometimes we need to calculate an invoice in reverse when we have a fixed price including VAT,
20
+ * but need to calculatle the price excluding VAT.
21
+ */
22
+ this.areItemsIncludingVAT = false;
23
+ this.companyEmail = null;
24
+ this.companyVATNumber = null;
25
+ this.companyNumber = null;
26
+ this.ipAddress = null;
27
+ this.userAgent = null;
28
+ this.stripeAccountId = null;
29
+ }
30
+ /**
31
+ * @deprecated
32
+ * Depending on areItemsIncludingVAT, this can either be including or excluding VAT
33
+ */
34
+ get itemPrice() {
35
+ return this.items.reduce((price, item) => price + item.price, 0);
36
+ }
37
+ includingVATToExcludingVAT(price) {
38
+ // Always only round the VAT, not other prices
39
+ return price - this.getVATOnIncludingVATAmount(price);
40
+ }
41
+ excludingVATToIncludingVAT(price) {
42
+ // Always only round the VAT, not other prices
43
+ return price + this.getVATOnExcludingVATAmount(price);
44
+ }
45
+ getVATOnIncludingVATAmount(price) {
46
+ return Math.round(price * this.VATPercentage / (100 + this.VATPercentage));
47
+ }
48
+ getVATOnExcludingVATAmount(price) {
49
+ // Make sure price result doesn't depend on the sign of the price
50
+ return Math.round(Math.abs(price) * this.VATPercentage / 100) * Math.sign(price);
51
+ }
52
+ get useLegacyRounding() {
53
+ // In the past we didn't round the price without VAT if we calculated starting from a price inclusive VAT
54
+ // in that case, we only rounded the VAT
55
+ return this.date && this.date < new Date('2025-12-01');
56
+ }
57
+ get priceWithoutVAT() {
58
+ if (this.useLegacyRounding) {
59
+ const itemPrice = this.itemPrice;
60
+ if (this.areItemsIncludingVAT) {
61
+ return itemPrice - this.VAT;
62
+ }
63
+ return itemPrice;
64
+ }
65
+ if (this.areItemsIncludingVAT) {
66
+ // We round at individual item level
67
+ // because PEPPOL requires prices with max 2 decimals on every line level, meaning we need to round.
68
+ return this.items.reduce((price, item) => price + this.includingVATToExcludingVAT(item.price), 0);
69
+ }
70
+ return this.items.reduce((price, item) => price + item.price, 0);
71
+ }
72
+ get VAT() {
73
+ if (this.useLegacyRounding && this.areItemsIncludingVAT) {
74
+ // Subtract VAT and round
75
+ // Need to be careful with circular calls
76
+ return this.getVATOnIncludingVATAmount(this.itemPrice);
77
+ }
78
+ return this.getVATOnExcludingVATAmount(this.priceWithoutVAT);
79
+ }
80
+ get priceWithVAT() {
81
+ return this.priceWithoutVAT + this.VAT;
82
+ }
83
+ /**
84
+ * 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.
85
+ *
86
+ * 1 cent if we need to add 1 cent
87
+ * -1 cent if we need to remove 1 cent from the priceWithVAT to get to the payable amount
88
+ */
89
+ get payableRoundingAmount() {
90
+ return this.totalPrice - this.priceWithVAT;
91
+ }
92
+ get totalPrice() {
93
+ const itemPrice = this.itemPrice;
94
+ if (this.areItemsIncludingVAT) {
95
+ return itemPrice;
96
+ }
97
+ return itemPrice + this.VAT;
98
+ }
99
+ }
100
+ __decorate([
101
+ field({ decoder: DateDecoder, optional: true })
102
+ ], STInvoiceMeta.prototype, "date", void 0);
103
+ __decorate([
104
+ field({ decoder: File, optional: true })
105
+ ], STInvoiceMeta.prototype, "pdf", void 0);
106
+ __decorate([
107
+ field({ decoder: File, optional: true })
108
+ ], STInvoiceMeta.prototype, "xml", void 0);
109
+ __decorate([
110
+ field({ decoder: BooleanDecoder, optional: true })
111
+ ], STInvoiceMeta.prototype, "backgroundCharge", void 0);
112
+ __decorate([
113
+ field({ decoder: IntegerDecoder })
114
+ ], STInvoiceMeta.prototype, "VATPercentage", void 0);
115
+ __decorate([
116
+ field({ decoder: new ArrayDecoder(STInvoiceItem) })
117
+ ], STInvoiceMeta.prototype, "items", void 0);
118
+ __decorate([
119
+ field({ decoder: BooleanDecoder, version: 186 })
120
+ ], STInvoiceMeta.prototype, "areItemsIncludingVAT", void 0);
121
+ __decorate([
122
+ field({ decoder: StringDecoder })
123
+ ], STInvoiceMeta.prototype, "companyName", void 0);
124
+ __decorate([
125
+ field({ decoder: StringDecoder })
126
+ ], STInvoiceMeta.prototype, "companyContact", void 0);
127
+ __decorate([
128
+ field({ decoder: StringDecoder, optional: true, nullable: true })
129
+ ], STInvoiceMeta.prototype, "companyEmail", void 0);
130
+ __decorate([
131
+ field({ decoder: Address })
132
+ ], STInvoiceMeta.prototype, "companyAddress", void 0);
133
+ __decorate([
134
+ field({ decoder: StringDecoder, nullable: true })
135
+ ], STInvoiceMeta.prototype, "companyVATNumber", void 0);
136
+ __decorate([
137
+ field({ decoder: StringDecoder, nullable: true, optional: true })
138
+ ], STInvoiceMeta.prototype, "companyNumber", void 0);
139
+ __decorate([
140
+ field({ decoder: StringDecoder, nullable: true, version: 133 })
141
+ ], STInvoiceMeta.prototype, "ipAddress", void 0);
142
+ __decorate([
143
+ field({ decoder: StringDecoder, nullable: true, version: 133 })
144
+ ], STInvoiceMeta.prototype, "userAgent", void 0);
145
+ __decorate([
146
+ field({ decoder: StringDecoder, nullable: true, version: 210 })
147
+ ], STInvoiceMeta.prototype, "stripeAccountId", void 0);
148
+ //# sourceMappingURL=STInvoiceMeta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STInvoiceMeta.js","sourceRoot":"","sources":["../../../../src/billing/STInvoiceMeta.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE3I,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,OAAO,aAAc,SAAQ,WAAW;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O,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;uDACX;AAGvC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;oDAC9B;AAGpC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;gDAChC;AAGhC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;gDAChC;AAGhC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;sDAC1B"}
@@ -0,0 +1,10 @@
1
+ import { Settlement } from '../members/Payment.js';
2
+ import { OrganizationSimple } from '../OrganizationSimple.js';
3
+ import { STInvoice } from './STInvoice.js';
4
+ export declare class STInvoicePrivate extends STInvoice {
5
+ organization?: OrganizationSimple;
6
+ settlement: Settlement | null;
7
+ reference: string | null;
8
+ matchQuery(query: string): boolean;
9
+ }
10
+ //# sourceMappingURL=STInvoicePrivate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STInvoicePrivate.d.ts","sourceRoot":"","sources":["../../../../src/billing/STInvoicePrivate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,qBAAa,gBAAiB,SAAQ,SAAS;IAE3C,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAGlC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAQ;IAGrC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEhC,UAAU,CAAC,KAAK,EAAE,MAAM;CA8B3B"}
@@ -0,0 +1,47 @@
1
+ import { __decorate } from "tslib";
2
+ import { field, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import { StringCompare } from '@stamhoofd/utility';
4
+ import { Settlement } from '../members/Payment.js';
5
+ import { OrganizationSimple } from '../OrganizationSimple.js';
6
+ import { STInvoice } from './STInvoice.js';
7
+ export class STInvoicePrivate extends STInvoice {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.settlement = null;
11
+ this.reference = null;
12
+ }
13
+ matchQuery(query) {
14
+ var _a;
15
+ if (query === ((_a = this.number) === null || _a === void 0 ? void 0 : _a.toString()) || query === this.id) {
16
+ return true;
17
+ }
18
+ if (StringCompare.contains(this.meta.companyName, query)
19
+ || StringCompare.typoCount(this.meta.companyAddress.city, query) < 2
20
+ || StringCompare.contains(this.meta.companyContact, query)
21
+ || (this.meta.companyVATNumber && StringCompare.typoCount(this.meta.companyVATNumber, query) < 2)
22
+ || StringCompare.typoCount(this.meta.companyAddress.street, query) < 2) {
23
+ return true;
24
+ }
25
+ if (!this.organization) {
26
+ return false;
27
+ }
28
+ if (StringCompare.typoCount(this.organization.name, query) < 2
29
+ || StringCompare.typoCount(this.organization.address.city, query) < 2
30
+ || StringCompare.typoCount(this.organization.address.street, query) < 2
31
+ || StringCompare.typoCount(this.meta.companyName, query) < 2
32
+ || StringCompare.typoCount(this.meta.companyName, query) < 2) {
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ }
38
+ __decorate([
39
+ field({ decoder: OrganizationSimple, optional: true })
40
+ ], STInvoicePrivate.prototype, "organization", void 0);
41
+ __decorate([
42
+ field({ decoder: Settlement, nullable: true })
43
+ ], STInvoicePrivate.prototype, "settlement", void 0);
44
+ __decorate([
45
+ field({ decoder: StringDecoder, nullable: true, version: 186 })
46
+ ], STInvoicePrivate.prototype, "reference", void 0);
47
+ //# sourceMappingURL=STInvoicePrivate.js.map
@@ -0,0 +1 @@
1
+ {"version":3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C,IAAI,CAAC,YAAY,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IACI,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;eACvD,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;eAClE,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC;eACpE,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC;eACzD,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,EAC9D,CAAC;YACC,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAtCG;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sDACrB;AAGlC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;oDACV;AAGrC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;mDAChC"}
@@ -0,0 +1,7 @@
1
+ export declare enum STInvoiceStatus {
2
+ Created = "Created",
3
+ Prepared = "Prepared",
4
+ Completed = "Completed",
5
+ Canceled = "Canceled"
6
+ }
7
+ //# sourceMappingURL=STInvoiceStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STInvoiceStatus.d.ts","sourceRoot":"","sources":["../../../../src/billing/STInvoiceStatus.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,QAAQ,aAAa;CACxB"}
@@ -0,0 +1,8 @@
1
+ export var STInvoiceStatus;
2
+ (function (STInvoiceStatus) {
3
+ STInvoiceStatus["Created"] = "Created";
4
+ STInvoiceStatus["Prepared"] = "Prepared";
5
+ STInvoiceStatus["Completed"] = "Completed";
6
+ STInvoiceStatus["Canceled"] = "Canceled";
7
+ })(STInvoiceStatus || (STInvoiceStatus = {}));
8
+ //# sourceMappingURL=STInvoiceStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STInvoiceStatus.js","sourceRoot":"","sources":["../../../../src/billing/STInvoiceStatus.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACvB,sCAAmB,CAAA;IACnB,wCAAqB,CAAA;IACrB,0CAAuB,CAAA;IACvB,wCAAqB,CAAA;AACzB,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B"}
@@ -0,0 +1,15 @@
1
+ import { AutoEncoder } from '@simonbackx/simple-encoding';
2
+ import { OrganizationSimple } from '../OrganizationSimple.js';
3
+ import { STInvoice } from './STInvoice.js';
4
+ import { STInvoiceMeta } from './STInvoiceMeta.js';
5
+ export declare class STPendingInvoice extends AutoEncoder {
6
+ id: string | null;
7
+ meta: STInvoiceMeta;
8
+ invoice: STInvoice | null;
9
+ createdAt: Date | null;
10
+ updatedAt: Date | null;
11
+ }
12
+ export declare class STPendingInvoicePrivate extends STPendingInvoice {
13
+ organization?: OrganizationSimple;
14
+ }
15
+ //# sourceMappingURL=STPendingInvoice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STPendingInvoice.d.ts","sourceRoot":"","sources":["../../../../src/billing/STPendingInvoice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqC,MAAM,6BAA6B,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAa,gBAAiB,SAAQ,WAAW;IAE7C,EAAE,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGzB,IAAI,EAAE,aAAa,CAAC;IAGpB,OAAO,EAAE,SAAS,GAAG,IAAI,CAAQ;IAGjC,SAAS,EAAE,IAAI,GAAG,IAAI,CAAQ;IAG9B,SAAS,EAAE,IAAI,GAAG,IAAI,CAAQ;CACjC;AAED,qBAAa,uBAAwB,SAAQ,gBAAgB;IAEzD,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACrC"}
@@ -0,0 +1,35 @@
1
+ import { __decorate } from "tslib";
2
+ import { AutoEncoder, DateDecoder, field, StringDecoder } from '@simonbackx/simple-encoding';
3
+ import { OrganizationSimple } from '../OrganizationSimple.js';
4
+ import { STInvoice } from './STInvoice.js';
5
+ import { STInvoiceMeta } from './STInvoiceMeta.js';
6
+ export class STPendingInvoice extends AutoEncoder {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.id = null;
10
+ this.invoice = null;
11
+ this.createdAt = null;
12
+ this.updatedAt = null;
13
+ }
14
+ }
15
+ __decorate([
16
+ field({ decoder: StringDecoder, nullable: true, optional: true })
17
+ ], STPendingInvoice.prototype, "id", void 0);
18
+ __decorate([
19
+ field({ decoder: STInvoiceMeta })
20
+ ], STPendingInvoice.prototype, "meta", void 0);
21
+ __decorate([
22
+ field({ decoder: STInvoice, nullable: true })
23
+ ], STPendingInvoice.prototype, "invoice", void 0);
24
+ __decorate([
25
+ field({ decoder: DateDecoder, nullable: true })
26
+ ], STPendingInvoice.prototype, "createdAt", void 0);
27
+ __decorate([
28
+ field({ decoder: DateDecoder, nullable: true })
29
+ ], STPendingInvoice.prototype, "updatedAt", void 0);
30
+ export class STPendingInvoicePrivate extends STPendingInvoice {
31
+ }
32
+ __decorate([
33
+ field({ decoder: OrganizationSimple, optional: true })
34
+ ], STPendingInvoicePrivate.prototype, "organization", void 0);
35
+ //# sourceMappingURL=STPendingInvoice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STPendingInvoice.js","sourceRoot":"","sources":["../../../../src/billing/STPendingInvoice.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAAjD;;QAEI,OAAE,GAAkB,IAAI,CAAC;QAMzB,YAAO,GAAqB,IAAI,CAAC;QAGjC,cAAS,GAAgB,IAAI,CAAC;QAG9B,cAAS,GAAgB,IAAI,CAAC;IAClC,CAAC;CAAA;AAbG;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;4CACzC;AAGzB;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;8CACd;AAGpB;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;iDACb;AAGjC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;mDAClB;AAG9B;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;mDAClB;AAGlC,MAAM,OAAO,uBAAwB,SAAQ,gBAAgB;CAG5D;AADG;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;6DACrB"}
@@ -2,9 +2,14 @@ export * from './OrganizationPaymentMandate.js';
2
2
  export * from './STBillingStatus.js';
3
3
  export * from './STCredit.js';
4
4
  export * from './STInvoice.js';
5
+ export * from './STInvoiceMeta.js';
6
+ export * from './STInvoiceItem.js';
7
+ export * from './STInvoiceStatus.js';
8
+ export * from './STInvoicePrivate.js';
5
9
  export * from './STPackage.js';
6
10
  export * from './STPackageBundle.js';
7
11
  export * from './OrganizationPackagesStatus.js';
12
+ export * from './STPendingInvoice.js';
8
13
  export * from './Invoice.js';
9
14
  export * from './InvoicedBalanceItem.js';
10
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/billing/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAEhD,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/billing/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AAEtC,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}
@@ -2,9 +2,14 @@ export * from './OrganizationPaymentMandate.js';
2
2
  export * from './STBillingStatus.js';
3
3
  export * from './STCredit.js';
4
4
  export * from './STInvoice.js';
5
+ export * from './STInvoiceMeta.js';
6
+ export * from './STInvoiceItem.js';
7
+ export * from './STInvoiceStatus.js';
8
+ export * from './STInvoicePrivate.js';
5
9
  export * from './STPackage.js';
6
10
  export * from './STPackageBundle.js';
7
11
  export * from './OrganizationPackagesStatus.js';
12
+ export * from './STPendingInvoice.js';
8
13
  export * from './Invoice.js';
9
14
  export * from './InvoicedBalanceItem.js';
10
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/billing/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAEhD,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/billing/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AAEtC,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC"}