@fin.cx/einvoice 8.1.0 → 8.2.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 +14 -1
- package/dist_ts/einvoice.js +17 -2
- package/dist_ts/formats/base/base.encoder.d.ts +1 -1
- package/dist_ts/formats/cii/cii.decoder.d.ts +12 -1
- package/dist_ts/formats/cii/cii.decoder.js +34 -1
- package/dist_ts/formats/cii/cii.encoder.d.ts +14 -3
- package/dist_ts/formats/cii/cii.encoder.js +58 -6
- package/dist_ts/formats/cii/cii.types.d.ts +1 -0
- package/dist_ts/formats/cii/cii.types.js +3 -2
- package/dist_ts/formats/cii/facturx/facturx.decoder.d.ts +1 -1
- package/dist_ts/formats/cii/facturx/facturx.decoder.js +9 -4
- package/dist_ts/formats/cii/facturx/facturx.encoder.d.ts +2 -2
- package/dist_ts/formats/cii/facturx/facturx.encoder.js +13 -10
- package/dist_ts/formats/cii/zugferd/zugferd.decoder.d.ts +1 -1
- package/dist_ts/formats/cii/zugferd/zugferd.decoder.js +9 -4
- package/dist_ts/formats/cii/zugferd/zugferd.encoder.d.ts +1 -1
- package/dist_ts/formats/cii/zugferd/zugferd.encoder.js +16 -13
- package/dist_ts/formats/cii/zugferd/zugferd.v1.decoder.d.ts +7 -1
- package/dist_ts/formats/cii/zugferd/zugferd.v1.decoder.js +27 -4
- package/dist_ts/formats/ubl/generic/ubl.encoder.d.ts +23 -1
- package/dist_ts/formats/ubl/generic/ubl.encoder.js +67 -11
- package/dist_ts/formats/ubl/ubl.decoder.d.ts +1 -1
- package/dist_ts/formats/ubl/ubl.encoder.d.ts +16 -3
- package/dist_ts/formats/ubl/ubl.encoder.js +75 -13
- package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.d.ts +6 -1
- package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.js +37 -7
- package/dist_ts/formats/ubl/xrechnung/xrechnung.encoder.d.ts +1 -1
- package/dist_ts/formats/ubl/xrechnung/xrechnung.encoder.js +4 -2
- package/dist_ts/formats/utils/date.value.d.ts +10 -0
- package/dist_ts/formats/utils/date.value.js +21 -0
- package/dist_ts/formats/utils/document.typecode.d.ts +3 -3
- package/dist_ts/formats/utils/document.typecode.js +8 -4
- package/dist_ts/formats/utils/preceding.invoice.d.ts +26 -0
- package/dist_ts/formats/utils/preceding.invoice.js +52 -0
- package/dist_ts/index.d.ts +1 -1
- package/dist_ts/index.js +1 -1
- package/dist_ts/interfaces/common.d.ts +6 -2
- package/package.json +3 -3
- package/readme.md +60 -10
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/einvoice.ts +18 -1
- package/ts/formats/base/base.encoder.ts +1 -1
- package/ts/formats/cii/cii.decoder.ts +43 -1
- package/ts/formats/cii/cii.encoder.ts +62 -6
- package/ts/formats/cii/cii.types.ts +2 -1
- package/ts/formats/cii/facturx/facturx.decoder.ts +9 -3
- package/ts/formats/cii/facturx/facturx.encoder.ts +13 -9
- package/ts/formats/cii/zugferd/zugferd.decoder.ts +9 -3
- package/ts/formats/cii/zugferd/zugferd.encoder.ts +16 -12
- package/ts/formats/cii/zugferd/zugferd.v1.decoder.ts +30 -3
- package/ts/formats/ubl/generic/ubl.encoder.ts +74 -10
- package/ts/formats/ubl/ubl.decoder.ts +1 -1
- package/ts/formats/ubl/ubl.encoder.ts +77 -13
- package/ts/formats/ubl/xrechnung/xrechnung.decoder.ts +45 -6
- package/ts/formats/ubl/xrechnung/xrechnung.encoder.ts +4 -1
- package/ts/formats/utils/date.value.ts +21 -0
- package/ts/formats/utils/document.typecode.ts +7 -3
- package/ts/formats/utils/preceding.invoice.ts +74 -0
- package/ts/index.ts +3 -0
- package/ts/interfaces/common.ts +6 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TAccountingDoc,
|
|
3
|
+
TAccountingDocType,
|
|
4
|
+
TCorrectedInvoiceReference,
|
|
5
|
+
TRelatedDocument,
|
|
6
|
+
} from '../../interfaces/common.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* One preceding invoice reference (BG-3): the number of the preceding invoice
|
|
10
|
+
* (BT-25) and, when the document states it, its issue date (BT-26).
|
|
11
|
+
*/
|
|
12
|
+
export type TPrecedingInvoiceReference = TCorrectedInvoiceReference;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The preceding invoice references (BG-3) an encoder writes for a document,
|
|
16
|
+
* taken only from what the document states:
|
|
17
|
+
* - a corrected invoice: the invoice it corrects (`correctedInvoice`);
|
|
18
|
+
* - a corrected invoice or a credit note: every related document with the
|
|
19
|
+
* relation `'corrects'`.
|
|
20
|
+
* Other documents and other relations write none.
|
|
21
|
+
*/
|
|
22
|
+
export const getPrecedingInvoiceReferences = (
|
|
23
|
+
accountingDoc: TAccountingDoc,
|
|
24
|
+
): TPrecedingInvoiceReference[] => {
|
|
25
|
+
const references: TPrecedingInvoiceReference[] = [];
|
|
26
|
+
if (accountingDoc.accountingDocType === 'corrected-invoice' && accountingDoc.correctedInvoice) {
|
|
27
|
+
references.push(accountingDoc.correctedInvoice);
|
|
28
|
+
}
|
|
29
|
+
if (
|
|
30
|
+
accountingDoc.accountingDocType === 'corrected-invoice' ||
|
|
31
|
+
accountingDoc.accountingDocType === 'creditnote'
|
|
32
|
+
) {
|
|
33
|
+
for (const relatedDocument of accountingDoc.relatedDocuments ?? []) {
|
|
34
|
+
if (relatedDocument.relationType === 'corrects') {
|
|
35
|
+
references.push(
|
|
36
|
+
relatedDocument.issueDate === undefined
|
|
37
|
+
? { documentId: relatedDocument.documentId }
|
|
38
|
+
: { documentId: relatedDocument.documentId, issueDate: relatedDocument.issueDate },
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return references;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The envelope fields for the preceding invoice references a decoder read, the
|
|
48
|
+
* inverse of {@link getPrecedingInvoiceReferences}: on a corrected invoice the
|
|
49
|
+
* first reference is the invoice it corrects and further ones are related
|
|
50
|
+
* documents it corrects; on a credit note every reference is a related
|
|
51
|
+
* document it corrects. Other documents keep no reference, as before.
|
|
52
|
+
*/
|
|
53
|
+
export const getPrecedingInvoiceFields = (
|
|
54
|
+
accountingDocType: TAccountingDocType,
|
|
55
|
+
references: TPrecedingInvoiceReference[],
|
|
56
|
+
): { correctedInvoice?: TCorrectedInvoiceReference; relatedDocuments?: TRelatedDocument[] } => {
|
|
57
|
+
const asRelated = (reference: TPrecedingInvoiceReference): TRelatedDocument => ({
|
|
58
|
+
relationType: 'corrects',
|
|
59
|
+
...reference,
|
|
60
|
+
});
|
|
61
|
+
if (references.length === 0) {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
if (accountingDocType === 'corrected-invoice') {
|
|
65
|
+
const [correctedInvoice, ...furtherReferences] = references;
|
|
66
|
+
return furtherReferences.length === 0
|
|
67
|
+
? { correctedInvoice }
|
|
68
|
+
: { correctedInvoice, relatedDocuments: furtherReferences.map(asRelated) };
|
|
69
|
+
}
|
|
70
|
+
if (accountingDocType === 'creditnote') {
|
|
71
|
+
return { relatedDocuments: references.map(asRelated) };
|
|
72
|
+
}
|
|
73
|
+
return {};
|
|
74
|
+
};
|
package/ts/index.ts
CHANGED
|
@@ -74,6 +74,9 @@ import { ZUGFeRDV1Decoder } from './formats/cii/zugferd/zugferd.v1.decoder.js';
|
|
|
74
74
|
export type {
|
|
75
75
|
// Common interfaces
|
|
76
76
|
TInvoice,
|
|
77
|
+
TCorrectedInvoice,
|
|
78
|
+
TCorrectedInvoiceReference,
|
|
79
|
+
TInvoiceCorrection,
|
|
77
80
|
TCreditNote,
|
|
78
81
|
TDebitNote,
|
|
79
82
|
TSelfBilledInvoice,
|
package/ts/interfaces/common.ts
CHANGED
|
@@ -83,11 +83,16 @@ export interface IPdf {
|
|
|
83
83
|
// Re-export types from tsclass for convenience
|
|
84
84
|
import type {
|
|
85
85
|
TInvoice,
|
|
86
|
+
TCorrectedInvoice,
|
|
86
87
|
TDebitNote,
|
|
87
88
|
TSelfBilledInvoice,
|
|
88
89
|
} from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
89
90
|
|
|
90
91
|
export type { TInvoice } from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
92
|
+
export type { TCorrectedInvoice } from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
93
|
+
export type { TCorrectedInvoiceReference } from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
94
|
+
export type { TInvoiceCorrection } from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
95
|
+
export type { TRelatedDocument } from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
91
96
|
export type { TCreditNote } from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
92
97
|
export type { TDebitNote } from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
93
98
|
export type { TSelfBilledInvoice } from '@tsclass/tsclass/dist_ts/finance/index.js';
|
|
@@ -100,7 +105,7 @@ export type { TAccountingDocEnvelope } from '@tsclass/tsclass/dist_ts/finance/in
|
|
|
100
105
|
* `Invoice` root and the CII type codes of the invoice family. Only a credit
|
|
101
106
|
* note has a document shape of its own.
|
|
102
107
|
*/
|
|
103
|
-
export type TInvoiceDocument = TInvoice | TDebitNote | TSelfBilledInvoice;
|
|
108
|
+
export type TInvoiceDocument = TInvoice | TCorrectedInvoice | TDebitNote | TSelfBilledInvoice;
|
|
104
109
|
export type { TContact } from '@tsclass/tsclass/dist_ts/business/index.js';
|
|
105
110
|
export type { TLetterEnvelope } from '@tsclass/tsclass/dist_ts/business/index.js';
|
|
106
111
|
export type { TDocumentEnvelope } from '@tsclass/tsclass/dist_ts/business/index.js';
|