@stamhoofd/models 2.146.0 → 2.146.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvoiceCounter.d.ts","sourceRoot":"","sources":["../../src/helpers/InvoiceCounter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sDAAsD,CAAC;AAGxG,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,qBAAa,cAAc;IACvB,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"InvoiceCounter.d.ts","sourceRoot":"","sources":["../../src/helpers/InvoiceCounter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sDAAsD,CAAC;AAGxG,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,qBAAa,cAAc;IACvB,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,CAAa;IAEhF,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAK/B,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,2BAA2B,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI;IAW3G;;;;;;;OAOG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,2BAA2B,EAAE,GAAG,EAAE,MAAM;IA4BrE,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,2BAA2B,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI;WAoB3E,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;WAmExF,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAShE,MAAM,CAAC,QAAQ;CAGlB"}
|
|
@@ -80,7 +80,7 @@ export class InvoiceCounter {
|
|
|
80
80
|
// If save succeeds, increase cache:
|
|
81
81
|
this.numberCache.set(organizationId, {
|
|
82
82
|
lastNumber: lastNumber + 1,
|
|
83
|
-
date: new Date(invoicedAt)
|
|
83
|
+
date: new Date(invoicedAt),
|
|
84
84
|
});
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
@@ -90,6 +90,7 @@ export class InvoiceCounter {
|
|
|
90
90
|
.where('number', '!=', null)
|
|
91
91
|
.where('invoicedAt', '!=', null)
|
|
92
92
|
.orderBy('invoicedAt', 'DESC')
|
|
93
|
+
.orderBy('number', 'DESC')
|
|
93
94
|
.first(false);
|
|
94
95
|
if (lastInvoice && lastInvoice.number && lastInvoice.invoicedAt) {
|
|
95
96
|
// check date
|
|
@@ -101,7 +102,7 @@ export class InvoiceCounter {
|
|
|
101
102
|
await invoice.save();
|
|
102
103
|
this.numberCache.set(organizationId, {
|
|
103
104
|
lastNumber: lastNumber + 1,
|
|
104
|
-
date: new Date(invoicedAt)
|
|
105
|
+
date: new Date(invoicedAt),
|
|
105
106
|
});
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
@@ -113,7 +114,7 @@ export class InvoiceCounter {
|
|
|
113
114
|
await invoice.save();
|
|
114
115
|
this.numberCache.set(organizationId, {
|
|
115
116
|
lastNumber: 1,
|
|
116
|
-
date: new Date(invoicedAt)
|
|
117
|
+
date: new Date(invoicedAt),
|
|
117
118
|
});
|
|
118
119
|
return;
|
|
119
120
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvoiceCounter.js","sourceRoot":"","sources":["../../src/helpers/InvoiceCounter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC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c,EAAE;4BACjC,UAAU,EAAE,UAAU,GAAG,CAAC;4BAC1B,IAAI,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC;yBAC7B,CAAC,CAAC;wBACH,OAAO;oBACX,CAAC;gBACL,CAAC;YACL,CAAC;YAED,YAAY;YACZ,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;YAC5D,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;YAChC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;YAErB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE;gBACjC,UAAU,EAAE,CAAC;gBACb,IAAI,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC;aAC7B,CAAC,CAAC;YACH,OAAO;QACX,CAAC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,cAAsB;QAC5C,0CAA0C;QAC1C,gHAAgH;QAChH,OAAO,MAAM,YAAY,CAAC,QAAQ,CAAC,kBAAkB,GAAG,cAAc,EAAE,KAAK,IAAI,EAAE;YAC/E,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YACxC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,QAAQ;QACX,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stamhoofd/models",
|
|
3
|
-
"version": "2.146.
|
|
3
|
+
"version": "2.146.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@simonbackx/simple-database": "1.37.1",
|
|
47
|
-
"@stamhoofd/test-utils": "2.146.
|
|
47
|
+
"@stamhoofd/test-utils": "2.146.2",
|
|
48
48
|
"@types/luxon": "3.7.2",
|
|
49
49
|
"@types/uuid": "8.3.4",
|
|
50
50
|
"vitest": "4.1.10"
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "ee26649a0cf35d2bd65a8931915a2dd6fd280942"
|
|
67
67
|
}
|
|
@@ -6,8 +6,7 @@ import type { DateTime } from 'luxon';
|
|
|
6
6
|
import { Invoice } from '../models/Invoice.js';
|
|
7
7
|
|
|
8
8
|
export class InvoiceCounter {
|
|
9
|
-
static numberCache: Map<string, {lastNumber: number
|
|
10
|
-
|
|
9
|
+
static numberCache: Map<string, { lastNumber: number; date: Date }> = new Map();
|
|
11
10
|
|
|
12
11
|
private static getNextResetDate(last: DateTime, resetMonth: number): DateTime {
|
|
13
12
|
const candidate = last.set({ month: resetMonth, day: 1 }).startOf('day');
|
|
@@ -22,13 +21,13 @@ export class InvoiceCounter {
|
|
|
22
21
|
const last = Formatter.luxon(lastInvoiceDate);
|
|
23
22
|
const current = Formatter.luxon(invoiceDate);
|
|
24
23
|
|
|
25
|
-
return current >= this.getNextResetDate(last, settings.resetMonth)
|
|
24
|
+
return current >= this.getNextResetDate(last, settings.resetMonth);
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* XXX-123 -> 123
|
|
30
29
|
* YYY-0001 -> 1
|
|
31
|
-
*
|
|
30
|
+
*
|
|
32
31
|
* if prefix is enabled:
|
|
33
32
|
* 2025001 -> 1
|
|
34
33
|
* STA-2025001 -> 1
|
|
@@ -40,15 +39,15 @@ export class InvoiceCounter {
|
|
|
40
39
|
|
|
41
40
|
let last = splitted[splitted.length - 1];
|
|
42
41
|
|
|
43
|
-
const stripYear = settings.prefixYear
|
|
42
|
+
const stripYear = settings.prefixYear;
|
|
44
43
|
|
|
45
44
|
if (last.length) {
|
|
46
45
|
if (stripYear) {
|
|
47
46
|
if (last.length <= 4) {
|
|
48
|
-
console.error('Could not parse invoice number from string ' + str + ' (could not trim year prefix)')
|
|
47
|
+
console.error('Could not parse invoice number from string ' + str + ' (could not trim year prefix)');
|
|
49
48
|
return null;
|
|
50
49
|
}
|
|
51
|
-
last = last.substring(4)
|
|
50
|
+
last = last.substring(4);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
const int = parseInt(last);
|
|
@@ -57,15 +56,15 @@ export class InvoiceCounter {
|
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
console.error('Could not parse invoice number from string ' + str)
|
|
59
|
+
console.error('Could not parse invoice number from string ' + str);
|
|
61
60
|
return null;
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
static formatNumber(settings: OrganizationInvoiceSettings, int: number, invoicedAt: Date) {
|
|
65
|
-
let str = int.toFixed(0).padStart(settings.padZeroLength, '0')
|
|
64
|
+
let str = int.toFixed(0).padStart(settings.padZeroLength, '0');
|
|
66
65
|
|
|
67
66
|
if (settings.prefixYear) {
|
|
68
|
-
const year = Formatter.luxon(invoicedAt).year
|
|
67
|
+
const year = Formatter.luxon(invoicedAt).year;
|
|
69
68
|
str = year + str;
|
|
70
69
|
}
|
|
71
70
|
|
|
@@ -74,7 +73,7 @@ export class InvoiceCounter {
|
|
|
74
73
|
// Need seperation character
|
|
75
74
|
str = settings.fixedPrefix.replace(/-$/, '') + '-' + str;
|
|
76
75
|
} else {
|
|
77
|
-
str = settings.fixedPrefix +
|
|
76
|
+
str = settings.fixedPrefix + str;
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -82,14 +81,14 @@ export class InvoiceCounter {
|
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
static async assignNextNumber(invoice: Invoice, settings: OrganizationInvoiceSettings): Promise<void> {
|
|
85
|
-
const organizationId = invoice.organizationId
|
|
84
|
+
const organizationId = invoice.organizationId;
|
|
86
85
|
return await QueueHandler.schedule('invoice/numbers-' + organizationId, async () => {
|
|
87
86
|
// Invoice date should be inside the queue to ensure it is chronologically generated
|
|
88
87
|
const invoicedAt = new Date();
|
|
89
88
|
|
|
90
89
|
const c = this.numberCache.get(organizationId);
|
|
91
90
|
if (c !== undefined) {
|
|
92
|
-
const lastNumber = c.lastNumber
|
|
91
|
+
const lastNumber = c.lastNumber;
|
|
93
92
|
|
|
94
93
|
// check date
|
|
95
94
|
if (!this.shouldStartNewSeries(settings, c.date, invoicedAt)) {
|
|
@@ -97,37 +96,38 @@ export class InvoiceCounter {
|
|
|
97
96
|
// we do this here because it assures we'll not increase the next number if the save fails
|
|
98
97
|
invoice.number = this.formatNumber(settings, lastNumber + 1, invoicedAt);
|
|
99
98
|
invoice.invoicedAt = invoicedAt;
|
|
100
|
-
await invoice.save()
|
|
99
|
+
await invoice.save();
|
|
101
100
|
|
|
102
101
|
// If save succeeds, increase cache:
|
|
103
102
|
this.numberCache.set(organizationId, {
|
|
104
103
|
lastNumber: lastNumber + 1,
|
|
105
|
-
date: new Date(invoicedAt)
|
|
104
|
+
date: new Date(invoicedAt),
|
|
106
105
|
});
|
|
107
|
-
return
|
|
106
|
+
return;
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
const lastInvoice = await Invoice.select()
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
.where('organizationId', organizationId)
|
|
112
|
+
.where('number', '!=', null)
|
|
113
|
+
.where('invoicedAt', '!=', null)
|
|
114
|
+
.orderBy('invoicedAt', 'DESC')
|
|
115
|
+
.orderBy('number', 'DESC')
|
|
116
|
+
.first(false);
|
|
117
117
|
|
|
118
118
|
if (lastInvoice && lastInvoice.number && lastInvoice.invoicedAt) {
|
|
119
119
|
// check date
|
|
120
120
|
if (!this.shouldStartNewSeries(settings, lastInvoice.invoicedAt, invoicedAt)) {
|
|
121
|
-
const lastNumber = this.parseNumber(settings, lastInvoice.number)
|
|
121
|
+
const lastNumber = this.parseNumber(settings, lastInvoice.number);
|
|
122
122
|
|
|
123
123
|
if (lastNumber) {
|
|
124
124
|
invoice.number = this.formatNumber(settings, lastNumber + 1, invoicedAt);
|
|
125
125
|
invoice.invoicedAt = invoicedAt;
|
|
126
|
-
await invoice.save()
|
|
127
|
-
|
|
126
|
+
await invoice.save();
|
|
127
|
+
|
|
128
128
|
this.numberCache.set(organizationId, {
|
|
129
129
|
lastNumber: lastNumber + 1,
|
|
130
|
-
date: new Date(invoicedAt)
|
|
130
|
+
date: new Date(invoicedAt),
|
|
131
131
|
});
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
@@ -137,11 +137,11 @@ export class InvoiceCounter {
|
|
|
137
137
|
// Start new
|
|
138
138
|
invoice.number = this.formatNumber(settings, 1, invoicedAt);
|
|
139
139
|
invoice.invoicedAt = invoicedAt;
|
|
140
|
-
await invoice.save()
|
|
141
|
-
|
|
140
|
+
await invoice.save();
|
|
141
|
+
|
|
142
142
|
this.numberCache.set(organizationId, {
|
|
143
143
|
lastNumber: 1,
|
|
144
|
-
date: new Date(invoicedAt)
|
|
144
|
+
date: new Date(invoicedAt),
|
|
145
145
|
});
|
|
146
146
|
return;
|
|
147
147
|
});
|