@managesome/eposmatic-toolkit 0.2.285 → 0.2.287
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.
|
@@ -36,17 +36,45 @@ const utils_1 = require("../utils");
|
|
|
36
36
|
const platform_catalog_1 = require("../utils/platform-catalog");
|
|
37
37
|
function getItemQuantityChangeResults({ prevQuantity, newQuantity, prevItemDiscountDetails, }) {
|
|
38
38
|
let item_discount_details = prevItemDiscountDetails;
|
|
39
|
+
const getScaledFixedDiscount = (discountValue, isPercentage) => {
|
|
40
|
+
if (isPercentage)
|
|
41
|
+
return discountValue;
|
|
42
|
+
if (prevQuantity <= 0)
|
|
43
|
+
return discountValue;
|
|
44
|
+
const perUnitDiscount = discountValue / prevQuantity;
|
|
45
|
+
return (0, utils_1.parseNum)(perUnitDiscount * newQuantity);
|
|
46
|
+
};
|
|
47
|
+
let hasUpdatedDiscount = false;
|
|
39
48
|
if (item_discount_details != null &&
|
|
40
49
|
item_discount_details.special_discount_id != null &&
|
|
41
50
|
item_discount_details.special_discount != null) {
|
|
42
|
-
let special_discount = item_discount_details.special_discount;
|
|
43
|
-
if (!item_discount_details.is_special_discount_percentage) {
|
|
44
|
-
const actualDiscount = item_discount_details.special_discount / prevQuantity;
|
|
45
|
-
special_discount = (0, utils_1.parseNum)(actualDiscount * newQuantity);
|
|
46
|
-
}
|
|
47
51
|
item_discount_details = {
|
|
48
52
|
...item_discount_details,
|
|
49
|
-
special_discount,
|
|
53
|
+
special_discount: getScaledFixedDiscount(item_discount_details.special_discount, item_discount_details.is_special_discount_percentage),
|
|
54
|
+
};
|
|
55
|
+
hasUpdatedDiscount = true;
|
|
56
|
+
}
|
|
57
|
+
if (item_discount_details != null &&
|
|
58
|
+
item_discount_details.loyalty_discount_id != null &&
|
|
59
|
+
item_discount_details.loyalty_discount != null) {
|
|
60
|
+
item_discount_details = {
|
|
61
|
+
...item_discount_details,
|
|
62
|
+
loyalty_discount: getScaledFixedDiscount(item_discount_details.loyalty_discount, item_discount_details.is_loyalty_discount_percentage),
|
|
63
|
+
};
|
|
64
|
+
hasUpdatedDiscount = true;
|
|
65
|
+
}
|
|
66
|
+
if (item_discount_details != null &&
|
|
67
|
+
item_discount_details.voucher_discount_id != null &&
|
|
68
|
+
item_discount_details.voucher_discount != null) {
|
|
69
|
+
item_discount_details = {
|
|
70
|
+
...item_discount_details,
|
|
71
|
+
voucher_discount: getScaledFixedDiscount(item_discount_details.voucher_discount, item_discount_details.is_voucher_discount_percentage),
|
|
72
|
+
};
|
|
73
|
+
hasUpdatedDiscount = true;
|
|
74
|
+
}
|
|
75
|
+
if (item_discount_details != null && hasUpdatedDiscount) {
|
|
76
|
+
item_discount_details = {
|
|
77
|
+
...item_discount_details,
|
|
50
78
|
total_discount: 0,
|
|
51
79
|
};
|
|
52
80
|
}
|
|
@@ -136,6 +136,7 @@ function getEditItemProps({ item, orderItemCategoryId, orderItem, offers, isLoya
|
|
|
136
136
|
excludedDiscountRefs = offerExcludedDiscountRefs;
|
|
137
137
|
}
|
|
138
138
|
// TODO: We need to add use case for HalfHalf and Specials
|
|
139
|
+
const isRewardItem = isLoyaltyDiscountApplied || isVoucherDiscountApplied;
|
|
139
140
|
const props = {
|
|
140
141
|
catalogItem: item,
|
|
141
142
|
orderItemId: orderItem._id,
|
|
@@ -145,6 +146,7 @@ function getEditItemProps({ item, orderItemCategoryId, orderItem, offers, isLoya
|
|
|
145
146
|
excludeRefs,
|
|
146
147
|
excludedDiscountRefs,
|
|
147
148
|
zeroPriceRefs,
|
|
149
|
+
...(isRewardItem && { maxQuantity: orderItem.quantity }),
|
|
148
150
|
};
|
|
149
151
|
return props;
|
|
150
152
|
}
|