foodbot-cart-calculations 1.0.11 → 1.0.12
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 +38 -30
- package/package.json +1 -1
|
@@ -585,51 +585,59 @@ function isJson(str) {
|
|
|
585
585
|
return true;
|
|
586
586
|
}
|
|
587
587
|
|
|
588
|
-
async function getBeforeTaxPriceOfItem(taxes, price, taxType,
|
|
588
|
+
async function getBeforeTaxPriceOfItem(taxes, price, taxType, quantity) {
|
|
589
589
|
return new Promise((resolve, reject) => {
|
|
590
590
|
let beforeTax = +price;
|
|
591
591
|
let beforeTaxIeps = 0;
|
|
592
592
|
let taxRate = 0;
|
|
593
593
|
let taxAmount = 0;
|
|
594
594
|
let iepsTaxRate = 0;
|
|
595
|
-
let iepsTaxAmount
|
|
595
|
+
let iepsTaxAmount=0;
|
|
596
596
|
let iepsTaxRateQuantity = 0;
|
|
597
|
+
let totalTax = 0;
|
|
598
|
+
let firstAmount = beforeTax ;
|
|
597
599
|
|
|
598
600
|
taxes.forEach((tax) => {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
601
|
+
if (!tax.ieps_type) {
|
|
602
|
+
taxRate += parseFloat(tax.tax_rate);
|
|
603
|
+
totalTax += parseFloat(tax.tax_rate);
|
|
604
|
+
}
|
|
605
|
+
if (tax.ieps_type && tax.ieps_type == 1) {
|
|
606
|
+
totalTax += parseFloat(tax.tax_rate);
|
|
607
|
+
}else if(tax.ieps_type && tax.ieps_type == 2){
|
|
608
|
+
beforeTax = beforeTax - tax.tax_rate * quantity
|
|
609
|
+
}
|
|
602
610
|
});
|
|
603
611
|
|
|
604
612
|
// Calculate taxAmount based on tax type 1 = exclusive and 2 = inclusive
|
|
605
|
-
if (taxType ==
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
beforeTax = (beforeTax / (1 + taxRate / 100)).toFixed(6);
|
|
609
|
-
taxAmount = (price - beforeTax).toFixed(6);
|
|
610
|
-
}
|
|
613
|
+
if (taxType == 2) {
|
|
614
|
+
beforeTax = (beforeTax / (1 + totalTax / 100));
|
|
615
|
+
}
|
|
611
616
|
|
|
612
617
|
// ieps tax type = 1 precentage 2 absoulte
|
|
613
618
|
taxes.forEach((tax) => {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
619
|
+
if (tax.ieps_type && tax.ieps_type == 2) {
|
|
620
|
+
// Adjust beforeTax based on tax type
|
|
621
|
+
if (beforeTax >= tax.tax_rate) {
|
|
622
|
+
beforeTaxIeps = taxType == 1 ? beforeTax : beforeTax;
|
|
623
|
+
beforeTaxIeps = parseFloat(beforeTaxIeps).toFixed(2)
|
|
624
|
+
iepsTaxRate = tax.tax_rate * quantity / beforeTaxIeps
|
|
625
|
+
iepsTaxRateQuantity = tax.tax_rate * quantity
|
|
626
|
+
iepsTaxRate = parseFloat(iepsTaxRate)
|
|
627
|
+
iepsTaxAmount = tax.tax_rate * quantity;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
else if (tax.ieps_type && tax.ieps_type == 1) {
|
|
631
|
+
beforeTaxIeps = beforeTax ;
|
|
632
|
+
iepsTaxRate = tax.tax_rate
|
|
633
|
+
iepsTaxAmount = (firstAmount - beforeTax - taxAmount);
|
|
634
|
+
}
|
|
635
|
+
else{
|
|
636
|
+
taxAmount = ((beforeTax * tax.tax_rate) / 100);
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
resolve({ beforeTax, taxAmount, beforeTaxIeps, iepsTaxRate,iepsTaxAmount,iepsTaxRateQuantity });
|
|
640
|
+
});
|
|
633
641
|
}
|
|
634
642
|
function setTaxes(cart, ele) {
|
|
635
643
|
let index = -1;
|
package/package.json
CHANGED