foodbot-cart-calculations 1.0.2 → 1.0.3

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
@@ -71,6 +71,7 @@ function applyDistribution(body) {
71
71
  mainCart.order_items.discount = parseFloat(mainCart.order_items.discount).toFixed(2)
72
72
 
73
73
  mainCart.discount = mainCart.order_items.discount;
74
+ mainCart.order_items.total=parseFloat(mainCart.order_items.total).toFixed(2)
74
75
  resolve(mainCart);
75
76
  }).catch(err => {
76
77
  reject(err);
@@ -54,7 +54,6 @@ function calculateTax2(cart, texSettings, taxType) {
54
54
  cart.cartTotal = parseFloat(cart.cartTotal) + parseFloat(afterDiscount);
55
55
  cart.cartTotal = parseFloat(cart.cartTotal).toFixed(2);
56
56
  total = +element.item_price;
57
-
58
57
  if (element.isPackage == 1) {
59
58
  let result = await calculatePackageItemTax(cart, itemIndex, element, texSettings, afterDiscount,taxType);
60
59
  cart = result.cart;
@@ -94,37 +93,40 @@ function calculateItemTax(cart, itemIndex, element, tax_settings, afterDicsount,
94
93
  getBeforeTaxPriceOfItem(itemTaxs, lastPrice,taxType).then((resp) => {
95
94
  lastPrice = +resp.beforeTax;
96
95
  let itemTotalTax = 0;
97
-
98
- itemTaxs.forEach(async (itemTaxArray, itemTaxIndex) => {
99
- let startItemTax = JSON.parse(JSON.stringify(itemTaxArray))
100
- if (!element.tax_array) {
101
- element.tax_array = []
102
- }
103
- let taxAmount = 0
104
- if (startItemTax.ieps_type && startItemTax.ieps_type == 2) {
105
- taxAmount = lastPrice >= startItemTax.tax_rate ? startItemTax.tax_rate : 0;
106
- } else {
107
- taxAmount = (lastPrice * startItemTax.tax_rate) / 100;
108
- }
109
- taxAmount = parseFloat(taxAmount).toFixed(2)
110
- itemTotalTax = (parseFloat(itemTotalTax) + parseFloat(taxAmount)).toFixed(2)
111
-
112
- cart.tax_amount = parseFloat(cart.tax_amount) + parseFloat(taxAmount)
113
- cart.tax_amount = parseFloat(cart.tax_amount).toFixed(2)
114
- startItemTax.base_price = parseFloat(lastPrice).toFixed(2)
115
- startItemTax.tax_amount = parseFloat(taxAmount).toFixed(2)
116
- element.tax_array.push(JSON.parse(JSON.stringify(startItemTax)))
117
- cart = await setTaxes(cart, JSON.parse(JSON.stringify(startItemTax)))
118
-
119
- if (itemTaxIndex == itemTaxs.length - 1) {
120
- element.tax_amount = itemTotalTax;
121
- element.tax_amount = parseFloat(element.tax_amount).toFixed(2);
122
- element.total_tax_amount = itemTotalTax;
123
- element.total_tax_amount = parseFloat(element.total_tax_amount).toFixed(2);
124
- element.tax_amount_modifier = parseFloat(itemTotalTax).toFixed(2);
125
- resolve({ 'cart': cart, "element": element });
126
- }
127
- });
96
+ if(itemTaxs && itemTaxs.length > 0){
97
+ itemTaxs.forEach(async (itemTaxArray, itemTaxIndex) => {
98
+ let startItemTax = JSON.parse(JSON.stringify(itemTaxArray))
99
+ if (!element.tax_array) {
100
+ element.tax_array = []
101
+ }
102
+ let taxAmount = 0
103
+ if (startItemTax.ieps_type && startItemTax.ieps_type == 2) {
104
+ taxAmount = lastPrice >= startItemTax.tax_rate ? startItemTax.tax_rate : 0;
105
+ } else {
106
+ taxAmount = (lastPrice * startItemTax.tax_rate) / 100;
107
+ }
108
+ taxAmount = parseFloat(taxAmount).toFixed(2)
109
+ itemTotalTax = (parseFloat(itemTotalTax) + parseFloat(taxAmount)).toFixed(2)
110
+
111
+ cart.tax_amount = parseFloat(cart.tax_amount) + parseFloat(taxAmount)
112
+ cart.tax_amount = parseFloat(cart.tax_amount).toFixed(2)
113
+ startItemTax.base_price = parseFloat(lastPrice).toFixed(2)
114
+ startItemTax.tax_amount = parseFloat(taxAmount).toFixed(2)
115
+ element.tax_array.push(JSON.parse(JSON.stringify(startItemTax)))
116
+ cart = await setTaxes(cart, JSON.parse(JSON.stringify(startItemTax)))
117
+
118
+ if (itemTaxIndex == itemTaxs.length - 1) {
119
+ element.tax_amount = itemTotalTax;
120
+ element.tax_amount = parseFloat(element.tax_amount).toFixed(2);
121
+ element.total_tax_amount = itemTotalTax;
122
+ element.total_tax_amount = parseFloat(element.total_tax_amount).toFixed(2);
123
+ element.tax_amount_modifier = parseFloat(itemTotalTax).toFixed(2);
124
+ resolve({ 'cart': cart, "element": element });
125
+ }
126
+ });
127
+ }else{
128
+ resolve({ 'cart': cart, "element": element });
129
+ }
128
130
  });
129
131
  })
130
132
  })
@@ -160,42 +162,43 @@ function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDi
160
162
 
161
163
  await getBeforeTaxPriceOfItem(itemTaxs, lastPrice,taxType).then(async (resp) => {
162
164
  lastPrice = +resp.beforeTax;
163
-
164
- itemTaxs.forEach(async (itemTaxArray, itemTaxIndex) => {
165
-
166
- let startItemTax = JSON.parse(JSON.stringify(itemTaxArray))
167
-
168
- if (!element.package_items[packageItemIndex].tax_array) {
169
- element.package_items[packageItemIndex].tax_array = []
170
- }
171
-
172
-
173
- let taxAmount = 0
174
-
175
- if (startItemTax.ieps_type && startItemTax.ieps_type == 2) {
176
- taxAmount = lastPrice >= startItemTax.tax_rate ? startItemTax.tax_rate : 0;
177
- } else {
178
- taxAmount = (lastPrice * startItemTax.tax_rate) / 100;
179
- }
180
-
181
- taxAmount = parseFloat(taxAmount).toFixed(2)
182
- itemTotalTax = (parseFloat(itemTotalTax) + parseFloat(taxAmount)).toFixed(2)
183
- itemtaxAmount = (parseFloat(itemtaxAmount) + parseFloat(taxAmount)).toFixed(2);
184
-
185
- cart.tax_amount = parseFloat(cart.tax_amount) + parseFloat(taxAmount)
186
- cart.tax_amount = parseFloat(cart.tax_amount).toFixed(2)
187
- startItemTax.base_price = parseFloat(lastPrice).toFixed(2)
188
- startItemTax.tax_amount = parseFloat(taxAmount).toFixed(2)
189
-
190
- element.package_items[packageItemIndex].tax_array.push(JSON.parse(JSON.stringify(startItemTax)));
191
- cart = await setTaxes(cart, JSON.parse(JSON.stringify(startItemTax)))
192
-
193
- //push array yo package
194
- element = await setPackageTaxes(element, JSON.parse(JSON.stringify(startItemTax)));
195
- element.package_items[packageItemIndex].tax_amount = parseFloat(itemtaxAmount).toFixed(2);
196
- element.package_items[packageItemIndex].total_tax_amount = parseFloat(itemtaxAmount).toFixed(2);
197
- // element.package_items[packageItemIndex].tax_amount_modifier = itemTotalTax
198
- });
165
+ if(itemTaxs && itemTaxs.length > 0){
166
+ itemTaxs.forEach(async (itemTaxArray, itemTaxIndex) => {
167
+
168
+ let startItemTax = JSON.parse(JSON.stringify(itemTaxArray))
169
+
170
+ if (!element.package_items[packageItemIndex].tax_array) {
171
+ element.package_items[packageItemIndex].tax_array = []
172
+ }
173
+
174
+
175
+ let taxAmount = 0
176
+
177
+ if (startItemTax.ieps_type && startItemTax.ieps_type == 2) {
178
+ taxAmount = lastPrice >= startItemTax.tax_rate ? startItemTax.tax_rate : 0;
179
+ } else {
180
+ taxAmount = (lastPrice * startItemTax.tax_rate) / 100;
181
+ }
182
+
183
+ taxAmount = parseFloat(taxAmount).toFixed(2)
184
+ itemTotalTax = (parseFloat(itemTotalTax) + parseFloat(taxAmount)).toFixed(2)
185
+ itemtaxAmount = (parseFloat(itemtaxAmount) + parseFloat(taxAmount)).toFixed(2);
186
+
187
+ cart.tax_amount = parseFloat(cart.tax_amount) + parseFloat(taxAmount)
188
+ cart.tax_amount = parseFloat(cart.tax_amount).toFixed(2)
189
+ startItemTax.base_price = parseFloat(lastPrice).toFixed(2)
190
+ startItemTax.tax_amount = parseFloat(taxAmount).toFixed(2)
191
+
192
+ element.package_items[packageItemIndex].tax_array.push(JSON.parse(JSON.stringify(startItemTax)));
193
+ cart = await setTaxes(cart, JSON.parse(JSON.stringify(startItemTax)))
194
+
195
+ //push array yo package
196
+ element = await setPackageTaxes(element, JSON.parse(JSON.stringify(startItemTax)));
197
+ element.package_items[packageItemIndex].tax_amount = parseFloat(itemtaxAmount).toFixed(2);
198
+ element.package_items[packageItemIndex].total_tax_amount = parseFloat(itemtaxAmount).toFixed(2);
199
+ // element.package_items[packageItemIndex].tax_amount_modifier = itemTotalTax
200
+ });
201
+ }
199
202
  });
200
203
 
201
204
  element.tax_amount = (parseFloat(element.tax_amount) + parseFloat(itemtaxAmount)).toFixed(2)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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": {