@pisell/pisellos 2.3.138 → 2.3.139

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.
@@ -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,68 @@ 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
24
  var DEFAULT_LOCALES = ['en', 'zh_CN'];
25
+
26
+ // Attach provenance to a private copy BEFORE any locale-dependent filtering.
27
+ // Symbols survive the existing spread-based normalization, never enter JSON,
28
+ // and leave both the caller's snapshot and the default native contract intact.
29
+ var RECEIPT_SOURCE = Symbol('customerReceiptSource');
30
+ function copyReceiptSource(value) {
31
+ var _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _value$metadata$uniqu, _value$metadata;
32
+ var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'order';
33
+ if (Array.isArray(value)) return value.map(function (item, index) {
34
+ return copyReceiptSource(item, "".concat(path, "/").concat(index));
35
+ });
36
+ if (!value || _typeof(value) !== 'object' || Object.getPrototypeOf(value) !== Object.prototype) return value;
37
+ 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;
38
+ var source = Object.fromEntries(Object.entries(value).map(function (_ref7) {
39
+ var _ref8 = _slicedToArray(_ref7, 2),
40
+ key = _ref8[0],
41
+ item = _ref8[1];
42
+ return [key, copyReceiptSource(item, "".concat(path, "/").concat(key))];
43
+ }));
44
+ // Retain the original occurrence even when a catalogue ID appears twice.
45
+ return _objectSpread(_objectSpread({}, source), {}, _defineProperty({}, RECEIPT_SOURCE, "".concat(path).concat(id != null ? "@".concat(encodeURIComponent(String(id))) : '')));
46
+ }
47
+ function receiptKey(source, kind) {
48
+ var valueKind = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'shared';
49
+ var key = source === null || source === void 0 ? void 0 : source[RECEIPT_SOURCE];
50
+ return typeof key === 'string' ? {
51
+ receipt_key: "".concat(key, "#").concat(kind),
52
+ receipt_value_kind: valueKind
53
+ } : {};
54
+ }
55
+ function receiptSourceIndex(source, index) {
56
+ return source !== null && source !== void 0 && source[RECEIPT_SOURCE] ? {
57
+ receipt_source_index: index
58
+ } : {};
59
+ }
60
+ function removePrivateReceiptSource(value) {
61
+ if (!value || _typeof(value) !== 'object') return;
62
+ delete value[RECEIPT_SOURCE];
63
+ Object.values(value).forEach(removePrivateReceiptSource);
64
+ }
65
+ function receiptTimeKey(source, kind) {
66
+ var identity = receiptKey(source, kind);
67
+ return identity.receipt_key ? _objectSpread(_objectSpread({}, identity), {}, {
68
+ receipt_item_kind: 'shared'
69
+ }) : {};
70
+ }
25
71
  var SERVICE_TYPE_LABEL_KEYS = {
26
72
  takeaway: 'takeAway',
27
73
  pick_up: 'pickUp',
@@ -259,11 +305,11 @@ var LABELS = {
259
305
  }
260
306
  };
261
307
  export function buildSmallTicketData(params) {
262
- var order = params.order || {};
308
+ var order = params.includeReceiptKeys ? copyReceiptSource(params.order || {}) : params.order || {};
263
309
  var shopInfo = params.shopInfo || {};
264
310
  var locales = resolveLocales(shopInfo, params.locales);
265
311
  var productMap = params.productMap || {};
266
- return locales.reduce(function (data, locale) {
312
+ var result = locales.reduce(function (data, locale) {
267
313
  data[locale] = buildLocaleData({
268
314
  order: order,
269
315
  shopInfo: shopInfo,
@@ -272,6 +318,8 @@ export function buildSmallTicketData(params) {
272
318
  });
273
319
  return data;
274
320
  }, {});
321
+ if (params.includeReceiptKeys) removePrivateReceiptSource(result);
322
+ return result;
275
323
  }
276
324
  export function hasSmallTicketData(value) {
277
325
  return !!value && _typeof(value) === 'object' && Object.keys(value).length > 0;
@@ -320,7 +368,11 @@ function buildLocaleData(params) {
320
368
  locale: locale,
321
369
  currencySymbol: currencySymbol
322
370
  }),
323
- tickets: Array.isArray(order.tickets) ? order.tickets : [],
371
+ tickets: Array.isArray(order.tickets) ? order.tickets.map(function (group) {
372
+ return Array.isArray(group) ? group.map(function (row) {
373
+ return row && _typeof(row) === 'object' ? _objectSpread(_objectSpread({}, row), receiptKey(row, 'ticket')) : row;
374
+ }) : group;
375
+ }) : [],
324
376
  source_shop: [],
325
377
  refund_data: buildRefundData({
326
378
  order: order,
@@ -362,12 +414,12 @@ function buildBaseData(params) {
362
414
  function buildProducts(order, locale, productMap) {
363
415
  var products = Array.isArray(order.products) ? order.products : [];
364
416
  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;
417
+ return products.map(function (rawProduct, sourceIndex) {
418
+ 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
419
  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;
420
+ 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);
421
+ 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;
422
+ 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
423
  var productTitle = resolveProductTitle({
372
424
  product: product,
373
425
  productMap: productMap,
@@ -407,7 +459,9 @@ function buildProducts(order, locale, productMap) {
407
459
  var basePrice = resolveProductBasePrice(product);
408
460
  var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
409
461
  var shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
410
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
462
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, receiptKey(rawProduct, 'product')), rawProduct[RECEIPT_SOURCE] ? {
463
+ receipt_source_index: sourceIndex
464
+ } : {}), {}, {
411
465
  product_title: productTitle,
412
466
  product_quantity: quantity,
413
467
  selling_price: formatMoney(sellingPrice, currencySymbol),
@@ -519,19 +573,19 @@ function getReceiptDiscountBundleMapId(discount) {
519
573
  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
574
  }
521
575
  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;
576
+ var _ref16, _left$discount$resour, _left$discount, _ref17, _right$discount$resou, _right$discount, _ref18, _ref19, _left$amount, _ref20, _ref21, _right$amount;
523
577
  var leftOrderDiscountId = normalizeReceiptId(left === null || left === void 0 ? void 0 : left.order_discount_id);
524
578
  var rightOrderDiscountId = normalizeReceiptId(right === null || right === void 0 ? void 0 : right.order_discount_id);
525
579
  if (leftOrderDiscountId && rightOrderDiscountId) {
526
580
  return leftOrderDiscountId === rightOrderDiscountId;
527
581
  }
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);
582
+ 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);
583
+ 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
584
  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 : '');
585
+ 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
586
  }
533
587
  function resolveProductBasePrice(product) {
534
- var _product$product_vari, _ref14, _ref15, _product$product_quan2, _product$product_sku, _product$_origin, _product$_origin2;
588
+ var _product$product_vari, _ref22, _ref23, _product$product_quan2, _product$product_sku, _product$_origin, _product$_origin2;
535
589
  var metadata = product.metadata || {};
536
590
  var origin = product._origin || metadata.origin || {};
537
591
  var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
@@ -539,7 +593,7 @@ function resolveProductBasePrice(product) {
539
593
  return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
540
594
  }) : undefined;
541
595
  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);
596
+ 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
597
  var hasEntitlementPass = normalizeArray(product.discount_list).some(function (discount) {
544
598
  return getProductWalletDiscountType(discount) === 'entitlement_pass';
545
599
  });
@@ -558,44 +612,44 @@ function normalizeProductDiscounts(params) {
558
612
  currencySymbol = params.currencySymbol,
559
613
  quantity = params.quantity;
560
614
  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;
615
+ var _ref24, _discount$amount;
616
+ 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
617
  return isNonZero(amount);
564
618
  }).map(function (discount) {
565
- var _ref17, _discount$amount2;
619
+ var _ref25, _discount$amount2;
566
620
  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;
621
+ 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
622
  var isMarkup = isManualMarkup(discount);
569
623
  var isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
570
624
  var isEntitlementPass = getProductWalletDiscountType(discount) === 'entitlement_pass';
571
625
  var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount || isEntitlementPass ? 1 : quantity);
572
626
  var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
573
- return {
627
+ return _objectSpread(_objectSpread({}, receiptKey(discount, 'discount')), {}, {
574
628
  item: title,
575
629
  value: formattedAmount,
576
630
  isMarkup: isMarkup
577
- };
631
+ });
578
632
  });
579
633
  return rows.sort(function (left, right) {
580
634
  return Number(right.isMarkup) - Number(left.isMarkup);
581
- }).map(function (_ref18) {
582
- var _isMarkup = _ref18.isMarkup,
583
- row = _objectWithoutProperties(_ref18, _excluded);
635
+ }).map(function (_ref26) {
636
+ var _isMarkup = _ref26.isMarkup,
637
+ row = _objectWithoutProperties(_ref26, _excluded);
584
638
  return row;
585
639
  });
586
640
  }
587
641
  function isManualMarkup(discount) {
588
- var _discount$discount, _ref19, _discount$amount3;
642
+ var _discount$discount, _ref27, _discount$amount3;
589
643
  if (discount.type !== 'product') return false;
590
644
  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;
645
+ 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
646
  return new Decimal(toMoneyNumber(amount)).isNegative();
593
647
  }
594
648
  function hasProductDiscount(product) {
595
649
  var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
596
650
  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);
651
+ var _ref28, _discount$amount4;
652
+ 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
653
  });
600
654
  return hasDiscountListAmount || extensionList.some(function (row) {
601
655
  return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
@@ -617,15 +671,17 @@ function buildProductExtensionList(params) {
617
671
  product: product,
618
672
  locale: locale,
619
673
  currencySymbol: currencySymbol
620
- })), _toConsumableArray(quantity > 1 ? [{
674
+ })), _toConsumableArray(quantity > 1 ? [_objectSpread(_objectSpread({}, receiptTimeKey(product, 'quantity-price')), {}, {
621
675
  item: buildProductQuantityPriceText({
622
676
  quantity: quantity,
623
677
  currencySymbol: currencySymbol,
624
678
  price: originalPrice
625
679
  }),
626
680
  value: ''
627
- }] : []));
628
- var productExtensionList = extensionList.length ? extensionList : normalizeArray(product.extension_list);
681
+ })] : []));
682
+ var productExtensionList = extensionList.length ? extensionList : normalizeArray(product.extension_list).map(function (row) {
683
+ return _objectSpread(_objectSpread({}, row), receiptKey(row, 'extension'));
684
+ });
629
685
  return [].concat(_toConsumableArray(productExtensionList), _toConsumableArray(discountList));
630
686
  }
631
687
  function buildProductOpenWeightRows(params) {
@@ -641,22 +697,22 @@ function buildProductOpenWeightRows(params) {
641
697
  var rows = [];
642
698
  if (hasTare) {
643
699
  var _productSku$weight;
644
- rows.push({
700
+ rows.push(_objectSpread(_objectSpread({}, receiptKey(product, 'gross')), {}, {
645
701
  item: "".concat(manualFlag).concat(label(locale, 'gross'), ": ").concat((_productSku$weight = productSku.weight) !== null && _productSku$weight !== void 0 ? _productSku$weight : 0).concat(unit),
646
702
  value: ''
647
- });
648
- rows.push({
703
+ }));
704
+ rows.push(_objectSpread(_objectSpread({}, receiptKey(product, 'tare')), {}, {
649
705
  item: "".concat(label(locale, 'tare'), ": ").concat(productSku.tare_weight).concat(unit),
650
706
  value: ''
651
- });
707
+ }));
652
708
  }
653
709
  var netWeight = (_productSku$net_weigh = productSku.net_weight) !== null && _productSku$net_weigh !== void 0 ? _productSku$net_weigh : 0;
654
710
  var unitPrice = (_productSku$unit_pric = productSku.unit_price) !== null && _productSku$unit_pric !== void 0 ? _productSku$unit_pric : 0;
655
711
  var netItem = "".concat(netWeight, " ").concat(unit, " NET @ ").concat(currencySymbol).concat(unitPrice, "/").concat(unit);
656
- rows.push({
712
+ rows.push(_objectSpread(_objectSpread({}, receiptTimeKey(product, 'net-weight')), {}, {
657
713
  item: hasTare ? netItem : "".concat(manualFlag).concat(netItem),
658
714
  value: ''
659
- });
715
+ }));
660
716
  return rows;
661
717
  }
662
718
  function buildProductQuantityPriceText(params) {
@@ -680,8 +736,8 @@ function resolveDiscountTitleWithPercent(discount, locale) {
680
736
  return "".concat(title, " (").concat(percent, "%)");
681
737
  }
682
738
  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);
739
+ var _ref29, _ref30, _ref31, _ref32, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
740
+ 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
741
  if (title) return title;
686
742
  if (discount.type === 'product') {
687
743
  return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
@@ -707,17 +763,17 @@ function normalizeProductOptions(params) {
707
763
  currencySymbol = params.currencySymbol,
708
764
  parentProduct = params.parentProduct;
709
765
  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;
766
+ return rawOptions.map(function (option, sourceIndex) {
767
+ var _ref33, _option$original_pric, _ref34, _option$num, _ref35, _option$value;
768
+ 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;
769
+ var quantity = toNumber((_ref34 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref34 !== void 0 ? _ref34 : 1, 1);
770
+ var value = (_ref35 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref35 !== void 0 ? _ref35 : option.item;
715
771
  var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
716
772
  option: option,
717
773
  parentProduct: parentProduct,
718
774
  locale: locale
719
775
  });
720
- return _objectSpread(_objectSpread(_objectSpread({
776
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, receiptKey(option, 'option')), receiptSourceIndex(option, sourceIndex)), {}, {
721
777
  name: name
722
778
  }, option.num !== undefined || option.quantity !== undefined ? {
723
779
  num: quantity
@@ -737,8 +793,8 @@ function normalizeProductCombinations(params) {
737
793
  currencySymbol = params.currencySymbol,
738
794
  parentProduct = params.parentProduct;
739
795
  var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
740
- return bundles.map(function (bundle) {
741
- var _ref28, _bundle$num;
796
+ return bundles.map(function (bundle, sourceIndex) {
797
+ var _ref36, _bundle$num;
742
798
  var combinationsOptions = normalizeProductOptions({
743
799
  product: {},
744
800
  locale: locale,
@@ -754,7 +810,7 @@ function normalizeProductCombinations(params) {
754
810
  });
755
811
  var productNote = resolveProductNote(bundle, locale);
756
812
  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);
813
+ 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
814
  var formattedPrice = formatBundlePrice(bundle, currencySymbol);
759
815
  var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
760
816
  var explicitBasePrice = resolveCombinationBasePrice(bundle);
@@ -767,7 +823,7 @@ function normalizeProductCombinations(params) {
767
823
  originalPrice: formattedPrice
768
824
  });
769
825
  var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle, extensionList);
770
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
826
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, receiptKey(bundle, 'combination')), receiptSourceIndex(bundle, sourceIndex)), {}, {
771
827
  product_title: baseTitle,
772
828
  product_quantity: quantity,
773
829
  price: formattedPrice,
@@ -790,8 +846,8 @@ function normalizeProductCombinations(params) {
790
846
  });
791
847
  }
792
848
  function normalizeExistingCombinations(combinations, locale, currencySymbol) {
793
- return combinations.map(function (combination) {
794
- var _ref29, _ref30, _combination$product_, _firstPresentValue;
849
+ return combinations.map(function (combination, sourceIndex) {
850
+ var _ref37, _ref38, _combination$product_, _firstPresentValue;
795
851
  if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
796
852
  return combination;
797
853
  }
@@ -811,7 +867,7 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
811
867
  delete snapshot.note;
812
868
  delete snapshot.combinations;
813
869
  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);
870
+ 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
871
  var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
816
872
  var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
817
873
  return option.total_price;
@@ -826,7 +882,7 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
826
882
  originalPrice: unitPrice
827
883
  });
828
884
  var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
829
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), productTitle ? {
885
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), receiptKey(combination, 'combination')), receiptSourceIndex(combination, sourceIndex)), productTitle ? {
830
886
  product_title: productTitle
831
887
  } : {}), {}, {
832
888
  product_quantity: quantity,
@@ -896,7 +952,7 @@ function buildProductAllergyMap(order, locale) {
896
952
  return allergyByProductUid;
897
953
  }
898
954
  function resolveBundleProductTitle(params) {
899
- var _ref31, _ref32, _bundle$bundle_produc;
955
+ var _ref39, _ref40, _bundle$bundle_produc;
900
956
  var bundle = params.bundle,
901
957
  productMap = params.productMap,
902
958
  locale = params.locale,
@@ -909,7 +965,7 @@ function resolveBundleProductTitle(params) {
909
965
  });
910
966
  var parentBundleTitle = parentBundleItem ? getBundleProductTitleSource(parentBundleItem, locale) : '';
911
967
  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;
968
+ 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
969
  var fallbackProduct = resolveProductFromMap(productId, productMap);
914
970
  if (!fallbackProduct) return '';
915
971
  return getBundleProductTitleSource(fallbackProduct, locale);
@@ -961,10 +1017,10 @@ function resolveVariantTextFromSkuKey(params) {
961
1017
  }
962
1018
  function resolveVariantTextFromNameMap(params) {
963
1019
  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];
1020
+ return Object.entries(params.nameMap).map(function (_ref41) {
1021
+ var _ref42 = _slicedToArray(_ref41, 2),
1022
+ groupPositionId = _ref42[0],
1023
+ value = _ref42[1];
968
1024
  var group = resolveVariantGroup(params.parentProduct, groupPositionId);
969
1025
  if (!group) return '';
970
1026
  var groupName = getLocalizedValue(group.name, params.locale);
@@ -1002,12 +1058,12 @@ function getBundleProductTitleSource(source, locale) {
1002
1058
  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
1059
  }
1004
1060
  function resolveTitleValue(value, locale) {
1005
- var _ref35, _ref36, _ref37, _ref38, _value$locale;
1061
+ var _ref43, _ref44, _ref45, _ref46, _value$locale;
1006
1062
  if (value === undefined || value === null) return '';
1007
1063
  if (_typeof(value) !== 'object') return stringify(value);
1008
1064
  var dashedLocale = locale.replace('_', '-');
1009
1065
  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 : '');
1066
+ 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
1067
  }
1012
1068
  function resolveOptionTitleFromParentProduct(params) {
1013
1069
  var option = params.option,
@@ -1025,17 +1081,17 @@ function flattenOptionItems(parentProduct) {
1025
1081
  return optionGroups.flatMap(function (group) {
1026
1082
  var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
1027
1083
  return items.map(function (item) {
1028
- var _ref39, _item$option_group_id;
1084
+ var _ref47, _item$option_group_id;
1029
1085
  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
1086
+ 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
1087
  });
1032
1088
  });
1033
1089
  });
1034
1090
  }
1035
1091
  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;
1092
+ var _ref48, _option$option_group_, _ref49, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
1093
+ 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;
1094
+ 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
1095
  if (!isSameId(optionItemId, itemId)) return false;
1040
1096
  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
1097
  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 +1101,16 @@ function isOptionItemMatch(option, item) {
1045
1101
  return true;
1046
1102
  }
1047
1103
  function resolveBundleItemFromParentProduct(params) {
1048
- var _ref42, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref44, _bundle$bundle_produc2;
1104
+ var _ref50, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref52, _bundle$bundle_produc2;
1049
1105
  var bundle = params.bundle,
1050
1106
  parentProduct = params.parentProduct;
1051
1107
  if (!parentProduct) return null;
1052
1108
  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;
1109
+ 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
1110
  if (isNonZeroId(bundleVariantId)) {
1055
1111
  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);
1112
+ var _ref51, _item$bundle_variant_;
1113
+ 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
1114
  });
1059
1115
  if (matchedByVariant) return matchedByVariant;
1060
1116
  }
@@ -1067,18 +1123,18 @@ function resolveBundleItemFromParentProduct(params) {
1067
1123
  if (matchedByBundleId) return matchedByBundleId;
1068
1124
  }
1069
1125
  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;
1126
+ 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
1127
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
1072
1128
  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);
1129
+ var _item$group_id, _ref53, _item$bundle_product_;
1130
+ 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
1131
  });
1076
1132
  if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
1077
1133
  }
1078
1134
  if (isPresentId(bundleProductId)) {
1079
1135
  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);
1136
+ var _ref54, _item$bundle_product_2;
1137
+ 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
1138
  }) || null;
1083
1139
  }
1084
1140
  return null;
@@ -1088,9 +1144,9 @@ function flattenBundleItems(parentProduct) {
1088
1144
  return bundleGroups.flatMap(function (group) {
1089
1145
  var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
1090
1146
  return items.map(function (item) {
1091
- var _ref47, _item$group_id2;
1147
+ var _ref55, _item$group_id2;
1092
1148
  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
1149
+ 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
1150
  });
1095
1151
  });
1096
1152
  });
@@ -1114,8 +1170,8 @@ function isSameId(left, right) {
1114
1170
  return String(left) === String(right);
1115
1171
  }
1116
1172
  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;
1173
+ var _ref56, _ref57, _bundle$bundle_sellin;
1174
+ 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
1175
  var amount = new Decimal(toMoneyNumber(value));
1120
1176
  // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
1121
1177
  var isNegative = bundle.price_type === 'markdown';
@@ -1133,21 +1189,21 @@ function buildFees(params) {
1133
1189
  financials = params.financials;
1134
1190
  var fees = [];
1135
1191
  for (var _i2 = 0, _normalizeArray2 = normalizeArray(order.surcharges || summary.surcharges); _i2 < _normalizeArray2.length; _i2++) {
1136
- var _ref50, _surcharge$amount;
1192
+ var _ref58, _surcharge$amount;
1137
1193
  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;
1194
+ 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
1195
  if (!isNonZero(value)) continue;
1140
- fees.push({
1196
+ fees.push(_objectSpread(_objectSpread({}, receiptKey(surcharge, 'surcharge')), {}, {
1141
1197
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
1142
1198
  value: formatMoney(value, currencySymbol)
1143
- });
1199
+ }));
1144
1200
  }
1145
1201
  var discountAmount = firstPresentValue(order.shop_discount, summary.discount_amount, order.discount_amount);
1146
1202
  if (isNonZero(discountAmount)) {
1147
- fees.push({
1203
+ fees.push(_objectSpread(_objectSpread({}, receiptKey(order, 'order-discount')), {}, {
1148
1204
  item: label(locale, 'orderDiscount'),
1149
1205
  value: formatNegativeMoney(discountAmount, currencySymbol)
1150
- });
1206
+ }));
1151
1207
  }
1152
1208
  var taxFee = firstPresentValue(summary.tax_fee, order.tax_fee);
1153
1209
  var taxTitle = resolveTaxTitle({
@@ -1160,10 +1216,10 @@ function buildFees(params) {
1160
1216
  var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
1161
1217
  var payProcessingFee = financials.payProcessingFee;
1162
1218
  if (isNonZero(payProcessingFee)) {
1163
- fees.push({
1219
+ fees.push(_objectSpread(_objectSpread({}, receiptKey(order, 'payment-processing-fee')), {}, {
1164
1220
  item: label(locale, 'payProcessingFee'),
1165
1221
  value: formatMoney(payProcessingFee, currencySymbol)
1166
- });
1222
+ }));
1167
1223
  }
1168
1224
  var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
1169
1225
  var productOriginalAmount = (_firstPresentValue2 = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : calculateProductOriginalAmount(order);
@@ -1237,24 +1293,24 @@ function resolveTaxTitle(params) {
1237
1293
  }
1238
1294
  function calculateProductOriginalAmount(order) {
1239
1295
  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;
1296
+ var _ref59, _ref60, _product$product_quan3, _ref61, _ref62, _ref63, _product$original_pri2;
1297
+ 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);
1298
+ 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
1299
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
1244
1300
  }, new Decimal(0));
1245
1301
  }
1246
1302
  function buildCustomer(order, locale) {
1247
1303
  var _order$customer, _order$customer2, _order$customer3, _order$customer4;
1248
- return [{
1304
+ return [_objectSpread(_objectSpread({}, receiptKey(order, 'customer.contactName')), {}, {
1249
1305
  item: label(locale, 'contactName'),
1250
1306
  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
- }, {
1307
+ }), _objectSpread(_objectSpread({}, receiptKey(order, 'customer.contactMobile')), {}, {
1252
1308
  item: label(locale, 'contactMobile'),
1253
1309
  value: stringify(order.phone || ((_order$customer3 = order.customer) === null || _order$customer3 === void 0 ? void 0 : _order$customer3.phone))
1254
- }, {
1310
+ }), _objectSpread(_objectSpread({}, receiptKey(order, 'customer.email')), {}, {
1255
1311
  item: label(locale, 'email'),
1256
1312
  value: stringify(order.email || ((_order$customer4 = order.customer) === null || _order$customer4 === void 0 ? void 0 : _order$customer4.email))
1257
- }];
1313
+ })];
1258
1314
  }
1259
1315
  function normalizeCustomerDisplayValue(value) {
1260
1316
  var text = stringify(value).trim();
@@ -1267,28 +1323,28 @@ function buildDelivery(order, locale) {
1267
1323
  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
1324
  var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType);
1269
1325
  if (!serviceTypeLabelKey) return [];
1270
- var items = [{
1326
+ var items = [_objectSpread(_objectSpread({}, receiptKey(order, 'service-type')), {}, {
1271
1327
  item: label(locale, serviceTypeLabelKey),
1272
1328
  value: '',
1273
1329
  size: 2
1274
- }];
1330
+ })];
1275
1331
  if (serviceType === 'pick_up') {
1276
1332
  var pickupTime = formatPickupBookingStart(order.bookings, locale);
1277
1333
  if (pickupTime) {
1278
- items.push({
1334
+ items.push(_objectSpread(_objectSpread({}, receiptTimeKey(order, 'pickup-time')), {}, {
1279
1335
  item: pickupTime,
1280
1336
  value: '',
1281
1337
  size: 2
1282
- });
1338
+ }));
1283
1339
  return items;
1284
1340
  }
1285
1341
  }
1286
1342
  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
1343
  if (isPresentId(handoverTime)) {
1288
- items.push({
1344
+ items.push(_objectSpread(_objectSpread({}, receiptKey(order, 'handover-time')), {}, {
1289
1345
  item: label(locale, 'handoverTime'),
1290
1346
  value: formatDateTime(handoverTime, locale)
1291
- });
1347
+ }));
1292
1348
  }
1293
1349
  return items;
1294
1350
  }
@@ -1333,10 +1389,10 @@ function buildAppointment(order, locale) {
1333
1389
  }
1334
1390
  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
1391
  if (!tableName) return [];
1336
- return [{
1392
+ return [_objectSpread(_objectSpread({}, receiptKey(order, 'table', 'text')), {}, {
1337
1393
  item: label(locale, 'table'),
1338
1394
  value: getLocalizedValue(tableName, locale)
1339
- }];
1395
+ })];
1340
1396
  }
1341
1397
  function isReceiptAppointmentBooking(booking, parentScheduleId) {
1342
1398
  if (!booking || _typeof(booking) !== 'object' || Array.isArray(booking)) {
@@ -1367,16 +1423,16 @@ function buildAppointmentRows(params) {
1367
1423
  var bookingTime = formatBookingRange(booking, locale);
1368
1424
  var resourceText = formatBookingResources(resolveBookingResourcesForReceipt(booking, allResources, bookingCount), locale);
1369
1425
  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({
1426
+ return [_objectSpread(_objectSpread({}, receiptKey(booking, 'booking-id')), {}, {
1371
1427
  item: label(locale, 'bookingId'),
1372
1428
  value: bookingId
1373
- }, association), _objectSpread({
1429
+ }, association), _objectSpread(_objectSpread({}, receiptKey(booking, 'booking-time', 'shared')), {}, {
1374
1430
  item: label(locale, 'bookingDateTime'),
1375
1431
  value: bookingTime
1376
- }, association), _objectSpread({
1432
+ }, association), _objectSpread(_objectSpread({}, receiptKey(booking, 'booking-resource', 'text')), {}, {
1377
1433
  item: label(locale, 'bookingResource'),
1378
1434
  value: resourceText
1379
- }, association), _objectSpread({
1435
+ }, association), _objectSpread(_objectSpread({}, receiptKey(booking, 'booking-holder', 'text')), {}, {
1380
1436
  item: label(locale, 'bookingHolder'),
1381
1437
  value: holder
1382
1438
  }, association)].filter(function (row) {
@@ -1422,9 +1478,9 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1422
1478
  _step3;
1423
1479
  try {
1424
1480
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1425
- var _ref57, _resource$id2;
1481
+ var _ref65, _resource$id2;
1426
1482
  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();
1483
+ 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
1484
  if (id) resourceIds.add(id);
1429
1485
  }
1430
1486
  } catch (err) {
@@ -1434,8 +1490,8 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1434
1490
  }
1435
1491
  if (resourceIds.size) {
1436
1492
  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());
1493
+ var _ref64, _resource$id;
1494
+ 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
1495
  });
1440
1496
  if (matched.length) return matched;
1441
1497
  }
@@ -1468,8 +1524,8 @@ function sortBookings(bookings) {
1468
1524
  }
1469
1525
  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
1526
  return bookingUidOrder || left.index - right.index;
1471
- }).map(function (_ref58) {
1472
- var booking = _ref58.booking;
1527
+ }).map(function (_ref66) {
1528
+ var booking = _ref66.booking;
1473
1529
  return booking;
1474
1530
  });
1475
1531
  }
@@ -1495,12 +1551,12 @@ function compareOptionalValues(left, right) {
1495
1551
  }
1496
1552
  function buildResources(order, locale) {
1497
1553
  return normalizeArray(order.resources || order.resource_list).map(function (resource) {
1498
- return {
1554
+ return _objectSpread(_objectSpread({}, receiptKey(resource, 'resource', 'text')), {}, {
1499
1555
  id: resource.id || resource.resource_id || '',
1500
1556
  code: '',
1501
1557
  title: getLocalizedValue(resource.title || resource.name, locale),
1502
1558
  form_title: getLocalizedValue(resource.form_title || resource.type || '', locale)
1503
- };
1559
+ });
1504
1560
  });
1505
1561
  }
1506
1562
  function buildPaymentData(params) {
@@ -1531,8 +1587,8 @@ function buildRefundData(params) {
1531
1587
  result.set(identity, candidate);
1532
1588
  }
1533
1589
  return result;
1534
- }, new Map()).values()).filter(function (_ref59) {
1535
- var refund = _ref59.refund;
1590
+ }, new Map()).values()).filter(function (_ref67) {
1591
+ var refund = _ref67.refund;
1536
1592
  return isPrintableRefund(refund);
1537
1593
  }).sort(function (left, right) {
1538
1594
  var leftTime = refundTimestamp(left.refund);
@@ -1540,22 +1596,22 @@ function buildRefundData(params) {
1540
1596
  if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1541
1597
  return left.index - right.index;
1542
1598
  });
1543
- return refunds.map(function (_ref60) {
1599
+ return refunds.map(function (_ref68) {
1544
1600
  var _firstPresentValue8;
1545
- var refund = _ref60.refund;
1601
+ var refund = _ref68.refund;
1546
1602
  var payment = resolveRefundPayment(refund, payments);
1547
1603
  var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
1548
1604
  var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
1549
- var items = [{
1605
+ var items = [_objectSpread(_objectSpread({}, receiptKey(refund, 'refund')), {}, {
1550
1606
  item: methodName,
1551
1607
  value: formatNegativeMoney(amount, params.currencySymbol)
1552
- }];
1608
+ })];
1553
1609
  var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
1554
1610
  if (isPresentId(occurredAt)) {
1555
- items.push({
1611
+ items.push(_objectSpread(_objectSpread({}, receiptTimeKey(refund, 'refund-time')), {}, {
1556
1612
  item: formatDateTime(occurredAt, params.locale),
1557
1613
  value: ''
1558
- });
1614
+ }));
1559
1615
  }
1560
1616
  return items;
1561
1617
  });
@@ -1673,35 +1729,35 @@ function buildProductDiscountAssets(params) {
1673
1729
  })) return [];
1674
1730
  var name = getProductWalletDiscountName(asset, params.locale);
1675
1731
  var assetTime = (_getProductWalletDisc = getProductWalletDiscountTime(asset)) !== null && _getProductWalletDisc !== void 0 ? _getProductWalletDisc : fallbackAssetTime;
1676
- var timeRow = isPresentId(assetTime) ? {
1732
+ var timeRow = isPresentId(assetTime) ? _objectSpread(_objectSpread({}, receiptTimeKey(asset.records[0], 'asset-time')), {}, {
1677
1733
  item: formatDateTime(assetTime, params.locale),
1678
1734
  value: ''
1679
- } : null;
1735
+ }) : null;
1680
1736
  if (asset.type === 'entitlement_pass') {
1681
1737
  var remaining = getProductEntitlementBalance(asset);
1682
- return [[{
1738
+ return [[_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'asset-name')), {}, {
1683
1739
  item: name,
1684
1740
  value: ''
1685
- }].concat(_toConsumableArray(remaining ? [{
1741
+ })].concat(_toConsumableArray(remaining ? [_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'entitlementRemaining')), {}, {
1686
1742
  item: label(params.locale, 'entitlementRemaining'),
1687
1743
  value: formatEntitlementUses(remaining, params.locale)
1688
- }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1744
+ })] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1689
1745
  }
1690
1746
  var percent = getProductWalletDiscountPercent(asset);
1691
1747
  if (percent) {
1692
- return [[{
1748
+ return [[_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'asset-discount')), {}, {
1693
1749
  item: appendPercentToVoucherName(name, percent),
1694
1750
  value: formatVoucherDiscount(percent, params.locale)
1695
- }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1751
+ })].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1696
1752
  }
1697
1753
  var balance = getProductWalletMoneyBalance(asset);
1698
- return [[{
1754
+ return [[_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'asset-name')), {}, {
1699
1755
  item: name,
1700
1756
  value: ''
1701
- }].concat(_toConsumableArray(balance ? [{
1757
+ })].concat(_toConsumableArray(balance ? [_objectSpread(_objectSpread({}, receiptKey(asset.records[0], 'balance')), {}, {
1702
1758
  item: label(params.locale, 'balance'),
1703
1759
  value: formatMoney(balance, params.currencySymbol)
1704
- }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1760
+ })] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1705
1761
  });
1706
1762
  }
1707
1763
  function collectProductWalletDiscountAssets(order) {
@@ -1935,22 +1991,22 @@ function buildPointCardSnapshotAssets(params) {
1935
1991
  id: assetId,
1936
1992
  codes: []
1937
1993
  })) return [];
1938
- var rows = [{
1994
+ var rows = [_objectSpread(_objectSpread({}, receiptKey(pointCard, 'asset-name')), {}, {
1939
1995
  item: appendMaskedCardCode(stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'), pointCard.code),
1940
1996
  value: ''
1941
- }];
1997
+ })];
1942
1998
  var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
1943
1999
  if (remainingPoints) {
1944
- rows.push({
2000
+ rows.push(_objectSpread(_objectSpread({}, receiptKey(pointCard, 'remainingPoints')), {}, {
1945
2001
  item: label(params.locale, 'remainingPoints'),
1946
2002
  value: trimDecimal(remainingPoints)
1947
- });
2003
+ }));
1948
2004
  }
1949
2005
  if (isPresentId(snapshotTime)) {
1950
- rows.push({
2006
+ rows.push(_objectSpread(_objectSpread({}, receiptTimeKey(pointCard, 'asset-time')), {}, {
1951
2007
  item: formatDateTime(snapshotTime, params.locale),
1952
2008
  value: ''
1953
- });
2009
+ }));
1954
2010
  }
1955
2011
  return [rows];
1956
2012
  });
@@ -1997,22 +2053,22 @@ function buildVirtualCurrencySnapshotAssets(params) {
1997
2053
  id: assetId,
1998
2054
  codes: []
1999
2055
  })) return [];
2000
- var rows = [{
2056
+ var rows = [_objectSpread(_objectSpread({}, receiptKey(virtualCurrency, 'asset-name')), {}, {
2001
2057
  item: stringify(virtualCurrency.product_name).trim(),
2002
2058
  value: ''
2003
- }];
2059
+ })];
2004
2060
  var balance = getVirtualCurrencySnapshotBalance(virtualCurrency);
2005
2061
  if (balance) {
2006
- rows.push({
2062
+ rows.push(_objectSpread(_objectSpread({}, receiptKey(virtualCurrency, 'balance')), {}, {
2007
2063
  item: label(params.locale, 'balance'),
2008
2064
  value: formatVirtualCurrencyBalance(balance, getVirtualCurrencySnapshotUnit(virtualCurrency, params.locale))
2009
- });
2065
+ }));
2010
2066
  }
2011
2067
  if (isPresentId(snapshotTime)) {
2012
- rows.push({
2068
+ rows.push(_objectSpread(_objectSpread({}, receiptTimeKey(virtualCurrency, 'asset-time')), {}, {
2013
2069
  item: formatDateTime(snapshotTime, params.locale),
2014
2070
  value: ''
2015
- });
2071
+ }));
2016
2072
  }
2017
2073
  return [rows];
2018
2074
  });
@@ -2121,46 +2177,46 @@ function buildVoucherAssets(params) {
2121
2177
  if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, getVoucherAssetIdentity(voucher))) return [];
2122
2178
  var name = getVoucherAssetName(voucher, params.locale);
2123
2179
  var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
2124
- var timeRow = isPresentId(assetTime) ? {
2180
+ var timeRow = isPresentId(assetTime) ? _objectSpread(_objectSpread({}, receiptTimeKey(voucher, 'asset-time')), {}, {
2125
2181
  item: formatDateTime(assetTime, params.locale),
2126
2182
  value: ''
2127
- } : null;
2183
+ }) : null;
2128
2184
  if (isEntitlementVoucher(voucher)) {
2129
2185
  var _voucher$metadata;
2130
2186
  var remaining = getEntitlementBalance((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.balance, voucher.balance);
2131
- return [[{
2187
+ return [[_objectSpread(_objectSpread({}, receiptKey(voucher, 'asset-name')), {}, {
2132
2188
  item: name,
2133
2189
  value: ''
2134
- }].concat(_toConsumableArray(remaining ? [{
2190
+ })].concat(_toConsumableArray(remaining ? [_objectSpread(_objectSpread({}, receiptKey(voucher, 'entitlementRemaining')), {}, {
2135
2191
  item: label(params.locale, 'entitlementRemaining'),
2136
2192
  value: formatEntitlementUses(remaining, params.locale)
2137
- }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
2193
+ })] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
2138
2194
  }
2139
2195
  if (isTicketVoucher(voucher)) {
2140
2196
  var validity = getVoucherValidity(voucher, params.locale);
2141
- return [[{
2197
+ return [[_objectSpread(_objectSpread({}, receiptKey(voucher, 'asset-name')), {}, {
2142
2198
  item: name,
2143
2199
  value: ''
2144
- }].concat(_toConsumableArray(validity ? [{
2200
+ })].concat(_toConsumableArray(validity ? [_objectSpread(_objectSpread({}, receiptKey(voucher, 'validity')), {}, {
2145
2201
  item: label(params.locale, 'validity'),
2146
2202
  value: validity
2147
- }] : []))];
2203
+ })] : []))];
2148
2204
  }
2149
2205
  var percent = getVoucherDiscountPercent(voucher);
2150
2206
  if (percent) {
2151
- return [[{
2207
+ return [[_objectSpread(_objectSpread({}, receiptKey(voucher, 'asset-discount')), {}, {
2152
2208
  item: appendPercentToVoucherName(name, percent),
2153
2209
  value: formatVoucherDiscount(percent, params.locale)
2154
- }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
2210
+ })].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
2155
2211
  }
2156
2212
  var balance = getVoucherBalance(voucher);
2157
- return [[{
2213
+ return [[_objectSpread(_objectSpread({}, receiptKey(voucher, 'asset-name')), {}, {
2158
2214
  item: name,
2159
2215
  value: ''
2160
- }, {
2216
+ }), _objectSpread(_objectSpread({}, receiptKey(voucher, 'balance')), {}, {
2161
2217
  item: label(params.locale, 'balance'),
2162
2218
  value: formatMoney(balance, params.currencySymbol)
2163
- }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
2219
+ })].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
2164
2220
  });
2165
2221
  }
2166
2222
  var TICKET_VOUCHER_TAGS = new Set(['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket']);
@@ -2297,20 +2353,20 @@ function buildPaymentItems(params) {
2297
2353
  includePaymentAmount = params.includePaymentAmount,
2298
2354
  virtualCurrencyUnit = params.virtualCurrencyUnit;
2299
2355
  var serviceFee = getPaymentServiceFee(payment);
2300
- var items = [{
2356
+ var items = [_objectSpread(_objectSpread({}, receiptKey(payment, 'payment')), {}, {
2301
2357
  item: paymentMethodName(payment, locale),
2302
2358
  value: includePaymentAmount ? formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol) : ''
2303
- }];
2359
+ })];
2304
2360
  items.push.apply(items, _toConsumableArray(buildCashChangePaymentItems({
2305
2361
  payment: payment,
2306
2362
  locale: locale,
2307
2363
  currencySymbol: currencySymbol
2308
2364
  })));
2309
2365
  if (serviceFee.gt(0)) {
2310
- items.push({
2366
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'surchargeIncluded')), {}, {
2311
2367
  item: label(locale, 'surchargeIncluded'),
2312
2368
  value: formatMoney(serviceFee, currencySymbol)
2313
- });
2369
+ }));
2314
2370
  }
2315
2371
  var fundRecord = getFundRecord(payment);
2316
2372
  if (fundRecord) {
@@ -2324,20 +2380,24 @@ function buildPaymentItems(params) {
2324
2380
  virtualCurrencyUnit: virtualCurrencyUnit
2325
2381
  })));
2326
2382
  } 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;
2383
+ var _ref69, _payment$remaining_am, _payment$metadata;
2384
+ 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
2385
  if (remainingAmount !== undefined && remainingAmount !== null) {
2330
- items.push({
2386
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'remainingAmount')), {}, {
2331
2387
  item: label(locale, 'remainingAmount'),
2332
2388
  value: formatMoney(remainingAmount, currencySymbol)
2333
- });
2389
+ }));
2334
2390
  }
2335
2391
  }
2336
- items.push({
2392
+ items.push(_objectSpread(_objectSpread({}, receiptTimeKey(payment, 'payment-time')), {}, {
2337
2393
  item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), locale),
2338
2394
  value: ''
2395
+ }));
2396
+ return items.map(function (item) {
2397
+ return item.receipt_key ? _objectSpread(_objectSpread({}, item), {}, {
2398
+ receipt_key: "".concat(item.receipt_key, "/").concat(includeFundRecordBalance ? 'wallet' : 'history')
2399
+ }) : item;
2339
2400
  });
2340
- return items;
2341
2401
  }
2342
2402
  function getPaymentServiceFee(payment) {
2343
2403
  return new Decimal(toMoneyNumber(payment.service_fee));
@@ -2356,13 +2416,13 @@ function buildCashChangePaymentItems(params) {
2356
2416
  locale = params.locale,
2357
2417
  currencySymbol = params.currencySymbol;
2358
2418
  if (!shouldDisplayCashChange(payment)) return [];
2359
- return [{
2419
+ return [_objectSpread(_objectSpread({}, receiptKey(payment, 'cashReceived')), {}, {
2360
2420
  item: label(locale, 'cashReceived'),
2361
2421
  value: formatMoney(payment.metadata.actual_paid_amount, currencySymbol)
2362
- }, {
2422
+ }), _objectSpread(_objectSpread({}, receiptKey(payment, 'changeDue')), {}, {
2363
2423
  item: label(locale, 'changeDue'),
2364
2424
  value: formatMoney(payment.metadata.change_given_amount, currencySymbol)
2365
- }];
2425
+ })];
2366
2426
  }
2367
2427
  function shouldDisplayCashChange(payment) {
2368
2428
  var _payment$code, _payment$metadata2, _payment$metadata3;
@@ -2394,32 +2454,32 @@ function buildFundRecordPaymentItems(params) {
2394
2454
  if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
2395
2455
  var usedPoints = new Decimal(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
2396
2456
  if (includeUsage) {
2397
- items.push({
2457
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'redeemPoints')), {}, {
2398
2458
  item: label(locale, 'redeemPoints'),
2399
2459
  value: trimDecimal(usedPoints)
2400
- });
2460
+ }));
2401
2461
  }
2402
2462
  if (includeBalance) {
2403
- items.push({
2463
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'remainingPoints')), {}, {
2404
2464
  item: label(locale, 'remainingPoints'),
2405
2465
  value: trimDecimal(new Decimal(toMoneyNumber(usingAfterValue)))
2406
- });
2466
+ }));
2407
2467
  }
2408
2468
  return items;
2409
2469
  }
2410
2470
  if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
2411
2471
  if (virtualCurrencyUnit !== undefined) {
2412
2472
  if (!isNumericAmount(usingAfterValue)) return items;
2413
- items.push({
2473
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'balance')), {}, {
2414
2474
  item: label(locale, 'balance'),
2415
2475
  value: formatVirtualCurrencyBalance(new Decimal(usingAfterValue), virtualCurrencyUnit)
2416
- });
2476
+ }));
2417
2477
  return items;
2418
2478
  }
2419
- items.push({
2479
+ items.push(_objectSpread(_objectSpread({}, receiptKey(payment, 'balance')), {}, {
2420
2480
  item: label(locale, 'balance'),
2421
2481
  value: formatMoney(usingAfterValue, currencySymbol)
2422
- });
2482
+ }));
2423
2483
  }
2424
2484
  return items;
2425
2485
  }
@@ -2490,12 +2550,12 @@ function label(locale, key) {
2490
2550
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
2491
2551
  }
2492
2552
  function getLocalizedValue(value, locale) {
2493
- var _ref62, _ref63, _ref64, _ref65, _ref66, _ref67, _value$locale2;
2553
+ var _ref70, _ref71, _ref72, _ref73, _ref74, _ref75, _value$locale2;
2494
2554
  if (value === undefined || value === null) return '';
2495
2555
  if (_typeof(value) !== 'object') return stringify(value);
2496
2556
  var dashedLocale = locale.replace('_', '-');
2497
2557
  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 : '');
2558
+ 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
2559
  }
2500
2560
  function resolveServiceTypeLabelKey(serviceType) {
2501
2561
  return SERVICE_TYPE_LABEL_KEYS[serviceType] || null;