@managesome/eposmatic-toolkit 0.2.755 → 0.2.757

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.
@@ -290,3 +290,10 @@ export declare enum WAREHOUSE_CLIENT_TYPE_ENUM {
290
290
  WAREHOUSE = "WAREHOUSE"
291
291
  }
292
292
  export declare const ALL_WAREHOUSE_CLIENT_TYPE_NAMES: WAREHOUSE_CLIENT_TYPE_ENUM[];
293
+ export declare enum VENDOR_TYPE_ENUM {
294
+ EXTERNAL = "EXTERNAL",
295
+ EXTERNAL_WAREHOUSE = "EXTERNAL_WAREHOUSE",
296
+ TENANT = "TENANT",
297
+ WAREHOUSE = "WAREHOUSE"
298
+ }
299
+ export declare const ALL_VENDOR_TYPE_NAMES: VENDOR_TYPE_ENUM[];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ALL_WAREHOUSE_INTERNAL_MOVEMENT_LOCATION_TYPE_NAMES = exports.WAREHOUSE_INTERNAL_MOVEMENT_LOCATION_TYPE_ENUM = exports.ALL_WAREHOUSE_INTERNAL_MOVEMENT_FLOW_NAMES = exports.WAREHOUSE_INTERNAL_MOVEMENT_FLOW_ENUM = exports.ALL_WAREHOUSE_INTERNAL_MOVEMENT_EDIT_REQUEST_STATUS_NAMES = exports.ALL_WAREHOUSE_INVENTORY_LOT_SERIAL_MUTATION_ACTION_NAMES = exports.WAREHOUSE_INVENTORY_LOT_SERIAL_MUTATION_ACTION_ENUM = exports.ALL_WAREHOUSE_INVENTORY_LOT_SERIAL_MOVEMENT_TYPE_NAMES = exports.WAREHOUSE_INVENTORY_LOT_SERIAL_MOVEMENT_TYPE_ENUM = exports.WAREHOUSE_INTERNAL_MOVEMENT_EDIT_REQUEST_STATUS_ENUM = exports.ALL_WAREHOUSE_INTERNAL_MOVEMENT_STATUS_NAMES = exports.WAREHOUSE_INTERNAL_MOVEMENT_STATUS_ENUM = exports.ALL_WAREHOUSE_INTERNAL_MOVEMENT_RECORD_TYPE_NAMES = exports.WAREHOUSE_INTERNAL_MOVEMENT_RECORD_TYPE_ENUM = exports.ALL_WAREHOUSE_REF_TYPE_NAMES = exports.WAREHOUSE_REF_TYPE_ENUM = exports.ALL_WAREHOUSE_SALE_ORDER_DELIVERY_RETURN_STATUS_NAMES = exports.WAREHOUSE_SALE_ORDER_DELIVERY_RETURN_STATUS_ENUM = exports.ALL_WAREHOUSE_SALE_ORDER_DELIVERY_STATUS_NAMES = exports.WAREHOUSE_SALE_ORDER_DELIVERY_STATUS_ENUM = exports.ALL_WAREHOUSE_SALE_ORDER_PHYSICAL_DOC_KIND_NAMES = exports.WAREHOUSE_SALE_ORDER_PHYSICAL_DOC_KIND_ENUM = exports.ALL_WAREHOUSE_SALE_ORDER_CREDIT_NOTE_STATUS_NAMES = exports.WAREHOUSE_SALE_ORDER_CREDIT_NOTE_STATUS_ENUM = exports.ALL_WAREHOUSE_SALE_ORDER_INVOICE_PAYMENT_STATUS_NAMES = exports.WAREHOUSE_SALE_ORDER_INVOICE_PAYMENT_STATUS_ENUM = exports.ALL_WAREHOUSE_SALE_ORDER_INVOICE_TYPE_NAMES = exports.WAREHOUSE_SALE_ORDER_INVOICE_TYPE_ENUM = exports.ALL_WAREHOUSE_SALE_ORDER_FIN_DOC_KIND_NAMES = exports.WAREHOUSE_SALE_ORDER_FIN_DOC_KIND_ENUM = exports.ALL_WAREHOUSE_SALES_ORDER_STATUS_NAMES = exports.WAREHOUSE_SALES_ORDER_STATUS_ENUM = exports.ALL_WAREHOUSE_SALE_ORDER_RFQ_STATUS_NAMES = exports.WAREHOUSE_SALE_ORDER_RFQ_STATUS_ENUM = exports.ALL_WAREHOUSE_RFQ_VENDOR_STATUS_NAMES = exports.WAREHOUSE_PURCHASE_ORDER_RFQ_VENDOR_STATUS_ENUM = exports.ALL_WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_NAMES = exports.WAREHOUSE_PURCHASE_ORDER_RFQ_STATUS_ENUM = exports.ALL_WAREHOUSE_PURCHASE_ORDER_STATUS_NAMES = exports.WAREHOUSE_PURCHASE_ORDER_STATUS_ENUM = exports.ALL_VOID_WAREHOUSE_INVOICE_ITEM_TYPE_NAMES = exports.VOID_WAREHOUSE_INVOICE_ITEM_TYPE_ENUM = exports.ALL_WAREHOUSE_REMOVAL_STRATEGY_NAMES = exports.WAREHOUSE_REMOVAL_STRATEGY_ENUM = exports.ALL_WAREHOUSE_LOT_SERIAL_MOVEMENT_SOURCE_NAMES = exports.WAREHOUSE_LOT_SERIAL_MOVEMENT_SOURCE_ENUM = exports.ALL_WAREHOUSE_LOT_SERIAL_DOC_TYPE_NAMES = exports.WAREHOUSE_LOT_SERIAL_DOC_TYPE_ENUM = exports.ALL_WAREHOUSE_TRACKING_MODE_NAMES = exports.WAREHOUSE_TRACKING_MODE_ENUM = void 0;
4
- exports.ALL_WAREHOUSE_CLIENT_TYPE_NAMES = exports.WAREHOUSE_CLIENT_TYPE_ENUM = exports.ALL_WAREHOUSE_SUPPORT_SPECIALIST_PERMISSION_NAMES = exports.ALL_WAREHOUSE_MODERATOR_PERMISSION_NAMES = exports.ALL_WAREHOUSE_USER_PERMISSION_NAMES = exports.WAREHOUSE_USER_PERMISSIONS_ENUM = exports.ALL_WAREHOUSE_ACTIVITY_LOG_SEVERITY_NAMES = exports.WAREHOUSE_ACTIVITY_LOG_SEVERITY_ENUM = exports.ALL_WAREHOUSE_ACTIVITY_LOG_ACTION_NAMES = exports.WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM = exports.ALL_WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_NAMES = exports.WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM = exports.ALL_WAREHOUSE_PURCHASE_ORDER_VENDOR_RETURN_STATUS_NAMES = exports.WAREHOUSE_PURCHASE_ORDER_VENDOR_RETURN_STATUS_ENUM = exports.ALL_WAREHOUSE_PURCHASE_ORDER_RECEIPT_STATUS_NAMES = exports.WAREHOUSE_PURCHASE_ORDER_RECEIPT_STATUS_ENUM = exports.ALL_WAREHOUSE_INTERNAL_MOVEMENT_DIRECTION_NAMES = exports.WAREHOUSE_INTERNAL_MOVEMENT_DIRECTION_ENUM = void 0;
4
+ exports.ALL_VENDOR_TYPE_NAMES = exports.VENDOR_TYPE_ENUM = exports.ALL_WAREHOUSE_CLIENT_TYPE_NAMES = exports.WAREHOUSE_CLIENT_TYPE_ENUM = exports.ALL_WAREHOUSE_SUPPORT_SPECIALIST_PERMISSION_NAMES = exports.ALL_WAREHOUSE_MODERATOR_PERMISSION_NAMES = exports.ALL_WAREHOUSE_USER_PERMISSION_NAMES = exports.WAREHOUSE_USER_PERMISSIONS_ENUM = exports.ALL_WAREHOUSE_ACTIVITY_LOG_SEVERITY_NAMES = exports.WAREHOUSE_ACTIVITY_LOG_SEVERITY_ENUM = exports.ALL_WAREHOUSE_ACTIVITY_LOG_ACTION_NAMES = exports.WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM = exports.ALL_WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_NAMES = exports.WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM = exports.ALL_WAREHOUSE_PURCHASE_ORDER_VENDOR_RETURN_STATUS_NAMES = exports.WAREHOUSE_PURCHASE_ORDER_VENDOR_RETURN_STATUS_ENUM = exports.ALL_WAREHOUSE_PURCHASE_ORDER_RECEIPT_STATUS_NAMES = exports.WAREHOUSE_PURCHASE_ORDER_RECEIPT_STATUS_ENUM = exports.ALL_WAREHOUSE_INTERNAL_MOVEMENT_DIRECTION_NAMES = exports.WAREHOUSE_INTERNAL_MOVEMENT_DIRECTION_ENUM = void 0;
5
5
  // ======================>> <<====================== //
6
6
  var WAREHOUSE_TRACKING_MODE_ENUM;
7
7
  (function (WAREHOUSE_TRACKING_MODE_ENUM) {
@@ -394,3 +394,12 @@ var WAREHOUSE_CLIENT_TYPE_ENUM;
394
394
  WAREHOUSE_CLIENT_TYPE_ENUM["WAREHOUSE"] = "WAREHOUSE";
395
395
  })(WAREHOUSE_CLIENT_TYPE_ENUM || (exports.WAREHOUSE_CLIENT_TYPE_ENUM = WAREHOUSE_CLIENT_TYPE_ENUM = {}));
396
396
  exports.ALL_WAREHOUSE_CLIENT_TYPE_NAMES = Object.values(WAREHOUSE_CLIENT_TYPE_ENUM);
397
+ // ======================>> <<====================== //
398
+ var VENDOR_TYPE_ENUM;
399
+ (function (VENDOR_TYPE_ENUM) {
400
+ VENDOR_TYPE_ENUM["EXTERNAL"] = "EXTERNAL";
401
+ VENDOR_TYPE_ENUM["EXTERNAL_WAREHOUSE"] = "EXTERNAL_WAREHOUSE";
402
+ VENDOR_TYPE_ENUM["TENANT"] = "TENANT";
403
+ VENDOR_TYPE_ENUM["WAREHOUSE"] = "WAREHOUSE";
404
+ })(VENDOR_TYPE_ENUM || (exports.VENDOR_TYPE_ENUM = VENDOR_TYPE_ENUM = {}));
405
+ exports.ALL_VENDOR_TYPE_NAMES = Object.values(VENDOR_TYPE_ENUM);
@@ -230,11 +230,4 @@ export declare function getClearVoucherCodeAndOffersFromCartData(data: Partial<I
230
230
  * `order_discount_details`.
231
231
  */
232
232
  export declare function getResetRewardStateForNewCustomer(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
233
- /**
234
- * Calculate the eligible subtotal by excluding items/categories in excluded_refs
235
- */
236
- export declare function calculateEligibleOfferDiscountDetails(categories: IOrderCategory[] | undefined, excluded_refs: string[]): {
237
- subtotal: number;
238
- hasExcludedRefs: boolean;
239
- };
240
233
  export {};
@@ -31,7 +31,6 @@ exports.getRemoveOfferFromCartData = getRemoveOfferFromCartData;
31
31
  exports.getRemoveAllOffersFromCartData = getRemoveAllOffersFromCartData;
32
32
  exports.getClearVoucherCodeAndOffersFromCartData = getClearVoucherCodeAndOffersFromCartData;
33
33
  exports.getResetRewardStateForNewCustomer = getResetRewardStateForNewCustomer;
34
- exports.calculateEligibleOfferDiscountDetails = calculateEligibleOfferDiscountDetails;
35
34
  const bson_objectid_1 = __importDefault(require("bson-objectid"));
36
35
  const lodash_1 = require("lodash");
37
36
  const constants_1 = require("../../constants");
@@ -1025,7 +1024,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
1025
1024
  if (loyaltyOffer.reward_discount != null) {
1026
1025
  const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage, } = loyaltyOffer.reward_discount;
1027
1026
  const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
1028
- ? calculateEligibleOfferDiscountDetails(categories, excluded_refs)
1027
+ ? (0, utils_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
1029
1028
  : {
1030
1029
  subtotal: orderLevelDiscountBaseAmount,
1031
1030
  hasExcludedRefs: false,
@@ -1160,7 +1159,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
1160
1159
  if (voucherOffer?.reward_discount != null) {
1161
1160
  const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage, } = voucherOffer.reward_discount;
1162
1161
  const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
1163
- ? calculateEligibleOfferDiscountDetails(categories, excluded_refs)
1162
+ ? (0, utils_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
1164
1163
  : {
1165
1164
  subtotal: orderLevelDiscountBaseAmount,
1166
1165
  hasExcludedRefs: false,
@@ -3515,30 +3514,3 @@ function getResetRewardStateForNewCustomer(data, courses, listnerSettings) {
3515
3514
  wallet_redemptions: null,
3516
3515
  }, courses, listnerSettings);
3517
3516
  }
3518
- // ================================><================================= //
3519
- /**
3520
- * Calculate the eligible subtotal by excluding items/categories in excluded_refs
3521
- */
3522
- function calculateEligibleOfferDiscountDetails(categories, excluded_refs) {
3523
- if (!categories?.length)
3524
- return { subtotal: 0, hasExcludedRefs: false };
3525
- let eligibleSubtotal = 0;
3526
- let hasExcludedRefs = false;
3527
- for (const category of categories) {
3528
- // Skip entire category if it's in excluded_refs
3529
- if (excluded_refs.includes(category.category_id)) {
3530
- hasExcludedRefs = true;
3531
- continue;
3532
- }
3533
- // Otherwise, check each item
3534
- for (const item of category.items ?? []) {
3535
- if (excluded_refs.includes(item.item_id)) {
3536
- hasExcludedRefs = true;
3537
- }
3538
- else {
3539
- eligibleSubtotal += item.subtotal ?? 0;
3540
- }
3541
- }
3542
- }
3543
- return { subtotal: eligibleSubtotal, hasExcludedRefs };
3544
- }
@@ -1,5 +1,6 @@
1
1
  import { PhoneNumberUtil } from 'google-libphonenumber';
2
2
  import { COUNTRY_ALPHA_2_ENUM, CURRENCY_SYMBOL_ENUM, SUBSCRIPTION_STATUS_ENUM, TAX_INVOICE_PROVIDER_ENUM } from '../../constants';
3
+ import { IOrderCategory } from '../../schemas';
3
4
  export declare const phoneUtil: PhoneNumberUtil;
4
5
  export declare function getNationalNumberFromPhone(phoneNumber: string, region?: string): string | null | undefined;
5
6
  export declare function getIntNumberFromPhone(phoneNumber: string, region?: string): string | null;
@@ -43,4 +44,14 @@ interface IGetCappedOfferDiscountAmount {
43
44
  maxDiscountPercentage?: number | null;
44
45
  }
45
46
  export declare function getCappedOfferDiscountAmount({ baseAmount, discountValue, isDiscountPercentage, maxDiscountAmount, maxDiscountPercentage, }: IGetCappedOfferDiscountAmount): number;
47
+ /**
48
+ * Calculate the eligible subtotal by excluding items/categories in excluded_refs.
49
+ *
50
+ * Shared by the cart engine (discount application/re-sync) and the offer-stats
51
+ * engine (spend qualification) so both use the exact same exclusion math.
52
+ */
53
+ export declare function calculateEligibleOfferDiscountDetails(categories: IOrderCategory[] | undefined, excluded_refs: string[]): {
54
+ subtotal: number;
55
+ hasExcludedRefs: boolean;
56
+ };
46
57
  export {};
@@ -30,6 +30,7 @@ exports.formattedStoreName = formattedStoreName;
30
30
  exports.getPercentage = getPercentage;
31
31
  exports.getPercentageAmount = getPercentageAmount;
32
32
  exports.getCappedOfferDiscountAmount = getCappedOfferDiscountAmount;
33
+ exports.calculateEligibleOfferDiscountDetails = calculateEligibleOfferDiscountDetails;
33
34
  const google_libphonenumber_1 = require("google-libphonenumber");
34
35
  const moment_1 = __importDefault(require("moment"));
35
36
  const constants_1 = require("../../constants");
@@ -373,3 +374,32 @@ function getCappedOfferDiscountAmount({ baseAmount, discountValue, isDiscountPer
373
374
  }
374
375
  return Math.min(amount, normalizedBaseAmount);
375
376
  }
377
+ /**
378
+ * Calculate the eligible subtotal by excluding items/categories in excluded_refs.
379
+ *
380
+ * Shared by the cart engine (discount application/re-sync) and the offer-stats
381
+ * engine (spend qualification) so both use the exact same exclusion math.
382
+ */
383
+ function calculateEligibleOfferDiscountDetails(categories, excluded_refs) {
384
+ if (!categories?.length)
385
+ return { subtotal: 0, hasExcludedRefs: false };
386
+ let eligibleSubtotal = 0;
387
+ let hasExcludedRefs = false;
388
+ for (const category of categories) {
389
+ // Skip entire category if it's in excluded_refs
390
+ if (excluded_refs.includes(category.category_id)) {
391
+ hasExcludedRefs = true;
392
+ continue;
393
+ }
394
+ // Otherwise, check each item
395
+ for (const item of category.items ?? []) {
396
+ if (excluded_refs.includes(item.item_id)) {
397
+ hasExcludedRefs = true;
398
+ }
399
+ else {
400
+ eligibleSubtotal += item.subtotal ?? 0;
401
+ }
402
+ }
403
+ }
404
+ return { subtotal: eligibleSubtotal, hasExcludedRefs };
405
+ }
@@ -94,7 +94,7 @@ function buildOfferDiscountUpdate({ offer, orderDiscountDetails, categories, })
94
94
  const orderLevelDiscountBaseAmount = getOrderSubtotalFromCategories(categories);
95
95
  // Handle excluded_refs
96
96
  if (excluded_refs != null && excluded_refs.length > 0) {
97
- const { subtotal: eligibleSubtotal, hasExcludedRefs } = (0, cart_actions_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
97
+ const { subtotal: eligibleSubtotal, hasExcludedRefs } = (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
98
98
  if (hasExcludedRefs) {
99
99
  if (!is_discount_percentage) {
100
100
  return { success: false, discountDetails: null, errorMessage: null };
@@ -191,7 +191,7 @@ function buildOfferCashbackUpdate({ offer, orderDiscountDetails, categories, })
191
191
  // Validate excluded_refs
192
192
  const excluded_refs = offer.reward_cashback.excluded_refs ?? [];
193
193
  if (excluded_refs.length > 0) {
194
- const { subtotal: eligibleSubtotal } = (0, cart_actions_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
194
+ const { subtotal: eligibleSubtotal } = (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
195
195
  if (eligibleSubtotal <= 0) {
196
196
  return {
197
197
  success: false,
@@ -270,7 +270,7 @@ function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categorie
270
270
  const { discount_value, excluded_refs, is_discount_percentage, max_discount_amount, max_discount_percentage } = reward;
271
271
  const orderLevelDiscountBaseAmount = getOrderSubtotalFromCategories(categories);
272
272
  const { subtotal: eligibleSubtotal, hasExcludedRefs } = excluded_refs != null && excluded_refs.length > 0
273
- ? (0, cart_actions_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
273
+ ? (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs)
274
274
  : { subtotal: orderLevelDiscountBaseAmount, hasExcludedRefs: false };
275
275
  const hasRelevantCap = is_discount_percentage &&
276
276
  max_discount_amount != null &&
@@ -320,7 +320,7 @@ function buildGiftCardDiscountUpdate({ giftCard, orderDiscountDetails, categorie
320
320
  }
321
321
  const excluded_refs = giftCard.reward_cashback.excluded_refs ?? [];
322
322
  if (excluded_refs.length > 0) {
323
- const { subtotal: eligibleSubtotal } = (0, cart_actions_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
323
+ const { subtotal: eligibleSubtotal } = (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excluded_refs);
324
324
  if (eligibleSubtotal <= 0) {
325
325
  return {
326
326
  success: false,
@@ -1168,14 +1168,40 @@ function getOwnOfferOrderLevelDiscountAmount({ offer, orderDiscountDetails, orde
1168
1168
  });
1169
1169
  return (0, common_1.parseNum)(Math.min(orderLevelDiscountAmount, discountSlotAmounts[discountSlot]));
1170
1170
  }
1171
- function getOfferQualifyingOrderValue({ offer, orderLevelDiscountBaseAmount, orderLevelDiscountAmount, orderDiscountDetails, }) {
1171
+ /**
1172
+ * Discount-eligibility refs whose cart amounts must not count toward the
1173
+ * offer's spend qualification. Mirrors the refs used to compute the eligible
1174
+ * discount base (`calculateEligibleOfferDiscountDetails`) and to gate
1175
+ * "no eligible items" in the stats engine.
1176
+ */
1177
+ function getOfferOrderValueExcludedRefs(offer) {
1178
+ if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT) {
1179
+ return offer.reward_discount?.excluded_refs ?? [];
1180
+ }
1181
+ if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
1182
+ return offer.reward_discount_items?.excluded_refs ?? [];
1183
+ }
1184
+ if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK) {
1185
+ return offer.reward_cashback?.excluded_refs ?? [];
1186
+ }
1187
+ return [];
1188
+ }
1189
+ function getOfferQualifyingOrderValue({ offer, categories, orderLevelDiscountBaseAmount, orderLevelDiscountAmount, orderDiscountDetails, }) {
1190
+ // Spend thresholds measure only the eligible (non-excluded) portion of the
1191
+ // cart — excluded categories/items never count toward unlock amounts. When
1192
+ // the cart has no matching excluded refs, keep the original base untouched.
1193
+ const excludedRefs = getOfferOrderValueExcludedRefs(offer);
1194
+ const eligibleSubtotalResult = excludedRefs.length > 0 && categories != null
1195
+ ? (0, common_1.calculateEligibleOfferDiscountDetails)(categories, excludedRefs)
1196
+ : null;
1197
+ const effectiveBaseAmount = eligibleSubtotalResult?.hasExcludedRefs === true ? eligibleSubtotalResult.subtotal : orderLevelDiscountBaseAmount;
1172
1198
  const ownOrderLevelDiscountAmount = getOwnOfferOrderLevelDiscountAmount({
1173
1199
  offer,
1174
1200
  orderDiscountDetails,
1175
- orderLevelDiscountBaseAmount,
1201
+ orderLevelDiscountBaseAmount: effectiveBaseAmount,
1176
1202
  orderLevelDiscountAmount,
1177
1203
  });
1178
- return (0, common_1.parseNum)(Math.max(0, orderLevelDiscountBaseAmount - orderLevelDiscountAmount + ownOrderLevelDiscountAmount));
1204
+ return (0, common_1.parseNum)(Math.max(0, effectiveBaseAmount - orderLevelDiscountAmount + ownOrderLevelDiscountAmount));
1179
1205
  }
1180
1206
  function getMaxApplicableWalletCashback({ cashbackBalance, itemsPrice, totalDiscountApplied, orderLevelDiscount, }) {
1181
1207
  const safeCashbackBalance = Number.isFinite(cashbackBalance) ? Math.max(0, Number(cashbackBalance)) : 0;
@@ -1480,8 +1506,20 @@ function getProgressPercentage(currentValue, requiredValue) {
1480
1506
  return 100;
1481
1507
  return Math.max(0, Math.min(100, Math.round((safeCurrentValue / safeRequiredValue) * 100)));
1482
1508
  }
1509
+ /**
1510
+ * Progress that stays below 100% while a pathway requirement is still unmet.
1511
+ *
1512
+ * A requirement that is absent, zero or negative counts as already satisfied
1513
+ * (`getProgressPercentage` returns 100 for it), so callers must pass the RAW
1514
+ * requirement. The old `requirement || 1` fallbacks turned a satisfied minimum
1515
+ * (e.g. `min_num_of_orders: 0`, `num_of_items: 0`, `num_of_points: 0`,
1516
+ * `total_amount: 0`) into 0%, which then zeroed the `Math.min(...)` combined
1517
+ * progress for the whole pre-unlock range. Unlocking is never decided by this
1518
+ * progress value — the pathway comparisons (`orderValue >= total_amount` etc.)
1519
+ * and the explicit `stats.progress = 100` branches decide it.
1520
+ */
1483
1521
  function getPreUnlockProgressPercentage(currentValue, requiredValue) {
1484
- return Math.min(99, getProgressPercentage(currentValue, requiredValue));
1522
+ return Math.min(99, getProgressPercentage(currentValue, requiredValue ?? 0));
1485
1523
  }
1486
1524
  function getUnlockedOffersApplicableTimesHashKey(map, isEdit) {
1487
1525
  const keys = Object.keys(map).sort();
@@ -1886,6 +1924,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1886
1924
  }
1887
1925
  const orderValue = getOfferQualifyingOrderValue({
1888
1926
  offer,
1927
+ categories,
1889
1928
  orderLevelDiscountBaseAmount,
1890
1929
  orderLevelDiscountAmount,
1891
1930
  orderDiscountDetails: order_discount_details,
@@ -1908,8 +1947,10 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1908
1947
  continue;
1909
1948
  }
1910
1949
  const { totalOrders, totalAmount } = scopedStats;
1911
- const ordersProgress = getPreUnlockProgressPercentage(totalOrders, min_num_of_orders || 1);
1912
- const amountProgress = getPreUnlockProgressPercentage(totalAmount, total_amount || 1);
1950
+ // Raw requirements: a zero minimum is already satisfied, so it must not
1951
+ // drag `Math.min(ordersProgress, amountProgress)` down to 0%.
1952
+ const ordersProgress = getPreUnlockProgressPercentage(totalOrders, min_num_of_orders);
1953
+ const amountProgress = getPreUnlockProgressPercentage(totalAmount, total_amount);
1913
1954
  const combinedProgress = Math.min(ordersProgress, amountProgress);
1914
1955
  const ordersBetweenUnlocksStats = getOrdersBetweenUnlocksStats({
1915
1956
  totalOrders,
@@ -2212,6 +2253,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2212
2253
  }
2213
2254
  const orderValue = getOfferQualifyingOrderValue({
2214
2255
  offer,
2256
+ categories,
2215
2257
  orderLevelDiscountBaseAmount,
2216
2258
  orderLevelDiscountAmount,
2217
2259
  orderDiscountDetails: order_discount_details,
@@ -2232,8 +2274,8 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2232
2274
  const unlockTimesForItems = Math.floor(totalItemsSelected / (num_of_items || 1));
2233
2275
  const unlockTimesForAmount = total_amount != null && total_amount > 0 ? Math.floor(orderValue / total_amount) : unlockTimesForItems;
2234
2276
  const totalUnlockableClaims = Math.min(unlockTimesForItems, unlockTimesForAmount, maxClaimsPerOrder);
2235
- const itemsProgress = getPreUnlockProgressPercentage(bachelorItems, num_of_items || 1);
2236
- const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount || 1);
2277
+ const itemsProgress = getPreUnlockProgressPercentage(bachelorItems, num_of_items);
2278
+ const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount);
2237
2279
  const combinedProgress = Math.min(itemsProgress, amountProgress);
2238
2280
  if (totalItemsSelected >= num_of_items) {
2239
2281
  if (orderValue >= total_amount) {
@@ -2485,6 +2527,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2485
2527
  }
2486
2528
  const orderValue = getOfferQualifyingOrderValue({
2487
2529
  offer,
2530
+ categories,
2488
2531
  orderLevelDiscountBaseAmount,
2489
2532
  orderLevelDiscountAmount,
2490
2533
  orderDiscountDetails: order_discount_details,
@@ -2507,8 +2550,8 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2507
2550
  const orderLevelClaimSignal = order_discount_details?.loyalty_discount_id === offer._id ? 1 : 0;
2508
2551
  const redeemedTimesForCurrentOffer = Math.max(getOfferRedeemedTimes(offer._id), orderLevelClaimSignal);
2509
2552
  const effectiveLoyaltyPointsForCurrentOffer = (totalLoyaltyPointsOfCustomer ?? 0) + redeemedTimesForCurrentOffer * (num_of_points ?? 0);
2510
- const pointsProgress = getPreUnlockProgressPercentage(effectiveLoyaltyPointsForCurrentOffer, num_of_points || 1);
2511
- const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount || 1);
2553
+ const pointsProgress = getPreUnlockProgressPercentage(effectiveLoyaltyPointsForCurrentOffer, num_of_points);
2554
+ const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount);
2512
2555
  const combinedProgress = Math.min(pointsProgress, amountProgress);
2513
2556
  if (effectiveLoyaltyPointsForCurrentOffer >= num_of_points) {
2514
2557
  if (orderValue >= total_amount) {
@@ -2763,6 +2806,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2763
2806
  }
2764
2807
  const orderValue = getOfferQualifyingOrderValue({
2765
2808
  offer,
2809
+ categories,
2766
2810
  orderLevelDiscountBaseAmount,
2767
2811
  orderLevelDiscountAmount,
2768
2812
  orderDiscountDetails: order_discount_details,
@@ -2816,7 +2860,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2816
2860
  const normalizedMatchedVoucherCode = matchingVoucherContext != null ? getVoucherCode(matchingVoucherContext) : null;
2817
2861
  const spendableVoucherCount = normalizedMatchedVoucherCode == null ? 0 : (spendableVoucherCodesByCode[normalizedMatchedVoucherCode] ?? 0);
2818
2862
  const hasVoucherAccess = matchedVoucher != null || (redeemedTimesForOffer > 0 && matchingVoucherContext != null);
2819
- const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount || 1);
2863
+ const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount);
2820
2864
  if (!hasMatchingVoucher) {
2821
2865
  stats.progress = 0;
2822
2866
  stats.message = `Enter a matching voucher code to unlock this offer`;
@@ -64,6 +64,7 @@ export * from './tenant_inventory_department_utilities';
64
64
  export * from './tenant_inventory_departments';
65
65
  export * from './tenant_inventory_entries';
66
66
  export * from './tenant_metadata';
67
+ export * from './tenant_order_item_instructions';
67
68
  export * from './tenant_purchase_order_vendor_returns';
68
69
  export * from './tenant_purchase_orders';
69
70
  export * from './tenant_shifts';
@@ -80,6 +80,7 @@ __exportStar(require("./tenant_inventory_department_utilities"), exports);
80
80
  __exportStar(require("./tenant_inventory_departments"), exports);
81
81
  __exportStar(require("./tenant_inventory_entries"), exports);
82
82
  __exportStar(require("./tenant_metadata"), exports);
83
+ __exportStar(require("./tenant_order_item_instructions"), exports);
83
84
  __exportStar(require("./tenant_purchase_order_vendor_returns"), exports);
84
85
  __exportStar(require("./tenant_purchase_orders"), exports);
85
86
  __exportStar(require("./tenant_shifts"), exports);
@@ -0,0 +1,62 @@
1
+ import { Schema } from 'mongoose';
2
+ export declare const TenantOrderItemInstructionSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
3
+ timestamps: true;
4
+ versionKey: false;
5
+ minimize: false;
6
+ }, {
7
+ createdAt: NativeDate;
8
+ updatedAt: NativeDate;
9
+ } & {
10
+ _id: import("mongoose").Types.ObjectId;
11
+ tenant_id: string;
12
+ createdAt: NativeDate;
13
+ updatedAt: NativeDate;
14
+ sort_id: number;
15
+ item_ids: import("mongoose").Types.ObjectId[];
16
+ is_public: boolean;
17
+ instruction: string;
18
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
19
+ createdAt: NativeDate;
20
+ updatedAt: NativeDate;
21
+ } & {
22
+ _id: import("mongoose").Types.ObjectId;
23
+ tenant_id: string;
24
+ createdAt: NativeDate;
25
+ updatedAt: NativeDate;
26
+ sort_id: number;
27
+ item_ids: import("mongoose").Types.ObjectId[];
28
+ is_public: boolean;
29
+ instruction: string;
30
+ }>> & import("mongoose").FlatRecord<{
31
+ createdAt: NativeDate;
32
+ updatedAt: NativeDate;
33
+ } & {
34
+ _id: import("mongoose").Types.ObjectId;
35
+ tenant_id: string;
36
+ createdAt: NativeDate;
37
+ updatedAt: NativeDate;
38
+ sort_id: number;
39
+ item_ids: import("mongoose").Types.ObjectId[];
40
+ is_public: boolean;
41
+ instruction: string;
42
+ }> & Required<{
43
+ _id: import("mongoose").Types.ObjectId;
44
+ }> & {
45
+ __v: number;
46
+ }>;
47
+ export declare const TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_NAME = "tenant_order_item_instructions";
48
+ /**
49
+ * Describes the indexes for `tenant_order_item_instructions`. Values are Mongo key patterns
50
+ * that can be passed straight to `.hint()`.
51
+ * - `_id`: unique primary key.
52
+ * - `tenant_id__sort_id`: per-tenant lookup ordered by `sort_id`.
53
+ */
54
+ export declare const TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_INDEXES: {
55
+ _id: {
56
+ _id: number;
57
+ };
58
+ tenant_id__sort_id: {
59
+ tenant_id: number;
60
+ sort_id: number;
61
+ };
62
+ };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_INDEXES = exports.TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_NAME = exports.TenantOrderItemInstructionSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ exports.TenantOrderItemInstructionSchema = new mongoose_1.Schema({
6
+ _id: {
7
+ type: mongoose_1.Schema.Types.ObjectId,
8
+ required: true,
9
+ immutable: true,
10
+ },
11
+ tenant_id: {
12
+ type: String,
13
+ required: true,
14
+ immutable: true,
15
+ ref: 'tenants',
16
+ },
17
+ item_ids: {
18
+ type: [
19
+ {
20
+ type: mongoose_1.Schema.Types.ObjectId,
21
+ ref: 'items',
22
+ },
23
+ ],
24
+ required: true,
25
+ default: [],
26
+ },
27
+ sort_id: {
28
+ type: Number,
29
+ required: true,
30
+ },
31
+ instruction: {
32
+ type: String,
33
+ required: true,
34
+ trim: true,
35
+ },
36
+ is_public: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
40
+ createdAt: {
41
+ type: mongoose_1.Schema.Types.Date,
42
+ required: true,
43
+ default: () => new Date(),
44
+ immutable: true,
45
+ },
46
+ updatedAt: {
47
+ type: mongoose_1.Schema.Types.Date,
48
+ required: true,
49
+ default: () => new Date(),
50
+ },
51
+ }, {
52
+ timestamps: true,
53
+ versionKey: false,
54
+ minimize: false,
55
+ });
56
+ exports.TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_NAME = 'tenant_order_item_instructions';
57
+ /**
58
+ * Describes the indexes for `tenant_order_item_instructions`. Values are Mongo key patterns
59
+ * that can be passed straight to `.hint()`.
60
+ * - `_id`: unique primary key.
61
+ * - `tenant_id__sort_id`: per-tenant lookup ordered by `sort_id`.
62
+ */
63
+ exports.TENANT_ORDER_ITEM_INSTRUCTIONS_COLLECTION_INDEXES = {
64
+ _id: { _id: 1 }, // Unique Index
65
+ tenant_id__sort_id: {
66
+ tenant_id: 1,
67
+ sort_id: 1,
68
+ }, // compound index
69
+ };
@@ -25,10 +25,12 @@ export declare const TenantVendorsSchema: Schema<any, import("mongoose").Model<a
25
25
  category_id: import("mongoose").Types.ObjectId;
26
26
  excluded_items: import("mongoose").Types.ObjectId[];
27
27
  }>;
28
+ ref_id: string;
28
29
  phone_number: string;
29
30
  uid: string;
30
31
  email: string;
31
32
  tax_business_number: string;
33
+ vendor_type: import("../../constants").VENDOR_TYPE_ENUM;
32
34
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
33
35
  createdAt: NativeDate;
34
36
  updatedAt: NativeDate;
@@ -51,10 +53,12 @@ export declare const TenantVendorsSchema: Schema<any, import("mongoose").Model<a
51
53
  category_id: import("mongoose").Types.ObjectId;
52
54
  excluded_items: import("mongoose").Types.ObjectId[];
53
55
  }>;
56
+ ref_id: string;
54
57
  phone_number: string;
55
58
  uid: string;
56
59
  email: string;
57
60
  tax_business_number: string;
61
+ vendor_type: import("../../constants").VENDOR_TYPE_ENUM;
58
62
  }>> & import("mongoose").FlatRecord<{
59
63
  createdAt: NativeDate;
60
64
  updatedAt: NativeDate;
@@ -77,10 +81,12 @@ export declare const TenantVendorsSchema: Schema<any, import("mongoose").Model<a
77
81
  category_id: import("mongoose").Types.ObjectId;
78
82
  excluded_items: import("mongoose").Types.ObjectId[];
79
83
  }>;
84
+ ref_id: string;
80
85
  phone_number: string;
81
86
  uid: string;
82
87
  email: string;
83
88
  tax_business_number: string;
89
+ vendor_type: import("../../constants").VENDOR_TYPE_ENUM;
84
90
  }> & Required<{
85
91
  _id: import("mongoose").Types.ObjectId;
86
92
  }> & {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VENDORS_COLLECTION_NAME = exports.TenantVendorsSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
+ const constants_1 = require("../../constants");
5
6
  const TenantVendorIncludedCategoriesSchema = new mongoose_1.Schema({
6
7
  category_id: {
7
8
  type: mongoose_1.Schema.Types.ObjectId,
@@ -33,6 +34,17 @@ exports.TenantVendorsSchema = new mongoose_1.Schema({
33
34
  immutable: true,
34
35
  ref: 'tenants',
35
36
  },
37
+ ref_id: {
38
+ type: String,
39
+ immutable: true,
40
+ default: null,
41
+ },
42
+ vendor_type: {
43
+ type: String,
44
+ required: true,
45
+ enum: constants_1.ALL_VENDOR_TYPE_NAMES,
46
+ immutable: true,
47
+ },
36
48
  uid: {
37
49
  type: String,
38
50
  required: true,
@@ -24,11 +24,13 @@ export declare const WarehouseVendorsSchema: Schema<any, import("mongoose").Mode
24
24
  category_id: import("mongoose").Types.ObjectId;
25
25
  excluded_items: import("mongoose").Types.ObjectId[];
26
26
  }>;
27
+ ref_id: string;
27
28
  phone_number: string;
28
29
  uid: string;
29
30
  email: string;
30
31
  warehouse_id: string;
31
32
  tax_business_number: string;
33
+ vendor_type: import("../../constants").VENDOR_TYPE_ENUM;
32
34
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
33
35
  createdAt: NativeDate;
34
36
  updatedAt: NativeDate;
@@ -50,11 +52,13 @@ export declare const WarehouseVendorsSchema: Schema<any, import("mongoose").Mode
50
52
  category_id: import("mongoose").Types.ObjectId;
51
53
  excluded_items: import("mongoose").Types.ObjectId[];
52
54
  }>;
55
+ ref_id: string;
53
56
  phone_number: string;
54
57
  uid: string;
55
58
  email: string;
56
59
  warehouse_id: string;
57
60
  tax_business_number: string;
61
+ vendor_type: import("../../constants").VENDOR_TYPE_ENUM;
58
62
  }>> & import("mongoose").FlatRecord<{
59
63
  createdAt: NativeDate;
60
64
  updatedAt: NativeDate;
@@ -76,11 +80,13 @@ export declare const WarehouseVendorsSchema: Schema<any, import("mongoose").Mode
76
80
  category_id: import("mongoose").Types.ObjectId;
77
81
  excluded_items: import("mongoose").Types.ObjectId[];
78
82
  }>;
83
+ ref_id: string;
79
84
  phone_number: string;
80
85
  uid: string;
81
86
  email: string;
82
87
  warehouse_id: string;
83
88
  tax_business_number: string;
89
+ vendor_type: import("../../constants").VENDOR_TYPE_ENUM;
84
90
  }> & Required<{
85
91
  _id: import("mongoose").Types.ObjectId;
86
92
  }> & {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WAREHOUSE_VENDORS_COLLECTION_NAME = exports.WarehouseVendorsSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
+ const constants_1 = require("../../constants");
5
6
  const WarehouseVendorIncludedCategoriesSchema = new mongoose_1.Schema({
6
7
  category_id: {
7
8
  type: mongoose_1.Schema.Types.ObjectId,
@@ -33,6 +34,17 @@ exports.WarehouseVendorsSchema = new mongoose_1.Schema({
33
34
  immutable: true,
34
35
  ref: 'warehouses',
35
36
  },
37
+ ref_id: {
38
+ type: String,
39
+ immutable: true,
40
+ default: null,
41
+ },
42
+ vendor_type: {
43
+ type: String,
44
+ required: true,
45
+ enum: constants_1.ALL_VENDOR_TYPE_NAMES,
46
+ immutable: true,
47
+ },
36
48
  uid: {
37
49
  type: String,
38
50
  required: true,
@@ -68,6 +68,7 @@ export * from './tenant_instore_shift_sessions';
68
68
  export * from './tenant_instore_shifts';
69
69
  export * from './tenant_inventory_entries';
70
70
  export * from './tenant_metadata';
71
+ export * from './tenant_order_item_instructions';
71
72
  export * from './tenant_purchase_order_vendor_returns';
72
73
  export * from './tenant_purchase_orders';
73
74
  export * from './tenant_shifts';
@@ -84,6 +84,7 @@ __exportStar(require("./tenant_instore_shift_sessions"), exports);
84
84
  __exportStar(require("./tenant_instore_shifts"), exports);
85
85
  __exportStar(require("./tenant_inventory_entries"), exports);
86
86
  __exportStar(require("./tenant_metadata"), exports);
87
+ __exportStar(require("./tenant_order_item_instructions"), exports);
87
88
  __exportStar(require("./tenant_purchase_order_vendor_returns"), exports);
88
89
  __exportStar(require("./tenant_purchase_orders"), exports);
89
90
  __exportStar(require("./tenant_shifts"), exports);