@qrwise/pos-calculations 0.0.9 → 0.0.10
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/index.cjs +24 -32
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +24 -32
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -62,51 +62,43 @@ function getDiscountBreakdown(discountType, discountedAmount) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
function calculateTotals(input) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
voucherType = null,
|
|
71
|
-
voucherRate = 0,
|
|
72
|
-
discountType = null,
|
|
73
|
-
discountRate = 0,
|
|
74
|
-
vatRate = 12,
|
|
75
|
-
serviceChargeRate = 0,
|
|
76
|
-
togoCharge = 0
|
|
77
|
-
} = input;
|
|
78
|
-
const totalOrderAmount = format2(discountableTotalAmount + nonDiscountableTotalAmount);
|
|
65
|
+
const vatRate = Number(input.vatRate || 0) / 100;
|
|
66
|
+
const scRate = Number(input.serviceChargeRate || 0) / 100;
|
|
67
|
+
const discountRate = Number(input.discountRate || 0) / 100;
|
|
68
|
+
const voucherRate = input.voucherType === "FIXED" ? input.voucherRate : Number(input.voucherRate || 0) / 100;
|
|
69
|
+
const totalOrderAmount = input.discountableTotalAmount + input.nonDiscountableTotalAmount;
|
|
79
70
|
let voucherDiscounted = 0;
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
if (voucherRate > 0) {
|
|
72
|
+
if (input.voucherType === "FIXED") {
|
|
73
|
+
voucherDiscounted = -format2(Math.min(toMoneyNumber(voucherRate), totalOrderAmount));
|
|
74
|
+
} else {
|
|
75
|
+
voucherDiscounted = -format2(totalOrderAmount * voucherRate);
|
|
76
|
+
}
|
|
85
77
|
}
|
|
78
|
+
const togoCharge = input.togoableTotalAmount > 0 ? input.togoCharge : 0;
|
|
86
79
|
const subtotal = totalOrderAmount + voucherDiscounted;
|
|
87
|
-
const voucherVatNet =
|
|
88
|
-
const voucherVat =
|
|
89
|
-
let vatNet =
|
|
90
|
-
let vat =
|
|
80
|
+
const voucherVatNet = format2(totalOrderAmount / vatRate);
|
|
81
|
+
const voucherVat = format2(voucherVatNet * 0.12);
|
|
82
|
+
let vatNet = format2(subtotal / vatRate);
|
|
83
|
+
let vat = format2(vatNet * 0.12);
|
|
91
84
|
const isSpecial = discountRate > 0;
|
|
92
|
-
const isAddVat = isAddVatAfterDiscount(discountType);
|
|
93
|
-
const discounted =
|
|
85
|
+
const isAddVat = isAddVatAfterDiscount(input.discountType);
|
|
86
|
+
const discounted = format2(discountRate / 100 * -vatNet);
|
|
94
87
|
if (isSpecial) {
|
|
95
|
-
vatNet =
|
|
88
|
+
vatNet = format2(vatNet + discounted);
|
|
96
89
|
if (!isAddVat) {
|
|
97
90
|
vat = -vat;
|
|
98
91
|
}
|
|
99
92
|
}
|
|
100
93
|
let serviceCharge = 0;
|
|
101
|
-
if (serviceChargeRate > 0 && serviceChargeableTotalAmount > 0) {
|
|
102
|
-
const scRate = serviceChargeRate / 100;
|
|
94
|
+
if (input.serviceChargeRate > 0 && input.serviceChargeableTotalAmount > 0) {
|
|
103
95
|
if (isSpecial) {
|
|
104
|
-
serviceCharge =
|
|
96
|
+
serviceCharge = format2((vatNet + Math.abs(discounted)) * scRate);
|
|
105
97
|
} else {
|
|
106
|
-
serviceCharge =
|
|
98
|
+
serviceCharge = format2(vatNet * scRate);
|
|
107
99
|
}
|
|
108
100
|
}
|
|
109
|
-
let totalAmount = vatNet + vat + serviceCharge +
|
|
101
|
+
let totalAmount = vatNet + vat + serviceCharge + togoCharge;
|
|
110
102
|
if (isSpecial && !isAddVat) {
|
|
111
103
|
totalAmount -= vat;
|
|
112
104
|
}
|
|
@@ -119,7 +111,7 @@ function calculateTotals(input) {
|
|
|
119
111
|
net: subtotal,
|
|
120
112
|
vatNet: voucherVatNet,
|
|
121
113
|
vat: voucherVat,
|
|
122
|
-
forBirDiscount: -(voucherType === "FIXED" ? voucherVatNet - Number(voucherRate.toFixed(2)) : voucherVatNet * Number(voucherRate.toFixed(2)))
|
|
114
|
+
forBirDiscount: -(input.voucherType === "FIXED" ? voucherVatNet - Number(voucherRate.toFixed(2)) : voucherVatNet * Number(voucherRate.toFixed(2)))
|
|
123
115
|
},
|
|
124
116
|
hasDiscount: discountRate > 0,
|
|
125
117
|
discount: {
|
package/dist/index.d.cts
CHANGED
|
@@ -4,15 +4,15 @@ type DiscountType = "SENIOR" | "PWD" | "NAAC" | "SOLO" | "MOV";
|
|
|
4
4
|
interface CalculateTotalsInput {
|
|
5
5
|
discountableTotalAmount: number;
|
|
6
6
|
nonDiscountableTotalAmount: number;
|
|
7
|
-
serviceChargeableTotalAmount
|
|
8
|
-
togoableTotalAmount
|
|
9
|
-
voucherType
|
|
10
|
-
voucherRate
|
|
11
|
-
discountType
|
|
12
|
-
discountRate
|
|
13
|
-
vatRate
|
|
14
|
-
serviceChargeRate
|
|
15
|
-
togoCharge
|
|
7
|
+
serviceChargeableTotalAmount: number;
|
|
8
|
+
togoableTotalAmount: number;
|
|
9
|
+
voucherType: VoucherType | null;
|
|
10
|
+
voucherRate: number;
|
|
11
|
+
discountType: DiscountType | null;
|
|
12
|
+
discountRate: number;
|
|
13
|
+
vatRate: number;
|
|
14
|
+
serviceChargeRate: number;
|
|
15
|
+
togoCharge: number;
|
|
16
16
|
}
|
|
17
17
|
interface CalculateTotalsResult {
|
|
18
18
|
gross: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,15 +4,15 @@ type DiscountType = "SENIOR" | "PWD" | "NAAC" | "SOLO" | "MOV";
|
|
|
4
4
|
interface CalculateTotalsInput {
|
|
5
5
|
discountableTotalAmount: number;
|
|
6
6
|
nonDiscountableTotalAmount: number;
|
|
7
|
-
serviceChargeableTotalAmount
|
|
8
|
-
togoableTotalAmount
|
|
9
|
-
voucherType
|
|
10
|
-
voucherRate
|
|
11
|
-
discountType
|
|
12
|
-
discountRate
|
|
13
|
-
vatRate
|
|
14
|
-
serviceChargeRate
|
|
15
|
-
togoCharge
|
|
7
|
+
serviceChargeableTotalAmount: number;
|
|
8
|
+
togoableTotalAmount: number;
|
|
9
|
+
voucherType: VoucherType | null;
|
|
10
|
+
voucherRate: number;
|
|
11
|
+
discountType: DiscountType | null;
|
|
12
|
+
discountRate: number;
|
|
13
|
+
vatRate: number;
|
|
14
|
+
serviceChargeRate: number;
|
|
15
|
+
togoCharge: number;
|
|
16
16
|
}
|
|
17
17
|
interface CalculateTotalsResult {
|
|
18
18
|
gross: number;
|
package/dist/index.js
CHANGED
|
@@ -30,51 +30,43 @@ function getDiscountBreakdown(discountType, discountedAmount) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
function calculateTotals(input) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
voucherType = null,
|
|
39
|
-
voucherRate = 0,
|
|
40
|
-
discountType = null,
|
|
41
|
-
discountRate = 0,
|
|
42
|
-
vatRate = 12,
|
|
43
|
-
serviceChargeRate = 0,
|
|
44
|
-
togoCharge = 0
|
|
45
|
-
} = input;
|
|
46
|
-
const totalOrderAmount = format2(discountableTotalAmount + nonDiscountableTotalAmount);
|
|
33
|
+
const vatRate = Number(input.vatRate || 0) / 100;
|
|
34
|
+
const scRate = Number(input.serviceChargeRate || 0) / 100;
|
|
35
|
+
const discountRate = Number(input.discountRate || 0) / 100;
|
|
36
|
+
const voucherRate = input.voucherType === "FIXED" ? input.voucherRate : Number(input.voucherRate || 0) / 100;
|
|
37
|
+
const totalOrderAmount = input.discountableTotalAmount + input.nonDiscountableTotalAmount;
|
|
47
38
|
let voucherDiscounted = 0;
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
if (voucherRate > 0) {
|
|
40
|
+
if (input.voucherType === "FIXED") {
|
|
41
|
+
voucherDiscounted = -format2(Math.min(toMoneyNumber(voucherRate), totalOrderAmount));
|
|
42
|
+
} else {
|
|
43
|
+
voucherDiscounted = -format2(totalOrderAmount * voucherRate);
|
|
44
|
+
}
|
|
53
45
|
}
|
|
46
|
+
const togoCharge = input.togoableTotalAmount > 0 ? input.togoCharge : 0;
|
|
54
47
|
const subtotal = totalOrderAmount + voucherDiscounted;
|
|
55
|
-
const voucherVatNet =
|
|
56
|
-
const voucherVat =
|
|
57
|
-
let vatNet =
|
|
58
|
-
let vat =
|
|
48
|
+
const voucherVatNet = format2(totalOrderAmount / vatRate);
|
|
49
|
+
const voucherVat = format2(voucherVatNet * 0.12);
|
|
50
|
+
let vatNet = format2(subtotal / vatRate);
|
|
51
|
+
let vat = format2(vatNet * 0.12);
|
|
59
52
|
const isSpecial = discountRate > 0;
|
|
60
|
-
const isAddVat = isAddVatAfterDiscount(discountType);
|
|
61
|
-
const discounted =
|
|
53
|
+
const isAddVat = isAddVatAfterDiscount(input.discountType);
|
|
54
|
+
const discounted = format2(discountRate / 100 * -vatNet);
|
|
62
55
|
if (isSpecial) {
|
|
63
|
-
vatNet =
|
|
56
|
+
vatNet = format2(vatNet + discounted);
|
|
64
57
|
if (!isAddVat) {
|
|
65
58
|
vat = -vat;
|
|
66
59
|
}
|
|
67
60
|
}
|
|
68
61
|
let serviceCharge = 0;
|
|
69
|
-
if (serviceChargeRate > 0 && serviceChargeableTotalAmount > 0) {
|
|
70
|
-
const scRate = serviceChargeRate / 100;
|
|
62
|
+
if (input.serviceChargeRate > 0 && input.serviceChargeableTotalAmount > 0) {
|
|
71
63
|
if (isSpecial) {
|
|
72
|
-
serviceCharge =
|
|
64
|
+
serviceCharge = format2((vatNet + Math.abs(discounted)) * scRate);
|
|
73
65
|
} else {
|
|
74
|
-
serviceCharge =
|
|
66
|
+
serviceCharge = format2(vatNet * scRate);
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
|
-
let totalAmount = vatNet + vat + serviceCharge +
|
|
69
|
+
let totalAmount = vatNet + vat + serviceCharge + togoCharge;
|
|
78
70
|
if (isSpecial && !isAddVat) {
|
|
79
71
|
totalAmount -= vat;
|
|
80
72
|
}
|
|
@@ -87,7 +79,7 @@ function calculateTotals(input) {
|
|
|
87
79
|
net: subtotal,
|
|
88
80
|
vatNet: voucherVatNet,
|
|
89
81
|
vat: voucherVat,
|
|
90
|
-
forBirDiscount: -(voucherType === "FIXED" ? voucherVatNet - Number(voucherRate.toFixed(2)) : voucherVatNet * Number(voucherRate.toFixed(2)))
|
|
82
|
+
forBirDiscount: -(input.voucherType === "FIXED" ? voucherVatNet - Number(voucherRate.toFixed(2)) : voucherVatNet * Number(voucherRate.toFixed(2)))
|
|
91
83
|
},
|
|
92
84
|
hasDiscount: discountRate > 0,
|
|
93
85
|
discount: {
|