@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.
- package/dist/src/BalanceItem.d.ts +5 -0
- package/dist/src/BalanceItem.d.ts.map +1 -1
- package/dist/src/BalanceItem.js +10 -1
- package/dist/src/BalanceItem.js.map +1 -1
- package/dist/src/Document.d.ts +1 -0
- package/dist/src/Document.d.ts.map +1 -1
- package/dist/src/Document.js +3 -0
- package/dist/src/Document.js.map +1 -1
- package/dist/src/GenericBalance.d.ts.map +1 -1
- package/dist/src/GenericBalance.js +2 -1
- package/dist/src/GenericBalance.js.map +1 -1
- package/dist/src/GroupType.d.ts +1 -0
- package/dist/src/GroupType.d.ts.map +1 -1
- package/dist/src/GroupType.js +11 -0
- package/dist/src/GroupType.js.map +1 -1
- package/dist/src/Version.d.ts +1 -1
- package/dist/src/Version.js +1 -1
- package/dist/src/billing/Invoice.d.ts +51 -4
- package/dist/src/billing/Invoice.d.ts.map +1 -1
- package/dist/src/billing/Invoice.js +119 -2
- package/dist/src/billing/Invoice.js.map +1 -1
- package/dist/src/billing/InvoicedBalanceItem.d.ts +35 -6
- package/dist/src/billing/InvoicedBalanceItem.d.ts.map +1 -1
- package/dist/src/billing/InvoicedBalanceItem.js +79 -12
- package/dist/src/billing/InvoicedBalanceItem.js.map +1 -1
- package/dist/src/billing/InvoicedBalanceItem.test.d.ts +2 -0
- package/dist/src/billing/InvoicedBalanceItem.test.d.ts.map +1 -0
- package/dist/src/billing/InvoicedBalanceItem.test.js +195 -0
- package/dist/src/billing/InvoicedBalanceItem.test.js.map +1 -0
- package/dist/src/billing/STBillingStatus.d.ts +2 -1
- package/dist/src/billing/STBillingStatus.d.ts.map +1 -1
- package/dist/src/billing/STBillingStatus.js +2 -1
- package/dist/src/billing/STBillingStatus.js.map +1 -1
- package/dist/src/billing/STInvoice.d.ts +2 -125
- package/dist/src/billing/STInvoice.d.ts.map +1 -1
- package/dist/src/billing/STInvoice.js +3 -400
- package/dist/src/billing/STInvoice.js.map +1 -1
- package/dist/src/billing/STInvoiceItem.d.ts +32 -0
- package/dist/src/billing/STInvoiceItem.d.ts.map +1 -0
- package/dist/src/billing/STInvoiceItem.js +169 -0
- package/dist/src/billing/STInvoiceItem.js.map +1 -0
- package/dist/src/billing/STInvoiceMeta.d.ts +63 -0
- package/dist/src/billing/STInvoiceMeta.d.ts.map +1 -0
- package/dist/src/billing/STInvoiceMeta.js +152 -0
- package/dist/src/billing/STInvoiceMeta.js.map +1 -0
- package/dist/src/billing/STInvoicePrivate.d.ts +10 -0
- package/dist/src/billing/STInvoicePrivate.d.ts.map +1 -0
- package/dist/src/billing/STInvoicePrivate.js +51 -0
- package/dist/src/billing/STInvoicePrivate.js.map +1 -0
- package/dist/src/billing/STInvoiceStatus.d.ts +7 -0
- package/dist/src/billing/STInvoiceStatus.d.ts.map +1 -0
- package/dist/src/billing/STInvoiceStatus.js +11 -0
- package/dist/src/billing/STInvoiceStatus.js.map +1 -0
- package/dist/src/billing/STPendingInvoice.d.ts +15 -0
- package/dist/src/billing/STPendingInvoice.d.ts.map +1 -0
- package/dist/src/billing/STPendingInvoice.js +40 -0
- package/dist/src/billing/STPendingInvoice.js.map +1 -0
- package/dist/src/billing/index.d.ts +5 -0
- package/dist/src/billing/index.d.ts.map +1 -1
- package/dist/src/billing/index.js +5 -0
- package/dist/src/billing/index.js.map +1 -1
- package/dist/src/email/EmailTemplate.js +2 -2
- package/dist/src/email/EmailTemplate.js.map +1 -1
- package/dist/src/members/Registration.d.ts +1 -0
- package/dist/src/members/Registration.d.ts.map +1 -1
- package/dist/src/members/Registration.js +4 -0
- package/dist/src/members/Registration.js.map +1 -1
- package/dist/src/members/checkout/RegisterItem.d.ts +5 -0
- package/dist/src/members/checkout/RegisterItem.d.ts.map +1 -1
- package/dist/src/members/checkout/RegisterItem.js +60 -5
- package/dist/src/members/checkout/RegisterItem.js.map +1 -1
- package/dist/src/webshops/Checkout.d.ts.map +1 -1
- package/dist/src/webshops/Checkout.js +10 -1
- package/dist/src/webshops/Checkout.js.map +1 -1
- package/esm/dist/src/BalanceItem.d.ts +5 -0
- package/esm/dist/src/BalanceItem.d.ts.map +1 -1
- package/esm/dist/src/BalanceItem.js +10 -1
- package/esm/dist/src/BalanceItem.js.map +1 -1
- package/esm/dist/src/Document.d.ts +1 -0
- package/esm/dist/src/Document.d.ts.map +1 -1
- package/esm/dist/src/Document.js +3 -0
- package/esm/dist/src/Document.js.map +1 -1
- package/esm/dist/src/GenericBalance.d.ts.map +1 -1
- package/esm/dist/src/GenericBalance.js +2 -1
- package/esm/dist/src/GenericBalance.js.map +1 -1
- package/esm/dist/src/GroupType.d.ts +1 -0
- package/esm/dist/src/GroupType.d.ts.map +1 -1
- package/esm/dist/src/GroupType.js +10 -0
- package/esm/dist/src/GroupType.js.map +1 -1
- package/esm/dist/src/Version.d.ts +1 -1
- package/esm/dist/src/Version.js +1 -1
- package/esm/dist/src/billing/Invoice.d.ts +51 -4
- package/esm/dist/src/billing/Invoice.d.ts.map +1 -1
- package/esm/dist/src/billing/Invoice.js +118 -2
- package/esm/dist/src/billing/Invoice.js.map +1 -1
- package/esm/dist/src/billing/InvoicedBalanceItem.d.ts +35 -6
- package/esm/dist/src/billing/InvoicedBalanceItem.d.ts.map +1 -1
- package/esm/dist/src/billing/InvoicedBalanceItem.js +79 -12
- package/esm/dist/src/billing/InvoicedBalanceItem.js.map +1 -1
- package/esm/dist/src/billing/STBillingStatus.d.ts +2 -1
- package/esm/dist/src/billing/STBillingStatus.d.ts.map +1 -1
- package/esm/dist/src/billing/STBillingStatus.js +2 -1
- package/esm/dist/src/billing/STBillingStatus.js.map +1 -1
- package/esm/dist/src/billing/STInvoice.d.ts +2 -125
- package/esm/dist/src/billing/STInvoice.d.ts.map +1 -1
- package/esm/dist/src/billing/STInvoice.js +3 -394
- package/esm/dist/src/billing/STInvoice.js.map +1 -1
- package/esm/dist/src/billing/STInvoiceItem.d.ts +32 -0
- package/esm/dist/src/billing/STInvoiceItem.d.ts.map +1 -0
- package/esm/dist/src/billing/STInvoiceItem.js +165 -0
- package/esm/dist/src/billing/STInvoiceItem.js.map +1 -0
- package/esm/dist/src/billing/STInvoiceMeta.d.ts +63 -0
- package/esm/dist/src/billing/STInvoiceMeta.d.ts.map +1 -0
- package/esm/dist/src/billing/STInvoiceMeta.js +148 -0
- package/esm/dist/src/billing/STInvoiceMeta.js.map +1 -0
- package/esm/dist/src/billing/STInvoicePrivate.d.ts +10 -0
- package/esm/dist/src/billing/STInvoicePrivate.d.ts.map +1 -0
- package/esm/dist/src/billing/STInvoicePrivate.js +47 -0
- package/esm/dist/src/billing/STInvoicePrivate.js.map +1 -0
- package/esm/dist/src/billing/STInvoiceStatus.d.ts +7 -0
- package/esm/dist/src/billing/STInvoiceStatus.d.ts.map +1 -0
- package/esm/dist/src/billing/STInvoiceStatus.js +8 -0
- package/esm/dist/src/billing/STInvoiceStatus.js.map +1 -0
- package/esm/dist/src/billing/STPendingInvoice.d.ts +15 -0
- package/esm/dist/src/billing/STPendingInvoice.d.ts.map +1 -0
- package/esm/dist/src/billing/STPendingInvoice.js +35 -0
- package/esm/dist/src/billing/STPendingInvoice.js.map +1 -0
- package/esm/dist/src/billing/index.d.ts +5 -0
- package/esm/dist/src/billing/index.d.ts.map +1 -1
- package/esm/dist/src/billing/index.js +5 -0
- package/esm/dist/src/billing/index.js.map +1 -1
- package/esm/dist/src/email/EmailTemplate.js +2 -2
- package/esm/dist/src/email/EmailTemplate.js.map +1 -1
- package/esm/dist/src/members/Registration.d.ts +1 -0
- package/esm/dist/src/members/Registration.d.ts.map +1 -1
- package/esm/dist/src/members/Registration.js +4 -0
- package/esm/dist/src/members/Registration.js.map +1 -1
- package/esm/dist/src/members/checkout/RegisterItem.d.ts +5 -0
- package/esm/dist/src/members/checkout/RegisterItem.d.ts.map +1 -1
- package/esm/dist/src/members/checkout/RegisterItem.js +60 -5
- package/esm/dist/src/members/checkout/RegisterItem.js.map +1 -1
- package/esm/dist/src/webshops/Checkout.d.ts.map +1 -1
- package/esm/dist/src/webshops/Checkout.js +10 -1
- package/esm/dist/src/webshops/Checkout.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,319 +1,8 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
import { Formatter, StringCompare } from '@stamhoofd/utility';
|
|
2
|
+
import { AutoEncoder, BooleanDecoder, DateDecoder, field, IntegerDecoder, StringDecoder } from '@simonbackx/simple-encoding';
|
|
4
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Payment, Settlement } from '../members/Payment.js';
|
|
8
|
-
import { OrganizationSimple } from '../OrganizationSimple.js';
|
|
9
|
-
import { STPackage, STPricingType } from './STPackage.js';
|
|
10
|
-
import { upgradePriceFrom2To4DecimalPlaces } from '../upgradePriceFrom2To4DecimalPlaces.js';
|
|
11
|
-
export var STInvoiceStatus;
|
|
12
|
-
(function (STInvoiceStatus) {
|
|
13
|
-
STInvoiceStatus["Created"] = "Created";
|
|
14
|
-
STInvoiceStatus["Prepared"] = "Prepared";
|
|
15
|
-
STInvoiceStatus["Completed"] = "Completed";
|
|
16
|
-
STInvoiceStatus["Canceled"] = "Canceled";
|
|
17
|
-
})(STInvoiceStatus || (STInvoiceStatus = {}));
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated use Invoice
|
|
20
|
-
*/
|
|
21
|
-
export class STInvoiceItem extends AutoEncoder {
|
|
22
|
-
constructor() {
|
|
23
|
-
super(...arguments);
|
|
24
|
-
this.name = '';
|
|
25
|
-
this.description = '';
|
|
26
|
-
this.amount = 1;
|
|
27
|
-
this.unitPrice = 0;
|
|
28
|
-
this.canUseCredits = true;
|
|
29
|
-
this.firstFailedPayment = null;
|
|
30
|
-
this.paymentFailedCount = 0;
|
|
31
|
-
}
|
|
32
|
-
get price() {
|
|
33
|
-
return this.unitPrice * this.amount;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Convertable into STInvoiceItem (or the diffence if amount is increased)
|
|
37
|
-
* Use this to calculate prices or create an invoice
|
|
38
|
-
* This will calculate the price to expand the package to the given amount.
|
|
39
|
-
* If you want to renew a package, you need to create a new package first
|
|
40
|
-
*/
|
|
41
|
-
static fromPackage(pack, amount = 1, pendingAmount = 0, date) {
|
|
42
|
-
let unitPrice = Math.round(pack.meta.unitPrice);
|
|
43
|
-
if (amount < pack.meta.minimumAmount) {
|
|
44
|
-
// Minimum should get applied first, because we might already have paid for the minimum (paid amount)
|
|
45
|
-
amount = pack.meta.minimumAmount;
|
|
46
|
-
}
|
|
47
|
-
amount -= pendingAmount;
|
|
48
|
-
amount -= pack.meta.paidAmount;
|
|
49
|
-
if (amount <= 0) {
|
|
50
|
-
amount = 0;
|
|
51
|
-
}
|
|
52
|
-
/// When pricing type is memebrs, the price is calculated per year.
|
|
53
|
-
/// If a shorter period is remaining, we give a discount in order
|
|
54
|
-
/// to no need to handle it more complicated
|
|
55
|
-
let now = date !== null && date !== void 0 ? date : new Date();
|
|
56
|
-
if (now < pack.meta.startDate) {
|
|
57
|
-
// When creating a new package, we sometimes buy it for the future, so use that date instead of now
|
|
58
|
-
now = pack.meta.startDate;
|
|
59
|
-
}
|
|
60
|
-
if (pack.validUntil && pack.meta.pricingType !== STPricingType.Fixed) {
|
|
61
|
-
const totalDays = Math.round((pack.validUntil.getTime() - pack.meta.startDate.getTime()) / (1000 * 60 * 60 * 24));
|
|
62
|
-
let remainingDays = Math.round((pack.validUntil.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
|
|
63
|
-
/// First 3 months are full price
|
|
64
|
-
const paidDays = 30 * 3;
|
|
65
|
-
if (remainingDays > totalDays) {
|
|
66
|
-
remainingDays = totalDays;
|
|
67
|
-
}
|
|
68
|
-
if (totalDays > 366) {
|
|
69
|
-
// Increase unit price
|
|
70
|
-
unitPrice = unitPrice * (totalDays / 365);
|
|
71
|
-
}
|
|
72
|
-
if (pack.meta.pricingType === STPricingType.PerMember) {
|
|
73
|
-
unitPrice = Math.round(Math.min(unitPrice, unitPrice * remainingDays / (Math.max(365, totalDays) - paidDays)));
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
unitPrice = Math.round(unitPrice);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const item = STInvoiceItem.create({
|
|
80
|
-
name: pack.meta.name,
|
|
81
|
-
description: pack.validUntil ? ('Van ' + Formatter.date(now, true) + ' tot ' + Formatter.date(pack.validUntil, true)) : ('Vanaf ' + Formatter.date(pack.meta.startDate, true)),
|
|
82
|
-
package: pack,
|
|
83
|
-
date: now,
|
|
84
|
-
unitPrice: unitPrice,
|
|
85
|
-
amount: amount,
|
|
86
|
-
});
|
|
87
|
-
return item;
|
|
88
|
-
}
|
|
89
|
-
canMerge(other) {
|
|
90
|
-
// Mergeable if both don't have a packege, or both have the same package
|
|
91
|
-
if (other.package && !this.package) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
if (!other.package && this.package) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
if (other.package && this.package && other.package.id !== this.package.id) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
if (this.name === other.name && this.description === other.description) {
|
|
101
|
-
if (this.unitPrice === other.unitPrice) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
if (this.amount === 1 && other.amount === 1) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
merge(other) {
|
|
111
|
-
if (other.paymentFailedCount > this.paymentFailedCount) {
|
|
112
|
-
this.paymentFailedCount = other.paymentFailedCount;
|
|
113
|
-
}
|
|
114
|
-
if (other.firstFailedPayment && (!this.firstFailedPayment || other.firstFailedPayment < this.firstFailedPayment)) {
|
|
115
|
-
this.firstFailedPayment = other.firstFailedPayment;
|
|
116
|
-
}
|
|
117
|
-
if (other.unitPrice !== this.unitPrice) {
|
|
118
|
-
if (other.amount === 1 && this.amount === 1) {
|
|
119
|
-
this.unitPrice += other.unitPrice;
|
|
120
|
-
this.package = other.package;
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
throw new Error('Cannot merge items with different unit prices and amount greater than 1');
|
|
124
|
-
}
|
|
125
|
-
this.amount += other.amount;
|
|
126
|
-
}
|
|
127
|
-
/// Only compress an invoice when it is marked as paid and for a pending invoice when it doesn't has an invoice
|
|
128
|
-
/// Else you'll lose the ID's!
|
|
129
|
-
static compress(items) {
|
|
130
|
-
const copy = items.slice();
|
|
131
|
-
for (let index = 0; index < copy.length; index++) {
|
|
132
|
-
// Create a copy to prevent changing the original one
|
|
133
|
-
const item = STInvoiceItem.create(copy[index]);
|
|
134
|
-
copy[index] = item;
|
|
135
|
-
// Loop further (in reverse order to be able to delete items)
|
|
136
|
-
for (let j = copy.length - 1; j > index; j--) {
|
|
137
|
-
const other = copy[j];
|
|
138
|
-
if (item.canMerge(other)) {
|
|
139
|
-
// Delete other
|
|
140
|
-
item.merge(other);
|
|
141
|
-
copy.splice(j, 1);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return copy;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
__decorate([
|
|
149
|
-
field({ decoder: StringDecoder, defaultValue: () => uuidv4() })
|
|
150
|
-
], STInvoiceItem.prototype, "id", void 0);
|
|
151
|
-
__decorate([
|
|
152
|
-
field({ decoder: StringDecoder })
|
|
153
|
-
], STInvoiceItem.prototype, "name", void 0);
|
|
154
|
-
__decorate([
|
|
155
|
-
field({ decoder: StringDecoder })
|
|
156
|
-
], STInvoiceItem.prototype, "description", void 0);
|
|
157
|
-
__decorate([
|
|
158
|
-
field({ decoder: IntegerDecoder })
|
|
159
|
-
], STInvoiceItem.prototype, "amount", void 0);
|
|
160
|
-
__decorate([
|
|
161
|
-
field({ decoder: IntegerDecoder }),
|
|
162
|
-
field({ ...upgradePriceFrom2To4DecimalPlaces })
|
|
163
|
-
], STInvoiceItem.prototype, "unitPrice", void 0);
|
|
164
|
-
__decorate([
|
|
165
|
-
field({ decoder: BooleanDecoder, version: 155 })
|
|
166
|
-
], STInvoiceItem.prototype, "canUseCredits", void 0);
|
|
167
|
-
__decorate([
|
|
168
|
-
field({ decoder: DateDecoder, nullable: true, optional: true })
|
|
169
|
-
], STInvoiceItem.prototype, "firstFailedPayment", void 0);
|
|
170
|
-
__decorate([
|
|
171
|
-
field({ decoder: IntegerDecoder, optional: true })
|
|
172
|
-
], STInvoiceItem.prototype, "paymentFailedCount", void 0);
|
|
173
|
-
__decorate([
|
|
174
|
-
field({ decoder: STPackage, optional: true })
|
|
175
|
-
], STInvoiceItem.prototype, "package", void 0);
|
|
176
|
-
__decorate([
|
|
177
|
-
field({ decoder: DateDecoder, optional: true })
|
|
178
|
-
], STInvoiceItem.prototype, "date", void 0);
|
|
179
|
-
/**
|
|
180
|
-
* @deprecated use Invoice
|
|
181
|
-
*/
|
|
182
|
-
export class STInvoiceMeta extends AutoEncoder {
|
|
183
|
-
constructor() {
|
|
184
|
-
super(...arguments);
|
|
185
|
-
/**
|
|
186
|
-
* VATPercentage should be zero in countries outside Belgium in EU
|
|
187
|
-
*/
|
|
188
|
-
this.VATPercentage = 21;
|
|
189
|
-
this.items = [];
|
|
190
|
-
/**
|
|
191
|
-
* Sometimes we need to calculate an invoice in reverse when we have a fixed price including VAT,
|
|
192
|
-
* but need to calculatle the price excluding VAT.
|
|
193
|
-
*/
|
|
194
|
-
this.areItemsIncludingVAT = false;
|
|
195
|
-
this.companyVATNumber = null;
|
|
196
|
-
this.companyNumber = null;
|
|
197
|
-
this.ipAddress = null;
|
|
198
|
-
this.userAgent = null;
|
|
199
|
-
this.stripeAccountId = null;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* @deprecated
|
|
203
|
-
* Depending on areItemsIncludingVAT, this can either be including or excluding VAT
|
|
204
|
-
*/
|
|
205
|
-
get itemPrice() {
|
|
206
|
-
return this.items.reduce((price, item) => price + item.price, 0);
|
|
207
|
-
}
|
|
208
|
-
includingVATToExcludingVAT(price) {
|
|
209
|
-
// Always only round the VAT, not other prices
|
|
210
|
-
return price - this.getVATOnIncludingVATAmount(price);
|
|
211
|
-
}
|
|
212
|
-
excludingVATToIncludingVAT(price) {
|
|
213
|
-
// Always only round the VAT, not other prices
|
|
214
|
-
return price + this.getVATOnExcludingVATAmount(price);
|
|
215
|
-
}
|
|
216
|
-
getVATOnIncludingVATAmount(price) {
|
|
217
|
-
return Math.round(price * this.VATPercentage / (100 + this.VATPercentage));
|
|
218
|
-
}
|
|
219
|
-
getVATOnExcludingVATAmount(price) {
|
|
220
|
-
// Make sure price result doesn't depend on the sign of the price
|
|
221
|
-
return Math.round(Math.abs(price) * this.VATPercentage / 100) * Math.sign(price);
|
|
222
|
-
}
|
|
223
|
-
get useLegacyRounding() {
|
|
224
|
-
// In the past we didn't round the price without VAT if we calculated starting from a price inclusive VAT
|
|
225
|
-
// in that case, we only rounded the VAT
|
|
226
|
-
// todo: based on number!
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
get priceWithoutVAT() {
|
|
230
|
-
if (this.useLegacyRounding) {
|
|
231
|
-
const itemPrice = this.itemPrice;
|
|
232
|
-
if (this.areItemsIncludingVAT) {
|
|
233
|
-
return itemPrice - this.VAT;
|
|
234
|
-
}
|
|
235
|
-
return itemPrice;
|
|
236
|
-
}
|
|
237
|
-
if (this.areItemsIncludingVAT) {
|
|
238
|
-
// We round at individual item level
|
|
239
|
-
// because PEPPOL requires prices with max 2 decimals on every line level, meaning we need to round.
|
|
240
|
-
return this.items.reduce((price, item) => price + this.includingVATToExcludingVAT(item.price), 0);
|
|
241
|
-
}
|
|
242
|
-
return this.items.reduce((price, item) => price + item.price, 0);
|
|
243
|
-
}
|
|
244
|
-
get VAT() {
|
|
245
|
-
if (this.useLegacyRounding && this.areItemsIncludingVAT) {
|
|
246
|
-
// Subtract VAT and round
|
|
247
|
-
// Need to be careful with circular calls
|
|
248
|
-
return this.getVATOnIncludingVATAmount(this.itemPrice);
|
|
249
|
-
}
|
|
250
|
-
return this.getVATOnExcludingVATAmount(this.priceWithoutVAT);
|
|
251
|
-
}
|
|
252
|
-
get priceWithVAT() {
|
|
253
|
-
return this.priceWithoutVAT + this.VAT;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* 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.
|
|
257
|
-
*
|
|
258
|
-
* 1 cent if we need to add 1 cent
|
|
259
|
-
* -1 cent if we need to remove 1 cent from the priceWithVAT to get to the payable amount
|
|
260
|
-
*/
|
|
261
|
-
get payableRoundingAmount() {
|
|
262
|
-
return this.totalPrice - this.priceWithVAT;
|
|
263
|
-
}
|
|
264
|
-
get totalPrice() {
|
|
265
|
-
const itemPrice = this.itemPrice;
|
|
266
|
-
if (this.areItemsIncludingVAT) {
|
|
267
|
-
return itemPrice;
|
|
268
|
-
}
|
|
269
|
-
return itemPrice + this.VAT;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
__decorate([
|
|
273
|
-
field({ decoder: DateDecoder, optional: true })
|
|
274
|
-
], STInvoiceMeta.prototype, "date", void 0);
|
|
275
|
-
__decorate([
|
|
276
|
-
field({ decoder: File, optional: true })
|
|
277
|
-
], STInvoiceMeta.prototype, "pdf", void 0);
|
|
278
|
-
__decorate([
|
|
279
|
-
field({ decoder: File, optional: true })
|
|
280
|
-
], STInvoiceMeta.prototype, "xml", void 0);
|
|
281
|
-
__decorate([
|
|
282
|
-
field({ decoder: IntegerDecoder })
|
|
283
|
-
], STInvoiceMeta.prototype, "VATPercentage", void 0);
|
|
284
|
-
__decorate([
|
|
285
|
-
field({ decoder: new ArrayDecoder(STInvoiceItem) })
|
|
286
|
-
], STInvoiceMeta.prototype, "items", void 0);
|
|
287
|
-
__decorate([
|
|
288
|
-
field({ decoder: BooleanDecoder, version: 186 })
|
|
289
|
-
], STInvoiceMeta.prototype, "areItemsIncludingVAT", void 0);
|
|
290
|
-
__decorate([
|
|
291
|
-
field({ decoder: StringDecoder })
|
|
292
|
-
], STInvoiceMeta.prototype, "companyName", void 0);
|
|
293
|
-
__decorate([
|
|
294
|
-
field({ decoder: StringDecoder })
|
|
295
|
-
], STInvoiceMeta.prototype, "companyContact", void 0);
|
|
296
|
-
__decorate([
|
|
297
|
-
field({ decoder: Address })
|
|
298
|
-
], STInvoiceMeta.prototype, "companyAddress", void 0);
|
|
299
|
-
__decorate([
|
|
300
|
-
field({ decoder: StringDecoder, nullable: true })
|
|
301
|
-
], STInvoiceMeta.prototype, "companyVATNumber", void 0);
|
|
302
|
-
__decorate([
|
|
303
|
-
field({ decoder: StringDecoder, nullable: true, optional: true })
|
|
304
|
-
], STInvoiceMeta.prototype, "companyNumber", void 0);
|
|
305
|
-
__decorate([
|
|
306
|
-
field({ decoder: StringDecoder, nullable: true, version: 133 })
|
|
307
|
-
], STInvoiceMeta.prototype, "ipAddress", void 0);
|
|
308
|
-
__decorate([
|
|
309
|
-
field({ decoder: StringDecoder, nullable: true, version: 133 })
|
|
310
|
-
], STInvoiceMeta.prototype, "userAgent", void 0);
|
|
311
|
-
__decorate([
|
|
312
|
-
field({ decoder: StringDecoder, nullable: true, version: 210 })
|
|
313
|
-
], STInvoiceMeta.prototype, "stripeAccountId", void 0);
|
|
314
|
-
/**
|
|
315
|
-
* @deprecated use Invoice
|
|
316
|
-
*/
|
|
4
|
+
import { Payment } from '../members/Payment.js';
|
|
5
|
+
import { STInvoiceMeta } from './STInvoiceMeta.js';
|
|
317
6
|
export class STInvoice extends AutoEncoder {
|
|
318
7
|
constructor() {
|
|
319
8
|
super(...arguments);
|
|
@@ -356,84 +45,4 @@ __decorate([
|
|
|
356
45
|
__decorate([
|
|
357
46
|
field({ decoder: BooleanDecoder, optional: true })
|
|
358
47
|
], STInvoice.prototype, "didSendPeppol", void 0);
|
|
359
|
-
/**
|
|
360
|
-
* @deprecated use Invoice
|
|
361
|
-
*/
|
|
362
|
-
export class STInvoicePrivate extends STInvoice {
|
|
363
|
-
constructor() {
|
|
364
|
-
super(...arguments);
|
|
365
|
-
this.settlement = null;
|
|
366
|
-
this.reference = null;
|
|
367
|
-
}
|
|
368
|
-
matchQuery(query) {
|
|
369
|
-
var _a;
|
|
370
|
-
if (query === ((_a = this.number) === null || _a === void 0 ? void 0 : _a.toString()) || query === this.id) {
|
|
371
|
-
return true;
|
|
372
|
-
}
|
|
373
|
-
if (StringCompare.contains(this.meta.companyName, query)
|
|
374
|
-
|| StringCompare.typoCount(this.meta.companyAddress.city, query) < 2
|
|
375
|
-
|| StringCompare.contains(this.meta.companyContact, query)
|
|
376
|
-
|| (this.meta.companyVATNumber && StringCompare.typoCount(this.meta.companyVATNumber, query) < 2)
|
|
377
|
-
|| StringCompare.typoCount(this.meta.companyAddress.street, query) < 2) {
|
|
378
|
-
return true;
|
|
379
|
-
}
|
|
380
|
-
if (!this.organization) {
|
|
381
|
-
return false;
|
|
382
|
-
}
|
|
383
|
-
if (StringCompare.typoCount(this.organization.name, query) < 2
|
|
384
|
-
|| StringCompare.typoCount(this.organization.address.city, query) < 2
|
|
385
|
-
|| StringCompare.typoCount(this.organization.address.street, query) < 2
|
|
386
|
-
|| StringCompare.typoCount(this.meta.companyName, query) < 2
|
|
387
|
-
|| StringCompare.typoCount(this.meta.companyName, query) < 2) {
|
|
388
|
-
return true;
|
|
389
|
-
}
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
__decorate([
|
|
394
|
-
field({ decoder: OrganizationSimple, optional: true })
|
|
395
|
-
], STInvoicePrivate.prototype, "organization", void 0);
|
|
396
|
-
__decorate([
|
|
397
|
-
field({ decoder: Settlement, nullable: true })
|
|
398
|
-
], STInvoicePrivate.prototype, "settlement", void 0);
|
|
399
|
-
__decorate([
|
|
400
|
-
field({ decoder: StringDecoder, nullable: true, version: 186 })
|
|
401
|
-
], STInvoicePrivate.prototype, "reference", void 0);
|
|
402
|
-
export class STPendingInvoice extends AutoEncoder {
|
|
403
|
-
constructor() {
|
|
404
|
-
super(...arguments);
|
|
405
|
-
this.id = null;
|
|
406
|
-
this.invoice = null;
|
|
407
|
-
this.createdAt = null;
|
|
408
|
-
this.updatedAt = null;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
__decorate([
|
|
412
|
-
field({ decoder: StringDecoder, nullable: true, optional: true })
|
|
413
|
-
], STPendingInvoice.prototype, "id", void 0);
|
|
414
|
-
__decorate([
|
|
415
|
-
field({ decoder: STInvoiceMeta })
|
|
416
|
-
], STPendingInvoice.prototype, "meta", void 0);
|
|
417
|
-
__decorate([
|
|
418
|
-
field({ decoder: STInvoice, nullable: true })
|
|
419
|
-
], STPendingInvoice.prototype, "invoice", void 0);
|
|
420
|
-
__decorate([
|
|
421
|
-
field({ decoder: DateDecoder, nullable: true })
|
|
422
|
-
], STPendingInvoice.prototype, "createdAt", void 0);
|
|
423
|
-
__decorate([
|
|
424
|
-
field({ decoder: DateDecoder, nullable: true })
|
|
425
|
-
], STPendingInvoice.prototype, "updatedAt", void 0);
|
|
426
|
-
export class STPendingInvoicePrivate extends STPendingInvoice {
|
|
427
|
-
}
|
|
428
|
-
__decorate([
|
|
429
|
-
field({ decoder: OrganizationSimple, optional: true })
|
|
430
|
-
], STPendingInvoicePrivate.prototype, "organization", void 0);
|
|
431
|
-
export class STInvoiceResponse extends AutoEncoder {
|
|
432
|
-
}
|
|
433
|
-
__decorate([
|
|
434
|
-
field({ decoder: StringDecoder, optional: true })
|
|
435
|
-
], STInvoiceResponse.prototype, "paymentUrl", void 0);
|
|
436
|
-
__decorate([
|
|
437
|
-
field({ decoder: STInvoice, optional: true })
|
|
438
|
-
], STInvoiceResponse.prototype, "invoice", void 0);
|
|
439
48
|
//# sourceMappingURL=STInvoice.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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,EAAE,CAAC;uCACd;AAMpB;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;yCACtB;AAG7B;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;4CAClB;AAG9B;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;4CAClB;AAG9B;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;yCACrB;AAG3B;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;oDACxB;AAGxC;IADC,KAAK,CAAC,EAAE,OAAO,EAAE,cAAc,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,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=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