foodbot-cart-calculations 1.0.57 → 1.0.58

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
@@ -132,10 +132,19 @@ function applyDistribution(body) {
132
132
 
133
133
  mainCart.order_items.discount = parseFloat(mainCart.order_items.discount) ;
134
134
  mainCart.order_items.discount = parseFloat(mainCart.order_items.discount).toFixed(2)
135
-
136
135
  mainCart.discount = mainCart.order_items.discount;
137
136
  mainCart.order_items.total=parseFloat(mainCart.order_items.total).toFixed(2)
138
-
137
+
138
+ if(mainCart.order_items && mainCart.order_items.item_details && mainCart.order_items.item_details.length > 0){
139
+ mainCart.order_items.item_details.forEach((item) =>{
140
+ let promoDisc = item.promotion_discount_modifier ?? 0;
141
+ let pointItemDisc = item.points_discount ?? 0;
142
+ let pointDisc = item.points_discount_modifier ?? 0;
143
+ let totalDiscount = (parseFloat(promoDisc) + parseFloat(pointDisc) + parseFloat(pointItemDisc)).toFixed(2);
144
+ let totalItemCost = (item.item_price_with_modifier * item.quantity).toFixed(2)
145
+ item.total_item_cost = (totalItemCost - totalDiscount).toFixed(2)
146
+ })
147
+ }
139
148
  resolve(mainCart);
140
149
  }).catch(err => {
141
150
  reject(err);
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const calculation = require('./calculations');
2
- // const fs = require('fs');
3
- // const path = require('path')
2
+ const fs = require('fs');
3
+ const path = require('path')
4
4
 
5
5
  async function calculateTax(inputJSON) {
6
6
  return new Promise(async (resolve, reject) => {
@@ -75,23 +75,23 @@ async function calculateTax(inputJSON) {
75
75
  })
76
76
  }
77
77
 
78
- // let json = JSON.parse(fs.readFileSync('./sample.json', 'utf8'));
79
- // calculateTax(json).then(res=>{
80
- // // console.log(JSON.stringify(res))
78
+ let json = JSON.parse(fs.readFileSync('./sample.json', 'utf8'));
79
+ calculateTax(json).then(res=>{
80
+ // console.log(JSON.stringify(res))
81
81
 
82
- // const jsonResponse = JSON.stringify(res, null, 2); // Format the JSON with indentation
83
- // const filePath = path.join(__dirname, 'response.json'); // File path in the same directory
82
+ const jsonResponse = JSON.stringify(res, null, 2); // Format the JSON with indentation
83
+ const filePath = path.join(__dirname, 'response.json'); // File path in the same directory
84
84
 
85
- // fs.writeFile(filePath, jsonResponse, 'utf8', err => {
86
- // if (err) {
87
- // console.error('Error writing to file:', err);
88
- // } else {
89
- // console.log('Response successfully written to response.json');
90
- // }
91
- // });
85
+ fs.writeFile(filePath, jsonResponse, 'utf8', err => {
86
+ if (err) {
87
+ console.error('Error writing to file:', err);
88
+ } else {
89
+ console.log('Response successfully written to response.json');
90
+ }
91
+ });
92
92
 
93
- // }).catch(err=>{
94
- // console.log(err)
95
- // })
93
+ }).catch(err=>{
94
+ console.log(err)
95
+ })
96
96
 
97
97
  module.exports = { calculateTax }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foodbot-cart-calculations",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
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": {
package/response.json ADDED
@@ -0,0 +1,460 @@
1
+ {
2
+ "status": "success",
3
+ "status_code": 201,
4
+ "message": "Tax calculated successfully with few details missing",
5
+ "missing_optional_fields": [
6
+ "order_type",
7
+ "restaurant_id",
8
+ "branch_id",
9
+ "request_id"
10
+ ],
11
+ "data": {
12
+ "isPos": 1,
13
+ "order_items": {
14
+ "item_details": [
15
+ {
16
+ "item_id": "dadb6147-f759-49dc-867e-cb9d0aa25d1d",
17
+ "category_id": "e46ace5b-8f14-11f0-a5b4-12b5681bf65d",
18
+ "item_price": 99,
19
+ "quantity": 1,
20
+ "item_display_text": "Monch Burge",
21
+ "item_name": "Monch Burge",
22
+ "tax_rate": 16,
23
+ "item_modifiers": [],
24
+ "isPackage": 0,
25
+ "item_price_with_modifier": 99,
26
+ "package_items": [],
27
+ "item_event": "new",
28
+ "actual_price": 0,
29
+ "tax_id": [
30
+ {
31
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021"
32
+ }
33
+ ],
34
+ "ieps_tax": {
35
+ "status": 0,
36
+ "ieps_details": {
37
+ "type": "",
38
+ "tax_id": 0
39
+ }
40
+ },
41
+ "menu_id": "6bdd9eaf-dd18-4946-8aee-03c0f98db58a",
42
+ "item_trx_id": "b2A8B3vz",
43
+ "tax_amount": "0.000000",
44
+ "tax_array": [
45
+ {
46
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
47
+ "tax_label": "IVA 16%",
48
+ "tax_rate": 16,
49
+ "tax_sequence": 1,
50
+ "base_price_effected": 0,
51
+ "tax_amount": "0.000000",
52
+ "base_price": "0.00",
53
+ "tax_rate_quantity": 0
54
+ }
55
+ ],
56
+ "tax_amount_modifier": "0.000000",
57
+ "total_tax_amount": "0.000000",
58
+ "stk_seq_id": 1,
59
+ "order_version": 2,
60
+ "wa_user_info": {
61
+ "user_id": 1000221,
62
+ "user_name": "POS Manager"
63
+ },
64
+ "sync": true,
65
+ "pos_user_id": 1000221,
66
+ "promotion_discount_modifier": 0,
67
+ "point_discount_status": true,
68
+ "points_discount": "99.00",
69
+ "points_discount_modifier": 0,
70
+ "promotion_discount": 0,
71
+ "total_item_cost": "0.00"
72
+ },
73
+ {
74
+ "item_id": "dadb6147-f759-49dc-867e-cb9d0aa25d1d",
75
+ "category_id": "e46ace5b-8f14-11f0-a5b4-12b5681bf65d",
76
+ "item_price": 99,
77
+ "quantity": 1,
78
+ "item_display_text": "Monch Burge",
79
+ "item_name": "Monch Burge",
80
+ "tax_rate": 16,
81
+ "item_modifiers": [],
82
+ "isPackage": 0,
83
+ "item_price_with_modifier": 99,
84
+ "package_items": [],
85
+ "item_event": "new",
86
+ "actual_price": 0,
87
+ "tax_id": [
88
+ {
89
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021"
90
+ }
91
+ ],
92
+ "ieps_tax": {
93
+ "status": 0,
94
+ "ieps_details": {
95
+ "type": "",
96
+ "tax_id": 0
97
+ }
98
+ },
99
+ "menu_id": "6bdd9eaf-dd18-4946-8aee-03c0f98db58a",
100
+ "item_trx_id": "0ZQABEmf",
101
+ "tax_amount": "0.000000",
102
+ "tax_array": [
103
+ {
104
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
105
+ "tax_label": "IVA 16%",
106
+ "tax_rate": 16,
107
+ "tax_sequence": 1,
108
+ "base_price_effected": 0,
109
+ "tax_amount": "0.000000",
110
+ "base_price": "0.00",
111
+ "tax_rate_quantity": 0
112
+ }
113
+ ],
114
+ "tax_amount_modifier": "0.000000",
115
+ "total_tax_amount": "0.000000",
116
+ "stk_seq_id": 1,
117
+ "order_version": 2,
118
+ "wa_user_info": {
119
+ "user_id": 1000221,
120
+ "user_name": "POS Manager"
121
+ },
122
+ "sync": true,
123
+ "pos_user_id": 1000221,
124
+ "promotion_discount_modifier": 0,
125
+ "point_discount_status": true,
126
+ "points_discount": "99.00",
127
+ "points_discount_modifier": 0,
128
+ "promotion_discount": 0,
129
+ "total_item_cost": "0.00"
130
+ },
131
+ {
132
+ "item_id": "dadb6147-f759-49dc-867e-cb9d0aa25d1d",
133
+ "category_id": "e46ace5b-8f14-11f0-a5b4-12b5681bf65d",
134
+ "item_price": 99,
135
+ "quantity": 1,
136
+ "item_display_text": "Monch Burge",
137
+ "item_name": "Monch Burge",
138
+ "tax_rate": 16,
139
+ "item_modifiers": [],
140
+ "isPackage": 0,
141
+ "item_price_with_modifier": 99,
142
+ "package_items": [],
143
+ "item_event": "new",
144
+ "actual_price": 0,
145
+ "tax_id": [
146
+ {
147
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021"
148
+ }
149
+ ],
150
+ "ieps_tax": {
151
+ "status": 0,
152
+ "ieps_details": {
153
+ "type": "",
154
+ "tax_id": 0
155
+ }
156
+ },
157
+ "menu_id": "6bdd9eaf-dd18-4946-8aee-03c0f98db58a",
158
+ "item_trx_id": "H11U43p9",
159
+ "tax_amount": "0.000000",
160
+ "tax_array": [
161
+ {
162
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
163
+ "tax_label": "IVA 16%",
164
+ "tax_rate": 16,
165
+ "tax_sequence": 1,
166
+ "base_price_effected": 0,
167
+ "tax_amount": "0.000000",
168
+ "base_price": "0.00",
169
+ "tax_rate_quantity": 0
170
+ }
171
+ ],
172
+ "tax_amount_modifier": "0.000000",
173
+ "total_tax_amount": "0.000000",
174
+ "stk_seq_id": 1,
175
+ "order_version": 2,
176
+ "wa_user_info": {
177
+ "user_id": 1000221,
178
+ "user_name": "POS Manager"
179
+ },
180
+ "sync": true,
181
+ "pos_user_id": 1000221,
182
+ "promotion_discount_modifier": 0,
183
+ "point_discount_status": true,
184
+ "points_discount": "99.00",
185
+ "points_discount_modifier": 0,
186
+ "promotion_discount": 0,
187
+ "total_item_cost": "0.00"
188
+ },
189
+ {
190
+ "menu_id": "6bdd9eaf-dd18-4946-8aee-03c0f98db58a",
191
+ "item_id": "9e90ef00-c1cd-43f4-a204-d9e3e00ed1da",
192
+ "category_id": "100ff5ec-5e3e-11f0-b5e1-1228d12cd9c5",
193
+ "item_price": 70,
194
+ "item_price_with_modifier": 74,
195
+ "quantity": 1,
196
+ "item_display_text": "Large Pizza",
197
+ "item_name": "Large Pizza",
198
+ "tax_rate": 16,
199
+ "item_modifiers": [
200
+ {
201
+ "modifier_category_id": "cf9b55fc-268b-4ad9-bf6a-c77cf173acb9",
202
+ "modifer_cat": "cf9b55fc-268b-4ad9-bf6a-c77cf173acb9",
203
+ "modifier_caetgory_name": "Pizza modifiers",
204
+ "modifier_item_id": "59bcebc1-1ac4-4779-a64d-cd14a1f2f55b",
205
+ "modifier_category_sequence": "0",
206
+ "modifier_sequence": "0undefined",
207
+ "modifier_item_price": 1,
208
+ "modifier_item_name": "Modifier 2",
209
+ "is_tax_rate_same": 1,
210
+ "tax_rate": 16,
211
+ "quantity": 1,
212
+ "item_id": "9e90ef00-c1cd-43f4-a204-d9e3e00ed1da",
213
+ "tax_id": [
214
+ {
215
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021"
216
+ }
217
+ ],
218
+ "modifier_trx_id": "uDW4x89i",
219
+ "linked_product": "",
220
+ "tax_amount": "0.000000",
221
+ "tax_array": [
222
+ {
223
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
224
+ "tax_label": "IVA 16%",
225
+ "tax_rate": 16,
226
+ "tax_sequence": 1,
227
+ "base_price_effected": 0,
228
+ "tax_amount": "0.000000",
229
+ "base_price": "0.00",
230
+ "tax_rate_quantity": 0
231
+ }
232
+ ],
233
+ "stk_seq_id": 2,
234
+ "points_discount": "1.00"
235
+ },
236
+ {
237
+ "modifier_category_id": "cf9b55fc-268b-4ad9-bf6a-c77cf173acb9",
238
+ "modifer_cat": "cf9b55fc-268b-4ad9-bf6a-c77cf173acb9",
239
+ "modifier_caetgory_name": "Pizza modifiers",
240
+ "modifier_item_id": "daf7c6c9-0c31-43b9-a526-d40d192c6b5a",
241
+ "modifier_category_sequence": "0",
242
+ "modifier_sequence": "0undefined",
243
+ "modifier_item_price": 1,
244
+ "modifier_item_name": "Modifier 3",
245
+ "is_tax_rate_same": 1,
246
+ "tax_rate": 16,
247
+ "quantity": 2,
248
+ "item_id": "9e90ef00-c1cd-43f4-a204-d9e3e00ed1da",
249
+ "tax_id": [
250
+ {
251
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021"
252
+ }
253
+ ],
254
+ "modifier_trx_id": "EC0J76AH",
255
+ "linked_product": "",
256
+ "tax_amount": "0.000000",
257
+ "tax_array": [
258
+ {
259
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
260
+ "tax_label": "IVA 16%",
261
+ "tax_rate": 16,
262
+ "tax_sequence": 1,
263
+ "base_price_effected": 0,
264
+ "tax_amount": "0.000000",
265
+ "base_price": "0.00",
266
+ "tax_rate_quantity": 0
267
+ }
268
+ ],
269
+ "stk_seq_id": 2,
270
+ "points_discount": "2.00"
271
+ },
272
+ {
273
+ "modifier_category_id": "cf9b55fc-268b-4ad9-bf6a-c77cf173acb9",
274
+ "modifer_cat": "cf9b55fc-268b-4ad9-bf6a-c77cf173acb9",
275
+ "modifier_caetgory_name": "Pizza modifiers",
276
+ "modifier_item_id": "35bf8105-f454-4d5a-a905-660c19740710",
277
+ "modifier_category_sequence": "0",
278
+ "modifier_sequence": "0undefined",
279
+ "modifier_item_price": 1,
280
+ "modifier_item_name": "Modifier 4",
281
+ "is_tax_rate_same": 1,
282
+ "tax_rate": 16,
283
+ "quantity": 1,
284
+ "item_id": "9e90ef00-c1cd-43f4-a204-d9e3e00ed1da",
285
+ "tax_id": [
286
+ {
287
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021"
288
+ }
289
+ ],
290
+ "modifier_trx_id": "EpWpPRku",
291
+ "linked_product": "",
292
+ "tax_amount": "0.000000",
293
+ "tax_array": [
294
+ {
295
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
296
+ "tax_label": "IVA 16%",
297
+ "tax_rate": 16,
298
+ "tax_sequence": 1,
299
+ "base_price_effected": 0,
300
+ "tax_amount": "0.000000",
301
+ "base_price": "0.00",
302
+ "tax_rate_quantity": 0
303
+ }
304
+ ],
305
+ "stk_seq_id": 2,
306
+ "points_discount": "1.00"
307
+ }
308
+ ],
309
+ "isPackage": 0,
310
+ "package_items": [],
311
+ "actual_price": 0,
312
+ "item_event": "new",
313
+ "tax_id": [
314
+ {
315
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021"
316
+ }
317
+ ],
318
+ "ieps_tax": {
319
+ "status": 0,
320
+ "ieps_details": {
321
+ "type": "",
322
+ "tax_id": 0
323
+ }
324
+ },
325
+ "item_trx_id": "AIbvQuCt",
326
+ "special_instruction": "",
327
+ "tax_amount": "0.000000",
328
+ "tax_array": [
329
+ {
330
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
331
+ "tax_label": "IVA 16%",
332
+ "tax_rate": 16,
333
+ "tax_sequence": 1,
334
+ "base_price_effected": 0,
335
+ "tax_amount": "0.000000",
336
+ "base_price": "0.00",
337
+ "tax_rate_quantity": 0
338
+ }
339
+ ],
340
+ "tax_amount_modifier": "0.000000",
341
+ "total_tax_amount": "0.000000",
342
+ "stk_seq_id": 2,
343
+ "order_version": 3,
344
+ "wa_user_info": {
345
+ "user_id": 1000221,
346
+ "user_name": "POS Manager"
347
+ },
348
+ "sync": true,
349
+ "pos_user_id": 1000221,
350
+ "promotion_discount_modifier": 0,
351
+ "point_discount_status": true,
352
+ "points_discount": "70.00",
353
+ "points_discount_modifier": "4.00",
354
+ "promotion_discount": 0,
355
+ "total_item_cost": "0.00"
356
+ }
357
+ ],
358
+ "total": "371.00",
359
+ "discount": "0.00",
360
+ "points_redeem_message": "",
361
+ "service_discount": 0,
362
+ "is_service_discount": false,
363
+ "delivery_discount": 0,
364
+ "is_delivery_discount": false,
365
+ "store_value": "371.00",
366
+ "point_discount_amount": "371.00",
367
+ "points_discount": "371.00",
368
+ "cartTotal": "0.00",
369
+ "tax_amount": "0.000000",
370
+ "merged_tax_array": [
371
+ {
372
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
373
+ "tax_label": "IVA 16%",
374
+ "tax_rate": 16,
375
+ "tax_sequence": 1,
376
+ "base_price_effected": 0,
377
+ "tax_amount": "0.000000",
378
+ "base_price": "0.000000",
379
+ "tax_rate_quantity": 0
380
+ }
381
+ ],
382
+ "cart_total_with_tax": "0.00",
383
+ "sub_total": "0.00",
384
+ "total_after_tax": "0.00",
385
+ "final_amount": "NaN",
386
+ "cash_expected": "NaN"
387
+ },
388
+ "tax_settings": [
389
+ {
390
+ "tax_id": "425a195c-3b37-11ed-af0e-42010ad46021",
391
+ "tax_label": "IVA 16%",
392
+ "tax_rate": 16,
393
+ "tax_sequence": 1,
394
+ "base_price_effected": 0
395
+ },
396
+ {
397
+ "tax_id": "21036b00-bdb4-4485-aaba-d088a721a67f",
398
+ "tax_label": "IVA 8%",
399
+ "tax_rate": 8,
400
+ "tax_sequence": 1,
401
+ "base_price_effected": 0
402
+ },
403
+ {
404
+ "tax_id": "e47296aa-b5ae-449f-ab5f-ff50f43a648a",
405
+ "tax_label": "Sin IVA",
406
+ "tax_rate": 0,
407
+ "tax_sequence": 3,
408
+ "base_price_effected": 0
409
+ },
410
+ {
411
+ "tax_id": "21036b00-bdb4-4485-aaba-d088a721a67f1",
412
+ "tax_label": "IEPS 8%",
413
+ "tax_rate": 8,
414
+ "tax_sequence": 2,
415
+ "base_price_effected": 0
416
+ }
417
+ ],
418
+ "tax_type": 2,
419
+ "store_value": "371.00",
420
+ "store_value_without_roundoff": "84859.00",
421
+ "loyalty_points_details": {
422
+ "points": "84859.00",
423
+ "redeemable": "yes",
424
+ "store_value": "84859.00",
425
+ "redeem_categories": [
426
+ {
427
+ "product_id": "All",
428
+ "category_id": "All"
429
+ }
430
+ ],
431
+ "original_store_value": "84859.00",
432
+ "point_amount": 371,
433
+ "status": true,
434
+ "points_redeemed": 371
435
+ },
436
+ "user_detais": {
437
+ "customer_id": 12,
438
+ "member_id": "0a424756-9357-4a3d-a595-9b33ef1961fe",
439
+ "first_name": "MD",
440
+ "last_name": "Talib",
441
+ "phone_number": "9899429030",
442
+ "country_code": "91",
443
+ "fb_sender_id": "9899429030",
444
+ "created_on": "2024-12-23 06:15:35",
445
+ "reward_plan_name": " Chocolate Crumble",
446
+ "reward_plan_id": "13",
447
+ "calling_code": "+52",
448
+ "name": "MD Talib",
449
+ "mobile": "9899429030"
450
+ },
451
+ "tip_type": "",
452
+ "tip_value": "",
453
+ "delivery_cost": 0,
454
+ "service_amount": 0,
455
+ "discount": "0.00",
456
+ "final_amount": 0,
457
+ "cash_expected": 0,
458
+ "tip_amount": "0.00"
459
+ }
460
+ }