foodbot-cart-calculations 1.0.0

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.
@@ -0,0 +1,1030 @@
1
+ function offerCalculation(carts, offer) {
2
+ return new Promise(function (resolve, reject) {
3
+ try {
4
+ carts.total = 0
5
+ carts.item_details.forEach(element => {
6
+ let itemTotal = element.item_price * element.quantity
7
+ carts.total = carts.total + itemTotal
8
+ element.item_modifiers.forEach(mod => {
9
+ let modTotal = (mod.modifier_item_price * mod.quantity) * element.quantity
10
+ carts.total += modTotal
11
+ });
12
+ });
13
+ if (offer && offer.offer_discount_type && offer.offer_discount_type == 'buy_x_get_y') {
14
+ getOfferDetails(carts, offer).then(res => {
15
+ carts = res
16
+ if (offer && offer.oo_offer_type == 'percentage' && offer.discount_roundoff && offer.discount_roundoff == 1) {
17
+ offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
18
+ offer.oo_offer_values = JSON.parse(JSON.stringify(offer.oo_offer_value))
19
+ offer.oo_offer_type = 'absolute'
20
+ offer.oo_offer_value = Math.round(carts.discount)
21
+ getOfferDetails(carts, offer).then(res => {
22
+ resolve(res)
23
+ }).catch(error);
24
+ }
25
+ else {
26
+ resolve(carts)
27
+ }
28
+ }).catch(error => {
29
+ reject(error);
30
+ })
31
+ } else if (offer && offer.offer_discount_type && (offer.offer_discount_type == 'discount' || offer.offer_discount_type == 'manual')) {
32
+ getCategorySpeificOffer(carts, offer).then(res => {
33
+ carts = res
34
+
35
+ if (offer && offer.oo_offer_type == 'percentage' && offer.discount_roundoff && offer.discount_roundoff == 1) {
36
+ offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
37
+ offer.oo_offer_values = JSON.parse(JSON.stringify(offer.oo_offer_value))
38
+ offer.oo_offer_type = 'absolute'
39
+ offer.oo_offer_value = Math.round(carts.discount)
40
+ getCategorySpeificOffer(carts, offer).then(res => {
41
+ resolve(carts)
42
+ }).catch(error => {
43
+ reject(error);
44
+ })
45
+ } else {
46
+ resolve(carts)
47
+ }
48
+
49
+ }).catch(error => {
50
+ reject(error);
51
+ })
52
+ } else if (offer && offer.offer_discount_type && offer.offer_discount_type == 'free_product') {
53
+ getFreeProductOffer(carts, offer).then(free => {
54
+ resolve(free)
55
+ }).catch(error => {
56
+ reject(error);
57
+ })
58
+ } else {
59
+ carts.discount = 0
60
+ resolve(carts)
61
+ }
62
+ } catch (error) {
63
+ reject(error);
64
+ }
65
+ })
66
+ };
67
+
68
+ function getCategorySpeificOffer(carts, offer) {
69
+ try {
70
+ if (carts && carts.item_details) {
71
+ carts.item_details.map((a) => { a.promotion_discount = 0; a.redeem_promotion_id = 0 });
72
+
73
+ carts.item_details.forEach(function (v) {
74
+ v.promotion_discount_modifier = 0, v.promotion_discount = 0; v.redeem_promotion_id = 0
75
+ if (v.item_modifiers)
76
+ v.item_modifiers.forEach((mod) => {
77
+ mod.promotion_discount = 0; mod.redeem_promotion_id = 0
78
+ });
79
+ });
80
+
81
+ return new Promise(function (resolve, reject) {
82
+ var total = 0;
83
+ var count = 0
84
+ carts.discount = (carts.discount) ? carts.discount : 0
85
+ let afterTotal = parseFloat(carts.total) + parseFloat(carts.discount)
86
+ let indexes = []
87
+
88
+ if (parseFloat(offer.oo_min_amount) <= parseFloat(afterTotal)) {
89
+
90
+ if (offer.offer_discount_type != 'manual')
91
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
92
+
93
+ if (offer.offer_discount_type != 'manual')
94
+ if (offer.offer_products.package_items) {
95
+ offer.offer_products.package_items = offer.offer_products.package_items.map(function (x) {
96
+ return parseInt(x, 10);
97
+ });
98
+ }
99
+ else {
100
+ offer.offer_products.package_items = []
101
+ }
102
+
103
+ let foundItemsSum = 0
104
+ carts.item_details.filter((res) => {
105
+ if (!res.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes(parseInt(res.item_id)) && res.isPackage == 0) || (offer.offer_products.package_items.includes(parseInt(res.item_id)) && res.isPackage == 1))) {
106
+
107
+ foundItemsSum = foundItemsSum + res.item_price_with_modifier * res.quantity
108
+ return foundItemsSum
109
+ }
110
+ })
111
+
112
+ let offerAmount = (offer.oo_offer_value <= foundItemsSum) ? offer.oo_offer_value : foundItemsSum;
113
+ let remaningOfferAmount = offerAmount
114
+ carts.item_details.forEach((element, index) => {
115
+
116
+ if (!element.event && (offer.offer_discount_type == 'manual' || (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id)) && element.isPackage == 0) || (offer.offer_products.package_items.includes(parseInt(element.item_id)) && element.isPackage == 1))) {
117
+ var itemAmount = 0;
118
+
119
+ // Apply discount on Packages
120
+ if (element.isPackage == 1) {
121
+ if (offer.oo_offer_type == 'percentage') {
122
+ let itemTotalDiscount = 0
123
+ itemAmount = ((parseFloat(element.item_price) * parseFloat(element.quantity)) * parseFloat(offer.oo_offer_value)) / 100;
124
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount)
125
+ let itemDiscount = parseFloat(itemAmount).toFixed(2);
126
+
127
+ total = parseFloat(total) + parseFloat(itemDiscount)
128
+ total = parseFloat(total)
129
+
130
+ carts.item_details[index].package_items.forEach((packageItem, packageItemIndex) => {
131
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount = 0
132
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier = 0
133
+
134
+ //apply discount on element modifier
135
+ if (packageItem.modifiers.length > 0) {
136
+ let modiCount = 0
137
+ packageItem.modifiers.forEach((modi, modiIndex) => {
138
+ let modiItemAmount = 0
139
+ modiItemAmount = (((parseFloat(modi.modifier_item_price) * parseFloat(modi.quantity))) * element.quantity * parseFloat(offer.oo_offer_value)) / 100;
140
+
141
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)
142
+ let discount = parseFloat(modiItemAmount).toFixed(2)
143
+ total = parseFloat(total) + parseFloat(discount)
144
+ total = parseFloat(total).toFixed(2);
145
+ carts.item_details[index].package_items[packageItemIndex].modifiers[modiIndex].promotion_discount = parseFloat(modiItemAmount).toFixed(2)
146
+ carts.item_details[index].package_items[packageItemIndex].modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
147
+ modiCount++;
148
+ // if (modiCount == element.item_modifiers.length)
149
+ // count++
150
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier = (parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier) + parseFloat(modiItemAmount)).toFixed(2);
151
+ });
152
+ }
153
+ else {
154
+ // count++
155
+ }
156
+ // console.log("package carts", carts.item_details[index]);
157
+ // discount/totalamount
158
+
159
+ let singlePriceDiscount = ((parseFloat(offer.oo_offer_value) * foundItemsSum) / 100) / foundItemsSum
160
+ singlePriceDiscount = parseFloat(singlePriceDiscount).toFixed(6);
161
+ // console.log("singlePriceDiscount", singlePriceDiscount);
162
+ // let packageDisc = ((packageItem.price - packageItem.default_combo_discount) * singlePriceDiscount).toFixed(2);
163
+ let packageDisc = (((packageItem.price * parseInt(packageItem.quantity)) - packageItem.default_combo_discount) * singlePriceDiscount).toFixed(2);
164
+
165
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount = (parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount) + parseFloat(packageDisc)).toFixed(2);
166
+ carts.item_details[index].package_items[packageItemIndex].redeem_promotion_id = offer.offer_id;
167
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier = (parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier) + parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount)).toFixed(2);
168
+
169
+ carts.item_details[index].promotion_discount = (parseFloat(carts.item_details[index].promotion_discount) + parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount)).toFixed(2);
170
+ carts.item_details[index].promotion_discount_modifier = (parseFloat(carts.item_details[index].promotion_discount_modifier) + parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier)).toFixed(2);
171
+ carts.item_details[index].redeem_promotion_id = offer.offer_id;
172
+ })
173
+ count++
174
+ }
175
+ else {
176
+ let singlePriceDiscount = (offerAmount / foundItemsSum)
177
+ singlePriceDiscount = parseFloat(singlePriceDiscount).toFixed(6)
178
+
179
+ let itemTotalDiscount = 0
180
+
181
+ carts.item_details[index].package_items.forEach((packageItem, packageItemIndex) => {
182
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount = 0
183
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier = 0
184
+
185
+ if (packageItem.modifiers.length > 0) {
186
+ let modiCount = 0
187
+ packageItem.modifiers.forEach((modi, modiIndex) => {
188
+ let modiItemAmount = 0
189
+ modiItemAmount = ((parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * element.quantity) * parseFloat(singlePriceDiscount);
190
+
191
+ modiItemAmount = parseFloat(modiItemAmount).toFixed(2)
192
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)
193
+ total = parseFloat(total) + parseFloat(modiItemAmount)
194
+ total = parseFloat(total).toFixed(2);
195
+ carts.item_details[index].package_items[packageItemIndex].modifiers[modiIndex].promotion_discount = parseFloat(modiItemAmount).toFixed(2)
196
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier = (parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier) + parseFloat(modiItemAmount)).toFixed(2);
197
+ carts.item_details[index].package_items[packageItemIndex].modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
198
+ modiCount++;
199
+
200
+ // remaningOfferAmount = remaningOfferAmount - modiItemAmount
201
+
202
+ // if (modiCount == packageItem.item_modifiers.length)
203
+ // count++
204
+ });
205
+ }
206
+ else {
207
+ // count++
208
+ }
209
+ // if (totalItemFound[totalItemFound.length - 1].item_id == element.item_id) {
210
+ // itemAmount = parseFloat(remaningOfferAmount).toFixed(2)
211
+ // }
212
+ // else {
213
+
214
+ //divide single price discount with package items length
215
+ itemAmount = (((packageItem.price * parseInt(element.quantity)) - packageItem.default_combo_discount) * (singlePriceDiscount)).toFixed(2)
216
+ // }
217
+ itemAmount = parseFloat(itemAmount).toFixed(2)
218
+ total = parseFloat(total) + parseFloat(itemAmount)
219
+
220
+ if (itemAmount > 0)
221
+ indexes.push(index)
222
+
223
+ total = parseFloat(total).toFixed(2)
224
+
225
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount)
226
+ remaningOfferAmount = remaningOfferAmount - itemAmount
227
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount = (parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount) + parseFloat(itemAmount)).toFixed(2);
228
+ carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier = (parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier) + parseFloat(itemAmount)).toFixed(2);
229
+ carts.item_details[index].package_items[packageItemIndex].redeem_promotion_id = offer.offer_id;
230
+
231
+ carts.item_details[index].promotion_discount = (parseFloat(carts.item_details[index].promotion_discount) + parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount)).toFixed(2);
232
+ carts.item_details[index].promotion_discount_modifier = (parseFloat(carts.item_details[index].promotion_discount_modifier) + parseFloat(carts.item_details[index].package_items[packageItemIndex].promotion_discount_modifier)).toFixed(2);
233
+ carts.item_details[index].redeem_promotion_id = offer.offer_id;
234
+ })
235
+ count++;
236
+ }
237
+ } else {
238
+ if (offer.oo_offer_type == 'percentage') {
239
+ let itemTotalDiscount = 0
240
+ itemAmount = ((parseFloat(element.item_price) * parseFloat(element.quantity)) * parseFloat(offer.oo_offer_value)) / 100;
241
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount)
242
+ let itemDiscount = parseFloat(itemAmount).toFixed(2)
243
+
244
+ total = parseFloat(total) + parseFloat(itemDiscount)
245
+ total = parseFloat(total)
246
+ carts.item_details[index].promotion_discount_modifier = 0
247
+
248
+ //apply discount on element modifier
249
+ if (element.item_modifiers.length > 0) {
250
+ let modiCount = 0
251
+ element.item_modifiers.forEach((modi, modiIndex) => {
252
+ let modiItemAmount = 0
253
+ modiItemAmount = (((parseFloat(modi.modifier_item_price) * parseFloat(modi.quantity))) * element.quantity * parseFloat(offer.oo_offer_value)) / 100;
254
+
255
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)
256
+ let discount = parseFloat(modiItemAmount).toFixed(2)
257
+ total = parseFloat(total) + parseFloat(discount)
258
+ total = parseFloat(total).toFixed(2);
259
+ carts.item_details[index].item_modifiers[modiIndex].promotion_discount = parseFloat(modiItemAmount).toFixed(2)
260
+ carts.item_details[index].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
261
+ modiCount++;
262
+ if (modiCount == element.item_modifiers.length)
263
+ count++
264
+ });
265
+ }
266
+ else {
267
+ count++
268
+ }
269
+
270
+ // console.log("carts", carts.item_details[index]);
271
+ carts.item_details[index].promotion_discount = (parseFloat(carts.item_details[index].promotion_discount) + parseFloat(itemAmount)).toFixed(2);
272
+ carts.item_details[index].promotion_discount_modifier = (parseFloat(carts.item_details[index].promotion_discount_modifier) + parseFloat(itemTotalDiscount)).toFixed(2);
273
+ carts.item_details[index].redeem_promotion_id = offer.offer_id;
274
+ }
275
+ else {
276
+ // console.log("carts", carts.item_details[index]);
277
+
278
+ let singlePriceDiscount = offerAmount / foundItemsSum
279
+ singlePriceDiscount = parseFloat(singlePriceDiscount).toFixed(6)
280
+ let itemTotalDiscount = 0
281
+ carts.item_details[index].promotion_discount_modifier = 0
282
+ if (element.item_modifiers.length > 0) {
283
+ let modiCount = 0
284
+ element.item_modifiers.forEach((modi, modiIndex) => {
285
+ let modiItemAmount = 0
286
+ modiItemAmount = ((parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * element.quantity) * parseFloat(singlePriceDiscount);
287
+
288
+ modiItemAmount = parseFloat(modiItemAmount).toFixed(2)
289
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)
290
+ total = parseFloat(total) + parseFloat(modiItemAmount)
291
+ total = parseFloat(total).toFixed(2);
292
+ carts.item_details[index].item_modifiers[modiIndex].promotion_discount = parseFloat(modiItemAmount).toFixed(2)
293
+ carts.item_details[index].promotion_discount_modifier = (parseFloat(carts.item_details[index].promotion_discount_modifier) + parseFloat(modiItemAmount)).toFixed(2);
294
+ carts.item_details[index].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
295
+ modiCount++;
296
+
297
+ // remaningOfferAmount = remaningOfferAmount - modiItemAmount
298
+ if (modiCount == element.item_modifiers.length)
299
+ count++
300
+ });
301
+ }
302
+ else {
303
+ count++
304
+ }
305
+ // if (totalItemFound[totalItemFound.length - 1].item_id == element.item_id) {
306
+ // itemAmount = parseFloat(remaningOfferAmount).toFixed(2)
307
+ // }
308
+ // else {
309
+ itemAmount = (element.item_price * element.quantity) * singlePriceDiscount
310
+ // }
311
+ itemAmount = parseFloat(itemAmount).toFixed(2)
312
+ total = parseFloat(total) + parseFloat(itemAmount)
313
+
314
+ if (itemAmount > 0)
315
+ indexes.push(index)
316
+
317
+ total = parseFloat(total).toFixed(2)
318
+
319
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount)
320
+ remaningOfferAmount = remaningOfferAmount - itemAmount
321
+ carts.item_details[index].promotion_discount = (parseFloat(carts.item_details[index].promotion_discount) + parseFloat(itemAmount)).toFixed(2);
322
+ carts.item_details[index].promotion_discount_modifier = (parseFloat(carts.item_details[index].promotion_discount_modifier) + parseFloat(itemAmount)).toFixed(2);
323
+ carts.item_details[index].redeem_promotion_id = offer.offer_id;
324
+ }
325
+ }
326
+ } else {
327
+ count++
328
+ }
329
+
330
+ // console.log("count", count)
331
+ if (count == carts.item_details.length && carts.item_details) {
332
+ if ((Number(total) < Number(offerAmount) || Number(total) > Number(offerAmount)) && offer.oo_offer_type != 'percentage') {
333
+ let difference = Number(offerAmount) - Number(total)
334
+ difference = parseFloat(difference).toFixed(2)
335
+ difference = Math.abs(difference)
336
+
337
+ if (indexes.length > 0) {
338
+
339
+ // console.log("difference", difference)
340
+ // console.log("total", total)
341
+ // console.log("offerAmount", offerAmount)
342
+
343
+ carts.item_details[indexes[0]].promotion_discount = (Number(total) < Number(offerAmount)) ? parseFloat(carts.item_details[indexes[0]].promotion_discount) + parseFloat(difference) : parseFloat(carts.item_details[indexes[0]].promotion_discount) - difference
344
+ carts.item_details[indexes[0]].promotion_discount = parseFloat(carts.item_details[indexes[0]].promotion_discount).toFixed(2)
345
+
346
+
347
+ carts.item_details[indexes[0]].promotion_discount_modifier = (Number(total) < Number(offerAmount)) ? parseFloat(carts.item_details[indexes[0]].promotion_discount_modifier) + parseFloat(difference) : parseFloat(carts.item_details[indexes[0]].promotion_discount_modifier) - difference
348
+ carts.item_details[indexes[0]].promotion_discount_modifier = parseFloat(carts.item_details[indexes[0]].promotion_discount_modifier).toFixed(2)
349
+
350
+ total = (Number(total) < Number(offerAmount)) ? parseFloat(total) + parseFloat(difference) : parseFloat(total) - difference
351
+ total = parseFloat(total).toFixed(2)
352
+ }
353
+ }
354
+ // console.log("total", total)
355
+ carts.discount = total
356
+ resolve(carts);
357
+ }
358
+
359
+ });
360
+ }
361
+ else {
362
+ carts.discount = 0
363
+ resolve(carts);
364
+ }
365
+ })
366
+ } else {
367
+ return new Promise(function (resolve, reject) {
368
+ carts.discount = 0
369
+ resolve(carts);
370
+ })
371
+ }
372
+ } catch (error) {
373
+ reject(error)
374
+ }
375
+ }
376
+
377
+ function getOfferDetails(carts, offer = []) {
378
+ try {
379
+ buyItemAmount = 0
380
+ buyItemss = []
381
+ total = 0
382
+
383
+ offer.offer_products.get_item_count = parseInt(offer.offer_products.get_item_count);
384
+ offer.offer_products.buy_item_count = parseInt(offer.offer_products.buy_item_count);
385
+
386
+ // const buyItems = [];
387
+ // let buyItemAmount = 0;
388
+
389
+ carts.item_details.forEach(function (v) {
390
+ delete v.promotion_discount_modifier;
391
+ delete v.promotion_discount;
392
+ delete v.redeem_promotion_id;
393
+ });
394
+
395
+ carts.item_details.forEach(function (v) {
396
+ delete v.promotion_discount_modifier;
397
+ delete v.promotion_discount;
398
+ delete v.redeem_promotion_id;
399
+ if (v.item_modifiers) {
400
+ v.item_modifiers.forEach((mod) => {
401
+ delete mod.promotion_discount;
402
+ delete mod.redeem_promotion_id;
403
+ });
404
+ }
405
+ });
406
+
407
+ if (carts && carts.item_details) {
408
+ carts.item_details.map((a) => {
409
+ a.promotion_discount = 0;
410
+ a.redeem_promotion_id = 0;
411
+ a.promotion_discount_modifier = 0;
412
+ a.discount_applied = false;
413
+ });
414
+ let total = 0;
415
+ const loopArray = [];
416
+ const offerBuyProducts = offer.offer_products.offer_buy_products.map(Number);
417
+ const offerGetProducts = offer.offer_products.offer_get_products.map(Number);
418
+
419
+ return new Promise(function (resolve, reject) {
420
+ addItemQuantity(carts.item_details, offer).then((data) => {
421
+ const descending = data.sort((a, b) => (parseInt(b.amount) > parseInt(a.amount)) ? -1 : 1);
422
+ getBuyxGetYOnCondition(descending, carts, offer).then((total) => {
423
+ carts.discount = carts.totalDiscount
424
+ resolve(carts)
425
+ }).catch(error => {
426
+ reject(error)
427
+ });;
428
+ }).catch(error => {
429
+ reject(error);
430
+ })
431
+ });
432
+ } else {
433
+ return new Promise(function (resolve, reject) {
434
+ resolve({ 'offer_amount': 0, 'amount': '' });
435
+ });
436
+ }
437
+ } catch (error) {
438
+ reject(error)
439
+ }
440
+
441
+ };
442
+
443
+ function getBuyxGetYOnCondition(descending, cartData, offer) {
444
+ return new Promise(function (resolve, reject) {
445
+
446
+ try {
447
+ let carts = cartData.item_details
448
+ var desc = JSON.parse(JSON.stringify(descending));
449
+ var desc1 = JSON.parse(JSON.stringify(descending));
450
+ var amount = 0;
451
+ var buyArray = [];
452
+ var getArray = [];
453
+ let total = 0
454
+
455
+ if (!cartData.totalDiscount)
456
+ cartData.totalDiscount = 0
457
+
458
+ var buyItems = desc.filter((e) => {
459
+ if (offer.offer_products.offer_buy_products.includes(parseInt(e.item_id))) {
460
+ return e.item_id;
461
+ }
462
+ });
463
+
464
+ let totalCount = parseInt(offer.offer_products.get_item_count) + parseInt(offer.offer_products.buy_item_count);
465
+
466
+ if (
467
+ buyItems &&
468
+ parseInt(buyItems.length) >= parseInt(offer.offer_products.buy_item_count) &&
469
+ desc.length > 1 &&
470
+ descending.length >= totalCount
471
+ ) {
472
+ var buyCount = 0;
473
+ var getCount = 0;
474
+
475
+ for (var i = 0, ii = desc.length; i < ii; i++) {
476
+ let itemAmount = 0;
477
+
478
+
479
+ if (desc[i] && desc[i].get && getCount < offer.offer_products.get_item_count && getCount != offer.offer_products.get_item_count && desc[i].buy && buyCount < offer.offer_products.buy_item_count && buyCount != offer.offer_products.buy_item_count
480
+ ) {
481
+ var amt = 0;
482
+ let amtWithModi = 0;
483
+ getArray.push(desc[i].item_id);
484
+
485
+ buyCount++;
486
+ desc1[i].remove = true;
487
+ buyArray.push(desc[i].item_id);
488
+ var itemIndex = -1;
489
+
490
+ if (desc[i]) itemIndex = carts.findIndex((obj) => obj.item_id == desc[i].item.item_id);
491
+
492
+ if (offer.oo_offer_type == "percentage") {
493
+
494
+ console.log('desc[i].item.item_pricedesc[i].item.item_price', desc[i].item.item_price)
495
+
496
+ let itemTotalDiscount = 0;
497
+ itemAmount =
498
+ (parseFloat(desc[i].item.item_price)) *
499
+ parseFloat(offer.oo_offer_value) /
500
+ 100;
501
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount);
502
+ amt = parseFloat(amt) + parseFloat(itemAmount);
503
+ amt = parseFloat(amt);
504
+ amtWithModi = amt;
505
+
506
+ let modiItemAmount = 0;
507
+ cartData.totalDiscount = parseFloat(cartData.totalDiscount) + parseFloat(amt)
508
+ carts[itemIndex].promotion_discount_modifier = parseFloat(
509
+ parseFloat(carts[itemIndex].promotion_discount_modifier) +
510
+ parseFloat(amt)
511
+ ).toFixed(2);
512
+
513
+ if (desc[i].item.item_modifiers.length > 0 && offer.offer_products.order_modifiercost_use == 1) {
514
+ let modiCount = 0;
515
+
516
+ desc[i].item.item_modifiers.forEach((modi, mIndex) => {
517
+ modiItemAmount =
518
+ (((parseFloat(modi.modifier_item_price) * parseFloat(modi.quantity))) *
519
+ parseFloat(offer.oo_offer_value)) /
520
+ 100;
521
+
522
+ if (carts[itemIndex].item_modifiers[mIndex]) {
523
+ carts[itemIndex].item_modifiers[mIndex].promotion_discount = parseFloat(
524
+ modiItemAmount
525
+ ).toFixed(2);
526
+
527
+ carts[itemIndex].item_modifiers[mIndex].redeem_promotion_id = offer.offer_id;
528
+ }
529
+
530
+ cartData.totalDiscount = parseFloat(cartData.totalDiscount) + parseFloat(modiItemAmount)
531
+ carts[itemIndex].promotion_discount_modifier = parseFloat(
532
+ parseFloat(carts[itemIndex].promotion_discount_modifier) +
533
+ parseFloat(modiItemAmount)
534
+ ).toFixed(2);
535
+
536
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount);
537
+ amtWithModi = parseFloat(amtWithModi) + parseFloat(modiItemAmount);
538
+ amtWithModi = parseFloat(amtWithModi);
539
+ amt = parseFloat(amt) + parseFloat(amtWithModi);
540
+
541
+ var modiIndex = carts[itemIndex].item_modifiers.findIndex((obj) => {
542
+ return obj.modifier_item_id == modi.modifier_item_id;
543
+ });
544
+
545
+ // if (carts[itemIndex].item_modifiers[modiIndex]) {
546
+ // carts[itemIndex].item_modifiers[modiIndex].promotion_discount = parseFloat(
547
+ // modiItemAmount
548
+ // ).toFixed(2);
549
+ // carts[itemIndex].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
550
+ // }
551
+
552
+ // modiCount++;
553
+ });
554
+ } else {
555
+ }
556
+
557
+ carts[itemIndex].promotion_discount = parseFloat(
558
+ parseFloat(carts[itemIndex].promotion_discount) + parseFloat(itemAmount)
559
+ ).toFixed(2);
560
+
561
+ // carts[itemIndex].promotion_discount_modifier = parseFloat(
562
+ // parseFloat(carts[itemIndex].promotion_discount_modifier) +
563
+ // parseFloat(itemTotalDiscount)
564
+ // ).toFixed(2);
565
+ carts[itemIndex].redeem_promotion_id = offer.offer_id;
566
+ } else {
567
+ buyItemAmount = buyItemAmount + desc[i].amount;
568
+ desc[i].item.indexss = i;
569
+ buyItemss.push(desc[i].item);
570
+ }
571
+
572
+ if (parseInt(amt) != 0) {
573
+ let amtModiTotal = amt;
574
+ // carts[itemIndex].promotion_discount_modifier = amtModiTotal;
575
+ // carts[itemIndex].promotion_discount = (
576
+ // parseFloat(carts[itemIndex].promotion_discount) + parseFloat(itemAmount)
577
+ // ).toFixed(2);
578
+ total = total + amtWithModi;
579
+
580
+ // console.log('amount modifffffffffffffff', amtModiTotal)
581
+
582
+
583
+
584
+ carts[itemIndex].redeem_promotion_id = offer.offer_id;
585
+ }
586
+
587
+ getCount++;
588
+ desc1[i].remove = true;
589
+ desc1[i + 1].remove = true;
590
+ }
591
+
592
+ if (
593
+ getCount == offer.offer_products.get_item_count &&
594
+ buyCount == offer.offer_products.buy_item_count
595
+ ) {
596
+ total = parseFloat(total) + parseFloat(amount);
597
+ // cartData.totalDiscount = parseFloat(cartData.totalDiscount) + parseFloat(amount)
598
+
599
+ if (offer.offer_products.order_multi_use == 1) {
600
+ var filterItem = desc1.filter((e) => {
601
+ if (!e.remove) {
602
+ return e.item_id;
603
+ }
604
+ });
605
+
606
+ console.log('dddddddddfilterItem', filterItem)
607
+
608
+ cartData.item_details = carts
609
+ getBuyxGetYOnCondition(filterItem, cartData, offer).then((data) => {
610
+ resolve(data)
611
+ }).catch(error => {
612
+ reject(error);
613
+ })
614
+ break;
615
+ } else {
616
+ if (offer.oo_offer_type == 'absolute') {
617
+ cartData.item_details = carts
618
+ getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount).then((data) => {
619
+ resolve(data);
620
+ }).catch(error => {
621
+ reject(error);
622
+ })
623
+ }
624
+ else {
625
+ cartData.discount = cartData.totalDiscount
626
+ resolve(cartData);
627
+ }
628
+
629
+ break;
630
+ }
631
+ }
632
+ else {
633
+ cartData.discount = cartData.totalDiscount
634
+ resolve(cartData);
635
+ }
636
+ }
637
+ } else {
638
+ if (offer.oo_offer_type == 'absolute') {
639
+ cartData.item_details = carts
640
+ getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount).then((data) => {
641
+ resolve(data);
642
+ }).catch(error => {
643
+ reject(error);
644
+ })
645
+ }
646
+ else {
647
+ cartData.discount = cartData.totalDiscount
648
+ resolve(cartData);
649
+ }
650
+
651
+
652
+ }
653
+
654
+ // setTimeout(() => {
655
+ // if (total && total != 0) {
656
+ // cartData.discount = cartData.totalDiscount
657
+ // resolve(cartData);
658
+ // }
659
+ // }, 20);
660
+ } catch (e) {
661
+ reject(e);
662
+ }
663
+ });
664
+ };
665
+
666
+ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount) {
667
+ return new Promise(function (resolve, reject) {
668
+ try {
669
+ let offerAmount = offer.oo_offer_value;
670
+ let singlePriceDiscount = offerAmount / buyItemAmount;
671
+ singlePriceDiscount = parseFloat(singlePriceDiscount).toFixed(6);
672
+ let remaningOfferAmount = offer.oo_offer_value;
673
+ let count = 0;
674
+ let carts = cartObject.item_details
675
+
676
+ buyItemss.forEach((element, buyIndex) => {
677
+ let itemAmount = 0;
678
+ let itemTotalDiscount = 0;
679
+ let itemIndex = carts.findIndex((obj) => {
680
+ return obj.item_id == element.item_id && !obj.discount_applied;
681
+ });
682
+
683
+ if (itemIndex == -1) itemIndex = carts.findIndex((obj) => {
684
+ return obj.item_id == element.item_id;
685
+ });
686
+
687
+ if (!carts[itemIndex].promotion_discount_modifier) carts[itemIndex].promotion_discount_modifier = 0;
688
+
689
+ if (element.item_modifiers && element.item_modifiers.length > 0 && offer.offer_products.order_modifiercost_use == 1) {
690
+ let modiCount = 0;
691
+ element.item_modifiers.forEach((modi) => {
692
+ let modiItemAmount = 0;
693
+ let modOfferAmount = (parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * element.quantity * parseFloat(singlePriceDiscount);
694
+ modiItemAmount = (modi.modifier_item_price < modOfferAmount) ? modi.modifier_item_price : modOfferAmount;
695
+ modiItemAmount = parseFloat(modiItemAmount).toFixed(2);
696
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount);
697
+ total = parseFloat(total) + parseFloat(modiItemAmount);
698
+ total = parseFloat(total).toFixed(2);
699
+
700
+ var modiIndex = carts[itemIndex].item_modifiers.findIndex((obj) => {
701
+ return obj.modifier_item_id == modi.modifier_item_id;
702
+ });
703
+
704
+ carts[itemIndex].promotion_discount_modifier = parseFloat(carts[itemIndex].promotion_discount_modifier) + parseFloat(modiItemAmount);
705
+ carts[itemIndex].promotion_discount_modifier = parseFloat(carts[itemIndex].promotion_discount_modifier).toFixed(2);
706
+
707
+ if (modiIndex >= 0) {
708
+ if (!carts[itemIndex].item_modifiers[modiIndex].promotion_discount) carts[itemIndex].item_modifiers[modiIndex].promotion_discount = 0;
709
+ if (!carts[itemIndex].item_modifiers[modiIndex]) {
710
+ carts[itemIndex].item_modifiers[modiIndex] = {};
711
+ carts[itemIndex].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
712
+ }
713
+
714
+ carts[itemIndex].item_modifiers[modiIndex].promotion_discount = parseFloat(carts[itemIndex].item_modifiers[modiIndex].promotion_discount) + parseFloat(modiItemAmount);
715
+ carts[itemIndex].item_modifiers[modiIndex].promotion_discount = parseFloat(carts[itemIndex].item_modifiers[modiIndex].promotion_discount).toFixed(2);
716
+ carts[itemIndex].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
717
+ modiCount++;
718
+ remaningOfferAmount = remaningOfferAmount - modiItemAmount;
719
+ } else {
720
+ modiCount++;
721
+ }
722
+
723
+ if (modiCount == element.item_modifiers.length) count++;
724
+ });
725
+ } else {
726
+ count++;
727
+ }
728
+
729
+ carts[itemIndex].discount_applied = true;
730
+
731
+ if (buyItemss[buyItemss.length - 1].item_id == element.item_id) {
732
+
733
+ itemAmount = (element.item_price < remaningOfferAmount) ? element.item_price : parseFloat(remaningOfferAmount).toFixed(2);
734
+ } else {
735
+ itemAmount = element.item_price * singlePriceDiscount;
736
+ }
737
+
738
+ itemAmount = parseFloat(itemAmount);
739
+ total = parseFloat(total) + parseFloat(itemAmount);
740
+ total = parseFloat(total).toFixed(2);
741
+ itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount);
742
+ remaningOfferAmount = remaningOfferAmount - itemAmount;
743
+
744
+ carts[itemIndex].promotion_discount = (parseFloat(carts[itemIndex].promotion_discount) + parseFloat(itemAmount)).toFixed(2);
745
+ carts[itemIndex].promotion_discount_modifier = (parseFloat(carts[itemIndex].promotion_discount_modifier) + parseFloat(itemAmount)).toFixed(2);
746
+ carts[itemIndex].redeem_promotion_id = offer.offer_id;
747
+
748
+ if (count == buyItemss.length) {
749
+ cartObject.item_details = carts
750
+ cartObject.discount = total
751
+
752
+
753
+ resolve(cartObject);
754
+ }
755
+ });
756
+ } catch (error) {
757
+ reject(error);
758
+ }
759
+ });
760
+ };
761
+
762
+ function addItemQuantity(items, offer) {
763
+ return new Promise(function (resolve, reject) {
764
+ try {
765
+ var finalItems = [];
766
+ var count = 0;
767
+ items.forEach(function (element) {
768
+ if (offer.offer_products.offer_buy_products.includes(parseInt(element.item_id)) || offer.offer_products.offer_get_products.includes(parseInt(element.item_id))) {
769
+ for (var i = 1; i <= element.quantity; i++) {
770
+ if (offer.offer_products.order_modifiercost_use == 1) {
771
+ var amount = element.item_price;
772
+ var item = JSON.parse(JSON.stringify(element));
773
+ if (offer.offer_products.modifier_category.includes('all') || offer.offer_products.modifier_category.includes('All')) {
774
+ amount = element.item_price_with_modifier;
775
+ } else {
776
+ offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(function (x) {
777
+ return parseInt(x, 10);
778
+ });
779
+ var modifiers = [];
780
+ element.item_modifiers.forEach(function (modifier) {
781
+
782
+ if (offer.offer_products.modifier_category.includes(modifier.modifier_category_id)) {
783
+ amount = amount + modifier.modifier_item_price;
784
+ modifiers.push(modifier);
785
+ }
786
+ });
787
+ item.item_modifiers = modifiers;
788
+ }
789
+
790
+ finalItems.push({
791
+ 'item_id': element.item_id,
792
+ 'amount': amount,
793
+ 'item': item,
794
+ 'buy': offer.offer_products.offer_buy_products.includes(parseInt(element.item_id)),
795
+ 'get': offer.offer_products.offer_get_products.includes(parseInt(element.item_id))
796
+ });
797
+ } else {
798
+ finalItems.push({
799
+ 'item': element,
800
+ 'item_id': element.item_id,
801
+ // / element.quantity
802
+ 'amount': element.item_price,
803
+ 'buy': offer.offer_products.offer_buy_products.includes(parseInt(element.item_id)),
804
+ 'get': offer.offer_products.offer_get_products.includes(parseInt(element.item_id))
805
+ });
806
+ }
807
+ }
808
+ } else {
809
+ count++;
810
+ }
811
+ count++;
812
+ if (count == items.length) {
813
+ resolve(finalItems);
814
+ }
815
+ });
816
+ } catch (error) {
817
+ reject(error)
818
+ }
819
+
820
+ });
821
+ };
822
+
823
+ function getFreeProductOffer(cartObject, offer) {
824
+ try {
825
+ let carts = cartObject.item_details;
826
+ carts.forEach(function (v) {
827
+ v.promotion_discount_modifier = 0;
828
+ v.promotion_discount = 0;
829
+ v.redeem_promotion_id = 0;
830
+ if (v.item_modifiers) v.item_modifiers.forEach((mod) => {
831
+ mod.promotion_discount = 0;
832
+ mod.redeem_promotion_id = 0;
833
+ });
834
+ });
835
+
836
+ var cartItem = JSON.parse(JSON.stringify(carts));
837
+
838
+ if (carts) {
839
+ carts.map((a) => {
840
+ a.promotion_discount = 0;
841
+ a.redeem_promotion_id = 0;
842
+ a.remove = false;
843
+ });
844
+
845
+ return new Promise(function (resolve, reject) {
846
+ var total = 0;
847
+ var count = 0;
848
+ var offerAmount = offer.oo_offer_value;
849
+ offer.offer_products.offer_discount_products = offer.offer_products.offer_discount_products.map(Number);
850
+
851
+ if (offer.offer_products.order_modifiercost_use == 1) {
852
+ cartItem.sort(function (a, b) {
853
+ return a.item_price_with_modifier / a.quantity > b.item_price_with_modifier / b.quantity ? 1 : -1;
854
+ });
855
+ } else {
856
+ cartItem.sort(function (a, b) {
857
+ return a.item_price / a.quantity > b.item_price / b.quantity ? 1 : -1;
858
+ });
859
+ }
860
+
861
+ var maxProduct = offer.offer_products.max_product;
862
+
863
+ cartItem.forEach((element, index) => {
864
+ var ItemIndex = carts.findIndex((x) => x.item_id == element.item_id && !x.remove);
865
+
866
+ if (offer.offer_products.offer_discount_products.includes(parseInt(element.item_id))) {
867
+ var offerAmount = 0;
868
+ let costWithOutModifier = 0;
869
+ var singleItemCost = element.item_price;
870
+
871
+ if (offer.offer_products.order_modifiercost_use == 1) {
872
+ if (offer.offer_products.modifier_category.includes('all') || offer.offer_products.modifier_category.includes('All')) {
873
+ element.item_modifiers.forEach((elementMod, modiIndex) => {
874
+ if (!carts[ItemIndex].item_modifiers[modiIndex].promotion_discount)
875
+ carts[ItemIndex].item_modifiers[modiIndex].promotion_discount = 0;
876
+
877
+ let singModPrice = elementMod.modifier_item_price * elementMod.quantity;
878
+ let promotionDiscount = singModPrice * (element.quantity <= maxProduct ? element.quantity : maxProduct);
879
+
880
+ carts[ItemIndex].item_modifiers[modiIndex].promotion_discount = parseFloat(promotionDiscount).toFixed(2);
881
+ carts[ItemIndex].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
882
+ singleItemCost = singleItemCost + singModPrice;
883
+ });
884
+ } else {
885
+ offer.offer_products.modifier_category = offer.offer_products.modifier_category.map(function (x) {
886
+ return parseInt(x, 10);
887
+ });
888
+
889
+ element.item_modifiers.forEach((modifier, modiIndex) => {
890
+ if (offer.offer_products.modifier_category.includes(modifier.modifier_category_id)) {
891
+ let singModPrice1 = modifier.modifier_item_price * modifier.quantity;
892
+
893
+ if (!carts[ItemIndex].item_modifiers[modiIndex].promotion_discount)
894
+ carts[ItemIndex].item_modifiers[modiIndex].promotion_discount = 0;
895
+
896
+ carts[ItemIndex].item_modifiers[modiIndex].promotion_discount = singModPrice1;
897
+ carts[ItemIndex].item_modifiers[modiIndex].promotion_discount = parseFloat(carts[ItemIndex].item_modifiers[modiIndex].promotion_discount).toFixed(2);
898
+ carts[ItemIndex].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
899
+ singleItemCost = singleItemCost + singModPrice1;
900
+ }
901
+ });
902
+ }
903
+ }
904
+
905
+ if (element.quantity <= maxProduct) {
906
+ maxProduct = maxProduct - element.quantity;
907
+ offerAmount = singleItemCost * element.quantity;
908
+ costWithOutModifier = costWithOutModifier + (element.item_price * element.quantity);
909
+ } else {
910
+ offerAmount = singleItemCost * maxProduct;
911
+ costWithOutModifier = element.item_price * maxProduct;
912
+ maxProduct = 0;
913
+ }
914
+
915
+ total = total + parseFloat(offerAmount);
916
+
917
+ carts[ItemIndex].promotion_discount_modifier = parseFloat(offerAmount).toFixed(2);
918
+ carts[ItemIndex].promotion_discount = parseFloat(costWithOutModifier).toFixed(2);
919
+ carts[ItemIndex].remove = true;
920
+
921
+ if (offerAmount > 0) {
922
+ carts[ItemIndex].redeem_promotion_id = offer.offer_id;
923
+ } else {
924
+ carts[ItemIndex].item_modifiers.map((res) => {
925
+ res.promotion_discount = 0;
926
+ res.redeem_promotion_id = 0;
927
+ });
928
+ }
929
+ count++;
930
+ } else {
931
+ count++;
932
+ }
933
+
934
+ if (count == carts.length && carts) {
935
+ cartObject.item_details = carts
936
+ cartObject.discount = total
937
+ resolve(cartObject);
938
+ }
939
+ });
940
+ });
941
+ } else {
942
+ return new Promise(function (resolve, reject) {
943
+ resolve(cartObject);
944
+ });
945
+ }
946
+ } catch (error) {
947
+ reject(error)
948
+ }
949
+ };
950
+
951
+ function setPackageDefaultDiscount(cart) {
952
+ return new Promise(async (resolve, reject) => {
953
+ try {
954
+ if (cart && cart.item_details) {
955
+ cart.item_details.forEach(function (v) {
956
+ if (v.isPackage == 1 && v.package_items)
957
+ v.package_items.forEach(function (item) {
958
+ item.default_combo_discount = 0;
959
+ })
960
+ });
961
+ cart.item_details.forEach(async function (item, index) {
962
+ if (item.isPackage == 1) {
963
+ let itemTotal = 0;
964
+ if (item.package_items && item.package_items.length > 0) {
965
+ item.package_items.forEach(function (v) {
966
+ itemTotal += (item.quantity * v.price);
967
+ })
968
+ let packagePrice = item.quantity * item.item_price;
969
+ let totalDiscount = (packagePrice < itemTotal) ? (parseFloat(itemTotal) - parseFloat(packagePrice)).toFixed(2) : 0;
970
+ await distributeDiscount(item.package_items, totalDiscount, itemTotal, item.quantity).then(ele => {
971
+ item.package_items = ele;
972
+ if (index == cart.item_details.length - 1) {
973
+ resolve(cart);
974
+ }
975
+ }).catch(error => {
976
+ reject(error);
977
+ })
978
+ } else {
979
+ if (index == cart.item_details.length - 1) {
980
+ resolve(cart);
981
+ }
982
+ }
983
+ } else {
984
+ if (index == cart.item_details.length - 1) {
985
+ resolve(cart);
986
+ }
987
+ }
988
+ })
989
+ } else {
990
+ resolve(cart);
991
+ }
992
+ } catch (error) {
993
+ reject(error);
994
+ }
995
+ })
996
+ };
997
+
998
+ function distributeDiscount(packageItems, totalDiscount, itemTotal, quantity) {
999
+ return new Promise(async (resolve, reject) => {
1000
+ try {
1001
+ let totalApplied = 0;
1002
+ let singleUnit = (quantity * parseFloat(totalDiscount) / parseFloat(itemTotal)).toFixed(2);
1003
+ for (const [index, item] of packageItems.entries()) {
1004
+ let discountPerItem = (parseFloat(singleUnit) * parseFloat(item.price)).toFixed(2);
1005
+ totalApplied = (parseFloat(totalApplied) + parseFloat(discountPerItem)).toFixed(2);
1006
+ item.default_combo_discount = parseFloat(discountPerItem).toFixed(2);
1007
+
1008
+ if (index == packageItems.length - 1) {
1009
+
1010
+ let remaningOfferAmount = (parseFloat(totalDiscount) - parseFloat(totalApplied)).toFixed(2);
1011
+ for (const updateItem of packageItems) {
1012
+ let updateDisc = (parseFloat(updateItem.default_combo_discount) + parseFloat(remaningOfferAmount)).toFixed(2);
1013
+ if (updateDisc <= updateItem.price) {
1014
+ updateItem.default_combo_discount = updateDisc
1015
+ break;
1016
+ }
1017
+ }
1018
+ resolve(packageItems);
1019
+ }
1020
+ }
1021
+ } catch (error) {
1022
+ reject(error);
1023
+ }
1024
+ })
1025
+ };
1026
+
1027
+
1028
+ module.exports = {
1029
+ offerCalculation, setPackageDefaultDiscount
1030
+ }