foodbot-cart-calculations 1.0.16 → 1.0.18
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/functions/promotionCalculation.js +146 -213
- package/functions/taxCalculation.js +9 -3
- package/package.json +1 -1
|
@@ -460,225 +460,156 @@ function getOfferDetails(carts, offer = []) {
|
|
|
460
460
|
})
|
|
461
461
|
};
|
|
462
462
|
|
|
463
|
-
function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,buyItemss) {
|
|
464
|
-
return new Promise(function (resolve, reject) {
|
|
465
|
-
|
|
466
|
-
try {
|
|
467
|
-
let carts = cartData.item_details
|
|
468
|
-
var desc = JSON.parse(JSON.stringify(descending));
|
|
469
|
-
var desc1 = JSON.parse(JSON.stringify(descending));
|
|
470
|
-
var amount = 0;
|
|
471
|
-
var buyArray = [];
|
|
472
|
-
var getArray = [];
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (!cartData.totalDiscount)
|
|
476
|
-
cartData.totalDiscount = 0
|
|
477
|
-
|
|
478
|
-
var buyItems = desc.filter((e) => {
|
|
479
|
-
if (offer.offer_products.offer_buy_products.includes(parseInt(e.item_id))) {
|
|
480
|
-
return e.item_id;
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
let totalCount = parseInt(offer.offer_products.get_item_count) + parseInt(offer.offer_products.buy_item_count);
|
|
487
|
-
|
|
488
|
-
if (buyItems && parseInt(buyItems.length) >= parseInt(offer.offer_products.buy_item_count) && desc.length > 1 && descending.length >= totalCount) {
|
|
489
|
-
var buyCount = 0;
|
|
490
|
-
var getCount = 0;
|
|
491
|
-
|
|
492
|
-
for (var i = 0, ii = desc.length; i < ii; i++) {
|
|
493
|
-
let itemAmount = 0;
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
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
|
|
497
|
-
) {
|
|
498
|
-
var amt = 0;
|
|
499
|
-
let amtWithModi = 0;
|
|
500
|
-
getArray.push(desc[i].item_id);
|
|
501
|
-
|
|
502
|
-
buyCount++;
|
|
503
|
-
desc1[i].remove = true;
|
|
504
|
-
buyArray.push(desc[i].item_id);
|
|
505
|
-
var itemIndex = -1;
|
|
506
|
-
|
|
507
|
-
if (desc[i]) itemIndex = carts.findIndex((obj) => obj.item_id == desc[i].item.item_id);
|
|
508
|
-
|
|
509
|
-
if (offer.oo_offer_type == "percentage") {
|
|
510
|
-
|
|
511
|
-
console.log('desc[i].item.item_pricedesc[i].item.item_price', desc[i].item.item_price)
|
|
512
|
-
|
|
513
|
-
let itemTotalDiscount = 0;
|
|
514
|
-
itemAmount =
|
|
515
|
-
(parseFloat(desc[i].item.item_price)) *
|
|
516
|
-
parseFloat(offer.oo_offer_value) /
|
|
517
|
-
100;
|
|
518
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount);
|
|
519
|
-
amt = parseFloat(amt) + parseFloat(itemAmount);
|
|
520
|
-
amt = parseFloat(amt);
|
|
521
|
-
amtWithModi = amt;
|
|
522
|
-
|
|
523
|
-
let modiItemAmount = 0;
|
|
524
|
-
cartData.totalDiscount = parseFloat(cartData.totalDiscount) + parseFloat(amt)
|
|
525
|
-
carts[itemIndex].promotion_discount_modifier = parseFloat(
|
|
526
|
-
parseFloat(carts[itemIndex].promotion_discount_modifier) +
|
|
527
|
-
parseFloat(amt)
|
|
528
|
-
).toFixed(2);
|
|
529
|
-
|
|
530
|
-
if (desc[i].item.item_modifiers.length > 0 && offer.offer_products.order_modifiercost_use == 1) {
|
|
531
|
-
let modiCount = 0;
|
|
532
|
-
|
|
533
|
-
desc[i].item.item_modifiers.forEach((modi, mIndex) => {
|
|
534
|
-
modiItemAmount =
|
|
535
|
-
(((parseFloat(modi.modifier_item_price) * parseFloat(modi.quantity))) *
|
|
536
|
-
parseFloat(offer.oo_offer_value)) /
|
|
537
|
-
100;
|
|
538
|
-
|
|
539
|
-
if (carts[itemIndex].item_modifiers[mIndex]) {
|
|
540
|
-
carts[itemIndex].item_modifiers[mIndex].promotion_discount = parseFloat(
|
|
541
|
-
modiItemAmount
|
|
542
|
-
).toFixed(2);
|
|
543
|
-
|
|
544
|
-
carts[itemIndex].item_modifiers[mIndex].redeem_promotion_id = offer.offer_id;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
cartData.totalDiscount = parseFloat(cartData.totalDiscount) + parseFloat(modiItemAmount)
|
|
548
|
-
carts[itemIndex].promotion_discount_modifier = parseFloat(
|
|
549
|
-
parseFloat(carts[itemIndex].promotion_discount_modifier) +
|
|
550
|
-
parseFloat(modiItemAmount)
|
|
551
|
-
).toFixed(2);
|
|
552
|
-
|
|
553
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount);
|
|
554
|
-
amtWithModi = parseFloat(amtWithModi) + parseFloat(modiItemAmount);
|
|
555
|
-
amtWithModi = parseFloat(amtWithModi);
|
|
556
|
-
amt = parseFloat(amt) + parseFloat(amtWithModi);
|
|
557
|
-
|
|
558
|
-
var modiIndex = carts[itemIndex].item_modifiers.findIndex((obj) => {
|
|
559
|
-
return obj.modifier_item_id == modi.modifier_item_id;
|
|
560
|
-
});
|
|
561
|
-
|
|
562
|
-
// if (carts[itemIndex].item_modifiers[modiIndex]) {
|
|
563
|
-
// carts[itemIndex].item_modifiers[modiIndex].promotion_discount = parseFloat(
|
|
564
|
-
// modiItemAmount
|
|
565
|
-
// ).toFixed(2);
|
|
566
|
-
// carts[itemIndex].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
|
|
567
|
-
// }
|
|
568
|
-
|
|
569
|
-
// modiCount++;
|
|
570
|
-
});
|
|
571
|
-
} else {
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
carts[itemIndex].promotion_discount = parseFloat(
|
|
575
|
-
parseFloat(carts[itemIndex].promotion_discount) + parseFloat(itemAmount)
|
|
576
|
-
).toFixed(2);
|
|
577
|
-
|
|
578
|
-
// carts[itemIndex].promotion_discount_modifier = parseFloat(
|
|
579
|
-
// parseFloat(carts[itemIndex].promotion_discount_modifier) +
|
|
580
|
-
// parseFloat(itemTotalDiscount)
|
|
581
|
-
// ).toFixed(2);
|
|
582
|
-
carts[itemIndex].redeem_promotion_id = offer.offer_id;
|
|
583
|
-
} else {
|
|
584
|
-
buyItemAmount = buyItemAmount + desc[i].amount;
|
|
585
|
-
desc[i].item.indexss = i;
|
|
586
|
-
buyItemss.push(desc[i].item);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
if (parseInt(amt) != 0) {
|
|
590
|
-
let amtModiTotal = amt;
|
|
591
|
-
// carts[itemIndex].promotion_discount_modifier = amtModiTotal;
|
|
592
|
-
// carts[itemIndex].promotion_discount = (
|
|
593
|
-
// parseFloat(carts[itemIndex].promotion_discount) + parseFloat(itemAmount)
|
|
594
|
-
// ).toFixed(2);
|
|
595
|
-
total = total + amtWithModi;
|
|
596
|
-
|
|
597
|
-
// console.log('amount modifffffffffffffff', amtModiTotal)
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
carts[itemIndex].redeem_promotion_id = offer.offer_id;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
getCount++;
|
|
605
|
-
desc1[i].remove = true;
|
|
606
|
-
desc1[i + 1].remove = true;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
if (
|
|
610
|
-
getCount == offer.offer_products.get_item_count &&
|
|
611
|
-
buyCount == offer.offer_products.buy_item_count
|
|
612
|
-
) {
|
|
613
|
-
total = parseFloat(total) + parseFloat(amount);
|
|
614
|
-
// cartData.totalDiscount = parseFloat(cartData.totalDiscount) + parseFloat(amount)
|
|
615
|
-
|
|
616
|
-
if (offer.offer_products.order_multi_use == 1) {
|
|
617
|
-
var filterItem = desc1.filter((e) => {
|
|
618
|
-
if (!e.remove) {
|
|
619
|
-
return e.item_id;
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
463
|
|
|
623
464
|
|
|
624
|
-
cartData.item_details = carts
|
|
625
|
-
getBuyxGetYOnCondition(filterItem, cartData, offer,total,buyItemAmount,buyItemss).then((data) => {
|
|
626
|
-
resolve(data)
|
|
627
|
-
}).catch(error => {
|
|
628
|
-
reject(error);
|
|
629
|
-
})
|
|
630
|
-
break;
|
|
631
|
-
} else {
|
|
632
|
-
if (offer.oo_offer_type == 'absolute') {
|
|
633
|
-
cartData.item_details = carts
|
|
634
|
-
getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount,total).then((data) => {
|
|
635
|
-
resolve(data);
|
|
636
|
-
}).catch(error => {
|
|
637
|
-
reject(error);
|
|
638
|
-
})
|
|
639
|
-
}
|
|
640
|
-
else {
|
|
641
|
-
cartData.discount = cartData.totalDiscount
|
|
642
|
-
resolve(cartData);
|
|
643
|
-
}
|
|
644
465
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
466
|
+
function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,buyItemss) {
|
|
467
|
+
return new Promise((resolve, reject) => {
|
|
468
|
+
let carts = cartData.item_details;
|
|
469
|
+
const desc = JSON.parse(JSON.stringify(descending));
|
|
470
|
+
const desc1 = JSON.parse(JSON.stringify(descending));
|
|
471
|
+
let amount = 0;
|
|
472
|
+
const buyArray = [];
|
|
473
|
+
const getArray = [];
|
|
474
|
+
const buyItems = desc.filter(e => {
|
|
475
|
+
if (offer.offer_products.offer_buy_products.some(item => item == e.item_id)) {
|
|
476
|
+
return e.item_id;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
console.log("bbbbbbbbbbbbbbbbbbbb",buyItems)
|
|
481
|
+
|
|
482
|
+
const totalCount = parseInt(offer.offer_products.get_item_count) + parseInt(offer.offer_products.buy_item_count);
|
|
483
|
+
if (buyItems && parseInt(buyItems.length) >= parseInt(offer.offer_products.buy_item_count) && desc.length > 1 && descending.length >= totalCount) {
|
|
484
|
+
let buyCount = 0;
|
|
485
|
+
let getCount = 0;
|
|
486
|
+
for (let i = 0; i < desc.length; i++) {
|
|
487
|
+
let itemAmount = 0;
|
|
488
|
+
|
|
489
|
+
if (desc[i].buy && buyCount < offer.offer_products.buy_item_count && buyCount != offer.offer_products.buy_item_count) {
|
|
490
|
+
buyCount++;
|
|
491
|
+
desc1[i].remove = true;
|
|
492
|
+
buyArray.push(desc[i].item_id);
|
|
493
|
+
} else if (desc[i] && desc[i].get && getCount < offer.offer_products.get_item_count && getCount != offer.offer_products.get_item_count) {
|
|
494
|
+
let amt = 0;
|
|
495
|
+
let amtWithModi = 0;
|
|
496
|
+
getArray.push(desc[i].item_id);
|
|
497
|
+
|
|
498
|
+
let itemIndex = -1;
|
|
499
|
+
if (desc[i]) itemIndex = carts.findIndex(obj => obj.item_id == desc[i].item.item_id && !obj.discount_status);
|
|
500
|
+
if (itemIndex == -1) itemIndex = carts.findIndex(obj => obj.item_id == desc[i].item.item_id);
|
|
501
|
+
|
|
502
|
+
console.log("item index",itemIndex)
|
|
503
|
+
|
|
504
|
+
if (offer.oo_offer_type === "percentage") {
|
|
505
|
+
let itemTotalDiscount = 0;
|
|
506
|
+
itemAmount = (parseFloat(desc[i].item.item_price) * parseFloat(offer.oo_offer_value)) / 100;
|
|
507
|
+
|
|
508
|
+
itemTotalDiscount += itemAmount;
|
|
509
|
+
amt += itemAmount;
|
|
510
|
+
amtWithModi = amt;
|
|
511
|
+
let modiItemAmount = 0;
|
|
512
|
+
|
|
513
|
+
if (desc[i].item.item_modifiers.length > 0 && offer.offer_products.order_modifiercost_use == 1) {
|
|
514
|
+
let modiCount = 0;
|
|
515
|
+
desc[i].item.item_modifiers.forEach(modi => {
|
|
516
|
+
modiItemAmount = ((parseFloat(modi.modifier_item_price) * parseFloat(modi.quantity)) * parseFloat(offer.oo_offer_value)) / 100;
|
|
517
|
+
itemTotalDiscount += modiItemAmount;
|
|
518
|
+
amtWithModi += modiItemAmount;
|
|
519
|
+
amt += amtWithModi;
|
|
520
|
+
|
|
521
|
+
const modiIndex = carts[itemIndex].item_modifiers.findIndex(obj => obj.modifier_item_id == modi.modifier_item_id);
|
|
522
|
+
if (carts[itemIndex].item_modifiers[modiIndex]) {
|
|
523
|
+
carts[itemIndex].item_modifiers[modiIndex].promotion_discount = parseFloat(modiItemAmount).toFixed(2);
|
|
524
|
+
carts[itemIndex].item_modifiers[modiIndex].redeem_promotion_id = offer.offer_id;
|
|
525
|
+
}
|
|
526
|
+
modiCount++;
|
|
527
|
+
});
|
|
528
|
+
}
|
|
653
529
|
} else {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
})
|
|
661
|
-
}
|
|
662
|
-
else {
|
|
663
|
-
cartData.discount = cartData.totalDiscount
|
|
664
|
-
resolve(cartData);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
|
|
530
|
+
// Handle absolute discount type
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
buyItemAmount = buyItemAmount + desc[i].amount;
|
|
534
|
+
desc[i].item.indexss = i;
|
|
535
|
+
buyItemss.push(desc[i].item);
|
|
668
536
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
537
|
+
|
|
538
|
+
if (parseInt(amt) != 0) {
|
|
539
|
+
const amtModiTotal = (offer.offer_products.order_modifiercost_use == 1)
|
|
540
|
+
? (parseFloat(carts[itemIndex].promotion_discount_modifier) + parseFloat(amtWithModi)).toFixed(2)
|
|
541
|
+
: (parseFloat(carts[itemIndex].promotion_discount) + parseFloat(amt)).toFixed(2);
|
|
542
|
+
|
|
543
|
+
carts[itemIndex].promotion_discount_modifier = amtModiTotal;
|
|
544
|
+
carts[itemIndex].promotion_discount = (parseFloat(carts[itemIndex].promotion_discount) + parseFloat(buyItemAmount)).toFixed(2);
|
|
545
|
+
carts[itemIndex].discount_status = true;
|
|
546
|
+
total = total + amtWithModi;
|
|
547
|
+
carts[itemIndex].redeem_promotion_id = offer.offer_id;
|
|
548
|
+
}
|
|
549
|
+
getCount++;
|
|
550
|
+
desc1[i].remove = true;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
if (getCount == offer.offer_products.get_item_count && buyCount == offer.offer_products.buy_item_count) {
|
|
556
|
+
|
|
557
|
+
total = parseFloat(total) + parseFloat(amount);
|
|
558
|
+
if (offer.offer_products.order_multi_use == 1) {
|
|
559
|
+
const filterItem = desc1.filter(e => !e.remove);
|
|
560
|
+
|
|
561
|
+
cartData.item_details = carts
|
|
562
|
+
getBuyxGetYOnCondition(filterItem, cartData, offer,total,buyItemAmount,buyItemss).then((data) => {
|
|
563
|
+
resolve(data)
|
|
564
|
+
}).catch(error => {
|
|
565
|
+
reject(error);
|
|
566
|
+
})
|
|
567
|
+
break;
|
|
568
|
+
} else {
|
|
569
|
+
if (offer.oo_offer_type === 'absolute') {
|
|
570
|
+
cartData.item_details = carts
|
|
571
|
+
getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount,total).then((data) => {
|
|
572
|
+
resolve(data);
|
|
573
|
+
}).catch(error => {
|
|
574
|
+
reject(error);
|
|
575
|
+
})
|
|
576
|
+
}else{
|
|
577
|
+
cartData.discount = cartData.totalDiscount
|
|
578
|
+
resolve(cartData);
|
|
579
|
+
}
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
}else{
|
|
583
|
+
|
|
584
|
+
if(i == desc.length -1){
|
|
585
|
+
|
|
586
|
+
cartData.discount = cartData.totalDiscount
|
|
587
|
+
resolve(cartData);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
}
|
|
678
591
|
}
|
|
592
|
+
} else {
|
|
593
|
+
if (offer.oo_offer_type === 'absolute') {
|
|
594
|
+
|
|
595
|
+
cartData.item_details = carts
|
|
596
|
+
getAbsoluteDiscount(cartData, offer, buyItemss, buyItemAmount,total).then((data) => {
|
|
597
|
+
resolve(data);
|
|
598
|
+
}).catch(error => {
|
|
599
|
+
reject(error);
|
|
600
|
+
})
|
|
601
|
+
}else{
|
|
602
|
+
cartData.discount = cartData.totalDiscount
|
|
603
|
+
resolve(cartData);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// setTimeout(() => {
|
|
608
|
+
// resolve(0);
|
|
609
|
+
// }, 20);
|
|
679
610
|
});
|
|
680
|
-
}
|
|
681
|
-
|
|
611
|
+
}
|
|
612
|
+
|
|
682
613
|
function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total) {
|
|
683
614
|
return new Promise(function (resolve, reject) {
|
|
684
615
|
try {
|
|
@@ -687,7 +618,7 @@ function getAbsoluteDiscount(cartObject, offer, buyItemss, buyItemAmount,total)
|
|
|
687
618
|
singlePriceDiscount = parseFloat(singlePriceDiscount).toFixed(6);
|
|
688
619
|
let remaningOfferAmount = offer.oo_offer_value;
|
|
689
620
|
let count = 0;
|
|
690
|
-
let carts = cartObject.item_details
|
|
621
|
+
let carts = cartObject.item_details;
|
|
691
622
|
if(buyItemss && buyItemss.length>0){
|
|
692
623
|
buyItemss.forEach((element, buyIndex) => {
|
|
693
624
|
let itemAmount = 0;
|
|
@@ -783,6 +714,8 @@ function addItemQuantity(items, offer) {
|
|
|
783
714
|
try {
|
|
784
715
|
var finalItems = [];
|
|
785
716
|
var count = 0;
|
|
717
|
+
offer.offer_products.offer_buy_products=offer.offer_products.offer_buy_products.map(item => parseInt(item, 10));
|
|
718
|
+
offer.offer_products.offer_get_products=offer.offer_products.offer_get_products.map(item => parseInt(item, 10));
|
|
786
719
|
items.forEach(function (element) {
|
|
787
720
|
if (offer.offer_products.offer_buy_products.includes(parseInt(element.item_id)) || offer.offer_products.offer_get_products.includes(parseInt(element.item_id))) {
|
|
788
721
|
for (var i = 1; i <= element.quantity; i++) {
|
|
@@ -251,10 +251,15 @@ function calculatePackageItemTax(cart, itemIndex, element, tax_settings, afterDi
|
|
|
251
251
|
function calculateModiTax(cart, itemIndex, element, tax_settings, afterDicsount, taxType) {
|
|
252
252
|
return new Promise(async (resolve, reject) => {
|
|
253
253
|
if (element && element.item_modifiers && element.item_modifiers.length > 0) {
|
|
254
|
-
|
|
254
|
+
|
|
255
255
|
element.item_modifiers.forEach((modi, modiIndex) => {
|
|
256
|
+
let itemModiTotalTax = 0
|
|
256
257
|
let taxId = []
|
|
257
|
-
let iepsTax;
|
|
258
|
+
let iepsTax;
|
|
259
|
+
//code commented for test
|
|
260
|
+
|
|
261
|
+
//code gain commented for push
|
|
262
|
+
|
|
258
263
|
if (modi.is_tax_rate_same == 1) {
|
|
259
264
|
if (modi.linked_product && modi.linked_product.product_tax_id) {
|
|
260
265
|
taxId = modi.linked_product.product_tax_id
|
|
@@ -368,8 +373,9 @@ function calculatePackageModiTax(cart, itemIndex, element, tax_settings, afterDi
|
|
|
368
373
|
element.package_items.forEach((packageItem, packageItemIndex) => {
|
|
369
374
|
element.package_items[packageItemIndex].tax_amount_modifier = 0
|
|
370
375
|
if (packageItem.modifiers.length > 0) {
|
|
371
|
-
|
|
376
|
+
|
|
372
377
|
packageItem.modifiers.forEach((modi, modiIndex) => {
|
|
378
|
+
let itemModiTotalTax = 0;
|
|
373
379
|
let taxId = []
|
|
374
380
|
let iepsTax;
|
|
375
381
|
if (modi.is_tax_rate_same == 1) {
|
package/package.json
CHANGED