foodbot-cart-calculations 1.0.3-dev.1 → 1.0.4-dev.1
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 +23 -16
- package/functions/pointsCalculation.js +199 -87
- package/index.js +3 -2
- package/package.json +1 -1
package/calculations.js
CHANGED
|
@@ -8,10 +8,15 @@ 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
|
+
}
|
|
15
20
|
|
|
16
21
|
promoCalculation.setPackageDefaultDiscount(body.order_items).then(res => {
|
|
17
22
|
promoCalculation.offerCalculation(res, promotion, deliveryCost).then(final => {
|
|
@@ -30,8 +35,7 @@ function applyDistribution(body) {
|
|
|
30
35
|
}
|
|
31
36
|
mainCart.store_value = 0;
|
|
32
37
|
|
|
33
|
-
pointsCalculation.getPointsDiscount(final, body.loyalty_points_details, body.user_detais).then(pointsCal => {
|
|
34
|
-
|
|
38
|
+
pointsCalculation.getPointsDiscount(final, body.loyalty_points_details, body.user_detais, body.delivery_cost, body.service_amount).then(pointsCal => {
|
|
35
39
|
if (typeof (final.store_value) == "undefined" || isNaN(final.store_value))
|
|
36
40
|
final.store_value = 0
|
|
37
41
|
if (body.loyalty_points_details && parseInt(body.loyalty_points_details.points_redeemed) == 0) {
|
|
@@ -73,23 +77,26 @@ function applyDistribution(body) {
|
|
|
73
77
|
mainCart.cash_expected = parseFloat(taxData.cartTotal) + parseFloat(taxData.tax_amount);
|
|
74
78
|
}
|
|
75
79
|
mainCart.order_items = taxData
|
|
76
|
-
|
|
80
|
+
|
|
77
81
|
let delivery_cost = body.delivery_cost ? body.delivery_cost : 0;
|
|
82
|
+
let service_amount = body.service_amount ? body.service_amount : 0;
|
|
78
83
|
// Adjust delivery cost based on delivery discount
|
|
79
84
|
if (final.is_delivery_discount) {
|
|
80
|
-
delivery_cost = Math.max(0, delivery_cost - final.delivery_discount);
|
|
85
|
+
delivery_cost = Math.max(0, delivery_cost - final.delivery_discount);
|
|
81
86
|
body.delivery_cost = delivery_cost; // Update body accordingly
|
|
82
87
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
// Adjust service amount based on service discount
|
|
89
|
+
if (final.is_service_discount) {
|
|
90
|
+
service_amount = Math.max(0, service_amount - final.service_discount);
|
|
91
|
+
body.service_amount = service_amount;
|
|
92
|
+
}
|
|
93
|
+
//we took 2 value because in case of absolute we use tipValue
|
|
94
|
+
let tipValue = body.tip_value?body.tip_value:0;
|
|
95
|
+
let tipValueReq = body.tip_value?body.tip_value:0;
|
|
89
96
|
|
|
90
97
|
if (body.tip_type && body.tip_type == 'percentage') {
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
tipValue = (mainCart.final_amount * parseInt(tipValueReq)) / 100
|
|
99
|
+
tipValue = parseFloat(tipValue).toFixed(2)
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
mainCart.tip_amount = parseFloat(tipValue).toFixed(2);
|
|
@@ -105,10 +112,10 @@ function applyDistribution(body) {
|
|
|
105
112
|
|
|
106
113
|
taxData.total_after_tax = parseFloat(taxData.total_after_tax) + parseFloat(tipValue);
|
|
107
114
|
taxData.total_after_tax = parseFloat(taxData.total_after_tax).toFixed(2);
|
|
108
|
-
|
|
115
|
+
|
|
109
116
|
mainCart.final_amount = parseFloat(mainCart.final_amount) + parseFloat(tipValue);
|
|
110
117
|
mainCart.cash_expected = parseFloat(mainCart.cash_expected) + parseFloat(tipValue);
|
|
111
|
-
|
|
118
|
+
|
|
112
119
|
taxData.final_amount = parseFloat(taxData.final_amount).toFixed(2);
|
|
113
120
|
taxData.cash_expected = parseFloat(taxData.cash_expected).toFixed(2);
|
|
114
121
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
function getPointsDiscount(cartObject, points, userDetails) {
|
|
1
|
+
function getPointsDiscount(cartObject, points, userDetails, deliveryCost = 0, serviceAmount = 0) {
|
|
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;
|
|
6
8
|
|
|
9
|
+
// reset old discounts
|
|
7
10
|
carts.forEach(function (v) {
|
|
8
11
|
delete v.points_discount_modifier;
|
|
9
12
|
delete v.points_discount;
|
|
@@ -32,8 +35,11 @@ function getPointsDiscount(cartObject, points, userDetails) {
|
|
|
32
35
|
});
|
|
33
36
|
}
|
|
34
37
|
});
|
|
38
|
+
|
|
35
39
|
if (!points) {
|
|
36
|
-
|
|
40
|
+
cartObject.delivery_discount = 0;
|
|
41
|
+
cartObject.service_discount = 0;
|
|
42
|
+
resolve(cartObject);
|
|
37
43
|
} else {
|
|
38
44
|
let pointsAmount = 0;
|
|
39
45
|
let count = 0;
|
|
@@ -71,113 +77,219 @@ function getPointsDiscount(cartObject, points, userDetails) {
|
|
|
71
77
|
element.point_discount_status = true;
|
|
72
78
|
}
|
|
73
79
|
count++;
|
|
80
|
+
});
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
// Apply points to service charge if enabled
|
|
83
|
+
if (points.enable_service_charge_usage === 1 && serviceAmount > 0 && storeAmount > 0) {
|
|
84
|
+
cartObject.is_service_discount = true;
|
|
85
|
+
if (parseFloat(storeAmount) >= parseFloat(serviceAmount)) {
|
|
86
|
+
serviceDiscount = parseFloat(serviceAmount);
|
|
87
|
+
pointsAmount = parseFloat(pointsAmount) + parseFloat(serviceAmount);
|
|
88
|
+
storeAmount = parseFloat(storeAmount) - parseFloat(serviceAmount);
|
|
89
|
+
} else {
|
|
90
|
+
serviceDiscount = parseFloat(storeAmount);
|
|
91
|
+
pointsAmount = parseFloat(pointsAmount) + parseFloat(storeAmount);
|
|
92
|
+
storeAmount = 0;
|
|
93
|
+
}
|
|
94
|
+
serviceDiscount = parseFloat(serviceDiscount).toFixed(2);
|
|
95
|
+
cartObject.service_discount = serviceDiscount;
|
|
96
|
+
} else {
|
|
97
|
+
cartObject.service_discount = 0;
|
|
98
|
+
cartObject.is_service_discount = false;
|
|
99
|
+
}
|
|
78
100
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
101
|
+
// Apply points to delivery if enabled
|
|
102
|
+
if (points.enable_delivery_points_usage === 1 && deliveryCost > 0 && storeAmount > 0) {
|
|
103
|
+
cartObject.is_delivery_discount = true;
|
|
104
|
+
if (parseFloat(storeAmount) >= parseFloat(deliveryCost)) {
|
|
105
|
+
deliveryDiscount = parseFloat(deliveryCost);
|
|
106
|
+
pointsAmount = parseFloat(pointsAmount) + parseFloat(deliveryCost);
|
|
107
|
+
storeAmount = parseFloat(storeAmount) - parseFloat(deliveryCost);
|
|
108
|
+
} else {
|
|
109
|
+
deliveryDiscount = parseFloat(storeAmount);
|
|
110
|
+
pointsAmount = parseFloat(pointsAmount) + parseFloat(storeAmount);
|
|
111
|
+
storeAmount = 0;
|
|
112
|
+
}
|
|
113
|
+
deliveryDiscount = parseFloat(deliveryDiscount).toFixed(2);
|
|
114
|
+
cartObject.delivery_discount = deliveryDiscount;
|
|
115
|
+
} else {
|
|
116
|
+
cartObject.delivery_discount = 0;
|
|
117
|
+
cartObject.is_delivery_discount = false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (count == carts.length) {
|
|
121
|
+
let singlePriceDiscount = pointsAmount / itemsTotal;
|
|
122
|
+
singlePriceDiscount = (itemsTotal && itemsTotal > 0)?parseFloat(singlePriceDiscount).toFixed(6):0;
|
|
82
123
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
item.points_discount_modifier = item.points_discount_modifier ? item.points_discount_modifier : 0;
|
|
124
|
+
let indexes = [];
|
|
125
|
+
let itemTotalDicount = 0;
|
|
86
126
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
itemDiscount = ((item.item_price * item.quantity) - promoDiscount) * singlePriceDiscount;
|
|
91
|
-
itemDiscount = parseFloat(itemDiscount).toFixed(2);
|
|
92
|
-
itemTotalDicount = parseFloat(itemDiscount) + parseFloat(itemTotalDicount);
|
|
127
|
+
carts.forEach((item, index) => {
|
|
128
|
+
item.points_discount = item.points_discount ? item.points_discount : 0;
|
|
129
|
+
item.points_discount_modifier = item.points_discount_modifier ? item.points_discount_modifier : 0;
|
|
93
130
|
|
|
94
|
-
|
|
95
|
-
indexes.push(index);
|
|
131
|
+
// Replace the package items section (around line 120-170) with this corrected version:
|
|
96
132
|
|
|
97
|
-
item.
|
|
98
|
-
|
|
133
|
+
if (item.isPackage == 1) {
|
|
134
|
+
if (item.point_discount_status) {
|
|
135
|
+
let promoDiscount = (item.promotion_discount) ? item.promotion_discount : 0;
|
|
136
|
+
let itemDiscount = ((item.item_price * item.quantity) - promoDiscount) * singlePriceDiscount;
|
|
137
|
+
itemDiscount = parseFloat(itemDiscount).toFixed(2);
|
|
138
|
+
|
|
139
|
+
// Cap item discount to not exceed actual item price
|
|
140
|
+
let maxItemDiscount = (item.item_price * item.quantity) - promoDiscount;
|
|
141
|
+
if (parseFloat(itemDiscount) > maxItemDiscount) {
|
|
142
|
+
itemDiscount = parseFloat(maxItemDiscount).toFixed(2);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (itemDiscount > 0)
|
|
146
|
+
indexes.push(index);
|
|
147
|
+
|
|
148
|
+
let totalPackageItemsDiscount = 0;
|
|
149
|
+
let totalPackageModifiersDiscount = 0;
|
|
150
|
+
|
|
151
|
+
item.package_items.forEach((packageItem, packageItemIndex) => {
|
|
152
|
+
let packageItemPromoDiscount = (packageItem.promotion_discount) ? packageItem.promotion_discount : 0;
|
|
153
|
+
packageItem.points_discount_modifier = 0;
|
|
154
|
+
|
|
155
|
+
// Calculate base package item price
|
|
156
|
+
let packageItemBasePrice = (packageItem.price * parseInt(item.quantity)) - parseFloat(packageItem.default_combo_discount || 0) - parseFloat(packageItemPromoDiscount);
|
|
157
|
+
|
|
158
|
+
// Ensure base price is not negative
|
|
159
|
+
if (packageItemBasePrice < 0) {
|
|
160
|
+
packageItemBasePrice = 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Calculate discount for package item
|
|
164
|
+
let packageItemDiscount = (packageItemBasePrice * parseFloat(singlePriceDiscount));
|
|
165
|
+
packageItemDiscount = parseFloat(packageItemDiscount).toFixed(2);
|
|
166
|
+
|
|
167
|
+
// Cap package item discount to not exceed its actual price
|
|
168
|
+
if (parseFloat(packageItemDiscount) > packageItemBasePrice) {
|
|
169
|
+
packageItemDiscount = parseFloat(packageItemBasePrice).toFixed(2);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Ensure discount is not negative
|
|
173
|
+
if (parseFloat(packageItemDiscount) < 0) {
|
|
174
|
+
packageItemDiscount = "0.00";
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
packageItem.points_discount = packageItemDiscount;
|
|
178
|
+
totalPackageItemsDiscount = parseFloat(totalPackageItemsDiscount) + parseFloat(packageItemDiscount);
|
|
179
|
+
|
|
180
|
+
// Handle modifiers
|
|
181
|
+
if (packageItem.modifiers && packageItem.modifiers.length > 0) {
|
|
182
|
+
packageItem.modifiers.forEach((modi, modiIndex) => {
|
|
183
|
+
let modiPromoDiscount = (modi.promotion_discount) ? modi.promotion_discount : 0;
|
|
184
|
+
|
|
185
|
+
// Calculate modifier base price
|
|
186
|
+
let modiBasePrice = (parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * item.quantity - modiPromoDiscount;
|
|
187
|
+
|
|
188
|
+
// Ensure modifier base price is not negative
|
|
189
|
+
if (modiBasePrice < 0) {
|
|
190
|
+
modiBasePrice = 0;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let modiItemAmount = (modiBasePrice * parseFloat(singlePriceDiscount));
|
|
194
|
+
modiItemAmount = parseFloat(modiItemAmount).toFixed(2);
|
|
195
|
+
|
|
196
|
+
// Cap modifier discount
|
|
197
|
+
if (parseFloat(modiItemAmount) > modiBasePrice) {
|
|
198
|
+
modiItemAmount = parseFloat(modiBasePrice).toFixed(2);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Ensure discount is not negative
|
|
202
|
+
if (parseFloat(modiItemAmount) < 0) {
|
|
203
|
+
modiItemAmount = "0.00";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
modi.points_discount = modiItemAmount;
|
|
207
|
+
packageItem.points_discount_modifier = (parseFloat(packageItem.points_discount_modifier) + parseFloat(modi.points_discount)).toFixed(2);
|
|
208
|
+
totalPackageModifiersDiscount = parseFloat(totalPackageModifiersDiscount) + parseFloat(modiItemAmount);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Set main package item discounts to reflect total of package items
|
|
214
|
+
item.points_discount = parseFloat(totalPackageItemsDiscount).toFixed(2);
|
|
215
|
+
item.points_discount_modifier = parseFloat(totalPackageModifiersDiscount).toFixed(2);
|
|
216
|
+
|
|
217
|
+
// Add to cart-level total
|
|
218
|
+
itemTotalDicount = parseFloat(itemTotalDicount) + parseFloat(totalPackageItemsDiscount) + parseFloat(totalPackageModifiersDiscount);
|
|
219
|
+
itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
if (item.point_discount_status) {
|
|
223
|
+
let promoDiscount = (item.promotion_discount) ? item.promotion_discount : 0;
|
|
99
224
|
|
|
100
|
-
|
|
225
|
+
// --- Base item discount ---
|
|
226
|
+
let basePrice = parseFloat(item.item_price) * item.quantity;
|
|
227
|
+
let baseDiscount = ((basePrice - promoDiscount) * singlePriceDiscount);
|
|
228
|
+
baseDiscount = parseFloat(baseDiscount).toFixed(2);
|
|
101
229
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
230
|
+
// cap base discount
|
|
231
|
+
if (parseFloat(baseDiscount) > basePrice) {
|
|
232
|
+
baseDiscount = basePrice.toFixed(2);
|
|
233
|
+
}
|
|
105
234
|
|
|
106
|
-
|
|
107
|
-
|
|
235
|
+
if (parseFloat(baseDiscount) > 0) {
|
|
236
|
+
indexes.push(index);
|
|
237
|
+
}
|
|
238
|
+
item.points_discount = baseDiscount;
|
|
108
239
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
});
|
|
240
|
+
// --- Modifiers ---
|
|
241
|
+
let modsTotalDiscount = 0;
|
|
242
|
+
if (item.item_modifiers && item.item_modifiers.length > 0) {
|
|
243
|
+
item.item_modifiers.forEach((modi) => {
|
|
244
|
+
let modiBase = parseFloat(modi.modifier_item_price) * modi.quantity * item.quantity;
|
|
245
|
+
let modiDiscount = (modiBase * parseFloat(singlePriceDiscount));
|
|
246
|
+
modiDiscount = parseFloat(modiDiscount).toFixed(2);
|
|
121
247
|
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
|
|
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);
|
|
248
|
+
// cap modifier
|
|
249
|
+
if (parseFloat(modiDiscount) > modiBase) {
|
|
250
|
+
modiDiscount = modiBase.toFixed(2);
|
|
129
251
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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) => {
|
|
145
|
-
let modiItemAmount = 0;
|
|
146
|
-
let modiPromoDiscount = (modi.promotion_discount) ? modi.promotion_discount : 0;
|
|
147
|
-
modiItemAmount = (((parseFloat(modi.modifier_item_price) * parseInt(modi.quantity)) * item.quantity) - modiPromoDiscount) * parseFloat(singlePriceDiscount);
|
|
148
|
-
modiItemAmount = parseFloat(modiItemAmount).toFixed(2);
|
|
149
|
-
itemTotalDicount = parseFloat(itemTotalDicount) + parseFloat(modiItemAmount);
|
|
150
|
-
itemTotalDicount = parseFloat(itemTotalDicount).toFixed(2);
|
|
151
|
-
modi.points_discount = modiItemAmount;
|
|
252
|
+
|
|
253
|
+
modi.points_discount = modiDiscount;
|
|
254
|
+
modsTotalDiscount = (parseFloat(modsTotalDiscount) + parseFloat(modiDiscount)).toFixed(2);
|
|
152
255
|
});
|
|
256
|
+
}
|
|
257
|
+
item.points_discount_modifier = modsTotalDiscount;
|
|
153
258
|
|
|
154
|
-
|
|
259
|
+
// --- cap total item discount ---
|
|
260
|
+
let itemMax = parseFloat(item.item_price_with_modifier) * item.quantity;
|
|
261
|
+
let totalItemDiscount = parseFloat(item.points_discount) + parseFloat(item.points_discount_modifier);
|
|
262
|
+
if (totalItemDiscount > itemMax) {
|
|
263
|
+
let overflow = totalItemDiscount - itemMax;
|
|
264
|
+
if (parseFloat(item.points_discount_modifier) >= overflow) {
|
|
265
|
+
item.points_discount_modifier = (parseFloat(item.points_discount_modifier) - overflow).toFixed(2);
|
|
266
|
+
} else {
|
|
267
|
+
let leftover = overflow - parseFloat(item.points_discount_modifier);
|
|
268
|
+
item.points_discount_modifier = "0.00";
|
|
269
|
+
item.points_discount = (parseFloat(item.points_discount) - leftover).toFixed(2);
|
|
270
|
+
}
|
|
155
271
|
}
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
272
|
|
|
159
|
-
|
|
160
|
-
|
|
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);
|
|
273
|
+
// add to cart-level total
|
|
274
|
+
itemTotalDicount = (parseFloat(itemTotalDicount) + parseFloat(item.points_discount) + parseFloat(item.points_discount_modifier)).toFixed(2);
|
|
167
275
|
}
|
|
168
276
|
}
|
|
277
|
+
});
|
|
169
278
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
279
|
+
cartObject.item_details = carts
|
|
280
|
+
cartObject.store_value = pointsAmount
|
|
281
|
+
cartObject.point_discount_amount = pointsAmount
|
|
282
|
+
cartObject.delivery_discount = deliveryDiscount;
|
|
283
|
+
cartObject.service_discount = serviceDiscount;
|
|
173
284
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
});
|
|
285
|
+
resolve(cartObject);
|
|
286
|
+
}
|
|
177
287
|
} else {
|
|
178
288
|
cartObject.item_details = carts
|
|
179
|
-
cartObject.store_value =
|
|
180
|
-
cartObject.point_discount_amount =
|
|
289
|
+
cartObject.store_value = 0
|
|
290
|
+
cartObject.point_discount_amount = 0
|
|
291
|
+
cartObject.delivery_discount = 0;
|
|
292
|
+
cartObject.service_discount = 0;
|
|
181
293
|
|
|
182
294
|
resolve(cartObject);
|
|
183
295
|
}
|
package/index.js
CHANGED
|
@@ -848,8 +848,9 @@ async function calculateTax(inputJSON) {
|
|
|
848
848
|
// }
|
|
849
849
|
// };
|
|
850
850
|
|
|
851
|
+
// let json = JSON.parse(fs.readFileSync('./sampleInput.json', 'utf8'));
|
|
851
852
|
// calculateTax(json).then(res=>{
|
|
852
|
-
//
|
|
853
|
+
// console.log(JSON.stringify(res))
|
|
853
854
|
|
|
854
855
|
// const jsonResponse = JSON.stringify(res, null, 2); // Format the JSON with indentation
|
|
855
856
|
// const filePath = path.join(__dirname, 'response.json'); // File path in the same directory
|
|
@@ -865,5 +866,5 @@ async function calculateTax(inputJSON) {
|
|
|
865
866
|
// }).catch(err=>{
|
|
866
867
|
// console.log(err)
|
|
867
868
|
// })
|
|
868
|
-
|
|
869
|
+
|
|
869
870
|
module.exports = { calculateTax }
|
package/package.json
CHANGED