@managesome/eposmatic-toolkit 0.4.37 → 0.4.39
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/esm/constants/accounting-templates.js +431 -0
- package/esm/constants/index.js +1 -0
- package/esm/helpers/store/cart-actions.js +54 -6
- package/esm/helpers/utils/cart-helpers.js +19 -5
- package/esm/helpers/utils/common.js +18 -1
- package/esm/helpers/utils/offer-apply-helpers.js +5 -3
- package/esm/helpers/utils/offers-helpers.js +92 -63
- package/lib/constants/accounting-templates.d.ts +8 -0
- package/lib/constants/accounting-templates.js +434 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/helpers/store/cart-actions.js +54 -6
- package/lib/helpers/utils/cart-helpers.js +19 -5
- package/lib/helpers/utils/common.d.ts +15 -0
- package/lib/helpers/utils/common.js +19 -1
- package/lib/helpers/utils/offer-apply-helpers.js +5 -3
- package/lib/helpers/utils/offers-helpers.d.ts +15 -4
- package/lib/helpers/utils/offers-helpers.js +92 -62
- package/lib/schemas/models/expense_categories.d.ts +3 -3
- package/lib/schemas/models/expense_details.d.ts +3 -3
- package/lib/schemas/models/gift_cards.d.ts +3 -3
- package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
- package/lib/schemas/models/internal_invoices.d.ts +3 -3
- package/lib/schemas/models/items.d.ts +12 -12
- package/lib/schemas/models/marketing_fingerprints.d.ts +3 -3
- package/lib/schemas/models/modifier_extras.d.ts +3 -3
- package/lib/schemas/models/offers.d.ts +3 -3
- package/lib/schemas/models/public_holidays.d.ts +3 -3
- package/lib/schemas/models/specials.d.ts +3 -3
- package/lib/schemas/models/tenant_chart_of_accounts.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_departments.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_documents.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_policies.d.ts +3 -3
- package/lib/schemas/models/tenant_hr_positions.d.ts +3 -3
- package/lib/schemas/models/tenant_journal_entries.d.ts +3 -3
- package/lib/schemas/models/void_order_items.d.ts +3 -3
- package/lib/schemas/models/vouchers.d.ts +3 -3
- package/lib/schemas/models/warehouse_communications.d.ts +3 -3
- package/lib/schemas/models/warehouse_items.d.ts +3 -3
- package/lib/schemas/models/warehouse_void_purchase_order_items.d.ts +3 -3
- package/lib/schemas/models/warehouse_void_sale_order_items.d.ts +3 -3
- package/lib/schemas/types/tenant_chart_of_accounts.d.ts +7 -0
- package/lib/tests/cart-helpers-edit-item-refs.test.d.ts +1 -0
- package/lib/tests/cart-helpers-edit-item-refs.test.js +99 -0
- package/lib/tests/code-redemption-helpers.test.d.ts +1 -0
- package/lib/tests/code-redemption-helpers.test.js +246 -0
- package/lib/tests/gift-card-helpers.test.d.ts +1 -0
- package/lib/tests/gift-card-helpers.test.js +100 -0
- package/lib/tests/offer-claim-regressions.test.d.ts +1 -0
- package/lib/tests/offer-claim-regressions.test.js +367 -0
- package/lib/tests/offers-helpers.test.js +24 -4
- package/lib/tests/offers-matrix.test.js +248 -20
- package/lib/tests/ref-exclusion-matching.test.d.ts +1 -0
- package/lib/tests/ref-exclusion-matching.test.js +168 -0
- package/lib/tests/wallet-cashback-helpers.test.d.ts +1 -0
- package/lib/tests/wallet-cashback-helpers.test.js +108 -0
- package/package.json +1 -1
|
@@ -23,6 +23,7 @@ exports.formattedStoreName = formattedStoreName;
|
|
|
23
23
|
exports.getPercentage = getPercentage;
|
|
24
24
|
exports.getPercentageAmount = getPercentageAmount;
|
|
25
25
|
exports.getCappedOfferDiscountAmount = getCappedOfferDiscountAmount;
|
|
26
|
+
exports.doesOrderItemMatchRefs = doesOrderItemMatchRefs;
|
|
26
27
|
exports.calculateEligibleOfferDiscountDetails = calculateEligibleOfferDiscountDetails;
|
|
27
28
|
const constants_1 = require("../../constants");
|
|
28
29
|
const price_conversion_1 = require("./price-conversion");
|
|
@@ -321,11 +322,28 @@ function getCappedOfferDiscountAmount({ baseAmount, discountValue, isDiscountPer
|
|
|
321
322
|
}
|
|
322
323
|
return Math.min(amount, normalizedBaseAmount);
|
|
323
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Does this order line match any of the given refs?
|
|
327
|
+
*
|
|
328
|
+
* A ref is an **item-level** id: an item id, and - because a SPECIAL or
|
|
329
|
+
* HALF_HALF order line stores its own document id in `item_id` - a special or
|
|
330
|
+
* half-half id too. Modifier/option refs never appear here: those belong to the
|
|
331
|
+
* reward's "Hide Options" / "Discount Not Applicable" lists, which act on the
|
|
332
|
+
* modifier tree at selection time, not on spend qualification.
|
|
333
|
+
*/
|
|
334
|
+
function doesOrderItemMatchRefs(item, refs) {
|
|
335
|
+
if (refs.length === 0)
|
|
336
|
+
return false;
|
|
337
|
+
return item.item_id != null && refs.includes(item.item_id);
|
|
338
|
+
}
|
|
324
339
|
/**
|
|
325
340
|
* Calculate the eligible subtotal by excluding items/categories in excluded_refs.
|
|
326
341
|
*
|
|
327
342
|
* Shared by the cart engine (discount application/re-sync) and the offer-stats
|
|
328
343
|
* engine (spend qualification) so both use the exact same exclusion math.
|
|
344
|
+
*
|
|
345
|
+
* A ref matches a whole category (`category_id`) or an item - where "item" means
|
|
346
|
+
* the item id, one of its modifier refs, or one of its option refs.
|
|
329
347
|
*/
|
|
330
348
|
function calculateEligibleOfferDiscountDetails(categories, excluded_refs) {
|
|
331
349
|
if (!categories?.length)
|
|
@@ -340,7 +358,7 @@ function calculateEligibleOfferDiscountDetails(categories, excluded_refs) {
|
|
|
340
358
|
}
|
|
341
359
|
// Otherwise, check each item
|
|
342
360
|
for (const item of category.items ?? []) {
|
|
343
|
-
if (
|
|
361
|
+
if (doesOrderItemMatchRefs(item, excluded_refs)) {
|
|
344
362
|
hasExcludedRefs = true;
|
|
345
363
|
}
|
|
346
364
|
else {
|
|
@@ -97,12 +97,14 @@ function buildOfferDiscountUpdate({ offer, orderDiscountDetails, categories, })
|
|
|
97
97
|
if (excluded_refs != null && excluded_refs.length > 0) {
|
|
98
98
|
const { subtotal: eligibleSubtotal, hasExcludedRefs } = (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
|
|
99
99
|
if (hasExcludedRefs) {
|
|
100
|
-
if (!is_discount_percentage) {
|
|
101
|
-
return { success: false, discountDetails: null, errorMessage: null };
|
|
102
|
-
}
|
|
103
100
|
if (eligibleSubtotal <= 0) {
|
|
104
101
|
return { success: false, discountDetails: null, errorMessage: null };
|
|
105
102
|
}
|
|
103
|
+
// Both shapes resolve against the eligible subtotal. A fixed amount used to
|
|
104
|
+
// bail out here while the eligibility engine still reported the offer as
|
|
105
|
+
// claimable, so the claim button always failed with a generic error. Capping
|
|
106
|
+
// is the same contract the gift-card path already uses: a discount may never
|
|
107
|
+
// exceed the amount it is allowed to discount.
|
|
106
108
|
discount_value = (0, common_1.parseNum)((0, common_1.getCappedOfferDiscountAmount)({
|
|
107
109
|
baseAmount: eligibleSubtotal,
|
|
108
110
|
discountValue: discount_value,
|
|
@@ -100,15 +100,26 @@ export declare const getTotalSelectedOfferItemsAgainstOffer: (categories: IOrder
|
|
|
100
100
|
*/
|
|
101
101
|
export declare function getOfferRewardApplicableQuantity(offer: IOffer): number | null;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* True when an offer's pathway and reward both draw on the same wallet resource
|
|
104
|
+
* (points to earn points, a voucher to earn a voucher). The admin blocks both
|
|
105
|
+
* cells, so they are only reachable through legacy or externally written rows;
|
|
106
|
+
* the engine refuses them rather than counting the resource twice.
|
|
107
|
+
*
|
|
108
|
+
* Deliberately a function rather than an inline test: it keeps the runtime guard
|
|
109
|
+
* without letting the compiler narrow the offer union (which would mark the
|
|
110
|
+
* remaining reward branches as unreachable).
|
|
111
|
+
*/
|
|
112
|
+
export declare function isOfferPathwayAndRewardSharingResource(offer: Partial<IOffer>): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Claims of `offer` evidenced by the stamped cart items.
|
|
104
115
|
*
|
|
105
116
|
* ITEMS / DISCOUNT_ITEMS rewards are claimed by selecting items, and the
|
|
106
117
|
* selection is persisted on each item's `item_discount_details`. That entry is
|
|
107
118
|
* folded into `redeemed_offers` later, by the cart reconcile — which itself runs
|
|
108
119
|
* only after the cart has already been evaluated. Eligibility that reads ONLY
|
|
109
|
-
* `redeemed_offers`
|
|
110
|
-
*
|
|
111
|
-
*
|
|
120
|
+
* `redeemed_offers` misses the claim for exactly one cycle, and because
|
|
121
|
+
* `calculateCustomerLoyaltyPoints` does count the cart-item evidence, the points
|
|
122
|
+
* spent by the claim would be deducted and never credited back. The offer then
|
|
112
123
|
* reads unaffordable, `unlockedOffersApplicableTimes` drops to 0 and the cart
|
|
113
124
|
* reconcile strips the reward item that granted it.
|
|
114
125
|
*
|
|
@@ -12,6 +12,7 @@ exports.calculateCustomerSpendableVoucherCodes = calculateCustomerSpendableVouch
|
|
|
12
12
|
exports.calculateCustomerSpendableGiftCardCodes = calculateCustomerSpendableGiftCardCodes;
|
|
13
13
|
exports.calculateCustomerLoyaltyPoints = calculateCustomerLoyaltyPoints;
|
|
14
14
|
exports.getOfferRewardApplicableQuantity = getOfferRewardApplicableQuantity;
|
|
15
|
+
exports.isOfferPathwayAndRewardSharingResource = isOfferPathwayAndRewardSharingResource;
|
|
15
16
|
exports.getOfferItemEvidenceClaims = getOfferItemEvidenceClaims;
|
|
16
17
|
exports.getRedeemedOffersFromAppliedState = getRedeemedOffersFromAppliedState;
|
|
17
18
|
exports.getOfferUsageLimitMeta = getOfferUsageLimitMeta;
|
|
@@ -250,9 +251,15 @@ function calculatePointsRedeemedForOffer(redeemedOffer, totalOrderPrice, categor
|
|
|
250
251
|
}
|
|
251
252
|
let times = 1;
|
|
252
253
|
if (!redeemedOffer.reward_points.once_per_order) {
|
|
254
|
+
// A spend threshold chunks the reward: one claim per "threshold" of spend.
|
|
255
|
+
// No threshold (`0` / null) means the offer simply has no minimum spend - it
|
|
256
|
+
// must NOT be read as "one claim per currency unit", which would multiply the
|
|
257
|
+
// reward by the cart total.
|
|
253
258
|
const getUnlockTimesByOrderAmount = (orderValue, totalAmount) => {
|
|
254
|
-
const
|
|
255
|
-
|
|
259
|
+
const requiredAmount = Number(totalAmount);
|
|
260
|
+
if (!Number.isFinite(requiredAmount) || requiredAmount <= 0)
|
|
261
|
+
return 1;
|
|
262
|
+
return Math.max(1, Math.floor(orderValue / requiredAmount));
|
|
256
263
|
};
|
|
257
264
|
// This means that we need to see if the condition to unlock the redeemedOffer is met multiple times
|
|
258
265
|
// i.e. if the customer has ordered 2 pizzas, and the redeemedOffer is applicable for 1 pizza
|
|
@@ -273,7 +280,7 @@ function calculatePointsRedeemedForOffer(redeemedOffer, totalOrderPrice, categor
|
|
|
273
280
|
if (bachelorItems >= num_of_items) {
|
|
274
281
|
if (totalOrderPrice >= total_amount) {
|
|
275
282
|
const timesForItems = Math.floor(bachelorItems / (num_of_items || 1));
|
|
276
|
-
const timesForAmount =
|
|
283
|
+
const timesForAmount = getUnlockTimesByOrderAmount(totalOrderPrice, total_amount);
|
|
277
284
|
// we need to find the minimum of the two
|
|
278
285
|
const minTimes = Math.min(timesForItems, timesForAmount);
|
|
279
286
|
const maxClaims = max_claims == null ? Infinity : Math.max(1, max_claims);
|
|
@@ -841,9 +848,11 @@ function hasEligibleItemsForDiscount(categories, excluded_refs) {
|
|
|
841
848
|
if (excluded_refs.includes(category.category_id)) {
|
|
842
849
|
continue;
|
|
843
850
|
}
|
|
844
|
-
//
|
|
851
|
+
// Item-level only: these lists hold item ids, and an excluded category is
|
|
852
|
+
// skipped above. Modifier/option refs belong to the reward's "Hide Options" /
|
|
853
|
+
// "Discount Not Applicable" lists and never reach this gate.
|
|
845
854
|
for (const item of category.items ?? []) {
|
|
846
|
-
if (!
|
|
855
|
+
if (!(0, common_1.doesOrderItemMatchRefs)(item, excluded_refs)) {
|
|
847
856
|
return true; // Found at least one eligible item
|
|
848
857
|
}
|
|
849
858
|
}
|
|
@@ -885,15 +894,31 @@ function getOfferRewardApplicableQuantity(offer) {
|
|
|
885
894
|
}
|
|
886
895
|
// ====================================================================================================================
|
|
887
896
|
/**
|
|
888
|
-
*
|
|
897
|
+
* True when an offer's pathway and reward both draw on the same wallet resource
|
|
898
|
+
* (points to earn points, a voucher to earn a voucher). The admin blocks both
|
|
899
|
+
* cells, so they are only reachable through legacy or externally written rows;
|
|
900
|
+
* the engine refuses them rather than counting the resource twice.
|
|
901
|
+
*
|
|
902
|
+
* Deliberately a function rather than an inline test: it keeps the runtime guard
|
|
903
|
+
* without letting the compiler narrow the offer union (which would mark the
|
|
904
|
+
* remaining reward branches as unreachable).
|
|
905
|
+
*/
|
|
906
|
+
function isOfferPathwayAndRewardSharingResource(offer) {
|
|
907
|
+
return ((offer.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS &&
|
|
908
|
+
offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.POINTS) ||
|
|
909
|
+
(offer.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER &&
|
|
910
|
+
offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER));
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Claims of `offer` evidenced by the stamped cart items.
|
|
889
914
|
*
|
|
890
915
|
* ITEMS / DISCOUNT_ITEMS rewards are claimed by selecting items, and the
|
|
891
916
|
* selection is persisted on each item's `item_discount_details`. That entry is
|
|
892
917
|
* folded into `redeemed_offers` later, by the cart reconcile — which itself runs
|
|
893
918
|
* only after the cart has already been evaluated. Eligibility that reads ONLY
|
|
894
|
-
* `redeemed_offers`
|
|
895
|
-
*
|
|
896
|
-
*
|
|
919
|
+
* `redeemed_offers` misses the claim for exactly one cycle, and because
|
|
920
|
+
* `calculateCustomerLoyaltyPoints` does count the cart-item evidence, the points
|
|
921
|
+
* spent by the claim would be deducted and never credited back. The offer then
|
|
897
922
|
* reads unaffordable, `unlockedOffersApplicableTimes` drops to 0 and the cart
|
|
898
923
|
* reconcile strips the reward item that granted it.
|
|
899
924
|
*
|
|
@@ -1276,9 +1301,10 @@ function getOfferOrderValueExcludedRefs(offer) {
|
|
|
1276
1301
|
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT) {
|
|
1277
1302
|
return offer.reward_discount?.excluded_refs ?? [];
|
|
1278
1303
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1304
|
+
// DISCOUNT_ITEMS deliberately does NOT contribute here: its excluded_refs /
|
|
1305
|
+
// exclusive_refs are option-level lists (same as an ITEMS reward) that act on
|
|
1306
|
+
// the modifier tree at selection time. Which items are eligible is decided by
|
|
1307
|
+
// `item_ids`, not by the spend-qualification base.
|
|
1282
1308
|
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK) {
|
|
1283
1309
|
return offer.reward_cashback?.excluded_refs ?? [];
|
|
1284
1310
|
}
|
|
@@ -1949,9 +1975,14 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
1949
1975
|
const remainingBudget = getRemainingClaimBudgetForOffer(offerToCheck);
|
|
1950
1976
|
return remainingBudget == null ? perOrderClaims : Math.min(perOrderClaims, remainingBudget);
|
|
1951
1977
|
};
|
|
1978
|
+
// Same rule as getUnlockTimesByOrderAmount: a threshold chunks the reward, but
|
|
1979
|
+
// an absent threshold means "no minimum spend" = a single claim, never
|
|
1980
|
+
// `floor(orderValue / 1)` claims.
|
|
1952
1981
|
const getOrderValueClaimTimes = (orderValue, minAmount) => {
|
|
1953
|
-
const
|
|
1954
|
-
|
|
1982
|
+
const requiredAmount = Number(minAmount);
|
|
1983
|
+
if (!Number.isFinite(requiredAmount) || requiredAmount <= 0)
|
|
1984
|
+
return 1;
|
|
1985
|
+
return Math.max(1, Math.floor(orderValue / requiredAmount));
|
|
1955
1986
|
};
|
|
1956
1987
|
const getOrdersBetweenUnlocksStats = ({ totalOrders, ordersBetweenUnlocks, }) => {
|
|
1957
1988
|
const normalizedTotalOrders = Math.max(0, Math.floor(Number.isFinite(totalOrders) ? totalOrders : 0));
|
|
@@ -2067,6 +2098,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2067
2098
|
action_hint: null,
|
|
2068
2099
|
auto_apply: offer.auto_apply ?? false,
|
|
2069
2100
|
};
|
|
2101
|
+
if (isOfferPathwayAndRewardSharingResource(offer)) {
|
|
2102
|
+
stats.invalid_offer = true;
|
|
2103
|
+
stats.claimable = false;
|
|
2104
|
+
stats.message = `This offer is misconfigured: its pathway and reward use the same resource`;
|
|
2105
|
+
offersWithStats.push({ offer, stats });
|
|
2106
|
+
continue;
|
|
2107
|
+
}
|
|
2070
2108
|
if (offer.pathway_to_unlock_type === constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ORDERS) {
|
|
2071
2109
|
if (offer.pathway_to_unlock_type_orders == null) {
|
|
2072
2110
|
stats.invalid_offer = true;
|
|
@@ -2176,16 +2214,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2176
2214
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
|
|
2177
2215
|
if (offer.reward_discount_items == null)
|
|
2178
2216
|
continue;
|
|
2179
|
-
//
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
// All items are excluded, offer cannot be unlocked
|
|
2183
|
-
stats.progress = 0;
|
|
2184
|
-
stats.claimable = false;
|
|
2185
|
-
stats.message = `⛔️ No eligible items for this offer ⛔️`;
|
|
2186
|
-
offersWithStats.push({ offer, stats });
|
|
2187
|
-
continue;
|
|
2188
|
-
}
|
|
2217
|
+
// No "all items excluded" gate here: DISCOUNT_ITEMS acts on the modifier
|
|
2218
|
+
// tree (excluded_refs / exclusive_refs), and item eligibility is driven by
|
|
2219
|
+
// item_ids, not by an item-level exclusion list.
|
|
2189
2220
|
const applicableQuantity = offer.reward_discount_items.num_of_items || 1;
|
|
2190
2221
|
const totalOfferItemsSelected = (0, exports.getTotalSelectedOfferItemsAgainstOffer)(categories, offer._id);
|
|
2191
2222
|
const redeemedTimes = getItemRewardRedeemedTimes({
|
|
@@ -2482,14 +2513,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2482
2513
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
|
|
2483
2514
|
if (offer.reward_discount_items == null)
|
|
2484
2515
|
continue;
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
stats.claimable = false;
|
|
2489
|
-
stats.message = `⛔️ No eligible items for this offer ⛔️`;
|
|
2490
|
-
offersWithStats.push({ offer, stats });
|
|
2491
|
-
continue;
|
|
2492
|
-
}
|
|
2516
|
+
// No "all items excluded" gate here: DISCOUNT_ITEMS acts on the modifier
|
|
2517
|
+
// tree (excluded_refs / exclusive_refs), and item eligibility is driven by
|
|
2518
|
+
// item_ids, not by an item-level exclusion list.
|
|
2493
2519
|
const applicableQuantity = offer.reward_discount_items.num_of_items || 1;
|
|
2494
2520
|
const redeemedTimes = getItemRewardRedeemedTimes({
|
|
2495
2521
|
totalOfferItemsSelected,
|
|
@@ -2727,14 +2753,10 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2727
2753
|
const combinedProgress = Math.min(pointsProgress, amountProgress);
|
|
2728
2754
|
if (effectiveLoyaltyPointsForCurrentOffer >= num_of_points) {
|
|
2729
2755
|
if (orderValue >= total_amount) {
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
else {
|
|
2735
|
-
stats.progress = combinedProgress;
|
|
2736
|
-
stats.message = `You are ${(num_of_points - effectiveLoyaltyPointsForCurrentOffer).toFixed(0)} points away from unlocking this offer`;
|
|
2737
|
-
}
|
|
2756
|
+
// The points axis is already satisfied by the outer condition; only the
|
|
2757
|
+
// spend axis was in question here.
|
|
2758
|
+
stats.progress = 100;
|
|
2759
|
+
stats.message = `🎉 You have unlocked this offer 🎉`;
|
|
2738
2760
|
}
|
|
2739
2761
|
else {
|
|
2740
2762
|
stats.progress = combinedProgress;
|
|
@@ -2746,7 +2768,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2746
2768
|
stats.message = `You are ${(num_of_points - effectiveLoyaltyPointsForCurrentOffer).toFixed(0)} points away from unlocking this offer`;
|
|
2747
2769
|
}
|
|
2748
2770
|
if (stats.progress >= 100) {
|
|
2749
|
-
|
|
2771
|
+
// A reward that costs zero points is free - it must not burn the whole
|
|
2772
|
+
// balance into claims (same rule as a zero spend threshold).
|
|
2773
|
+
const pointBurnTimes = num_of_points > 0 ? Math.floor(effectiveLoyaltyPointsForCurrentOffer / num_of_points) : 1;
|
|
2750
2774
|
const amountTimes = total_amount != null && total_amount > 0 ? Math.floor(orderValue / total_amount) : pointBurnTimes;
|
|
2751
2775
|
const totalUnlockableClaims = clampClaimsToRemainingClaimBudget(offer, Math.min(pointBurnTimes, amountTimes, maxClaimsPerOrder));
|
|
2752
2776
|
if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT) {
|
|
@@ -2781,14 +2805,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
2781
2805
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
|
|
2782
2806
|
if (offer.reward_discount_items == null)
|
|
2783
2807
|
continue;
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
stats.claimable = false;
|
|
2788
|
-
stats.message = `⛔️ No eligible items for this offer ⛔️`;
|
|
2789
|
-
offersWithStats.push({ offer, stats });
|
|
2790
|
-
continue;
|
|
2791
|
-
}
|
|
2808
|
+
// No "all items excluded" gate here: DISCOUNT_ITEMS acts on the modifier
|
|
2809
|
+
// tree (excluded_refs / exclusive_refs), and item eligibility is driven by
|
|
2810
|
+
// item_ids, not by an item-level exclusion list.
|
|
2792
2811
|
const totalOfferItemsSelected = (0, exports.getTotalSelectedOfferItemsAgainstOffer)(categories, offer._id);
|
|
2793
2812
|
const applicableQuantity = offer.reward_discount_items.num_of_items || 1;
|
|
2794
2813
|
const redeemedTimes = getItemRewardRedeemedTimes({
|
|
@@ -3028,6 +3047,14 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3028
3047
|
firstReferencedVoucherWithWalletInventory ??
|
|
3029
3048
|
singleReferencedVoucherForRedeemedClaim ??
|
|
3030
3049
|
null;
|
|
3050
|
+
// Distinguish "the customer has not entered a code" from "this offer's
|
|
3051
|
+
// voucher cannot be used at all". When the tenant configured voucher ids
|
|
3052
|
+
// but none resolves to a usable voucher (inactive, expired, used up, or
|
|
3053
|
+
// deleted), telling the customer to "enter a matching voucher code" is a
|
|
3054
|
+
// dead end - they may already hold the code.
|
|
3055
|
+
const hasUnavailableReferencedVoucher = referencedVouchers.length === 0 &&
|
|
3056
|
+
voucher_ids.length > 0 &&
|
|
3057
|
+
voucher_ids.every((voucherId) => !vouchersById.has(voucherId));
|
|
3031
3058
|
const hasMatchingVoucher = matchingVoucherContext != null;
|
|
3032
3059
|
const normalizedMatchedVoucherCode = matchingVoucherContext != null ? getVoucherCode(matchingVoucherContext) : null;
|
|
3033
3060
|
const spendableVoucherCount = normalizedMatchedVoucherCode == null ? 0 : (spendableVoucherCodesByCode[normalizedMatchedVoucherCode] ?? 0);
|
|
@@ -3035,7 +3062,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3035
3062
|
const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount);
|
|
3036
3063
|
if (!hasMatchingVoucher) {
|
|
3037
3064
|
stats.progress = 0;
|
|
3038
|
-
stats.message =
|
|
3065
|
+
stats.message = hasUnavailableReferencedVoucher
|
|
3066
|
+
? `⛔️ This offer's voucher is no longer available ⛔️`
|
|
3067
|
+
: `Enter a matching voucher code to unlock this offer`;
|
|
3039
3068
|
}
|
|
3040
3069
|
else if (!hasVoucherAccess) {
|
|
3041
3070
|
stats.progress = 0;
|
|
@@ -3086,14 +3115,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3086
3115
|
else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
|
|
3087
3116
|
if (offer.reward_discount_items == null)
|
|
3088
3117
|
continue;
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
stats.claimable = false;
|
|
3093
|
-
stats.message = `⛔️ No eligible items for this offer ⛔️`;
|
|
3094
|
-
offersWithStats.push({ offer, stats });
|
|
3095
|
-
continue;
|
|
3096
|
-
}
|
|
3118
|
+
// No "all items excluded" gate here: DISCOUNT_ITEMS acts on the modifier
|
|
3119
|
+
// tree (excluded_refs / exclusive_refs), and item eligibility is driven by
|
|
3120
|
+
// item_ids, not by an item-level exclusion list.
|
|
3097
3121
|
const totalOfferItemsSelected = (0, exports.getTotalSelectedOfferItemsAgainstOffer)(categories, offer._id);
|
|
3098
3122
|
const applicableQuantity = offer.reward_discount_items.num_of_items || 1;
|
|
3099
3123
|
const redeemedTimes = getItemRewardRedeemedTimes({
|
|
@@ -3101,7 +3125,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3101
3125
|
applicableQuantity,
|
|
3102
3126
|
});
|
|
3103
3127
|
const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
|
|
3104
|
-
|
|
3128
|
+
// No spend threshold on a voucher pathway means "no minimum spend", so the
|
|
3129
|
+
// vouchers held - not a spend chunk count - decide how many claims fit.
|
|
3130
|
+
const unlockTimesForAmount = total_amount > 0 ? getOrderValueClaimTimes(orderValue, total_amount) : Infinity;
|
|
3105
3131
|
const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
|
|
3106
3132
|
const totalUnlockableClaims = clampClaimsToRemainingClaimBudget(offer, Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap));
|
|
3107
3133
|
const isClaimable = redeemedTimes < totalUnlockableClaims;
|
|
@@ -3122,7 +3148,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3122
3148
|
continue;
|
|
3123
3149
|
const redeemedTimes = getOfferRedeemedTimes(offer._id);
|
|
3124
3150
|
const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
|
|
3125
|
-
|
|
3151
|
+
// No spend threshold on a voucher pathway means "no minimum spend", so the
|
|
3152
|
+
// vouchers held - not a spend chunk count - decide how many claims fit.
|
|
3153
|
+
const unlockTimesForAmount = total_amount > 0 ? getOrderValueClaimTimes(orderValue, total_amount) : Infinity;
|
|
3126
3154
|
const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
|
|
3127
3155
|
const totalUnlockableClaims = clampClaimsToRemainingClaimBudget(offer, Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap));
|
|
3128
3156
|
const maxRedeemableClaims = getPointsMaxRedeemableClaims({
|
|
@@ -3198,7 +3226,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3198
3226
|
// (every total_amount unlocks one claim), capped by max_claims
|
|
3199
3227
|
// and the voucher inventory available for this order.
|
|
3200
3228
|
const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
|
|
3201
|
-
const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
|
|
3229
|
+
const unlockTimesForAmount = total_amount > 0 ? getOrderValueClaimTimes(orderValue, total_amount) : Infinity;
|
|
3202
3230
|
const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
|
|
3203
3231
|
const totalUnlockableClaims = clampClaimsToRemainingClaimBudget(offer, Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap));
|
|
3204
3232
|
const maxRedeemableClaims = getPathwayMaxRedeemableClaims(totalUnlockableClaims);
|
|
@@ -3250,7 +3278,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3250
3278
|
applicableQuantity,
|
|
3251
3279
|
});
|
|
3252
3280
|
const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
|
|
3253
|
-
|
|
3281
|
+
// No spend threshold on a voucher pathway means "no minimum spend", so the
|
|
3282
|
+
// vouchers held - not a spend chunk count - decide how many claims fit.
|
|
3283
|
+
const unlockTimesForAmount = total_amount > 0 ? getOrderValueClaimTimes(orderValue, total_amount) : Infinity;
|
|
3254
3284
|
const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
|
|
3255
3285
|
const totalUnlockableClaims = clampClaimsToRemainingClaimBudget(offer, Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap));
|
|
3256
3286
|
const isClaimable = redeemedTimes < totalUnlockableClaims;
|
|
@@ -7,12 +7,12 @@ export declare const ExpenseCategorySchema: Schema<any, import("mongoose").Model
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
description: string;
|
|
10
11
|
_id: import("mongoose").Types.ObjectId;
|
|
11
12
|
name: string;
|
|
12
13
|
createdAt: NativeDate;
|
|
13
14
|
updatedAt: NativeDate;
|
|
14
15
|
sort_id: number;
|
|
15
|
-
description: string;
|
|
16
16
|
tenant_id: string;
|
|
17
17
|
sub_categories: import("mongoose").Types.DocumentArray<{
|
|
18
18
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -31,12 +31,12 @@ export declare const ExpenseCategorySchema: Schema<any, import("mongoose").Model
|
|
|
31
31
|
createdAt: NativeDate;
|
|
32
32
|
updatedAt: NativeDate;
|
|
33
33
|
} & {
|
|
34
|
+
description: string;
|
|
34
35
|
_id: import("mongoose").Types.ObjectId;
|
|
35
36
|
name: string;
|
|
36
37
|
createdAt: NativeDate;
|
|
37
38
|
updatedAt: NativeDate;
|
|
38
39
|
sort_id: number;
|
|
39
|
-
description: string;
|
|
40
40
|
tenant_id: string;
|
|
41
41
|
sub_categories: import("mongoose").Types.DocumentArray<{
|
|
42
42
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -55,12 +55,12 @@ export declare const ExpenseCategorySchema: Schema<any, import("mongoose").Model
|
|
|
55
55
|
createdAt: NativeDate;
|
|
56
56
|
updatedAt: NativeDate;
|
|
57
57
|
} & {
|
|
58
|
+
description: string;
|
|
58
59
|
_id: import("mongoose").Types.ObjectId;
|
|
59
60
|
name: string;
|
|
60
61
|
createdAt: NativeDate;
|
|
61
62
|
updatedAt: NativeDate;
|
|
62
63
|
sort_id: number;
|
|
63
|
-
description: string;
|
|
64
64
|
tenant_id: string;
|
|
65
65
|
sub_categories: import("mongoose").Types.DocumentArray<{
|
|
66
66
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -7,10 +7,10 @@ export declare const ExpenseDetailsSchema: Schema<any, import("mongoose").Model<
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
description: string;
|
|
10
11
|
_id: import("mongoose").Types.ObjectId;
|
|
11
12
|
createdAt: NativeDate;
|
|
12
13
|
updatedAt: NativeDate;
|
|
13
|
-
description: string;
|
|
14
14
|
tenant_id: string;
|
|
15
15
|
createdAt_mins: number;
|
|
16
16
|
amount: number;
|
|
@@ -31,10 +31,10 @@ export declare const ExpenseDetailsSchema: Schema<any, import("mongoose").Model<
|
|
|
31
31
|
createdAt: NativeDate;
|
|
32
32
|
updatedAt: NativeDate;
|
|
33
33
|
} & {
|
|
34
|
+
description: string;
|
|
34
35
|
_id: import("mongoose").Types.ObjectId;
|
|
35
36
|
createdAt: NativeDate;
|
|
36
37
|
updatedAt: NativeDate;
|
|
37
|
-
description: string;
|
|
38
38
|
tenant_id: string;
|
|
39
39
|
createdAt_mins: number;
|
|
40
40
|
amount: number;
|
|
@@ -55,10 +55,10 @@ export declare const ExpenseDetailsSchema: Schema<any, import("mongoose").Model<
|
|
|
55
55
|
createdAt: NativeDate;
|
|
56
56
|
updatedAt: NativeDate;
|
|
57
57
|
} & {
|
|
58
|
+
description: string;
|
|
58
59
|
_id: import("mongoose").Types.ObjectId;
|
|
59
60
|
createdAt: NativeDate;
|
|
60
61
|
updatedAt: NativeDate;
|
|
61
|
-
description: string;
|
|
62
62
|
tenant_id: string;
|
|
63
63
|
createdAt_mins: number;
|
|
64
64
|
amount: number;
|
|
@@ -8,6 +8,7 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
|
|
|
8
8
|
createdAt: NativeDate;
|
|
9
9
|
updatedAt: NativeDate;
|
|
10
10
|
} & {
|
|
11
|
+
description: string;
|
|
11
12
|
code: string;
|
|
12
13
|
_id: import("mongoose").Types.ObjectId;
|
|
13
14
|
name: string;
|
|
@@ -16,7 +17,6 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
|
|
|
16
17
|
brand_id: string;
|
|
17
18
|
tenants: string[];
|
|
18
19
|
active: boolean;
|
|
19
|
-
description: string;
|
|
20
20
|
reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
|
|
21
21
|
used_count: number;
|
|
22
22
|
assigned_count: number;
|
|
@@ -142,6 +142,7 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
|
|
|
142
142
|
createdAt: NativeDate;
|
|
143
143
|
updatedAt: NativeDate;
|
|
144
144
|
} & {
|
|
145
|
+
description: string;
|
|
145
146
|
code: string;
|
|
146
147
|
_id: import("mongoose").Types.ObjectId;
|
|
147
148
|
name: string;
|
|
@@ -150,7 +151,6 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
|
|
|
150
151
|
brand_id: string;
|
|
151
152
|
tenants: string[];
|
|
152
153
|
active: boolean;
|
|
153
|
-
description: string;
|
|
154
154
|
reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
|
|
155
155
|
used_count: number;
|
|
156
156
|
assigned_count: number;
|
|
@@ -276,6 +276,7 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
|
|
|
276
276
|
createdAt: NativeDate;
|
|
277
277
|
updatedAt: NativeDate;
|
|
278
278
|
} & {
|
|
279
|
+
description: string;
|
|
279
280
|
code: string;
|
|
280
281
|
_id: import("mongoose").Types.ObjectId;
|
|
281
282
|
name: string;
|
|
@@ -284,7 +285,6 @@ export declare const GiftCardsSchema: Schema<any, import("mongoose").Model<any,
|
|
|
284
285
|
brand_id: string;
|
|
285
286
|
tenants: string[];
|
|
286
287
|
active: boolean;
|
|
287
|
-
description: string;
|
|
288
288
|
reward_type: GIFT_CARD_REWARD_TYPE_ENUM;
|
|
289
289
|
used_count: number;
|
|
290
290
|
assigned_count: number;
|
|
@@ -26,6 +26,7 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
26
26
|
createdAt: NativeDate;
|
|
27
27
|
updatedAt: NativeDate;
|
|
28
28
|
} & {
|
|
29
|
+
description: string;
|
|
29
30
|
_id: import("mongoose").Types.ObjectId;
|
|
30
31
|
name: string;
|
|
31
32
|
image_url: string;
|
|
@@ -175,7 +176,6 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
175
176
|
BASE_PRICE: number;
|
|
176
177
|
};
|
|
177
178
|
}>;
|
|
178
|
-
description: string;
|
|
179
179
|
discount_amount: {
|
|
180
180
|
"POS_WALK-IN": number;
|
|
181
181
|
"POS_TAKE-AWAY": number;
|
|
@@ -571,6 +571,7 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
571
571
|
createdAt: NativeDate;
|
|
572
572
|
updatedAt: NativeDate;
|
|
573
573
|
} & {
|
|
574
|
+
description: string;
|
|
574
575
|
_id: import("mongoose").Types.ObjectId;
|
|
575
576
|
name: string;
|
|
576
577
|
image_url: string;
|
|
@@ -720,7 +721,6 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
720
721
|
BASE_PRICE: number;
|
|
721
722
|
};
|
|
722
723
|
}>;
|
|
723
|
-
description: string;
|
|
724
724
|
discount_amount: {
|
|
725
725
|
"POS_WALK-IN": number;
|
|
726
726
|
"POS_TAKE-AWAY": number;
|
|
@@ -1116,6 +1116,7 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
1116
1116
|
createdAt: NativeDate;
|
|
1117
1117
|
updatedAt: NativeDate;
|
|
1118
1118
|
} & {
|
|
1119
|
+
description: string;
|
|
1119
1120
|
_id: import("mongoose").Types.ObjectId;
|
|
1120
1121
|
name: string;
|
|
1121
1122
|
image_url: string;
|
|
@@ -1265,7 +1266,6 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
1265
1266
|
BASE_PRICE: number;
|
|
1266
1267
|
};
|
|
1267
1268
|
}>;
|
|
1268
|
-
description: string;
|
|
1269
1269
|
discount_amount: {
|
|
1270
1270
|
"POS_WALK-IN": number;
|
|
1271
1271
|
"POS_TAKE-AWAY": number;
|
|
@@ -7,10 +7,10 @@ export declare const InternalInvoiceSchema: Schema<any, import("mongoose").Model
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
description: string;
|
|
10
11
|
_id: import("mongoose").Types.ObjectId;
|
|
11
12
|
createdAt: NativeDate;
|
|
12
13
|
updatedAt: NativeDate;
|
|
13
|
-
description: string;
|
|
14
14
|
discount_amount: number;
|
|
15
15
|
ref_id: string;
|
|
16
16
|
customer_name: string;
|
|
@@ -35,10 +35,10 @@ export declare const InternalInvoiceSchema: Schema<any, import("mongoose").Model
|
|
|
35
35
|
createdAt: NativeDate;
|
|
36
36
|
updatedAt: NativeDate;
|
|
37
37
|
} & {
|
|
38
|
+
description: string;
|
|
38
39
|
_id: import("mongoose").Types.ObjectId;
|
|
39
40
|
createdAt: NativeDate;
|
|
40
41
|
updatedAt: NativeDate;
|
|
41
|
-
description: string;
|
|
42
42
|
discount_amount: number;
|
|
43
43
|
ref_id: string;
|
|
44
44
|
customer_name: string;
|
|
@@ -63,10 +63,10 @@ export declare const InternalInvoiceSchema: Schema<any, import("mongoose").Model
|
|
|
63
63
|
createdAt: NativeDate;
|
|
64
64
|
updatedAt: NativeDate;
|
|
65
65
|
} & {
|
|
66
|
+
description: string;
|
|
66
67
|
_id: import("mongoose").Types.ObjectId;
|
|
67
68
|
createdAt: NativeDate;
|
|
68
69
|
updatedAt: NativeDate;
|
|
69
|
-
description: string;
|
|
70
70
|
discount_amount: number;
|
|
71
71
|
ref_id: string;
|
|
72
72
|
customer_name: string;
|