@qrwise/pos-calculations 0.0.19 → 0.0.20

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 CHANGED
@@ -69,6 +69,11 @@ var splitDiscountTypes = [
69
69
  { type: "MOV", count: "movCount", breakdown: "mov", vatExempt: false },
70
70
  { type: "SOLO", count: "soloParentCount", breakdown: "solo", vatExempt: false }
71
71
  ];
72
+ function resolvedVatDivisor(input) {
73
+ if (input.isVatRegistered === false) return 1;
74
+ const divisor = Number(input.vatRate || 0) / 100;
75
+ return divisor > 0 ? divisor : 1;
76
+ }
72
77
  function normalizedCount(value) {
73
78
  return Math.max(0, Math.floor(toMoneyNumber(value)));
74
79
  }
@@ -79,7 +84,7 @@ function calculateSplitTotals(input) {
79
84
  const concessionCount = splitDiscountTypes.reduce((total, item) => total + normalizedCount(counts[item.count]), 0);
80
85
  const paxCount = regularCount + concessionCount;
81
86
  if (paxCount === 0) return null;
82
- const vatDivisor = Number(input.vatRate || 0) / 100;
87
+ const vatDivisor = resolvedVatDivisor(input);
83
88
  const vatRate = Math.max(0, vatDivisor - 1);
84
89
  const scRate = Number(input.serviceChargeRate || 0) / 100;
85
90
  const discountableAmount = Math.max(0, toMoneyNumber(input.discountableTotalAmount));
@@ -109,6 +114,10 @@ function calculateSplitTotals(input) {
109
114
  discountBreakdown[item.breakdown] = -discount;
110
115
  totalDiscount += discount;
111
116
  }
117
+ if (input.isVatRegistered === false) {
118
+ vatExemptSales += vatSales;
119
+ vatSales = 0;
120
+ }
112
121
  vatSales = format2(vatSales);
113
122
  vatExemptSales = format2(vatExemptSales);
114
123
  const discounted = -format2(totalDiscount);
@@ -123,7 +132,7 @@ function calculateSplitTotals(input) {
123
132
  return {
124
133
  quantity: input.quantity,
125
134
  subtotal,
126
- isAddVat: splitDiscountTypes.some((item) => !item.vatExempt && normalizedCount(counts[item.count]) > 0),
135
+ isAddVat: input.isVatRegistered !== false && splitDiscountTypes.some((item) => !item.vatExempt && normalizedCount(counts[item.count]) > 0),
127
136
  vatNet,
128
137
  vat,
129
138
  discounted,
@@ -170,7 +179,8 @@ function calculateSplitTotals(input) {
170
179
  function calculateTotals(input) {
171
180
  const splitTotals = calculateSplitTotals(input);
172
181
  if (splitTotals) return splitTotals;
173
- const vatRate = Number(input.vatRate || 0) / 100;
182
+ const vatRate = resolvedVatDivisor(input);
183
+ const vatPercent = Math.max(0, vatRate - 1);
174
184
  const scRate = Number(input.serviceChargeRate || 0) / 100;
175
185
  const discountRate = Number(input.discountRate || 0) / 100;
176
186
  const voucherRate = input.voucherType === "FIXED" ? input.voucherRate : Number(input.voucherRate || 0) / 100;
@@ -185,11 +195,11 @@ function calculateTotals(input) {
185
195
  }
186
196
  const subtotal = totalOrderAmount + voucherDiscounted;
187
197
  const voucherVatNet2 = format2(totalOrderAmount / vatRate);
188
- const voucherVat = format2(voucherVatNet2 * 0.12);
198
+ const voucherVat = format2(voucherVatNet2 * vatPercent);
189
199
  let vatNet = format2(subtotal / vatRate);
190
- let vat = format2(vatNet * 0.12);
200
+ let vat = format2(vatNet * vatPercent);
191
201
  const isSpecial = discountRate > 0;
192
- const isAddVat = isAddVatAfterDiscount(input.discountType);
202
+ const isAddVat = input.isVatRegistered === false ? false : isAddVatAfterDiscount(input.discountType);
193
203
  const discounted = format2(discountRate * -vatNet);
194
204
  if (isSpecial) {
195
205
  vatNet = format2(vatNet + discounted);
package/dist/index.d.cts CHANGED
@@ -33,6 +33,7 @@ interface CalculateTotalsInput {
33
33
  */
34
34
  paxDiscountCounts?: PaxDiscountCounts;
35
35
  vatRate: number;
36
+ isVatRegistered?: boolean;
36
37
  serviceChargeRate: number;
37
38
  togoCharge: number;
38
39
  }
package/dist/index.d.ts CHANGED
@@ -33,6 +33,7 @@ interface CalculateTotalsInput {
33
33
  */
34
34
  paxDiscountCounts?: PaxDiscountCounts;
35
35
  vatRate: number;
36
+ isVatRegistered?: boolean;
36
37
  serviceChargeRate: number;
37
38
  togoCharge: number;
38
39
  }
package/dist/index.js CHANGED
@@ -36,6 +36,11 @@ var splitDiscountTypes = [
36
36
  { type: "MOV", count: "movCount", breakdown: "mov", vatExempt: false },
37
37
  { type: "SOLO", count: "soloParentCount", breakdown: "solo", vatExempt: false }
38
38
  ];
39
+ function resolvedVatDivisor(input) {
40
+ if (input.isVatRegistered === false) return 1;
41
+ const divisor = Number(input.vatRate || 0) / 100;
42
+ return divisor > 0 ? divisor : 1;
43
+ }
39
44
  function normalizedCount(value) {
40
45
  return Math.max(0, Math.floor(toMoneyNumber(value)));
41
46
  }
@@ -46,7 +51,7 @@ function calculateSplitTotals(input) {
46
51
  const concessionCount = splitDiscountTypes.reduce((total, item) => total + normalizedCount(counts[item.count]), 0);
47
52
  const paxCount = regularCount + concessionCount;
48
53
  if (paxCount === 0) return null;
49
- const vatDivisor = Number(input.vatRate || 0) / 100;
54
+ const vatDivisor = resolvedVatDivisor(input);
50
55
  const vatRate = Math.max(0, vatDivisor - 1);
51
56
  const scRate = Number(input.serviceChargeRate || 0) / 100;
52
57
  const discountableAmount = Math.max(0, toMoneyNumber(input.discountableTotalAmount));
@@ -76,6 +81,10 @@ function calculateSplitTotals(input) {
76
81
  discountBreakdown[item.breakdown] = -discount;
77
82
  totalDiscount += discount;
78
83
  }
84
+ if (input.isVatRegistered === false) {
85
+ vatExemptSales += vatSales;
86
+ vatSales = 0;
87
+ }
79
88
  vatSales = format2(vatSales);
80
89
  vatExemptSales = format2(vatExemptSales);
81
90
  const discounted = -format2(totalDiscount);
@@ -90,7 +99,7 @@ function calculateSplitTotals(input) {
90
99
  return {
91
100
  quantity: input.quantity,
92
101
  subtotal,
93
- isAddVat: splitDiscountTypes.some((item) => !item.vatExempt && normalizedCount(counts[item.count]) > 0),
102
+ isAddVat: input.isVatRegistered !== false && splitDiscountTypes.some((item) => !item.vatExempt && normalizedCount(counts[item.count]) > 0),
94
103
  vatNet,
95
104
  vat,
96
105
  discounted,
@@ -137,7 +146,8 @@ function calculateSplitTotals(input) {
137
146
  function calculateTotals(input) {
138
147
  const splitTotals = calculateSplitTotals(input);
139
148
  if (splitTotals) return splitTotals;
140
- const vatRate = Number(input.vatRate || 0) / 100;
149
+ const vatRate = resolvedVatDivisor(input);
150
+ const vatPercent = Math.max(0, vatRate - 1);
141
151
  const scRate = Number(input.serviceChargeRate || 0) / 100;
142
152
  const discountRate = Number(input.discountRate || 0) / 100;
143
153
  const voucherRate = input.voucherType === "FIXED" ? input.voucherRate : Number(input.voucherRate || 0) / 100;
@@ -152,11 +162,11 @@ function calculateTotals(input) {
152
162
  }
153
163
  const subtotal = totalOrderAmount + voucherDiscounted;
154
164
  const voucherVatNet2 = format2(totalOrderAmount / vatRate);
155
- const voucherVat = format2(voucherVatNet2 * 0.12);
165
+ const voucherVat = format2(voucherVatNet2 * vatPercent);
156
166
  let vatNet = format2(subtotal / vatRate);
157
- let vat = format2(vatNet * 0.12);
167
+ let vat = format2(vatNet * vatPercent);
158
168
  const isSpecial = discountRate > 0;
159
- const isAddVat = isAddVatAfterDiscount(input.discountType);
169
+ const isAddVat = input.isVatRegistered === false ? false : isAddVatAfterDiscount(input.discountType);
160
170
  const discounted = format2(discountRate * -vatNet);
161
171
  if (isSpecial) {
162
172
  vatNet = format2(vatNet + discounted);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrwise/pos-calculations",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "Shared POS calculations for QR Wise POS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",