foodbot-cart-calculations 1.0.64 → 1.0.66
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/functions/taxCalculation.js +34 -34
- package/index.js +1 -2
- package/package.json +1 -1
- package/response.json +459 -3441
|
@@ -44,15 +44,15 @@ function calculateTax2(cart, texSettings, taxType) {
|
|
|
44
44
|
}
|
|
45
45
|
promoDiscount = (promoDiscount > element.item_price * element.quantity) ? element.item_price * element.quantity : promoDiscount;
|
|
46
46
|
element.promotion_discount = JSON.parse(JSON.stringify(promoDiscount));
|
|
47
|
-
promoDiscount = parseFloat(promoDiscount).toFixed(
|
|
47
|
+
promoDiscount = parseFloat(promoDiscount).toFixed(6);
|
|
48
48
|
|
|
49
49
|
let afterDiscount = element.item_price * element.quantity - promoDiscount;
|
|
50
|
-
afterDiscount = parseFloat(afterDiscount).toFixed(
|
|
50
|
+
afterDiscount = parseFloat(afterDiscount).toFixed(6);
|
|
51
51
|
afterDiscount = afterDiscount - pointsDiscount;
|
|
52
|
-
afterDiscount = parseFloat(afterDiscount).toFixed(
|
|
52
|
+
afterDiscount = parseFloat(afterDiscount).toFixed(6);
|
|
53
53
|
afterDiscount = (afterDiscount < 0) ? 0 : afterDiscount;
|
|
54
54
|
cart.cartTotal = parseFloat(cart.cartTotal) + parseFloat(afterDiscount);
|
|
55
|
-
cart.cartTotal = parseFloat(cart.cartTotal).toFixed(
|
|
55
|
+
cart.cartTotal = parseFloat(cart.cartTotal).toFixed(6);
|
|
56
56
|
total = +element.item_price;
|
|
57
57
|
if (element.isPackage == 1) {
|
|
58
58
|
let result = await calculatePackageItemTax(cart, itemIndex, element, texSettings, afterDiscount, taxType);
|
|
@@ -75,7 +75,7 @@ function calculateTax2(cart, texSettings, taxType) {
|
|
|
75
75
|
}
|
|
76
76
|
if (itemIndex == cart.item_details.length - 1) {
|
|
77
77
|
cart.cart_total_with_tax = parseFloat(cart.cartTotal) + parseFloat(cart.tax_amount);
|
|
78
|
-
cart.cart_total_with_tax = parseFloat(cart.cart_total_with_tax).toFixed(
|
|
78
|
+
cart.cart_total_with_tax = parseFloat(cart.cart_total_with_tax).toFixed(6);
|
|
79
79
|
|
|
80
80
|
//delay
|
|
81
81
|
await new Promise((resolve) => {
|
|
@@ -125,13 +125,13 @@ function calculateItemTax(cart, itemIndex, element, tax_settings, afterDicsount,
|
|
|
125
125
|
// } else {
|
|
126
126
|
// taxAmount = (lastPrice * startItemTax.tax_rate) / 100;
|
|
127
127
|
// }
|
|
128
|
-
// taxAmount = parseFloat(taxAmount).toFixed(
|
|
129
|
-
// itemTotalTax = (parseFloat(itemTotalTax) + parseFloat(taxAmount)).toFixed(
|
|
128
|
+
// taxAmount = parseFloat(taxAmount).toFixed(6)
|
|
129
|
+
// itemTotalTax = (parseFloat(itemTotalTax) + parseFloat(taxAmount)).toFixed(6)
|
|
130
130
|
|
|
131
131
|
// cart.tax_amount = parseFloat(cart.tax_amount) + parseFloat(taxAmount)
|
|
132
|
-
// cart.tax_amount = parseFloat(cart.tax_amount).toFixed(
|
|
133
|
-
// startItemTax.base_price = parseFloat(lastPrice).toFixed(
|
|
134
|
-
// startItemTax.tax_amount = parseFloat(taxAmount).toFixed(
|
|
132
|
+
// cart.tax_amount = parseFloat(cart.tax_amount).toFixed(6)
|
|
133
|
+
// startItemTax.base_price = parseFloat(lastPrice).toFixed(6)
|
|
134
|
+
// startItemTax.tax_amount = parseFloat(taxAmount).toFixed(6)
|
|
135
135
|
// element.tax_array.push(JSON.parse(JSON.stringify(startItemTax)))
|
|
136
136
|
|
|
137
137
|
|
|
@@ -186,13 +186,13 @@ function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDi
|
|
|
186
186
|
let defaultComboDiscount = packageItem.default_combo_discount ? packageItem.default_combo_discount : 0
|
|
187
187
|
let afterDicsountPackage = packageItem.price * packageItem.quantity - promoDiscountPackage
|
|
188
188
|
|
|
189
|
-
afterDicsountPackage = parseFloat(afterDicsountPackage).toFixed(
|
|
189
|
+
afterDicsountPackage = parseFloat(afterDicsountPackage).toFixed(6)
|
|
190
190
|
afterDicsountPackage = afterDicsountPackage - pointsDisouuntPackage
|
|
191
191
|
|
|
192
|
-
afterDicsountPackage = parseFloat(afterDicsountPackage).toFixed(
|
|
192
|
+
afterDicsountPackage = parseFloat(afterDicsountPackage).toFixed(6)
|
|
193
193
|
afterDicsountPackage = afterDicsountPackage - defaultComboDiscount
|
|
194
194
|
|
|
195
|
-
afterDicsountPackage = parseFloat(afterDicsountPackage).toFixed(
|
|
195
|
+
afterDicsountPackage = parseFloat(afterDicsountPackage).toFixed(6)
|
|
196
196
|
|
|
197
197
|
getTaxSettings2(packageItem.tax_id, tax_settings, packageItem.ieps_tax).then(async (itemTaxs) => {
|
|
198
198
|
|
|
@@ -292,15 +292,15 @@ function calculateModiTax(cart, itemIndex, element, tax_settings, afterDicsount,
|
|
|
292
292
|
modi.tax_id = taxId
|
|
293
293
|
let promoDiscount = (modi.promotion_discount) ? modi.promotion_discount : 0
|
|
294
294
|
let pointsDisouunt = (modi.points_discount) ? modi.points_discount : 0
|
|
295
|
-
promoDiscount = parseFloat(promoDiscount).toFixed(
|
|
295
|
+
promoDiscount = parseFloat(promoDiscount).toFixed(6)
|
|
296
296
|
let afterDicsount = (modi.modifier_item_price * modi.quantity) * element.quantity - promoDiscount
|
|
297
297
|
afterDicsount = afterDicsount - pointsDisouunt
|
|
298
|
-
afterDicsount = parseFloat(afterDicsount).toFixed(
|
|
298
|
+
afterDicsount = parseFloat(afterDicsount).toFixed(6)
|
|
299
299
|
|
|
300
300
|
afterDicsount = (afterDicsount < 0) ? 0 : afterDicsount
|
|
301
301
|
|
|
302
302
|
cart.cartTotal = parseFloat(cart.cartTotal) + parseFloat(afterDicsount)
|
|
303
|
-
cart.cartTotal = parseFloat(cart.cartTotal).toFixed(
|
|
303
|
+
cart.cartTotal = parseFloat(cart.cartTotal).toFixed(6)
|
|
304
304
|
|
|
305
305
|
getTaxSettings2(taxId, tax_settings, iepsTax).then(async (modiItemTaxs) => {
|
|
306
306
|
|
|
@@ -412,12 +412,12 @@ function calculatePackageModiTax(cart, itemIndex, element, tax_settings, afterDi
|
|
|
412
412
|
let pointsDisouunt = (modi.points_discount) ? modi.points_discount : 0
|
|
413
413
|
let afterDicsount = (modi.modifier_item_price * modi.quantity) * element.quantity - promoDiscount
|
|
414
414
|
afterDicsount = afterDicsount - pointsDisouunt
|
|
415
|
-
afterDicsount = parseFloat(afterDicsount).toFixed(
|
|
415
|
+
afterDicsount = parseFloat(afterDicsount).toFixed(6)
|
|
416
416
|
|
|
417
417
|
afterDicsount = (afterDicsount < 0) ? 0 : afterDicsount
|
|
418
418
|
|
|
419
419
|
cart.cartTotal = parseFloat(cart.cartTotal) + parseFloat(afterDicsount)
|
|
420
|
-
cart.cartTotal = parseFloat(cart.cartTotal).toFixed(
|
|
420
|
+
cart.cartTotal = parseFloat(cart.cartTotal).toFixed(6)
|
|
421
421
|
|
|
422
422
|
getTaxSettings2(taxId, tax_settings, iepsTax).then(async (modiItemTaxs) => {
|
|
423
423
|
|
|
@@ -457,7 +457,7 @@ function calculatePackageModiTax(cart, itemIndex, element, tax_settings, afterDi
|
|
|
457
457
|
cart.tax_amount = parseFloat(cart.tax_amount).toFixed(6)
|
|
458
458
|
|
|
459
459
|
|
|
460
|
-
// modiItemTax.base_price = that.taxType == 1 ? parseFloat(afterDicsount).toFixed(
|
|
460
|
+
// modiItemTax.base_price = that.taxType == 1 ? parseFloat(afterDicsount).toFixed(6) : (parseFloat(afterDicsount) - parseFloat(taxAmount)).toFixed(6)
|
|
461
461
|
modiItemTaxArray.tax_amount = parseFloat(taxAmount).toFixed(6);
|
|
462
462
|
modiItemTaxArray.base_price = modiItemTaxArray.ieps_type ? lastPriceIeps : lastPrice;
|
|
463
463
|
modiItemTaxArray.tax_rate = modiItemTaxArray.ieps_type ? iepsTaxRate : modiItemTaxArray.tax_rate;
|
|
@@ -627,7 +627,7 @@ async function getBeforeTaxPriceOfItem(taxes, price, taxType, quantity) {
|
|
|
627
627
|
|
|
628
628
|
// Calculate taxAmount based on tax type 1 = exclusive and 2 = inclusive
|
|
629
629
|
if (taxType == 2) {
|
|
630
|
-
beforeTax = (beforeTax / (1 + totalTax / 100)).toFixed(
|
|
630
|
+
beforeTax = (beforeTax / (1 + totalTax / 100)).toFixed(6);
|
|
631
631
|
}
|
|
632
632
|
|
|
633
633
|
// ieps tax type = 1 precentage 2 absoulte
|
|
@@ -636,20 +636,20 @@ async function getBeforeTaxPriceOfItem(taxes, price, taxType, quantity) {
|
|
|
636
636
|
// Adjust beforeTax based on tax type
|
|
637
637
|
if (beforeTax >= tax.tax_rate) {
|
|
638
638
|
beforeTaxIeps = taxType == 1 ? beforeTax : beforeTax - tax.tax_rate * quantity;
|
|
639
|
-
beforeTaxIeps = parseFloat(beforeTaxIeps).toFixed(
|
|
639
|
+
beforeTaxIeps = parseFloat(beforeTaxIeps).toFixed(6)
|
|
640
640
|
iepsTaxRate = tax.tax_rate * quantity / beforeTaxIeps
|
|
641
641
|
iepsTaxRateQuantity = tax.tax_rate * quantity
|
|
642
642
|
iepsTaxRate = parseFloat(iepsTaxRate)
|
|
643
|
-
iepsTaxAmount = (tax.tax_rate * quantity).toFixed(
|
|
643
|
+
iepsTaxAmount = (tax.tax_rate * quantity).toFixed(6);
|
|
644
644
|
}
|
|
645
645
|
}
|
|
646
646
|
else if (tax.ieps_type && tax.ieps_type == 1) {
|
|
647
647
|
beforeTaxIeps = beforeTax;
|
|
648
648
|
iepsTaxRate = tax.tax_rate
|
|
649
|
-
iepsTaxAmount = (firstAmount - beforeTax - taxAmount).toFixed(
|
|
649
|
+
iepsTaxAmount = (firstAmount - beforeTax - taxAmount).toFixed(6);
|
|
650
650
|
}
|
|
651
651
|
else {
|
|
652
|
-
taxAmount = ((beforeTax * tax.tax_rate) / 100).toFixed(
|
|
652
|
+
taxAmount = ((beforeTax * tax.tax_rate) / 100).toFixed(6);
|
|
653
653
|
}
|
|
654
654
|
});
|
|
655
655
|
resolve({ beforeTax, taxAmount, beforeTaxIeps, iepsTaxRate, iepsTaxAmount, iepsTaxRateQuantity });
|
|
@@ -787,9 +787,9 @@ async function calculateItemWiseSplit(cart, itemWiseItems) {
|
|
|
787
787
|
}));
|
|
788
788
|
|
|
789
789
|
// FINAL VALUES
|
|
790
|
-
p.tax = totalTax.toFixed(
|
|
791
|
-
p.amount = subtotal.toFixed(
|
|
792
|
-
p.due = subtotal.toFixed(
|
|
790
|
+
p.tax = totalTax.toFixed(6);
|
|
791
|
+
p.amount = subtotal.toFixed(6);
|
|
792
|
+
p.due = subtotal.toFixed(6);
|
|
793
793
|
}
|
|
794
794
|
});
|
|
795
795
|
resolve(cart);
|
|
@@ -956,17 +956,17 @@ async function calculateHalfSplit(cart, options = {}) {
|
|
|
956
956
|
const remainingTax = (unpaidTotalTax - accumulatedTax);
|
|
957
957
|
const remainingAmount = (unpaidTotalAmount - accumulatedAmount);
|
|
958
958
|
|
|
959
|
-
p.tax = Number(remainingTax).toFixed(
|
|
960
|
-
p.amount = Number(remainingAmount).toFixed(
|
|
959
|
+
p.tax = Number(remainingTax).toFixed(6);
|
|
960
|
+
p.amount = Number(remainingAmount).toFixed(6);
|
|
961
961
|
p.due = p.amount;
|
|
962
962
|
} else {
|
|
963
963
|
// Non-last unpaid: assign precomputed per-person values (rounded to 2 decimals)
|
|
964
|
-
const taxAmount = Number(Number(halfSplitTaxPerPerson).toFixed(
|
|
965
|
-
const dueAmount = Number(Number(halfSplitTotalPerPerson).toFixed(
|
|
964
|
+
const taxAmount = Number(Number(halfSplitTaxPerPerson).toFixed(6));
|
|
965
|
+
const dueAmount = Number(Number(halfSplitTotalPerPerson).toFixed(6));
|
|
966
966
|
|
|
967
|
-
p.tax = taxAmount.toFixed(
|
|
968
|
-
p.amount = dueAmount.toFixed(
|
|
969
|
-
p.due = dueAmount.toFixed(
|
|
967
|
+
p.tax = taxAmount.toFixed(6);
|
|
968
|
+
p.amount = dueAmount.toFixed(6);
|
|
969
|
+
p.due = dueAmount.toFixed(6);
|
|
970
970
|
|
|
971
971
|
accumulatedTax += taxAmount;
|
|
972
972
|
accumulatedAmount += dueAmount;
|
package/index.js
CHANGED
|
@@ -76,8 +76,7 @@ async function calculateTax(inputJSON) {
|
|
|
76
76
|
})
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
let json = JSON.parse(fs.readFileSync('./sample.json', 'utf8'));
|
|
80
|
-
|
|
79
|
+
// let json = JSON.parse(fs.readFileSync('./sample.json', 'utf8'));
|
|
81
80
|
// calculateTax(json).then(res=>{
|
|
82
81
|
// // console.log(JSON.stringify(res))
|
|
83
82
|
|
package/package.json
CHANGED