@pisell/pisellos 0.10.49 → 0.10.51

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 (62) hide show
  1. package/dist/modules/Discount/types.d.ts +2 -0
  2. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  3. package/dist/modules/FulfillmentTiming/index.js +407 -0
  4. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  5. package/dist/modules/FulfillmentTiming/types.js +1 -0
  6. package/dist/modules/OpenData/types.d.ts +6 -0
  7. package/dist/modules/Order/index.d.ts +19 -1
  8. package/dist/modules/Order/index.js +362 -217
  9. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  10. package/dist/modules/Order/pickupTiming.js +53 -0
  11. package/dist/modules/Order/types.d.ts +11 -1
  12. package/dist/modules/Order/utils.d.ts +10 -0
  13. package/dist/modules/Order/utils.js +145 -85
  14. package/dist/modules/Rules/index.js +45 -26
  15. package/dist/modules/Rules/types.d.ts +4 -0
  16. package/dist/modules/index.d.ts +1 -0
  17. package/dist/modules/index.js +1 -0
  18. package/dist/server/modules/order/index.d.ts +8 -0
  19. package/dist/server/modules/order/index.js +506 -453
  20. package/dist/server/modules/order/types.d.ts +1 -0
  21. package/dist/server/utils/small-ticket.js +173 -95
  22. package/dist/solution/BaseSales/index.d.ts +23 -0
  23. package/dist/solution/BaseSales/index.js +1216 -1031
  24. package/dist/solution/BaseSales/pickupTiming.d.ts +37 -0
  25. package/dist/solution/BaseSales/pickupTiming.js +482 -0
  26. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  27. package/dist/solution/BookingByStep/index.d.ts +1 -1
  28. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  29. package/dist/solution/UnifiedBookingSales/index.d.ts +2 -0
  30. package/dist/solution/UnifiedBookingSales/index.js +583 -531
  31. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  32. package/lib/modules/Discount/types.d.ts +2 -0
  33. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  34. package/lib/modules/FulfillmentTiming/index.js +359 -0
  35. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  36. package/lib/modules/FulfillmentTiming/types.js +5 -0
  37. package/lib/modules/OpenData/types.d.ts +6 -0
  38. package/lib/modules/Order/index.d.ts +19 -1
  39. package/lib/modules/Order/index.js +120 -7
  40. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  41. package/lib/modules/Order/pickupTiming.js +61 -0
  42. package/lib/modules/Order/types.d.ts +11 -1
  43. package/lib/modules/Order/utils.d.ts +10 -0
  44. package/lib/modules/Order/utils.js +58 -4
  45. package/lib/modules/Rules/index.js +24 -13
  46. package/lib/modules/Rules/types.d.ts +4 -0
  47. package/lib/modules/index.d.ts +1 -0
  48. package/lib/modules/index.js +11 -0
  49. package/lib/server/modules/order/index.d.ts +8 -0
  50. package/lib/server/modules/order/index.js +19 -0
  51. package/lib/server/modules/order/types.d.ts +1 -0
  52. package/lib/server/utils/small-ticket.js +93 -22
  53. package/lib/solution/BaseSales/index.d.ts +23 -0
  54. package/lib/solution/BaseSales/index.js +104 -1
  55. package/lib/solution/BaseSales/pickupTiming.d.ts +37 -0
  56. package/lib/solution/BaseSales/pickupTiming.js +222 -0
  57. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  58. package/lib/solution/BookingByStep/index.d.ts +1 -1
  59. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  60. package/lib/solution/UnifiedBookingSales/index.d.ts +2 -0
  61. package/lib/solution/UnifiedBookingSales/index.js +20 -0
  62. package/package.json +1 -1
@@ -20,6 +20,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
20
20
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
21
21
  import dayjs from 'dayjs';
22
22
  import Decimal from 'decimal.js';
23
+ import { isFulfillmentTimingBooking } from "../../modules/Order/pickupTiming";
23
24
  var DEFAULT_LOCALES = ['en', 'zh_CN'];
24
25
  var SERVICE_TYPE_LABEL_KEYS = {
25
26
  takeaway: 'takeAway',
@@ -530,7 +531,7 @@ function isSameReceiptDiscount(left, right) {
530
531
  return leftResourceId === rightResourceId && getReceiptDiscountBundleMapId(left) === getReceiptDiscountBundleMapId(right) && String((_ref10 = (_ref11 = (_left$amount = left === null || left === void 0 ? void 0 : left.amount) !== null && _left$amount !== void 0 ? _left$amount : left === null || left === void 0 ? void 0 : left.value) !== null && _ref11 !== void 0 ? _ref11 : left === null || left === void 0 ? void 0 : left.discount_amount) !== null && _ref10 !== void 0 ? _ref10 : '') === String((_ref12 = (_ref13 = (_right$amount = right === null || right === void 0 ? void 0 : right.amount) !== null && _right$amount !== void 0 ? _right$amount : right === null || right === void 0 ? void 0 : right.value) !== null && _ref13 !== void 0 ? _ref13 : right === null || right === void 0 ? void 0 : right.discount_amount) !== null && _ref12 !== void 0 ? _ref12 : '');
531
532
  }
532
533
  function resolveProductBasePrice(product) {
533
- var _product$product_vari, _product$_origin, _product$_origin2;
534
+ var _product$product_vari, _ref14, _ref15, _product$product_quan2, _product$product_sku, _product$_origin, _product$_origin2;
534
535
  var metadata = product.metadata || {};
535
536
  var origin = product._origin || metadata.origin || {};
536
537
  var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
@@ -538,7 +539,18 @@ function resolveProductBasePrice(product) {
538
539
  return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
539
540
  }) : undefined;
540
541
  var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
541
- return firstPresentValue(metadata.source_product_price, variant === null || variant === void 0 ? void 0 : variant.price, (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.price, (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
542
+ var quantity = toNumber((_ref14 = (_ref15 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref15 !== void 0 ? _ref15 : product.num) !== null && _ref14 !== void 0 ? _ref14 : 1, 1);
543
+ var hasEntitlementPass = normalizeArray(product.discount_list).some(function (discount) {
544
+ return getProductWalletDiscountType(discount) === 'entitlement_pass';
545
+ });
546
+ var hasOptions = normalizeArray(product.options).length > 0 || normalizeArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option).length > 0;
547
+ var hasCombinations = normalizeArray(product.combinations).length > 0 || normalizeArray(product.product_bundle).length > 0 || normalizeArray(product.bundle).length > 0;
548
+ var aggregateSourcePrice = firstPresentValue(metadata.source_product_price, product.price);
549
+ var originalPrice = product.original_price;
550
+ // 部分旧 entitlement 商品把 source/price 持久化成了整行总价,但
551
+ // original_price 仍是单件价。仅在等式能明确证明该口径时做窄幅回退。
552
+ var useOriginalPriceAsLegacyUnitPrice = hasEntitlementPass && quantity > 1 && !hasOptions && !hasCombinations && isNumericAmount(aggregateSourcePrice) && isNumericAmount(originalPrice) && new Decimal(aggregateSourcePrice).eq(new Decimal(originalPrice).mul(quantity));
553
+ return firstPresentValue(useOriginalPriceAsLegacyUnitPrice ? originalPrice : undefined, metadata.source_product_price, variant === null || variant === void 0 ? void 0 : variant.price, (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.price, (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
542
554
  }
543
555
  function normalizeProductDiscounts(params) {
544
556
  var product = params.product,
@@ -546,15 +558,17 @@ function normalizeProductDiscounts(params) {
546
558
  currencySymbol = params.currencySymbol,
547
559
  quantity = params.quantity;
548
560
  var rows = normalizeArray(product.discount_list).filter(function (discount) {
549
- var _ref14, _discount$amount;
550
- var amount = (_ref14 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref14 !== void 0 ? _ref14 : discount.discount_amount;
561
+ var _ref16, _discount$amount;
562
+ var amount = (_ref16 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref16 !== void 0 ? _ref16 : discount.discount_amount;
551
563
  return isNonZero(amount);
552
564
  }).map(function (discount) {
553
- var _ref15, _discount$amount2;
565
+ var _ref17, _discount$amount2;
554
566
  var title = resolveDiscountTitleWithPercent(discount, locale);
555
- var amount = (_ref15 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref15 !== void 0 ? _ref15 : discount.discount_amount;
567
+ var amount = (_ref17 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
556
568
  var isMarkup = isManualMarkup(discount);
557
- var totalAmount = new Decimal(toMoneyNumber(amount)).mul(quantity);
569
+ var isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
570
+ var isEntitlementPass = getProductWalletDiscountType(discount) === 'entitlement_pass';
571
+ var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount || isEntitlementPass ? 1 : quantity);
558
572
  var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
559
573
  return {
560
574
  item: title,
@@ -564,24 +578,24 @@ function normalizeProductDiscounts(params) {
564
578
  });
565
579
  return rows.sort(function (left, right) {
566
580
  return Number(right.isMarkup) - Number(left.isMarkup);
567
- }).map(function (_ref16) {
568
- var _isMarkup = _ref16.isMarkup,
569
- row = _objectWithoutProperties(_ref16, _excluded);
581
+ }).map(function (_ref18) {
582
+ var _isMarkup = _ref18.isMarkup,
583
+ row = _objectWithoutProperties(_ref18, _excluded);
570
584
  return row;
571
585
  });
572
586
  }
573
587
  function isManualMarkup(discount) {
574
- var _discount$discount, _ref17, _discount$amount3;
588
+ var _discount$discount, _ref19, _discount$amount3;
575
589
  if (discount.type !== 'product') return false;
576
590
  if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
577
- var amount = (_ref17 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
591
+ var amount = (_ref19 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref19 !== void 0 ? _ref19 : discount.discount_amount;
578
592
  return new Decimal(toMoneyNumber(amount)).isNegative();
579
593
  }
580
594
  function hasProductDiscount(product) {
581
595
  var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
582
596
  var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
583
- var _ref18, _discount$amount4;
584
- return isNonZero((_ref18 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref18 !== void 0 ? _ref18 : discount.discount_amount);
597
+ var _ref20, _discount$amount4;
598
+ return isNonZero((_ref20 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref20 !== void 0 ? _ref20 : discount.discount_amount);
585
599
  });
586
600
  return hasDiscountListAmount || extensionList.some(function (row) {
587
601
  return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
@@ -654,6 +668,9 @@ function buildProductQuantityPriceText(params) {
654
668
  function resolveDiscountTitleWithPercent(discount, locale) {
655
669
  var _discount$discount2, _discount$discount$di, _discount$discount3;
656
670
  var title = resolveDiscountTitle(discount, locale);
671
+ if (getProductWalletDiscountType(discount) === 'entitlement_pass') {
672
+ return title;
673
+ }
657
674
  var percentRaw = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.percent;
658
675
  var cardType = (_discount$discount$di = (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.discount_card_type) !== null && _discount$discount$di !== void 0 ? _discount$discount$di : 'percent';
659
676
  var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
@@ -663,8 +680,8 @@ function resolveDiscountTitleWithPercent(discount, locale) {
663
680
  return "".concat(title, " (").concat(percent, "%)");
664
681
  }
665
682
  function resolveDiscountTitle(discount, locale) {
666
- var _ref19, _ref20, _ref21, _ref22, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
667
- var title = getLocalizedValue((_ref19 = (_ref20 = (_ref21 = (_ref22 = (_discount$discount$na = (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.title) !== null && _ref22 !== void 0 ? _ref22 : (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.message) !== null && _ref21 !== void 0 ? _ref21 : discount.name) !== null && _ref20 !== void 0 ? _ref20 : discount.title) !== null && _ref19 !== void 0 ? _ref19 : discount.message, locale);
683
+ var _ref21, _ref22, _ref23, _ref24, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
684
+ var title = getLocalizedValue((_ref21 = (_ref22 = (_ref23 = (_ref24 = (_discount$discount$na = (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.title) !== null && _ref24 !== void 0 ? _ref24 : (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.message) !== null && _ref23 !== void 0 ? _ref23 : discount.name) !== null && _ref22 !== void 0 ? _ref22 : discount.title) !== null && _ref21 !== void 0 ? _ref21 : discount.message, locale);
668
685
  if (title) return title;
669
686
  if (discount.type === 'product') {
670
687
  return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
@@ -684,17 +701,17 @@ function resolveProductTitle(params) {
684
701
  return getProductTitleSource(fallbackProduct, locale);
685
702
  }
686
703
  function normalizeProductOptions(params) {
687
- var _product$product_sku;
704
+ var _product$product_sku2;
688
705
  var product = params.product,
689
706
  locale = params.locale,
690
707
  currencySymbol = params.currencySymbol,
691
708
  parentProduct = params.parentProduct;
692
- var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option) ? product.product_sku.option : [];
709
+ var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$product_sku2 = product.product_sku) === null || _product$product_sku2 === void 0 ? void 0 : _product$product_sku2.option) ? product.product_sku.option : [];
693
710
  return rawOptions.map(function (option) {
694
- var _ref23, _option$original_pric, _ref24, _option$num, _ref25, _option$value;
695
- var price = (_ref23 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref23 !== void 0 ? _ref23 : option.price;
696
- var quantity = toNumber((_ref24 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref24 !== void 0 ? _ref24 : 1, 1);
697
- var value = (_ref25 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref25 !== void 0 ? _ref25 : option.item;
711
+ var _ref25, _option$original_pric, _ref26, _option$num, _ref27, _option$value;
712
+ var price = (_ref25 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref25 !== void 0 ? _ref25 : option.price;
713
+ var quantity = toNumber((_ref26 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
714
+ var value = (_ref27 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref27 !== void 0 ? _ref27 : option.item;
698
715
  var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
699
716
  option: option,
700
717
  parentProduct: parentProduct,
@@ -721,7 +738,7 @@ function normalizeProductCombinations(params) {
721
738
  parentProduct = params.parentProduct;
722
739
  var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
723
740
  return bundles.map(function (bundle) {
724
- var _ref26, _bundle$num;
741
+ var _ref28, _bundle$num;
725
742
  var combinationsOptions = normalizeProductOptions({
726
743
  product: {},
727
744
  locale: locale,
@@ -737,7 +754,7 @@ function normalizeProductCombinations(params) {
737
754
  });
738
755
  var productNote = resolveProductNote(bundle, locale);
739
756
  var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
740
- var quantity = toNumber((_ref26 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
757
+ var quantity = toNumber((_ref28 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref28 !== void 0 ? _ref28 : 1, 1);
741
758
  var formattedPrice = formatBundlePrice(bundle, currencySymbol);
742
759
  var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
743
760
  var explicitBasePrice = resolveCombinationBasePrice(bundle);
@@ -774,7 +791,7 @@ function normalizeProductCombinations(params) {
774
791
  }
775
792
  function normalizeExistingCombinations(combinations, locale, currencySymbol) {
776
793
  return combinations.map(function (combination) {
777
- var _ref27, _ref28, _combination$product_, _firstPresentValue;
794
+ var _ref29, _ref30, _combination$product_, _firstPresentValue;
778
795
  if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
779
796
  return combination;
780
797
  }
@@ -787,12 +804,14 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
787
804
  options: rawOptions
788
805
  });
789
806
  var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
807
+ var productTitle = getBundleProductTitleSource(combination, locale);
790
808
  var snapshot = _objectSpread({}, combination);
809
+ delete snapshot.product_title;
791
810
  delete snapshot.product_note;
792
811
  delete snapshot.note;
793
812
  delete snapshot.combinations;
794
813
  delete snapshot.discount_list;
795
- var quantity = toNumber((_ref27 = (_ref28 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref28 !== void 0 ? _ref28 : combination.quantity) !== null && _ref27 !== void 0 ? _ref27 : 1, 1);
814
+ var quantity = toNumber((_ref29 = (_ref30 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref30 !== void 0 ? _ref30 : combination.quantity) !== null && _ref29 !== void 0 ? _ref29 : 1, 1);
796
815
  var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
797
816
  var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
798
817
  return option.total_price;
@@ -807,7 +826,9 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
807
826
  originalPrice: unitPrice
808
827
  });
809
828
  var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
810
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), {}, {
829
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), productTitle ? {
830
+ product_title: productTitle
831
+ } : {}), {}, {
811
832
  product_quantity: quantity,
812
833
  total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
813
834
  }, shouldIncludeBasePrice ? {
@@ -875,23 +896,23 @@ function buildProductAllergyMap(order, locale) {
875
896
  return allergyByProductUid;
876
897
  }
877
898
  function resolveBundleProductTitle(params) {
878
- var _ref29, _ref30, _bundle$bundle_produc;
899
+ var _ref31, _ref32, _bundle$bundle_produc;
879
900
  var bundle = params.bundle,
880
901
  productMap = params.productMap,
881
902
  locale = params.locale,
882
903
  parentProduct = params.parentProduct;
883
- var ownTitle = getProductTitleSource(bundle, locale);
904
+ var ownTitle = getBundleProductTitleSource(bundle, locale);
884
905
  if (ownTitle) return ownTitle;
885
906
  var parentBundleItem = resolveBundleItemFromParentProduct({
886
907
  bundle: bundle,
887
908
  parentProduct: parentProduct
888
909
  });
889
- var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
910
+ var parentBundleTitle = parentBundleItem ? getBundleProductTitleSource(parentBundleItem, locale) : '';
890
911
  if (parentBundleTitle) return parentBundleTitle;
891
- var productId = (_ref29 = (_ref30 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref30 !== void 0 ? _ref30 : bundle.product_id) !== null && _ref29 !== void 0 ? _ref29 : bundle.id;
912
+ var productId = (_ref31 = (_ref32 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref32 !== void 0 ? _ref32 : bundle.product_id) !== null && _ref31 !== void 0 ? _ref31 : bundle.id;
892
913
  var fallbackProduct = resolveProductFromMap(productId, productMap);
893
914
  if (!fallbackProduct) return '';
894
- return getProductTitleSource(fallbackProduct, locale);
915
+ return getBundleProductTitleSource(fallbackProduct, locale);
895
916
  }
896
917
  function resolveProductFromMap(productId, productMap) {
897
918
  if (productId === undefined || productId === null || productId === '') return null;
@@ -940,10 +961,10 @@ function resolveVariantTextFromSkuKey(params) {
940
961
  }
941
962
  function resolveVariantTextFromNameMap(params) {
942
963
  if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
943
- return Object.entries(params.nameMap).map(function (_ref31) {
944
- var _ref32 = _slicedToArray(_ref31, 2),
945
- groupPositionId = _ref32[0],
946
- value = _ref32[1];
964
+ return Object.entries(params.nameMap).map(function (_ref33) {
965
+ var _ref34 = _slicedToArray(_ref33, 2),
966
+ groupPositionId = _ref34[0],
967
+ value = _ref34[1];
947
968
  var group = resolveVariantGroup(params.parentProduct, groupPositionId);
948
969
  if (!group) return '';
949
970
  var groupName = getLocalizedValue(group.name, params.locale);
@@ -974,15 +995,19 @@ function resolveVariantItem(group, itemPositionId) {
974
995
  }
975
996
  function getProductTitleSource(source, locale) {
976
997
  if (!source || _typeof(source) !== 'object') return '';
977
- return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
998
+ return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
999
+ }
1000
+ function getBundleProductTitleSource(source, locale) {
1001
+ if (!source || _typeof(source) !== 'object') return '';
1002
+ return resolveTitleValue(source.bundle_title, locale) || resolveTitleValue(source.trans_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
978
1003
  }
979
1004
  function resolveTitleValue(value, locale) {
980
- var _ref33, _ref34, _ref35, _ref36, _value$locale;
1005
+ var _ref35, _ref36, _ref37, _ref38, _value$locale;
981
1006
  if (value === undefined || value === null) return '';
982
1007
  if (_typeof(value) !== 'object') return stringify(value);
983
1008
  var dashedLocale = locale.replace('_', '-');
984
1009
  var underscoredLocale = locale.replace('-', '_');
985
- return stringify((_ref33 = (_ref34 = (_ref35 = (_ref36 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref36 !== void 0 ? _ref36 : value[underscoredLocale]) !== null && _ref35 !== void 0 ? _ref35 : value.original) !== null && _ref34 !== void 0 ? _ref34 : value.auto) !== null && _ref33 !== void 0 ? _ref33 : '');
1010
+ return stringify((_ref35 = (_ref36 = (_ref37 = (_ref38 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref38 !== void 0 ? _ref38 : value[underscoredLocale]) !== null && _ref37 !== void 0 ? _ref37 : value.original) !== null && _ref36 !== void 0 ? _ref36 : value.auto) !== null && _ref35 !== void 0 ? _ref35 : '');
986
1011
  }
987
1012
  function resolveOptionTitleFromParentProduct(params) {
988
1013
  var option = params.option,
@@ -1000,17 +1025,17 @@ function flattenOptionItems(parentProduct) {
1000
1025
  return optionGroups.flatMap(function (group) {
1001
1026
  var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
1002
1027
  return items.map(function (item) {
1003
- var _ref37, _item$option_group_id;
1028
+ var _ref39, _item$option_group_id;
1004
1029
  return _objectSpread(_objectSpread({}, item), {}, {
1005
- option_group_id: (_ref37 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref37 !== void 0 ? _ref37 : group.option_group_id
1030
+ option_group_id: (_ref39 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref39 !== void 0 ? _ref39 : group.option_group_id
1006
1031
  });
1007
1032
  });
1008
1033
  });
1009
1034
  }
1010
1035
  function isOptionItemMatch(option, item) {
1011
- var _ref38, _option$option_group_, _ref39, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
1012
- var optionItemId = (_ref38 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref38 !== void 0 ? _ref38 : option.id;
1013
- var itemId = (_ref39 = (_item$option_group_it = item.option_group_item_id) !== null && _item$option_group_it !== void 0 ? _item$option_group_it : item.product_option_item_id) !== null && _ref39 !== void 0 ? _ref39 : item.id;
1036
+ var _ref40, _option$option_group_, _ref41, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
1037
+ var optionItemId = (_ref40 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref40 !== void 0 ? _ref40 : option.id;
1038
+ var itemId = (_ref41 = (_item$option_group_it = item.option_group_item_id) !== null && _item$option_group_it !== void 0 ? _item$option_group_it : item.product_option_item_id) !== null && _ref41 !== void 0 ? _ref41 : item.id;
1014
1039
  if (!isSameId(optionItemId, itemId)) return false;
1015
1040
  var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
1016
1041
  var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
@@ -1020,16 +1045,16 @@ function isOptionItemMatch(option, item) {
1020
1045
  return true;
1021
1046
  }
1022
1047
  function resolveBundleItemFromParentProduct(params) {
1023
- var _ref40, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref42, _bundle$bundle_produc2;
1048
+ var _ref42, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref44, _bundle$bundle_produc2;
1024
1049
  var bundle = params.bundle,
1025
1050
  parentProduct = params.parentProduct;
1026
1051
  if (!parentProduct) return null;
1027
1052
  var bundleItems = flattenBundleItems(parentProduct);
1028
- var bundleVariantId = (_ref40 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref40 !== void 0 ? _ref40 : bundle.product_variant_id;
1053
+ var bundleVariantId = (_ref42 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref42 !== void 0 ? _ref42 : bundle.product_variant_id;
1029
1054
  if (isNonZeroId(bundleVariantId)) {
1030
1055
  var matchedByVariant = bundleItems.find(function (item) {
1031
- var _ref41, _item$bundle_variant_;
1032
- return isSameId((_ref41 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref41 !== void 0 ? _ref41 : item.product_variant_id, bundleVariantId);
1056
+ var _ref43, _item$bundle_variant_;
1057
+ return isSameId((_ref43 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref43 !== void 0 ? _ref43 : item.product_variant_id, bundleVariantId);
1033
1058
  });
1034
1059
  if (matchedByVariant) return matchedByVariant;
1035
1060
  }
@@ -1042,18 +1067,18 @@ function resolveBundleItemFromParentProduct(params) {
1042
1067
  if (matchedByBundleId) return matchedByBundleId;
1043
1068
  }
1044
1069
  var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
1045
- var bundleProductId = (_ref42 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref42 !== void 0 ? _ref42 : bundle.product_id;
1070
+ var bundleProductId = (_ref44 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref44 !== void 0 ? _ref44 : bundle.product_id;
1046
1071
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
1047
1072
  var matchedByGroupAndProduct = bundleItems.find(function (item) {
1048
- var _item$group_id, _ref43, _item$bundle_product_;
1049
- return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref43 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref43 !== void 0 ? _ref43 : item.product_id, bundleProductId);
1073
+ var _item$group_id, _ref45, _item$bundle_product_;
1074
+ return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref45 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref45 !== void 0 ? _ref45 : item.product_id, bundleProductId);
1050
1075
  });
1051
1076
  if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
1052
1077
  }
1053
1078
  if (isPresentId(bundleProductId)) {
1054
1079
  return bundleItems.find(function (item) {
1055
- var _ref44, _item$bundle_product_2;
1056
- return isSameId((_ref44 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref44 !== void 0 ? _ref44 : item.product_id, bundleProductId);
1080
+ var _ref46, _item$bundle_product_2;
1081
+ return isSameId((_ref46 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref46 !== void 0 ? _ref46 : item.product_id, bundleProductId);
1057
1082
  }) || null;
1058
1083
  }
1059
1084
  return null;
@@ -1063,9 +1088,9 @@ function flattenBundleItems(parentProduct) {
1063
1088
  return bundleGroups.flatMap(function (group) {
1064
1089
  var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
1065
1090
  return items.map(function (item) {
1066
- var _ref45, _item$group_id2;
1091
+ var _ref47, _item$group_id2;
1067
1092
  return _objectSpread(_objectSpread({}, item), {}, {
1068
- group_id: (_ref45 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref45 !== void 0 ? _ref45 : group.group_id
1093
+ group_id: (_ref47 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref47 !== void 0 ? _ref47 : group.group_id
1069
1094
  });
1070
1095
  });
1071
1096
  });
@@ -1089,8 +1114,8 @@ function isSameId(left, right) {
1089
1114
  return String(left) === String(right);
1090
1115
  }
1091
1116
  function formatBundlePrice(bundle, currencySymbol) {
1092
- var _ref46, _ref47, _bundle$bundle_sellin;
1093
- var value = (_ref46 = (_ref47 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref47 !== void 0 ? _ref47 : bundle.price) !== null && _ref46 !== void 0 ? _ref46 : 0;
1117
+ var _ref48, _ref49, _bundle$bundle_sellin;
1118
+ var value = (_ref48 = (_ref49 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref49 !== void 0 ? _ref49 : bundle.price) !== null && _ref48 !== void 0 ? _ref48 : 0;
1094
1119
  var amount = new Decimal(toMoneyNumber(value));
1095
1120
  // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
1096
1121
  var isNegative = bundle.price_type === 'markdown';
@@ -1108,9 +1133,9 @@ function buildFees(params) {
1108
1133
  financials = params.financials;
1109
1134
  var fees = [];
1110
1135
  for (var _i2 = 0, _normalizeArray2 = normalizeArray(order.surcharges || summary.surcharges); _i2 < _normalizeArray2.length; _i2++) {
1111
- var _ref48, _surcharge$amount;
1136
+ var _ref50, _surcharge$amount;
1112
1137
  var surcharge = _normalizeArray2[_i2];
1113
- var value = (_ref48 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref48 !== void 0 ? _ref48 : surcharge.total_amount;
1138
+ var value = (_ref50 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref50 !== void 0 ? _ref50 : surcharge.total_amount;
1114
1139
  if (!isNonZero(value)) continue;
1115
1140
  fees.push({
1116
1141
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
@@ -1212,9 +1237,9 @@ function resolveTaxTitle(params) {
1212
1237
  }
1213
1238
  function calculateProductOriginalAmount(order) {
1214
1239
  return normalizeArray(order.products).reduce(function (total, product) {
1215
- var _ref49, _ref50, _product$product_quan2, _ref51, _ref52, _ref53, _product$original_pri2;
1216
- var quantity = toNumber((_ref49 = (_ref50 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref50 !== void 0 ? _ref50 : product.num) !== null && _ref49 !== void 0 ? _ref49 : 1, 1);
1217
- var originalPrice = (_ref51 = (_ref52 = (_ref53 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref53 !== void 0 ? _ref53 : product.payment_price) !== null && _ref52 !== void 0 ? _ref52 : product.price) !== null && _ref51 !== void 0 ? _ref51 : 0;
1240
+ var _ref51, _ref52, _product$product_quan3, _ref53, _ref54, _ref55, _product$original_pri2;
1241
+ var quantity = toNumber((_ref51 = (_ref52 = (_product$product_quan3 = product.product_quantity) !== null && _product$product_quan3 !== void 0 ? _product$product_quan3 : product.quantity) !== null && _ref52 !== void 0 ? _ref52 : product.num) !== null && _ref51 !== void 0 ? _ref51 : 1, 1);
1242
+ var originalPrice = (_ref53 = (_ref54 = (_ref55 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref55 !== void 0 ? _ref55 : product.payment_price) !== null && _ref54 !== void 0 ? _ref54 : product.price) !== null && _ref53 !== void 0 ? _ref53 : 0;
1218
1243
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
1219
1244
  }, new Decimal(0));
1220
1245
  }
@@ -1243,11 +1268,21 @@ function buildDelivery(order, locale) {
1243
1268
  var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType);
1244
1269
  if (!serviceTypeLabelKey) return [];
1245
1270
  var items = [{
1246
- item: '',
1247
- value: label(locale, serviceTypeLabelKey),
1248
- size: 2,
1249
- align: 'left'
1271
+ item: label(locale, serviceTypeLabelKey),
1272
+ value: '',
1273
+ size: 2
1250
1274
  }];
1275
+ if (serviceType === 'pick_up') {
1276
+ var pickupTime = formatPickupBookingStart(order.bookings, locale);
1277
+ if (pickupTime) {
1278
+ items.push({
1279
+ item: pickupTime,
1280
+ value: '',
1281
+ size: 2
1282
+ });
1283
+ return items;
1284
+ }
1285
+ }
1251
1286
  var handoverTime = firstPresentValue(order.handover_time, order.handover_at, order.pickup_time, order.pickup_at, order.scheduled_pickup_time, order.delivery_time, order.delivery_at, order.scheduled_delivery_time, order.fulfillment_time, order.fulfillment_at, (_order$metadata3 = order.metadata) === null || _order$metadata3 === void 0 ? void 0 : _order$metadata3.handover_time, (_order$metadata4 = order.metadata) === null || _order$metadata4 === void 0 ? void 0 : _order$metadata4.handover_at, (_order$metadata5 = order.metadata) === null || _order$metadata5 === void 0 ? void 0 : _order$metadata5.pickup_time, (_order$metadata6 = order.metadata) === null || _order$metadata6 === void 0 ? void 0 : _order$metadata6.pickup_at, (_order$metadata7 = order.metadata) === null || _order$metadata7 === void 0 ? void 0 : _order$metadata7.scheduled_pickup_time, (_order$metadata8 = order.metadata) === null || _order$metadata8 === void 0 ? void 0 : _order$metadata8.delivery_time, (_order$metadata9 = order.metadata) === null || _order$metadata9 === void 0 ? void 0 : _order$metadata9.delivery_at, (_order$metadata10 = order.metadata) === null || _order$metadata10 === void 0 ? void 0 : _order$metadata10.scheduled_delivery_time, (_order$metadata11 = order.metadata) === null || _order$metadata11 === void 0 ? void 0 : _order$metadata11.fulfillment_time, (_order$metadata12 = order.metadata) === null || _order$metadata12 === void 0 ? void 0 : _order$metadata12.fulfillment_at);
1252
1287
  if (isPresentId(handoverTime)) {
1253
1288
  items.push({
@@ -1257,9 +1292,34 @@ function buildDelivery(order, locale) {
1257
1292
  }
1258
1293
  return items;
1259
1294
  }
1295
+ function formatPickupBookingStart(bookings, locale) {
1296
+ var booking = normalizeArray(bookings).find(isFulfillmentTimingBooking);
1297
+ var date = stringify(booking === null || booking === void 0 ? void 0 : booking.start_date).trim();
1298
+ var time = stringify(booking === null || booking === void 0 ? void 0 : booking.start_time).trim();
1299
+ if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/.test(date) || !/^([01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/.test(time)) {
1300
+ return '';
1301
+ }
1302
+
1303
+ // Validate only the calendar date in UTC; display the stored shop-local
1304
+ // fields verbatim so the printing device's timezone cannot shift pickup.
1305
+ var calendarDate = new Date("".concat(date, "T00:00:00.000Z"));
1306
+ if (!Number.isFinite(calendarDate.getTime()) || calendarDate.toISOString().slice(0, 10) !== date) {
1307
+ return '';
1308
+ }
1309
+ var _date$split = date.split('-'),
1310
+ _date$split2 = _slicedToArray(_date$split, 3),
1311
+ year = _date$split2[0],
1312
+ month = _date$split2[1],
1313
+ day = _date$split2[2];
1314
+ var dateText = locale === 'en' ? "".concat(day, "/").concat(month, "/").concat(year) : "".concat(year, "/").concat(month, "/").concat(day);
1315
+ return "".concat(time.slice(0, 5), " ").concat(dateText);
1316
+ }
1260
1317
  function buildAppointment(order, locale) {
1261
- var _order$metadata13, _order$metadata14, _order$form_data;
1262
- var bookings = sortBookings(normalizeArray(order.bookings));
1318
+ var _order$metadata13, _order$metadata14, _order$metadata15, _order$form_data;
1319
+ var parentScheduleId = (_order$metadata13 = order.metadata) === null || _order$metadata13 === void 0 ? void 0 : _order$metadata13.appointment_booking_parent_schedule_id;
1320
+ var bookings = sortBookings(normalizeArray(order.bookings).filter(function (booking) {
1321
+ return !isFulfillmentTimingBooking(booking) && isReceiptAppointmentBooking(booking, parentScheduleId);
1322
+ }));
1263
1323
  if (bookings.length) {
1264
1324
  var allResources = normalizeArray(order.resources || order.resource_list);
1265
1325
  return bookings.flatMap(function (booking) {
@@ -1271,13 +1331,26 @@ function buildAppointment(order, locale) {
1271
1331
  });
1272
1332
  });
1273
1333
  }
1274
- var tableName = order.table_name || ((_order$metadata13 = order.metadata) === null || _order$metadata13 === void 0 ? void 0 : _order$metadata13.table_name) || ((_order$metadata14 = order.metadata) === null || _order$metadata14 === void 0 || (_order$metadata14 = _order$metadata14.table) === null || _order$metadata14 === void 0 ? void 0 : _order$metadata14.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
1334
+ var tableName = order.table_name || ((_order$metadata14 = order.metadata) === null || _order$metadata14 === void 0 ? void 0 : _order$metadata14.table_name) || ((_order$metadata15 = order.metadata) === null || _order$metadata15 === void 0 || (_order$metadata15 = _order$metadata15.table) === null || _order$metadata15 === void 0 ? void 0 : _order$metadata15.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
1275
1335
  if (!tableName) return [];
1276
1336
  return [{
1277
1337
  item: label(locale, 'table'),
1278
1338
  value: getLocalizedValue(tableName, locale)
1279
1339
  }];
1280
1340
  }
1341
+ function isReceiptAppointmentBooking(booking, parentScheduleId) {
1342
+ if (!booking || _typeof(booking) !== 'object' || Array.isArray(booking)) {
1343
+ return false;
1344
+ }
1345
+ if (isPresentId(parentScheduleId) && isSameId(booking.schedule_event_id, parentScheduleId)) {
1346
+ return false;
1347
+ }
1348
+ var parentId = booking.parent_id;
1349
+ if (parentId === undefined || parentId === null || parentId === '') {
1350
+ return true;
1351
+ }
1352
+ return Number(parentId) !== 0;
1353
+ }
1281
1354
  function buildAppointmentRows(params) {
1282
1355
  var _booking$metadata, _booking$metadata2, _booking$holder$name, _booking$holder, _booking$metadata3;
1283
1356
  var booking = params.booking,
@@ -1349,9 +1422,9 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1349
1422
  _step3;
1350
1423
  try {
1351
1424
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1352
- var _ref55, _resource$id2;
1425
+ var _ref57, _resource$id2;
1353
1426
  var resource = _step3.value;
1354
- var id = stringify((_ref55 = (_resource$id2 = resource.id) !== null && _resource$id2 !== void 0 ? _resource$id2 : resource.resource_id) !== null && _ref55 !== void 0 ? _ref55 : resource.relation_id).trim();
1427
+ var id = stringify((_ref57 = (_resource$id2 = resource.id) !== null && _resource$id2 !== void 0 ? _resource$id2 : resource.resource_id) !== null && _ref57 !== void 0 ? _ref57 : resource.relation_id).trim();
1355
1428
  if (id) resourceIds.add(id);
1356
1429
  }
1357
1430
  } catch (err) {
@@ -1361,8 +1434,8 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1361
1434
  }
1362
1435
  if (resourceIds.size) {
1363
1436
  var matched = allResources.filter(function (resource) {
1364
- var _ref54, _resource$id;
1365
- return resourceIds.has(stringify((_ref54 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.resource_id) !== null && _ref54 !== void 0 ? _ref54 : resource.relation_id).trim());
1437
+ var _ref56, _resource$id;
1438
+ return resourceIds.has(stringify((_ref56 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.resource_id) !== null && _ref56 !== void 0 ? _ref56 : resource.relation_id).trim());
1366
1439
  });
1367
1440
  if (matched.length) return matched;
1368
1441
  }
@@ -1395,8 +1468,8 @@ function sortBookings(bookings) {
1395
1468
  }
1396
1469
  var bookingUidOrder = compareOptionalValues(firstPresentValue((_left$booking2 = left.booking) === null || _left$booking2 === void 0 || (_left$booking2 = _left$booking2.metadata) === null || _left$booking2 === void 0 ? void 0 : _left$booking2.unique_identification_number, (_left$booking3 = left.booking) === null || _left$booking3 === void 0 ? void 0 : _left$booking3.booking_uid), firstPresentValue((_right$booking2 = right.booking) === null || _right$booking2 === void 0 || (_right$booking2 = _right$booking2.metadata) === null || _right$booking2 === void 0 ? void 0 : _right$booking2.unique_identification_number, (_right$booking3 = right.booking) === null || _right$booking3 === void 0 ? void 0 : _right$booking3.booking_uid));
1397
1470
  return bookingUidOrder || left.index - right.index;
1398
- }).map(function (_ref56) {
1399
- var booking = _ref56.booking;
1471
+ }).map(function (_ref58) {
1472
+ var booking = _ref58.booking;
1400
1473
  return booking;
1401
1474
  });
1402
1475
  }
@@ -1458,8 +1531,8 @@ function buildRefundData(params) {
1458
1531
  result.set(identity, candidate);
1459
1532
  }
1460
1533
  return result;
1461
- }, new Map()).values()).filter(function (_ref57) {
1462
- var refund = _ref57.refund;
1534
+ }, new Map()).values()).filter(function (_ref59) {
1535
+ var refund = _ref59.refund;
1463
1536
  return isPrintableRefund(refund);
1464
1537
  }).sort(function (left, right) {
1465
1538
  var leftTime = refundTimestamp(left.refund);
@@ -1467,9 +1540,9 @@ function buildRefundData(params) {
1467
1540
  if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1468
1541
  return left.index - right.index;
1469
1542
  });
1470
- return refunds.map(function (_ref58) {
1543
+ return refunds.map(function (_ref60) {
1471
1544
  var _firstPresentValue8;
1472
- var refund = _ref58.refund;
1545
+ var refund = _ref60.refund;
1473
1546
  var payment = resolveRefundPayment(refund, payments);
1474
1547
  var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
1475
1548
  var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
@@ -1738,9 +1811,8 @@ function getProductEntitlementBalance(asset) {
1738
1811
  _step6;
1739
1812
  try {
1740
1813
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1741
- var _record$metadata, _record$discount10, _record$discount11;
1742
1814
  var record = _step6.value;
1743
- var balance = getEntitlementBalance((_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.balance, record.balance, (_record$discount10 = record.discount) === null || _record$discount10 === void 0 || (_record$discount10 = _record$discount10.metadata) === null || _record$discount10 === void 0 ? void 0 : _record$discount10.balance, (_record$discount11 = record.discount) === null || _record$discount11 === void 0 ? void 0 : _record$discount11.balance);
1815
+ var balance = getProductDiscountEntitlementBalance(record);
1744
1816
  if (balance) return balance;
1745
1817
  }
1746
1818
  } catch (err) {
@@ -1750,6 +1822,10 @@ function getProductEntitlementBalance(asset) {
1750
1822
  }
1751
1823
  return null;
1752
1824
  }
1825
+ function getProductDiscountEntitlementBalance(record) {
1826
+ var _record$metadata, _record$discount10, _record$discount11;
1827
+ return getEntitlementBalance((_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.balance, record.balance, (_record$discount10 = record.discount) === null || _record$discount10 === void 0 || (_record$discount10 = _record$discount10.metadata) === null || _record$discount10 === void 0 ? void 0 : _record$discount10.balance, (_record$discount11 = record.discount) === null || _record$discount11 === void 0 ? void 0 : _record$discount11.balance);
1828
+ }
1753
1829
  function getEntitlementBalance() {
1754
1830
  for (var _len3 = arguments.length, values = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1755
1831
  values[_key3] = arguments[_key3];
@@ -1860,7 +1936,7 @@ function buildPointCardSnapshotAssets(params) {
1860
1936
  codes: []
1861
1937
  })) return [];
1862
1938
  var rows = [{
1863
- item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1939
+ item: appendMaskedCardCode(stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'), pointCard.code),
1864
1940
  value: ''
1865
1941
  }];
1866
1942
  var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
@@ -2248,8 +2324,8 @@ function buildPaymentItems(params) {
2248
2324
  virtualCurrencyUnit: virtualCurrencyUnit
2249
2325
  })));
2250
2326
  } else {
2251
- var _ref59, _payment$remaining_am, _payment$metadata;
2252
- var remainingAmount = (_ref59 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref59 !== void 0 ? _ref59 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
2327
+ var _ref61, _payment$remaining_am, _payment$metadata;
2328
+ var remainingAmount = (_ref61 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref61 !== void 0 ? _ref61 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
2253
2329
  if (remainingAmount !== undefined && remainingAmount !== null) {
2254
2330
  items.push({
2255
2331
  item: label(locale, 'remainingAmount'),
@@ -2360,9 +2436,14 @@ function isPointCardPayment(payment) {
2360
2436
  return code === 'POINTCARD' || type === 'point_card';
2361
2437
  }
2362
2438
  function maskMachineCode(code) {
2363
- var text = stringify(code);
2364
- if (text.length <= 6) return text;
2365
- return "".concat(text.slice(0, 2), "**").concat(text.slice(-4));
2439
+ var text = stringify(code).trim();
2440
+ if (!text) return '';
2441
+ if (text.length <= 6) return '*'.repeat(text.length);
2442
+ return "".concat(text.slice(0, 2), "****").concat(text.slice(-4));
2443
+ }
2444
+ function appendMaskedCardCode(name, code) {
2445
+ var maskedCode = maskMachineCode(code);
2446
+ return maskedCode ? "".concat(name, "(").concat(maskedCode, ")") : name;
2366
2447
  }
2367
2448
  function trimDecimal(value) {
2368
2449
  return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
@@ -2371,16 +2452,13 @@ function getFundRecordPaymentName(payment, locale) {
2371
2452
  var fundRecord = getFundRecord(payment);
2372
2453
  if (!fundRecord) return '';
2373
2454
  var name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
2374
- var code = maskMachineCode(fundRecord.code);
2375
- if (!name && !code) return '';
2376
- if (!code) return name;
2455
+ if (!name && !maskMachineCode(fundRecord.code)) return '';
2377
2456
  var fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
2378
- return "".concat(name || fallbackName, "(").concat(code, ")");
2457
+ return appendMaskedCardCode(name || fallbackName, fundRecord.code);
2379
2458
  }
2380
2459
  function appendMachineCodeToName(name, payment) {
2381
2460
  var fundRecord = getFundRecord(payment);
2382
- if (!(fundRecord !== null && fundRecord !== void 0 && fundRecord.code)) return name;
2383
- return "".concat(name, "(").concat(maskMachineCode(fundRecord.code), ")");
2461
+ return appendMaskedCardCode(name, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.code);
2384
2462
  }
2385
2463
  function paymentMethodName(payment, locale) {
2386
2464
  var fundRecordName = getFundRecordPaymentName(payment, locale);
@@ -2412,12 +2490,12 @@ function label(locale, key) {
2412
2490
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
2413
2491
  }
2414
2492
  function getLocalizedValue(value, locale) {
2415
- var _ref60, _ref61, _ref62, _ref63, _ref64, _ref65, _value$locale2;
2493
+ var _ref62, _ref63, _ref64, _ref65, _ref66, _ref67, _value$locale2;
2416
2494
  if (value === undefined || value === null) return '';
2417
2495
  if (_typeof(value) !== 'object') return stringify(value);
2418
2496
  var dashedLocale = locale.replace('_', '-');
2419
2497
  var underscoredLocale = locale.replace('-', '_');
2420
- return stringify((_ref60 = (_ref61 = (_ref62 = (_ref63 = (_ref64 = (_ref65 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref65 !== void 0 ? _ref65 : value[underscoredLocale]) !== null && _ref64 !== void 0 ? _ref64 : value.original) !== null && _ref63 !== void 0 ? _ref63 : value.auto) !== null && _ref62 !== void 0 ? _ref62 : value.default) !== null && _ref61 !== void 0 ? _ref61 : value.en) !== null && _ref60 !== void 0 ? _ref60 : '');
2498
+ return stringify((_ref62 = (_ref63 = (_ref64 = (_ref65 = (_ref66 = (_ref67 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref67 !== void 0 ? _ref67 : value[underscoredLocale]) !== null && _ref66 !== void 0 ? _ref66 : value.original) !== null && _ref65 !== void 0 ? _ref65 : value.auto) !== null && _ref64 !== void 0 ? _ref64 : value.default) !== null && _ref63 !== void 0 ? _ref63 : value.en) !== null && _ref62 !== void 0 ? _ref62 : '');
2421
2499
  }
2422
2500
  function resolveServiceTypeLabelKey(serviceType) {
2423
2501
  return SERVICE_TYPE_LABEL_KEYS[serviceType] || null;