foodbot-cart-calculations 1.0.23 → 1.0.25

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
@@ -52,6 +52,8 @@ function applyDistribution(body) {
52
52
  }
53
53
  taxCalculation.calculateTax2(final, taxSettings, taxType).then(taxData => {
54
54
  taxData.sub_total = taxData.cartTotal;
55
+ mainCart.final_amount = parseFloat(taxData.cartTotal);
56
+ mainCart.cash_expected = parseFloat(taxData.cartTotal) ;
55
57
  taxData.total_after_tax = taxData.cartTotal
56
58
  if (body.tax_type == 2) {
57
59
  taxData.sub_total = taxData.cartTotal - taxData.tax_amount
@@ -59,11 +61,13 @@ function applyDistribution(body) {
59
61
  }
60
62
  else {
61
63
  taxData.total_after_tax = parseFloat(taxData.cartTotal) + parseFloat(taxData.tax_amount)
62
- taxData.total_after_tax = parseFloat(taxData.total_after_tax).toFixed(2)
64
+ taxData.total_after_tax = parseFloat(taxData.total_after_tax).toFixed(2);
65
+
66
+ mainCart.final_amount = parseFloat(taxData.cartTotal) + parseFloat(taxData.tax_amount);
67
+ mainCart.cash_expected = parseFloat(taxData.cartTotal) + parseFloat(taxData.tax_amount);
63
68
  }
64
69
  mainCart.order_items = taxData
65
- mainCart.final_amount = taxData.cartTotal
66
- mainCart.cash_expected = taxData.cartTotal
70
+
67
71
 
68
72
  let delivery_cost = body.delivery_cost?body.delivery_cost:0;
69
73
  let service_amount = body.service_amount?body.service_amount:0;
@@ -238,7 +238,7 @@ function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDi
238
238
  }
239
239
  });
240
240
 
241
- element.tax_amount = (parseFloat(element.tax_amount) + parseFloat(itemTotalTax)).toFixed(6)
241
+ element.tax_amount = (parseFloat(element.tax_amount) + parseFloat(element.package_items[packageItemIndex].tax_amount)).toFixed(6)
242
242
  element.total_tax_amount = (parseFloat(element.total_tax_amount) + parseFloat(element.package_items[packageItemIndex].tax_amount)).toFixed(6)
243
243
  })
244
244
  if (packageItemIndex == element.package_items.length - 1) {
package/index.js CHANGED
@@ -72,211 +72,297 @@ async function calculateTax(inputJSON) {
72
72
  })
73
73
  }
74
74
 
75
- let json ={
76
- "order_items": {
77
- "item_details": [
78
- {
79
- "item_display_text": "Dairy Milk 3",
80
- "item_price": 186,
81
- "category_id": 501803,
82
- "order_details_id": "de52399e-3166-40af-bf7a-34c0ce0d7021",
83
- "order_id": 400524950,
84
- "restaurant_id": 400,
85
- "item_id": 9083,
86
- "special_instruction": "",
87
- "quantity": 2,
88
- "is_package": 0,
89
- "date_time": "2024-06-11 14:53:09",
90
- "item_cost": 186,
91
- "item_modifier_cost": 353,
92
- "redeem_promotion_id": 0,
93
- "promotion_discount": 0,
94
- "points_discount": 19,
95
- "net_cost": 353,
96
- "net_tax": 97.38,
97
- "tax_amount": 48.69,
98
- "total_after_tax": 353,
99
- "purchased_points": 0,
100
- "package_items": null,
101
- "status": 1,
102
- "isPackage": 0,
103
- "cetegoryModifier": [
104
- [
105
- {
106
- "linked_menu_item": 0,
107
- "modifier_item_name": "hfvjhfbv",
108
- "modifier_caetgory_name": "ABCD",
109
- "modifier_category_id": 510954,
110
- "modifier_item_price": 0,
111
- "modifier_details_id": 100018558,
112
- "order_id": 400524950,
113
- "order_details_id": "de52399e-3166-40af-bf7a-34c0ce0d7021",
114
- "modifier_item_id": 100131,
115
- "modifier_cost": 0,
116
- "tax_amount": 0,
117
- "total_after_tax": 0,
118
- "quantity": 1,
119
- "item_quantity": 2,
120
- "item_id": 9083,
121
- "date_time": "2024-06-11 14:53:09",
122
- "status": 1,
123
- "package_order_details_id": null,
124
- "points_discount": 0,
125
- "linked_product": ""
126
- },
127
- {
128
- "linked_menu_item": 0,
129
- "modifier_item_name": "fbvfbv",
130
- "modifier_caetgory_name": "ABCD",
131
- "modifier_category_id": 510954,
132
- "modifier_item_price": 0,
133
- "modifier_details_id": 100018559,
134
- "order_id": 400524950,
135
- "order_details_id": "de52399e-3166-40af-bf7a-34c0ce0d7021",
136
- "modifier_item_id": 100132,
137
- "modifier_cost": 0,
138
- "tax_amount": 0,
139
- "total_after_tax": 0,
140
- "quantity": 1,
141
- "item_quantity": 2,
142
- "item_id": 9083,
143
- "date_time": "2024-06-11 14:53:09",
144
- "status": 1,
145
- "package_order_details_id": null,
146
- "points_discount": 0,
147
- "linked_product": ""
148
- }
149
- ]
150
- ],
151
- "tax_id": [
152
- {
153
- "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
154
- }
155
- ],
156
- "ieps_tax": {
157
- "status": 0
158
- },
159
- "brand_id": "63011ad5-97bb-42c3-8ff7-484d706611ae",
160
- "menu_id": 48,
161
- "price_list_id": "56e55ca6-d246-11ed-8811-0e2fd5e35c29",
162
- "item_price_with_modifier": "186.00",
163
- "item_modifiers": [
164
- {
165
- "linked_menu_item": 0,
166
- "modifier_item_name": "hfvjhfbv",
167
- "modifier_caetgory_name": "ABCD",
168
- "modifier_category_id": 510954,
169
- "modifier_item_price": 0,
170
- "modifier_details_id": 100018558,
171
- "order_id": 400524950,
172
- "order_details_id": "de52399e-3166-40af-bf7a-34c0ce0d7021",
173
- "modifier_item_id": 100131,
174
- "modifier_cost": 0,
175
- "tax_amount": 0,
176
- "total_after_tax": 0,
177
- "quantity": 1,
178
- "item_quantity": 2,
179
- "item_id": 9083,
180
- "date_time": "2024-06-11 14:53:09",
181
- "status": 1,
182
- "package_order_details_id": null,
183
- "points_discount": 0,
184
- "linked_product": "",
185
- "tax_id": [],
186
- "price_list_id": "",
187
- "is_tax_rate_same": 1,
188
- "modifer_cat": 510954
189
- },
190
- {
191
- "linked_menu_item": 0,
192
- "modifier_item_name": "fbvfbv",
193
- "modifier_caetgory_name": "ABCD",
194
- "modifier_category_id": 510954,
195
- "modifier_item_price": 0,
196
- "modifier_details_id": 100018559,
197
- "order_id": 400524950,
198
- "order_details_id": "de52399e-3166-40af-bf7a-34c0ce0d7021",
199
- "modifier_item_id": 100132,
200
- "modifier_cost": 0,
201
- "tax_amount": 0,
202
- "total_after_tax": 0,
203
- "quantity": 1,
204
- "item_quantity": 2,
205
- "item_id": 9083,
206
- "date_time": "2024-06-11 14:53:09",
207
- "status": 1,
208
- "package_order_details_id": null,
209
- "points_discount": 0,
210
- "linked_product": "",
211
- "tax_id": [],
212
- "price_list_id": "",
213
- "is_tax_rate_same": 1,
214
- "modifer_cat": 510954
215
- }
216
- ]
217
- }
218
- ]
219
- },
220
- "tax_settings": [
221
- {
222
- "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003",
223
- "tax_label": "16% IVA",
224
- "tax_rate": 16,
225
- "tax_sequence": 1,
226
- "base_price_effected": 0
227
- },
228
- {
229
- "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120002",
230
- "tax_label": "8% IVA",
231
- "tax_rate": 8,
232
- "tax_sequence": 1,
233
- "base_price_effected": 0
234
- },
235
- {
236
- "tax_id": "9dc9be72-ba23-11ec-8422-0242ac12000200",
237
- "tax_label": "0% IVA",
238
- "tax_rate": 0,
239
- "tax_sequence": 3,
240
- "base_price_effected": 0
241
- },
242
- {
243
- "tax_id": "21036b00-bdb4-4485-aaba-d088a721a67f1",
244
- "tax_label": "IEPS 8%",
245
- "tax_rate": 8,
246
- "tax_sequence": 2,
247
- "base_price_effected": 0
248
- }
249
- ],
250
- "tax_type": 2,
251
- "store_value": 19,
252
- "store_value_without_roundoff": 19,
253
- "loyalty_points_details": {
254
- "point_amount": 19,
255
- "status": true,
256
- "store_value": 19,
257
- "redeem_categories": [
258
- {
259
- "category_id": "All"
260
- }
261
- ],
262
- "points_redeemed": 19
263
- },
264
- "user_detais": {
265
- "name": "Nikhil ",
266
- "first_name": "Nikhil ",
267
- "phone_number": "9816852375",
268
- "mobile": "9816852375"
269
- },
270
- "tip_type": "percentage",
271
- "tip_value": "10",
272
- "delivery_cost": 40,
273
- "service_amount": 0
274
- }
275
- calculateTax(json).then(res=>{
276
- console.log(JSON.stringify(res))
277
- }).catch(err=>{
278
- console.log(err)
279
- })
75
+ // let json ={
76
+ // "order_items": {
77
+ // "item_details": [
78
+ // {
79
+ // "menu_id": 320,
80
+ // "item_id": 9030,
81
+ // "category_id": 501768,
82
+ // "item_price": 80,
83
+ // "item_price_with_modifier": 215,
84
+ // "quantity": 1,
85
+ // "item_display_text": "daal rice",
86
+ // "item_name": "daal rice",
87
+ // "tax_rate": 16,
88
+ // "item_modifiers": [
89
+ // {
90
+ // "modifer_cat": 511432,
91
+ // "modifier_caetgory_name": "Bebidas sin alcohol",
92
+ // "modifier_item_id": 101383,
93
+ // "modifier_category_sequence": "0",
94
+ // "modifier_sequence": "01",
95
+ // "modifier_item_price": 20,
96
+ // "modifier_item_name": "Fanta",
97
+ // "is_tax_rate_same": 1,
98
+ // "tax_rate": 0,
99
+ // "quantity": 1,
100
+ // "item_id": 9030,
101
+ // "tax_id": [
102
+ // {
103
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
104
+ // }
105
+ // ],
106
+ // "modifier_trx_id": "ScrxcTSU",
107
+ // "linked_product": {
108
+ // "product_id": 9081,
109
+ // "product_tax_id": [
110
+ // {
111
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
112
+ // }
113
+ // ],
114
+ // "product_name": "Dairy Milk",
115
+ // "category_id": 501803,
116
+ // "ieps_tax": {
117
+ // "status": 0
118
+ // }
119
+ // },
120
+ // "tax_amount": "6.400000",
121
+ // "tax_array": [
122
+ // {
123
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003",
124
+ // "tax_label": "16% IVA",
125
+ // "tax_rate": 16,
126
+ // "tax_sequence": 1,
127
+ // "base_price_effected": 0,
128
+ // "tax_amount": "6.400000",
129
+ // "base_price": 40,
130
+ // "tax_rate_quantity": 0
131
+ // }
132
+ // ]
133
+ // },
134
+ // {
135
+ // "modifer_cat": 511432,
136
+ // "modifier_caetgory_name": "Bebidas sin alcohol",
137
+ // "modifier_item_id": 101384,
138
+ // "modifier_category_sequence": "0",
139
+ // "modifier_sequence": "02",
140
+ // "modifier_item_price": 35,
141
+ // "modifier_item_name": "Mountain Dew",
142
+ // "is_tax_rate_same": 1,
143
+ // "tax_rate": 0,
144
+ // "quantity": 1,
145
+ // "item_id": 9030,
146
+ // "tax_id": [
147
+ // {
148
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
149
+ // }
150
+ // ],
151
+ // "modifier_trx_id": "BGDqI7yI",
152
+ // "linked_product": {
153
+ // "product_id": 9081,
154
+ // "product_tax_id": [
155
+ // {
156
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
157
+ // }
158
+ // ],
159
+ // "product_name": "Dairy Milk",
160
+ // "category_id": 501803,
161
+ // "ieps_tax": {
162
+ // "status": 0
163
+ // }
164
+ // },
165
+ // "tax_amount": "11.200000",
166
+ // "tax_array": [
167
+ // {
168
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003",
169
+ // "tax_label": "16% IVA",
170
+ // "tax_rate": 16,
171
+ // "tax_sequence": 1,
172
+ // "base_price_effected": 0,
173
+ // "tax_amount": "11.200000",
174
+ // "base_price": 70,
175
+ // "tax_rate_quantity": 0
176
+ // }
177
+ // ]
178
+ // },
179
+ // {
180
+ // "modifer_cat": 511432,
181
+ // "modifier_caetgory_name": "Bebidas sin alcohol",
182
+ // "modifier_item_id": 101385,
183
+ // "modifier_category_sequence": "0",
184
+ // "modifier_sequence": "03",
185
+ // "modifier_item_price": 30,
186
+ // "modifier_item_name": "Pepsi",
187
+ // "is_tax_rate_same": 1,
188
+ // "tax_rate": 0,
189
+ // "quantity": 1,
190
+ // "item_id": 9030,
191
+ // "tax_id": [
192
+ // {
193
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
194
+ // }
195
+ // ],
196
+ // "modifier_trx_id": "hUiiwipa",
197
+ // "linked_product": {
198
+ // "product_id": 9081,
199
+ // "product_tax_id": [
200
+ // {
201
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
202
+ // }
203
+ // ],
204
+ // "product_name": "Dairy Milk",
205
+ // "category_id": 501803,
206
+ // "ieps_tax": {
207
+ // "status": 0
208
+ // }
209
+ // },
210
+ // "tax_amount": "9.600000",
211
+ // "tax_array": [
212
+ // {
213
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003",
214
+ // "tax_label": "16% IVA",
215
+ // "tax_rate": 16,
216
+ // "tax_sequence": 1,
217
+ // "base_price_effected": 0,
218
+ // "tax_amount": "9.600000",
219
+ // "base_price": 60,
220
+ // "tax_rate_quantity": 0
221
+ // }
222
+ // ]
223
+ // },
224
+ // {
225
+ // "modifer_cat": 511432,
226
+ // "modifier_caetgory_name": "Bebidas sin alcohol",
227
+ // "modifier_item_id": 101386,
228
+ // "modifier_category_sequence": "0",
229
+ // "modifier_sequence": "04",
230
+ // "modifier_item_price": 20,
231
+ // "modifier_item_name": "Spirte",
232
+ // "is_tax_rate_same": 1,
233
+ // "tax_rate": 0,
234
+ // "quantity": 1,
235
+ // "item_id": 9030,
236
+ // "tax_id": [
237
+ // {
238
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
239
+ // }
240
+ // ],
241
+ // "modifier_trx_id": "TfPyHHK7",
242
+ // "linked_product": "",
243
+ // "tax_amount": "6.400000",
244
+ // "tax_array": [
245
+ // {
246
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003",
247
+ // "tax_label": "16% IVA",
248
+ // "tax_rate": 16,
249
+ // "tax_sequence": 1,
250
+ // "base_price_effected": 0,
251
+ // "tax_amount": "6.400000",
252
+ // "base_price": 40,
253
+ // "tax_rate_quantity": 0
254
+ // }
255
+ // ]
256
+ // },
257
+ // {
258
+ // "modifer_cat": 511432,
259
+ // "modifier_caetgory_name": "Bebidas sin alcohol",
260
+ // "modifier_item_id": 101387,
261
+ // "modifier_category_sequence": "0",
262
+ // "modifier_sequence": "05",
263
+ // "modifier_item_price": 30,
264
+ // "modifier_item_name": "Thumbs Up",
265
+ // "is_tax_rate_same": 1,
266
+ // "tax_rate": 0,
267
+ // "quantity": 1,
268
+ // "item_id": 9030,
269
+ // "tax_id": [
270
+ // {
271
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
272
+ // }
273
+ // ],
274
+ // "modifier_trx_id": "5Yw17Q21",
275
+ // "linked_product": "",
276
+ // "tax_amount": "9.600000",
277
+ // "tax_array": [
278
+ // {
279
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003",
280
+ // "tax_label": "16% IVA",
281
+ // "tax_rate": 16,
282
+ // "tax_sequence": 1,
283
+ // "base_price_effected": 0,
284
+ // "tax_amount": "9.600000",
285
+ // "base_price": 60,
286
+ // "tax_rate_quantity": 0
287
+ // }
288
+ // ]
289
+ // }
290
+ // ],
291
+ // "isPackage": 0,
292
+ // "package_items": [],
293
+ // "actual_price": 0,
294
+ // "item_event": "new",
295
+ // "tax_id": [
296
+ // {
297
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003"
298
+ // }
299
+ // ],
300
+ // "ieps_tax": {
301
+ // "status": 0
302
+ // },
303
+ // "item_trx_id": "6nfb34q9",
304
+ // "special_instruction": "",
305
+ // "tax_amount": "25.600000",
306
+ // "tax_array": [
307
+ // {
308
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003",
309
+ // "tax_label": "16% IVA",
310
+ // "tax_rate": 16,
311
+ // "tax_sequence": 1,
312
+ // "base_price_effected": 0,
313
+ // "tax_amount": "25.600000",
314
+ // "base_price": 160,
315
+ // "tax_rate_quantity": 0
316
+ // }
317
+ // ],
318
+ // "tax_amount_modifier": "68.800000",
319
+ // "total_tax_amount": "68.800000",
320
+ // "active": true,
321
+ // "promotion_discount": 0
322
+ // }
323
+ // ]
324
+ // },
325
+ // "tax_settings": [
326
+ // {
327
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120003",
328
+ // "tax_label": "16% IVA",
329
+ // "tax_rate": 16,
330
+ // "tax_sequence": 1,
331
+ // "base_price_effected": 0
332
+ // },
333
+ // {
334
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac120002",
335
+ // "tax_label": "8% IVA",
336
+ // "tax_rate": 8,
337
+ // "tax_sequence": 1,
338
+ // "base_price_effected": 0
339
+ // },
340
+ // {
341
+ // "tax_id": "9dc9be72-ba23-11ec-8422-0242ac12000200",
342
+ // "tax_label": "0% IVA",
343
+ // "tax_rate": 0,
344
+ // "tax_sequence": 3,
345
+ // "base_price_effected": 0
346
+ // },
347
+ // {
348
+ // "tax_id": "21036b00-bdb4-4485-aaba-d088a721a67f1",
349
+ // "tax_label": "IEPS 8%",
350
+ // "tax_rate": 8,
351
+ // "tax_sequence": 2,
352
+ // "base_price_effected": 0
353
+ // }
354
+ // ],
355
+ // "tax_type": 1,
356
+ // "store_value": 0,
357
+ // "delivery_cost": 0,
358
+ // "service_amount": 0
359
+ // }
360
+
361
+ // calculateTax(json).then(res=>{
362
+ // console.log(JSON.stringify(res))
363
+ // }).catch(err=>{
364
+ // console.log(err)
365
+ // })
280
366
 
281
367
  module.exports = { calculateTax }
282
368
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
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": {