@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.
Files changed (61) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/einvoice.d.ts +14 -1
  3. package/dist_ts/einvoice.js +17 -2
  4. package/dist_ts/formats/base/base.encoder.d.ts +1 -1
  5. package/dist_ts/formats/cii/cii.decoder.d.ts +12 -1
  6. package/dist_ts/formats/cii/cii.decoder.js +34 -1
  7. package/dist_ts/formats/cii/cii.encoder.d.ts +14 -3
  8. package/dist_ts/formats/cii/cii.encoder.js +58 -6
  9. package/dist_ts/formats/cii/cii.types.d.ts +1 -0
  10. package/dist_ts/formats/cii/cii.types.js +3 -2
  11. package/dist_ts/formats/cii/facturx/facturx.decoder.d.ts +1 -1
  12. package/dist_ts/formats/cii/facturx/facturx.decoder.js +9 -4
  13. package/dist_ts/formats/cii/facturx/facturx.encoder.d.ts +2 -2
  14. package/dist_ts/formats/cii/facturx/facturx.encoder.js +13 -10
  15. package/dist_ts/formats/cii/zugferd/zugferd.decoder.d.ts +1 -1
  16. package/dist_ts/formats/cii/zugferd/zugferd.decoder.js +9 -4
  17. package/dist_ts/formats/cii/zugferd/zugferd.encoder.d.ts +1 -1
  18. package/dist_ts/formats/cii/zugferd/zugferd.encoder.js +16 -13
  19. package/dist_ts/formats/cii/zugferd/zugferd.v1.decoder.d.ts +7 -1
  20. package/dist_ts/formats/cii/zugferd/zugferd.v1.decoder.js +27 -4
  21. package/dist_ts/formats/ubl/generic/ubl.encoder.d.ts +23 -1
  22. package/dist_ts/formats/ubl/generic/ubl.encoder.js +67 -11
  23. package/dist_ts/formats/ubl/ubl.decoder.d.ts +1 -1
  24. package/dist_ts/formats/ubl/ubl.encoder.d.ts +16 -3
  25. package/dist_ts/formats/ubl/ubl.encoder.js +75 -13
  26. package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.d.ts +6 -1
  27. package/dist_ts/formats/ubl/xrechnung/xrechnung.decoder.js +37 -7
  28. package/dist_ts/formats/ubl/xrechnung/xrechnung.encoder.d.ts +1 -1
  29. package/dist_ts/formats/ubl/xrechnung/xrechnung.encoder.js +4 -2
  30. package/dist_ts/formats/utils/date.value.d.ts +10 -0
  31. package/dist_ts/formats/utils/date.value.js +21 -0
  32. package/dist_ts/formats/utils/document.typecode.d.ts +3 -3
  33. package/dist_ts/formats/utils/document.typecode.js +8 -4
  34. package/dist_ts/formats/utils/preceding.invoice.d.ts +26 -0
  35. package/dist_ts/formats/utils/preceding.invoice.js +52 -0
  36. package/dist_ts/index.d.ts +1 -1
  37. package/dist_ts/index.js +1 -1
  38. package/dist_ts/interfaces/common.d.ts +6 -2
  39. package/package.json +3 -3
  40. package/readme.md +60 -10
  41. package/ts/00_commitinfo_data.ts +1 -1
  42. package/ts/einvoice.ts +18 -1
  43. package/ts/formats/base/base.encoder.ts +1 -1
  44. package/ts/formats/cii/cii.decoder.ts +43 -1
  45. package/ts/formats/cii/cii.encoder.ts +62 -6
  46. package/ts/formats/cii/cii.types.ts +2 -1
  47. package/ts/formats/cii/facturx/facturx.decoder.ts +9 -3
  48. package/ts/formats/cii/facturx/facturx.encoder.ts +13 -9
  49. package/ts/formats/cii/zugferd/zugferd.decoder.ts +9 -3
  50. package/ts/formats/cii/zugferd/zugferd.encoder.ts +16 -12
  51. package/ts/formats/cii/zugferd/zugferd.v1.decoder.ts +30 -3
  52. package/ts/formats/ubl/generic/ubl.encoder.ts +74 -10
  53. package/ts/formats/ubl/ubl.decoder.ts +1 -1
  54. package/ts/formats/ubl/ubl.encoder.ts +77 -13
  55. package/ts/formats/ubl/xrechnung/xrechnung.decoder.ts +45 -6
  56. package/ts/formats/ubl/xrechnung/xrechnung.encoder.ts +4 -1
  57. package/ts/formats/utils/date.value.ts +21 -0
  58. package/ts/formats/utils/document.typecode.ts +7 -3
  59. package/ts/formats/utils/preceding.invoice.ts +74 -0
  60. package/ts/index.ts +3 -0
  61. 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,
@@ -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';