@ekwo-ai/peppol-ubl 0.4.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/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +247 -0
- package/dist/codelists.d.ts +26 -0
- package/dist/codelists.d.ts.map +1 -0
- package/dist/codelists.js +169 -0
- package/dist/codelists.js.map +1 -0
- package/dist/decimal.d.ts +49 -0
- package/dist/decimal.d.ts.map +1 -0
- package/dist/decimal.js +118 -0
- package/dist/decimal.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/model.d.ts +115 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +271 -0
- package/dist/model.js.map +1 -0
- package/dist/rules.d.ts +30 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +465 -0
- package/dist/rules.js.map +1 -0
- package/dist/types.d.ts +232 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +18 -0
- package/dist/types.js.map +1 -0
- package/dist/ubl.d.ts +20 -0
- package/dist/ubl.d.ts.map +1 -0
- package/dist/ubl.js +233 -0
- package/dist/ubl.js.map +1 -0
- package/package.json +61 -0
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The published rules, re-read against what is about to be written.
|
|
3
|
+
*
|
|
4
|
+
* A Peppol access point validates an invoice three times before it carries it:
|
|
5
|
+
* against the UBL 2.1 schema, against the Schematron of EN 16931, and against
|
|
6
|
+
* the Schematron of Peppol BIS Billing 3.0. The two Schematrons are XSLT 2.0,
|
|
7
|
+
* which nothing in a JavaScript runtime executes, so they cannot be run from
|
|
8
|
+
* here. What can be done is to read each assertion and ask the same question
|
|
9
|
+
* of the same figures — and to name the answer by the identifier the rule is
|
|
10
|
+
* published under, so that what this package reports and what the network
|
|
11
|
+
* would report are the same sentence.
|
|
12
|
+
*
|
|
13
|
+
* Every function below cites the rule it re-reads. The rule identifiers are
|
|
14
|
+
* checked against the Schematron itself by `test/rules.test.ts`, and the
|
|
15
|
+
* verdicts by the procedure the README describes. What is *not* here is listed
|
|
16
|
+
* in the README, by name.
|
|
17
|
+
*/
|
|
18
|
+
import type { DocumentModel } from './model.js';
|
|
19
|
+
import type { Violation } from './types.js';
|
|
20
|
+
/**
|
|
21
|
+
* Electronic address schemes EN 16931 lists and Peppol does not: an e-mail
|
|
22
|
+
* address or a telephone number is an electronic address to the standard and
|
|
23
|
+
* not somewhere the network delivers. The Peppol Schematron carries its own,
|
|
24
|
+
* shorter list (`eaid`); this is the difference between the two, and
|
|
25
|
+
* `scripts/play-schematron.mjs` recomputes it from the published files.
|
|
26
|
+
*/
|
|
27
|
+
export declare const SCHEMES_NOT_ON_PEPPOL: readonly string[];
|
|
28
|
+
/** Every published rule the document breaks, in the order a reader meets them. */
|
|
29
|
+
export declare function check(model: DocumentModel): Violation[];
|
|
30
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA4BH,OAAO,KAAK,EAAE,aAAa,EAAwC,MAAM,YAAY,CAAC;AACtF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA4B5C;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAkE,CAAC;AA2QtH,kFAAkF;AAClF,wBAAgB,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,EAAE,CAsJvD"}
|
package/dist/rules.js
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The published rules, re-read against what is about to be written.
|
|
3
|
+
*
|
|
4
|
+
* A Peppol access point validates an invoice three times before it carries it:
|
|
5
|
+
* against the UBL 2.1 schema, against the Schematron of EN 16931, and against
|
|
6
|
+
* the Schematron of Peppol BIS Billing 3.0. The two Schematrons are XSLT 2.0,
|
|
7
|
+
* which nothing in a JavaScript runtime executes, so they cannot be run from
|
|
8
|
+
* here. What can be done is to read each assertion and ask the same question
|
|
9
|
+
* of the same figures — and to name the answer by the identifier the rule is
|
|
10
|
+
* published under, so that what this package reports and what the network
|
|
11
|
+
* would report are the same sentence.
|
|
12
|
+
*
|
|
13
|
+
* Every function below cites the rule it re-reads. The rule identifiers are
|
|
14
|
+
* checked against the Schematron itself by `test/rules.test.ts`, and the
|
|
15
|
+
* verdicts by the procedure the README describes. What is *not* here is listed
|
|
16
|
+
* in the README, by name.
|
|
17
|
+
*/
|
|
18
|
+
import { COUNTRY_CODES, CURRENCY_CODES, ELECTRONIC_ADDRESS_SCHEMES, EXEMPTION_REASON_CODES, IDENTIFIER_SCHEMES, PAYMENT_MEANS_CODES, UNIT_CODES, VAT_CATEGORY_CODES, VAT_IDENTIFIER_PREFIXES, } from './codelists.js';
|
|
19
|
+
import { ZERO, abs, add, compare, equal, formatDecimal, isZero, multiply, roundXPath, significantScale, subtract, sum, } from './decimal.js';
|
|
20
|
+
const ONE = { units: 1n, scale: 0 };
|
|
21
|
+
const SLACK = { units: 2n, scale: 2 };
|
|
22
|
+
/** The categories whose rules come in the same numbered family, and the letters the family is named with. */
|
|
23
|
+
const FAMILIES = {
|
|
24
|
+
S: 'S',
|
|
25
|
+
Z: 'Z',
|
|
26
|
+
E: 'E',
|
|
27
|
+
AE: 'AE',
|
|
28
|
+
K: 'IC',
|
|
29
|
+
G: 'G',
|
|
30
|
+
O: 'O',
|
|
31
|
+
};
|
|
32
|
+
/** Exemption reason codes that belong to one category and no other (PEPPOL-EN16931-P0104 to P0111). */
|
|
33
|
+
const CODE_CATEGORY = {
|
|
34
|
+
'VATEX-EU-G': ['PEPPOL-EN16931-P0104', 'G'],
|
|
35
|
+
'VATEX-EU-O': ['PEPPOL-EN16931-P0105', 'O'],
|
|
36
|
+
'VATEX-EU-IC': ['PEPPOL-EN16931-P0106', 'K'],
|
|
37
|
+
'VATEX-EU-AE': ['PEPPOL-EN16931-P0107', 'AE'],
|
|
38
|
+
'VATEX-EU-D': ['PEPPOL-EN16931-P0108', 'E'],
|
|
39
|
+
'VATEX-EU-F': ['PEPPOL-EN16931-P0109', 'E'],
|
|
40
|
+
'VATEX-EU-I': ['PEPPOL-EN16931-P0110', 'E'],
|
|
41
|
+
'VATEX-EU-J': ['PEPPOL-EN16931-P0111', 'E'],
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Electronic address schemes EN 16931 lists and Peppol does not: an e-mail
|
|
45
|
+
* address or a telephone number is an electronic address to the standard and
|
|
46
|
+
* not somewhere the network delivers. The Peppol Schematron carries its own,
|
|
47
|
+
* shorter list (`eaid`); this is the difference between the two, and
|
|
48
|
+
* `scripts/play-schematron.mjs` recomputes it from the published files.
|
|
49
|
+
*/
|
|
50
|
+
export const SCHEMES_NOT_ON_PEPPOL = Object.freeze(['0219', '0220', 'AN', 'AQ', 'AS', 'AU', 'EM']);
|
|
51
|
+
const money = (value) => formatDecimal(value, 2);
|
|
52
|
+
/**
|
|
53
|
+
* BR-DEC-* and UBL-DT-01: an amount has two decimals at most. The first is the
|
|
54
|
+
* rule of the standard, one per business term; the second is the rule of its
|
|
55
|
+
* UBL binding, one for every amount that is not a price. Both fire.
|
|
56
|
+
*/
|
|
57
|
+
function decimalsRule(code, value, what, out, line) {
|
|
58
|
+
if (value === null || significantScale(value) <= 2)
|
|
59
|
+
return;
|
|
60
|
+
const message = `${what}, ${formatDecimal(value)}, has more than two decimals.`;
|
|
61
|
+
const on = line === undefined ? {} : { line };
|
|
62
|
+
out.push({ code, message, ...on }, { code: 'UBL-DT-01', message, ...on });
|
|
63
|
+
}
|
|
64
|
+
/** `u:gln` of the Peppol Schematron: the GS1 check digit. */
|
|
65
|
+
function validGln(value) {
|
|
66
|
+
if (!/^[0-9]+$/.test(value))
|
|
67
|
+
return false;
|
|
68
|
+
const body = [...value.slice(0, -1)].reverse().map(Number);
|
|
69
|
+
const weighted = body.reduce((total, digit, i) => total + digit * (1 + ((i + 1) % 2) * 2), 0);
|
|
70
|
+
return (10 - (weighted % 10)) % 10 === Number(value.slice(-1));
|
|
71
|
+
}
|
|
72
|
+
/** `u:mod97-0208` of the Peppol Schematron: the check digits of a Belgian enterprise number. */
|
|
73
|
+
function validEnterpriseNumber0208(value) {
|
|
74
|
+
if (!/^[0-9]{10}$/.test(value))
|
|
75
|
+
return false;
|
|
76
|
+
return 97 - (Number(value.slice(0, 8)) % 97) === Number(value.slice(8));
|
|
77
|
+
}
|
|
78
|
+
/** PEPPOL-COMMON-R040 and R043: an identifier in a scheme that has a check digit. */
|
|
79
|
+
function identifierRules(scheme, value, what, out) {
|
|
80
|
+
if (scheme === null || value === null)
|
|
81
|
+
return;
|
|
82
|
+
if (scheme === '0088' && !validGln(value)) {
|
|
83
|
+
out.push({ code: 'PEPPOL-COMMON-R040', message: `${what} is given as a GLN and ${value} is not one: its check digit is wrong.` });
|
|
84
|
+
}
|
|
85
|
+
if (scheme === '0208' && !validEnterpriseNumber0208(value)) {
|
|
86
|
+
out.push({
|
|
87
|
+
code: 'PEPPOL-COMMON-R043',
|
|
88
|
+
message: `${what} is given in scheme 0208 and ${value} is not a Belgian enterprise number: ten digits, the last two being 97 less the first eight modulo 97.`,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function partyRules(party, who, out) {
|
|
93
|
+
const seller = who === 'seller';
|
|
94
|
+
const Who = seller ? 'The seller' : 'The buyer';
|
|
95
|
+
if (party.registrationName === null) {
|
|
96
|
+
out.push({ code: seller ? 'BR-06' : 'BR-07', message: `${Who} has no name.` });
|
|
97
|
+
}
|
|
98
|
+
if (party.address === null) {
|
|
99
|
+
out.push({ code: seller ? 'BR-08' : 'BR-10', message: `${Who} has no postal address.` });
|
|
100
|
+
}
|
|
101
|
+
else if (party.address.country === null) {
|
|
102
|
+
out.push({ code: seller ? 'BR-09' : 'BR-11', message: `The address of ${who === 'seller' ? 'the seller' : 'the buyer'} has no country.` });
|
|
103
|
+
}
|
|
104
|
+
else if (!COUNTRY_CODES.has(party.address.country)) {
|
|
105
|
+
out.push({ code: 'BR-CL-14', message: `${party.address.country} is not an ISO 3166-1 country code.` });
|
|
106
|
+
}
|
|
107
|
+
if (party.endpoint === null) {
|
|
108
|
+
out.push({
|
|
109
|
+
code: seller ? 'PEPPOL-EN16931-R020' : 'PEPPOL-EN16931-R010',
|
|
110
|
+
message: `${Who} has no electronic address, and the network delivers to nothing else.`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else if (party.endpoint.scheme === '') {
|
|
114
|
+
out.push({ code: seller ? 'BR-62' : 'BR-63', message: `The electronic address of ${seller ? 'the seller' : 'the buyer'} names no scheme.` });
|
|
115
|
+
}
|
|
116
|
+
else if (!ELECTRONIC_ADDRESS_SCHEMES.has(party.endpoint.scheme)) {
|
|
117
|
+
// The two Schematrons each carry the list and each report it.
|
|
118
|
+
const message = `${party.endpoint.scheme} is not an electronic address scheme (EAS).`;
|
|
119
|
+
out.push({ code: 'BR-CL-25', message }, { code: 'PEPPOL-EN16931-CL008', message });
|
|
120
|
+
}
|
|
121
|
+
else if (SCHEMES_NOT_ON_PEPPOL.includes(party.endpoint.scheme)) {
|
|
122
|
+
out.push({
|
|
123
|
+
code: 'PEPPOL-EN16931-CL008',
|
|
124
|
+
message: `${party.endpoint.scheme} is an electronic address scheme of EN 16931 and not one Peppol delivers to.`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
identifierRules(party.endpoint.scheme, party.endpoint.id, `The electronic address of ${seller ? 'the seller' : 'the buyer'}`, out);
|
|
129
|
+
}
|
|
130
|
+
if (party.vatId !== null && !VAT_IDENTIFIER_PREFIXES.has(party.vatId.slice(0, 2))) {
|
|
131
|
+
out.push({
|
|
132
|
+
code: 'BR-CO-09',
|
|
133
|
+
message: `The VAT identifier of ${seller ? 'the seller' : 'the buyer'} starts with ${party.vatId.slice(0, 2)}, which is not a country.`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (party.legalIdScheme !== null) {
|
|
137
|
+
if (!IDENTIFIER_SCHEMES.has(party.legalIdScheme)) {
|
|
138
|
+
out.push({ code: 'BR-CL-11', message: `${party.legalIdScheme} is not an ISO 6523 identifier scheme.` });
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
identifierRules(party.legalIdScheme, party.legalId, `The registration number of ${seller ? 'the seller' : 'the buyer'}`, out);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (seller && party.vatId === null && party.legalId === null) {
|
|
145
|
+
out.push({ code: 'BR-CO-26', message: 'The seller has neither a VAT identifier nor a registration number, so a buyer cannot tell who it is.' });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function lineRules(line, out) {
|
|
149
|
+
const on = { line: line.id };
|
|
150
|
+
if (line.quantity === null)
|
|
151
|
+
out.push({ code: 'BR-22', message: 'The line has no quantity.', ...on });
|
|
152
|
+
if (line.unitCode === null) {
|
|
153
|
+
out.push({ code: 'BR-23', message: 'The quantity of the line has no unit.', ...on });
|
|
154
|
+
}
|
|
155
|
+
else if (!UNIT_CODES.has(line.unitCode)) {
|
|
156
|
+
out.push({ code: 'BR-CL-23', message: `${line.unitCode} is not a unit of UN/ECE Recommendation 20.`, ...on });
|
|
157
|
+
}
|
|
158
|
+
if (line.name === null)
|
|
159
|
+
out.push({ code: 'BR-25', message: 'The line names no item.', ...on });
|
|
160
|
+
decimalsRule('BR-DEC-23', line.netAmount, 'The net amount of the line', out, line.id);
|
|
161
|
+
if (line.netPrice === null) {
|
|
162
|
+
out.push({
|
|
163
|
+
code: 'BR-26',
|
|
164
|
+
message: 'The line has no net price. A price keyed with its tax in it is not one, and the net price is not worked out here.',
|
|
165
|
+
...on,
|
|
166
|
+
});
|
|
167
|
+
// The rule that a price is not negative is written so that an absent price
|
|
168
|
+
// fails it too, and a validator reports the two together.
|
|
169
|
+
out.push({ code: 'BR-27', message: 'The line has no net price, which the rule against a negative one also refuses.', ...on });
|
|
170
|
+
}
|
|
171
|
+
else if (line.netPrice.units < 0n) {
|
|
172
|
+
out.push({ code: 'BR-27', message: `The net price of the line, ${formatDecimal(line.netPrice)}, is negative.`, ...on });
|
|
173
|
+
}
|
|
174
|
+
if (line.grossPrice !== null && line.grossPrice.units < 0n) {
|
|
175
|
+
out.push({ code: 'BR-28', message: `The gross price of the line, ${formatDecimal(line.grossPrice)}, is negative.`, ...on });
|
|
176
|
+
}
|
|
177
|
+
// PEPPOL-EN16931-R120: the net amount is the quantity times the net price,
|
|
178
|
+
// give or take two cents. An absent quantity counts for one and an absent
|
|
179
|
+
// price for nothing, as the rule itself reads them.
|
|
180
|
+
const expected = multiply(line.quantity ?? ONE, line.netPrice ?? ZERO);
|
|
181
|
+
if (compare(add(line.netAmount, SLACK), expected) < 0 || compare(subtract(line.netAmount, SLACK), expected) > 0) {
|
|
182
|
+
out.push({
|
|
183
|
+
code: 'PEPPOL-EN16931-R120',
|
|
184
|
+
message: `The net amount of the line is ${money(line.netAmount)} and its quantity times its net price is ${formatDecimal(expected)}.`,
|
|
185
|
+
...on,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (line.category === null) {
|
|
189
|
+
// Once for the standard, once for its UBL binding, which counts the element.
|
|
190
|
+
out.push({ code: 'BR-CO-04', message: 'The line has no VAT category.', ...on }, { code: 'UBL-SR-48', message: 'The line has no VAT category, and the UBL binding wants exactly one.', ...on });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!VAT_CATEGORY_CODES.has(line.category)) {
|
|
194
|
+
out.push({ code: 'BR-CL-18', message: `${line.category} is not a VAT category of EN 16931.`, ...on });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const family = FAMILIES[line.category];
|
|
198
|
+
if (family === undefined)
|
|
199
|
+
return;
|
|
200
|
+
if (line.category === 'S') {
|
|
201
|
+
if (line.rate === null || line.rate.units <= 0n) {
|
|
202
|
+
out.push({ code: 'BR-S-05', message: 'A standard-rated line has a rate above zero.', ...on });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else if (line.category === 'O') {
|
|
206
|
+
if (line.rate !== null && !isZero(line.rate)) {
|
|
207
|
+
out.push({ code: 'BR-O-05', message: 'A line outside the scope of VAT has no rate.', ...on });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (line.rate === null || !isZero(line.rate)) {
|
|
211
|
+
out.push({ code: `BR-${family}-05`, message: `A line in category ${line.category} has a rate of zero.`, ...on });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function subtotalRules(model, subtotal, out) {
|
|
215
|
+
const { category, rate } = subtotal;
|
|
216
|
+
const label = `${category ?? '?'}${rate === null ? '' : ` at ${formatDecimal(rate)} %`}`;
|
|
217
|
+
decimalsRule('BR-DEC-19', subtotal.base, `The base of the VAT group ${label}`, out);
|
|
218
|
+
decimalsRule('BR-DEC-20', subtotal.tax, `The tax of the VAT group ${label}`, out);
|
|
219
|
+
if (category === null) {
|
|
220
|
+
out.push({ code: 'BR-47', message: 'A group of the VAT breakdown has no category.' });
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!VAT_CATEGORY_CODES.has(category)) {
|
|
224
|
+
out.push({ code: 'BR-CL-17', message: `${category} is not a VAT category of EN 16931.` });
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (rate === null && category !== 'O') {
|
|
228
|
+
out.push({ code: 'BR-48', message: `The VAT group ${label} has no rate.` });
|
|
229
|
+
// A standard-rated group is also asked for a tax that is its base times its
|
|
230
|
+
// rate, and with no rate the answer is no.
|
|
231
|
+
if (category === 'S')
|
|
232
|
+
out.push({ code: 'BR-S-09', message: 'A standard-rated group has no rate to work its tax out from.' });
|
|
233
|
+
}
|
|
234
|
+
// BR-CO-17: the tax of a group is its base times its rate, within one unit
|
|
235
|
+
// either way. One unit and not one cent: the standard leaves room for a tax
|
|
236
|
+
// rounded line by line, and this re-reads the rule rather than tightening it.
|
|
237
|
+
const written = category === 'O' && (rate === null || isZero(rate)) ? null : rate;
|
|
238
|
+
const rounded = written === null ? ZERO : roundXPath(written, 0);
|
|
239
|
+
if (isZero(rounded)) {
|
|
240
|
+
if (!isZero(roundXPath(subtotal.tax, 0))) {
|
|
241
|
+
out.push({ code: 'BR-CO-17', message: `The VAT group ${label} has no rate and a tax of ${money(subtotal.tax)}.` });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
const expected = roundXPath({ units: multiply(abs(subtotal.base), written).units, scale: subtotal.base.scale + written.scale + 2 }, 2);
|
|
246
|
+
const tax = abs(subtotal.tax);
|
|
247
|
+
if (!(compare(subtract(tax, ONE), expected) < 0 && compare(add(tax, ONE), expected) > 0)) {
|
|
248
|
+
out.push({
|
|
249
|
+
code: 'BR-CO-17',
|
|
250
|
+
message: `The VAT group ${label} has a base of ${money(subtotal.base)} and a tax of ${money(subtotal.tax)}, which is not the one times the other.`,
|
|
251
|
+
});
|
|
252
|
+
if (category === 'S') {
|
|
253
|
+
out.push({ code: 'BR-S-09', message: `The tax of the standard-rated group at ${formatDecimal(written)} % is not its base times its rate.` });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const family = FAMILIES[category];
|
|
258
|
+
if (family === undefined)
|
|
259
|
+
return;
|
|
260
|
+
// BR-*-08: the base of a group is the sum of the lines of its category —
|
|
261
|
+
// within one unit for the standard rate, where a group is also a rate, and
|
|
262
|
+
// to the cent for every other category, which has one group whatever its
|
|
263
|
+
// lines say of their rate.
|
|
264
|
+
if (category === 'S') {
|
|
265
|
+
if (written !== null) {
|
|
266
|
+
const ofRate = model.lines.filter((line) => line.category === 'S' && line.rate !== null && equal(line.rate, written));
|
|
267
|
+
const lines = sum(ofRate.map((line) => line.netAmount));
|
|
268
|
+
const within = compare(subtract(subtotal.base, ONE), lines) < 0 && compare(add(subtotal.base, ONE), lines) > 0;
|
|
269
|
+
if (ofRate.length === 0 || !within) {
|
|
270
|
+
out.push({
|
|
271
|
+
code: 'BR-S-08',
|
|
272
|
+
message: `The standard-rated group at ${formatDecimal(written)} % has a base of ${money(subtotal.base)} and its lines add up to ${money(lines)}.`,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const lines = sum(model.lines.filter((line) => line.category === category).map((line) => line.netAmount));
|
|
279
|
+
if (!equal(subtotal.base, lines)) {
|
|
280
|
+
out.push({
|
|
281
|
+
code: `BR-${family}-08`,
|
|
282
|
+
message: `The VAT group ${category} has a base of ${money(subtotal.base)} and its lines add up to ${money(lines)}.`,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
if (category !== 'Z' && !isZero(subtotal.tax)) {
|
|
286
|
+
out.push({ code: `BR-${family}-09`, message: `The VAT group ${category} charges ${money(subtotal.tax)}, and a group of that category charges nothing.` });
|
|
287
|
+
}
|
|
288
|
+
if (category === 'Z' && !isZero(subtotal.tax)) {
|
|
289
|
+
out.push({ code: 'BR-Z-09', message: `The zero-rated group charges ${money(subtotal.tax)}.` });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// BR-*-10: a reason where the category exempts, and none where it does not.
|
|
293
|
+
const reasoned = subtotal.reasonCode !== null || subtotal.reason !== null;
|
|
294
|
+
if (category === 'S' || category === 'Z') {
|
|
295
|
+
if (reasoned)
|
|
296
|
+
out.push({ code: `BR-${family}-10`, message: `The VAT group ${label} gives a reason for an exemption it is not.` });
|
|
297
|
+
}
|
|
298
|
+
else if (!reasoned) {
|
|
299
|
+
out.push({ code: `BR-${family}-10`, message: `The VAT group ${category} gives no reason for charging no tax: neither a code nor a text.` });
|
|
300
|
+
}
|
|
301
|
+
if (subtotal.ambiguousReasonCodes.length > 0) {
|
|
302
|
+
out.push({
|
|
303
|
+
code: 'exemption-reason-ambiguous',
|
|
304
|
+
message: `The lines of the VAT group ${category} carry several exemption codes (${subtotal.ambiguousReasonCodes.join(', ')}) and a group has room for one: none was written.`,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
if (subtotal.reasonCode !== null) {
|
|
308
|
+
const code = subtotal.reasonCode;
|
|
309
|
+
if (!EXEMPTION_REASON_CODES.has(code.toUpperCase()) && !EXEMPTION_REASON_CODES.has(code)) {
|
|
310
|
+
out.push({ code: 'BR-CL-22', message: `${code} is not a VATEX exemption reason code.` });
|
|
311
|
+
}
|
|
312
|
+
const belongs = CODE_CATEGORY[code.toUpperCase()];
|
|
313
|
+
if (belongs && belongs[1] !== category) {
|
|
314
|
+
out.push({ code: belongs[0], message: `${code} is the reason of category ${belongs[1]} and stands on a group of category ${category}.` });
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/** Every published rule the document breaks, in the order a reader meets them. */
|
|
319
|
+
export function check(model) {
|
|
320
|
+
const out = [];
|
|
321
|
+
// --- The document -------------------------------------------------------
|
|
322
|
+
if (model.buyerReference === null && model.orderReference === null) {
|
|
323
|
+
out.push({ code: 'PEPPOL-EN16931-R003', message: 'The document carries neither a buyer reference nor a purchase order reference, and the network requires one of the two.' });
|
|
324
|
+
}
|
|
325
|
+
if (!CURRENCY_CODES.has(model.currency)) {
|
|
326
|
+
// One wrong code is reported where it is declared and where it is used.
|
|
327
|
+
const message = `${model.currency} is not an ISO 4217 currency code.`;
|
|
328
|
+
out.push({ code: 'BR-CL-04', message }, { code: 'BR-CL-03', message }, { code: 'PEPPOL-EN16931-CL007', message });
|
|
329
|
+
}
|
|
330
|
+
partyRules(model.seller, 'seller', out);
|
|
331
|
+
partyRules(model.buyer, 'buyer', out);
|
|
332
|
+
if (model.delivery?.address) {
|
|
333
|
+
const { country } = model.delivery.address;
|
|
334
|
+
if (country === null)
|
|
335
|
+
out.push({ code: 'BR-57', message: 'The delivery address has no country.' });
|
|
336
|
+
else if (!COUNTRY_CODES.has(country))
|
|
337
|
+
out.push({ code: 'BR-CL-14', message: `${country} is not an ISO 3166-1 country code.` });
|
|
338
|
+
}
|
|
339
|
+
// --- Payment ------------------------------------------------------------
|
|
340
|
+
if (model.paymentWithoutMeans) {
|
|
341
|
+
out.push({
|
|
342
|
+
code: 'payment-means-missing',
|
|
343
|
+
message: 'An account or a payment reference was given without a payment means code (UNTDID 4461). The format files both under the code, so neither was written.',
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
if (model.payment) {
|
|
347
|
+
const { meansCode, iban } = model.payment;
|
|
348
|
+
if (!PAYMENT_MEANS_CODES.has(meansCode)) {
|
|
349
|
+
out.push({ code: 'BR-CL-16', message: `${meansCode} is not a UNTDID 4461 payment means code.` });
|
|
350
|
+
}
|
|
351
|
+
if ((meansCode === '30' || meansCode === '58') && iban === null) {
|
|
352
|
+
out.push({ code: 'BR-61', message: `Payment means ${meansCode} is a credit transfer, and no account to transfer to is given.` });
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (model.kind === 'Invoice' && model.payable.units > 0n && model.dueDate === null && model.paymentTerms === null) {
|
|
356
|
+
out.push({ code: 'BR-CO-25', message: `${money(model.payable)} is due and the invoice says neither when nor on what terms.` });
|
|
357
|
+
}
|
|
358
|
+
// --- Lines --------------------------------------------------------------
|
|
359
|
+
for (const line of model.lines)
|
|
360
|
+
lineRules(line, out);
|
|
361
|
+
// --- The VAT breakdown ----------------------------------------------------
|
|
362
|
+
if (model.subtotals.length === 0) {
|
|
363
|
+
// Once for the standard, once for Peppol, which counts the totals that have groups.
|
|
364
|
+
out.push({ code: 'BR-CO-18', message: 'The document has no VAT breakdown.' }, { code: 'PEPPOL-EN16931-R053', message: 'The document has no VAT total with a breakdown, and Peppol wants exactly one.' },
|
|
365
|
+
// The total is still written, because the books have one; and a total
|
|
366
|
+
// with nothing under it is what Peppol keeps for a second currency.
|
|
367
|
+
{ code: 'PEPPOL-EN16931-R054', message: 'The VAT total stands without a breakdown, which Peppol allows only for a total in a second currency.' });
|
|
368
|
+
}
|
|
369
|
+
for (const subtotal of model.subtotals)
|
|
370
|
+
subtotalRules(model, subtotal, out);
|
|
371
|
+
for (const [category, family] of Object.entries(FAMILIES)) {
|
|
372
|
+
const onLines = model.lines.some((line) => line.category === category);
|
|
373
|
+
const groups = model.subtotals.filter((subtotal) => subtotal.category === category).length;
|
|
374
|
+
// BR-*-01. The standard rate has one group per rate and wants at least one;
|
|
375
|
+
// every other category has exactly one, and a group without a line is as
|
|
376
|
+
// much of a mismatch as a line without a group.
|
|
377
|
+
const broken = category === 'S' ? onLines !== groups > 0 : (onLines || groups > 0) && groups !== 1;
|
|
378
|
+
if (broken) {
|
|
379
|
+
out.push({
|
|
380
|
+
code: `BR-${family}-01`,
|
|
381
|
+
message: onLines
|
|
382
|
+
? `Lines are in VAT category ${category} and the breakdown has ${groups === 0 ? 'no group' : `${groups} groups`} for it.`
|
|
383
|
+
: `The breakdown has a group for VAT category ${category} and no line is in it.`,
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
if (!onLines)
|
|
387
|
+
continue;
|
|
388
|
+
// BR-*-02: who has to be identified for VAT when a line is in this category.
|
|
389
|
+
const sellerVat = model.seller.vatId !== null;
|
|
390
|
+
const buyerVat = model.buyer.vatId !== null;
|
|
391
|
+
if (category === 'O') {
|
|
392
|
+
if (sellerVat || buyerVat) {
|
|
393
|
+
out.push({ code: 'BR-O-02', message: 'A document outside the scope of VAT carries no VAT identifier, and this one carries one.' });
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else if (!sellerVat) {
|
|
397
|
+
out.push({ code: `BR-${family}-02`, message: `A line is in VAT category ${category} and the seller has no VAT identifier.` });
|
|
398
|
+
}
|
|
399
|
+
else if (category === 'K' && !buyerVat) {
|
|
400
|
+
out.push({ code: 'BR-IC-02', message: 'An intra-community supply names the VAT identifier of the buyer, and the buyer has none.' });
|
|
401
|
+
}
|
|
402
|
+
else if (category === 'AE' && !buyerVat && model.buyer.legalId === null) {
|
|
403
|
+
out.push({ code: 'BR-AE-02', message: 'A reverse charge names the buyer by a VAT identifier or a registration number, and the buyer has neither.' });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const categories = new Set(model.subtotals.map((subtotal) => subtotal.category));
|
|
407
|
+
if (categories.has('O')) {
|
|
408
|
+
if (categories.size > 1)
|
|
409
|
+
out.push({ code: 'BR-O-11', message: 'A breakdown with a group outside the scope of VAT has no other group.' });
|
|
410
|
+
if (model.lines.some((line) => line.category !== 'O')) {
|
|
411
|
+
out.push({ code: 'BR-O-12', message: 'A document with a group outside the scope of VAT has no line in another category.' });
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (categories.has('K')) {
|
|
415
|
+
if (model.delivery?.date == null) {
|
|
416
|
+
out.push({ code: 'BR-IC-11', message: 'An intra-community supply says when the goods were delivered, and this one has no delivery date.' });
|
|
417
|
+
}
|
|
418
|
+
if (model.delivery?.address?.country == null) {
|
|
419
|
+
out.push({ code: 'BR-IC-12', message: 'An intra-community supply says which country the goods were delivered to, and this one has no delivery country.' });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
// --- Totals -------------------------------------------------------------
|
|
423
|
+
const decimals = [
|
|
424
|
+
['BR-DEC-09', model.lineTotal, 'The sum of the lines'],
|
|
425
|
+
['BR-DEC-12', model.taxExclusive, 'The total without VAT'],
|
|
426
|
+
['BR-DEC-14', model.taxInclusive, 'The total with VAT'],
|
|
427
|
+
['BR-DEC-16', model.prepaid, 'The amount paid'],
|
|
428
|
+
['BR-DEC-18', model.payable, 'The amount due'],
|
|
429
|
+
];
|
|
430
|
+
for (const [code, value, what] of decimals)
|
|
431
|
+
decimalsRule(code, value, what, out);
|
|
432
|
+
// The total VAT has a rule of its own, BR-DEC-13, and the published
|
|
433
|
+
// Schematron never reports it: its test looks for the currency of the
|
|
434
|
+
// document underneath the amount, where it is not. The rule of the binding
|
|
435
|
+
// catches the same digits, and it is the one that is reported here.
|
|
436
|
+
if (significantScale(model.taxTotal) > 2) {
|
|
437
|
+
out.push({ code: 'UBL-DT-01', message: `The total VAT, ${formatDecimal(model.taxTotal)}, has more than two decimals.` });
|
|
438
|
+
}
|
|
439
|
+
const lines = sum(model.lines.map((line) => line.netAmount));
|
|
440
|
+
if (!equal(model.lineTotal, roundXPath(lines, 2))) {
|
|
441
|
+
out.push({ code: 'BR-CO-10', message: `The lines add up to ${money(lines)} and the document says ${money(model.lineTotal)}.` });
|
|
442
|
+
}
|
|
443
|
+
const taxes = sum(model.subtotals.map((subtotal) => subtotal.tax));
|
|
444
|
+
if (model.subtotals.length > 0 && !equal(model.taxTotal, roundXPath(taxes, 2))) {
|
|
445
|
+
out.push({ code: 'BR-CO-14', message: `The VAT groups add up to ${money(taxes)} and the document says ${money(model.taxTotal)}.` });
|
|
446
|
+
}
|
|
447
|
+
if (!equal(model.taxInclusive, roundXPath(add(model.taxExclusive, model.taxTotal), 2))) {
|
|
448
|
+
out.push({
|
|
449
|
+
code: 'BR-CO-15',
|
|
450
|
+
message: `${money(model.taxExclusive)} without VAT and ${money(model.taxTotal)} of VAT are not the ${money(model.taxInclusive)} the document totals.`,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
// BR-CO-16 rounds the difference where something was paid and compares the
|
|
454
|
+
// two figures as they stand where nothing was — which is how it is written,
|
|
455
|
+
// and the difference shows on an amount with a third decimal.
|
|
456
|
+
const due = model.prepaid === null ? model.taxInclusive : roundXPath(subtract(model.taxInclusive, model.prepaid), 2);
|
|
457
|
+
if (!equal(model.payable, due)) {
|
|
458
|
+
out.push({
|
|
459
|
+
code: 'BR-CO-16',
|
|
460
|
+
message: `${money(model.taxInclusive)} less ${money(model.prepaid ?? ZERO)} already paid is not the ${money(model.payable)} the document says is due.`,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
return out;
|
|
464
|
+
}
|
|
465
|
+
//# sourceMappingURL=rules.js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