@pisell/pisellos 0.10.50 → 0.10.52

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 (64) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  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 +18 -1
  8. package/dist/modules/Order/index.js +322 -195
  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 +3 -2
  15. package/dist/modules/Schedule/index.d.ts +8 -0
  16. package/dist/modules/Schedule/index.js +134 -37
  17. package/dist/modules/index.d.ts +1 -0
  18. package/dist/modules/index.js +1 -0
  19. package/dist/server/modules/order/index.d.ts +8 -0
  20. package/dist/server/modules/order/index.js +506 -453
  21. package/dist/server/modules/order/types.d.ts +1 -0
  22. package/dist/server/utils/small-ticket.js +165 -94
  23. package/dist/solution/BaseSales/index.d.ts +24 -0
  24. package/dist/solution/BaseSales/index.js +1231 -1037
  25. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  26. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  27. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  28. package/dist/solution/BookingByStep/index.d.ts +1 -1
  29. package/dist/solution/BookingTicket/index.d.ts +2 -2
  30. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  31. package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
  32. package/dist/solution/UnifiedBookingSales/index.js +873 -708
  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 +18 -1
  39. package/lib/modules/Order/index.js +101 -3
  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 +3 -2
  46. package/lib/modules/Schedule/index.d.ts +8 -0
  47. package/lib/modules/Schedule/index.js +64 -11
  48. package/lib/modules/index.d.ts +1 -0
  49. package/lib/modules/index.js +11 -0
  50. package/lib/server/modules/order/index.d.ts +8 -0
  51. package/lib/server/modules/order/index.js +19 -0
  52. package/lib/server/modules/order/types.d.ts +1 -0
  53. package/lib/server/utils/small-ticket.js +86 -22
  54. package/lib/solution/BaseSales/index.d.ts +24 -0
  55. package/lib/solution/BaseSales/index.js +109 -1
  56. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  57. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  58. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  59. package/lib/solution/BookingByStep/index.d.ts +1 -1
  60. package/lib/solution/BookingTicket/index.d.ts +2 -2
  61. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  62. package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
  63. package/lib/solution/UnifiedBookingSales/index.js +130 -46
  64. package/package.json +1 -1
@@ -454,6 +454,7 @@ export interface OrderData {
454
454
  id: number | string;
455
455
  tag: 'point_card';
456
456
  product_id?: number | string;
457
+ code?: string;
457
458
  product_name: string;
458
459
  par_value: string;
459
460
  used_par_value: string;
@@ -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,16 +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 isAggregatedBundleEntitlement = getProductWalletDiscountType(discount) === 'entitlement_pass' && Boolean(getReceiptDiscountBundleMapId(discount));
558
- var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleEntitlement ? 1 : 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);
559
572
  var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
560
573
  return {
561
574
  item: title,
@@ -565,24 +578,24 @@ function normalizeProductDiscounts(params) {
565
578
  });
566
579
  return rows.sort(function (left, right) {
567
580
  return Number(right.isMarkup) - Number(left.isMarkup);
568
- }).map(function (_ref16) {
569
- var _isMarkup = _ref16.isMarkup,
570
- row = _objectWithoutProperties(_ref16, _excluded);
581
+ }).map(function (_ref18) {
582
+ var _isMarkup = _ref18.isMarkup,
583
+ row = _objectWithoutProperties(_ref18, _excluded);
571
584
  return row;
572
585
  });
573
586
  }
574
587
  function isManualMarkup(discount) {
575
- var _discount$discount, _ref17, _discount$amount3;
588
+ var _discount$discount, _ref19, _discount$amount3;
576
589
  if (discount.type !== 'product') return false;
577
590
  if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
578
- 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;
579
592
  return new Decimal(toMoneyNumber(amount)).isNegative();
580
593
  }
581
594
  function hasProductDiscount(product) {
582
595
  var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
583
596
  var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
584
- var _ref18, _discount$amount4;
585
- 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);
586
599
  });
587
600
  return hasDiscountListAmount || extensionList.some(function (row) {
588
601
  return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
@@ -667,8 +680,8 @@ function resolveDiscountTitleWithPercent(discount, locale) {
667
680
  return "".concat(title, " (").concat(percent, "%)");
668
681
  }
669
682
  function resolveDiscountTitle(discount, locale) {
670
- var _ref19, _ref20, _ref21, _ref22, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
671
- 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);
672
685
  if (title) return title;
673
686
  if (discount.type === 'product') {
674
687
  return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
@@ -688,17 +701,17 @@ function resolveProductTitle(params) {
688
701
  return getProductTitleSource(fallbackProduct, locale);
689
702
  }
690
703
  function normalizeProductOptions(params) {
691
- var _product$product_sku;
704
+ var _product$product_sku2;
692
705
  var product = params.product,
693
706
  locale = params.locale,
694
707
  currencySymbol = params.currencySymbol,
695
708
  parentProduct = params.parentProduct;
696
- 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 : [];
697
710
  return rawOptions.map(function (option) {
698
- var _ref23, _option$original_pric, _ref24, _option$num, _ref25, _option$value;
699
- 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;
700
- var quantity = toNumber((_ref24 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref24 !== void 0 ? _ref24 : 1, 1);
701
- 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;
702
715
  var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
703
716
  option: option,
704
717
  parentProduct: parentProduct,
@@ -725,7 +738,7 @@ function normalizeProductCombinations(params) {
725
738
  parentProduct = params.parentProduct;
726
739
  var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
727
740
  return bundles.map(function (bundle) {
728
- var _ref26, _bundle$num;
741
+ var _ref28, _bundle$num;
729
742
  var combinationsOptions = normalizeProductOptions({
730
743
  product: {},
731
744
  locale: locale,
@@ -741,7 +754,7 @@ function normalizeProductCombinations(params) {
741
754
  });
742
755
  var productNote = resolveProductNote(bundle, locale);
743
756
  var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
744
- 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);
745
758
  var formattedPrice = formatBundlePrice(bundle, currencySymbol);
746
759
  var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
747
760
  var explicitBasePrice = resolveCombinationBasePrice(bundle);
@@ -778,7 +791,7 @@ function normalizeProductCombinations(params) {
778
791
  }
779
792
  function normalizeExistingCombinations(combinations, locale, currencySymbol) {
780
793
  return combinations.map(function (combination) {
781
- var _ref27, _ref28, _combination$product_, _firstPresentValue;
794
+ var _ref29, _ref30, _combination$product_, _firstPresentValue;
782
795
  if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
783
796
  return combination;
784
797
  }
@@ -791,12 +804,14 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
791
804
  options: rawOptions
792
805
  });
793
806
  var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
807
+ var productTitle = getBundleProductTitleSource(combination, locale);
794
808
  var snapshot = _objectSpread({}, combination);
809
+ delete snapshot.product_title;
795
810
  delete snapshot.product_note;
796
811
  delete snapshot.note;
797
812
  delete snapshot.combinations;
798
813
  delete snapshot.discount_list;
799
- 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);
800
815
  var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
801
816
  var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
802
817
  return option.total_price;
@@ -811,7 +826,9 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
811
826
  originalPrice: unitPrice
812
827
  });
813
828
  var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
814
- 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
+ } : {}), {}, {
815
832
  product_quantity: quantity,
816
833
  total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
817
834
  }, shouldIncludeBasePrice ? {
@@ -879,23 +896,23 @@ function buildProductAllergyMap(order, locale) {
879
896
  return allergyByProductUid;
880
897
  }
881
898
  function resolveBundleProductTitle(params) {
882
- var _ref29, _ref30, _bundle$bundle_produc;
899
+ var _ref31, _ref32, _bundle$bundle_produc;
883
900
  var bundle = params.bundle,
884
901
  productMap = params.productMap,
885
902
  locale = params.locale,
886
903
  parentProduct = params.parentProduct;
887
- var ownTitle = getProductTitleSource(bundle, locale);
904
+ var ownTitle = getBundleProductTitleSource(bundle, locale);
888
905
  if (ownTitle) return ownTitle;
889
906
  var parentBundleItem = resolveBundleItemFromParentProduct({
890
907
  bundle: bundle,
891
908
  parentProduct: parentProduct
892
909
  });
893
- var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
910
+ var parentBundleTitle = parentBundleItem ? getBundleProductTitleSource(parentBundleItem, locale) : '';
894
911
  if (parentBundleTitle) return parentBundleTitle;
895
- 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;
896
913
  var fallbackProduct = resolveProductFromMap(productId, productMap);
897
914
  if (!fallbackProduct) return '';
898
- return getProductTitleSource(fallbackProduct, locale);
915
+ return getBundleProductTitleSource(fallbackProduct, locale);
899
916
  }
900
917
  function resolveProductFromMap(productId, productMap) {
901
918
  if (productId === undefined || productId === null || productId === '') return null;
@@ -944,10 +961,10 @@ function resolveVariantTextFromSkuKey(params) {
944
961
  }
945
962
  function resolveVariantTextFromNameMap(params) {
946
963
  if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
947
- return Object.entries(params.nameMap).map(function (_ref31) {
948
- var _ref32 = _slicedToArray(_ref31, 2),
949
- groupPositionId = _ref32[0],
950
- 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];
951
968
  var group = resolveVariantGroup(params.parentProduct, groupPositionId);
952
969
  if (!group) return '';
953
970
  var groupName = getLocalizedValue(group.name, params.locale);
@@ -978,15 +995,19 @@ function resolveVariantItem(group, itemPositionId) {
978
995
  }
979
996
  function getProductTitleSource(source, locale) {
980
997
  if (!source || _typeof(source) !== 'object') return '';
981
- 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);
982
1003
  }
983
1004
  function resolveTitleValue(value, locale) {
984
- var _ref33, _ref34, _ref35, _ref36, _value$locale;
1005
+ var _ref35, _ref36, _ref37, _ref38, _value$locale;
985
1006
  if (value === undefined || value === null) return '';
986
1007
  if (_typeof(value) !== 'object') return stringify(value);
987
1008
  var dashedLocale = locale.replace('_', '-');
988
1009
  var underscoredLocale = locale.replace('-', '_');
989
- 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 : '');
990
1011
  }
991
1012
  function resolveOptionTitleFromParentProduct(params) {
992
1013
  var option = params.option,
@@ -1004,17 +1025,17 @@ function flattenOptionItems(parentProduct) {
1004
1025
  return optionGroups.flatMap(function (group) {
1005
1026
  var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
1006
1027
  return items.map(function (item) {
1007
- var _ref37, _item$option_group_id;
1028
+ var _ref39, _item$option_group_id;
1008
1029
  return _objectSpread(_objectSpread({}, item), {}, {
1009
- 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
1010
1031
  });
1011
1032
  });
1012
1033
  });
1013
1034
  }
1014
1035
  function isOptionItemMatch(option, item) {
1015
- var _ref38, _option$option_group_, _ref39, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
1016
- 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;
1017
- 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;
1018
1039
  if (!isSameId(optionItemId, itemId)) return false;
1019
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;
1020
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;
@@ -1024,16 +1045,16 @@ function isOptionItemMatch(option, item) {
1024
1045
  return true;
1025
1046
  }
1026
1047
  function resolveBundleItemFromParentProduct(params) {
1027
- 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;
1028
1049
  var bundle = params.bundle,
1029
1050
  parentProduct = params.parentProduct;
1030
1051
  if (!parentProduct) return null;
1031
1052
  var bundleItems = flattenBundleItems(parentProduct);
1032
- 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;
1033
1054
  if (isNonZeroId(bundleVariantId)) {
1034
1055
  var matchedByVariant = bundleItems.find(function (item) {
1035
- var _ref41, _item$bundle_variant_;
1036
- 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);
1037
1058
  });
1038
1059
  if (matchedByVariant) return matchedByVariant;
1039
1060
  }
@@ -1046,18 +1067,18 @@ function resolveBundleItemFromParentProduct(params) {
1046
1067
  if (matchedByBundleId) return matchedByBundleId;
1047
1068
  }
1048
1069
  var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
1049
- 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;
1050
1071
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
1051
1072
  var matchedByGroupAndProduct = bundleItems.find(function (item) {
1052
- var _item$group_id, _ref43, _item$bundle_product_;
1053
- 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);
1054
1075
  });
1055
1076
  if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
1056
1077
  }
1057
1078
  if (isPresentId(bundleProductId)) {
1058
1079
  return bundleItems.find(function (item) {
1059
- var _ref44, _item$bundle_product_2;
1060
- 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);
1061
1082
  }) || null;
1062
1083
  }
1063
1084
  return null;
@@ -1067,9 +1088,9 @@ function flattenBundleItems(parentProduct) {
1067
1088
  return bundleGroups.flatMap(function (group) {
1068
1089
  var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
1069
1090
  return items.map(function (item) {
1070
- var _ref45, _item$group_id2;
1091
+ var _ref47, _item$group_id2;
1071
1092
  return _objectSpread(_objectSpread({}, item), {}, {
1072
- 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
1073
1094
  });
1074
1095
  });
1075
1096
  });
@@ -1093,8 +1114,8 @@ function isSameId(left, right) {
1093
1114
  return String(left) === String(right);
1094
1115
  }
1095
1116
  function formatBundlePrice(bundle, currencySymbol) {
1096
- var _ref46, _ref47, _bundle$bundle_sellin;
1097
- 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;
1098
1119
  var amount = new Decimal(toMoneyNumber(value));
1099
1120
  // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
1100
1121
  var isNegative = bundle.price_type === 'markdown';
@@ -1112,9 +1133,9 @@ function buildFees(params) {
1112
1133
  financials = params.financials;
1113
1134
  var fees = [];
1114
1135
  for (var _i2 = 0, _normalizeArray2 = normalizeArray(order.surcharges || summary.surcharges); _i2 < _normalizeArray2.length; _i2++) {
1115
- var _ref48, _surcharge$amount;
1136
+ var _ref50, _surcharge$amount;
1116
1137
  var surcharge = _normalizeArray2[_i2];
1117
- 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;
1118
1139
  if (!isNonZero(value)) continue;
1119
1140
  fees.push({
1120
1141
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
@@ -1216,9 +1237,9 @@ function resolveTaxTitle(params) {
1216
1237
  }
1217
1238
  function calculateProductOriginalAmount(order) {
1218
1239
  return normalizeArray(order.products).reduce(function (total, product) {
1219
- var _ref49, _ref50, _product$product_quan2, _ref51, _ref52, _ref53, _product$original_pri2;
1220
- 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);
1221
- 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;
1222
1243
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
1223
1244
  }, new Decimal(0));
1224
1245
  }
@@ -1247,11 +1268,21 @@ function buildDelivery(order, locale) {
1247
1268
  var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType);
1248
1269
  if (!serviceTypeLabelKey) return [];
1249
1270
  var items = [{
1250
- item: '',
1251
- value: label(locale, serviceTypeLabelKey),
1252
- size: 2,
1253
- align: 'left'
1271
+ item: label(locale, serviceTypeLabelKey),
1272
+ value: '',
1273
+ size: 2
1254
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
+ }
1255
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);
1256
1287
  if (isPresentId(handoverTime)) {
1257
1288
  items.push({
@@ -1261,9 +1292,34 @@ function buildDelivery(order, locale) {
1261
1292
  }
1262
1293
  return items;
1263
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
+ }
1264
1317
  function buildAppointment(order, locale) {
1265
- var _order$metadata13, _order$metadata14, _order$form_data;
1266
- 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
+ }));
1267
1323
  if (bookings.length) {
1268
1324
  var allResources = normalizeArray(order.resources || order.resource_list);
1269
1325
  return bookings.flatMap(function (booking) {
@@ -1275,13 +1331,26 @@ function buildAppointment(order, locale) {
1275
1331
  });
1276
1332
  });
1277
1333
  }
1278
- 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);
1279
1335
  if (!tableName) return [];
1280
1336
  return [{
1281
1337
  item: label(locale, 'table'),
1282
1338
  value: getLocalizedValue(tableName, locale)
1283
1339
  }];
1284
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
+ }
1285
1354
  function buildAppointmentRows(params) {
1286
1355
  var _booking$metadata, _booking$metadata2, _booking$holder$name, _booking$holder, _booking$metadata3;
1287
1356
  var booking = params.booking,
@@ -1353,9 +1422,9 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1353
1422
  _step3;
1354
1423
  try {
1355
1424
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1356
- var _ref55, _resource$id2;
1425
+ var _ref57, _resource$id2;
1357
1426
  var resource = _step3.value;
1358
- 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();
1359
1428
  if (id) resourceIds.add(id);
1360
1429
  }
1361
1430
  } catch (err) {
@@ -1365,8 +1434,8 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1365
1434
  }
1366
1435
  if (resourceIds.size) {
1367
1436
  var matched = allResources.filter(function (resource) {
1368
- var _ref54, _resource$id;
1369
- 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());
1370
1439
  });
1371
1440
  if (matched.length) return matched;
1372
1441
  }
@@ -1399,8 +1468,8 @@ function sortBookings(bookings) {
1399
1468
  }
1400
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));
1401
1470
  return bookingUidOrder || left.index - right.index;
1402
- }).map(function (_ref56) {
1403
- var booking = _ref56.booking;
1471
+ }).map(function (_ref58) {
1472
+ var booking = _ref58.booking;
1404
1473
  return booking;
1405
1474
  });
1406
1475
  }
@@ -1462,8 +1531,8 @@ function buildRefundData(params) {
1462
1531
  result.set(identity, candidate);
1463
1532
  }
1464
1533
  return result;
1465
- }, new Map()).values()).filter(function (_ref57) {
1466
- var refund = _ref57.refund;
1534
+ }, new Map()).values()).filter(function (_ref59) {
1535
+ var refund = _ref59.refund;
1467
1536
  return isPrintableRefund(refund);
1468
1537
  }).sort(function (left, right) {
1469
1538
  var leftTime = refundTimestamp(left.refund);
@@ -1471,9 +1540,9 @@ function buildRefundData(params) {
1471
1540
  if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1472
1541
  return left.index - right.index;
1473
1542
  });
1474
- return refunds.map(function (_ref58) {
1543
+ return refunds.map(function (_ref60) {
1475
1544
  var _firstPresentValue8;
1476
- var refund = _ref58.refund;
1545
+ var refund = _ref60.refund;
1477
1546
  var payment = resolveRefundPayment(refund, payments);
1478
1547
  var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
1479
1548
  var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
@@ -1867,7 +1936,7 @@ function buildPointCardSnapshotAssets(params) {
1867
1936
  codes: []
1868
1937
  })) return [];
1869
1938
  var rows = [{
1870
- item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1939
+ item: appendMaskedCardCode(stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'), pointCard.code),
1871
1940
  value: ''
1872
1941
  }];
1873
1942
  var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
@@ -2255,8 +2324,8 @@ function buildPaymentItems(params) {
2255
2324
  virtualCurrencyUnit: virtualCurrencyUnit
2256
2325
  })));
2257
2326
  } else {
2258
- var _ref59, _payment$remaining_am, _payment$metadata;
2259
- 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;
2260
2329
  if (remainingAmount !== undefined && remainingAmount !== null) {
2261
2330
  items.push({
2262
2331
  item: label(locale, 'remainingAmount'),
@@ -2367,9 +2436,14 @@ function isPointCardPayment(payment) {
2367
2436
  return code === 'POINTCARD' || type === 'point_card';
2368
2437
  }
2369
2438
  function maskMachineCode(code) {
2370
- var text = stringify(code);
2371
- if (text.length <= 6) return text;
2372
- 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;
2373
2447
  }
2374
2448
  function trimDecimal(value) {
2375
2449
  return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
@@ -2378,16 +2452,13 @@ function getFundRecordPaymentName(payment, locale) {
2378
2452
  var fundRecord = getFundRecord(payment);
2379
2453
  if (!fundRecord) return '';
2380
2454
  var name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
2381
- var code = maskMachineCode(fundRecord.code);
2382
- if (!name && !code) return '';
2383
- if (!code) return name;
2455
+ if (!name && !maskMachineCode(fundRecord.code)) return '';
2384
2456
  var fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
2385
- return "".concat(name || fallbackName, "(").concat(code, ")");
2457
+ return appendMaskedCardCode(name || fallbackName, fundRecord.code);
2386
2458
  }
2387
2459
  function appendMachineCodeToName(name, payment) {
2388
2460
  var fundRecord = getFundRecord(payment);
2389
- if (!(fundRecord !== null && fundRecord !== void 0 && fundRecord.code)) return name;
2390
- return "".concat(name, "(").concat(maskMachineCode(fundRecord.code), ")");
2461
+ return appendMaskedCardCode(name, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.code);
2391
2462
  }
2392
2463
  function paymentMethodName(payment, locale) {
2393
2464
  var fundRecordName = getFundRecordPaymentName(payment, locale);
@@ -2419,12 +2490,12 @@ function label(locale, key) {
2419
2490
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
2420
2491
  }
2421
2492
  function getLocalizedValue(value, locale) {
2422
- var _ref60, _ref61, _ref62, _ref63, _ref64, _ref65, _value$locale2;
2493
+ var _ref62, _ref63, _ref64, _ref65, _ref66, _ref67, _value$locale2;
2423
2494
  if (value === undefined || value === null) return '';
2424
2495
  if (_typeof(value) !== 'object') return stringify(value);
2425
2496
  var dashedLocale = locale.replace('_', '-');
2426
2497
  var underscoredLocale = locale.replace('-', '_');
2427
- 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 : '');
2428
2499
  }
2429
2500
  function resolveServiceTypeLabelKey(serviceType) {
2430
2501
  return SERVICE_TYPE_LABEL_KEYS[serviceType] || null;