foodbot-cart-calculations 1.0.52 → 1.0.54

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.
@@ -1081,7 +1081,7 @@ function setPackageDefaultDiscount(cart) {
1081
1081
  item.package_items.forEach(function (v) {
1082
1082
  //this commemted code is sceniore when user can also increas item quantity i think which is wrong
1083
1083
  // itemTotal += ((item.quantity * v.quantity) * v.price);
1084
- itemTotal += (item.quantity * v.price);
1084
+ itemTotal += (item.quantity * (v.quantity * v.price));
1085
1085
  })
1086
1086
  let packagePrice = item.quantity * item.item_price;
1087
1087
  let totalDiscount = (packagePrice < itemTotal) ? (parseFloat(itemTotal) - parseFloat(packagePrice)).toFixed(2) : 0;
@@ -1121,7 +1121,7 @@ function distributeDiscount(packageItems, totalDiscount, itemTotal, quantity) {
1121
1121
  for (const [index, item] of packageItems.entries()) {
1122
1122
  //this commemted code is sceniore when user can also increas item quantity i think which is wrong
1123
1123
  // let discountPerItem = (parseFloat(singleUnit) * (parseInt(item.quantity) * parseFloat(item.price))).toFixed(2);
1124
- let discountPerItem = (parseFloat(singleUnit) * parseFloat(item.price)).toFixed(2);
1124
+ let discountPerItem = (parseFloat(singleUnit) * parseFloat(item.price * item.quantity)).toFixed(2);
1125
1125
  totalApplied = (parseFloat(totalApplied) + parseFloat(discountPerItem)).toFixed(2);
1126
1126
  item.default_combo_discount = parseFloat(discountPerItem).toFixed(2);
1127
1127
  if (index == packageItems.length - 1) {
@@ -182,7 +182,7 @@ function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDi
182
182
  let pointsDisouuntPackage = (packageItem.points_discount) ? packageItem.points_discount : 0
183
183
 
184
184
  let defaultComboDiscount = packageItem.default_combo_discount ? packageItem.default_combo_discount : 0
185
- let afterDicsountPackage = packageItem.price * element.quantity - promoDiscountPackage
185
+ let afterDicsountPackage = packageItem.price * (packageItem.quantity * element.quantity) - promoDiscountPackage
186
186
 
187
187
  afterDicsountPackage = parseFloat(afterDicsountPackage).toFixed(2)
188
188
  afterDicsountPackage = afterDicsountPackage - pointsDisouuntPackage
@@ -201,8 +201,7 @@ function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDi
201
201
 
202
202
  let lastPrice = afterDicsountPackage
203
203
  let itemtaxAmount = 0;
204
-
205
- await getBeforeTaxPriceOfItem(itemTaxs, lastPrice, taxType, packageItem.quantity).then(async (resp) => {
204
+ await getBeforeTaxPriceOfItem(itemTaxs, lastPrice, taxType, (packageItem.quantity * element.quantity)).then(async (resp) => {
206
205
  lastPrice = resp.beforeTax;
207
206
  let lastPriceIeps = +resp.beforeTaxIeps;
208
207
  let iepsTaxRate = +resp.iepsTaxRate;
@@ -624,7 +623,7 @@ async function getBeforeTaxPriceOfItem(taxes, price, taxType, quantity) {
624
623
  // Calculate taxAmount based on tax type 1 = exclusive and 2 = inclusive
625
624
  if (taxType == 2) {
626
625
  beforeTax = (beforeTax / (1 + totalTax / 100)).toFixed(2);
627
- }
626
+ }
628
627
 
629
628
  // ieps tax type = 1 precentage 2 absoulte
630
629
  taxes.forEach((tax) => {
@@ -638,19 +637,20 @@ async function getBeforeTaxPriceOfItem(taxes, price, taxType, quantity) {
638
637
  iepsTaxRate = parseFloat(iepsTaxRate)
639
638
  iepsTaxAmount = (tax.tax_rate * quantity).toFixed(2);
640
639
  }
641
- }
642
- else if (tax.ieps_type && tax.ieps_type == 1) {
643
- beforeTaxIeps = beforeTax ;
644
- iepsTaxRate = tax.tax_rate
645
- iepsTaxAmount = (firstAmount - beforeTax - taxAmount).toFixed(2);
646
- }
647
- else{
648
- taxAmount = ((beforeTax * tax.tax_rate) / 100).toFixed(2);
649
- }
640
+ }
641
+ else if (tax.ieps_type && tax.ieps_type == 1) {
642
+ beforeTaxIeps = beforeTax ;
643
+ iepsTaxRate = tax.tax_rate
644
+ iepsTaxAmount = (firstAmount - beforeTax - taxAmount).toFixed(2);
645
+ }
646
+ else{
647
+ taxAmount = ((beforeTax * tax.tax_rate) / 100).toFixed(2);
648
+ }
650
649
  });
651
650
  resolve({ beforeTax, taxAmount, beforeTaxIeps, iepsTaxRate,iepsTaxAmount,iepsTaxRateQuantity });
652
- });
651
+ });
653
652
  }
653
+
654
654
  function setTaxes(cart, ele) {
655
655
  let index = -1;
656
656
  if (ele.ieps_type) {