@open-nav/invoicing 0.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/LICENSE +29 -0
- package/README.md +190 -0
- package/dist/color.d.ts +31 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +150 -0
- package/dist/color.js.map +1 -0
- package/dist/export.d.ts +89 -0
- package/dist/export.d.ts.map +1 -0
- package/dist/export.js +115 -0
- package/dist/export.js.map +1 -0
- package/dist/format.d.ts +23 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +52 -0
- package/dist/format.js.map +1 -0
- package/dist/html.d.ts +43 -0
- package/dist/html.d.ts.map +1 -0
- package/dist/html.js +355 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/labels.d.ts +8 -0
- package/dist/labels.d.ts.map +1 -0
- package/dist/labels.js +199 -0
- package/dist/labels.js.map +1 -0
- package/dist/markings.d.ts +28 -0
- package/dist/markings.d.ts.map +1 -0
- package/dist/markings.js +69 -0
- package/dist/markings.js.map +1 -0
- package/dist/pdf-native.d.ts +32 -0
- package/dist/pdf-native.d.ts.map +1 -0
- package/dist/pdf-native.js +601 -0
- package/dist/pdf-native.js.map +1 -0
- package/dist/pdf.d.ts +92 -0
- package/dist/pdf.d.ts.map +1 -0
- package/dist/pdf.js +203 -0
- package/dist/pdf.js.map +1 -0
- package/dist/theme.d.ts +85 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +210 -0
- package/dist/theme.js.map +1 -0
- package/package.json +54 -0
- package/src/color.ts +170 -0
- package/src/export.ts +204 -0
- package/src/format.ts +66 -0
- package/src/html.ts +446 -0
- package/src/index.ts +9 -0
- package/src/labels.ts +222 -0
- package/src/markings.ts +102 -0
- package/src/pdf-native.ts +754 -0
- package/src/pdf.ts +302 -0
- package/src/theme.ts +305 -0
package/src/markings.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { InvoiceType, LineType, VatRateType } from '@open-nav/core';
|
|
2
|
+
import { marginSchemeLabel, label } from './labels.js';
|
|
3
|
+
import type { DocumentLanguage } from './format.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A phrase the VAT Act requires on the invoice itself.
|
|
7
|
+
*
|
|
8
|
+
* Section 169 of the VAT Act (Áfa tv. 169. §) prescribes not just the figures
|
|
9
|
+
* but specific wording: an exempt supply must state the legal ground, a
|
|
10
|
+
* domestic reverse charge must say "fordított adózás", cash accounting must
|
|
11
|
+
* say "pénzforgalmi elszámolás", and so on. These are derived from the data
|
|
12
|
+
* rather than left to whoever fills in a template, because a missing phrase
|
|
13
|
+
* makes the invoice defective even when every number on it is right.
|
|
14
|
+
*/
|
|
15
|
+
export interface Marking {
|
|
16
|
+
/** The text to print, in the document's language. */
|
|
17
|
+
text: string;
|
|
18
|
+
/** Where the requirement comes from, for the reader and for review. */
|
|
19
|
+
reference: string;
|
|
20
|
+
/** Free text NAV carries alongside a coded reason, if any. */
|
|
21
|
+
detail?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function vatRatesOf(invoice: InvoiceType): VatRateType[] {
|
|
25
|
+
const lines: LineType[] = invoice.invoiceLines?.line ?? [];
|
|
26
|
+
const fromLines = lines.flatMap((line) =>
|
|
27
|
+
[line.lineAmountsNormal?.lineVatRate, line.lineAmountsSimplified?.lineVatRate].filter(
|
|
28
|
+
(rate): rate is VatRateType => rate !== undefined,
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
const fromSummary = [
|
|
32
|
+
...(invoice.invoiceSummary.summaryNormal?.summaryByVatRate ?? []).map((entry) => entry.vatRate),
|
|
33
|
+
...(invoice.invoiceSummary.summarySimplified ?? []).map((entry) => entry.vatRate),
|
|
34
|
+
];
|
|
35
|
+
return [...fromLines, ...fromSummary];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Derive every marking the invoice must carry.
|
|
40
|
+
*
|
|
41
|
+
* Duplicates are collapsed: a reverse charge on twelve lines is one phrase on
|
|
42
|
+
* the document, not twelve.
|
|
43
|
+
*/
|
|
44
|
+
export function deriveMarkings(invoice: InvoiceType, language: DocumentLanguage): Marking[] {
|
|
45
|
+
const markings = new Map<string, Marking>();
|
|
46
|
+
const add = (marking: Marking): void => {
|
|
47
|
+
markings.set(`${marking.text}|${marking.detail ?? ''}`, marking);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const detail = invoice.invoiceHead.invoiceDetail;
|
|
51
|
+
|
|
52
|
+
if (detail.cashAccountingIndicator) {
|
|
53
|
+
add({ text: label('cashAccounting', language), reference: 'Áfa tv. 169. § h)' });
|
|
54
|
+
}
|
|
55
|
+
if (detail.selfBillingIndicator) {
|
|
56
|
+
add({ text: label('selfBilling', language), reference: 'Áfa tv. 169. § l)' });
|
|
57
|
+
}
|
|
58
|
+
if (invoice.invoiceHead.fiscalRepresentativeInfo) {
|
|
59
|
+
add({
|
|
60
|
+
text: `${label('fiscalRepresentative', language)}: ${invoice.invoiceHead.fiscalRepresentativeInfo.fiscalRepresentativeName}`,
|
|
61
|
+
reference: 'Áfa tv. 169. § p)',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const rate of vatRatesOf(invoice)) {
|
|
66
|
+
if (rate.vatDomesticReverseCharge) {
|
|
67
|
+
add({ text: label('reverseCharge', language), reference: 'Áfa tv. 169. § n)' });
|
|
68
|
+
}
|
|
69
|
+
if (rate.vatExemption) {
|
|
70
|
+
add({
|
|
71
|
+
text: `${label('exempt', language)} — ${rate.vatExemption.case}`,
|
|
72
|
+
reference: 'Áfa tv. 169. § m)',
|
|
73
|
+
detail: rate.vatExemption.reason,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (rate.vatOutOfScope) {
|
|
77
|
+
add({
|
|
78
|
+
text: `${label('outOfScope', language)} — ${rate.vatOutOfScope.case}`,
|
|
79
|
+
reference: 'Áfa tv. 169. § m)',
|
|
80
|
+
detail: rate.vatOutOfScope.reason,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (rate.marginSchemeIndicator) {
|
|
84
|
+
add({
|
|
85
|
+
text: marginSchemeLabel(rate.marginSchemeIndicator, language),
|
|
86
|
+
reference: 'Áfa tv. 169. § o) p)',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (rate.noVatCharge) {
|
|
90
|
+
add({ text: label('outOfScope', language), reference: 'Áfa tv. 169. § m)' });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const hasNewTransportMean = (invoice.invoiceLines?.line ?? []).some(
|
|
95
|
+
(line) => line.newTransportMean !== undefined,
|
|
96
|
+
);
|
|
97
|
+
if (hasNewTransportMean) {
|
|
98
|
+
add({ text: label('newTransportMean', language), reference: 'Áfa tv. 169. § k)' });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return [...markings.values()];
|
|
102
|
+
}
|