foodbot-cart-calculations 1.0.11 → 1.0.13

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.
@@ -585,51 +585,59 @@ function isJson(str) {
585
585
  return true;
586
586
  }
587
587
 
588
- async function getBeforeTaxPriceOfItem(taxes, price, taxType, qty) {
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 = 0;
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
- if (!tax.ieps_type) {
600
- taxRate += parseFloat(tax.tax_rate);
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 == 1) {
606
- taxAmount = ((beforeTax * taxRate) / 100).toFixed(6);
607
- } else {
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)).toFixed(2);
615
+ }
611
616
 
612
617
  // ieps tax type = 1 precentage 2 absoulte
613
618
  taxes.forEach((tax) => {
614
- if (tax.ieps_type && tax.ieps_type == 2) {
615
- // Adjust beforeTax based on tax type
616
- if (beforeTax >= tax.tax_rate) {
617
- beforeTaxIeps = taxType == 1 ? beforeTax : (beforeTax - (tax.tax_rate * qty));
618
- beforeTaxIeps = (beforeTaxIeps).toFixed(6);
619
- iepsTaxRate = (tax.tax_rate * qty) / beforeTaxIeps;
620
- iepsTaxRate = parseFloat(iepsTaxRate).toFixed(6);
621
- iepsTaxAmount = (tax.tax_rate * qty).toFixed(6);
622
- iepsTaxRateQuantity = iepsTaxAmount;
623
- }
624
- } else if (tax.ieps_type && tax.ieps_type == 1) {
625
- beforeTaxIeps = taxType == 1 ? (beforeTax).toFixed(6) : (beforeTax / (1 + tax.tax_rate / 100)).toFixed(6);
626
- iepsTaxRate = tax.tax_rate;
627
- iepsTaxAmount = beforeTax - beforeTaxIeps;
628
- iepsTaxAmount = (iepsTaxAmount).toFixed(6)
629
- }
630
- });
631
- resolve({ beforeTax, taxAmount, beforeTaxIeps, iepsTaxRate, iepsTaxAmount, iepsTaxRateQuantity });
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).toFixed(2);
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).toFixed(2);
634
+ }
635
+ else{
636
+ taxAmount = ((beforeTax * tax.tax_rate) / 100).toFixed(2);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Package for cart calculations in which it performs discount distribution and tax distribution on order",
5
5
  "main": "index.js",
6
6
  "scripts": {