@stamhoofd/models 2.152.0 → 2.153.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/factories/UserFactory.d.ts +1 -0
- package/dist/factories/UserFactory.d.ts.map +1 -1
- package/dist/factories/UserFactory.js +3 -1
- package/dist/factories/UserFactory.js.map +1 -1
- package/dist/helpers/Handlebars.d.ts.map +1 -1
- package/dist/helpers/Handlebars.js +2 -10
- package/dist/helpers/Handlebars.js.map +1 -1
- package/dist/helpers/countDays.d.ts +5 -0
- package/dist/helpers/countDays.d.ts.map +1 -0
- package/dist/helpers/countDays.js +15 -0
- package/dist/helpers/countDays.js.map +1 -0
- package/dist/migrations/1788509800-invoiced-balance-items-details.sql +5 -0
- package/dist/migrations/1788900000-document-parent-id.sql +2 -0
- package/dist/models/Document.d.ts +4 -0
- package/dist/models/Document.d.ts.map +1 -1
- package/dist/models/Document.js +7 -0
- package/dist/models/Document.js.map +1 -1
- package/dist/models/DocumentTemplate.d.ts +66 -3
- package/dist/models/DocumentTemplate.d.ts.map +1 -1
- package/dist/models/DocumentTemplate.js +234 -47
- package/dist/models/DocumentTemplate.js.map +1 -1
- package/dist/models/Invoice.d.ts.map +1 -1
- package/dist/models/Invoice.js +2 -2
- package/dist/models/Invoice.js.map +1 -1
- package/dist/models/InvoicedBalanceItem.d.ts +8 -0
- package/dist/models/InvoicedBalanceItem.d.ts.map +1 -1
- package/dist/models/InvoicedBalanceItem.js +21 -0
- package/dist/models/InvoicedBalanceItem.js.map +1 -1
- package/dist/models/Member.d.ts +2 -1
- package/dist/models/Member.d.ts.map +1 -1
- package/dist/models/Member.js +7 -1
- package/dist/models/Member.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/package.json +66 -66
- package/src/factories/UserFactory.ts +3 -1
- package/src/helpers/Handlebars.ts +2 -10
- package/src/helpers/countDays.ts +15 -0
- package/src/migrations/1788509800-invoiced-balance-items-details.sql +5 -0
- package/src/migrations/1788900000-document-parent-id.sql +2 -0
- package/src/models/Document.ts +6 -0
- package/src/models/DocumentTemplate.test.ts +75 -1
- package/src/models/DocumentTemplate.ts +295 -50
- package/src/models/Invoice.ts +2 -2
- package/src/models/InvoicedBalanceItem.ts +17 -0
- package/src/models/Member.ts +8 -1
package/package.json
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
2
|
+
"name": "@stamhoofd/models",
|
|
3
|
+
"version": "2.153.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"./src/models/_relations.ts",
|
|
9
|
+
"./dist/models/_relations.js"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/index.js",
|
|
13
|
+
"./*.ts": "./dist/*.js",
|
|
14
|
+
"./*.js": "./dist/*.js"
|
|
15
|
+
},
|
|
16
|
+
"imports": {
|
|
17
|
+
"#*": "./src/*.ts",
|
|
18
|
+
"#*.ts": "./src/*.ts"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@aws-sdk/client-s3": "3.1140.0",
|
|
26
|
+
"@aws-sdk/client-sesv2": "3.1140.0",
|
|
27
|
+
"@bwip-js/node": "4.11.4",
|
|
28
|
+
"@simonbackx/simple-database": "1.40.1",
|
|
29
|
+
"@simonbackx/simple-encoding": "2.26.11",
|
|
30
|
+
"@simonbackx/simple-endpoints": "1.22.0",
|
|
31
|
+
"@simonbackx/simple-errors": "1.5.0",
|
|
32
|
+
"argon2": "0.45.1",
|
|
33
|
+
"base-x": "3.0.11",
|
|
34
|
+
"handlebars": "4.7.9",
|
|
35
|
+
"luxon": "3.7.2",
|
|
36
|
+
"sharp": "0.35.4",
|
|
37
|
+
"uuid": "14.0.2"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@stamhoofd/test-utils": "2.153.0",
|
|
41
|
+
"@types/luxon": "3.7.5",
|
|
42
|
+
"@types/uuid": "8.3.4",
|
|
43
|
+
"mysql2": "3.24.4",
|
|
44
|
+
"vitest": "4.1.11"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@stamhoofd/backend-i18n": "*",
|
|
48
|
+
"@stamhoofd/email": "*",
|
|
49
|
+
"@stamhoofd/queues": "*",
|
|
50
|
+
"@stamhoofd/sql": "*",
|
|
51
|
+
"@stamhoofd/structures": "*",
|
|
52
|
+
"@stamhoofd/types": "*",
|
|
53
|
+
"@stamhoofd/utility": "*",
|
|
54
|
+
"mysql2": "3.24.4"
|
|
55
|
+
},
|
|
56
|
+
"license": "UNLICENCED",
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsc --build tsconfig.build.json && mkdir -p ./dist/migrations && rsync --delete --exclude='*.ts' --exclude='*.js' --exclude='*.map' -r --checksum ./src/migrations/ ./dist/migrations/ && rsync -r --checksum ./src/assets/ ./dist/assets/",
|
|
62
|
+
"lint": "eslint",
|
|
63
|
+
"typecheck": "tsc --build tsconfig.test.json",
|
|
64
|
+
"test": "vitest",
|
|
65
|
+
"test:coverage": "vitest --coverage"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -18,6 +18,7 @@ class Options {
|
|
|
18
18
|
verified?: boolean;
|
|
19
19
|
permissions?: Permissions | null;
|
|
20
20
|
globalPermissions?: Permissions | null;
|
|
21
|
+
isStamhoofd?: boolean;
|
|
21
22
|
|
|
22
23
|
apiUser?: boolean;
|
|
23
24
|
}
|
|
@@ -33,7 +34,8 @@ export class UserFactory extends Factory<Options, User> {
|
|
|
33
34
|
organization = this.options.organization ?? null;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
const
|
|
37
|
+
const emailDomain = this.options.isStamhoofd ? '@stamhoofd.be' : '@domain.com';
|
|
38
|
+
const email = this.options.email ?? 'generated-email-' + this.randomString(20) + emailDomain;
|
|
37
39
|
const password = this.options.password ?? this.randomString(20);
|
|
38
40
|
|
|
39
41
|
const user = await User.register(organization, NewUser.create({
|
|
@@ -3,7 +3,7 @@ import { ObjectData } from '@simonbackx/simple-encoding';
|
|
|
3
3
|
import { Image } from '@stamhoofd/structures';
|
|
4
4
|
import { Formatter } from '@stamhoofd/utility';
|
|
5
5
|
import Handlebars from 'handlebars';
|
|
6
|
-
import {
|
|
6
|
+
import { countDays } from './countDays.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Support for async helpers
|
|
@@ -116,15 +116,7 @@ Handlebars.registerHelper('days', (a, b) => {
|
|
|
116
116
|
if (!(a instanceof Date) || !(b instanceof Date)) {
|
|
117
117
|
return 0;
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
const start = Formatter.luxon(a).set({ hour: 0, minute: 0, second: 0, millisecond: 0 });
|
|
121
|
-
const end = Formatter.luxon(b).set({ hour: 0, minute: 0, second: 0, millisecond: 0 });
|
|
122
|
-
const diff = Interval.fromDateTimes(start, end);
|
|
123
|
-
const days = diff.length('days');
|
|
124
|
-
if (isNaN(days)) {
|
|
125
|
-
return 0;
|
|
126
|
-
}
|
|
127
|
-
return days + 1;
|
|
119
|
+
return countDays(a, b);
|
|
128
120
|
});
|
|
129
121
|
|
|
130
122
|
Handlebars.registerHelper('div', (a, b, options) => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Formatter } from '@stamhoofd/utility';
|
|
2
|
+
import { Interval } from 'luxon';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Amount of calendar days from `start` up to and including `end`, on Brussels day boundaries
|
|
6
|
+
*/
|
|
7
|
+
export function countDays(start: Date, end: Date): number {
|
|
8
|
+
const startDay = Formatter.luxon(start).startOf('day');
|
|
9
|
+
const endDay = Formatter.luxon(end).startOf('day');
|
|
10
|
+
const days = Interval.fromDateTimes(startDay, endDay).length('days');
|
|
11
|
+
if (isNaN(days)) {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
return days + 1;
|
|
15
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
ALTER TABLE `invoiced_balance_items`
|
|
2
|
+
ADD COLUMN `type` varchar(36) NOT NULL DEFAULT 'Other' AFTER `balanceItemId`,
|
|
3
|
+
ADD COLUMN `relations` json NOT NULL DEFAULT (json_object()) AFTER `description`,
|
|
4
|
+
ADD COLUMN `startDate` datetime NULL AFTER `relations`,
|
|
5
|
+
ADD COLUMN `endDate` datetime NULL AFTER `startDate`;
|
package/src/models/Document.ts
CHANGED
|
@@ -34,6 +34,12 @@ export class Document extends QueryableModel {
|
|
|
34
34
|
@column({ type: 'string', nullable: true })
|
|
35
35
|
registrationId: string | null = null;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Set when the certificate of a registration is split between multiple debtors: the id of the parent this document is issued to
|
|
39
|
+
*/
|
|
40
|
+
@column({ type: 'string', nullable: true })
|
|
41
|
+
parentId: string | null = null;
|
|
42
|
+
|
|
37
43
|
@column({ type: 'string' })
|
|
38
44
|
status = DocumentStatus.Draft;
|
|
39
45
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DocumentStatus } from '@stamhoofd/structures';
|
|
1
|
+
import { DocumentStatus, NationalRegisterNumberOptOut, Parent } from '@stamhoofd/structures';
|
|
2
2
|
import { DocumentTemplateFactory } from '../factories/DocumentTemplateFactory.js';
|
|
3
|
+
import { getTaxDependentDebtors, splitPrice } from './DocumentTemplate.js';
|
|
3
4
|
|
|
4
5
|
describe('Model.DocumentTemplate', () => {
|
|
5
6
|
it('PublishedAt should be set if status is published and publishedAt is null', async () => {
|
|
@@ -63,3 +64,76 @@ describe('Model.DocumentTemplate', () => {
|
|
|
63
64
|
expect(documentTemplate4.publishedAt).toBeNull();
|
|
64
65
|
});
|
|
65
66
|
});
|
|
67
|
+
|
|
68
|
+
describe('Model.getTaxDependentDebtors', () => {
|
|
69
|
+
function parent({ name, isMemberTaxDependent, nationalRegisterNumber }: { name: string; isMemberTaxDependent?: boolean | null; nationalRegisterNumber?: string | typeof NationalRegisterNumberOptOut | null }) {
|
|
70
|
+
return Parent.create({
|
|
71
|
+
firstName: name,
|
|
72
|
+
lastName: 'Doe',
|
|
73
|
+
isMemberTaxDependent: isMemberTaxDependent ?? null,
|
|
74
|
+
nationalRegisterNumber: nationalRegisterNumber ?? null,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
test('falls back to the old debtor logic when nobody has the member tax dependent', () => {
|
|
79
|
+
const parents = [parent({ name: 'Linda', nationalRegisterNumber: '93042012345' })];
|
|
80
|
+
|
|
81
|
+
expect(getTaxDependentDebtors(parents)).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('picks the parent that has the member tax dependent', () => {
|
|
85
|
+
const linda = parent({ name: 'Linda', isMemberTaxDependent: true, nationalRegisterNumber: '93042012345' });
|
|
86
|
+
const john = parent({ name: 'John', nationalRegisterNumber: '93042017297' });
|
|
87
|
+
|
|
88
|
+
expect(getTaxDependentDebtors([john, linda])).toEqual([{ debtor: linda, missingData: false }]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// The certificate has to carry the name the family chose, even though it cannot be completed
|
|
92
|
+
test('keeps a tax dependent parent that opted out, instead of falling back to another parent', () => {
|
|
93
|
+
const linda = parent({ name: 'Linda', isMemberTaxDependent: true, nationalRegisterNumber: NationalRegisterNumberOptOut });
|
|
94
|
+
const john = parent({ name: 'John', nationalRegisterNumber: '93042017297' });
|
|
95
|
+
|
|
96
|
+
expect(getTaxDependentDebtors([linda, john])).toEqual([{ debtor: linda, missingData: true }]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('reports missing data when the tax dependent parent has no number yet', () => {
|
|
100
|
+
const linda = parent({ name: 'Linda', isMemberTaxDependent: true });
|
|
101
|
+
|
|
102
|
+
expect(getTaxDependentDebtors([linda])).toEqual([{ debtor: linda, missingData: true }]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('with co-parenting, both parents become a debtor in the order of the parents', () => {
|
|
106
|
+
const linda = parent({ name: 'Linda', isMemberTaxDependent: true, nationalRegisterNumber: '93042012345' });
|
|
107
|
+
const john = parent({ name: 'John', isMemberTaxDependent: true, nationalRegisterNumber: '93042017297' });
|
|
108
|
+
|
|
109
|
+
expect(getTaxDependentDebtors([linda, john])).toEqual([{ debtor: linda, missingData: false }, { debtor: john, missingData: false }]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('with co-parenting, missing data is tracked per parent', () => {
|
|
113
|
+
const linda = parent({ name: 'Linda', isMemberTaxDependent: true, nationalRegisterNumber: NationalRegisterNumberOptOut });
|
|
114
|
+
const john = parent({ name: 'John', isMemberTaxDependent: true, nationalRegisterNumber: '93042017297' });
|
|
115
|
+
|
|
116
|
+
expect(getTaxDependentDebtors([linda, john])).toEqual([{ debtor: linda, missingData: true }, { debtor: john, missingData: false }]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('Model.splitPrice', () => {
|
|
121
|
+
test('splits an even amount in equal halves', () => {
|
|
122
|
+
expect(splitPrice(1000000, 2, 0)).toBe(500000);
|
|
123
|
+
expect(splitPrice(1000000, 2, 1)).toBe(500000);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('gives the remaining cent to the first document', () => {
|
|
127
|
+
expect(splitPrice(1234500, 2, 0)).toBe(617300);
|
|
128
|
+
expect(splitPrice(1234500, 2, 1)).toBe(617200);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('never splits below a whole cent', () => {
|
|
132
|
+
expect(splitPrice(1234567, 2, 0)).toBe(617367);
|
|
133
|
+
expect(splitPrice(1234567, 2, 1)).toBe(617200);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('halves of a negative amount add up to the total', () => {
|
|
137
|
+
expect(splitPrice(-500, 2, 0) + splitPrice(-500, 2, 1)).toBe(-500);
|
|
138
|
+
});
|
|
139
|
+
});
|