foodbot-cart-calculations 1.0.1 → 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 +1 -0
- package/functions/taxCalculation.js +84 -82
- package/package.json +1 -1
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,23 +54,22 @@ 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
|
-
let result = await calculatePackageItemTax(cart, itemIndex, element, texSettings, afterDiscount);
|
|
58
|
+
let result = await calculatePackageItemTax(cart, itemIndex, element, texSettings, afterDiscount,taxType);
|
|
60
59
|
cart = result.cart;
|
|
61
60
|
element = result.element;
|
|
62
61
|
} else {
|
|
63
|
-
let result = await calculateItemTax(cart, itemIndex, element, texSettings, afterDiscount);
|
|
62
|
+
let result = await calculateItemTax(cart, itemIndex, element, texSettings, afterDiscount,taxType);
|
|
64
63
|
cart = result.cart;
|
|
65
64
|
element = result.element;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
if (element.isPackage == 1) {
|
|
69
|
-
let result = await calculatePackageModiTax(cart, itemIndex, element, texSettings, afterDiscount);
|
|
68
|
+
let result = await calculatePackageModiTax(cart, itemIndex, element, texSettings, afterDiscount,taxType);
|
|
70
69
|
cart = result.cart;
|
|
71
70
|
element = result.element;
|
|
72
71
|
} else {
|
|
73
|
-
let result = await calculateModiTax(cart, itemIndex, element, texSettings, afterDiscount);
|
|
72
|
+
let result = await calculateModiTax(cart, itemIndex, element, texSettings, afterDiscount,taxType);
|
|
74
73
|
cart = result.cart;
|
|
75
74
|
element = result.element;
|
|
76
75
|
}
|
|
@@ -87,49 +86,52 @@ function calculateTax2(cart, texSettings, taxType) {
|
|
|
87
86
|
});
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
function calculateItemTax(cart, itemIndex, element, tax_settings, afterDicsount) {
|
|
89
|
+
function calculateItemTax(cart, itemIndex, element, tax_settings, afterDicsount,taxType) {
|
|
91
90
|
return new Promise(async (resolve, reject) => {
|
|
92
91
|
getTaxSettings2(element.tax_id, tax_settings, element.ieps_tax).then(async (itemTaxs) => {
|
|
93
92
|
let lastPrice = afterDicsount
|
|
94
|
-
getBeforeTaxPriceOfItem(itemTaxs, lastPrice).then((resp) => {
|
|
93
|
+
getBeforeTaxPriceOfItem(itemTaxs, lastPrice,taxType).then((resp) => {
|
|
95
94
|
lastPrice = +resp.beforeTax;
|
|
96
95
|
let itemTotalTax = 0;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
})
|
|
131
133
|
}
|
|
132
|
-
function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDicsount) {
|
|
134
|
+
function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDicsount,taxType) {
|
|
133
135
|
return new Promise(async (resolve, reject) => {
|
|
134
136
|
let itemTotalTax = 0;
|
|
135
137
|
element.package_items.forEach((packageItem, packageItemIndex) => {
|
|
@@ -158,44 +160,45 @@ function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDi
|
|
|
158
160
|
let lastPrice = afterDicsountPackage
|
|
159
161
|
let itemtaxAmount = 0;
|
|
160
162
|
|
|
161
|
-
await getBeforeTaxPriceOfItem(itemTaxs, lastPrice).then(async (resp) => {
|
|
163
|
+
await getBeforeTaxPriceOfItem(itemTaxs, lastPrice,taxType).then(async (resp) => {
|
|
162
164
|
lastPrice = +resp.beforeTax;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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)
|
|
@@ -208,7 +211,7 @@ function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDi
|
|
|
208
211
|
})
|
|
209
212
|
})
|
|
210
213
|
}
|
|
211
|
-
function calculateModiTax(cart, itemIndex, element, tax_settings, afterDicsount) {
|
|
214
|
+
function calculateModiTax(cart, itemIndex, element, tax_settings, afterDicsount,taxType) {
|
|
212
215
|
return new Promise(async (resolve, reject) => {
|
|
213
216
|
if (element && element.item_modifiers && element.item_modifiers.length > 0) {
|
|
214
217
|
let itemModiTotalTax = 0
|
|
@@ -250,7 +253,7 @@ function calculateModiTax(cart, itemIndex, element, tax_settings, afterDicsount)
|
|
|
250
253
|
|
|
251
254
|
let lastPrice = afterDicsount
|
|
252
255
|
if (modiItemTaxs.length > 0) {
|
|
253
|
-
await getBeforeTaxPriceOfItem(modiItemTaxs, lastPrice).then((resp) => {
|
|
256
|
+
await getBeforeTaxPriceOfItem(modiItemTaxs, lastPrice,taxType).then((resp) => {
|
|
254
257
|
lastPrice = +resp.beforeTax;
|
|
255
258
|
|
|
256
259
|
modiItemTaxs.forEach(async (modiItemTax, modiTaxItemIndex) => {
|
|
@@ -307,7 +310,7 @@ function calculateModiTax(cart, itemIndex, element, tax_settings, afterDicsount)
|
|
|
307
310
|
}
|
|
308
311
|
})
|
|
309
312
|
}
|
|
310
|
-
function calculatePackageModiTax(cart, itemIndex, element, tax_settings, afterDicsount) {
|
|
313
|
+
function calculatePackageModiTax(cart, itemIndex, element, tax_settings, afterDicsount,taxType) {
|
|
311
314
|
return new Promise(async (resolve, reject) => {
|
|
312
315
|
element.package_items.forEach((packageItem, packageItemIndex) => {
|
|
313
316
|
element.package_items[packageItemIndex].tax_amount_modifier = 0
|
|
@@ -351,7 +354,7 @@ function calculatePackageModiTax(cart, itemIndex, element, tax_settings, afterDi
|
|
|
351
354
|
let lastPrice = afterDicsount
|
|
352
355
|
|
|
353
356
|
if (modiItemTaxs.length > 0) {
|
|
354
|
-
await getBeforeTaxPriceOfItem(modiItemTaxs, lastPrice).then((resp) => {
|
|
357
|
+
await getBeforeTaxPriceOfItem(modiItemTaxs, lastPrice,taxType).then((resp) => {
|
|
355
358
|
lastPrice = +resp.beforeTax;
|
|
356
359
|
modiItemTaxs.forEach(async (modiItemTax, modiTaxItemIndex) => {
|
|
357
360
|
|
|
@@ -492,9 +495,8 @@ function isJson(str) {
|
|
|
492
495
|
return true;
|
|
493
496
|
}
|
|
494
497
|
|
|
495
|
-
async function getBeforeTaxPriceOfItem(taxes, price) {
|
|
498
|
+
async function getBeforeTaxPriceOfItem(taxes, price,taxType) {
|
|
496
499
|
return new Promise((resolve, reject) => {
|
|
497
|
-
let taxType = this.taxType;
|
|
498
500
|
let beforeTax = parseFloat(price);
|
|
499
501
|
let taxRate = 0;
|
|
500
502
|
let taxAmount = 0;
|
package/package.json
CHANGED