@fin.cx/einvoice 10.0.0 → 10.1.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_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/einvoice.d.ts +2 -0
- package/dist_ts/einvoice.js +7 -13
- package/dist_ts/formats/base/base.decoder.d.ts +9 -1
- package/dist_ts/formats/base/base.decoder.js +24 -12
- package/dist_ts/formats/cii/cii.decoder.d.ts +11 -3
- package/dist_ts/formats/cii/cii.decoder.js +27 -8
- package/dist_ts/formats/cii/cii.encoder.d.ts +12 -0
- package/dist_ts/formats/cii/cii.encoder.js +36 -1
- package/dist_ts/formats/cii/cii.types.js +2 -1
- package/dist_ts/formats/cii/facturx/facturx.encoder.js +12 -8
- package/dist_ts/formats/cii/zugferd/zugferd.encoder.js +12 -8
- package/dist_ts/formats/semantic/semantic.adapter.d.ts +0 -4
- package/dist_ts/formats/semantic/semantic.adapter.js +7 -18
- package/dist_ts/formats/ubl/generic/ubl.encoder.d.ts +6 -1
- package/dist_ts/formats/ubl/generic/ubl.encoder.js +40 -8
- package/dist_ts/formats/ubl/ubl.decoder.d.ts +11 -0
- package/dist_ts/formats/ubl/ubl.decoder.js +30 -1
- package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.js +3 -3
- package/dist_ts/formats/utils/date.value.d.ts +24 -0
- package/dist_ts/formats/utils/date.value.js +77 -12
- package/dist_ts/formats/utils/delivery.address.d.ts +18 -0
- package/dist_ts/formats/utils/delivery.address.js +30 -0
- package/dist_ts/formats/utils/document.totals.d.ts +5 -4
- package/dist_ts/formats/utils/document.totals.js +24 -8
- package/dist_ts/formats/utils/stated.values.js +4 -2
- package/dist_ts/formats/utils/vat.category.d.ts +146 -55
- package/dist_ts/formats/utils/vat.category.js +357 -69
- package/dist_ts/formats/validation/vat-categories.validator.d.ts +14 -15
- package/dist_ts/formats/validation/vat-categories.validator.js +123 -85
- package/package.json +5 -5
- package/readme.md +61 -20
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/einvoice.ts +8 -14
- package/ts/formats/base/base.decoder.ts +24 -17
- package/ts/formats/cii/cii.decoder.ts +28 -7
- package/ts/formats/cii/cii.encoder.ts +36 -0
- package/ts/formats/cii/cii.types.ts +1 -0
- package/ts/formats/cii/facturx/facturx.encoder.ts +12 -7
- package/ts/formats/cii/zugferd/zugferd.encoder.ts +12 -7
- package/ts/formats/semantic/semantic.adapter.ts +6 -15
- package/ts/formats/ubl/generic/ubl.encoder.ts +40 -7
- package/ts/formats/ubl/ubl.decoder.ts +31 -0
- package/ts/formats/ubl/xrechnung/xrechnung.decoder.ts +2 -2
- package/ts/formats/utils/date.value.ts +84 -11
- package/ts/formats/utils/delivery.address.ts +36 -0
- package/ts/formats/utils/document.totals.ts +38 -11
- package/ts/formats/utils/stated.values.ts +4 -1
- package/ts/formats/utils/vat.category.ts +426 -95
- package/ts/formats/validation/vat-categories.validator.ts +169 -88
|
@@ -1,83 +1,174 @@
|
|
|
1
1
|
import type { TAccountingDoc } from '../../interfaces/common.js';
|
|
2
|
+
import type { finance } from '@tsclass/tsclass';
|
|
3
|
+
type TAccountingDocItem = finance.TAccountingDocItem;
|
|
4
|
+
import type { IEInvoiceStatedValues } from '../../interfaces/stated.values.js';
|
|
2
5
|
/**
|
|
3
|
-
* The VAT category codes (UNTDID 5305, EN 16931 BT-118/BT-151)
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* The VAT category codes (UNTDID 5305, EN 16931 BT-118/BT-151) an item can
|
|
7
|
+
* state (`TAccountingDocItem.vatCategory`): standard rated (S), zero rated (Z),
|
|
8
|
+
* exempt (E), reverse charge (AE), intra-community supply (K), export outside
|
|
9
|
+
* the EU (G), not subject to VAT (O), IGIC (L) and IPSI (M).
|
|
10
|
+
*/
|
|
11
|
+
export type TVatCategoryCode = finance.TVatCategory;
|
|
12
|
+
/** Every VAT category code EN 16931 allows, in the order of `TVatCategoryCode` */
|
|
13
|
+
export declare const VAT_CATEGORY_CODES: readonly TVatCategoryCode[];
|
|
14
|
+
/**
|
|
15
|
+
* Whether a value is a VAT category code EN 16931 allows
|
|
16
|
+
* @param value The value
|
|
17
|
+
*/
|
|
18
|
+
export declare const isVatCategoryCode: (value: unknown) => value is TVatCategoryCode;
|
|
19
|
+
/**
|
|
20
|
+
* The categories whose VAT breakdown states an exemption reason, as a code
|
|
21
|
+
* (BT-121) or a text (BT-120): exempt (BR-E-10), reverse charge (BR-AE-10),
|
|
22
|
+
* intra-community supply (BR-IC-10), export (BR-G-10) and not subject to VAT
|
|
23
|
+
* (BR-O-10). The others state none (BR-S-10, BR-Z-10, BR-AF-10, BR-AG-10).
|
|
24
|
+
*/
|
|
25
|
+
export declare const VAT_CATEGORIES_WITH_EXEMPTION: readonly TVatCategoryCode[];
|
|
26
|
+
/**
|
|
27
|
+
* The VAT exemption reason code (BT-121) and text (BT-120) a VAT breakdown
|
|
28
|
+
* states; at least one of them
|
|
7
29
|
*/
|
|
8
|
-
export type TVatCategoryCode = 'S' | 'AE';
|
|
9
|
-
/** The VAT exemption reason (BT-121 code, BT-120 text) a VAT category states */
|
|
10
30
|
export interface IVatExemption {
|
|
11
|
-
code
|
|
12
|
-
reason
|
|
31
|
+
code?: string;
|
|
32
|
+
reason?: string;
|
|
13
33
|
}
|
|
14
34
|
/**
|
|
15
|
-
* The
|
|
16
|
-
*
|
|
35
|
+
* The CEF VATEX code list, as the CEN/TC 434 EN 16931 validation artefacts
|
|
36
|
+
* 1.3.16 check a VAT exemption reason code (BT-121) against it (BR-CL-22,
|
|
37
|
+
* compared in upper case)
|
|
38
|
+
*/
|
|
39
|
+
export declare const VATEX_CODES: ReadonlySet<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether a VAT exemption reason code is on the CEF VATEX code list (BR-CL-22)
|
|
42
|
+
* @param code The code
|
|
43
|
+
*/
|
|
44
|
+
export declare const isVatexCode: (code: string) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The VAT category of an item: the one it states (`vatCategory`, BT-151), else
|
|
47
|
+
* reverse charge (AE) when the document states `reverseCharge`, standard rated
|
|
48
|
+
* (S) otherwise.
|
|
17
49
|
* @param accountingDoc The document
|
|
50
|
+
* @param item The item
|
|
18
51
|
*/
|
|
19
|
-
export declare const
|
|
52
|
+
export declare const getItemVatCategory: (accountingDoc: {
|
|
20
53
|
reverseCharge?: boolean;
|
|
21
|
-
}) => TVatCategoryCode;
|
|
54
|
+
}, item: Pick<TAccountingDocItem, "vatCategory">) => TVatCategoryCode;
|
|
22
55
|
/**
|
|
23
|
-
* The exemption reason
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
56
|
+
* The exemption reason an item states: its VATEX code (BT-121) and its text
|
|
57
|
+
* (BT-120), each trimmed; undefined when it states neither
|
|
58
|
+
* @param item The item
|
|
59
|
+
*/
|
|
60
|
+
export declare const getItemVatExemption: (item: Pick<TAccountingDocItem, "vatExemptionReason" | "vatExemptionReasonCode">) => IVatExemption | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* The exemption reason a VAT breakdown of a category states when none of its
|
|
63
|
+
* items states one.
|
|
64
|
+
* - Reverse charge (AE): the code `VATEX-EU-AE` and the wording the law
|
|
65
|
+
* prescribes, "Steuerschuldnerschaft des Leistungsempfängers" (§ 14a Abs. 1
|
|
66
|
+
* and 5 UStG). A document in another language may use the wording of
|
|
67
|
+
* Article 226 Nr. 11a of the VAT Directive in that language, "Reverse charge"
|
|
68
|
+
* in English (Abschnitt 14a.1 Abs. 6 Satz 2 UStAE).
|
|
69
|
+
* - Intra-community supply (K), export outside the EU (G) and not subject to
|
|
70
|
+
* VAT (O): the VATEX code that means the category, `VATEX-EU-IC`,
|
|
71
|
+
* `VATEX-EU-G` and `VATEX-EU-O`, which BR-IC-10, BR-G-10 and BR-O-10 accept.
|
|
72
|
+
* - Exempt (E): none. The reason depends on the exemption applied, which only
|
|
73
|
+
* the issuer knows; a document with an exempt item that states none is
|
|
74
|
+
* refused (BR-E-10).
|
|
29
75
|
* @param category The VAT category
|
|
30
76
|
* @param language The document language
|
|
31
77
|
*/
|
|
32
|
-
export declare const
|
|
78
|
+
export declare const getDefaultVatExemption: (category: TVatCategoryCode, language: string | undefined) => IVatExemption | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* The exemption reason a VAT breakdown states: the code and the text its items
|
|
81
|
+
* state, each completed by the category's default where they state none
|
|
82
|
+
* (`getDefaultVatExemption`); undefined when there is neither
|
|
83
|
+
* @param stated The exemption the items state
|
|
84
|
+
* @param categoryDefault The category's default
|
|
85
|
+
*/
|
|
86
|
+
export declare const mergeVatExemption: (stated: IVatExemption | undefined, categoryDefault: IVatExemption | undefined) => IVatExemption | undefined;
|
|
33
87
|
/**
|
|
34
88
|
* Whether a VAT rate is a number not greater than zero; a rate that is no
|
|
35
89
|
* number is refused as such (`findInvalidItemAmounts`), not as BR-S-05
|
|
36
90
|
* @param rate The rate
|
|
37
91
|
*/
|
|
38
92
|
export declare const isRateNotAboveZero: (rate: unknown) => boolean;
|
|
39
|
-
/**
|
|
40
|
-
|
|
93
|
+
/**
|
|
94
|
+
* The refusal or finding for a standard rated line whose VAT rate is not
|
|
95
|
+
* greater than zero (BR-S-05)
|
|
96
|
+
* @param line The line index and its rate
|
|
97
|
+
* @param statedCategory Whether the item states the category S itself
|
|
98
|
+
*/
|
|
99
|
+
export declare const standardRatedLineWithoutRateMessage: (line: {
|
|
41
100
|
index: number;
|
|
42
101
|
vatPercentage: number;
|
|
102
|
+
}, statedCategory?: boolean) => string;
|
|
103
|
+
/** One rule a VAT category finding names */
|
|
104
|
+
export interface IVatCategoryViolation {
|
|
105
|
+
/** the EN 16931 rule ID, or the package's own code for a check no official rule states */
|
|
106
|
+
ruleId: string;
|
|
107
|
+
/** what is wrong, with the field */
|
|
108
|
+
message: string;
|
|
109
|
+
/** the envelope field concerned */
|
|
110
|
+
field: string;
|
|
43
111
|
}
|
|
112
|
+
/** The package's own check: the items of one VAT breakdown state different exemption reasons */
|
|
113
|
+
export declare const VAT_EXEMPTION_DIFFERS = "EINVOICE-VAT-EXEMPTION-DIFFERS";
|
|
44
114
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
115
|
+
* Every rule of EN 16931 on the VAT categories of a document's items that the
|
|
116
|
+
* envelope can break, in item order and then per document; an empty list when
|
|
117
|
+
* the document can be written. Amounts that are no number are not checked
|
|
118
|
+
* here (`findInvalidItemAmounts`).
|
|
119
|
+
* - The rate each category allows (BR-S-05, BR-Z-05, BR-E-05, BR-AE-05,
|
|
120
|
+
* BR-IC-05, BR-G-05, BR-O-05, BR-AF-05, BR-AG-05).
|
|
121
|
+
* - The exemption reason: stated for E, AE, K, G and O (a default for AE, K,
|
|
122
|
+
* G and O, `getDefaultVatExemption`), not stated for S, Z, L and M (the
|
|
123
|
+
* BR-x-10 rules); a code on the VATEX list (BR-CL-22); one reason per VAT
|
|
124
|
+
* breakdown, as a breakdown states one (`EINVOICE-VAT-EXEMPTION-DIFFERS`).
|
|
125
|
+
* - The parties' identifiers: for Z, E, L and M the seller VAT identifier
|
|
126
|
+
* (BT-31) or tax registration identifier (BT-32) (BR-Z-02, BR-E-02,
|
|
127
|
+
* BR-AF-02, BR-AG-02); for AE that and the buyer VAT identifier (BT-48) or
|
|
128
|
+
* legal registration identifier (BT-47) (BR-AE-02); for K the seller and the
|
|
129
|
+
* buyer VAT identifier (BR-IC-02); for G the seller VAT identifier
|
|
130
|
+
* (BR-G-02); for O neither VAT identifier (BR-O-02). The rules also accept
|
|
131
|
+
* a seller tax representative (BT-63), which the envelope cannot state.
|
|
132
|
+
* - An intra-community supply states the delivery date (BT-72) or the
|
|
133
|
+
* invoicing period (BG-14) (BR-IC-11) and the deliver to country (BT-80,
|
|
134
|
+
* `metadata.deliveryAddress.countryCode`) (BR-IC-12).
|
|
135
|
+
* - A document not subject to VAT has no item of another category (BR-O-11,
|
|
136
|
+
* BR-O-12).
|
|
137
|
+
* The rule for a standard rated item holds whether it states S or is S
|
|
138
|
+
* because it states no category, so an item at the rate 0 outside reverse
|
|
139
|
+
* charge that states no category breaks BR-S-05. Whether a document in
|
|
140
|
+
* reverse charge meets § 14a Abs. 1 UStG (both VAT identification numbers for
|
|
141
|
+
* a supply in another member state) cannot be told from the envelope, which
|
|
142
|
+
* has no place of supply; the issuing application enforces it.
|
|
143
|
+
* @param accountingDoc The document
|
|
52
144
|
*/
|
|
53
|
-
export declare const
|
|
145
|
+
export declare const findVatCategoryViolations: (accountingDoc: Pick<TAccountingDoc, "items" | "from" | "to" | "deliveryDate" | "periodOfPerformance"> & {
|
|
146
|
+
reverseCharge?: boolean;
|
|
147
|
+
language?: string;
|
|
148
|
+
metadata?: {
|
|
149
|
+
deliveryAddress?: {
|
|
150
|
+
countryCode?: string;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
}, syntax?: "ubl" | "cii") => IVatCategoryViolation[];
|
|
54
154
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
155
|
+
* Refuses a document whose items cannot be written with a valid VAT category
|
|
156
|
+
* (`findVatCategoryViolations`), naming the first rule it breaks; no value is
|
|
157
|
+
* put in place of a missing one.
|
|
158
|
+
* @param accountingDoc The document
|
|
159
|
+
* @param targetFormat The syntax being written
|
|
57
160
|
*/
|
|
58
|
-
export declare const
|
|
161
|
+
export declare const assertVatCategoryWritable: (accountingDoc: TAccountingDoc, targetFormat: "ubl" | "cii") => void;
|
|
59
162
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* Steuernummer, which § 14 Abs. 4 Satz 1 Nr. 2 UStG allows instead), and the
|
|
70
|
-
* buyer a VAT identifier (BT-48) or a legal registration identifier (BT-47).
|
|
71
|
-
* The rule also accepts a tax representative's VAT identifier (BT-63) for
|
|
72
|
-
* the seller; the envelope cannot state one, so a seller with neither BT-31
|
|
73
|
-
* nor BT-32 is refused.
|
|
74
|
-
* The envelope has no place of supply, so whether a document is one for a
|
|
75
|
-
* supply in another member state, whose invoice states the VAT identification
|
|
76
|
-
* numbers of both parties (§ 14a Abs. 1 Satz 3 UStG), cannot be told here: a
|
|
77
|
-
* domestic § 13b supply to a buyer based in another member state is taxed in
|
|
78
|
-
* Germany and may state a tax number. Only what BR-AE-02 requires is checked;
|
|
79
|
-
* the issuing application enforces § 14a Abs. 1.
|
|
80
|
-
* @param accountingDoc The document
|
|
81
|
-
* @param targetFormat The format being written
|
|
163
|
+
* Gives the items of a decoded document the VAT category their lines state
|
|
164
|
+
* (BT-151) and the exemption reason (BT-120) and code (BT-121) of the VAT
|
|
165
|
+
* breakdown they belong to: the one of their category and rate, or of their
|
|
166
|
+
* category for an item not subject to VAT, which states no rate. A line that
|
|
167
|
+
* states no category, or a code EN 16931 does not allow, keeps none; the item
|
|
168
|
+
* is then read as AE or S (`getItemVatCategory`) and the code list rules
|
|
169
|
+
* report the code.
|
|
170
|
+
* @param items The decoded items, in line order
|
|
171
|
+
* @param statedValues What the document states; undefined for a ZUGFeRD 1.0 document
|
|
82
172
|
*/
|
|
83
|
-
export declare const
|
|
173
|
+
export declare const applyStatedVatCategories: (items: TAccountingDocItem[], statedValues: IEInvoiceStatedValues | undefined) => void;
|
|
174
|
+
export {};
|