foodbot-cart-calculations 1.0.51 → 1.0.53

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.
@@ -247,7 +247,8 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
247
247
  let basePrice = parseFloat(item.item_price) * item.quantity;
248
248
  let baseDiscount = ((basePrice - promoDiscount) * parseFloat(singlePriceDiscount));
249
249
  baseDiscount = parseFloat(baseDiscount).toFixed(2);
250
-
250
+ console.log("singlePriceDiscount -->", singlePriceDiscount);
251
+ console.log("baseDiscount -->", baseDiscount);
251
252
  // cap base discount
252
253
  if (parseFloat(baseDiscount) > basePrice) {
253
254
  baseDiscount = basePrice.toFixed(2);
@@ -266,6 +267,7 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
266
267
  let modiBase = parseFloat(modi.modifier_item_price) * modi.quantity * item.quantity;
267
268
  let modiDiscount = ((modiBase - modiPromoDiscount) * parseFloat(singlePriceDiscount));
268
269
  modiDiscount = parseFloat(modiDiscount).toFixed(2);
270
+ console.log("modiDiscount -->", modiDiscount);
269
271
 
270
272
  // cap modifier
271
273
  if (parseFloat(modiDiscount) > modiBase) {
@@ -298,6 +300,17 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
298
300
  }
299
301
  });
300
302
 
303
+ if ((Number(itemTotalDicount) < Number(pointsAmount) || Number(itemTotalDicount) > Number(pointsAmount)) && pointsAmount > 0 && itemTotalDicount > 0) {
304
+ let difference = Number(pointsAmount) - Number(itemTotalDicount);
305
+ difference = parseFloat(difference).toFixed(2);
306
+ if (indexes.length > 0 && difference) {
307
+ carts[indexes[0]].points_discount = (difference > 0) ? parseFloat(carts[indexes[0]].points_discount) + parseFloat(difference) : parseFloat(carts[indexes[0]].points_discount) - Math.abs(difference);
308
+ carts[indexes[0]].points_discount = parseFloat(carts[indexes[0]].points_discount).toFixed(2);
309
+ itemTotalDicount = (difference < 0) ? itemTotalDicount + difference : itemTotalDicount - Math.abs(difference);
310
+ itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
311
+ }
312
+ }
313
+
301
314
  cartObject.item_details = carts
302
315
  cartObject.store_value = pointsAmount
303
316
  cartObject.point_discount_amount = pointsAmount
@@ -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) {