@managesome/eposmatic-toolkit 0.2.341 → 0.2.342-beta.0

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.
Files changed (40) hide show
  1. package/lib/constants/ENUMS.d.ts +35 -0
  2. package/lib/constants/ENUMS.js +48 -3
  3. package/lib/helpers/store/common-purchase-order-actions.d.ts +2 -2
  4. package/lib/helpers/store/purchase-orders-cart-actions.d.ts +7 -6
  5. package/lib/helpers/utils/index.d.ts +0 -1
  6. package/lib/helpers/utils/index.js +0 -1
  7. package/lib/helpers/utils/offer-apply-helpers.d.ts +1 -63
  8. package/lib/helpers/utils/offer-apply-helpers.js +3 -61
  9. package/lib/helpers/utils/offers-helpers.d.ts +4 -22
  10. package/lib/helpers/utils/offers-helpers.js +98 -254
  11. package/lib/schemas/models/index.d.ts +3 -0
  12. package/lib/schemas/models/index.js +3 -0
  13. package/lib/schemas/models/purchase_order_receipts.d.ts +165 -0
  14. package/lib/schemas/models/purchase_order_receipts.js +151 -0
  15. package/lib/schemas/models/purchase_order_rfq.d.ts +1938 -0
  16. package/lib/schemas/models/purchase_order_rfq.js +309 -0
  17. package/lib/schemas/models/purchase_order_vendor_returns.d.ts +234 -0
  18. package/lib/schemas/models/purchase_order_vendor_returns.js +188 -0
  19. package/lib/schemas/models/purchase_orders.d.ts +3 -0
  20. package/lib/schemas/models/purchase_orders.js +10 -1
  21. package/lib/schemas/models/void_purchase_order_items.js +2 -1
  22. package/lib/schemas/models/warehouse.d.ts +7 -1
  23. package/lib/schemas/models/warehouse.js +9 -0
  24. package/lib/schemas/models/warehouse_items.d.ts +19 -0
  25. package/lib/schemas/models/warehouse_items.js +29 -0
  26. package/lib/schemas/models/warehouse_vendors.d.ts +3 -3
  27. package/lib/schemas/types/index.d.ts +4 -0
  28. package/lib/schemas/types/index.js +4 -0
  29. package/lib/schemas/types/purchase_order_common.d.ts +39 -0
  30. package/lib/schemas/types/purchase_order_common.js +2 -0
  31. package/lib/schemas/types/purchase_order_receipts.d.ts +33 -0
  32. package/lib/schemas/types/purchase_order_receipts.js +2 -0
  33. package/lib/schemas/types/purchase_order_rfq.d.ts +25 -0
  34. package/lib/schemas/types/purchase_order_rfq.js +2 -0
  35. package/lib/schemas/types/purchase_order_vendor_returns.d.ts +42 -0
  36. package/lib/schemas/types/purchase_order_vendor_returns.js +2 -0
  37. package/lib/schemas/types/purchase_orders.d.ts +7 -43
  38. package/lib/schemas/types/warehouse.d.ts +3 -1
  39. package/lib/schemas/types/warehouse_items.d.ts +7 -1
  40. package/package.json +2 -2
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_WALLET_CASHBACK_PERCENTAGE_STEPS = exports.getTotalSelectedOfferItemsAgainstOffer = void 0;
4
4
  exports.getOfferWithPrice = getOfferWithPrice;
5
5
  exports.convertOffersToWorkableOffers = convertOffersToWorkableOffers;
6
- exports.getVoucherPathwayCartContext = getVoucherPathwayCartContext;
7
- exports.isVoucherPathwayOfferBlockedByCartContext = isVoucherPathwayOfferBlockedByCartContext;
8
6
  exports.isExhaustedVoucherOffer = isExhaustedVoucherOffer;
9
7
  exports.findLinkedVoucherOffers = findLinkedVoucherOffers;
10
8
  exports.buildClearVoucherDiscountDetails = buildClearVoucherDiscountDetails;
@@ -325,69 +323,6 @@ function getOfferRedeemedClaims(redeemedOffers, offerId) {
325
323
  }
326
324
  return 0;
327
325
  }
328
- function getVoucherPathwayCartContext({ offers, vouchers, redeemedOffers, orderDiscountDetails, }) {
329
- const consumedVoucherCodes = new Set();
330
- const consumedVoucherIds = new Set();
331
- const redeemedOfferIds = new Set();
332
- const voucherCodeById = new Map();
333
- const referencedVoucherCode = normalizeVoucherCode(orderDiscountDetails?.voucher_reference_number);
334
- if (vouchers != null) {
335
- for (let i = 0; i < vouchers.length; i++) {
336
- const voucher = vouchers[i];
337
- const normalizedVoucherCode = normalizeVoucherCode(voucher.code);
338
- if (normalizedVoucherCode == null)
339
- continue;
340
- voucherCodeById.set(voucher._id, normalizedVoucherCode);
341
- }
342
- }
343
- for (let i = 0; i < offers.length; i++) {
344
- const offer = offers[i];
345
- if (offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER) {
346
- continue;
347
- }
348
- const redeemedTimes = getOfferRedeemedClaims(redeemedOffers, offer._id);
349
- if (redeemedTimes <= 0) {
350
- continue;
351
- }
352
- const pathwayVouchers = offer.pathway_to_unlock_type_vouchers;
353
- if (pathwayVouchers == null || pathwayVouchers.voucher_ids.length === 0) {
354
- continue;
355
- }
356
- redeemedOfferIds.add(offer._id);
357
- const linkedVoucherCodes = new Set();
358
- for (let j = 0; j < pathwayVouchers.voucher_ids.length; j++) {
359
- const voucherId = pathwayVouchers.voucher_ids[j];
360
- consumedVoucherIds.add(voucherId);
361
- const linkedVoucherCode = voucherCodeById.get(voucherId);
362
- if (linkedVoucherCode == null)
363
- continue;
364
- linkedVoucherCodes.add(linkedVoucherCode);
365
- }
366
- if (referencedVoucherCode != null && linkedVoucherCodes.has(referencedVoucherCode)) {
367
- consumedVoucherCodes.add(referencedVoucherCode);
368
- continue;
369
- }
370
- for (const linkedVoucherCode of linkedVoucherCodes) {
371
- consumedVoucherCodes.add(linkedVoucherCode);
372
- }
373
- }
374
- const inferredVoucherCode = referencedVoucherCode ?? (consumedVoucherCodes.size === 1 ? consumedVoucherCodes.values().next().value : null);
375
- return {
376
- activeVoucherCode: inferredVoucherCode ?? null,
377
- consumedVoucherCodes,
378
- consumedVoucherIds,
379
- redeemedOfferIds,
380
- };
381
- }
382
- function isVoucherPathwayOfferBlockedByCartContext({ offer, cartContext, }) {
383
- if (offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER) {
384
- return false;
385
- }
386
- if (cartContext.redeemedOfferIds.size === 0) {
387
- return false;
388
- }
389
- return !cartContext.redeemedOfferIds.has(offer._id);
390
- }
391
326
  // ================================><================================= //
392
327
  // === isExhaustedVoucherOffer === //
393
328
  // ================================><================================= //
@@ -409,8 +344,7 @@ function isExhaustedVoucherOffer({ offer, customerOfferRedemptionCounts, redeeme
409
344
  if (!isThisOfferRedeemed)
410
345
  return false;
411
346
  const pathwayMaxUsesPerCustomer = offer.pathway_to_unlock_type_vouchers.max_uses_per_customer;
412
- return (pathwayMaxUsesPerCustomer != null &&
413
- getCustomerUsedRedemptionCount(customerOfferRedemptionCounts, offer._id) >= pathwayMaxUsesPerCustomer);
347
+ return (pathwayMaxUsesPerCustomer != null && (customerOfferRedemptionCounts[offer._id] ?? 0) >= pathwayMaxUsesPerCustomer);
414
348
  }
415
349
  // ================================><================================= //
416
350
  // === findLinkedVoucherOffers === //
@@ -465,7 +399,7 @@ function calculateCustomerSpendableVoucherCodes({ customerVoucherCodes, orderDis
465
399
  }
466
400
  }
467
401
  const activeVoucherCode = normalizeVoucherCode(orderDiscountDetails?.voucher_reference_number);
468
- if (vouchers == null || offers.length === 0 || redeemedOffers == null) {
402
+ if (activeVoucherCode == null || vouchers == null || offers.length === 0) {
469
403
  return {
470
404
  voucherCodes,
471
405
  totalVouchers: Object.values(voucherCodes).reduce((acc, count) => acc + count, 0),
@@ -473,59 +407,45 @@ function calculateCustomerSpendableVoucherCodes({ customerVoucherCodes, orderDis
473
407
  consumedVoucherClaims: 0,
474
408
  };
475
409
  }
476
- const voucherCodeById = new Map();
410
+ const activeVoucherIds = new Set();
477
411
  for (let i = 0; i < vouchers.length; i++) {
478
412
  const voucher = vouchers[i];
479
- const normalizedVoucherCode = normalizeVoucherCode(voucher.code);
480
- if (normalizedVoucherCode == null)
481
- continue;
482
- voucherCodeById.set(voucher._id, normalizedVoucherCode);
483
- }
484
- const consumedVoucherClaimsByCode = {};
485
- for (let i = 0; i < offers.length; i++) {
486
- const offer = offers[i];
487
- if (offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER) {
488
- continue;
413
+ if (normalizeVoucherCode(voucher.code) === activeVoucherCode) {
414
+ activeVoucherIds.add(voucher._id);
489
415
  }
490
- const pathwayVouchers = offer.pathway_to_unlock_type_vouchers;
491
- if (pathwayVouchers == null || pathwayVouchers.voucher_ids.length === 0) {
492
- continue;
493
- }
494
- const redeemedTimes = getOfferRedeemedClaims(redeemedOffers, offer._id);
495
- if (redeemedTimes <= 0) {
496
- continue;
497
- }
498
- const linkedVoucherCodes = new Set();
499
- for (let j = 0; j < pathwayVouchers.voucher_ids.length; j++) {
500
- const linkedVoucherCode = voucherCodeById.get(pathwayVouchers.voucher_ids[j]);
501
- if (linkedVoucherCode == null)
416
+ }
417
+ let consumedVoucherClaims = 0;
418
+ if (activeVoucherIds.size > 0) {
419
+ for (let i = 0; i < offers.length; i++) {
420
+ const offer = offers[i];
421
+ if (offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER) {
502
422
  continue;
503
- linkedVoucherCodes.add(linkedVoucherCode);
504
- }
505
- if (linkedVoucherCodes.size === 0) {
506
- continue;
507
- }
508
- const [singleLinkedVoucherCode] = linkedVoucherCodes;
509
- const targetVoucherCode = linkedVoucherCodes.size === 1
510
- ? singleLinkedVoucherCode
511
- : activeVoucherCode != null && linkedVoucherCodes.has(activeVoucherCode)
512
- ? activeVoucherCode
513
- : null;
514
- if (targetVoucherCode == null) {
515
- continue;
423
+ }
424
+ const pathwayVouchers = offer.pathway_to_unlock_type_vouchers;
425
+ if (pathwayVouchers == null || pathwayVouchers.voucher_ids.length === 0) {
426
+ continue;
427
+ }
428
+ let supportsActiveVoucherCode = false;
429
+ for (let j = 0; j < pathwayVouchers.voucher_ids.length; j++) {
430
+ if (activeVoucherIds.has(pathwayVouchers.voucher_ids[j])) {
431
+ supportsActiveVoucherCode = true;
432
+ break;
433
+ }
434
+ }
435
+ if (!supportsActiveVoucherCode)
436
+ continue;
437
+ const redeemedTimes = getOfferRedeemedClaims(redeemedOffers, offer._id);
438
+ if (redeemedTimes > 0) {
439
+ // Count 1 voucher use per redeemed offer (not redeemedTimes which
440
+ // can be > 1 for repeat claims). Each distinct offer consumes one
441
+ // voucher code use, regardless of how many times it was redeemed.
442
+ consumedVoucherClaims += 1;
443
+ }
516
444
  }
517
- consumedVoucherClaimsByCode[targetVoucherCode] =
518
- (consumedVoucherClaimsByCode[targetVoucherCode] ?? 0) + redeemedTimes;
519
445
  }
520
- const consumedVoucherCodes = Object.keys(consumedVoucherClaimsByCode);
521
- for (let i = 0; i < consumedVoucherCodes.length; i++) {
522
- const voucherCode = consumedVoucherCodes[i];
523
- if (voucherCodes[voucherCode] == null) {
524
- continue;
525
- }
526
- voucherCodes[voucherCode] = Math.max(0, voucherCodes[voucherCode] - consumedVoucherClaimsByCode[voucherCode]);
446
+ if (voucherCodes[activeVoucherCode] != null && consumedVoucherClaims > 0) {
447
+ voucherCodes[activeVoucherCode] = Math.max(0, voucherCodes[activeVoucherCode] - consumedVoucherClaims);
527
448
  }
528
- const consumedVoucherClaims = activeVoucherCode != null ? (consumedVoucherClaimsByCode[activeVoucherCode] ?? 0) : 0;
529
449
  return {
530
450
  voucherCodes,
531
451
  totalVouchers: Object.values(voucherCodes).reduce((acc, count) => acc + count, 0),
@@ -874,27 +794,6 @@ function toPositiveInteger(value, fallback = 0) {
874
794
  }
875
795
  return Math.floor(parsedValue);
876
796
  }
877
- function getCustomerRedemptionCount(customerOfferRedemptionCounts, type, id) {
878
- const normalizedId = normalizeOfferId(id);
879
- if (customerOfferRedemptionCounts == null || normalizedId == null) {
880
- return 0;
881
- }
882
- const typedCount = customerOfferRedemptionCounts[type]?.[normalizedId];
883
- if (typedCount != null) {
884
- return toPositiveInteger(typedCount, 0);
885
- }
886
- const legacyFlatCounts = customerOfferRedemptionCounts;
887
- return toPositiveInteger(legacyFlatCounts[normalizedId], 0);
888
- }
889
- function getRewardMaxAssignmentsPerCustomer(rewardResource) {
890
- return rewardResource.max_assignments_per_customer ?? rewardResource.max_uses_per_customer ?? null;
891
- }
892
- function getCustomerUsedRedemptionCount(customerOfferRedemptionCounts, id) {
893
- return getCustomerRedemptionCount(customerOfferRedemptionCounts, constants_1.CUSTOMER_REDEMPTION_TYPE_ENUM.USED, id);
894
- }
895
- function getCustomerAssignedRedemptionCount(customerOfferRedemptionCounts, id) {
896
- return getCustomerRedemptionCount(customerOfferRedemptionCounts, constants_1.CUSTOMER_REDEMPTION_TYPE_ENUM.ASSIGNED, id);
897
- }
898
797
  function getOfferPathwayMaxUsesPerCustomer(offer) {
899
798
  if (offer == null) {
900
799
  return null;
@@ -935,7 +834,7 @@ function getOfferConsumedUses({ offer, usageLimit, customerOfferRedemptionCounts
935
834
  if (usageKey == null) {
936
835
  return null;
937
836
  }
938
- return getCustomerUsedRedemptionCount(customerOfferRedemptionCounts, usageKey);
837
+ return toPositiveInteger(customerOfferRedemptionCounts[usageKey], 0);
939
838
  }
940
839
  function isOfferFullyConsumedForCustomer({ offer, usageLimit, customerOfferRedemptionCounts, }) {
941
840
  const consumedUses = getOfferConsumedUses({
@@ -1092,13 +991,8 @@ function normalizeWalletRedemptions(walletRedemptions) {
1092
991
  if (Number.isFinite(cashbackAmount) && cashbackAmount > 0) {
1093
992
  normalizedWalletRedemptions.cashback_amount = (0, common_1.parseNum)(cashbackAmount);
1094
993
  }
1095
- const rawGiftCardRedemptions = walletRedemptions.gift_cards;
1096
- const giftCardRedemptions = rawGiftCardRedemptions == null
1097
- ? []
1098
- : Array.isArray(rawGiftCardRedemptions)
1099
- ? rawGiftCardRedemptions
1100
- : [rawGiftCardRedemptions];
1101
- if (giftCardRedemptions.length > 0) {
994
+ const giftCardRedemptions = walletRedemptions.gift_cards;
995
+ if (Array.isArray(giftCardRedemptions)) {
1102
996
  const normalizedGiftCardRedemptionsMap = {};
1103
997
  for (let i = 0; i < giftCardRedemptions.length; i++) {
1104
998
  const giftCardRedemption = giftCardRedemptions[i];
@@ -1398,7 +1292,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1398
1292
  let totalClaimableOffers = [];
1399
1293
  let totalLoyaltyPointsOfCustomer = null;
1400
1294
  const nowTs = Date.now();
1401
- const isVoucherUseResourceUnavailable = (voucher) => {
1295
+ const isVoucherRewardResourceUnavailable = (voucher) => {
1402
1296
  if (voucher == null) {
1403
1297
  return true;
1404
1298
  }
@@ -1406,21 +1300,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1406
1300
  const voucherUsesExhausted = voucher.max_uses != null && voucher.used_count >= voucher.max_uses;
1407
1301
  return !voucher.active || voucherIsExpired || voucherUsesExhausted;
1408
1302
  };
1409
- const isVoucherRewardResourceUnavailable = (voucher) => {
1410
- if (voucher == null) {
1411
- return true;
1412
- }
1413
- const voucherIsExpired = voucher.expire_at != null && new Date(voucher.expire_at).getTime() <= nowTs;
1414
- const voucherAssignmentsExhausted = voucher.max_assignments != null && voucher.assigned_count >= voucher.max_assignments;
1415
- return !voucher.active || voucherIsExpired || voucherAssignmentsExhausted;
1416
- };
1417
1303
  const isGiftCardRewardResourceUnavailable = (giftCard) => {
1418
1304
  if (giftCard == null) {
1419
1305
  return true;
1420
1306
  }
1421
1307
  const giftCardIsExpired = giftCard.expire_at != null && new Date(giftCard.expire_at).getTime() <= nowTs;
1422
- const giftCardAssignmentsExhausted = giftCard.max_assignments != null && giftCard.assigned_count >= giftCard.max_assignments;
1423
- return !giftCard.active || giftCardIsExpired || giftCardAssignmentsExhausted;
1308
+ const giftCardUsesExhausted = giftCard.max_uses != null && giftCard.used_count >= giftCard.max_uses;
1309
+ return !giftCard.active || giftCardIsExpired || giftCardUsesExhausted;
1424
1310
  };
1425
1311
  const { voucherCodes: spendableVoucherCodesByCode } = calculateCustomerSpendableVoucherCodes({
1426
1312
  customerVoucherCodes: customer?.voucher_codes,
@@ -1429,12 +1315,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1429
1315
  offers,
1430
1316
  vouchers,
1431
1317
  });
1432
- const voucherPathwayCartContext = getVoucherPathwayCartContext({
1433
- offers,
1434
- vouchers,
1435
- redeemedOffers: redeemed_offers,
1436
- orderDiscountDetails: order_discount_details,
1437
- });
1438
1318
  const redeemedOffersById = redeemed_offers ?? null;
1439
1319
  const vouchersById = new Map();
1440
1320
  const allVouchersById = new Map();
@@ -1442,7 +1322,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1442
1322
  for (let i = 0; i < vouchers.length; i++) {
1443
1323
  const voucher = vouchers[i];
1444
1324
  allVouchersById.set(voucher._id, voucher);
1445
- if (isVoucherUseResourceUnavailable(voucher)) {
1325
+ if (isVoucherRewardResourceUnavailable(voucher)) {
1446
1326
  continue;
1447
1327
  }
1448
1328
  vouchersById.set(voucher._id, voucher);
@@ -1469,11 +1349,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1469
1349
  rewardVoucherUnavailable = true;
1470
1350
  break;
1471
1351
  }
1472
- const maxAssignmentsPerCustomer = getRewardMaxAssignmentsPerCustomer(rewardVoucher);
1473
- if (maxAssignmentsPerCustomer != null &&
1474
- (customerOfferRedemptionCounts == null ||
1475
- getCustomerAssignedRedemptionCount(customerOfferRedemptionCounts, rewardVoucher._id) >=
1476
- maxAssignmentsPerCustomer)) {
1352
+ if (customerOfferRedemptionCounts != null &&
1353
+ rewardVoucher.max_uses_per_customer != null &&
1354
+ (customerOfferRedemptionCounts[rewardVoucher._id] ?? 0) >= rewardVoucher.max_uses_per_customer) {
1477
1355
  rewardVoucherLimitExhausted = true;
1478
1356
  break;
1479
1357
  }
@@ -1492,11 +1370,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1492
1370
  rewardGiftCardUnavailable = true;
1493
1371
  break;
1494
1372
  }
1495
- const maxAssignmentsPerCustomer = getRewardMaxAssignmentsPerCustomer(rewardGiftCard);
1496
- if (maxAssignmentsPerCustomer != null &&
1497
- (customerOfferRedemptionCounts == null ||
1498
- getCustomerAssignedRedemptionCount(customerOfferRedemptionCounts, rewardGiftCard._id) >=
1499
- maxAssignmentsPerCustomer)) {
1373
+ if (customerOfferRedemptionCounts != null &&
1374
+ rewardGiftCard.max_uses_per_customer != null &&
1375
+ (customerOfferRedemptionCounts[rewardGiftCard._id] ?? 0) >= rewardGiftCard.max_uses_per_customer) {
1500
1376
  rewardGiftCardLimitExhausted = true;
1501
1377
  break;
1502
1378
  }
@@ -1506,19 +1382,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1506
1382
  rewardGiftCardLimitExhausted,
1507
1383
  };
1508
1384
  };
1509
- const clearBlockedRewardApplicableQuantity = (offerToCheck, statsToUpdate) => {
1510
- if (statsToUpdate.claimable ||
1511
- (offerToCheck.reward_type !== constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER &&
1512
- offerToCheck.reward_type !== constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS)) {
1513
- return;
1514
- }
1515
- if (statsToUpdate.message !== '⛔️ This reward is no longer available ⛔️' &&
1516
- statsToUpdate.message !== '⛔️ You have reached your personal limit for this reward ⛔️') {
1517
- return;
1518
- }
1519
- statsToUpdate.applicable_quantity = 0;
1520
- unlockedOffersApplicableTimes[offerToCheck._id] = 0;
1521
- };
1522
1385
  const getOfferRedeemedTimes = (offerId) => {
1523
1386
  const redeemedTimes = Number(redeemedOffersById?.[offerId]);
1524
1387
  if (Number.isFinite(redeemedTimes) && redeemedTimes > 0) {
@@ -1596,7 +1459,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1596
1459
  return false;
1597
1460
  if (customerOfferRedemptionCounts == null)
1598
1461
  return true;
1599
- return getCustomerUsedRedemptionCount(customerOfferRedemptionCounts, offerToCheck._id) >= maxUsesPerCustomer;
1462
+ return (customerOfferRedemptionCounts[offerToCheck._id] ?? 0) >= maxUsesPerCustomer;
1600
1463
  };
1601
1464
  const getRemainingOfferUsesForCustomer = (offerToCheck) => {
1602
1465
  const maxUsesPerCustomer = getOfferMaxUsesPerCustomer(offerToCheck);
@@ -1604,7 +1467,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1604
1467
  return Infinity;
1605
1468
  if (customerOfferRedemptionCounts == null)
1606
1469
  return 0;
1607
- const redeemedByCustomer = getCustomerUsedRedemptionCount(customerOfferRedemptionCounts, offerToCheck._id);
1470
+ const redeemedByCustomer = customerOfferRedemptionCounts[offerToCheck._id] ?? 0;
1608
1471
  return Math.max(0, maxUsesPerCustomer - redeemedByCustomer);
1609
1472
  };
1610
1473
  const getOrderValueClaimTimes = (orderValue, minAmount) => {
@@ -1684,25 +1547,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1684
1547
  totalClaimableOffers.push(offerToCheck._id);
1685
1548
  }
1686
1549
  };
1687
- const applyVoucherPathwayCartContextBlock = ({ offerToCheck, statsToUpdate, }) => {
1688
- if (!isVoucherPathwayOfferBlockedByCartContext({
1689
- offer: offerToCheck,
1690
- cartContext: voucherPathwayCartContext,
1691
- })) {
1692
- return;
1693
- }
1694
- if (!statsToUpdate.claimable && statsToUpdate.applicable_quantity <= 0 && statsToUpdate.progress < 100) {
1695
- return;
1696
- }
1697
- totalClaimableOffers = totalClaimableOffers.filter((id) => id !== offerToCheck._id);
1698
- statsToUpdate.claimable = false;
1699
- statsToUpdate.applicable_quantity = 0;
1700
- unlockedOffersApplicableTimes[offerToCheck._id] = 0;
1701
- statsToUpdate.message =
1702
- voucherPathwayCartContext.activeVoucherCode != null
1703
- ? `You already selected a reward for voucher ${voucherPathwayCartContext.activeVoucherCode}.`
1704
- : 'You already selected a voucher reward for this order.';
1705
- };
1706
1550
  for (let i = 0; i < offers.length; i++) {
1707
1551
  const offer = offers[i];
1708
1552
  const stats = {
@@ -1885,7 +1729,22 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1885
1729
  else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER) {
1886
1730
  if (offer.reward_voucher == null)
1887
1731
  continue;
1888
- const { rewardVoucherUnavailable, rewardVoucherLimitExhausted } = getRewardVoucherAvailability(Object.keys(offer.reward_voucher.voucher_ids));
1732
+ const vIds = Object.keys(offer.reward_voucher.voucher_ids);
1733
+ let rewardVoucherUnavailable = false;
1734
+ let rewardVoucherLimitExhausted = false;
1735
+ for (let vIdx = 0; vIdx < vIds.length; vIdx++) {
1736
+ const rewardVoucher = allVouchersById.get(vIds[vIdx]);
1737
+ if (rewardVoucher == null || isVoucherRewardResourceUnavailable(rewardVoucher)) {
1738
+ rewardVoucherUnavailable = true;
1739
+ break;
1740
+ }
1741
+ if (customerOfferRedemptionCounts != null &&
1742
+ rewardVoucher.max_uses_per_customer != null &&
1743
+ (customerOfferRedemptionCounts[rewardVoucher._id] ?? 0) >= rewardVoucher.max_uses_per_customer) {
1744
+ rewardVoucherLimitExhausted = true;
1745
+ break;
1746
+ }
1747
+ }
1889
1748
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
1890
1749
  const isRedeemed = redeemedTimes > 0;
1891
1750
  stats.redeemed_times = redeemedTimes;
@@ -1946,7 +1805,22 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1946
1805
  else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS) {
1947
1806
  if (offer.reward_gift_cards == null)
1948
1807
  continue;
1949
- const { rewardGiftCardUnavailable, rewardGiftCardLimitExhausted } = getRewardGiftCardAvailability(Object.keys(offer.reward_gift_cards.gift_card_ids));
1808
+ const gcIds = Object.keys(offer.reward_gift_cards.gift_card_ids);
1809
+ let rewardGiftCardUnavailable = false;
1810
+ let rewardGiftCardLimitExhausted = false;
1811
+ for (let gcIdx = 0; gcIdx < gcIds.length; gcIdx++) {
1812
+ const giftCard = allGiftCardsById.get(gcIds[gcIdx]);
1813
+ if (giftCard == null || isGiftCardRewardResourceUnavailable(giftCard)) {
1814
+ rewardGiftCardUnavailable = true;
1815
+ break;
1816
+ }
1817
+ if (customerOfferRedemptionCounts != null &&
1818
+ giftCard.max_uses_per_customer != null &&
1819
+ (customerOfferRedemptionCounts[giftCard._id] ?? 0) >= giftCard.max_uses_per_customer) {
1820
+ rewardGiftCardLimitExhausted = true;
1821
+ break;
1822
+ }
1823
+ }
1950
1824
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
1951
1825
  const isRedeemed = redeemedTimes > 0;
1952
1826
  stats.redeemed_times = redeemedTimes;
@@ -2007,7 +1881,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2007
1881
  stats.claimable = false;
2008
1882
  stats.message = '⛔️ You have reached your personal limit for this offer ⛔️';
2009
1883
  }
2010
- clearBlockedRewardApplicableQuantity(offer, stats);
2011
1884
  stats.action_hint = getActionHint(offer, stats.claimable);
2012
1885
  offersWithStats.push({
2013
1886
  offer,
@@ -2259,7 +2132,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2259
2132
  stats.claimable = false;
2260
2133
  stats.message = '⛔️ You have reached your personal limit for this offer ⛔️';
2261
2134
  }
2262
- clearBlockedRewardApplicableQuantity(offer, stats);
2263
2135
  stats.action_hint = getActionHint(offer, stats.claimable);
2264
2136
  offersWithStats.push({
2265
2137
  offer,
@@ -2512,7 +2384,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2512
2384
  stats.claimable = false;
2513
2385
  stats.message = '⛔️ You have reached your personal limit for this offer ⛔️';
2514
2386
  }
2515
- clearBlockedRewardApplicableQuantity(offer, stats);
2516
2387
  stats.action_hint = getActionHint(offer, stats.claimable);
2517
2388
  offersWithStats.push({
2518
2389
  offer,
@@ -2537,44 +2408,18 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2537
2408
  const referencedVouchers = voucher_ids
2538
2409
  .map((voucherId) => vouchersById.get(voucherId))
2539
2410
  .filter((voucher) => voucher != null);
2540
- const getVoucherCode = (voucher) => voucher.code.trim().toUpperCase();
2541
- const getVoucherSpendableCount = (voucher) => spendableVoucherCodesByCode[getVoucherCode(voucher)] ?? 0;
2542
- const isVoucherPathwayUsageAvailable = (voucher) => {
2543
- const maxUsesPerCustomer = voucher.max_uses_per_customer;
2544
- if (maxUsesPerCustomer == null) {
2545
- return true;
2546
- }
2547
- if (customerOfferRedemptionCounts == null) {
2548
- // Defensive block when capped voucher counts are unavailable.
2549
- return false;
2550
- }
2551
- return getCustomerUsedRedemptionCount(customerOfferRedemptionCounts, voucher._id) < maxUsesPerCustomer;
2552
- };
2553
- // Wallet-first unlock policy for voucher pathways:
2554
- // - A referenced voucher must exist in wallet inventory (spendable > 0)
2555
- // to unlock claimability.
2556
- // - Applied voucher code is optional and only used to disambiguate when
2557
- // multiple referenced vouchers are available in wallet.
2558
- const referencedVouchersWithWalletAccess = referencedVouchers.filter((voucher) => getVoucherSpendableCount(voucher) > 0 && isVoucherPathwayUsageAvailable(voucher));
2559
- const matchedReferencedVoucherByReference = normalizedVoucherRef == null
2560
- ? null
2561
- : (referencedVouchers.find((voucher) => getVoucherCode(voucher) === normalizedVoucherRef) ?? null);
2562
- const matchedVoucherForAccess = normalizedVoucherRef == null
2411
+ const matchedVoucher = normalizedVoucherRef == null
2563
2412
  ? null
2564
- : (referencedVouchersWithWalletAccess.find((voucher) => getVoucherCode(voucher) === normalizedVoucherRef) ??
2565
- null);
2566
- const firstReferencedVoucherWithWalletInventory = referencedVouchers.find((voucher) => getVoucherSpendableCount(voucher) > 0) ?? null;
2567
- const matchedVoucher = matchedVoucherForAccess ?? referencedVouchersWithWalletAccess[0] ?? null;
2568
- const matchingVoucherContext = matchedVoucher ?? matchedReferencedVoucherByReference ?? firstReferencedVoucherWithWalletInventory ?? null;
2569
- const hasMatchingVoucher = matchingVoucherContext != null;
2570
- const normalizedMatchedVoucherCode = matchingVoucherContext != null ? getVoucherCode(matchingVoucherContext) : null;
2413
+ : (referencedVouchers.find((voucher) => voucher.code.trim().toUpperCase() === normalizedVoucherRef) ?? null);
2414
+ const hasMatchingVoucher = matchedVoucher != null;
2415
+ const normalizedMatchedVoucherCode = matchedVoucher?.code.trim().toUpperCase() ?? null;
2571
2416
  const redeemedTimesForOffer = getOfferRedeemedTimes(offer._id);
2572
2417
  const spendableVoucherCount = normalizedMatchedVoucherCode == null ? 0 : (spendableVoucherCodesByCode[normalizedMatchedVoucherCode] ?? 0);
2573
- const hasVoucherAccess = matchedVoucher != null || (redeemedTimesForOffer > 0 && matchingVoucherContext != null);
2418
+ const hasVoucherAccess = matchedVoucher != null && (matchedVoucher.is_public || spendableVoucherCount > 0 || redeemedTimesForOffer > 0);
2574
2419
  const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount || 1);
2575
2420
  if (!hasMatchingVoucher) {
2576
2421
  stats.progress = 0;
2577
- stats.message = `Add a matching voucher to your wallet to unlock this offer`;
2422
+ stats.message = `Apply a matching voucher to unlock this offer`;
2578
2423
  }
2579
2424
  else if (!hasVoucherAccess) {
2580
2425
  stats.progress = 0;
@@ -2659,7 +2504,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2659
2504
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
2660
2505
  const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
2661
2506
  const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
2662
- const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
2507
+ const voucherInventoryClaimCap = matchedVoucher != null && !matchedVoucher.is_public
2508
+ ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer)
2509
+ : Infinity;
2663
2510
  const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
2664
2511
  const maxRedeemableClaims = getPointsMaxRedeemableClaims({
2665
2512
  offerToCheck: offer,
@@ -2716,7 +2563,9 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2716
2563
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
2717
2564
  const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
2718
2565
  const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
2719
- const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
2566
+ const voucherInventoryClaimCap = matchedVoucher != null && !matchedVoucher.is_public
2567
+ ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer)
2568
+ : Infinity;
2720
2569
  const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
2721
2570
  const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
2722
2571
  offerToCheck: offer,
@@ -2786,10 +2635,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2786
2635
  offerToCheck: offer,
2787
2636
  stats,
2788
2637
  });
2789
- applyVoucherPathwayCartContextBlock({
2790
- offerToCheck: offer,
2791
- statsToUpdate: stats,
2792
- });
2793
2638
  if (stats.progress >= 100 && isOfferUsesPerCustomerExhausted(offer)) {
2794
2639
  if (stats.claimable) {
2795
2640
  totalClaimableOffers = totalClaimableOffers.filter((id) => id !== offer._id);
@@ -2799,7 +2644,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2799
2644
  stats.claimable = false;
2800
2645
  stats.message = '⛔️ You have reached your personal limit for this offer ⛔️';
2801
2646
  }
2802
- clearBlockedRewardApplicableQuantity(offer, stats);
2803
2647
  stats.action_hint = getActionHint(offer, stats.claimable);
2804
2648
  offersWithStats.push({
2805
2649
  offer,
@@ -2817,7 +2661,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2817
2661
  }
2818
2662
  }
2819
2663
  // When customerOfferRedemptionCounts is null, invalidate claimability for offers whose
2820
- // reward vouchers/gift-cards have assignment limits, since we cannot verify the limit.
2664
+ // reward vouchers/gift-cards have max_uses_per_customer set, since we cannot verify the limit.
2821
2665
  if (customerOfferRedemptionCounts == null) {
2822
2666
  for (let i = 0; i < offersWithStats.length; i++) {
2823
2667
  const { offer, stats } = offersWithStats[i];
@@ -2826,8 +2670,8 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2826
2670
  if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER && offer.reward_voucher != null) {
2827
2671
  const vIds = Object.keys(offer.reward_voucher.voucher_ids);
2828
2672
  for (let vIdx = 0; vIdx < vIds.length; vIdx++) {
2829
- const rewardVoucher = allVouchersById.get(vIds[vIdx]);
2830
- if (rewardVoucher != null && getRewardMaxAssignmentsPerCustomer(rewardVoucher) != null) {
2673
+ const rewardVoucher = vouchersById.get(vIds[vIdx]);
2674
+ if (rewardVoucher != null && rewardVoucher.max_uses_per_customer != null) {
2831
2675
  stats.claimable = false;
2832
2676
  stats.applicable_quantity = 0;
2833
2677
  unlockedOffersApplicableTimes[offer._id] = 0;
@@ -2843,8 +2687,8 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2843
2687
  stats.claimable) {
2844
2688
  const gcIds = Object.keys(offer.reward_gift_cards.gift_card_ids);
2845
2689
  for (let gcIdx = 0; gcIdx < gcIds.length; gcIdx++) {
2846
- const giftCard = allGiftCardsById.get(gcIds[gcIdx]);
2847
- if (giftCard != null && getRewardMaxAssignmentsPerCustomer(giftCard) != null) {
2690
+ const giftCard = giftCardsById.get(gcIds[gcIdx]);
2691
+ if (giftCard != null && giftCard.max_uses_per_customer != null) {
2848
2692
  stats.claimable = false;
2849
2693
  stats.applicable_quantity = 0;
2850
2694
  unlockedOffersApplicableTimes[offer._id] = 0;
@@ -38,6 +38,9 @@ export * from './operational_roles';
38
38
  export * from './order';
39
39
  export * from './printer_settings';
40
40
  export * from './public_holidays';
41
+ export * from './purchase_order_receipts';
42
+ export * from './purchase_order_rfq';
43
+ export * from './purchase_order_vendor_returns';
41
44
  export * from './purchase_orders';
42
45
  export * from './reservations';
43
46
  export * from './reviews';
@@ -54,6 +54,9 @@ __exportStar(require("./operational_roles"), exports);
54
54
  __exportStar(require("./order"), exports);
55
55
  __exportStar(require("./printer_settings"), exports);
56
56
  __exportStar(require("./public_holidays"), exports);
57
+ __exportStar(require("./purchase_order_receipts"), exports);
58
+ __exportStar(require("./purchase_order_rfq"), exports);
59
+ __exportStar(require("./purchase_order_vendor_returns"), exports);
57
60
  __exportStar(require("./purchase_orders"), exports);
58
61
  __exportStar(require("./reservations"), exports);
59
62
  __exportStar(require("./reviews"), exports);