foodbot-cart-calculations 1.0.45 → 1.0.47
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 +16 -23
- package/functions/pointsCalculation.js +90 -137
- package/functions/promotionCalculation.js +24 -25
- package/index.js +766 -279
- package/package.json +1 -1
- package/response.json +0 -239
- package/sampleInput.json +0 -231
package/calculations.js
CHANGED
|
@@ -8,15 +8,10 @@ function applyDistribution(body) {
|
|
|
8
8
|
let mainCart = body
|
|
9
9
|
let promotion = (body.promotion_applied && body.promotion_applied) ? body.promotion_applied : {};
|
|
10
10
|
let deliveryCost = (body.delivery_cost && body.delivery_cost) ? body.delivery_cost : 0;
|
|
11
|
-
|
|
12
|
-
if(body?.order_items?.delivery_discount)
|
|
11
|
+
|
|
12
|
+
if(body?.order_items?.delivery_discount)
|
|
13
13
|
body.order_items.delivery_discount = 0
|
|
14
14
|
body.order_items.is_delivery_discount = false
|
|
15
|
-
}
|
|
16
|
-
if (body?.order_items?.service_discount) {
|
|
17
|
-
body.order_items.service_discount = 0;
|
|
18
|
-
body.order_items.is_service_discount = false;
|
|
19
|
-
}
|
|
20
15
|
|
|
21
16
|
promoCalculation.setPackageDefaultDiscount(body.order_items).then(res => {
|
|
22
17
|
promoCalculation.offerCalculation(res, promotion, deliveryCost).then(final => {
|
|
@@ -35,7 +30,8 @@ function applyDistribution(body) {
|
|
|
35
30
|
}
|
|
36
31
|
mainCart.store_value = 0;
|
|
37
32
|
|
|
38
|
-
pointsCalculation.getPointsDiscount(final, body.loyalty_points_details, body.user_detais
|
|
33
|
+
pointsCalculation.getPointsDiscount(final, body.loyalty_points_details, body.user_detais).then(pointsCal => {
|
|
34
|
+
|
|
39
35
|
if (typeof (final.store_value) == "undefined" || isNaN(final.store_value))
|
|
40
36
|
final.store_value = 0
|
|
41
37
|
if (body.loyalty_points_details && parseInt(body.loyalty_points_details.points_redeemed) == 0) {
|
|
@@ -77,26 +73,23 @@ function applyDistribution(body) {
|
|
|
77
73
|
mainCart.cash_expected = parseFloat(taxData.cartTotal) + parseFloat(taxData.tax_amount);
|
|
78
74
|
}
|
|
79
75
|
mainCart.order_items = taxData
|
|
80
|
-
|
|
76
|
+
|
|
81
77
|
let delivery_cost = body.delivery_cost ? body.delivery_cost : 0;
|
|
82
|
-
let service_amount = body.service_amount ? body.service_amount : 0;
|
|
83
78
|
// Adjust delivery cost based on delivery discount
|
|
84
79
|
if (final.is_delivery_discount) {
|
|
85
|
-
delivery_cost = Math.max(0, delivery_cost - final.delivery_discount);
|
|
80
|
+
delivery_cost = Math.max(0, delivery_cost - final.delivery_discount);
|
|
86
81
|
body.delivery_cost = delivery_cost; // Update body accordingly
|
|
87
82
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
let tipValue = body.tip_value?body.tip_value:0;
|
|
95
|
-
let tipValueReq = body.tip_value?body.tip_value:0;
|
|
83
|
+
|
|
84
|
+
let service_amount = body.service_amount?body.service_amount:0;
|
|
85
|
+
|
|
86
|
+
//we took 2 value because in case of absolute we use tipValue
|
|
87
|
+
let tipValue = body.tip_value?body.tip_value:0;
|
|
88
|
+
let tipValueReq = body.tip_value?body.tip_value:0;
|
|
96
89
|
|
|
97
90
|
if (body.tip_type && body.tip_type == 'percentage') {
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
tipValue = (mainCart.final_amount * parseInt(tipValueReq)) / 100
|
|
92
|
+
tipValue = parseFloat(tipValue).toFixed(2)
|
|
100
93
|
}
|
|
101
94
|
|
|
102
95
|
mainCart.tip_amount = parseFloat(tipValue).toFixed(2);
|
|
@@ -112,10 +105,10 @@ function applyDistribution(body) {
|
|
|
112
105
|
|
|
113
106
|
taxData.total_after_tax = parseFloat(taxData.total_after_tax) + parseFloat(tipValue);
|
|
114
107
|
taxData.total_after_tax = parseFloat(taxData.total_after_tax).toFixed(2);
|
|
115
|
-
|
|
108
|
+
|
|
116
109
|
mainCart.final_amount = parseFloat(mainCart.final_amount) + parseFloat(tipValue);
|
|
117
110
|
mainCart.cash_expected = parseFloat(mainCart.cash_expected) + parseFloat(tipValue);
|
|
118
|
-
|
|
111
|
+
|
|
119
112
|
taxData.final_amount = parseFloat(taxData.final_amount).toFixed(2);
|
|
120
113
|
taxData.cash_expected = parseFloat(taxData.cash_expected).toFixed(2);
|
|
121
114
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
function getPointsDiscount(cartObject, points, userDetails
|
|
1
|
+
function getPointsDiscount(cartObject, points, userDetails) {
|
|
2
2
|
return new Promise(function (resolve, reject) {
|
|
3
3
|
try {
|
|
4
4
|
let itemsTotal = 0
|
|
5
5
|
let carts = cartObject.item_details
|
|
6
|
-
let deliveryDiscount = 0;
|
|
7
|
-
let serviceDiscount = 0;
|
|
8
6
|
|
|
9
7
|
carts.forEach(function (v) {
|
|
10
8
|
delete v.points_discount_modifier;
|
|
@@ -34,11 +32,8 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
|
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
34
|
});
|
|
37
|
-
|
|
38
35
|
if (!points) {
|
|
39
|
-
|
|
40
|
-
cartObject.service_discount = 0;
|
|
41
|
-
resolve(cartObject);
|
|
36
|
+
resolve(0);
|
|
42
37
|
} else {
|
|
43
38
|
let pointsAmount = 0;
|
|
44
39
|
let count = 0;
|
|
@@ -76,81 +71,77 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
|
|
|
76
71
|
element.point_discount_status = true;
|
|
77
72
|
}
|
|
78
73
|
count++;
|
|
79
|
-
});
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
packDis = (parseFloat(packDis) + parseFloat(packageItem.points_discount)).toFixed(2);
|
|
152
|
-
|
|
153
|
-
packageItem.modifiers.forEach((modi, modiIndex) => {
|
|
75
|
+
if (count == carts.length) {
|
|
76
|
+
let singlePriceDiscount = pointsAmount / itemsTotal;
|
|
77
|
+
singlePriceDiscount = (itemsTotal && itemsTotal > 0)?parseFloat(singlePriceDiscount).toFixed(6):0;
|
|
78
|
+
|
|
79
|
+
let storeValue = 0
|
|
80
|
+
let itemDiscount = 0;
|
|
81
|
+
let itemTotalDicount = 0;
|
|
82
|
+
|
|
83
|
+
carts.forEach((item, index) => {
|
|
84
|
+
item.points_discount = item.points_discount ? item.points_discount : 0;
|
|
85
|
+
item.points_discount_modifier = item.points_discount_modifier ? item.points_discount_modifier : 0;
|
|
86
|
+
|
|
87
|
+
if (item.isPackage == 1) {
|
|
88
|
+
if (item.point_discount_status) {
|
|
89
|
+
let promoDiscount = (item.promotion_discount) ? item.promotion_discount : 0;
|
|
90
|
+
itemDiscount = ((item.item_price * item.quantity) - promoDiscount) * singlePriceDiscount;
|
|
91
|
+
itemDiscount = parseFloat(itemDiscount).toFixed(2);
|
|
92
|
+
itemTotalDicount = parseFloat(itemDiscount) + parseFloat(itemTotalDicount);
|
|
93
|
+
|
|
94
|
+
if (itemDiscount > 0)
|
|
95
|
+
indexes.push(index);
|
|
96
|
+
|
|
97
|
+
item.points_discount = itemDiscount;
|
|
98
|
+
item.points_discount_modifier = 0;
|
|
99
|
+
|
|
100
|
+
let packDis = 0;
|
|
101
|
+
|
|
102
|
+
item.package_items.forEach((packageItem, packageItemIndex) => {
|
|
103
|
+
let packageItemPromoDiscount = (packageItem.promotion_discount) ? packageItem.promotion_discount : 0;
|
|
104
|
+
packageItem.points_discount_modifier = 0;
|
|
105
|
+
|
|
106
|
+
packageItem.points_discount = ((((packageItem.price * parseInt(item.quantity)) - parseFloat((packageItem.default_combo_discount)) - parseFloat(packageItemPromoDiscount))) * parseFloat(singlePriceDiscount)).toFixed(2);
|
|
107
|
+
packDis = (parseFloat(packDis) + parseFloat(packageItem.points_discount)).toFixed(2);
|
|
108
|
+
|
|
109
|
+
packageItem.modifiers.forEach((modi, modiIndex) => {
|
|
110
|
+
let modiItemAmount = 0;
|
|
111
|
+
let modiPromoDiscount = (modi.promotion_discount) ? modi.promotion_discount : 0;
|
|
112
|
+
modiItemAmount = (((parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * item.quantity) - modiPromoDiscount) * parseFloat(singlePriceDiscount);
|
|
113
|
+
modiItemAmount = parseFloat(modiItemAmount).toFixed(2);
|
|
114
|
+
itemTotalDicount = parseFloat(itemTotalDicount) + parseFloat(modiItemAmount);
|
|
115
|
+
itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
|
|
116
|
+
modi.points_discount = modiItemAmount;
|
|
117
|
+
packageItem.points_discount_modifier = (parseFloat(packageItem.points_discount_modifier) + parseFloat(modi.points_discount)).toFixed(2);
|
|
118
|
+
});
|
|
119
|
+
packageItem.points_discount_modifier = (parseFloat(packageItem.points_discount) + parseFloat(packageItem.points_discount_modifier)).toFixed(2);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (itemDiscount != packDis && item.package_items) {
|
|
123
|
+
if (packDis > itemDiscount) {
|
|
124
|
+
let diff = (parseFloat(packDis) - parseFloat(itemDiscount)).toFixed(2);
|
|
125
|
+
item.package_items[0].points_discount = (parseFloat(item.package_items[0].points_discount) - parseFloat(diff)).toFixed(2);
|
|
126
|
+
} else {
|
|
127
|
+
let diff = (parseFloat(itemDiscount) - parseFloat(packDis)).toFixed(2);
|
|
128
|
+
item.package_items[0].points_discount = (parseFloat(item.package_items[0].points_discount) - parseFloat(diff)).toFixed(2);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
if (item.point_discount_status) {
|
|
134
|
+
let promoDiscount = (item.promotion_discount) ? item.promotion_discount : 0;
|
|
135
|
+
itemDiscount = ((item.item_price * item.quantity) - promoDiscount) * singlePriceDiscount;
|
|
136
|
+
itemDiscount = parseFloat(itemDiscount).toFixed(2);
|
|
137
|
+
itemTotalDicount = parseFloat(itemDiscount) + parseFloat(itemTotalDicount);
|
|
138
|
+
|
|
139
|
+
if (itemDiscount > 0)
|
|
140
|
+
indexes.push(index);
|
|
141
|
+
|
|
142
|
+
item.points_discount = itemDiscount;
|
|
143
|
+
|
|
144
|
+
item.item_modifiers.forEach((modi, modiIndex) => {
|
|
154
145
|
let modiItemAmount = 0;
|
|
155
146
|
let modiPromoDiscount = (modi.promotion_discount) ? modi.promotion_discount : 0;
|
|
156
147
|
modiItemAmount = (((parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * item.quantity) - modiPromoDiscount) * parseFloat(singlePriceDiscount);
|
|
@@ -158,73 +149,35 @@ function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, se
|
|
|
158
149
|
itemTotalDicount = parseFloat(itemTotalDicount) + parseFloat(modiItemAmount);
|
|
159
150
|
itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
|
|
160
151
|
modi.points_discount = modiItemAmount;
|
|
161
|
-
packageItem.points_discount_modifier = (parseFloat(packageItem.points_discount_modifier) + parseFloat(modi.points_discount)).toFixed(2);
|
|
162
152
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (itemDiscount != packDis && item.package_items) {
|
|
167
|
-
if (packDis > itemDiscount) {
|
|
168
|
-
let diff = (parseFloat(packDis) - parseFloat(itemDiscount)).toFixed(2);
|
|
169
|
-
item.package_items[0].points_discount = (parseFloat(item.package_items[0].points_discount) - parseFloat(diff)).toFixed(2);
|
|
170
|
-
} else {
|
|
171
|
-
let diff = (parseFloat(itemDiscount) - parseFloat(packDis)).toFixed(2);
|
|
172
|
-
item.package_items[0].points_discount = (parseFloat(item.package_items[0].points_discount) - parseFloat(diff)).toFixed(2);
|
|
173
|
-
}
|
|
153
|
+
|
|
154
|
+
item.points_discount_modifier = itemTotalDicount;
|
|
174
155
|
}
|
|
175
156
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
item.points_discount = itemDiscount;
|
|
187
|
-
|
|
188
|
-
item.item_modifiers.forEach((modi, modiIndex) => {
|
|
189
|
-
let modiItemAmount = 0;
|
|
190
|
-
let modiPromoDiscount = (modi.promotion_discount) ? modi.promotion_discount : 0;
|
|
191
|
-
modiItemAmount = (((parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * item.quantity) - modiPromoDiscount) * parseFloat(singlePriceDiscount);
|
|
192
|
-
modiItemAmount = parseFloat(modiItemAmount).toFixed(2);
|
|
193
|
-
itemTotalDicount = parseFloat(itemTotalDicount) + parseFloat(modiItemAmount);
|
|
194
|
-
itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
|
|
195
|
-
modi.points_discount = modiItemAmount;
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
item.points_discount_modifier = itemTotalDicount;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
if ((Number(itemTotalDicount) < Number(pointsAmount) || Number(itemTotalDicount) > Number(pointsAmount)) && pointsAmount > 0 && itemTotalDicount > 0) {
|
|
160
|
+
let difference = Number(pointsAmount) - Number(itemTotalDicount);
|
|
161
|
+
difference = parseFloat(difference).toFixed(2);
|
|
162
|
+
if (index > -1) {
|
|
163
|
+
carts[indexes[0]].points_discount = (difference > 0) ? parseFloat(carts[indexes[0]].points_discount) + parseFloat(difference) : parseFloat(carts[indexes[0]].points_discount) - Math.abs(difference);
|
|
164
|
+
carts[indexes[0]].points_discount = parseFloat(carts[indexes[0]].points_discount).toFixed(2);
|
|
165
|
+
itemTotalDicount = (difference < 0) ? itemTotalDicount + difference : itemTotalDicount - Math.abs(difference);
|
|
166
|
+
itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
|
|
199
167
|
}
|
|
200
168
|
}
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
if ((Number(itemTotalDicount) < Number(pointsAmount) || Number(itemTotalDicount) > Number(pointsAmount)) && pointsAmount > 0 && itemTotalDicount > 0) {
|
|
204
|
-
let difference = Number(pointsAmount) - Number(itemTotalDicount);
|
|
205
|
-
difference = parseFloat(difference).toFixed(2);
|
|
206
|
-
if (indexes.length > 0) {
|
|
207
|
-
carts[indexes[0]].points_discount = (difference > 0) ? parseFloat(carts[indexes[0]].points_discount) + parseFloat(difference) : parseFloat(carts[indexes[0]].points_discount) - Math.abs(difference);
|
|
208
|
-
carts[indexes[0]].points_discount = parseFloat(carts[indexes[0]].points_discount).toFixed(2);
|
|
209
|
-
itemTotalDicount = (difference < 0) ? itemTotalDicount + difference : itemTotalDicount - Math.abs(difference);
|
|
210
|
-
itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
169
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
cartObject.delivery_discount = deliveryDiscount;
|
|
218
|
-
cartObject.service_discount = serviceDiscount;
|
|
170
|
+
cartObject.item_details = carts
|
|
171
|
+
cartObject.store_value = pointsAmount
|
|
172
|
+
cartObject.point_discount_amount = pointsAmount
|
|
219
173
|
|
|
220
|
-
|
|
221
|
-
|
|
174
|
+
resolve(cartObject);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
222
177
|
} else {
|
|
223
178
|
cartObject.item_details = carts
|
|
224
179
|
cartObject.store_value = pointsAmount
|
|
225
180
|
cartObject.point_discount_amount = pointsAmount
|
|
226
|
-
cartObject.delivery_discount = 0;
|
|
227
|
-
cartObject.service_discount = 0;
|
|
228
181
|
|
|
229
182
|
resolve(cartObject);
|
|
230
183
|
}
|
|
@@ -35,7 +35,7 @@ function offerCalculation(carts, offer, deliveryCost = 0) {
|
|
|
35
35
|
if (offer && offer.offer_discount_type && offer.offer_discount_type == 'buy_x_get_y') {
|
|
36
36
|
getOfferDetails(carts, offer).then(res => {
|
|
37
37
|
carts = res
|
|
38
|
-
console.log("res",res)
|
|
38
|
+
// console.log("res",res)
|
|
39
39
|
if (offer && offer.oo_offer_type == 'percentage' && offer.discount_roundoff && offer.discount_roundoff == 1) {
|
|
40
40
|
|
|
41
41
|
// offer.oo_offer_types = JSON.parse(JSON.stringify(offer.oo_offer_type))
|
|
@@ -164,7 +164,7 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
164
164
|
if (offer.oo_offer_type == 'percentage') {
|
|
165
165
|
let itemTotalDiscount = 0
|
|
166
166
|
itemAmount = ((parseFloat(element.item_price) * parseFloat(element.quantity)) * parseFloat(offer.oo_offer_value)) / 100;
|
|
167
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount)
|
|
167
|
+
itemTotalDiscount = (parseFloat(itemTotalDiscount) + parseFloat(itemAmount)).toFixed(2)
|
|
168
168
|
let itemDiscount = parseFloat(itemAmount).toFixed(2);
|
|
169
169
|
|
|
170
170
|
total = parseFloat(total) + parseFloat(itemDiscount)
|
|
@@ -181,7 +181,7 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
181
181
|
let modiItemAmount = 0
|
|
182
182
|
modiItemAmount = (((parseFloat(modi.modifier_item_price) * parseFloat(modi.quantity))) * element.quantity * parseFloat(offer.oo_offer_value)) / 100;
|
|
183
183
|
|
|
184
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)
|
|
184
|
+
itemTotalDiscount = (parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)).toFixed(2)
|
|
185
185
|
let discount = parseFloat(modiItemAmount).toFixed(2)
|
|
186
186
|
total = parseFloat(total) + parseFloat(discount)
|
|
187
187
|
total = parseFloat(total).toFixed(2);
|
|
@@ -232,7 +232,7 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
232
232
|
modiItemAmount = ((parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * element.quantity) * parseFloat(singlePriceDiscount);
|
|
233
233
|
|
|
234
234
|
modiItemAmount = parseFloat(modiItemAmount).toFixed(2)
|
|
235
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)
|
|
235
|
+
itemTotalDiscount = (parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)).toFixed(2)
|
|
236
236
|
total = parseFloat(total) + parseFloat(modiItemAmount)
|
|
237
237
|
total = parseFloat(total).toFixed(2);
|
|
238
238
|
carts.item_details[index].package_items[packageItemIndex].modifiers[modiIndex].promotion_discount = parseFloat(modiItemAmount).toFixed(2)
|
|
@@ -281,7 +281,7 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
281
281
|
if (offer.oo_offer_type == 'percentage') {
|
|
282
282
|
let itemTotalDiscount = 0
|
|
283
283
|
itemAmount = ((parseFloat(element.item_price) * parseFloat(element.quantity)) * parseFloat(offer.oo_offer_value)) / 100;
|
|
284
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount)
|
|
284
|
+
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount).toFixed(2)
|
|
285
285
|
let itemDiscount = parseFloat(itemAmount).toFixed(2)
|
|
286
286
|
|
|
287
287
|
total = parseFloat(total) + parseFloat(itemDiscount)
|
|
@@ -295,7 +295,7 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
295
295
|
let modiItemAmount = 0
|
|
296
296
|
modiItemAmount = (((parseFloat(modi.modifier_item_price) * parseFloat(modi.quantity))) * element.quantity * parseFloat(offer.oo_offer_value)) / 100;
|
|
297
297
|
|
|
298
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)
|
|
298
|
+
itemTotalDiscount = (parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)).toFixed(2)
|
|
299
299
|
let discount = parseFloat(modiItemAmount).toFixed(2)
|
|
300
300
|
total = parseFloat(total) + parseFloat(discount)
|
|
301
301
|
total = parseFloat(total).toFixed(2);
|
|
@@ -329,7 +329,7 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
329
329
|
modiItemAmount = ((parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * element.quantity) * parseFloat(singlePriceDiscount);
|
|
330
330
|
|
|
331
331
|
modiItemAmount = parseFloat(modiItemAmount).toFixed(2)
|
|
332
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)
|
|
332
|
+
itemTotalDiscount = (parseFloat(itemTotalDiscount) + parseFloat(modiItemAmount)).toFixed(2)
|
|
333
333
|
total = parseFloat(total) + parseFloat(modiItemAmount)
|
|
334
334
|
total = parseFloat(total).toFixed(2);
|
|
335
335
|
carts.item_details[index].item_modifiers[modiIndex].promotion_discount = parseFloat(modiItemAmount).toFixed(2)
|
|
@@ -359,7 +359,7 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
359
359
|
|
|
360
360
|
total = parseFloat(total).toFixed(2)
|
|
361
361
|
|
|
362
|
-
itemTotalDiscount = parseFloat(itemTotalDiscount) + parseFloat(itemAmount)
|
|
362
|
+
itemTotalDiscount = (parseFloat(itemTotalDiscount) + parseFloat(itemAmount)).toFixed(2)
|
|
363
363
|
remaningOfferAmount = remaningOfferAmount - itemAmount
|
|
364
364
|
carts.item_details[index].promotion_discount = (parseFloat(carts.item_details[index].promotion_discount) + parseFloat(itemAmount)).toFixed(2);
|
|
365
365
|
carts.item_details[index].promotion_discount_modifier = (parseFloat(carts.item_details[index].promotion_discount_modifier) + parseFloat(itemAmount)).toFixed(2);
|
|
@@ -376,13 +376,8 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
376
376
|
let difference = Number(offerAmount) - Number(total)
|
|
377
377
|
difference = parseFloat(difference).toFixed(2)
|
|
378
378
|
difference = Math.abs(difference)
|
|
379
|
-
|
|
380
379
|
if (indexes.length > 0) {
|
|
381
380
|
|
|
382
|
-
// console.log("difference", difference)
|
|
383
|
-
// console.log("total", total)
|
|
384
|
-
// console.log("offerAmount", offerAmount)
|
|
385
|
-
|
|
386
381
|
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
|
|
387
382
|
carts.item_details[indexes[0]].promotion_discount = parseFloat(carts.item_details[indexes[0]].promotion_discount).toFixed(2)
|
|
388
383
|
|
|
@@ -394,7 +389,7 @@ function getCategorySpeificOffer(carts, offer) {
|
|
|
394
389
|
total = parseFloat(total).toFixed(2)
|
|
395
390
|
}
|
|
396
391
|
}
|
|
397
|
-
|
|
392
|
+
console.log("total", total)
|
|
398
393
|
carts.discount = total
|
|
399
394
|
resolve(carts);
|
|
400
395
|
}
|
|
@@ -460,7 +455,14 @@ function getOfferDetails(carts, offer = []) {
|
|
|
460
455
|
const offerBuyProducts = offer.offer_products.offer_buy_products.map(Number);
|
|
461
456
|
const offerGetProducts = offer.offer_products.offer_get_products.map(Number);
|
|
462
457
|
addItemQuantity(carts.item_details, offer).then((data) => {
|
|
463
|
-
const descending = data.sort((a, b) => (parseInt(b.amount) > parseInt(a.amount)) ? 1 : -1);
|
|
458
|
+
// const descending = data.sort((a, b) => (parseInt(b.amount) > parseInt(a.amount)) ? 1 : -1);
|
|
459
|
+
let descending = data.sort((a, b) => (parseInt(b.amount) > parseInt(a.amount)) ? 1 : -1);
|
|
460
|
+
descending = data.sort((a, b) => {
|
|
461
|
+
if (a.get && !b.get) return 1; // GET item first
|
|
462
|
+
if (!a.get && b.get) return -1; // Non-GET after
|
|
463
|
+
return 0; // Keep original amount order for ties
|
|
464
|
+
});
|
|
465
|
+
|
|
464
466
|
let total = 0
|
|
465
467
|
let buyItemAmount=0;
|
|
466
468
|
let buyItemss =[]
|
|
@@ -485,7 +487,7 @@ function getOfferDetails(carts, offer = []) {
|
|
|
485
487
|
|
|
486
488
|
function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,buyItemss) {
|
|
487
489
|
return new Promise((resolve, reject) => {
|
|
488
|
-
|
|
490
|
+
let carts = cartData.item_details;
|
|
489
491
|
const desc = JSON.parse(JSON.stringify(descending));
|
|
490
492
|
const desc1 = JSON.parse(JSON.stringify(descending));
|
|
491
493
|
let amount = 0;
|
|
@@ -496,8 +498,10 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
496
498
|
return e.item_id;
|
|
497
499
|
}
|
|
498
500
|
});
|
|
499
|
-
|
|
500
501
|
|
|
502
|
+
// console.log(descending)
|
|
503
|
+
// console.log(buyItemAmount)
|
|
504
|
+
// console.log(buyItemss)
|
|
501
505
|
|
|
502
506
|
const totalCount = parseInt(offer.offer_products.get_item_count) + parseInt(offer.offer_products.buy_item_count);
|
|
503
507
|
if (buyItems && parseInt(buyItems.length) >= parseInt(offer.offer_products.buy_item_count) && desc.length > 1 && descending.length >= totalCount) {
|
|
@@ -520,7 +524,6 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
520
524
|
if (itemIndex == -1) itemIndex = carts.findIndex(obj => obj.item_id == desc[i].item.item_id);
|
|
521
525
|
|
|
522
526
|
|
|
523
|
-
|
|
524
527
|
if (offer.oo_offer_type === "percentage") {
|
|
525
528
|
let itemTotalDiscount = 0;
|
|
526
529
|
|
|
@@ -573,14 +576,11 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
573
576
|
cartData.totalDiscount = total;
|
|
574
577
|
}
|
|
575
578
|
|
|
576
|
-
|
|
577
|
-
|
|
578
579
|
if (getCount == offer.offer_products.get_item_count && buyCount == offer.offer_products.buy_item_count) {
|
|
579
580
|
|
|
580
581
|
total = parseFloat(total) + parseFloat(amount);
|
|
581
582
|
if (offer.offer_products.order_multi_use == 1) {
|
|
582
583
|
const filterItem = desc1.filter(e => !e.remove);
|
|
583
|
-
|
|
584
584
|
cartData.item_details = carts
|
|
585
585
|
getBuyxGetYOnCondition(filterItem, cartData, offer,total,buyItemAmount,buyItemss).then((data) => {
|
|
586
586
|
resolve(data)
|
|
@@ -603,13 +603,10 @@ function getBuyxGetYOnCondition(descending, cartData, offer,total,buyItemAmount,
|
|
|
603
603
|
break;
|
|
604
604
|
}
|
|
605
605
|
}else{
|
|
606
|
-
|
|
607
606
|
if(i == desc.length -1){
|
|
608
|
-
|
|
609
607
|
cartData.discount = cartData.totalDiscount?cartData.totalDiscount:0;
|
|
610
608
|
resolve(cartData);
|
|
611
609
|
}
|
|
612
|
-
|
|
613
610
|
}
|
|
614
611
|
}
|
|
615
612
|
} else {
|
|
@@ -748,7 +745,7 @@ function addItemQuantity(items, offer) {
|
|
|
748
745
|
);
|
|
749
746
|
offer.offer_products.offer_get_products=offer.offer_products.offer_get_products.map(item =>
|
|
750
747
|
item.toString().length > 10 ? item : parseInt(item, 10)
|
|
751
|
-
)
|
|
748
|
+
)
|
|
752
749
|
items.forEach(function (element) {
|
|
753
750
|
let itemId = element.item_id?.toString().length > 10 ? element.item_id : parseInt(element.item_id);
|
|
754
751
|
if (offer.offer_products.offer_buy_products.includes(itemId) || offer.offer_products.offer_get_products.includes(itemId)) {
|
|
@@ -789,6 +786,8 @@ function addItemQuantity(items, offer) {
|
|
|
789
786
|
'buy': offer.offer_products.offer_buy_products.includes(itemId),
|
|
790
787
|
'get': offer.offer_products.offer_get_products.includes(itemId)
|
|
791
788
|
});
|
|
789
|
+
|
|
790
|
+
// console.log(finalItems)
|
|
792
791
|
}
|
|
793
792
|
}
|
|
794
793
|
}
|