@fin.cx/einvoice 9.0.0 → 10.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist_ts/00_commitinfo_data.js +2 -2
  2. package/dist_ts/einvoice.d.ts +12 -0
  3. package/dist_ts/einvoice.js +45 -3
  4. package/dist_ts/formats/base/base.decoder.d.ts +27 -2
  5. package/dist_ts/formats/base/base.decoder.js +52 -27
  6. package/dist_ts/formats/cii/cii.decoder.d.ts +89 -6
  7. package/dist_ts/formats/cii/cii.decoder.js +125 -30
  8. package/dist_ts/formats/cii/cii.encoder.d.ts +71 -1
  9. package/dist_ts/formats/cii/cii.encoder.js +191 -12
  10. package/dist_ts/formats/cii/cii.types.d.ts +2 -5
  11. package/dist_ts/formats/cii/cii.types.js +7 -9
  12. package/dist_ts/formats/cii/cii.validator.d.ts +13 -6
  13. package/dist_ts/formats/cii/cii.validator.js +29 -30
  14. package/dist_ts/formats/cii/facturx/facturx.decoder.js +15 -3
  15. package/dist_ts/formats/cii/facturx/facturx.encoder.d.ts +0 -6
  16. package/dist_ts/formats/cii/facturx/facturx.encoder.js +11 -25
  17. package/dist_ts/formats/cii/facturx/facturx.types.d.ts +0 -5
  18. package/dist_ts/formats/cii/facturx/facturx.types.js +1 -8
  19. package/dist_ts/formats/cii/facturx/facturx.validator.d.ts +0 -5
  20. package/dist_ts/formats/cii/facturx/facturx.validator.js +5 -29
  21. package/dist_ts/formats/cii/zugferd/zugferd.decoder.js +15 -2
  22. package/dist_ts/formats/cii/zugferd/zugferd.encoder.d.ts +0 -7
  23. package/dist_ts/formats/cii/zugferd/zugferd.encoder.js +9 -67
  24. package/dist_ts/formats/cii/zugferd/zugferd.types.d.ts +0 -5
  25. package/dist_ts/formats/cii/zugferd/zugferd.types.js +1 -8
  26. package/dist_ts/formats/cii/zugferd/zugferd.v1.decoder.d.ts +26 -0
  27. package/dist_ts/formats/cii/zugferd/zugferd.v1.decoder.js +43 -1
  28. package/dist_ts/formats/cii/zugferd/zugferd.validator.js +6 -2
  29. package/dist_ts/formats/semantic/semantic.adapter.js +20 -18
  30. package/dist_ts/formats/ubl/en16931.ubl.validator.d.ts +0 -4
  31. package/dist_ts/formats/ubl/en16931.ubl.validator.js +5 -42
  32. package/dist_ts/formats/ubl/generic/ubl.encoder.js +18 -24
  33. package/dist_ts/formats/ubl/ubl.decoder.d.ts +4 -0
  34. package/dist_ts/formats/ubl/ubl.decoder.js +9 -1
  35. package/dist_ts/formats/ubl/ubl.encoder.js +9 -5
  36. package/dist_ts/formats/ubl/ubl.validator.d.ts +13 -0
  37. package/dist_ts/formats/ubl/ubl.validator.js +28 -1
  38. package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.js +10 -1
  39. package/dist_ts/formats/ubl/xrechnung/xrechnung.encoder.d.ts +0 -7
  40. package/dist_ts/formats/ubl/xrechnung/xrechnung.encoder.js +30 -45
  41. package/dist_ts/formats/ubl/xrechnung.validator.d.ts +5 -4
  42. package/dist_ts/formats/ubl/xrechnung.validator.js +71 -68
  43. package/dist_ts/formats/utils/date.value.d.ts +35 -0
  44. package/dist_ts/formats/utils/date.value.js +98 -1
  45. package/dist_ts/formats/utils/format.detector.js +16 -10
  46. package/dist_ts/formats/utils/party.contact.d.ts +16 -0
  47. package/dist_ts/formats/utils/party.contact.js +16 -0
  48. package/dist_ts/formats/utils/party.identifier.d.ts +28 -0
  49. package/dist_ts/formats/utils/party.identifier.js +49 -0
  50. package/dist_ts/formats/utils/peppol.profile.d.ts +10 -0
  51. package/dist_ts/formats/utils/peppol.profile.js +12 -0
  52. package/dist_ts/formats/utils/seller.identifier.d.ts +46 -0
  53. package/dist_ts/formats/utils/seller.identifier.js +78 -0
  54. package/dist_ts/formats/utils/stated.values.d.ts +80 -0
  55. package/dist_ts/formats/utils/stated.values.js +418 -0
  56. package/dist_ts/formats/utils/vat.category.d.ts +30 -2
  57. package/dist_ts/formats/utils/vat.category.js +36 -6
  58. package/dist_ts/formats/utils/vat.id.d.ts +18 -0
  59. package/dist_ts/formats/utils/vat.id.js +22 -0
  60. package/dist_ts/formats/validation/conformance.harness.js +6 -6
  61. package/dist_ts/formats/validation/en16931.business-rules.validator.js +4 -21
  62. package/dist_ts/formats/validation/facturx.validator.js +6 -6
  63. package/dist_ts/formats/validation/integrated.validator.js +4 -13
  64. package/dist_ts/formats/validation/peppol.validator.js +6 -13
  65. package/dist_ts/formats/validation/validation.types.d.ts +5 -0
  66. package/dist_ts/formats/validation/validation.types.js +6 -1
  67. package/dist_ts/formats/validation/vat-categories.validator.d.ts +21 -42
  68. package/dist_ts/formats/validation/vat-categories.validator.js +137 -431
  69. package/dist_ts/formats/validation/xrechnung.validator.d.ts +11 -58
  70. package/dist_ts/formats/validation/xrechnung.validator.js +58 -324
  71. package/dist_ts/index.d.ts +1 -0
  72. package/dist_ts/index.js +1 -1
  73. package/dist_ts/interfaces/en16931-metadata.d.ts +0 -4
  74. package/dist_ts/interfaces/stated.values.d.ts +93 -0
  75. package/dist_ts/interfaces/stated.values.js +2 -0
  76. package/package.json +4 -4
  77. package/readme.md +152 -7
  78. package/ts/00_commitinfo_data.ts +1 -1
  79. package/ts/einvoice.ts +52 -2
  80. package/ts/formats/base/base.decoder.ts +55 -45
  81. package/ts/formats/cii/cii.decoder.ts +159 -32
  82. package/ts/formats/cii/cii.encoder.ts +206 -14
  83. package/ts/formats/cii/cii.types.ts +7 -9
  84. package/ts/formats/cii/cii.validator.ts +30 -32
  85. package/ts/formats/cii/facturx/facturx.decoder.ts +16 -2
  86. package/ts/formats/cii/facturx/facturx.encoder.ts +13 -25
  87. package/ts/formats/cii/facturx/facturx.types.ts +0 -9
  88. package/ts/formats/cii/facturx/facturx.validator.ts +5 -43
  89. package/ts/formats/cii/zugferd/zugferd.decoder.ts +16 -1
  90. package/ts/formats/cii/zugferd/zugferd.encoder.ts +10 -72
  91. package/ts/formats/cii/zugferd/zugferd.types.ts +0 -9
  92. package/ts/formats/cii/zugferd/zugferd.v1.decoder.ts +56 -0
  93. package/ts/formats/cii/zugferd/zugferd.validator.ts +5 -1
  94. package/ts/formats/semantic/semantic.adapter.ts +19 -17
  95. package/ts/formats/ubl/en16931.ubl.validator.ts +5 -64
  96. package/ts/formats/ubl/generic/ubl.encoder.ts +19 -23
  97. package/ts/formats/ubl/ubl.decoder.ts +12 -0
  98. package/ts/formats/ubl/ubl.encoder.ts +8 -4
  99. package/ts/formats/ubl/ubl.validator.ts +29 -0
  100. package/ts/formats/ubl/xrechnung/xrechnung.decoder.ts +8 -0
  101. package/ts/formats/ubl/xrechnung/xrechnung.encoder.ts +33 -45
  102. package/ts/formats/ubl/xrechnung.validator.ts +75 -127
  103. package/ts/formats/utils/date.value.ts +106 -0
  104. package/ts/formats/utils/format.detector.ts +15 -9
  105. package/ts/formats/utils/party.contact.ts +30 -0
  106. package/ts/formats/utils/party.identifier.ts +61 -0
  107. package/ts/formats/utils/peppol.profile.ts +13 -0
  108. package/ts/formats/utils/seller.identifier.ts +102 -0
  109. package/ts/formats/utils/stated.values.ts +499 -0
  110. package/ts/formats/utils/vat.category.ts +47 -5
  111. package/ts/formats/utils/vat.id.ts +24 -0
  112. package/ts/formats/validation/conformance.harness.ts +5 -5
  113. package/ts/formats/validation/en16931.business-rules.validator.ts +3 -28
  114. package/ts/formats/validation/facturx.validator.ts +5 -5
  115. package/ts/formats/validation/integrated.validator.ts +3 -16
  116. package/ts/formats/validation/peppol.validator.ts +5 -16
  117. package/ts/formats/validation/validation.types.ts +7 -1
  118. package/ts/formats/validation/vat-categories.validator.ts +179 -761
  119. package/ts/formats/validation/xrechnung.validator.ts +61 -382
  120. package/ts/index.ts +9 -0
  121. package/ts/interfaces/en16931-metadata.ts +3 -7
  122. package/ts/interfaces/stated.values.ts +94 -0
  123. package/ts/readme.md +1 -1
  124. package/dist_ts/formats/utils/eu.memberstates.d.ts +0 -11
  125. package/dist_ts/formats/utils/eu.memberstates.js +0 -16
  126. package/ts/formats/utils/eu.memberstates.ts +0 -16
@@ -0,0 +1,46 @@
1
+ import type { TAccountingDoc } from '../../interfaces/common.js';
2
+ /**
3
+ * The official text of EN 16931 BR-CO-26 (CEN/TC 434 EN 16931 validation
4
+ * artefacts 1.3.16, fatal in UBL and CII)
5
+ */
6
+ export declare const BR_CO_26_TEXT = "In order for the buyer to automatically identify a supplier, the Seller identifier (BT-29), the Seller legal registration identifier (BT-30) and/or the Seller VAT identifier (BT-31) shall be present.";
7
+ /**
8
+ * Whether the seller of a UBL document meets BR-CO-26, as the CEN artefacts
9
+ * check it on `cac:AccountingSupplierParty`: a VAT identifier (BT-31, a
10
+ * `cac:PartyTaxScheme` with the scheme VAT), a seller identifier (BT-29, a
11
+ * `cac:PartyIdentification` whose scheme is not SEPA) or a legal registration
12
+ * identifier (BT-30, `cac:PartyLegalEntity/cbc:CompanyID`). A document without
13
+ * a seller party is not checked; BR-06 and BR-08 report that.
14
+ * @param doc The UBL document
15
+ */
16
+ export declare const ublSellerMeetsBrCo26: (doc: Document) => boolean;
17
+ /**
18
+ * Whether the seller of a CII document meets BR-CO-26, as the CEN artefacts
19
+ * check it on `ram:SellerTradeParty`: a seller identifier (BT-29, `ram:ID` or
20
+ * `ram:GlobalID`), a legal registration identifier (BT-30,
21
+ * `ram:SpecifiedLegalOrganization/ram:ID`) or a VAT identifier (BT-31,
22
+ * `ram:SpecifiedTaxRegistration/ram:ID` with the scheme VA).
23
+ * @param doc The CII document
24
+ */
25
+ export declare const ciiSellerMeetsBrCo26: (doc: Document) => boolean;
26
+ /**
27
+ * Whether the seller of an envelope states an identifier BR-CO-26 accepts:
28
+ * the VAT identifier (BT-31, `registrationDetails.vatId`), the legal
29
+ * registration identifier (BT-30, `registrationDetails.registrationId`) or a
30
+ * seller identifier (BT-29), which a decoded UBL document keeps in the
31
+ * party's `additionalIdentifiers`. A tax number (BT-32) is none of them.
32
+ * @param accountingDoc The document
33
+ */
34
+ export declare const envelopeSellerMeetsBrCo26: (accountingDoc: Pick<TAccountingDoc, "from">) => boolean;
35
+ /**
36
+ * Refuses a written document whose seller fails BR-CO-26, naming the rule; no
37
+ * identifier is put in place of a missing one. The seller states its VAT
38
+ * identifier (`registrationDetails.vatId`, BT-31) or its legal registration
39
+ * identifier (`registrationDetails.registrationId`, BT-30); a tax number
40
+ * (BT-32) alone does not identify it. A seller identifier (BT-29) is written
41
+ * from the party's `additionalIdentifiers` (no typed field in the envelope).
42
+ * @param xml The written document
43
+ * @param syntax The syntax it is written in
44
+ * @param targetFormat The format being written
45
+ */
46
+ export declare const assertSellerIdentified: (xml: string, syntax: "ubl" | "cii", targetFormat: string) => void;
@@ -0,0 +1,78 @@
1
+ import { EInvoiceFormatError } from '../../errors.js';
2
+ import { DOMParser, xpath } from '../../plugins.js';
3
+ import { CII_NAMESPACES } from '../cii/cii.types.js';
4
+ import { UBL_NAMESPACES } from '../ubl/ubl.types.js';
5
+ import { getPartyIdentifiers } from './party.identifier.js';
6
+ /**
7
+ * The official text of EN 16931 BR-CO-26 (CEN/TC 434 EN 16931 validation
8
+ * artefacts 1.3.16, fatal in UBL and CII)
9
+ */
10
+ export const BR_CO_26_TEXT = 'In order for the buyer to automatically identify a supplier, the Seller identifier (BT-29), the Seller legal registration identifier (BT-30) and/or the Seller VAT identifier (BT-31) shall be present.';
11
+ const ublSelect = xpath.useNamespaces({ cac: UBL_NAMESPACES.CAC, cbc: UBL_NAMESPACES.CBC });
12
+ const ciiSelect = xpath.useNamespaces({ rsm: CII_NAMESPACES.RSM, ram: CII_NAMESPACES.RAM });
13
+ const nodesOf = (result) => (Array.isArray(result) ? result : []);
14
+ /**
15
+ * Whether the seller of a UBL document meets BR-CO-26, as the CEN artefacts
16
+ * check it on `cac:AccountingSupplierParty`: a VAT identifier (BT-31, a
17
+ * `cac:PartyTaxScheme` with the scheme VAT), a seller identifier (BT-29, a
18
+ * `cac:PartyIdentification` whose scheme is not SEPA) or a legal registration
19
+ * identifier (BT-30, `cac:PartyLegalEntity/cbc:CompanyID`). A document without
20
+ * a seller party is not checked; BR-06 and BR-08 report that.
21
+ * @param doc The UBL document
22
+ */
23
+ export const ublSellerMeetsBrCo26 = (doc) => {
24
+ const sellers = nodesOf(ublSelect('/*/cac:AccountingSupplierParty', doc));
25
+ return sellers.every((seller) => {
26
+ const vatSchemes = nodesOf(ublSelect('./cac:Party/cac:PartyTaxScheme/cac:TaxScheme/cbc:ID', seller)).filter((node) => (node.textContent ?? '').trim().toUpperCase() === 'VAT');
27
+ const hasVatIdentifier = vatSchemes.some((scheme) => nodesOf(ublSelect('../../cbc:CompanyID', scheme)).length > 0);
28
+ const hasSellerIdentifier = nodesOf(ublSelect("./cac:Party/cac:PartyIdentification/cbc:ID[not(@schemeID = 'SEPA')]", seller)).length > 0;
29
+ const hasLegalRegistration = nodesOf(ublSelect('./cac:Party/cac:PartyLegalEntity/cbc:CompanyID', seller)).length > 0;
30
+ return hasVatIdentifier || hasSellerIdentifier || hasLegalRegistration;
31
+ });
32
+ };
33
+ /**
34
+ * Whether the seller of a CII document meets BR-CO-26, as the CEN artefacts
35
+ * check it on `ram:SellerTradeParty`: a seller identifier (BT-29, `ram:ID` or
36
+ * `ram:GlobalID`), a legal registration identifier (BT-30,
37
+ * `ram:SpecifiedLegalOrganization/ram:ID`) or a VAT identifier (BT-31,
38
+ * `ram:SpecifiedTaxRegistration/ram:ID` with the scheme VA).
39
+ * @param doc The CII document
40
+ */
41
+ export const ciiSellerMeetsBrCo26 = (doc) => nodesOf(ciiSelect('//ram:SellerTradeParty', doc)).every((seller) => nodesOf(ciiSelect("./ram:ID | ./ram:GlobalID | ./ram:SpecifiedLegalOrganization/ram:ID | ./ram:SpecifiedTaxRegistration/ram:ID[@schemeID='VA']", seller)).length > 0);
42
+ /**
43
+ * Whether the seller of an envelope states an identifier BR-CO-26 accepts:
44
+ * the VAT identifier (BT-31, `registrationDetails.vatId`), the legal
45
+ * registration identifier (BT-30, `registrationDetails.registrationId`) or a
46
+ * seller identifier (BT-29), which a decoded UBL document keeps in the
47
+ * party's `additionalIdentifiers`. A tax number (BT-32) is none of them.
48
+ * @param accountingDoc The document
49
+ */
50
+ export const envelopeSellerMeetsBrCo26 = (accountingDoc) => {
51
+ const seller = accountingDoc.from;
52
+ if (!seller) {
53
+ return true;
54
+ }
55
+ const details = seller.registrationDetails;
56
+ const hasSellerIdentifier = getPartyIdentifiers(seller).some((identifier) => identifier.scheme?.toUpperCase() !== 'SEPA');
57
+ return Boolean(details?.vatId?.trim() || details?.registrationId?.trim() || hasSellerIdentifier);
58
+ };
59
+ const writtenParser = new DOMParser();
60
+ /**
61
+ * Refuses a written document whose seller fails BR-CO-26, naming the rule; no
62
+ * identifier is put in place of a missing one. The seller states its VAT
63
+ * identifier (`registrationDetails.vatId`, BT-31) or its legal registration
64
+ * identifier (`registrationDetails.registrationId`, BT-30); a tax number
65
+ * (BT-32) alone does not identify it. A seller identifier (BT-29) is written
66
+ * from the party's `additionalIdentifiers` (no typed field in the envelope).
67
+ * @param xml The written document
68
+ * @param syntax The syntax it is written in
69
+ * @param targetFormat The format being written
70
+ */
71
+ export const assertSellerIdentified = (xml, syntax, targetFormat) => {
72
+ const doc = writtenParser.parseFromString(xml, 'application/xml');
73
+ const meets = syntax === 'ubl' ? ublSellerMeetsBrCo26(doc) : ciiSellerMeetsBrCo26(doc);
74
+ if (!meets) {
75
+ throw new EInvoiceFormatError(`BR-CO-26: ${BR_CO_26_TEXT} The seller states none of them: set from.registrationDetails.vatId (BT-31) or .registrationId (BT-30), or give the seller a seller identifier (BT-29) in from.additionalIdentifiers, where a decoded document keeps it; a tax number (BT-32, .taxNumber) does not identify the seller`, { targetFormat, unsupportedFeatures: ['BR-CO-26'] });
76
+ }
77
+ };
78
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VsbGVyLmlkZW50aWZpZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi90cy9mb3JtYXRzL3V0aWxzL3NlbGxlci5pZGVudGlmaWV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tJQUN2RyxNQUFNLEdBQUcsR0FBRyxhQUFhLENBQUMsZUFBZSxDQUFDLEdBQUcsRUFBRSxpQkFBaUIsQ0FBQyxDQUFDO0lBQ2xFLE1BQU0sS0FBSyxHQUFHLE1BQU0sS0FBSyxLQUFLLENBQUMsQ0FBQyxDQUFDLG9CQUFvQixDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxvQkFBb0IsQ0FBQyxHQUFHLENBQUMsQ0FBQztJQUN2RixJQUFJLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDWCxNQUFNLElBQUksbUJBQW1CLENBQzNCLGFBQWEsYUFBYSx3UkFBd1IsRUFDbFQsRUFBRSxZQUFZLEVBQUUsbUJBQW1CLEVBQUUsQ0FBQyxVQUFVLENBQUMsRUFBRSxDQUNwRCxDQUFDO0lBQ0osQ0FBQztBQUNILENBQUMsQ0FBQyJ9
@@ -0,0 +1,80 @@
1
+ import type { IEInvoiceStatedValues } from '../../interfaces/stated.values.js';
2
+ import type { IDocumentTotals } from './document.totals.js';
3
+ /** A stated value that is no decimal number, by business term and the text found */
4
+ export interface IStatedValueProblem {
5
+ businessTerm: string;
6
+ text: string;
7
+ }
8
+ /**
9
+ * The message for a stated amount that is no decimal number, as the paid
10
+ * amount's has been: "The paid amount (BT-113) is no decimal number: …"
11
+ * @param problem The problem
12
+ */
13
+ export declare const statedValueProblemMessage: (problem: IStatedValueProblem) => string;
14
+ /** The stated values of a document, and the stated amounts that are no number */
15
+ export interface IStatedValuesRead {
16
+ values: IEInvoiceStatedValues;
17
+ problems: IStatedValueProblem[];
18
+ /** How many VAT totals (BT-110) in the document currency the document states; BR-CO-15 asks for exactly one */
19
+ documentCurrencyTaxTotals?: number;
20
+ /** Each `cac:TaxTotal` of a UBL document with its tax amount and the tax amounts of its own subtotals, which BR-CO-14 compares */
21
+ ublTaxTotals?: Array<{
22
+ taxAmount?: number;
23
+ subtotalTaxAmounts: Array<number | undefined>;
24
+ }>;
25
+ }
26
+ /** A finding on stated values: the rule, its official text and where it applies */
27
+ export interface IStatedValueFinding {
28
+ ruleId: string;
29
+ message: string;
30
+ location: string;
31
+ }
32
+ /**
33
+ * Reads the stated values of a UBL invoice or credit note: the document totals
34
+ * (`cac:LegalMonetaryTotal`, BT-106 to BT-115, the VAT total `cac:TaxTotal/cbc:TaxAmount`
35
+ * in the document currency for BT-110 and in the VAT accounting currency for
36
+ * BT-111), the VAT breakdown (`cac:TaxSubtotal`, BT-116 to BT-121), the line
37
+ * amounts (BT-126, BT-131, BT-151, BT-152) and the document level allowances
38
+ * and charges (`cac:AllowanceCharge`, BT-92 to BT-105)
39
+ * @param doc The UBL document
40
+ */
41
+ export declare const readUblStatedValues: (doc: Document) => IStatedValuesRead;
42
+ /**
43
+ * Reads the stated values of a CII (D16B) document: the document totals of the
44
+ * header settlement (`ram:SpecifiedTradeSettlementHeaderMonetarySummation`,
45
+ * BT-106 to BT-115, `ram:TaxTotalAmount` in the invoice currency for BT-110 and
46
+ * in the VAT accounting currency for BT-111), the VAT breakdown (the header
47
+ * `ram:ApplicableTradeTax`, BT-116 to BT-121), the line amounts (BT-126,
48
+ * BT-131, BT-151, BT-152) and the document level allowances and charges (the
49
+ * header `ram:SpecifiedTradeAllowanceCharge`, BT-92 to BT-105)
50
+ * @param doc The CII document
51
+ */
52
+ export declare const readCiiStatedValues: (doc: Document) => IStatedValuesRead;
53
+ /**
54
+ * Checks the stated values of a document against each other as the EN 16931
55
+ * rules BR-CO-10 to BR-CO-17 do in the CEN artefacts 1.3.16: each sum rounded
56
+ * to two decimals, BR-CO-17 with the artefacts' tolerance of one unit (UBL
57
+ * strictly within it, CII up to it). A rule whose amounts the document does
58
+ * not state is not checked; the rules on the presence of the totals (BR-12 to
59
+ * BR-15) report that.
60
+ * @param read The stated values read from the document
61
+ * @param syntax The document's syntax
62
+ */
63
+ export declare const findStatedValueDisagreements: (read: IStatedValuesRead, syntax: "ubl" | "cii") => IStatedValueFinding[];
64
+ /** The package's code for a stated value the envelope computes differently */
65
+ export declare const STATED_VALUE_DIFFERS_CODE = "EINVOICE-STATED-DIFFERS";
66
+ /**
67
+ * The stated values of a loaded document that the envelope's computation
68
+ * (`computeDocumentTotals`, what `totalNet`, `totalVat`, `totalGross` and the
69
+ * encoders give) does not reproduce: the totals BT-106, BT-109, BT-110,
70
+ * BT-112 and BT-115, each line's net amount (BT-131) and VAT category
71
+ * (BT-151), and each VAT breakdown's category, rate and amounts (BG-23). No
72
+ * EN 16931 rule is broken by such a difference, so it is the package's own
73
+ * finding: the envelope has no document or line allowances and charges and no
74
+ * price base quantity, and every line is standard rated or reverse charge.
75
+ * Neither value is changed.
76
+ * @param values The stated values
77
+ * @param totals The envelope's computation
78
+ * @param paidAmount The envelope's paid amount (BT-113)
79
+ */
80
+ export declare const findEnvelopeDifferences: (values: IEInvoiceStatedValues, totals: IDocumentTotals, paidAmount: number | undefined) => IStatedValueFinding[];