@managesome/eposmatic-toolkit 0.2.412 → 0.2.415
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.
|
@@ -218,8 +218,15 @@ interface IGetOffersWithStats {
|
|
|
218
218
|
totalDiscountApplied: number | undefined;
|
|
219
219
|
currentItemsPrice: number | undefined;
|
|
220
220
|
order_discount_details: IDiscountDetails | null | undefined;
|
|
221
|
+
/**
|
|
222
|
+
* When true, the customer stats (total_orders, total_orders_per_platform_type)
|
|
223
|
+
* are adjusted to reflect the state before the current order was placed.
|
|
224
|
+
* Used during order editing to prevent the order being edited from
|
|
225
|
+
* inflating eligibility thresholds (e.g. ORDER_FROM max_num_of_orders).
|
|
226
|
+
*/
|
|
227
|
+
isEdit?: boolean;
|
|
221
228
|
}
|
|
222
|
-
export declare function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, }: IGetOffersWithStats): {
|
|
229
|
+
export declare function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, isEdit, }: IGetOffersWithStats): {
|
|
223
230
|
offersWithStats: IOfferWithStats[];
|
|
224
231
|
totalClaimableOffers: string[];
|
|
225
232
|
unlockedOffersApplicableTimes: Record<string, number>;
|
|
@@ -1461,11 +1461,12 @@ function getProgressPercentage(currentValue, requiredValue) {
|
|
|
1461
1461
|
function getPreUnlockProgressPercentage(currentValue, requiredValue) {
|
|
1462
1462
|
return Math.min(99, getProgressPercentage(currentValue, requiredValue));
|
|
1463
1463
|
}
|
|
1464
|
-
function getUnlockedOffersApplicableTimesHashKey(map) {
|
|
1464
|
+
function getUnlockedOffersApplicableTimesHashKey(map, isEdit) {
|
|
1465
1465
|
const keys = Object.keys(map).sort();
|
|
1466
|
+
const editPrefix = isEdit ? 'edit:v1:' : '';
|
|
1466
1467
|
if (keys.length === 0)
|
|
1467
|
-
return
|
|
1468
|
-
let result =
|
|
1468
|
+
return `unlock:v1:${editPrefix}empty`;
|
|
1469
|
+
let result = `unlock:v1:${editPrefix}`;
|
|
1469
1470
|
for (let i = 0; i < keys.length; i++) {
|
|
1470
1471
|
const key = keys[i];
|
|
1471
1472
|
result += `${key}:${map[key]};`;
|
|
@@ -1493,12 +1494,13 @@ function getRewardPreviewHashKey(rewardPreview) {
|
|
|
1493
1494
|
// Failing to do so will cause the frontend (OffersProvider) to miss state changes —
|
|
1494
1495
|
// it compares hash key strings to decide whether to update React state / dispatch Redux actions.
|
|
1495
1496
|
// The same rule applies to getUnlockedOffersApplicableTimesHashKey and getRewardPreviewHashKey.
|
|
1496
|
-
function getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers) {
|
|
1497
|
+
function getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers, isEdit) {
|
|
1498
|
+
const editSegment = isEdit ? 'edit:' : '';
|
|
1497
1499
|
if (offersWithStats.length === 0) {
|
|
1498
|
-
return `offers:v1
|
|
1500
|
+
return `offers:v1:${editSegment}empty:${totalClaimableOffers.length}`;
|
|
1499
1501
|
}
|
|
1500
1502
|
const sortedOffers = [...offersWithStats].sort((a, b) => a.offer._id.localeCompare(b.offer._id));
|
|
1501
|
-
let result = `offers:v1:${totalClaimableOffers.length}|`;
|
|
1503
|
+
let result = `offers:v1:${editSegment}${totalClaimableOffers.length}|`;
|
|
1502
1504
|
for (let i = 0; i < sortedOffers.length; i++) {
|
|
1503
1505
|
const { offer, stats } = sortedOffers[i];
|
|
1504
1506
|
const eligibleItemIds = [...stats.eligible_item_ids].sort().join(',');
|
|
@@ -1508,7 +1510,7 @@ function getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers) {
|
|
|
1508
1510
|
}
|
|
1509
1511
|
return result;
|
|
1510
1512
|
}
|
|
1511
|
-
function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, }) {
|
|
1513
|
+
function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, isEdit, }) {
|
|
1512
1514
|
const offersWithStats = [];
|
|
1513
1515
|
const orderLevelDiscountBaseAmount = getOrderLevelDiscountBaseAmountForOfferStats({
|
|
1514
1516
|
categories,
|
|
@@ -1660,9 +1662,11 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1660
1662
|
};
|
|
1661
1663
|
const getOrdersScopedStats = ({ scope, currentOrderValue, }) => {
|
|
1662
1664
|
if (scope === constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL) {
|
|
1665
|
+
const rawTotalOrders = customer?.total_orders ?? 0;
|
|
1666
|
+
const totalOrders = isEdit ? Math.max(0, rawTotalOrders - 1) : rawTotalOrders;
|
|
1663
1667
|
return {
|
|
1664
1668
|
valid: true,
|
|
1665
|
-
totalOrders
|
|
1669
|
+
totalOrders,
|
|
1666
1670
|
totalAmount: currentOrderValue,
|
|
1667
1671
|
};
|
|
1668
1672
|
}
|
|
@@ -1675,9 +1679,11 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1675
1679
|
}
|
|
1676
1680
|
const totalOrdersPerPlatform = customer?.total_orders_per_platform_type;
|
|
1677
1681
|
if (scope === constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.PLATFORM) {
|
|
1682
|
+
const rawPlatformOrders = totalOrdersPerPlatform?.[platform] ?? 0;
|
|
1683
|
+
const totalOrders = isEdit ? Math.max(0, rawPlatformOrders - 1) : rawPlatformOrders;
|
|
1678
1684
|
return {
|
|
1679
1685
|
valid: true,
|
|
1680
|
-
totalOrders
|
|
1686
|
+
totalOrders,
|
|
1681
1687
|
totalAmount: currentOrderValue,
|
|
1682
1688
|
};
|
|
1683
1689
|
}
|
|
@@ -1695,6 +1701,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1695
1701
|
const groupedPlatform = platformsForOrderFrom[i];
|
|
1696
1702
|
totalOrders += totalOrdersPerPlatform?.[groupedPlatform] ?? 0;
|
|
1697
1703
|
}
|
|
1704
|
+
// When editing, the current order's platform bucket is inflated by 1.
|
|
1705
|
+
// Since ORDER_FROM aggregates across all platforms under the same
|
|
1706
|
+
// prefix and the current order contributed exactly 1 to its own
|
|
1707
|
+
// platform bucket, subtract 1 from the aggregate.
|
|
1708
|
+
if (isEdit) {
|
|
1709
|
+
totalOrders = Math.max(0, totalOrders - 1);
|
|
1710
|
+
}
|
|
1698
1711
|
return {
|
|
1699
1712
|
valid: true,
|
|
1700
1713
|
totalOrders,
|
|
@@ -3016,7 +3029,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3016
3029
|
offersWithStats,
|
|
3017
3030
|
totalClaimableOffers,
|
|
3018
3031
|
unlockedOffersApplicableTimes,
|
|
3019
|
-
offersWithStatsHashKey: getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers),
|
|
3020
|
-
unlockedOffersApplicableTimesHashKey: getUnlockedOffersApplicableTimesHashKey(unlockedOffersApplicableTimes),
|
|
3032
|
+
offersWithStatsHashKey: getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers, isEdit),
|
|
3033
|
+
unlockedOffersApplicableTimesHashKey: getUnlockedOffersApplicableTimesHashKey(unlockedOffersApplicableTimes, isEdit),
|
|
3021
3034
|
};
|
|
3022
3035
|
}
|
|
@@ -128,11 +128,10 @@ function getReceiptEngineFooterDetails(order, settings) {
|
|
|
128
128
|
// Compute the actual GST base (the amount GST was calculated on)
|
|
129
129
|
let gstBase = price;
|
|
130
130
|
if (!order.exclude_discount_from_gst) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (order.exclude_discount_from_gst) {
|
|
134
|
-
gstBase += itemDiscount;
|
|
131
|
+
// Discount is included in GST base — subtract all applied discounts
|
|
132
|
+
gstBase -= totalDiscount;
|
|
135
133
|
}
|
|
134
|
+
// When exclude_discount_from_gst is true, GST base stays at the full price
|
|
136
135
|
if (order.is_surcharge_taxable) {
|
|
137
136
|
gstBase += order.surcharge_amount ?? 0;
|
|
138
137
|
}
|