rerobe-js-orm 4.9.13 → 4.9.14
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.
|
@@ -679,12 +679,15 @@ class OrderHelpers {
|
|
|
679
679
|
})
|
|
680
680
|
.reduce((acc, cur) => {
|
|
681
681
|
if (cur.taxRate) {
|
|
682
|
-
|
|
683
|
-
|
|
682
|
+
// Key by whole percent (25), matching the backend ReceiptBuilder and the
|
|
683
|
+
// canonical "Moms 25%" display format, so every receipt path is consistent.
|
|
684
|
+
const ratePercent = Math.round(Number(cur.taxRate) * 100);
|
|
685
|
+
if (!acc[ratePercent]) {
|
|
686
|
+
acc[ratePercent] = 0;
|
|
684
687
|
}
|
|
685
688
|
const amount = Number(cur.taxAmount);
|
|
686
|
-
acc[
|
|
687
|
-
acc[
|
|
689
|
+
acc[ratePercent] += isRefund ? -Math.abs(amount) : amount;
|
|
690
|
+
acc[ratePercent] = parseFloat(acc[ratePercent].toFixed(2));
|
|
688
691
|
}
|
|
689
692
|
return acc;
|
|
690
693
|
}, {});
|
|
@@ -7,6 +7,7 @@ export type ReceiptPreviewLine = {
|
|
|
7
7
|
};
|
|
8
8
|
export default class ReceiptXmlHelpers {
|
|
9
9
|
static escapeXML(text: any): string;
|
|
10
|
+
static vatRatePercent(rate: any): number;
|
|
10
11
|
private static variantLabelForReceipt;
|
|
11
12
|
static formatLineItemXML(lineItem: any): string;
|
|
12
13
|
static buildReceiptContentXML(receiptData: any): string;
|
|
@@ -18,6 +18,17 @@ class ReceiptXmlHelpers {
|
|
|
18
18
|
.replace(/"/g, '"')
|
|
19
19
|
.replace(/'/g, ''');
|
|
20
20
|
}
|
|
21
|
+
// Canonical VAT-rate-for-display normalizer — the single source of truth for how
|
|
22
|
+
// a VAT rate is shown on EVERY receipt/report ("Moms 25%"). Accepts a fraction
|
|
23
|
+
// (0.25), a whole percent (25), or their string forms, and always returns the
|
|
24
|
+
// integer percent (25). A value in (0,1) is treated as a fraction; >=1 is already
|
|
25
|
+
// a percent. Covers every Swedish rate (0, 6, 12, 25) from either representation.
|
|
26
|
+
static vatRatePercent(rate) {
|
|
27
|
+
const n = Math.abs(Number(rate));
|
|
28
|
+
if (!n || Number.isNaN(n))
|
|
29
|
+
return 0;
|
|
30
|
+
return Math.round(n < 1 ? n * 100 : n);
|
|
31
|
+
}
|
|
21
32
|
// Variant label for a receipt line (e.g. "M · R"), delegated to the shared
|
|
22
33
|
// helper so cart, order detail, and receipt render the same rule.
|
|
23
34
|
static variantLabelForReceipt(lineItem) {
|
|
@@ -131,7 +142,7 @@ class ReceiptXmlHelpers {
|
|
|
131
142
|
if (receiptData.taxRates && typeof receiptData.taxRates === 'object') {
|
|
132
143
|
receipt += '<text font="font_a" width="1" height="1">';
|
|
133
144
|
Object.entries(receiptData.taxRates).forEach(([taxRate, value]) => {
|
|
134
|
-
const rate =
|
|
145
|
+
const rate = this.vatRatePercent(taxRate);
|
|
135
146
|
receipt += `Moms ${this.escapeXML(String(rate))}%: ${this.escapeXML(value)}`;
|
|
136
147
|
receipt += '</text><feed/><text font="font_a" width="1" height="1">';
|
|
137
148
|
});
|
|
@@ -340,7 +351,7 @@ class ReceiptXmlHelpers {
|
|
|
340
351
|
// --- VAT ---
|
|
341
352
|
receipt += dividerLine;
|
|
342
353
|
vatLines.forEach((v) => {
|
|
343
|
-
receipt += row(`Moms ${this.escapeXML(String(v.rate))}%:`, String(v.amount));
|
|
354
|
+
receipt += row(`Moms ${this.escapeXML(String(this.vatRatePercent(v.rate)))}%:`, String(v.amount));
|
|
344
355
|
});
|
|
345
356
|
if (netExVat)
|
|
346
357
|
receipt += row('Netto (exkl. moms):', netExVat, true);
|