foodbot-cart-calculations 1.0.26 → 1.0.28

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/calculations.js CHANGED
@@ -68,13 +68,9 @@ function applyDistribution(body) {
68
68
  }
69
69
  mainCart.order_items = taxData
70
70
 
71
-
72
71
  let delivery_cost = body.delivery_cost?body.delivery_cost:0;
73
72
  let service_amount = body.service_amount?body.service_amount:0;
74
73
 
75
- mainCart.final_amount = parseFloat(mainCart.final_amount) + parseFloat(delivery_cost) + parseFloat(service_amount);
76
- mainCart.cash_expected = parseFloat(mainCart.cash_expected) + parseFloat(delivery_cost) + parseFloat(service_amount);
77
-
78
74
  let tipValue = body.tip_value?body.tip_value:0;
79
75
 
80
76
  if (body.tip_type && body.tip_type == 'percentage') {
@@ -82,6 +78,11 @@ function applyDistribution(body) {
82
78
  tipValue = parseFloat(tipValue).toFixed(2)
83
79
  }
84
80
 
81
+ mainCart.tip_amount = parseFloat(tipValue).toFixed(2);
82
+
83
+ mainCart.final_amount = parseFloat(mainCart.final_amount) + parseFloat(delivery_cost) + parseFloat(service_amount);
84
+ mainCart.cash_expected = parseFloat(mainCart.cash_expected) + parseFloat(delivery_cost) + parseFloat(service_amount);
85
+
85
86
  taxData.total_after_tax = parseFloat(taxData.total_after_tax) + parseFloat(tipValue);
86
87
  taxData.total_after_tax = parseFloat(taxData.total_after_tax).toFixed(2);
87
88
 
@@ -96,7 +97,6 @@ function applyDistribution(body) {
96
97
 
97
98
  mainCart.discount = mainCart.order_items.discount;
98
99
  mainCart.order_items.total=parseFloat(mainCart.order_items.total).toFixed(2)
99
-
100
100
 
101
101
  resolve(mainCart);
102
102
  }).catch(err => {
@@ -439,7 +439,7 @@ function getOfferDetails(carts, offer = []) {
439
439
  const offerBuyProducts = offer.offer_products.offer_buy_products.map(Number);
440
440
  const offerGetProducts = offer.offer_products.offer_get_products.map(Number);
441
441
  addItemQuantity(carts.item_details, offer).then((data) => {
442
- const descending = data.sort((a, b) => (parseInt(b.amount) > parseInt(a.amount)) ? -1 : 1);
442
+ const descending = data.sort((a, b) => (parseInt(b.amount) > parseInt(a.amount)) ? 1 : -1);
443
443
  let total = 0
444
444
  let buyItemAmount=0;
445
445
  let buyItemss =[]
@@ -338,7 +338,7 @@ function calculateModiTax(cart, itemIndex, element, tax_settings, afterDicsount,
338
338
  element.item_modifiers[modiIndex].tax_array = tax_array;
339
339
  cart = await setTaxes(cart, JSON.parse(JSON.stringify(modiItemTaxArray)));
340
340
 
341
- element.item_modifiers[modiIndex].tax_amount = parseFloat(itemModiTotalTax).toFixed(2);
341
+ element.item_modifiers[modiIndex].tax_amount = parseFloat(element.item_modifiers[modiIndex].tax_amount) + parseFloat(taxAmount);
342
342
  element.item_modifiers[modiIndex].tax_amount = parseFloat(element.item_modifiers[modiIndex].tax_amount).toFixed(6)
343
343
  element.tax_amount_modifier = parseFloat(element.tax_amount_modifier) + parseFloat(taxAmount)
344
344
  element.tax_amount_modifier = parseFloat(element.tax_amount_modifier).toFixed(6)
@@ -457,7 +457,7 @@ function calculatePackageModiTax(cart, itemIndex, element, tax_settings, afterDi
457
457
  element.package_items[packageItemIndex].modifiers[modiIndex].tax_array = tax_array;
458
458
  cart = await setTaxes(cart, JSON.parse(JSON.stringify(modiItemTaxArray)))
459
459
 
460
- element.package_items[packageItemIndex].modifiers[modiIndex].tax_amount = parseFloat(itemModiTotalTax).toFixed(2);
460
+ element.package_items[packageItemIndex].modifiers[modiIndex].tax_amount = parseFloat(element.package_items[packageItemIndex].modifiers[modiIndex].tax_amount) + parseFloat(taxAmount);
461
461
  element.package_items[packageItemIndex].tax_amount_modifier = (parseFloat(element.package_items[packageItemIndex].tax_amount_modifier) + parseFloat(taxAmount)).toFixed(6)
462
462
  element.package_items[packageItemIndex].total_tax_amount = (parseFloat(element.package_items[packageItemIndex].total_tax_amount) + parseFloat(taxAmount)).toFixed(6)
463
463
  element.tax_amount_modifier = (parseFloat(element.tax_amount_modifier) + parseFloat(taxAmount)).toFixed(6)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
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": {