@pisell/pisellos 0.10.56 → 0.10.57

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 (111) hide show
  1. package/dist/modules/OpenData/index.js +2 -1
  2. package/dist/modules/Order/index.d.ts +2 -1
  3. package/dist/modules/Order/index.js +118 -59
  4. package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
  5. package/dist/modules/Order/utils/weighedProduct.js +94 -0
  6. package/dist/modules/Order/utils.d.ts +1 -1
  7. package/dist/modules/Order/utils.js +9 -6
  8. package/dist/modules/Payment/index.d.ts +0 -5
  9. package/dist/modules/Payment/index.js +35 -85
  10. package/dist/modules/ProductList/index.js +18 -5
  11. package/dist/modules/ResourcePlanner/planner.js +10 -8
  12. package/dist/modules/Rules/index.js +16 -14
  13. package/dist/modules/Rules/types.d.ts +2 -0
  14. package/dist/server/index.js +122 -69
  15. package/dist/server/modules/floor-plan/index.js +34 -3
  16. package/dist/server/modules/payment/index.d.ts +25 -6
  17. package/dist/server/modules/payment/index.js +660 -133
  18. package/dist/server/test.json +1 -1
  19. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  20. package/dist/shared/receipt/customerInvoiceLanguages.js +60 -0
  21. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +5 -0
  22. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +46 -4
  23. package/dist/shared/receipt/small-ticket.d.ts +11 -0
  24. package/dist/shared/receipt/small-ticket.js +430 -255
  25. package/dist/shared/receipt/templateVisibility.d.ts +23 -0
  26. package/dist/shared/receipt/templateVisibility.js +64 -0
  27. package/dist/solution/BaseSales/index.d.ts +4 -2
  28. package/dist/solution/BaseSales/index.js +1328 -1214
  29. package/dist/solution/BaseSales/types.d.ts +5 -1
  30. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
  31. package/dist/solution/BaseSales/utils.js +3 -2
  32. package/dist/solution/BookingByStep/index.d.ts +1 -1
  33. package/dist/solution/BookingTicket/index.d.ts +4 -1
  34. package/dist/solution/BookingTicket/index.js +120 -80
  35. package/dist/solution/OrderInvoicePreview/index.d.ts +10 -0
  36. package/dist/solution/OrderInvoicePreview/index.js +85 -14
  37. package/dist/solution/RegisterAndLogin/config.js +54 -11
  38. package/dist/solution/RegisterAndLogin/index.d.ts +2 -0
  39. package/dist/solution/RegisterAndLogin/index.js +1 -1
  40. package/dist/solution/RegisterAndLogin/utils.d.ts +12 -4
  41. package/dist/solution/RegisterAndLogin/utils.js +36 -16
  42. package/dist/solution/Sales/index.d.ts +2 -0
  43. package/dist/solution/Sales/index.js +15 -1
  44. package/dist/solution/ScanOrder/utils.js +3 -2
  45. package/dist/solution/UnifiedBookingSales/index.js +12 -13
  46. package/dist/solution/VenueBooking/index.d.ts +15 -2
  47. package/dist/solution/VenueBooking/index.js +1062 -785
  48. package/dist/solution/VenueBooking/types.d.ts +2 -1
  49. package/dist/solution/VenueBooking/types.js +1 -0
  50. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  51. package/dist/solution/VenueBooking/utils/dateSummary.js +7 -4
  52. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  53. package/dist/solution/VenueBooking/utils/smartPricing.js +273 -0
  54. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  55. package/dist/solution/VenueBooking/utils/timeSlot.js +6 -3
  56. package/lib/modules/OpenData/index.js +2 -1
  57. package/lib/modules/Order/index.d.ts +2 -1
  58. package/lib/modules/Order/index.js +71 -11
  59. package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
  60. package/lib/modules/Order/utils/weighedProduct.js +89 -0
  61. package/lib/modules/Order/utils.d.ts +1 -1
  62. package/lib/modules/Order/utils.js +5 -3
  63. package/lib/modules/Payment/index.d.ts +0 -5
  64. package/lib/modules/Payment/index.js +3 -28
  65. package/lib/modules/ProductList/index.js +14 -1
  66. package/lib/modules/ResourcePlanner/planner.js +10 -8
  67. package/lib/modules/Rules/index.js +16 -14
  68. package/lib/modules/Rules/types.d.ts +2 -0
  69. package/lib/server/index.js +72 -28
  70. package/lib/server/modules/floor-plan/index.js +29 -1
  71. package/lib/server/modules/payment/index.d.ts +25 -6
  72. package/lib/server/modules/payment/index.js +350 -78
  73. package/lib/server/test.json +1 -1
  74. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  75. package/lib/shared/receipt/customerInvoiceLanguages.js +58 -0
  76. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +5 -0
  77. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +42 -4
  78. package/lib/shared/receipt/small-ticket.d.ts +11 -0
  79. package/lib/shared/receipt/small-ticket.js +234 -30
  80. package/lib/shared/receipt/templateVisibility.d.ts +23 -0
  81. package/lib/shared/receipt/templateVisibility.js +63 -0
  82. package/lib/solution/BaseSales/index.d.ts +4 -2
  83. package/lib/solution/BaseSales/index.js +79 -18
  84. package/lib/solution/BaseSales/types.d.ts +5 -1
  85. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
  86. package/lib/solution/BaseSales/utils.js +2 -1
  87. package/lib/solution/BookingByStep/index.d.ts +1 -1
  88. package/lib/solution/BookingTicket/index.d.ts +4 -1
  89. package/lib/solution/BookingTicket/index.js +14 -2
  90. package/lib/solution/OrderInvoicePreview/index.d.ts +10 -0
  91. package/lib/solution/OrderInvoicePreview/index.js +61 -7
  92. package/lib/solution/RegisterAndLogin/config.js +57 -11
  93. package/lib/solution/RegisterAndLogin/index.d.ts +2 -0
  94. package/lib/solution/RegisterAndLogin/index.js +9 -1
  95. package/lib/solution/RegisterAndLogin/utils.d.ts +12 -4
  96. package/lib/solution/RegisterAndLogin/utils.js +24 -17
  97. package/lib/solution/Sales/index.d.ts +2 -0
  98. package/lib/solution/Sales/index.js +10 -1
  99. package/lib/solution/ScanOrder/utils.js +2 -1
  100. package/lib/solution/UnifiedBookingSales/index.js +5 -6
  101. package/lib/solution/VenueBooking/index.d.ts +15 -2
  102. package/lib/solution/VenueBooking/index.js +243 -96
  103. package/lib/solution/VenueBooking/types.d.ts +2 -1
  104. package/lib/solution/VenueBooking/types.js +1 -0
  105. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  106. package/lib/solution/VenueBooking/utils/dateSummary.js +7 -4
  107. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  108. package/lib/solution/VenueBooking/utils/smartPricing.js +224 -0
  109. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  110. package/lib/solution/VenueBooking/utils/timeSlot.js +5 -2
  111. package/package.json +1 -1
@@ -1,8 +1,4 @@
1
1
  var _excluded = ["isMarkup"];
2
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
2
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
7
3
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
8
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
@@ -10,18 +6,69 @@ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread n
10
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
11
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
8
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
11
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
12
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
13
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
15
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
18
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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
23
  import { isFulfillmentTimingBooking } from "../../modules/Order/pickupTiming";
24
+ import { resolveInvoiceDataVisibility } from "./templateVisibility";
24
25
  var DEFAULT_LOCALES = ['en', 'zh_CN'];
26
+
27
+ // Attach provenance to a private copy BEFORE any locale-dependent filtering.
28
+ // Symbols survive the existing spread-based normalization, never enter JSON,
29
+ // and leave both the caller's snapshot and the default native contract intact.
30
+ var RECEIPT_SOURCE = Symbol('customerReceiptSource');
31
+ function copyReceiptSource(value) {
32
+ var _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _value$metadata$uniqu, _value$metadata;
33
+ var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'order';
34
+ if (Array.isArray(value)) return value.map(function (item, index) {
35
+ return copyReceiptSource(item, "".concat(path, "/").concat(index));
36
+ });
37
+ if (!value || _typeof(value) !== 'object' || Object.getPrototypeOf(value) !== Object.prototype) return value;
38
+ var id = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_value$metadata$uniqu = (_value$metadata = value.metadata) === null || _value$metadata === void 0 ? void 0 : _value$metadata.unique_identification_number) !== null && _value$metadata$uniqu !== void 0 ? _value$metadata$uniqu : value.product_uid) !== null && _ref6 !== void 0 ? _ref6 : value.booking_uid) !== null && _ref5 !== void 0 ? _ref5 : value.order_payment_id) !== null && _ref4 !== void 0 ? _ref4 : value.payment_number) !== null && _ref3 !== void 0 ? _ref3 : value.order_refund_id) !== null && _ref2 !== void 0 ? _ref2 : value.refund_number) !== null && _ref !== void 0 ? _ref : value.id;
39
+ var source = Object.fromEntries(Object.entries(value).map(function (_ref7) {
40
+ var _ref8 = _slicedToArray(_ref7, 2),
41
+ key = _ref8[0],
42
+ item = _ref8[1];
43
+ return [key, copyReceiptSource(item, "".concat(path, "/").concat(key))];
44
+ }));
45
+ // Retain the original occurrence even when a catalogue ID appears twice.
46
+ return _objectSpread(_objectSpread({}, source), {}, _defineProperty({}, RECEIPT_SOURCE, "".concat(path).concat(id != null ? "@".concat(encodeURIComponent(String(id))) : '')));
47
+ }
48
+ function receiptKey(source, kind) {
49
+ var valueKind = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'shared';
50
+ var key = source === null || source === void 0 ? void 0 : source[RECEIPT_SOURCE];
51
+ return typeof key === 'string' ? {
52
+ receipt_key: "".concat(key, "#").concat(kind),
53
+ receipt_value_kind: valueKind
54
+ } : {};
55
+ }
56
+ function receiptSourceIndex(source, index) {
57
+ return source !== null && source !== void 0 && source[RECEIPT_SOURCE] ? {
58
+ receipt_source_index: index
59
+ } : {};
60
+ }
61
+ function removePrivateReceiptSource(value) {
62
+ if (!value || _typeof(value) !== 'object') return;
63
+ delete value[RECEIPT_SOURCE];
64
+ Object.values(value).forEach(removePrivateReceiptSource);
65
+ }
66
+ function receiptTimeKey(source, kind) {
67
+ var identity = receiptKey(source, kind);
68
+ return identity.receipt_key ? _objectSpread(_objectSpread({}, identity), {}, {
69
+ receipt_item_kind: 'shared'
70
+ }) : {};
71
+ }
25
72
  var SERVICE_TYPE_LABEL_KEYS = {
26
73
  takeaway: 'takeAway',
27
74
  pick_up: 'pickUp',
@@ -259,19 +306,23 @@ var LABELS = {
259
306
  }
260
307
  };
261
308
  export function buildSmallTicketData(params) {
262
- var order = params.order || {};
309
+ var order = params.includeReceiptKeys ? copyReceiptSource(params.order || {}) : params.order || {};
263
310
  var shopInfo = params.shopInfo || {};
264
311
  var locales = resolveLocales(shopInfo, params.locales);
265
312
  var productMap = params.productMap || {};
266
- return locales.reduce(function (data, locale) {
313
+ var visibility = resolveInvoiceDataVisibility(params.templateSettings);
314
+ var result = locales.reduce(function (data, locale) {
267
315
  data[locale] = buildLocaleData({
268
316
  order: order,
269
317
  shopInfo: shopInfo,
270
318
  locale: locale,
271
- productMap: productMap
319
+ productMap: productMap,
320
+ visibility: visibility
272
321
  });
273
322
  return data;
274
323
  }, {});
324
+ if (params.includeReceiptKeys) removePrivateReceiptSource(result);
325
+ return result;
275
326
  }
276
327
  export function hasSmallTicketData(value) {
277
328
  return !!value && _typeof(value) === 'object' && Object.keys(value).length > 0;
@@ -280,12 +331,13 @@ function buildLocaleData(params) {
280
331
  var order = params.order,
281
332
  shopInfo = params.shopInfo,
282
333
  locale = params.locale,
283
- productMap = params.productMap;
334
+ productMap = params.productMap,
335
+ visibility = params.visibility;
284
336
  var products = buildProducts(order, locale, productMap);
285
337
  var summary = getSummary(order);
286
338
  var currencySymbol = getCurrencySymbol(order, shopInfo);
287
339
  var financials = resolveReceiptFinancials(order, summary);
288
- var delivery = buildDelivery(order, locale);
340
+ var delivery = buildDelivery(order, locale, visibility.handover);
289
341
  return _objectSpread(_objectSpread({
290
342
  base_data: buildBaseData({
291
343
  order: order,
@@ -304,7 +356,7 @@ function buildLocaleData(params) {
304
356
  currencySymbol: currencySymbol,
305
357
  financials: financials
306
358
  }),
307
- customer: buildCustomer(order, locale),
359
+ customer: buildCustomer(order, locale, visibility.customer),
308
360
  appointment: buildAppointment(order, locale)
309
361
  }, delivery.length ? {
310
362
  delivery: delivery
@@ -315,12 +367,19 @@ function buildLocaleData(params) {
315
367
  locale: locale,
316
368
  currencySymbol: currencySymbol
317
369
  }),
318
- wallets: buildWallets({
370
+ wallets: visibility.card.show ? buildWallets({
319
371
  order: order,
320
372
  locale: locale,
321
- currencySymbol: currencySymbol
322
- }),
323
- tickets: Array.isArray(order.tickets) ? order.tickets : [],
373
+ currencySymbol: currencySymbol,
374
+ passTypes: visibility.card.passTypes
375
+ }) : [],
376
+ // Native printers fall back to tickets when wallets is empty. Legacy rows
377
+ // have no trustworthy asset tags, so they cannot bypass a card whitelist.
378
+ tickets: visibility.card.show && visibility.card.passTypes === null && Array.isArray(order.tickets) ? order.tickets.map(function (group) {
379
+ return Array.isArray(group) ? group.map(function (row) {
380
+ return row && _typeof(row) === 'object' ? _objectSpread(_objectSpread({}, row), receiptKey(row, 'ticket')) : row;
381
+ }) : group;
382
+ }) : [],
324
383
  source_shop: [],
325
384
  refund_data: buildRefundData({
326
385
  order: order,
@@ -362,12 +421,12 @@ function buildBaseData(params) {
362
421
  function buildProducts(order, locale, productMap) {
363
422
  var products = Array.isArray(order.products) ? order.products : [];
364
423
  var allergyByProductUid = buildProductAllergyMap(order, locale);
365
- return products.map(function (rawProduct) {
366
- var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric, _product$product_id, _product$metadata, _product$metadata2;
424
+ return products.map(function (rawProduct, sourceIndex) {
425
+ var _ref9, _ref10, _product$product_quan, _ref11, _ref12, _ref13, _product$original_pri, _ref14, _ref15, _product$selling_pric, _product$product_id, _product$metadata, _product$metadata2;
367
426
  var product = restoreReceiptDiscountHierarchy(rawProduct);
368
- var quantity = toNumber((_ref = (_ref2 = (_product$product_quan = product.product_quantity) !== null && _product$product_quan !== void 0 ? _product$product_quan : product.quantity) !== null && _ref2 !== void 0 ? _ref2 : product.num) !== null && _ref !== void 0 ? _ref : 1, 1);
369
- var originalPrice = (_ref3 = (_ref4 = (_ref5 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref5 !== void 0 ? _ref5 : product.payment_price) !== null && _ref4 !== void 0 ? _ref4 : product.price) !== null && _ref3 !== void 0 ? _ref3 : 0;
370
- var sellingPrice = (_ref6 = (_ref7 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.payment_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : originalPrice;
427
+ var quantity = toNumber((_ref9 = (_ref10 = (_product$product_quan = product.product_quantity) !== null && _product$product_quan !== void 0 ? _product$product_quan : product.quantity) !== null && _ref10 !== void 0 ? _ref10 : product.num) !== null && _ref9 !== void 0 ? _ref9 : 1, 1);
428
+ var originalPrice = (_ref11 = (_ref12 = (_ref13 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref13 !== void 0 ? _ref13 : product.payment_price) !== null && _ref12 !== void 0 ? _ref12 : product.price) !== null && _ref11 !== void 0 ? _ref11 : 0;
429
+ var sellingPrice = (_ref14 = (_ref15 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.payment_price) !== null && _ref15 !== void 0 ? _ref15 : product.price) !== null && _ref14 !== void 0 ? _ref14 : originalPrice;
371
430
  var productTitle = resolveProductTitle({
372
431
  product: product,
373
432
  productMap: productMap,
@@ -407,7 +466,9 @@ function buildProducts(order, locale, productMap) {
407
466
  var basePrice = resolveProductBasePrice(product);
408
467
  var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
409
468
  var shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
410
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
469
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, receiptKey(rawProduct, 'product')), rawProduct[RECEIPT_SOURCE] ? {
470
+ receipt_source_index: sourceIndex
471
+ } : {}), {}, {
411
472
  product_title: productTitle,
412
473
  product_quantity: quantity,
413
474
  selling_price: formatMoney(sellingPrice, currencySymbol),
@@ -519,19 +580,19 @@ function getReceiptDiscountBundleMapId(discount) {
519
580
  return normalizeReceiptId(discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata[RECEIPT_BUNDLE_MAP_ID_KEY]);
520
581
  }
521
582
  function isSameReceiptDiscount(left, right) {
522
- var _ref8, _left$discount$resour, _left$discount, _ref9, _right$discount$resou, _right$discount, _ref10, _ref11, _left$amount, _ref12, _ref13, _right$amount;
583
+ var _ref16, _left$discount$resour, _left$discount, _ref17, _right$discount$resou, _right$discount, _ref18, _ref19, _left$amount, _ref20, _ref21, _right$amount;
523
584
  var leftOrderDiscountId = normalizeReceiptId(left === null || left === void 0 ? void 0 : left.order_discount_id);
524
585
  var rightOrderDiscountId = normalizeReceiptId(right === null || right === void 0 ? void 0 : right.order_discount_id);
525
586
  if (leftOrderDiscountId && rightOrderDiscountId) {
526
587
  return leftOrderDiscountId === rightOrderDiscountId;
527
588
  }
528
- var leftResourceId = normalizeReceiptId((_ref8 = (_left$discount$resour = left === null || left === void 0 || (_left$discount = left.discount) === null || _left$discount === void 0 ? void 0 : _left$discount.resource_id) !== null && _left$discount$resour !== void 0 ? _left$discount$resour : left === null || left === void 0 ? void 0 : left.resource_id) !== null && _ref8 !== void 0 ? _ref8 : left === null || left === void 0 ? void 0 : left.discount_id);
529
- var rightResourceId = normalizeReceiptId((_ref9 = (_right$discount$resou = right === null || right === void 0 || (_right$discount = right.discount) === null || _right$discount === void 0 ? void 0 : _right$discount.resource_id) !== null && _right$discount$resou !== void 0 ? _right$discount$resou : right === null || right === void 0 ? void 0 : right.resource_id) !== null && _ref9 !== void 0 ? _ref9 : right === null || right === void 0 ? void 0 : right.discount_id);
589
+ var leftResourceId = normalizeReceiptId((_ref16 = (_left$discount$resour = left === null || left === void 0 || (_left$discount = left.discount) === null || _left$discount === void 0 ? void 0 : _left$discount.resource_id) !== null && _left$discount$resour !== void 0 ? _left$discount$resour : left === null || left === void 0 ? void 0 : left.resource_id) !== null && _ref16 !== void 0 ? _ref16 : left === null || left === void 0 ? void 0 : left.discount_id);
590
+ var rightResourceId = normalizeReceiptId((_ref17 = (_right$discount$resou = right === null || right === void 0 || (_right$discount = right.discount) === null || _right$discount === void 0 ? void 0 : _right$discount.resource_id) !== null && _right$discount$resou !== void 0 ? _right$discount$resou : right === null || right === void 0 ? void 0 : right.resource_id) !== null && _ref17 !== void 0 ? _ref17 : right === null || right === void 0 ? void 0 : right.discount_id);
530
591
  if (!leftResourceId || !rightResourceId) return false;
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 : '');
592
+ return leftResourceId === rightResourceId && getReceiptDiscountBundleMapId(left) === getReceiptDiscountBundleMapId(right) && String((_ref18 = (_ref19 = (_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 && _ref19 !== void 0 ? _ref19 : left === null || left === void 0 ? void 0 : left.discount_amount) !== null && _ref18 !== void 0 ? _ref18 : '') === String((_ref20 = (_ref21 = (_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 && _ref21 !== void 0 ? _ref21 : right === null || right === void 0 ? void 0 : right.discount_amount) !== null && _ref20 !== void 0 ? _ref20 : '');
532
593
  }
533
594
  function resolveProductBasePrice(product) {
534
- var _product$product_vari, _ref14, _ref15, _product$product_quan2, _product$product_sku, _product$_origin, _product$_origin2;
595
+ var _product$product_vari, _ref22, _ref23, _product$product_quan2, _product$product_sku, _product$_origin, _product$_origin2;
535
596
  var metadata = product.metadata || {};
536
597
  var origin = product._origin || metadata.origin || {};
537
598
  var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
@@ -539,7 +600,7 @@ function resolveProductBasePrice(product) {
539
600
  return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
540
601
  }) : undefined;
541
602
  var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
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);
603
+ var quantity = toNumber((_ref22 = (_ref23 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref23 !== void 0 ? _ref23 : product.num) !== null && _ref22 !== void 0 ? _ref22 : 1, 1);
543
604
  var hasEntitlementPass = normalizeArray(product.discount_list).some(function (discount) {
544
605
  return getProductWalletDiscountType(discount) === 'entitlement_pass';
545
606
  });
@@ -558,44 +619,44 @@ function normalizeProductDiscounts(params) {
558
619
  currencySymbol = params.currencySymbol,
559
620
  quantity = params.quantity;
560
621
  var rows = normalizeArray(product.discount_list).filter(function (discount) {
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;
622
+ var _ref24, _discount$amount;
623
+ var amount = (_ref24 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref24 !== void 0 ? _ref24 : discount.discount_amount;
563
624
  return isNonZero(amount);
564
625
  }).map(function (discount) {
565
- var _ref17, _discount$amount2;
626
+ var _ref25, _discount$amount2;
566
627
  var title = resolveDiscountTitleWithPercent(discount, locale);
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;
628
+ var amount = (_ref25 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref25 !== void 0 ? _ref25 : discount.discount_amount;
568
629
  var isMarkup = isManualMarkup(discount);
569
630
  var isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
570
631
  var isEntitlementPass = getProductWalletDiscountType(discount) === 'entitlement_pass';
571
632
  var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount || isEntitlementPass ? 1 : quantity);
572
633
  var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
573
- return {
634
+ return _objectSpread(_objectSpread({}, receiptKey(discount, 'discount')), {}, {
574
635
  item: title,
575
636
  value: formattedAmount,
576
637
  isMarkup: isMarkup
577
- };
638
+ });
578
639
  });
579
640
  return rows.sort(function (left, right) {
580
641
  return Number(right.isMarkup) - Number(left.isMarkup);
581
- }).map(function (_ref18) {
582
- var _isMarkup = _ref18.isMarkup,
583
- row = _objectWithoutProperties(_ref18, _excluded);
642
+ }).map(function (_ref26) {
643
+ var _isMarkup = _ref26.isMarkup,
644
+ row = _objectWithoutProperties(_ref26, _excluded);
584
645
  return row;
585
646
  });
586
647
  }
587
648
  function isManualMarkup(discount) {
588
- var _discount$discount, _ref19, _discount$amount3;
649
+ var _discount$discount, _ref27, _discount$amount3;
589
650
  if (discount.type !== 'product') return false;
590
651
  if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
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;
652
+ var amount = (_ref27 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref27 !== void 0 ? _ref27 : discount.discount_amount;
592
653
  return new Decimal(toMoneyNumber(amount)).isNegative();
593
654
  }
594
655
  function hasProductDiscount(product) {
595
656
  var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
596
657
  var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
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);
658
+ var _ref28, _discount$amount4;
659
+ return isNonZero((_ref28 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref28 !== void 0 ? _ref28 : discount.discount_amount);
599
660
  });
600
661
  return hasDiscountListAmount || extensionList.some(function (row) {
601
662
  return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
@@ -617,15 +678,17 @@ function buildProductExtensionList(params) {
617
678
  product: product,
618
679
  locale: locale,
619
680
  currencySymbol: currencySymbol
620
- })), _toConsumableArray(quantity > 1 ? [{
681
+ })), _toConsumableArray(quantity > 1 ? [_objectSpread(_objectSpread({}, receiptTimeKey(product, 'quantity-price')), {}, {
621
682
  item: buildProductQuantityPriceText({
622
683
  quantity: quantity,
623
684
  currencySymbol: currencySymbol,
624
685
  price: originalPrice
625
686
  }),
626
687
  value: ''
627
- }] : []));
628
- var productExtensionList = extensionList.length ? extensionList : normalizeArray(product.extension_list);
688
+ })] : []));
689
+ var productExtensionList = extensionList.length ? extensionList : normalizeArray(product.extension_list).map(function (row) {
690
+ return _objectSpread(_objectSpread({}, row), receiptKey(row, 'extension'));
691
+ });
629
692
  return [].concat(_toConsumableArray(productExtensionList), _toConsumableArray(discountList));
630
693
  }
631
694
  function buildProductOpenWeightRows(params) {
@@ -641,22 +704,22 @@ function buildProductOpenWeightRows(params) {
641
704
  var rows = [];
642
705
  if (hasTare) {
643
706
  var _productSku$weight;
644
- rows.push({
707
+ rows.push(_objectSpread(_objectSpread({}, receiptKey(product, 'gross')), {}, {
645
708
  item: "".concat(manualFlag).concat(label(locale, 'gross'), ": ").concat((_productSku$weight = productSku.weight) !== null && _productSku$weight !== void 0 ? _productSku$weight : 0).concat(unit),
646
709
  value: ''
647
- });
648
- rows.push({
710
+ }));
711
+ rows.push(_objectSpread(_objectSpread({}, receiptKey(product, 'tare')), {}, {
649
712
  item: "".concat(label(locale, 'tare'), ": ").concat(productSku.tare_weight).concat(unit),
650
713
  value: ''
651
- });
714
+ }));
652
715
  }
653
716
  var netWeight = (_productSku$net_weigh = productSku.net_weight) !== null && _productSku$net_weigh !== void 0 ? _productSku$net_weigh : 0;
654
717
  var unitPrice = (_productSku$unit_pric = productSku.unit_price) !== null && _productSku$unit_pric !== void 0 ? _productSku$unit_pric : 0;
655
718
  var netItem = "".concat(netWeight, " ").concat(unit, " NET @ ").concat(currencySymbol).concat(unitPrice, "/").concat(unit);
656
- rows.push({
719
+ rows.push(_objectSpread(_objectSpread({}, receiptTimeKey(product, 'net-weight')), {}, {
657
720
  item: hasTare ? netItem : "".concat(manualFlag).concat(netItem),
658
721
  value: ''
659
- });
722
+ }));
660
723
  return rows;
661
724
  }
662
725
  function buildProductQuantityPriceText(params) {
@@ -680,8 +743,8 @@ function resolveDiscountTitleWithPercent(discount, locale) {
680
743
  return "".concat(title, " (").concat(percent, "%)");
681
744
  }
682
745
  function resolveDiscountTitle(discount, 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);
746
+ var _ref29, _ref30, _ref31, _ref32, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
747
+ var title = getLocalizedValue((_ref29 = (_ref30 = (_ref31 = (_ref32 = (_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 && _ref32 !== void 0 ? _ref32 : (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.message) !== null && _ref31 !== void 0 ? _ref31 : discount.name) !== null && _ref30 !== void 0 ? _ref30 : discount.title) !== null && _ref29 !== void 0 ? _ref29 : discount.message, locale);
685
748
  if (title) return title;
686
749
  if (discount.type === 'product') {
687
750
  return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
@@ -707,17 +770,17 @@ function normalizeProductOptions(params) {
707
770
  currencySymbol = params.currencySymbol,
708
771
  parentProduct = params.parentProduct;
709
772
  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 : [];
710
- return rawOptions.map(function (option) {
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;
773
+ return rawOptions.map(function (option, sourceIndex) {
774
+ var _ref33, _option$original_pric, _ref34, _option$num, _ref35, _option$value;
775
+ var price = (_ref33 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref33 !== void 0 ? _ref33 : option.price;
776
+ var quantity = toNumber((_ref34 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref34 !== void 0 ? _ref34 : 1, 1);
777
+ var value = (_ref35 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref35 !== void 0 ? _ref35 : option.item;
715
778
  var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
716
779
  option: option,
717
780
  parentProduct: parentProduct,
718
781
  locale: locale
719
782
  });
720
- return _objectSpread(_objectSpread(_objectSpread({
783
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, receiptKey(option, 'option')), receiptSourceIndex(option, sourceIndex)), {}, {
721
784
  name: name
722
785
  }, option.num !== undefined || option.quantity !== undefined ? {
723
786
  num: quantity
@@ -737,8 +800,8 @@ function normalizeProductCombinations(params) {
737
800
  currencySymbol = params.currencySymbol,
738
801
  parentProduct = params.parentProduct;
739
802
  var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
740
- return bundles.map(function (bundle) {
741
- var _ref28, _bundle$num;
803
+ return bundles.map(function (bundle, sourceIndex) {
804
+ var _ref36, _bundle$num;
742
805
  var combinationsOptions = normalizeProductOptions({
743
806
  product: {},
744
807
  locale: locale,
@@ -754,7 +817,7 @@ function normalizeProductCombinations(params) {
754
817
  });
755
818
  var productNote = resolveProductNote(bundle, locale);
756
819
  var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
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);
820
+ var quantity = toNumber((_ref36 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref36 !== void 0 ? _ref36 : 1, 1);
758
821
  var formattedPrice = formatBundlePrice(bundle, currencySymbol);
759
822
  var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
760
823
  var explicitBasePrice = resolveCombinationBasePrice(bundle);
@@ -767,7 +830,7 @@ function normalizeProductCombinations(params) {
767
830
  originalPrice: formattedPrice
768
831
  });
769
832
  var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle, extensionList);
770
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
833
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, receiptKey(bundle, 'combination')), receiptSourceIndex(bundle, sourceIndex)), {}, {
771
834
  product_title: baseTitle,
772
835
  product_quantity: quantity,
773
836
  price: formattedPrice,
@@ -790,8 +853,8 @@ function normalizeProductCombinations(params) {
790
853
  });
791
854
  }
792
855
  function normalizeExistingCombinations(combinations, locale, currencySymbol) {
793
- return combinations.map(function (combination) {
794
- var _ref29, _ref30, _combination$product_, _firstPresentValue;
856
+ return combinations.map(function (combination, sourceIndex) {
857
+ var _ref37, _ref38, _combination$product_, _firstPresentValue;
795
858
  if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
796
859
  return combination;
797
860
  }
@@ -811,7 +874,7 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
811
874
  delete snapshot.note;
812
875
  delete snapshot.combinations;
813
876
  delete snapshot.discount_list;
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);
877
+ var quantity = toNumber((_ref37 = (_ref38 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref38 !== void 0 ? _ref38 : combination.quantity) !== null && _ref37 !== void 0 ? _ref37 : 1, 1);
815
878
  var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
816
879
  var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
817
880
  return option.total_price;
@@ -826,7 +889,7 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
826
889
  originalPrice: unitPrice
827
890
  });
828
891
  var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
829
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), productTitle ? {
892
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), receiptKey(combination, 'combination')), receiptSourceIndex(combination, sourceIndex)), productTitle ? {
830
893
  product_title: productTitle
831
894
  } : {}), {}, {
832
895
  product_quantity: quantity,
@@ -896,7 +959,7 @@ function buildProductAllergyMap(order, locale) {
896
959
  return allergyByProductUid;
897
960
  }
898
961
  function resolveBundleProductTitle(params) {
899
- var _ref31, _ref32, _bundle$bundle_produc;
962
+ var _ref39, _ref40, _bundle$bundle_produc;
900
963
  var bundle = params.bundle,
901
964
  productMap = params.productMap,
902
965
  locale = params.locale,
@@ -909,7 +972,7 @@ function resolveBundleProductTitle(params) {
909
972
  });
910
973
  var parentBundleTitle = parentBundleItem ? getBundleProductTitleSource(parentBundleItem, locale) : '';
911
974
  if (parentBundleTitle) return parentBundleTitle;
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;
975
+ var productId = (_ref39 = (_ref40 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref40 !== void 0 ? _ref40 : bundle.product_id) !== null && _ref39 !== void 0 ? _ref39 : bundle.id;
913
976
  var fallbackProduct = resolveProductFromMap(productId, productMap);
914
977
  if (!fallbackProduct) return '';
915
978
  return getBundleProductTitleSource(fallbackProduct, locale);
@@ -961,10 +1024,10 @@ function resolveVariantTextFromSkuKey(params) {
961
1024
  }
962
1025
  function resolveVariantTextFromNameMap(params) {
963
1026
  if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
964
- return Object.entries(params.nameMap).map(function (_ref33) {
965
- var _ref34 = _slicedToArray(_ref33, 2),
966
- groupPositionId = _ref34[0],
967
- value = _ref34[1];
1027
+ return Object.entries(params.nameMap).map(function (_ref41) {
1028
+ var _ref42 = _slicedToArray(_ref41, 2),
1029
+ groupPositionId = _ref42[0],
1030
+ value = _ref42[1];
968
1031
  var group = resolveVariantGroup(params.parentProduct, groupPositionId);
969
1032
  if (!group) return '';
970
1033
  var groupName = getLocalizedValue(group.name, params.locale);
@@ -995,19 +1058,19 @@ function resolveVariantItem(group, itemPositionId) {
995
1058
  }
996
1059
  function getProductTitleSource(source, locale) {
997
1060
  if (!source || _typeof(source) !== 'object') return '';
998
- return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
1061
+ return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name_i18n, locale) || resolveTitleValue(source.name, locale);
999
1062
  }
1000
1063
  function getBundleProductTitleSource(source, locale) {
1001
1064
  if (!source || _typeof(source) !== 'object') return '';
1002
1065
  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);
1003
1066
  }
1004
1067
  function resolveTitleValue(value, locale) {
1005
- var _ref35, _ref36, _ref37, _ref38, _value$locale;
1068
+ var _ref43, _ref44, _ref45, _ref46, _value$locale;
1006
1069
  if (value === undefined || value === null) return '';
1007
1070
  if (_typeof(value) !== 'object') return stringify(value);
1008
1071
  var dashedLocale = locale.replace('_', '-');
1009
1072
  var underscoredLocale = locale.replace('-', '_');
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 : '');
1073
+ return stringify((_ref43 = (_ref44 = (_ref45 = (_ref46 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref46 !== void 0 ? _ref46 : value[underscoredLocale]) !== null && _ref45 !== void 0 ? _ref45 : value.original) !== null && _ref44 !== void 0 ? _ref44 : value.auto) !== null && _ref43 !== void 0 ? _ref43 : '');
1011
1074
  }
1012
1075
  function resolveOptionTitleFromParentProduct(params) {
1013
1076
  var option = params.option,
@@ -1025,17 +1088,17 @@ function flattenOptionItems(parentProduct) {
1025
1088
  return optionGroups.flatMap(function (group) {
1026
1089
  var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
1027
1090
  return items.map(function (item) {
1028
- var _ref39, _item$option_group_id;
1091
+ var _ref47, _item$option_group_id;
1029
1092
  return _objectSpread(_objectSpread({}, item), {}, {
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
1093
+ option_group_id: (_ref47 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref47 !== void 0 ? _ref47 : group.option_group_id
1031
1094
  });
1032
1095
  });
1033
1096
  });
1034
1097
  }
1035
1098
  function isOptionItemMatch(option, item) {
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;
1099
+ var _ref48, _option$option_group_, _ref49, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
1100
+ var optionItemId = (_ref48 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref48 !== void 0 ? _ref48 : option.id;
1101
+ var itemId = (_ref49 = (_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 && _ref49 !== void 0 ? _ref49 : item.id;
1039
1102
  if (!isSameId(optionItemId, itemId)) return false;
1040
1103
  var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
1041
1104
  var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
@@ -1045,16 +1108,16 @@ function isOptionItemMatch(option, item) {
1045
1108
  return true;
1046
1109
  }
1047
1110
  function resolveBundleItemFromParentProduct(params) {
1048
- var _ref42, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref44, _bundle$bundle_produc2;
1111
+ var _ref50, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref52, _bundle$bundle_produc2;
1049
1112
  var bundle = params.bundle,
1050
1113
  parentProduct = params.parentProduct;
1051
1114
  if (!parentProduct) return null;
1052
1115
  var bundleItems = flattenBundleItems(parentProduct);
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;
1116
+ var bundleVariantId = (_ref50 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref50 !== void 0 ? _ref50 : bundle.product_variant_id;
1054
1117
  if (isNonZeroId(bundleVariantId)) {
1055
1118
  var matchedByVariant = bundleItems.find(function (item) {
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);
1119
+ var _ref51, _item$bundle_variant_;
1120
+ return isSameId((_ref51 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref51 !== void 0 ? _ref51 : item.product_variant_id, bundleVariantId);
1058
1121
  });
1059
1122
  if (matchedByVariant) return matchedByVariant;
1060
1123
  }
@@ -1067,18 +1130,18 @@ function resolveBundleItemFromParentProduct(params) {
1067
1130
  if (matchedByBundleId) return matchedByBundleId;
1068
1131
  }
1069
1132
  var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_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;
1133
+ var bundleProductId = (_ref52 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref52 !== void 0 ? _ref52 : bundle.product_id;
1071
1134
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
1072
1135
  var matchedByGroupAndProduct = bundleItems.find(function (item) {
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);
1136
+ var _item$group_id, _ref53, _item$bundle_product_;
1137
+ return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref53 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref53 !== void 0 ? _ref53 : item.product_id, bundleProductId);
1075
1138
  });
1076
1139
  if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
1077
1140
  }
1078
1141
  if (isPresentId(bundleProductId)) {
1079
1142
  return bundleItems.find(function (item) {
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);
1143
+ var _ref54, _item$bundle_product_2;
1144
+ return isSameId((_ref54 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref54 !== void 0 ? _ref54 : item.product_id, bundleProductId);
1082
1145
  }) || null;
1083
1146
  }
1084
1147
  return null;
@@ -1088,9 +1151,9 @@ function flattenBundleItems(parentProduct) {
1088
1151
  return bundleGroups.flatMap(function (group) {
1089
1152
  var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
1090
1153
  return items.map(function (item) {
1091
- var _ref47, _item$group_id2;
1154
+ var _ref55, _item$group_id2;
1092
1155
  return _objectSpread(_objectSpread({}, item), {}, {
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
1156
+ group_id: (_ref55 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref55 !== void 0 ? _ref55 : group.group_id
1094
1157
  });
1095
1158
  });
1096
1159
  });
@@ -1114,8 +1177,8 @@ function isSameId(left, right) {
1114
1177
  return String(left) === String(right);
1115
1178
  }
1116
1179
  function formatBundlePrice(bundle, currencySymbol) {
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;
1180
+ var _ref56, _ref57, _bundle$bundle_sellin;
1181
+ var value = (_ref56 = (_ref57 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref57 !== void 0 ? _ref57 : bundle.price) !== null && _ref56 !== void 0 ? _ref56 : 0;
1119
1182
  var amount = new Decimal(toMoneyNumber(value));
1120
1183
  // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
1121
1184
  var isNegative = bundle.price_type === 'markdown';
@@ -1133,21 +1196,21 @@ function buildFees(params) {
1133
1196
  financials = params.financials;
1134
1197
  var fees = [];
1135
1198
  for (var _i2 = 0, _normalizeArray2 = normalizeArray(order.surcharges || summary.surcharges); _i2 < _normalizeArray2.length; _i2++) {
1136
- var _ref50, _surcharge$amount;
1199
+ var _ref58, _surcharge$amount;
1137
1200
  var surcharge = _normalizeArray2[_i2];
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;
1201
+ var value = (_ref58 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref58 !== void 0 ? _ref58 : surcharge.total_amount;
1139
1202
  if (!isNonZero(value)) continue;
1140
- fees.push({
1203
+ fees.push(_objectSpread(_objectSpread({}, receiptKey(surcharge, 'surcharge')), {}, {
1141
1204
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
1142
1205
  value: formatMoney(value, currencySymbol)
1143
- });
1206
+ }));
1144
1207
  }
1145
1208
  var discountAmount = firstPresentValue(order.shop_discount, summary.discount_amount, order.discount_amount);
1146
1209
  if (isNonZero(discountAmount)) {
1147
- fees.push({
1210
+ fees.push(_objectSpread(_objectSpread({}, receiptKey(order, 'order-discount')), {}, {
1148
1211
  item: label(locale, 'orderDiscount'),
1149
1212
  value: formatNegativeMoney(discountAmount, currencySymbol)
1150
- });
1213
+ }));
1151
1214
  }
1152
1215
  var taxFee = firstPresentValue(summary.tax_fee, order.tax_fee);
1153
1216
  var taxTitle = resolveTaxTitle({
@@ -1160,10 +1223,10 @@ function buildFees(params) {
1160
1223
  var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
1161
1224
  var payProcessingFee = financials.payProcessingFee;
1162
1225
  if (isNonZero(payProcessingFee)) {
1163
- fees.push({
1226
+ fees.push(_objectSpread(_objectSpread({}, receiptKey(order, 'payment-processing-fee')), {}, {
1164
1227
  item: label(locale, 'payProcessingFee'),
1165
1228
  value: formatMoney(payProcessingFee, currencySymbol)
1166
- });
1229
+ }));
1167
1230
  }
1168
1231
  var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
1169
1232
  var productOriginalAmount = (_firstPresentValue2 = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : calculateProductOriginalAmount(order);
@@ -1237,24 +1300,28 @@ function resolveTaxTitle(params) {
1237
1300
  }
1238
1301
  function calculateProductOriginalAmount(order) {
1239
1302
  return normalizeArray(order.products).reduce(function (total, product) {
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;
1303
+ var _ref59, _ref60, _product$product_quan3, _ref61, _ref62, _ref63, _product$original_pri2;
1304
+ var quantity = toNumber((_ref59 = (_ref60 = (_product$product_quan3 = product.product_quantity) !== null && _product$product_quan3 !== void 0 ? _product$product_quan3 : product.quantity) !== null && _ref60 !== void 0 ? _ref60 : product.num) !== null && _ref59 !== void 0 ? _ref59 : 1, 1);
1305
+ var originalPrice = (_ref61 = (_ref62 = (_ref63 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref63 !== void 0 ? _ref63 : product.payment_price) !== null && _ref62 !== void 0 ? _ref62 : product.price) !== null && _ref61 !== void 0 ? _ref61 : 0;
1243
1306
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
1244
1307
  }, new Decimal(0));
1245
1308
  }
1246
- function buildCustomer(order, locale) {
1309
+ function buildCustomer(order, locale, visibility) {
1247
1310
  var _order$customer, _order$customer2, _order$customer3, _order$customer4;
1248
- return [{
1311
+ if (!visibility.show) return [];
1312
+ var fields = [visibility.name, visibility.phone, visibility.email];
1313
+ return [_objectSpread(_objectSpread({}, receiptKey(order, 'customer.contactName')), {}, {
1249
1314
  item: label(locale, 'contactName'),
1250
1315
  value: normalizeCustomerDisplayValue(order.customer_name || ((_order$customer = order.customer) === null || _order$customer === void 0 ? void 0 : _order$customer.name) || ((_order$customer2 = order.customer) === null || _order$customer2 === void 0 ? void 0 : _order$customer2.display_name))
1251
- }, {
1316
+ }), _objectSpread(_objectSpread({}, receiptKey(order, 'customer.contactMobile')), {}, {
1252
1317
  item: label(locale, 'contactMobile'),
1253
1318
  value: stringify(order.phone || ((_order$customer3 = order.customer) === null || _order$customer3 === void 0 ? void 0 : _order$customer3.phone))
1254
- }, {
1319
+ }), _objectSpread(_objectSpread({}, receiptKey(order, 'customer.email')), {}, {
1255
1320
  item: label(locale, 'email'),
1256
1321
  value: stringify(order.email || ((_order$customer4 = order.customer) === null || _order$customer4 === void 0 ? void 0 : _order$customer4.email))
1257
- }];
1322
+ })].filter(function (_row, index) {
1323
+ return fields[index];
1324
+ });
1258
1325
  }
1259
1326
  function normalizeCustomerDisplayValue(value) {
1260
1327
  var text = stringify(value).trim();
@@ -1262,33 +1329,35 @@ function normalizeCustomerDisplayValue(value) {
1262
1329
  if (text.toLowerCase() === 'select a customer') return 'Walk-In';
1263
1330
  return text;
1264
1331
  }
1265
- function buildDelivery(order, locale) {
1332
+ function buildDelivery(order, locale, visibility) {
1266
1333
  var _order$metadata2, _order$metadata3, _order$metadata4, _order$metadata5, _order$metadata6, _order$metadata7, _order$metadata8, _order$metadata9, _order$metadata10, _order$metadata11, _order$metadata12;
1334
+ if (!visibility.show) return [];
1267
1335
  var serviceType = stringify((_order$metadata2 = order.metadata) === null || _order$metadata2 === void 0 || (_order$metadata2 = _order$metadata2.shop_service_data) === null || _order$metadata2 === void 0 ? void 0 : _order$metadata2.service_type).trim();
1268
1336
  var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType);
1269
1337
  if (!serviceTypeLabelKey) return [];
1270
- var items = [{
1338
+ var items = visibility.method ? [_objectSpread(_objectSpread({}, receiptKey(order, 'service-type')), {}, {
1271
1339
  item: label(locale, serviceTypeLabelKey),
1272
1340
  value: '',
1273
1341
  size: 2
1274
- }];
1342
+ })] : [];
1343
+ if (!visibility.fulfillmentTime) return items;
1275
1344
  if (serviceType === 'pick_up') {
1276
1345
  var pickupTime = formatPickupBookingStart(order.bookings, locale);
1277
1346
  if (pickupTime) {
1278
- items.push({
1347
+ items.push(_objectSpread(_objectSpread({}, receiptTimeKey(order, 'pickup-time')), {}, {
1279
1348
  item: pickupTime,
1280
1349
  value: '',
1281
1350
  size: 2
1282
- });
1351
+ }));
1283
1352
  return items;
1284
1353
  }
1285
1354
  }
1286
1355
  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);
1287
1356
  if (isPresentId(handoverTime)) {
1288
- items.push({
1357
+ items.push(_objectSpread(_objectSpread({}, receiptKey(order, 'handover-time')), {}, {
1289
1358
  item: label(locale, 'handoverTime'),
1290
1359
  value: formatDateTime(handoverTime, locale)
1291
- });
1360
+ }));
1292
1361
  }
1293
1362
  return items;
1294
1363
  }
@@ -1333,10 +1402,10 @@ function buildAppointment(order, locale) {
1333
1402
  }
1334
1403
  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);
1335
1404
  if (!tableName) return [];
1336
- return [{
1405
+ return [_objectSpread(_objectSpread({}, receiptKey(order, 'table', 'text')), {}, {
1337
1406
  item: label(locale, 'table'),
1338
1407
  value: getLocalizedValue(tableName, locale)
1339
- }];
1408
+ })];
1340
1409
  }
1341
1410
  function isReceiptAppointmentBooking(booking, parentScheduleId) {
1342
1411
  if (!booking || _typeof(booking) !== 'object' || Array.isArray(booking)) {
@@ -1367,16 +1436,16 @@ function buildAppointmentRows(params) {
1367
1436
  var bookingTime = formatBookingRange(booking, locale);
1368
1437
  var resourceText = formatBookingResources(resolveBookingResourcesForReceipt(booking, allResources, bookingCount), locale);
1369
1438
  var holder = getLocalizedValue((_booking$holder$name = (_booking$holder = booking.holder) === null || _booking$holder === void 0 ? void 0 : _booking$holder.name) !== null && _booking$holder$name !== void 0 ? _booking$holder$name : (_booking$metadata3 = booking.metadata) === null || _booking$metadata3 === void 0 || (_booking$metadata3 = _booking$metadata3.holder) === null || _booking$metadata3 === void 0 ? void 0 : _booking$metadata3.name, locale).trim();
1370
- return [_objectSpread({
1439
+ return [_objectSpread(_objectSpread({}, receiptKey(booking, 'booking-id')), {}, {
1371
1440
  item: label(locale, 'bookingId'),
1372
1441
  value: bookingId
1373
- }, association), _objectSpread({
1442
+ }, association), _objectSpread(_objectSpread({}, receiptKey(booking, 'booking-time', 'shared')), {}, {
1374
1443
  item: label(locale, 'bookingDateTime'),
1375
1444
  value: bookingTime
1376
- }, association), _objectSpread({
1445
+ }, association), _objectSpread(_objectSpread({}, receiptKey(booking, 'booking-resource', 'text')), {}, {
1377
1446
  item: label(locale, 'bookingResource'),
1378
1447
  value: resourceText
1379
- }, association), _objectSpread({
1448
+ }, association), _objectSpread(_objectSpread({}, receiptKey(booking, 'booking-holder', 'text')), {}, {
1380
1449
  item: label(locale, 'bookingHolder'),
1381
1450
  value: holder
1382
1451
  }, association)].filter(function (row) {
@@ -1422,9 +1491,9 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1422
1491
  _step3;
1423
1492
  try {
1424
1493
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1425
- var _ref57, _resource$id2;
1494
+ var _ref65, _resource$id2;
1426
1495
  var resource = _step3.value;
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();
1496
+ var id = stringify((_ref65 = (_resource$id2 = resource.id) !== null && _resource$id2 !== void 0 ? _resource$id2 : resource.resource_id) !== null && _ref65 !== void 0 ? _ref65 : resource.relation_id).trim();
1428
1497
  if (id) resourceIds.add(id);
1429
1498
  }
1430
1499
  } catch (err) {
@@ -1434,8 +1503,8 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1434
1503
  }
1435
1504
  if (resourceIds.size) {
1436
1505
  var matched = allResources.filter(function (resource) {
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());
1506
+ var _ref64, _resource$id;
1507
+ return resourceIds.has(stringify((_ref64 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.resource_id) !== null && _ref64 !== void 0 ? _ref64 : resource.relation_id).trim());
1439
1508
  });
1440
1509
  if (matched.length) return matched;
1441
1510
  }
@@ -1468,8 +1537,8 @@ function sortBookings(bookings) {
1468
1537
  }
1469
1538
  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));
1470
1539
  return bookingUidOrder || left.index - right.index;
1471
- }).map(function (_ref58) {
1472
- var booking = _ref58.booking;
1540
+ }).map(function (_ref66) {
1541
+ var booking = _ref66.booking;
1473
1542
  return booking;
1474
1543
  });
1475
1544
  }
@@ -1495,12 +1564,12 @@ function compareOptionalValues(left, right) {
1495
1564
  }
1496
1565
  function buildResources(order, locale) {
1497
1566
  return normalizeArray(order.resources || order.resource_list).map(function (resource) {
1498
- return {
1567
+ return _objectSpread(_objectSpread({}, receiptKey(resource, 'resource', 'text')), {}, {
1499
1568
  id: resource.id || resource.resource_id || '',
1500
1569
  code: '',
1501
1570
  title: getLocalizedValue(resource.title || resource.name, locale),
1502
1571
  form_title: getLocalizedValue(resource.form_title || resource.type || '', locale)
1503
- };
1572
+ });
1504
1573
  });
1505
1574
  }
1506
1575
  function buildPaymentData(params) {
@@ -1531,8 +1600,8 @@ function buildRefundData(params) {
1531
1600
  result.set(identity, candidate);
1532
1601
  }
1533
1602
  return result;
1534
- }, new Map()).values()).filter(function (_ref59) {
1535
- var refund = _ref59.refund;
1603
+ }, new Map()).values()).filter(function (_ref67) {
1604
+ var refund = _ref67.refund;
1536
1605
  return isPrintableRefund(refund);
1537
1606
  }).sort(function (left, right) {
1538
1607
  var leftTime = refundTimestamp(left.refund);
@@ -1540,22 +1609,22 @@ function buildRefundData(params) {
1540
1609
  if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1541
1610
  return left.index - right.index;
1542
1611
  });
1543
- return refunds.map(function (_ref60) {
1612
+ return refunds.map(function (_ref68) {
1544
1613
  var _firstPresentValue8;
1545
- var refund = _ref60.refund;
1614
+ var refund = _ref68.refund;
1546
1615
  var payment = resolveRefundPayment(refund, payments);
1547
1616
  var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
1548
1617
  var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
1549
- var items = [{
1618
+ var items = [_objectSpread(_objectSpread({}, receiptKey(refund, 'refund')), {}, {
1550
1619
  item: methodName,
1551
1620
  value: formatNegativeMoney(amount, params.currencySymbol)
1552
- }];
1621
+ })];
1553
1622
  var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
1554
1623
  if (isPresentId(occurredAt)) {
1555
- items.push({
1624
+ items.push(_objectSpread(_objectSpread({}, receiptTimeKey(refund, 'refund-time')), {}, {
1556
1625
  item: formatDateTime(occurredAt, params.locale),
1557
1626
  value: ''
1558
- });
1627
+ }));
1559
1628
  }
1560
1629
  return items;
1561
1630
  });
@@ -1601,10 +1670,100 @@ function resolveRefundPayment(refund, payments) {
1601
1670
  });
1602
1671
  return matchedPayment || refund;
1603
1672
  }
1673
+ function getPaymentWalletAssetIdentity(payment) {
1674
+ var record = getFundRecord(payment);
1675
+ return {
1676
+ id: firstNormalizedWalletAssetId(record === null || record === void 0 ? void 0 : record.voucher_id, payment.voucher_id),
1677
+ codes: normalizeWalletAssetCodes(record === null || record === void 0 ? void 0 : record.code, record === null || record === void 0 ? void 0 : record.encoded)
1678
+ };
1679
+ }
1680
+ function getProductWalletAssetTag(record) {
1681
+ // Rules normalizes product_discount_card to type=discount_card. That
1682
+ // ambiguous alias cannot establish the original asset tag for a whitelist.
1683
+ for (var _i6 = 0, _arr2 = [record.tag, (_record$discount = record.discount) === null || _record$discount === void 0 ? void 0 : _record$discount.tag]; _i6 < _arr2.length; _i6++) {
1684
+ var _record$discount;
1685
+ var _tag = _arr2[_i6];
1686
+ if (typeof _tag === 'string' && _tag) return _tag;
1687
+ }
1688
+ for (var _i7 = 0, _arr3 = [record.type, (_record$discount2 = record.discount) === null || _record$discount2 === void 0 ? void 0 : _record$discount2.type]; _i7 < _arr3.length; _i7++) {
1689
+ var _record$discount2;
1690
+ var type = _arr3[_i7];
1691
+ if (typeof type === 'string' && type !== 'discount_card' && PRODUCT_WALLET_DISCOUNT_TYPES.has(type)) return type;
1692
+ }
1693
+ return undefined;
1694
+ }
1695
+ function createWalletAssetFilter(order, passTypes) {
1696
+ if (passTypes === null) return function () {
1697
+ return true;
1698
+ };
1699
+ var assets = [];
1700
+ var remember = function remember(identity, tag) {
1701
+ if (typeof tag === 'string' && tag && (identity.id || identity.codes.length)) assets.push({
1702
+ identity: identity,
1703
+ tag: tag
1704
+ });
1705
+ };
1706
+ for (var _i8 = 0, _arr4 = [].concat(_toConsumableArray(normalizeArray(order.vouchers)), _toConsumableArray(normalizeArray((_order$order_meta_lis = order.order_meta_list) === null || _order$order_meta_lis === void 0 ? void 0 : _order$order_meta_lis.point_cards_snapshot)), _toConsumableArray(normalizeArray((_order$order_meta_lis2 = order.order_meta_list) === null || _order$order_meta_lis2 === void 0 ? void 0 : _order$order_meta_lis2.virtual_currency_snapshot))); _i8 < _arr4.length; _i8++) {
1707
+ var _order$order_meta_lis, _order$order_meta_lis2;
1708
+ var asset = _arr4[_i8];
1709
+ if (asset && _typeof(asset) === 'object') remember(getVoucherAssetIdentity(asset), asset.tag);
1710
+ }
1711
+ // Some order snapshots retain the original selected assets at the root.
1712
+ // Only their explicit tag is authoritative; do not infer it from type.
1713
+ for (var _i9 = 0, _normalizeArray3 = normalizeArray(order.discount_list); _i9 < _normalizeArray3.length; _i9++) {
1714
+ var _record$tag, _record$discount3;
1715
+ var record = _normalizeArray3[_i9];
1716
+ if (!record || _typeof(record) !== 'object') continue;
1717
+ remember({
1718
+ id: getProductWalletDiscountAssetId(record),
1719
+ codes: getProductWalletDiscountCodes(record)
1720
+ }, (_record$tag = record.tag) !== null && _record$tag !== void 0 ? _record$tag : (_record$discount3 = record.discount) === null || _record$discount3 === void 0 ? void 0 : _record$discount3.tag);
1721
+ }
1722
+ var visit = function visit(product) {
1723
+ if (!product || _typeof(product) !== 'object') return;
1724
+ for (var _i10 = 0, _normalizeArray4 = normalizeArray(product.discount_list); _i10 < _normalizeArray4.length; _i10++) {
1725
+ var _record = _normalizeArray4[_i10];
1726
+ if (!_record || _typeof(_record) !== 'object') continue;
1727
+ remember({
1728
+ id: getProductWalletDiscountAssetId(_record),
1729
+ codes: getProductWalletDiscountCodes(_record)
1730
+ }, getProductWalletAssetTag(_record));
1731
+ }
1732
+ for (var _i11 = 0, _arr5 = ['combinations', 'product_bundle', 'bundle']; _i11 < _arr5.length; _i11++) {
1733
+ var _key3 = _arr5[_i11];
1734
+ normalizeArray(product[_key3]).forEach(visit);
1735
+ }
1736
+ };
1737
+ normalizeArray(order.products).forEach(function (product) {
1738
+ if (product && _typeof(product) === 'object') visit(restoreReceiptDiscountHierarchy(product));
1739
+ });
1740
+ return function (identity, tag) {
1741
+ var resolvePaymentSource = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1742
+ var directTag = typeof tag === 'string' && tag ? tag : undefined;
1743
+ if (directTag && !resolvePaymentSource) return passTypes.has(directTag);
1744
+ var exactMatches = identity.id ? assets.filter(function (asset) {
1745
+ return asset.identity.id === identity.id;
1746
+ }) : [];
1747
+ // A known asset ID is stronger than an unrelated code-only snapshot.
1748
+ var matches = exactMatches.length ? exactMatches : assets.filter(function (asset) {
1749
+ return isSameWalletAssetIdentity(asset.identity, identity);
1750
+ });
1751
+ var tags = new Set(matches.map(function (asset) {
1752
+ return asset.tag;
1753
+ }));
1754
+ if (!tags.size) return !!directTag && passTypes.has(directTag);
1755
+ // A conflicting fund record is not reliable evidence for a payment's tag.
1756
+ // It must not claim the identity ahead of the original typed asset.
1757
+ if (tags.size !== 1 || directTag && !tags.has(directTag)) return false;
1758
+ return passTypes.has(matches[0].tag);
1759
+ };
1760
+ }
1604
1761
  function buildWallets(params) {
1605
- var virtualCurrencySnapshots = collectVirtualCurrencySnapshots(params.order);
1762
+ var allowAsset = createWalletAssetFilter(params.order, params.passTypes);
1763
+ var virtualCurrencySnapshots = collectVirtualCurrencySnapshots(params.order, allowAsset);
1606
1764
  var displayedWalletPayments = normalizeArray(params.order.payments).filter(function (payment) {
1607
- return isPrintablePayment(payment) && !!getFundRecord(payment);
1765
+ var _getFundRecord;
1766
+ return isPrintablePayment(payment) && !!getFundRecord(payment) && allowAsset(getPaymentWalletAssetIdentity(payment), (_getFundRecord = getFundRecord(payment)) === null || _getFundRecord === void 0 ? void 0 : _getFundRecord.tag, true);
1608
1767
  });
1609
1768
  var paymentWallets = displayedWalletPayments.map(function (payment) {
1610
1769
  var virtualCurrencySnapshot = findVirtualCurrencySnapshotForPayment(payment, virtualCurrencySnapshots.byId);
@@ -1620,19 +1779,23 @@ function buildWallets(params) {
1620
1779
  });
1621
1780
  var displayedWalletAssetIdentities = collectDisplayedWalletAssetIdentities(displayedWalletPayments);
1622
1781
  var voucherWallets = buildVoucherAssets(_objectSpread(_objectSpread({}, params), {}, {
1782
+ allowAsset: allowAsset,
1623
1783
  displayedWalletAssetIdentities: displayedWalletAssetIdentities
1624
1784
  }));
1625
1785
  var productDiscountWallets = buildProductDiscountAssets(_objectSpread(_objectSpread({}, params), {}, {
1786
+ allowAsset: allowAsset,
1626
1787
  displayedWalletAssetIdentities: displayedWalletAssetIdentities
1627
1788
  }));
1628
1789
  return [].concat(_toConsumableArray(paymentWallets), voucherWallets, productDiscountWallets, _toConsumableArray(buildPointCardSnapshotAssets({
1629
1790
  order: params.order,
1630
1791
  locale: params.locale,
1792
+ allowAsset: allowAsset,
1631
1793
  displayedWalletAssetIdentities: displayedWalletAssetIdentities
1632
1794
  })), _toConsumableArray(buildVirtualCurrencySnapshotAssets({
1633
1795
  snapshots: virtualCurrencySnapshots.items,
1634
1796
  order: params.order,
1635
1797
  locale: params.locale,
1798
+ allowAsset: allowAsset,
1636
1799
  displayedWalletAssetIdentities: displayedWalletAssetIdentities
1637
1800
  })));
1638
1801
  }
@@ -1665,7 +1828,7 @@ function collectDisplayedWalletAssetIdentities(payments) {
1665
1828
  var PRODUCT_WALLET_DISCOUNT_TYPES = new Set(['good_pass', 'discount_card', 'product_discount_card', 'entitlement_pass']);
1666
1829
  function buildProductDiscountAssets(params) {
1667
1830
  var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1668
- return collectProductWalletDiscountAssets(params.order).flatMap(function (asset) {
1831
+ return collectProductWalletDiscountAssets(params.order, params.allowAsset).flatMap(function (asset) {
1669
1832
  var _getProductWalletDisc;
1670
1833
  if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1671
1834
  id: asset.id,
@@ -1673,47 +1836,47 @@ function buildProductDiscountAssets(params) {
1673
1836
  })) return [];
1674
1837
  var name = getProductWalletDiscountName(asset, params.locale);
1675
1838
  var assetTime = (_getProductWalletDisc = getProductWalletDiscountTime(asset)) !== null && _getProductWalletDisc !== void 0 ? _getProductWalletDisc : fallbackAssetTime;
1676
- var timeRow = isPresentId(assetTime) ? {
1839
+ var timeRow = isPresentId(assetTime) ? _objectSpread(_objectSpread({}, receiptTimeKey(asset.records[0], 'asset-time')), {}, {
1677
1840
  item: formatDateTime(assetTime, params.locale),
1678
1841
  value: ''
1679
- } : null;
1842
+ }) : null;
1680
1843
  if (asset.type === 'entitlement_pass') {
1681
1844
  var remaining = getProductEntitlementBalance(asset);
1682
- return [[{
1845
+ return [[_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'asset-name')), {}, {
1683
1846
  item: name,
1684
1847
  value: ''
1685
- }].concat(_toConsumableArray(remaining ? [{
1848
+ })].concat(_toConsumableArray(remaining ? [_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'entitlementRemaining')), {}, {
1686
1849
  item: label(params.locale, 'entitlementRemaining'),
1687
1850
  value: formatEntitlementUses(remaining, params.locale)
1688
- }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1851
+ })] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1689
1852
  }
1690
1853
  var percent = getProductWalletDiscountPercent(asset);
1691
1854
  if (percent) {
1692
- return [[{
1855
+ return [[_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'asset-discount')), {}, {
1693
1856
  item: appendPercentToVoucherName(name, percent),
1694
1857
  value: formatVoucherDiscount(percent, params.locale)
1695
- }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1858
+ })].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1696
1859
  }
1697
1860
  var balance = getProductWalletMoneyBalance(asset);
1698
- return [[{
1861
+ return [[_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'asset-name')), {}, {
1699
1862
  item: name,
1700
1863
  value: ''
1701
- }].concat(_toConsumableArray(balance ? [{
1864
+ })].concat(_toConsumableArray(balance ? [_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'balance')), {}, {
1702
1865
  item: label(params.locale, 'balance'),
1703
1866
  value: formatMoney(balance, params.currencySymbol)
1704
- }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1867
+ })] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1705
1868
  });
1706
1869
  }
1707
- function collectProductWalletDiscountAssets(order) {
1870
+ function collectProductWalletDiscountAssets(order, allowAsset) {
1708
1871
  var assets = [];
1709
1872
  var assetsById = new Map();
1710
1873
  normalizeArray(order.products).forEach(function (rawProduct) {
1711
1874
  if (!rawProduct || _typeof(rawProduct) !== 'object') return;
1712
- visitProductWalletDiscounts(restoreReceiptDiscountHierarchy(rawProduct), assets, assetsById);
1875
+ visitProductWalletDiscounts(restoreReceiptDiscountHierarchy(rawProduct), assets, assetsById, allowAsset);
1713
1876
  });
1714
1877
  return assets;
1715
1878
  }
1716
- function visitProductWalletDiscounts(product, assets, assetsById) {
1879
+ function visitProductWalletDiscounts(product, assets, assetsById, allowAsset) {
1717
1880
  normalizeArray(product.discount_list).forEach(function (record) {
1718
1881
  if (!record || _typeof(record) !== 'object' || Array.isArray(record)) return;
1719
1882
  var type = getProductWalletDiscountType(record);
@@ -1721,6 +1884,10 @@ function visitProductWalletDiscounts(product, assets, assetsById) {
1721
1884
  var id = getProductWalletDiscountAssetId(record);
1722
1885
  if (!id) return;
1723
1886
  var codes = getProductWalletDiscountCodes(record);
1887
+ if (allowAsset && !allowAsset({
1888
+ id: id,
1889
+ codes: codes
1890
+ }, getProductWalletAssetTag(record))) return;
1724
1891
  var existing = assetsById.get(id);
1725
1892
  if (existing) {
1726
1893
  existing.records.push(record);
@@ -1736,35 +1903,35 @@ function visitProductWalletDiscounts(product, assets, assetsById) {
1736
1903
  assetsById.set(id, asset);
1737
1904
  assets.push(asset);
1738
1905
  });
1739
- for (var _i6 = 0, _arr2 = ['combinations', 'product_bundle', 'bundle']; _i6 < _arr2.length; _i6++) {
1740
- var childKey = _arr2[_i6];
1906
+ for (var _i12 = 0, _arr6 = ['combinations', 'product_bundle', 'bundle']; _i12 < _arr6.length; _i12++) {
1907
+ var childKey = _arr6[_i12];
1741
1908
  normalizeArray(product[childKey]).forEach(function (child) {
1742
1909
  if (!child || _typeof(child) !== 'object' || Array.isArray(child)) return;
1743
- visitProductWalletDiscounts(child, assets, assetsById);
1910
+ visitProductWalletDiscounts(child, assets, assetsById, allowAsset);
1744
1911
  });
1745
1912
  }
1746
1913
  }
1747
1914
  function getProductWalletDiscountType(record) {
1748
- for (var _i7 = 0, _arr3 = [record.tag, record.type, (_record$discount = record.discount) === null || _record$discount === void 0 ? void 0 : _record$discount.tag, (_record$discount2 = record.discount) === null || _record$discount2 === void 0 ? void 0 : _record$discount2.type]; _i7 < _arr3.length; _i7++) {
1749
- var _record$discount, _record$discount2;
1750
- var value = _arr3[_i7];
1915
+ for (var _i13 = 0, _arr7 = [record.tag, record.type, (_record$discount4 = record.discount) === null || _record$discount4 === void 0 ? void 0 : _record$discount4.tag, (_record$discount5 = record.discount) === null || _record$discount5 === void 0 ? void 0 : _record$discount5.type]; _i13 < _arr7.length; _i13++) {
1916
+ var _record$discount4, _record$discount5;
1917
+ var value = _arr7[_i13];
1751
1918
  var type = stringify(value).trim().toLowerCase();
1752
1919
  if (PRODUCT_WALLET_DISCOUNT_TYPES.has(type)) return type;
1753
1920
  }
1754
1921
  return null;
1755
1922
  }
1756
1923
  function getProductWalletDiscountAssetId(record) {
1757
- for (var _i8 = 0, _arr4 = [(_record$discount3 = record.discount) === null || _record$discount3 === void 0 ? void 0 : _record$discount3.resource_id, record.resource_id, record.id, record.discount_id]; _i8 < _arr4.length; _i8++) {
1758
- var _record$discount3;
1759
- var value = _arr4[_i8];
1924
+ for (var _i14 = 0, _arr8 = [(_record$discount6 = record.discount) === null || _record$discount6 === void 0 ? void 0 : _record$discount6.resource_id, record.resource_id, record.id, record.discount_id]; _i14 < _arr8.length; _i14++) {
1925
+ var _record$discount6;
1926
+ var value = _arr8[_i14];
1760
1927
  var id = normalizeWalletPassId(value);
1761
1928
  if (id && id !== '0') return id;
1762
1929
  }
1763
1930
  return null;
1764
1931
  }
1765
1932
  function getProductWalletDiscountCodes(record) {
1766
- var _record$discount4, _record$discount5;
1767
- return normalizeWalletAssetCodes(record.code, record.encoded, (_record$discount4 = record.discount) === null || _record$discount4 === void 0 ? void 0 : _record$discount4.code, (_record$discount5 = record.discount) === null || _record$discount5 === void 0 ? void 0 : _record$discount5.encoded);
1933
+ var _record$discount7, _record$discount8;
1934
+ return normalizeWalletAssetCodes(record.code, record.encoded, (_record$discount7 = record.discount) === null || _record$discount7 === void 0 ? void 0 : _record$discount7.code, (_record$discount8 = record.discount) === null || _record$discount8 === void 0 ? void 0 : _record$discount8.encoded);
1768
1935
  }
1769
1936
  function getProductWalletDiscountName(asset, locale) {
1770
1937
  var _iterator4 = _createForOfIteratorHelper(asset.records),
@@ -1772,9 +1939,9 @@ function getProductWalletDiscountName(asset, locale) {
1772
1939
  try {
1773
1940
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1774
1941
  var record = _step4.value;
1775
- for (var _i9 = 0, _arr5 = [(_record$discount6 = record.discount) === null || _record$discount6 === void 0 ? void 0 : _record$discount6.title, (_record$discount7 = record.discount) === null || _record$discount7 === void 0 ? void 0 : _record$discount7.name, (_record$discount8 = record.discount) === null || _record$discount8 === void 0 ? void 0 : _record$discount8.message, record.product_name, record.format_title, record.title, record.name, record.message]; _i9 < _arr5.length; _i9++) {
1776
- var _record$discount6, _record$discount7, _record$discount8;
1777
- var value = _arr5[_i9];
1942
+ for (var _i15 = 0, _arr9 = [(_record$discount9 = record.discount) === null || _record$discount9 === void 0 ? void 0 : _record$discount9.title, (_record$discount10 = record.discount) === null || _record$discount10 === void 0 ? void 0 : _record$discount10.name, (_record$discount11 = record.discount) === null || _record$discount11 === void 0 ? void 0 : _record$discount11.message, record.product_name, record.format_title, record.title, record.name, record.message]; _i15 < _arr9.length; _i15++) {
1943
+ var _record$discount9, _record$discount10, _record$discount11;
1944
+ var value = _arr9[_i15];
1778
1945
  var name = getLocalizedValue(value, locale).trim();
1779
1946
  if (name) return name;
1780
1947
  }
@@ -1787,15 +1954,15 @@ function getProductWalletDiscountName(asset, locale) {
1787
1954
  return asset.codes[0] || label(locale, 'giftCard');
1788
1955
  }
1789
1956
  function getProductWalletDiscountTime(asset) {
1790
- for (var _i10 = 0, _arr6 = ['updated_at', 'created_at', 'collection_time']; _i10 < _arr6.length; _i10++) {
1791
- var field = _arr6[_i10];
1957
+ for (var _i16 = 0, _arr10 = ['updated_at', 'created_at', 'collection_time']; _i16 < _arr10.length; _i16++) {
1958
+ var field = _arr10[_i16];
1792
1959
  var _iterator5 = _createForOfIteratorHelper(asset.records),
1793
1960
  _step5;
1794
1961
  try {
1795
1962
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1796
- var _record$discount9;
1963
+ var _record$discount12;
1797
1964
  var record = _step5.value;
1798
- var value = firstPresentValue(record[field], (_record$discount9 = record.discount) === null || _record$discount9 === void 0 ? void 0 : _record$discount9[field]);
1965
+ var value = firstPresentValue(record[field], (_record$discount12 = record.discount) === null || _record$discount12 === void 0 ? void 0 : _record$discount12[field]);
1799
1966
  if (isPresentId(value)) return value;
1800
1967
  }
1801
1968
  } catch (err) {
@@ -1823,15 +1990,15 @@ function getProductEntitlementBalance(asset) {
1823
1990
  return null;
1824
1991
  }
1825
1992
  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);
1993
+ var _record$metadata, _record$discount13, _record$discount14;
1994
+ return getEntitlementBalance((_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.balance, record.balance, (_record$discount13 = record.discount) === null || _record$discount13 === void 0 || (_record$discount13 = _record$discount13.metadata) === null || _record$discount13 === void 0 ? void 0 : _record$discount13.balance, (_record$discount14 = record.discount) === null || _record$discount14 === void 0 ? void 0 : _record$discount14.balance);
1828
1995
  }
1829
1996
  function getEntitlementBalance() {
1830
- for (var _len3 = arguments.length, values = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1831
- values[_key3] = arguments[_key3];
1997
+ for (var _len3 = arguments.length, values = new Array(_len3), _key4 = 0; _key4 < _len3; _key4++) {
1998
+ values[_key4] = arguments[_key4];
1832
1999
  }
1833
- for (var _i11 = 0, _values2 = values; _i11 < _values2.length; _i11++) {
1834
- var value = _values2[_i11];
2000
+ for (var _i17 = 0, _values2 = values; _i17 < _values2.length; _i17++) {
2001
+ var value = _values2[_i17];
1835
2002
  if (!isNumericAmount(value)) continue;
1836
2003
  var balance = new Decimal(value);
1837
2004
  if (balance.isFinite() && balance.isInteger() && balance.gte(0)) {
@@ -1860,17 +2027,17 @@ function getProductWalletDiscountPercent(asset) {
1860
2027
  _step7;
1861
2028
  try {
1862
2029
  for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1863
- var _record$metadata2, _record$discount12, _record$discount13, _record$discount14;
2030
+ var _record$metadata2, _record$discount15, _record$discount16, _record$discount17;
1864
2031
  var record = _step7.value;
1865
- var discountType = stringify(firstPresentValue(record.discount_card_type, (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.discount_card_type, (_record$discount12 = record.discount) === null || _record$discount12 === void 0 ? void 0 : _record$discount12.discount_card_type, (_record$discount13 = record.discount) === null || _record$discount13 === void 0 || (_record$discount13 = _record$discount13.metadata) === null || _record$discount13 === void 0 ? void 0 : _record$discount13.discount_card_type)).trim().toLowerCase();
2032
+ var discountType = stringify(firstPresentValue(record.discount_card_type, (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.discount_card_type, (_record$discount15 = record.discount) === null || _record$discount15 === void 0 ? void 0 : _record$discount15.discount_card_type, (_record$discount16 = record.discount) === null || _record$discount16 === void 0 || (_record$discount16 = _record$discount16.metadata) === null || _record$discount16 === void 0 ? void 0 : _record$discount16.discount_card_type)).trim().toLowerCase();
1866
2033
  if (discountType && discountType !== 'percent' && discountType !== 'percentage') continue;
1867
- var candidates = [record.percent, (_record$discount14 = record.discount) === null || _record$discount14 === void 0 ? void 0 : _record$discount14.percent];
2034
+ var candidates = [record.percent, (_record$discount17 = record.discount) === null || _record$discount17 === void 0 ? void 0 : _record$discount17.percent];
1868
2035
  if (discountType === 'percent' || discountType === 'percentage') {
1869
- var _record$discount15;
1870
- candidates.push(record.par_value, (_record$discount15 = record.discount) === null || _record$discount15 === void 0 ? void 0 : _record$discount15.par_value);
2036
+ var _record$discount18;
2037
+ candidates.push(record.par_value, (_record$discount18 = record.discount) === null || _record$discount18 === void 0 ? void 0 : _record$discount18.par_value);
1871
2038
  }
1872
- for (var _i12 = 0, _candidates = candidates; _i12 < _candidates.length; _i12++) {
1873
- var value = _candidates[_i12];
2039
+ for (var _i18 = 0, _candidates = candidates; _i18 < _candidates.length; _i18++) {
2040
+ var value = _candidates[_i18];
1874
2041
  if (!isNumericAmount(value)) continue;
1875
2042
  var percent = new Decimal(value);
1876
2043
  if (percent.isFinite() && percent.gt(0) && percent.lte(100)) {
@@ -1891,9 +2058,9 @@ function getProductWalletMoneyBalance(asset) {
1891
2058
  try {
1892
2059
  for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1893
2060
  var record = _step8.value;
1894
- for (var _i13 = 0, _arr7 = [(_record$metadata3 = record.metadata) === null || _record$metadata3 === void 0 ? void 0 : _record$metadata3.balance, record.balance, (_record$discount16 = record.discount) === null || _record$discount16 === void 0 || (_record$discount16 = _record$discount16.metadata) === null || _record$discount16 === void 0 ? void 0 : _record$discount16.balance, (_record$discount17 = record.discount) === null || _record$discount17 === void 0 ? void 0 : _record$discount17.balance]; _i13 < _arr7.length; _i13++) {
1895
- var _record$metadata3, _record$discount16, _record$discount17;
1896
- var value = _arr7[_i13];
2061
+ for (var _i19 = 0, _arr11 = [(_record$metadata3 = record.metadata) === null || _record$metadata3 === void 0 ? void 0 : _record$metadata3.balance, record.balance, (_record$discount19 = record.discount) === null || _record$discount19 === void 0 || (_record$discount19 = _record$discount19.metadata) === null || _record$discount19 === void 0 ? void 0 : _record$discount19.balance, (_record$discount20 = record.discount) === null || _record$discount20 === void 0 ? void 0 : _record$discount20.balance]; _i19 < _arr11.length; _i19++) {
2062
+ var _record$metadata3, _record$discount19, _record$discount20;
2063
+ var value = _arr11[_i19];
1897
2064
  if (!isNumericAmount(value)) continue;
1898
2065
  return Decimal.max(new Decimal(value), 0);
1899
2066
  }
@@ -1907,10 +2074,10 @@ function getProductWalletMoneyBalance(asset) {
1907
2074
  _step9;
1908
2075
  try {
1909
2076
  for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1910
- var _record$discount18, _record$discount19;
1911
- var _record = _step9.value;
1912
- var parValue = firstPresentValue(_record.par_value, (_record$discount18 = _record.discount) === null || _record$discount18 === void 0 ? void 0 : _record$discount18.par_value);
1913
- var usedParValue = firstPresentValue(_record.used_par_value, (_record$discount19 = _record.discount) === null || _record$discount19 === void 0 ? void 0 : _record$discount19.used_par_value);
2077
+ var _record2$discount, _record2$discount2;
2078
+ var _record2 = _step9.value;
2079
+ var parValue = firstPresentValue(_record2.par_value, (_record2$discount = _record2.discount) === null || _record2$discount === void 0 ? void 0 : _record2$discount.par_value);
2080
+ var usedParValue = firstPresentValue(_record2.used_par_value, (_record2$discount2 = _record2.discount) === null || _record2$discount2 === void 0 ? void 0 : _record2$discount2.used_par_value);
1914
2081
  if (!isNumericAmount(parValue) || !isNumericAmount(usedParValue)) continue;
1915
2082
  return Decimal.max(new Decimal(parValue).minus(new Decimal(usedParValue)), 0);
1916
2083
  }
@@ -1931,35 +2098,36 @@ function buildPointCardSnapshotAssets(params) {
1931
2098
  var pointCard = snapshot;
1932
2099
  if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
1933
2100
  var assetId = normalizeWalletPassId(pointCard.id);
2101
+ if (!params.allowAsset(getVoucherAssetIdentity(pointCard), pointCard.tag)) return [];
1934
2102
  if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1935
2103
  id: assetId,
1936
2104
  codes: []
1937
2105
  })) return [];
1938
- var rows = [{
2106
+ var rows = [_objectSpread(_objectSpread({}, receiptKey(pointCard, 'asset-name')), {}, {
1939
2107
  item: appendMaskedCardCode(stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'), pointCard.code),
1940
2108
  value: ''
1941
- }];
2109
+ })];
1942
2110
  var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
1943
2111
  if (remainingPoints) {
1944
- rows.push({
2112
+ rows.push(_objectSpread(_objectSpread({}, receiptKey(pointCard, 'remainingPoints')), {}, {
1945
2113
  item: label(params.locale, 'remainingPoints'),
1946
2114
  value: trimDecimal(remainingPoints)
1947
- });
2115
+ }));
1948
2116
  }
1949
2117
  if (isPresentId(snapshotTime)) {
1950
- rows.push({
2118
+ rows.push(_objectSpread(_objectSpread({}, receiptTimeKey(pointCard, 'asset-time')), {}, {
1951
2119
  item: formatDateTime(snapshotTime, params.locale),
1952
2120
  value: ''
1953
- });
2121
+ }));
1954
2122
  }
1955
2123
  return [rows];
1956
2124
  });
1957
2125
  }
1958
- function collectVirtualCurrencySnapshots(order) {
1959
- var _order$order_meta_lis;
2126
+ function collectVirtualCurrencySnapshots(order, allowAsset) {
2127
+ var _order$order_meta_lis3;
1960
2128
  var items = [];
1961
2129
  var byId = new Map();
1962
- var snapshots = (_order$order_meta_lis = order.order_meta_list) === null || _order$order_meta_lis === void 0 ? void 0 : _order$order_meta_lis.virtual_currency_snapshot;
2130
+ var snapshots = (_order$order_meta_lis3 = order.order_meta_list) === null || _order$order_meta_lis3 === void 0 ? void 0 : _order$order_meta_lis3.virtual_currency_snapshot;
1963
2131
  if (!Array.isArray(snapshots)) return {
1964
2132
  items: items,
1965
2133
  byId: byId
@@ -1968,6 +2136,7 @@ function collectVirtualCurrencySnapshots(order) {
1968
2136
  if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return;
1969
2137
  var virtualCurrency = snapshot;
1970
2138
  if (stringify(virtualCurrency.tag).trim().toLowerCase() !== 'virtual_currency') return;
2139
+ if (!allowAsset(getVoucherAssetIdentity(virtualCurrency), virtualCurrency.tag)) return;
1971
2140
  var id = normalizeWalletPassId(virtualCurrency.id);
1972
2141
  if (!id || byId.has(id)) return;
1973
2142
  byId.set(id, virtualCurrency);
@@ -1980,8 +2149,8 @@ function collectVirtualCurrencySnapshots(order) {
1980
2149
  }
1981
2150
  function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
1982
2151
  var fundRecord = getFundRecord(payment);
1983
- for (var _i14 = 0, _arr8 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i14 < _arr8.length; _i14++) {
1984
- var value = _arr8[_i14];
2152
+ for (var _i20 = 0, _arr12 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i20 < _arr12.length; _i20++) {
2153
+ var value = _arr12[_i20];
1985
2154
  var id = normalizeWalletPassId(value);
1986
2155
  if (!id) continue;
1987
2156
  var snapshot = snapshotsById.get(id);
@@ -1993,26 +2162,27 @@ function buildVirtualCurrencySnapshotAssets(params) {
1993
2162
  var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1994
2163
  return params.snapshots.flatMap(function (virtualCurrency) {
1995
2164
  var assetId = normalizeWalletPassId(virtualCurrency.id);
2165
+ if (!params.allowAsset(getVoucherAssetIdentity(virtualCurrency), virtualCurrency.tag)) return [];
1996
2166
  if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1997
2167
  id: assetId,
1998
2168
  codes: []
1999
2169
  })) return [];
2000
- var rows = [{
2170
+ var rows = [_objectSpread(_objectSpread({}, receiptKey(virtualCurrency, 'asset-name')), {}, {
2001
2171
  item: stringify(virtualCurrency.product_name).trim(),
2002
2172
  value: ''
2003
- }];
2173
+ })];
2004
2174
  var balance = getVirtualCurrencySnapshotBalance(virtualCurrency);
2005
2175
  if (balance) {
2006
- rows.push({
2176
+ rows.push(_objectSpread(_objectSpread({}, receiptKey(virtualCurrency, 'balance')), {}, {
2007
2177
  item: label(params.locale, 'balance'),
2008
2178
  value: formatVirtualCurrencyBalance(balance, getVirtualCurrencySnapshotUnit(virtualCurrency, params.locale))
2009
- });
2179
+ }));
2010
2180
  }
2011
2181
  if (isPresentId(snapshotTime)) {
2012
- rows.push({
2182
+ rows.push(_objectSpread(_objectSpread({}, receiptTimeKey(virtualCurrency, 'asset-time')), {}, {
2013
2183
  item: formatDateTime(snapshotTime, params.locale),
2014
2184
  value: ''
2015
- });
2185
+ }));
2016
2186
  }
2017
2187
  return [rows];
2018
2188
  });
@@ -2031,8 +2201,8 @@ function getNonEmptyLocalizedValue(value, locale) {
2031
2201
  if (_typeof(value) !== 'object' || Array.isArray(value)) return stringify(value).trim();
2032
2202
  var dashedLocale = locale.replace('_', '-');
2033
2203
  var underscoredLocale = locale.replace('-', '_');
2034
- for (var _i15 = 0, _arr9 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i15 < _arr9.length; _i15++) {
2035
- var candidate = _arr9[_i15];
2204
+ for (var _i21 = 0, _arr13 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i21 < _arr13.length; _i21++) {
2205
+ var candidate = _arr13[_i21];
2036
2206
  var text = stringify(candidate).trim();
2037
2207
  if (text) return text;
2038
2208
  }
@@ -2049,19 +2219,19 @@ function normalizeWalletPassId(value) {
2049
2219
  return value.trim() || null;
2050
2220
  }
2051
2221
  function firstNormalizedWalletAssetId() {
2052
- for (var _len4 = arguments.length, values = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2053
- values[_key4] = arguments[_key4];
2222
+ for (var _len4 = arguments.length, values = new Array(_len4), _key5 = 0; _key5 < _len4; _key5++) {
2223
+ values[_key5] = arguments[_key5];
2054
2224
  }
2055
- for (var _i16 = 0, _values3 = values; _i16 < _values3.length; _i16++) {
2056
- var value = _values3[_i16];
2225
+ for (var _i22 = 0, _values3 = values; _i22 < _values3.length; _i22++) {
2226
+ var value = _values3[_i22];
2057
2227
  var id = normalizeWalletPassId(value);
2058
2228
  if (id) return id;
2059
2229
  }
2060
2230
  return null;
2061
2231
  }
2062
2232
  function normalizeWalletAssetCodes() {
2063
- for (var _len5 = arguments.length, values = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2064
- values[_key5] = arguments[_key5];
2233
+ for (var _len5 = arguments.length, values = new Array(_len5), _key6 = 0; _key6 < _len5; _key6++) {
2234
+ values[_key6] = arguments[_key6];
2065
2235
  }
2066
2236
  return Array.from(new Set(values.map(function (value) {
2067
2237
  return normalizeWalletPassId(value);
@@ -2118,49 +2288,50 @@ function buildVoucherAssets(params) {
2118
2288
  var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
2119
2289
  return normalizeArray(params.order.vouchers).flatMap(function (voucher) {
2120
2290
  if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
2291
+ if (!params.allowAsset(getVoucherAssetIdentity(voucher), voucher.tag)) return [];
2121
2292
  if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, getVoucherAssetIdentity(voucher))) return [];
2122
2293
  var name = getVoucherAssetName(voucher, params.locale);
2123
2294
  var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
2124
- var timeRow = isPresentId(assetTime) ? {
2295
+ var timeRow = isPresentId(assetTime) ? _objectSpread(_objectSpread({}, receiptTimeKey(voucher, 'asset-time')), {}, {
2125
2296
  item: formatDateTime(assetTime, params.locale),
2126
2297
  value: ''
2127
- } : null;
2298
+ }) : null;
2128
2299
  if (isEntitlementVoucher(voucher)) {
2129
2300
  var _voucher$metadata;
2130
2301
  var remaining = getEntitlementBalance((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.balance, voucher.balance);
2131
- return [[{
2302
+ return [[_objectSpread(_objectSpread({}, receiptKey(voucher, 'asset-name')), {}, {
2132
2303
  item: name,
2133
2304
  value: ''
2134
- }].concat(_toConsumableArray(remaining ? [{
2305
+ })].concat(_toConsumableArray(remaining ? [_objectSpread(_objectSpread({}, receiptKey(voucher, 'entitlementRemaining')), {}, {
2135
2306
  item: label(params.locale, 'entitlementRemaining'),
2136
2307
  value: formatEntitlementUses(remaining, params.locale)
2137
- }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
2308
+ })] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
2138
2309
  }
2139
2310
  if (isTicketVoucher(voucher)) {
2140
2311
  var validity = getVoucherValidity(voucher, params.locale);
2141
- return [[{
2312
+ return [[_objectSpread(_objectSpread({}, receiptKey(voucher, 'asset-name')), {}, {
2142
2313
  item: name,
2143
2314
  value: ''
2144
- }].concat(_toConsumableArray(validity ? [{
2315
+ })].concat(_toConsumableArray(validity ? [_objectSpread(_objectSpread({}, receiptKey(voucher, 'validity')), {}, {
2145
2316
  item: label(params.locale, 'validity'),
2146
2317
  value: validity
2147
- }] : []))];
2318
+ })] : []))];
2148
2319
  }
2149
2320
  var percent = getVoucherDiscountPercent(voucher);
2150
2321
  if (percent) {
2151
- return [[{
2322
+ return [[_objectSpread(_objectSpread({}, receiptKey(voucher, 'asset-discount')), {}, {
2152
2323
  item: appendPercentToVoucherName(name, percent),
2153
2324
  value: formatVoucherDiscount(percent, params.locale)
2154
- }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
2325
+ })].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
2155
2326
  }
2156
2327
  var balance = getVoucherBalance(voucher);
2157
- return [[{
2328
+ return [[_objectSpread(_objectSpread({}, receiptKey(voucher, 'asset-name')), {}, {
2158
2329
  item: name,
2159
2330
  value: ''
2160
- }, {
2331
+ }), _objectSpread(_objectSpread({}, receiptKey(voucher, 'balance')), {}, {
2161
2332
  item: label(params.locale, 'balance'),
2162
2333
  value: formatMoney(balance, params.currencySymbol)
2163
- }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
2334
+ })].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
2164
2335
  });
2165
2336
  }
2166
2337
  var TICKET_VOUCHER_TAGS = new Set(['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket']);
@@ -2278,9 +2449,9 @@ function formatVoucherDiscount(percent, locale) {
2278
2449
  return normalizedLocale === 'en' ? "Discount ".concat(trimDecimal(percent), "% OFF") : "".concat(trimDecimal(percent), "% OFF");
2279
2450
  }
2280
2451
  function getVoucherBalance(voucher) {
2281
- for (var _i17 = 0, _arr10 = [(_voucher$metadata15 = voucher.metadata) === null || _voucher$metadata15 === void 0 ? void 0 : _voucher$metadata15.balance, voucher.balance]; _i17 < _arr10.length; _i17++) {
2452
+ for (var _i23 = 0, _arr14 = [(_voucher$metadata15 = voucher.metadata) === null || _voucher$metadata15 === void 0 ? void 0 : _voucher$metadata15.balance, voucher.balance]; _i23 < _arr14.length; _i23++) {
2282
2453
  var _voucher$metadata15;
2283
- var value = _arr10[_i17];
2454
+ var value = _arr14[_i23];
2284
2455
  if (!isNumericAmount(value)) continue;
2285
2456
  return Decimal.max(new Decimal(value), 0);
2286
2457
  }
@@ -2297,20 +2468,20 @@ function buildPaymentItems(params) {
2297
2468
  includePaymentAmount = params.includePaymentAmount,
2298
2469
  virtualCurrencyUnit = params.virtualCurrencyUnit;
2299
2470
  var serviceFee = getPaymentServiceFee(payment);
2300
- var items = [{
2471
+ var items = [_objectSpread(_objectSpread({}, receiptKey(payment, 'payment')), {}, {
2301
2472
  item: paymentMethodName(payment, locale),
2302
2473
  value: includePaymentAmount ? formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol) : ''
2303
- }];
2474
+ })];
2304
2475
  items.push.apply(items, _toConsumableArray(buildCashChangePaymentItems({
2305
2476
  payment: payment,
2306
2477
  locale: locale,
2307
2478
  currencySymbol: currencySymbol
2308
2479
  })));
2309
2480
  if (serviceFee.gt(0)) {
2310
- items.push({
2481
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'surchargeIncluded')), {}, {
2311
2482
  item: label(locale, 'surchargeIncluded'),
2312
2483
  value: formatMoney(serviceFee, currencySymbol)
2313
- });
2484
+ }));
2314
2485
  }
2315
2486
  var fundRecord = getFundRecord(payment);
2316
2487
  if (fundRecord) {
@@ -2324,20 +2495,24 @@ function buildPaymentItems(params) {
2324
2495
  virtualCurrencyUnit: virtualCurrencyUnit
2325
2496
  })));
2326
2497
  } else {
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;
2498
+ var _ref69, _payment$remaining_am, _payment$metadata;
2499
+ var remainingAmount = (_ref69 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref69 !== void 0 ? _ref69 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
2329
2500
  if (remainingAmount !== undefined && remainingAmount !== null) {
2330
- items.push({
2501
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'remainingAmount')), {}, {
2331
2502
  item: label(locale, 'remainingAmount'),
2332
2503
  value: formatMoney(remainingAmount, currencySymbol)
2333
- });
2504
+ }));
2334
2505
  }
2335
2506
  }
2336
- items.push({
2507
+ items.push(_objectSpread(_objectSpread({}, receiptTimeKey(payment, 'payment-time')), {}, {
2337
2508
  item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), locale),
2338
2509
  value: ''
2510
+ }));
2511
+ return items.map(function (item) {
2512
+ return item.receipt_key ? _objectSpread(_objectSpread({}, item), {}, {
2513
+ receipt_key: "".concat(item.receipt_key, "/").concat(includeFundRecordBalance ? 'wallet' : 'history')
2514
+ }) : item;
2339
2515
  });
2340
- return items;
2341
2516
  }
2342
2517
  function getPaymentServiceFee(payment) {
2343
2518
  return new Decimal(toMoneyNumber(payment.service_fee));
@@ -2356,13 +2531,13 @@ function buildCashChangePaymentItems(params) {
2356
2531
  locale = params.locale,
2357
2532
  currencySymbol = params.currencySymbol;
2358
2533
  if (!shouldDisplayCashChange(payment)) return [];
2359
- return [{
2534
+ return [_objectSpread(_objectSpread({}, receiptKey(payment, 'cashReceived')), {}, {
2360
2535
  item: label(locale, 'cashReceived'),
2361
2536
  value: formatMoney(payment.metadata.actual_paid_amount, currencySymbol)
2362
- }, {
2537
+ }), _objectSpread(_objectSpread({}, receiptKey(payment, 'changeDue')), {}, {
2363
2538
  item: label(locale, 'changeDue'),
2364
2539
  value: formatMoney(payment.metadata.change_given_amount, currencySymbol)
2365
- }];
2540
+ })];
2366
2541
  }
2367
2542
  function shouldDisplayCashChange(payment) {
2368
2543
  var _payment$code, _payment$metadata2, _payment$metadata3;
@@ -2394,32 +2569,32 @@ function buildFundRecordPaymentItems(params) {
2394
2569
  if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
2395
2570
  var usedPoints = new Decimal(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
2396
2571
  if (includeUsage) {
2397
- items.push({
2572
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'redeemPoints')), {}, {
2398
2573
  item: label(locale, 'redeemPoints'),
2399
2574
  value: trimDecimal(usedPoints)
2400
- });
2575
+ }));
2401
2576
  }
2402
2577
  if (includeBalance) {
2403
- items.push({
2578
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'remainingPoints')), {}, {
2404
2579
  item: label(locale, 'remainingPoints'),
2405
2580
  value: trimDecimal(new Decimal(toMoneyNumber(usingAfterValue)))
2406
- });
2581
+ }));
2407
2582
  }
2408
2583
  return items;
2409
2584
  }
2410
2585
  if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
2411
2586
  if (virtualCurrencyUnit !== undefined) {
2412
2587
  if (!isNumericAmount(usingAfterValue)) return items;
2413
- items.push({
2588
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'balance')), {}, {
2414
2589
  item: label(locale, 'balance'),
2415
2590
  value: formatVirtualCurrencyBalance(new Decimal(usingAfterValue), virtualCurrencyUnit)
2416
- });
2591
+ }));
2417
2592
  return items;
2418
2593
  }
2419
- items.push({
2594
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'balance')), {}, {
2420
2595
  item: label(locale, 'balance'),
2421
2596
  value: formatMoney(usingAfterValue, currencySymbol)
2422
- });
2597
+ }));
2423
2598
  }
2424
2599
  return items;
2425
2600
  }
@@ -2490,12 +2665,12 @@ function label(locale, key) {
2490
2665
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
2491
2666
  }
2492
2667
  function getLocalizedValue(value, locale) {
2493
- var _ref62, _ref63, _ref64, _ref65, _ref66, _ref67, _value$locale2;
2668
+ var _ref70, _ref71, _ref72, _ref73, _ref74, _ref75, _value$locale2;
2494
2669
  if (value === undefined || value === null) return '';
2495
2670
  if (_typeof(value) !== 'object') return stringify(value);
2496
2671
  var dashedLocale = locale.replace('_', '-');
2497
2672
  var underscoredLocale = locale.replace('-', '_');
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 : '');
2673
+ return stringify((_ref70 = (_ref71 = (_ref72 = (_ref73 = (_ref74 = (_ref75 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref75 !== void 0 ? _ref75 : value[underscoredLocale]) !== null && _ref74 !== void 0 ? _ref74 : value.original) !== null && _ref73 !== void 0 ? _ref73 : value.auto) !== null && _ref72 !== void 0 ? _ref72 : value.default) !== null && _ref71 !== void 0 ? _ref71 : value.en) !== null && _ref70 !== void 0 ? _ref70 : '');
2499
2674
  }
2500
2675
  function resolveServiceTypeLabelKey(serviceType) {
2501
2676
  return SERVICE_TYPE_LABEL_KEYS[serviceType] || null;