@pisell/pisellos 0.10.36 → 0.10.38

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,12 +1,16 @@
1
+ var _excluded = ["isMarkup"];
1
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
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."); }
3
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; } }
4
5
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
+ 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
+ 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; }
5
8
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
9
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
- 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); }
8
10
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
11
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
+ 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); }
10
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; }
11
15
  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; }
12
16
  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; }
@@ -37,12 +41,18 @@ var LABELS = {
37
41
  giftCard: 'Gift card',
38
42
  pointCard: 'Point card',
39
43
  balance: 'Balance',
44
+ validity: 'Validity',
40
45
  remainingAmount: 'Remaining amount',
41
46
  redeemPoints: 'Redeem points',
42
47
  remainingPoints: 'Points balance',
43
48
  table: 'Table',
49
+ bookingId: 'Booking ID',
50
+ bookingDateTime: 'Date & time',
51
+ bookingResource: 'Resource',
52
+ bookingHolder: 'Holder',
44
53
  orderDiscount: 'Order discount',
45
54
  manualDiscount: 'Manual discount',
55
+ manualMarkup: 'Manual markup',
46
56
  payProcessingFee: 'Pay processing fee',
47
57
  surchargeIncluded: 'Surcharge(Included)',
48
58
  rounding: 'Rounding',
@@ -70,12 +80,18 @@ var LABELS = {
70
80
  giftCard: '礼品卡',
71
81
  pointCard: '积分卡',
72
82
  balance: '余额',
83
+ validity: '有效期',
73
84
  remainingAmount: '剩余金额',
74
85
  redeemPoints: '本次使用积分',
75
86
  remainingPoints: '积分余额',
76
87
  table: '桌台',
88
+ bookingId: '预约编号',
89
+ bookingDateTime: '日期和时间',
90
+ bookingResource: '资源',
91
+ bookingHolder: '预约人',
77
92
  orderDiscount: '整单折扣',
78
93
  manualDiscount: '手动折扣',
94
+ manualMarkup: '手动加价',
79
95
  payProcessingFee: '支付手续费',
80
96
  surchargeIncluded: '手续费(已含)',
81
97
  rounding: '抹零',
@@ -103,12 +119,18 @@ var LABELS = {
103
119
  giftCard: '禮品卡',
104
120
  pointCard: '積分卡',
105
121
  balance: '餘額',
122
+ validity: '有效期',
106
123
  remainingAmount: '剩餘金額',
107
124
  redeemPoints: '本次使用積分',
108
125
  remainingPoints: '積分餘額',
109
126
  table: '桌台',
127
+ bookingId: '預約編號',
128
+ bookingDateTime: '日期和時間',
129
+ bookingResource: '資源',
130
+ bookingHolder: '預約人',
110
131
  orderDiscount: '整單折扣',
111
132
  manualDiscount: '手動折扣',
133
+ manualMarkup: '手動加價',
112
134
  payProcessingFee: '支付手續費',
113
135
  surchargeIncluded: '手續費(已含)',
114
136
  rounding: '抹零',
@@ -134,12 +156,18 @@ var LABELS = {
134
156
  giftCard: 'ギフトカード',
135
157
  pointCard: 'ポイントカード',
136
158
  balance: '残高',
159
+ validity: '有効期限',
137
160
  remainingAmount: '残高',
138
161
  redeemPoints: '利用ポイント',
139
162
  remainingPoints: 'ポイント残高',
140
163
  table: 'テーブル',
164
+ bookingId: '予約ID',
165
+ bookingDateTime: '日時',
166
+ bookingResource: 'リソース',
167
+ bookingHolder: '予約者',
141
168
  orderDiscount: '注文割引',
142
169
  manualDiscount: '手動割引',
170
+ manualMarkup: '手動値上げ',
143
171
  payProcessingFee: '決済手数料',
144
172
  rounding: '端数調整',
145
173
  gross: '総重量',
@@ -166,12 +194,18 @@ var LABELS = {
166
194
  giftCard: 'Cartão-presente',
167
195
  pointCard: 'Cartão de pontos',
168
196
  balance: 'Saldo',
197
+ validity: 'Validade',
169
198
  remainingAmount: 'Saldo restante',
170
199
  redeemPoints: 'Pontos utilizados',
171
200
  remainingPoints: 'Saldo de pontos',
172
201
  table: 'Mesa',
202
+ bookingId: 'ID da reserva',
203
+ bookingDateTime: 'Data e hora',
204
+ bookingResource: 'Recurso',
205
+ bookingHolder: 'Titular',
173
206
  orderDiscount: 'Desconto do pedido',
174
207
  manualDiscount: 'Desconto manual',
208
+ manualMarkup: 'Acréscimo manual',
175
209
  payProcessingFee: 'Taxa de processamento',
176
210
  rounding: 'Arredondamento',
177
211
  gross: 'Peso bruto',
@@ -285,8 +319,9 @@ function buildBaseData(params) {
285
319
  }
286
320
  function buildProducts(order, locale, productMap) {
287
321
  var products = Array.isArray(order.products) ? order.products : [];
288
- return products.map(function (product) {
322
+ return products.map(function (rawProduct) {
289
323
  var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric, _product$product_id, _product$metadata, _product$metadata2;
324
+ var product = restoreReceiptDiscountHierarchy(rawProduct);
290
325
  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);
291
326
  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;
292
327
  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;
@@ -359,6 +394,96 @@ function buildProducts(order, locale, productMap) {
359
394
  } : {});
360
395
  });
361
396
  }
397
+ var RECEIPT_BUNDLE_MAP_ID_KEY = 'custom_product_bundle_map_id';
398
+ function restoreReceiptDiscountHierarchy(source) {
399
+ if (!source || _typeof(source) !== 'object' || Array.isArray(source)) {
400
+ return source;
401
+ }
402
+ var childKey = Array.isArray(source.combinations) && source.combinations.length ? 'combinations' : Array.isArray(source.product_bundle) && source.product_bundle.length ? 'product_bundle' : null;
403
+ if (!childKey) return _objectSpread({}, source);
404
+ var children = source[childKey].map(function (child) {
405
+ return child && _typeof(child) === 'object' && !Array.isArray(child) ? restoreReceiptDiscountHierarchy(child) : child;
406
+ });
407
+ var restored = _objectSpread(_objectSpread({}, source), {}, _defineProperty({}, childKey, children));
408
+ if (!Array.isArray(source.discount_list) || !source.discount_list.length) {
409
+ return restored;
410
+ }
411
+ var descendantsByMapId = new Map();
412
+ indexReceiptDiscountTargets(children, descendantsByMapId);
413
+ if (!descendantsByMapId.size) return restored;
414
+ var ownDiscounts = [];
415
+ var _iterator = _createForOfIteratorHelper(source.discount_list),
416
+ _step;
417
+ try {
418
+ var _loop = function _loop() {
419
+ var discount = _step.value;
420
+ var mapId = getReceiptDiscountBundleMapId(discount);
421
+ var target = mapId ? descendantsByMapId.get(mapId) : undefined;
422
+ if (!target) {
423
+ ownDiscounts.push(discount);
424
+ return 1; // continue
425
+ }
426
+ var targetDiscounts = Array.isArray(target.discount_list) ? target.discount_list : [];
427
+ if (!targetDiscounts.some(function (item) {
428
+ return isSameReceiptDiscount(item, discount);
429
+ })) {
430
+ target.discount_list = [].concat(_toConsumableArray(targetDiscounts), [discount]);
431
+ }
432
+ };
433
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
434
+ if (_loop()) continue;
435
+ }
436
+ } catch (err) {
437
+ _iterator.e(err);
438
+ } finally {
439
+ _iterator.f();
440
+ }
441
+ restored.discount_list = ownDiscounts;
442
+ return restored;
443
+ }
444
+ function indexReceiptDiscountTargets(nodes, targets) {
445
+ var _iterator2 = _createForOfIteratorHelper(nodes),
446
+ _step2;
447
+ try {
448
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
449
+ var node = _step2.value;
450
+ if (!node || _typeof(node) !== 'object' || Array.isArray(node)) continue;
451
+ var mapId = getReceiptBundleMapId(node);
452
+ if (mapId && !targets.has(mapId)) targets.set(mapId, node);
453
+ var children = Array.isArray(node.combinations) && node.combinations.length ? node.combinations : Array.isArray(node.product_bundle) ? node.product_bundle : [];
454
+ indexReceiptDiscountTargets(children, targets);
455
+ }
456
+ } catch (err) {
457
+ _iterator2.e(err);
458
+ } finally {
459
+ _iterator2.f();
460
+ }
461
+ }
462
+ function normalizeReceiptId(value) {
463
+ if (value === undefined || value === null) return null;
464
+ var normalized = String(value).trim();
465
+ return normalized ? normalized : null;
466
+ }
467
+ function getReceiptBundleMapId(node) {
468
+ var _node$metadata$RECEIP, _node$metadata;
469
+ return normalizeReceiptId((_node$metadata$RECEIP = (_node$metadata = node.metadata) === null || _node$metadata === void 0 ? void 0 : _node$metadata[RECEIPT_BUNDLE_MAP_ID_KEY]) !== null && _node$metadata$RECEIP !== void 0 ? _node$metadata$RECEIP : node._id);
470
+ }
471
+ function getReceiptDiscountBundleMapId(discount) {
472
+ var _discount$metadata;
473
+ 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]);
474
+ }
475
+ function isSameReceiptDiscount(left, right) {
476
+ var _ref8, _left$discount$resour, _left$discount, _ref9, _right$discount$resou, _right$discount, _ref10, _ref11, _left$amount, _ref12, _ref13, _right$amount;
477
+ var leftOrderDiscountId = normalizeReceiptId(left === null || left === void 0 ? void 0 : left.order_discount_id);
478
+ var rightOrderDiscountId = normalizeReceiptId(right === null || right === void 0 ? void 0 : right.order_discount_id);
479
+ if (leftOrderDiscountId && rightOrderDiscountId) {
480
+ return leftOrderDiscountId === rightOrderDiscountId;
481
+ }
482
+ 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);
483
+ 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);
484
+ if (!leftResourceId || !rightResourceId) return false;
485
+ 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 : '');
486
+ }
362
487
  function resolveProductBasePrice(product) {
363
488
  var _product$product_vari, _product$_origin, _product$_origin2;
364
489
  var metadata = product.metadata || {};
@@ -375,26 +500,43 @@ function normalizeProductDiscounts(params) {
375
500
  locale = params.locale,
376
501
  currencySymbol = params.currencySymbol,
377
502
  quantity = params.quantity;
378
- return normalizeArray(product.discount_list).filter(function (discount) {
379
- var _ref8, _discount$amount;
380
- var amount = (_ref8 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref8 !== void 0 ? _ref8 : discount.discount_amount;
503
+ var rows = normalizeArray(product.discount_list).filter(function (discount) {
504
+ var _ref14, _discount$amount;
505
+ var amount = (_ref14 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref14 !== void 0 ? _ref14 : discount.discount_amount;
381
506
  return isNonZero(amount);
382
507
  }).map(function (discount) {
383
- var _ref9, _discount$amount2;
508
+ var _ref15, _discount$amount2;
384
509
  var title = resolveDiscountTitleWithPercent(discount, locale);
385
- var amount = (_ref9 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref9 !== void 0 ? _ref9 : discount.discount_amount;
386
- var formattedAmount = formatNegativeMoney(new Decimal(toMoneyNumber(amount)).mul(quantity), currencySymbol);
510
+ var amount = (_ref15 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref15 !== void 0 ? _ref15 : discount.discount_amount;
511
+ var isMarkup = isManualMarkup(discount);
512
+ var totalAmount = new Decimal(toMoneyNumber(amount)).mul(quantity);
513
+ var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
387
514
  return {
388
515
  item: title,
389
- value: formattedAmount
516
+ value: formattedAmount,
517
+ isMarkup: isMarkup
390
518
  };
391
519
  });
520
+ return rows.sort(function (left, right) {
521
+ return Number(right.isMarkup) - Number(left.isMarkup);
522
+ }).map(function (_ref16) {
523
+ var _isMarkup = _ref16.isMarkup,
524
+ row = _objectWithoutProperties(_ref16, _excluded);
525
+ return row;
526
+ });
527
+ }
528
+ function isManualMarkup(discount) {
529
+ var _discount$discount, _ref17, _discount$amount3;
530
+ if (discount.type !== 'product') return false;
531
+ if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
532
+ var amount = (_ref17 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
533
+ return new Decimal(toMoneyNumber(amount)).isNegative();
392
534
  }
393
535
  function hasProductDiscount(product) {
394
536
  var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
395
537
  var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
396
- var _ref10, _discount$amount3;
397
- return isNonZero((_ref10 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref10 !== void 0 ? _ref10 : discount.discount_amount);
538
+ var _ref18, _discount$amount4;
539
+ return isNonZero((_ref18 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref18 !== void 0 ? _ref18 : discount.discount_amount);
398
540
  });
399
541
  return hasDiscountListAmount || extensionList.some(function (row) {
400
542
  return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
@@ -465,10 +607,10 @@ function buildProductQuantityPriceText(params) {
465
607
  return "".concat(quantity, " @ ").concat(currencySymbol).concat(stringify(price), " EACH");
466
608
  }
467
609
  function resolveDiscountTitleWithPercent(discount, locale) {
468
- var _discount$discount, _discount$discount$di, _discount$discount2;
610
+ var _discount$discount2, _discount$discount$di, _discount$discount3;
469
611
  var title = resolveDiscountTitle(discount, locale);
470
- var percentRaw = (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.percent;
471
- var cardType = (_discount$discount$di = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.discount_card_type) !== null && _discount$discount$di !== void 0 ? _discount$discount$di : 'percent';
612
+ var percentRaw = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.percent;
613
+ var cardType = (_discount$discount$di = (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.discount_card_type) !== null && _discount$discount$di !== void 0 ? _discount$discount$di : 'percent';
472
614
  var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
473
615
  if (percentRaw === undefined || percentRaw === null) return title;
474
616
  if (cardType !== 'percent') return title;
@@ -476,10 +618,12 @@ function resolveDiscountTitleWithPercent(discount, locale) {
476
618
  return "".concat(title, " (").concat(percent, "%)");
477
619
  }
478
620
  function resolveDiscountTitle(discount, locale) {
479
- var _ref11, _ref12, _ref13, _ref14, _discount$discount$na, _discount$discount3, _discount$discount4, _discount$discount5;
480
- var title = getLocalizedValue((_ref11 = (_ref12 = (_ref13 = (_ref14 = (_discount$discount$na = (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.title) !== null && _ref14 !== void 0 ? _ref14 : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.message) !== null && _ref13 !== void 0 ? _ref13 : discount.name) !== null && _ref12 !== void 0 ? _ref12 : discount.title) !== null && _ref11 !== void 0 ? _ref11 : discount.message, locale);
621
+ var _ref19, _ref20, _ref21, _ref22, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
622
+ var title = getLocalizedValue((_ref19 = (_ref20 = (_ref21 = (_ref22 = (_discount$discount$na = (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.title) !== null && _ref22 !== void 0 ? _ref22 : (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.message) !== null && _ref21 !== void 0 ? _ref21 : discount.name) !== null && _ref20 !== void 0 ? _ref20 : discount.title) !== null && _ref19 !== void 0 ? _ref19 : discount.message, locale);
481
623
  if (title) return title;
482
- if (discount.type === 'product') return label(locale, 'manualDiscount');
624
+ if (discount.type === 'product') {
625
+ return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
626
+ }
483
627
  return '';
484
628
  }
485
629
  function resolveProductTitle(params) {
@@ -502,10 +646,10 @@ function normalizeProductOptions(params) {
502
646
  parentProduct = params.parentProduct;
503
647
  var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option) ? product.product_sku.option : [];
504
648
  return rawOptions.map(function (option) {
505
- var _ref15, _option$original_pric, _ref16, _option$num, _ref17, _option$value;
506
- var price = (_ref15 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref15 !== void 0 ? _ref15 : option.price;
507
- var quantity = toNumber((_ref16 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref16 !== void 0 ? _ref16 : 1, 1);
508
- var value = (_ref17 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref17 !== void 0 ? _ref17 : option.item;
649
+ var _ref23, _option$original_pric, _ref24, _option$num, _ref25, _option$value;
650
+ var price = (_ref23 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref23 !== void 0 ? _ref23 : option.price;
651
+ var quantity = toNumber((_ref24 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref24 !== void 0 ? _ref24 : 1, 1);
652
+ var value = (_ref25 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref25 !== void 0 ? _ref25 : option.item;
509
653
  var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
510
654
  option: option,
511
655
  parentProduct: parentProduct,
@@ -532,7 +676,7 @@ function normalizeProductCombinations(params) {
532
676
  parentProduct = params.parentProduct;
533
677
  var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
534
678
  return bundles.map(function (bundle) {
535
- var _ref18, _bundle$num, _bundle$metadata;
679
+ var _ref26, _bundle$num;
536
680
  var combinationsOptions = normalizeProductOptions({
537
681
  product: {},
538
682
  locale: locale,
@@ -548,13 +692,20 @@ function normalizeProductCombinations(params) {
548
692
  });
549
693
  var productNote = resolveProductNote(bundle, locale);
550
694
  var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
551
- var quantity = toNumber((_ref18 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref18 !== void 0 ? _ref18 : 1, 1);
695
+ var quantity = toNumber((_ref26 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
552
696
  var formattedPrice = formatBundlePrice(bundle, currencySymbol);
553
697
  var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
554
- var explicitBasePrice = firstPresentValue(bundle.base_price, (_bundle$metadata = bundle.metadata) === null || _bundle$metadata === void 0 ? void 0 : _bundle$metadata.source_product_price);
698
+ var explicitBasePrice = resolveCombinationBasePrice(bundle);
555
699
  var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
556
- var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle);
557
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
700
+ var extensionList = buildProductExtensionList({
701
+ product: bundle,
702
+ locale: locale,
703
+ currencySymbol: currencySymbol,
704
+ quantity: quantity,
705
+ originalPrice: formattedPrice
706
+ });
707
+ var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle, extensionList);
708
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
558
709
  product_title: baseTitle,
559
710
  product_quantity: quantity,
560
711
  price: formattedPrice,
@@ -569,6 +720,8 @@ function normalizeProductCombinations(params) {
569
720
  package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
570
721
  } : {}), productNote ? {
571
722
  product_note: productNote
723
+ } : {}), extensionList.length ? {
724
+ extension_list: extensionList
572
725
  } : {}), nestedCombinations.length ? {
573
726
  combinations: nestedCombinations
574
727
  } : {});
@@ -576,7 +729,7 @@ function normalizeProductCombinations(params) {
576
729
  }
577
730
  function normalizeExistingCombinations(combinations, locale, currencySymbol) {
578
731
  return combinations.map(function (combination) {
579
- var _ref19, _ref20, _combination$product_, _firstPresentValue;
732
+ var _ref27, _ref28, _combination$product_, _firstPresentValue;
580
733
  if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
581
734
  return combination;
582
735
  }
@@ -593,15 +746,23 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
593
746
  delete snapshot.product_note;
594
747
  delete snapshot.note;
595
748
  delete snapshot.combinations;
596
- var quantity = toNumber((_ref19 = (_ref20 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref20 !== void 0 ? _ref20 : combination.quantity) !== null && _ref19 !== void 0 ? _ref19 : 1, 1);
749
+ delete snapshot.discount_list;
750
+ var quantity = toNumber((_ref27 = (_ref28 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref28 !== void 0 ? _ref28 : combination.quantity) !== null && _ref27 !== void 0 ? _ref27 : 1, 1);
597
751
  var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
598
752
  var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
599
753
  return option.total_price;
600
754
  }));
601
- var explicitBasePrice = firstPresentValue(combination.base_price);
755
+ var explicitBasePrice = resolveCombinationBasePrice(combination, true);
602
756
  var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
603
- var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, normalizeArray(combination.extension_list));
604
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), {}, {
757
+ var extensionList = buildProductExtensionList({
758
+ product: combination,
759
+ locale: locale,
760
+ currencySymbol: currencySymbol,
761
+ quantity: quantity,
762
+ originalPrice: unitPrice
763
+ });
764
+ var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
765
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), {}, {
605
766
  product_quantity: quantity,
606
767
  total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
607
768
  }, shouldIncludeBasePrice ? {
@@ -616,6 +777,8 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
616
777
  package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
617
778
  } : {}), productNote ? {
618
779
  product_note: productNote
780
+ } : {}), extensionList.length ? {
781
+ extension_list: extensionList
619
782
  } : {}), nestedCombinations.length ? {
620
783
  combinations: nestedCombinations
621
784
  } : {});
@@ -626,6 +789,12 @@ function sumMoneyValues(values) {
626
789
  return sum.plus(toMoneyNumber(value));
627
790
  }, new Decimal(0));
628
791
  }
792
+ function resolveCombinationBasePrice(combination) {
793
+ var _combination$metadata;
794
+ var preferOriginalPrice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
795
+ var fallbackPrices = preferOriginalPrice ? [combination.original_price, combination.product_price, combination.price] : [combination.price, combination.original_price, combination.product_price];
796
+ return firstPresentValue.apply(void 0, [combination.base_price, (_combination$metadata = combination.metadata) === null || _combination$metadata === void 0 ? void 0 : _combination$metadata.source_product_price].concat(fallbackPrices));
797
+ }
629
798
  function sumNormalizedOptionTotals(options, currencySymbol) {
630
799
  return formatCalculatedMoney(sumMoneyValues(options.map(function (option) {
631
800
  return option.total_price;
@@ -642,7 +811,7 @@ function resolveProductNote(product, locale) {
642
811
  return getLocalizedValue(product.note, locale).trim();
643
812
  }
644
813
  function resolveBundleProductTitle(params) {
645
- var _ref21, _ref22, _bundle$bundle_produc;
814
+ var _ref29, _ref30, _bundle$bundle_produc;
646
815
  var bundle = params.bundle,
647
816
  productMap = params.productMap,
648
817
  locale = params.locale,
@@ -655,7 +824,7 @@ function resolveBundleProductTitle(params) {
655
824
  });
656
825
  var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
657
826
  if (parentBundleTitle) return parentBundleTitle;
658
- var productId = (_ref21 = (_ref22 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref22 !== void 0 ? _ref22 : bundle.product_id) !== null && _ref21 !== void 0 ? _ref21 : bundle.id;
827
+ var productId = (_ref29 = (_ref30 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref30 !== void 0 ? _ref30 : bundle.product_id) !== null && _ref29 !== void 0 ? _ref29 : bundle.id;
659
828
  var fallbackProduct = resolveProductFromMap(productId, productMap);
660
829
  if (!fallbackProduct) return '';
661
830
  return getProductTitleSource(fallbackProduct, locale);
@@ -707,10 +876,10 @@ function resolveVariantTextFromSkuKey(params) {
707
876
  }
708
877
  function resolveVariantTextFromNameMap(params) {
709
878
  if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
710
- return Object.entries(params.nameMap).map(function (_ref23) {
711
- var _ref24 = _slicedToArray(_ref23, 2),
712
- groupPositionId = _ref24[0],
713
- value = _ref24[1];
879
+ return Object.entries(params.nameMap).map(function (_ref31) {
880
+ var _ref32 = _slicedToArray(_ref31, 2),
881
+ groupPositionId = _ref32[0],
882
+ value = _ref32[1];
714
883
  var group = resolveVariantGroup(params.parentProduct, groupPositionId);
715
884
  if (!group) return '';
716
885
  var groupName = getLocalizedValue(group.name, params.locale);
@@ -744,12 +913,12 @@ function getProductTitleSource(source, locale) {
744
913
  return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
745
914
  }
746
915
  function resolveTitleValue(value, locale) {
747
- var _ref25, _ref26, _ref27, _ref28, _value$locale;
916
+ var _ref33, _ref34, _ref35, _ref36, _value$locale;
748
917
  if (value === undefined || value === null) return '';
749
918
  if (_typeof(value) !== 'object') return stringify(value);
750
919
  var dashedLocale = locale.replace('_', '-');
751
920
  var underscoredLocale = locale.replace('-', '_');
752
- return stringify((_ref25 = (_ref26 = (_ref27 = (_ref28 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref28 !== void 0 ? _ref28 : value[underscoredLocale]) !== null && _ref27 !== void 0 ? _ref27 : value.original) !== null && _ref26 !== void 0 ? _ref26 : value.auto) !== null && _ref25 !== void 0 ? _ref25 : '');
921
+ return stringify((_ref33 = (_ref34 = (_ref35 = (_ref36 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref36 !== void 0 ? _ref36 : value[underscoredLocale]) !== null && _ref35 !== void 0 ? _ref35 : value.original) !== null && _ref34 !== void 0 ? _ref34 : value.auto) !== null && _ref33 !== void 0 ? _ref33 : '');
753
922
  }
754
923
  function resolveOptionTitleFromParentProduct(params) {
755
924
  var option = params.option,
@@ -767,17 +936,17 @@ function flattenOptionItems(parentProduct) {
767
936
  return optionGroups.flatMap(function (group) {
768
937
  var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
769
938
  return items.map(function (item) {
770
- var _ref29, _item$option_group_id;
939
+ var _ref37, _item$option_group_id;
771
940
  return _objectSpread(_objectSpread({}, item), {}, {
772
- option_group_id: (_ref29 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref29 !== void 0 ? _ref29 : group.option_group_id
941
+ option_group_id: (_ref37 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref37 !== void 0 ? _ref37 : group.option_group_id
773
942
  });
774
943
  });
775
944
  });
776
945
  }
777
946
  function isOptionItemMatch(option, item) {
778
- var _ref30, _option$option_group_, _ref31, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
779
- var optionItemId = (_ref30 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref30 !== void 0 ? _ref30 : option.id;
780
- var itemId = (_ref31 = (_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 && _ref31 !== void 0 ? _ref31 : item.id;
947
+ var _ref38, _option$option_group_, _ref39, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
948
+ var optionItemId = (_ref38 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref38 !== void 0 ? _ref38 : option.id;
949
+ var itemId = (_ref39 = (_item$option_group_it = item.option_group_item_id) !== null && _item$option_group_it !== void 0 ? _item$option_group_it : item.product_option_item_id) !== null && _ref39 !== void 0 ? _ref39 : item.id;
781
950
  if (!isSameId(optionItemId, itemId)) return false;
782
951
  var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
783
952
  var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
@@ -787,16 +956,16 @@ function isOptionItemMatch(option, item) {
787
956
  return true;
788
957
  }
789
958
  function resolveBundleItemFromParentProduct(params) {
790
- var _ref32, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref34, _bundle$bundle_produc2;
959
+ var _ref40, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref42, _bundle$bundle_produc2;
791
960
  var bundle = params.bundle,
792
961
  parentProduct = params.parentProduct;
793
962
  if (!parentProduct) return null;
794
963
  var bundleItems = flattenBundleItems(parentProduct);
795
- var bundleVariantId = (_ref32 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref32 !== void 0 ? _ref32 : bundle.product_variant_id;
964
+ var bundleVariantId = (_ref40 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref40 !== void 0 ? _ref40 : bundle.product_variant_id;
796
965
  if (isNonZeroId(bundleVariantId)) {
797
966
  var matchedByVariant = bundleItems.find(function (item) {
798
- var _ref33, _item$bundle_variant_;
799
- return isSameId((_ref33 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref33 !== void 0 ? _ref33 : item.product_variant_id, bundleVariantId);
967
+ var _ref41, _item$bundle_variant_;
968
+ return isSameId((_ref41 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref41 !== void 0 ? _ref41 : item.product_variant_id, bundleVariantId);
800
969
  });
801
970
  if (matchedByVariant) return matchedByVariant;
802
971
  }
@@ -809,18 +978,18 @@ function resolveBundleItemFromParentProduct(params) {
809
978
  if (matchedByBundleId) return matchedByBundleId;
810
979
  }
811
980
  var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
812
- var bundleProductId = (_ref34 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref34 !== void 0 ? _ref34 : bundle.product_id;
981
+ var bundleProductId = (_ref42 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref42 !== void 0 ? _ref42 : bundle.product_id;
813
982
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
814
983
  var matchedByGroupAndProduct = bundleItems.find(function (item) {
815
- var _item$group_id, _ref35, _item$bundle_product_;
816
- return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref35 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref35 !== void 0 ? _ref35 : item.product_id, bundleProductId);
984
+ var _item$group_id, _ref43, _item$bundle_product_;
985
+ return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref43 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref43 !== void 0 ? _ref43 : item.product_id, bundleProductId);
817
986
  });
818
987
  if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
819
988
  }
820
989
  if (isPresentId(bundleProductId)) {
821
990
  return bundleItems.find(function (item) {
822
- var _ref36, _item$bundle_product_2;
823
- return isSameId((_ref36 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref36 !== void 0 ? _ref36 : item.product_id, bundleProductId);
991
+ var _ref44, _item$bundle_product_2;
992
+ return isSameId((_ref44 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref44 !== void 0 ? _ref44 : item.product_id, bundleProductId);
824
993
  }) || null;
825
994
  }
826
995
  return null;
@@ -830,9 +999,9 @@ function flattenBundleItems(parentProduct) {
830
999
  return bundleGroups.flatMap(function (group) {
831
1000
  var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
832
1001
  return items.map(function (item) {
833
- var _ref37, _item$group_id2;
1002
+ var _ref45, _item$group_id2;
834
1003
  return _objectSpread(_objectSpread({}, item), {}, {
835
- group_id: (_ref37 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref37 !== void 0 ? _ref37 : group.group_id
1004
+ group_id: (_ref45 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref45 !== void 0 ? _ref45 : group.group_id
836
1005
  });
837
1006
  });
838
1007
  });
@@ -856,8 +1025,8 @@ function isSameId(left, right) {
856
1025
  return String(left) === String(right);
857
1026
  }
858
1027
  function formatBundlePrice(bundle, currencySymbol) {
859
- var _ref38, _ref39, _bundle$bundle_sellin;
860
- var value = (_ref38 = (_ref39 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref39 !== void 0 ? _ref39 : bundle.price) !== null && _ref38 !== void 0 ? _ref38 : 0;
1028
+ var _ref46, _ref47, _bundle$bundle_sellin;
1029
+ var value = (_ref46 = (_ref47 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref47 !== void 0 ? _ref47 : bundle.price) !== null && _ref46 !== void 0 ? _ref46 : 0;
861
1030
  var amount = new Decimal(toMoneyNumber(value));
862
1031
  // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
863
1032
  var isNegative = bundle.price_type === 'markdown';
@@ -875,9 +1044,9 @@ function buildFees(params) {
875
1044
  financials = params.financials;
876
1045
  var fees = [];
877
1046
  for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
878
- var _ref40, _surcharge$amount;
1047
+ var _ref48, _surcharge$amount;
879
1048
  var surcharge = _normalizeArray[_i];
880
- var value = (_ref40 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref40 !== void 0 ? _ref40 : surcharge.total_amount;
1049
+ var value = (_ref48 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref48 !== void 0 ? _ref48 : surcharge.total_amount;
881
1050
  if (!isNonZero(value)) continue;
882
1051
  fees.push({
883
1052
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
@@ -900,12 +1069,6 @@ function buildFees(params) {
900
1069
  });
901
1070
  var isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
902
1071
  var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
903
- if (isNonZero(roundingAmount)) {
904
- fees.push({
905
- item: label(locale, 'rounding'),
906
- value: formatMoney(roundingAmount, currencySymbol)
907
- });
908
- }
909
1072
  var payProcessingFee = financials.payProcessingFee;
910
1073
  if (isNonZero(payProcessingFee)) {
911
1074
  fees.push({
@@ -985,9 +1148,9 @@ function resolveTaxTitle(params) {
985
1148
  }
986
1149
  function calculateProductOriginalAmount(order) {
987
1150
  return normalizeArray(order.products).reduce(function (total, product) {
988
- var _ref41, _ref42, _product$product_quan2, _ref43, _ref44, _ref45, _product$original_pri2;
989
- var quantity = toNumber((_ref41 = (_ref42 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref42 !== void 0 ? _ref42 : product.num) !== null && _ref41 !== void 0 ? _ref41 : 1, 1);
990
- var originalPrice = (_ref43 = (_ref44 = (_ref45 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref45 !== void 0 ? _ref45 : product.payment_price) !== null && _ref44 !== void 0 ? _ref44 : product.price) !== null && _ref43 !== void 0 ? _ref43 : 0;
1151
+ var _ref49, _ref50, _product$product_quan2, _ref51, _ref52, _ref53, _product$original_pri2;
1152
+ var quantity = toNumber((_ref49 = (_ref50 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref50 !== void 0 ? _ref50 : product.num) !== null && _ref49 !== void 0 ? _ref49 : 1, 1);
1153
+ var originalPrice = (_ref51 = (_ref52 = (_ref53 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref53 !== void 0 ? _ref53 : product.payment_price) !== null && _ref52 !== void 0 ? _ref52 : product.price) !== null && _ref51 !== void 0 ? _ref51 : 0;
991
1154
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
992
1155
  }, new Decimal(0));
993
1156
  }
@@ -1035,18 +1198,14 @@ function buildAppointment(order, locale) {
1035
1198
  var _order$metadata13, _order$metadata14, _order$form_data;
1036
1199
  var bookings = sortBookings(normalizeArray(order.bookings));
1037
1200
  if (bookings.length) {
1038
- return bookings.map(function (booking) {
1039
- var _booking$metadata, _booking$metadata2;
1040
- var snapshot = _objectSpread({}, booking);
1041
- delete snapshot.product_uid;
1042
- delete snapshot.booking_uid;
1043
- var productUid = firstPresentValue(booking.product_uid, (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid);
1044
- var bookingUid = firstPresentValue((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number, booking.booking_uid);
1045
- return _objectSpread(_objectSpread(_objectSpread({}, snapshot), isPresentId(productUid) ? {
1046
- product_uid: productUid
1047
- } : {}), isPresentId(bookingUid) ? {
1048
- booking_uid: bookingUid
1049
- } : {});
1201
+ var allResources = normalizeArray(order.resources || order.resource_list);
1202
+ return bookings.flatMap(function (booking) {
1203
+ return buildAppointmentRows({
1204
+ booking: booking,
1205
+ allResources: allResources,
1206
+ bookingCount: bookings.length,
1207
+ locale: locale
1208
+ });
1050
1209
  });
1051
1210
  }
1052
1211
  var tableName = order.table_name || ((_order$metadata13 = order.metadata) === null || _order$metadata13 === void 0 ? void 0 : _order$metadata13.table_name) || ((_order$metadata14 = order.metadata) === null || _order$metadata14 === void 0 || (_order$metadata14 = _order$metadata14.table) === null || _order$metadata14 === void 0 ? void 0 : _order$metadata14.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
@@ -1056,6 +1215,104 @@ function buildAppointment(order, locale) {
1056
1215
  value: getLocalizedValue(tableName, locale)
1057
1216
  }];
1058
1217
  }
1218
+ function buildAppointmentRows(params) {
1219
+ var _booking$metadata, _booking$metadata2, _booking$holder$name, _booking$holder, _booking$metadata3;
1220
+ var booking = params.booking,
1221
+ allResources = params.allResources,
1222
+ bookingCount = params.bookingCount,
1223
+ locale = params.locale;
1224
+ var productUid = stringify(firstPresentValue(booking.product_uid, (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid)).trim();
1225
+ var bookingUid = stringify(firstPresentValue((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number, booking.booking_uid)).trim();
1226
+ var association = {
1227
+ product_uid: productUid,
1228
+ booking_uid: bookingUid
1229
+ };
1230
+ var bookingId = stringify(firstPresentValue(booking.booking_id, booking.schedule_event_id, bookingUid)).trim();
1231
+ var bookingTime = formatBookingRange(booking, locale);
1232
+ var resourceText = formatBookingResources(resolveBookingResourcesForReceipt(booking, allResources, bookingCount), locale);
1233
+ 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();
1234
+ return [_objectSpread({
1235
+ item: label(locale, 'bookingId'),
1236
+ value: bookingId
1237
+ }, association), _objectSpread({
1238
+ item: label(locale, 'bookingDateTime'),
1239
+ value: bookingTime
1240
+ }, association), _objectSpread({
1241
+ item: label(locale, 'bookingResource'),
1242
+ value: resourceText
1243
+ }, association), _objectSpread({
1244
+ item: label(locale, 'bookingHolder'),
1245
+ value: holder
1246
+ }, association)].filter(function (row) {
1247
+ return Boolean(row.value);
1248
+ });
1249
+ }
1250
+ function formatBookingRange(booking, locale) {
1251
+ var startDate = stringify(booking.start_date);
1252
+ var startTime = stringify(booking.start_time);
1253
+ var endDate = stringify(booking.end_date || startDate);
1254
+ var endTime = stringify(booking.end_time);
1255
+ var start = firstValidBookingDate(booking.start_at, booking.start_datetime, booking.start_date_time, "".concat(startDate, " ").concat(startTime).trim());
1256
+ var end = firstValidBookingDate(booking.end_at, booking.end_datetime, booking.end_date_time, endTime ? "".concat(endDate, " ").concat(endTime).trim() : '');
1257
+ if (!start) {
1258
+ return [startDate, startTime, endTime ? "- ".concat(endDate, " ").concat(endTime) : ''].filter(Boolean).join(' ');
1259
+ }
1260
+ var dateFormat = locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD';
1261
+ var startText = start.format("".concat(dateFormat, " HH:mm"));
1262
+ if (!end) return startText;
1263
+ return "".concat(startText, " - ").concat(end.isSame(start, 'day') ? end.format('HH:mm') : end.format("".concat(dateFormat, " HH:mm")));
1264
+ }
1265
+ function firstValidBookingDate() {
1266
+ for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1267
+ values[_key2] = arguments[_key2];
1268
+ }
1269
+ for (var _i2 = 0, _values = values; _i2 < _values.length; _i2++) {
1270
+ var value = _values[_i2];
1271
+ if (!isPresentId(value)) continue;
1272
+ var parsed = dayjs(value);
1273
+ if (parsed.isValid()) return parsed;
1274
+ }
1275
+ return null;
1276
+ }
1277
+ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount) {
1278
+ var _booking$metadata4;
1279
+ var embedded = normalizeArray(booking.resources).filter(function (resource) {
1280
+ return Boolean(resource) && _typeof(resource) === 'object' && !Array.isArray(resource);
1281
+ });
1282
+ var resourceIds = new Set([booking.resource_id, booking.relation_id].concat(_toConsumableArray(normalizeArray(booking.resource_ids)), _toConsumableArray(normalizeArray((_booking$metadata4 = booking.metadata) === null || _booking$metadata4 === void 0 ? void 0 : _booking$metadata4.resource_ids))).map(function (value) {
1283
+ return stringify(value).trim();
1284
+ }).filter(Boolean));
1285
+ var _iterator3 = _createForOfIteratorHelper(embedded),
1286
+ _step3;
1287
+ try {
1288
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1289
+ var _ref55, _resource$id2;
1290
+ var resource = _step3.value;
1291
+ var id = stringify((_ref55 = (_resource$id2 = resource.id) !== null && _resource$id2 !== void 0 ? _resource$id2 : resource.resource_id) !== null && _ref55 !== void 0 ? _ref55 : resource.relation_id).trim();
1292
+ if (id) resourceIds.add(id);
1293
+ }
1294
+ } catch (err) {
1295
+ _iterator3.e(err);
1296
+ } finally {
1297
+ _iterator3.f();
1298
+ }
1299
+ if (resourceIds.size) {
1300
+ var matched = allResources.filter(function (resource) {
1301
+ var _ref54, _resource$id;
1302
+ return resourceIds.has(stringify((_ref54 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.resource_id) !== null && _ref54 !== void 0 ? _ref54 : resource.relation_id).trim());
1303
+ });
1304
+ if (matched.length) return matched;
1305
+ }
1306
+ if (embedded.length) return embedded;
1307
+ if (bookingCount === 1 && allResources.length) return allResources;
1308
+ return [];
1309
+ }
1310
+ function formatBookingResources(resources, locale) {
1311
+ return resources.map(function (resource) {
1312
+ var _resource$metadata, _resource$metadata2, _resource$metadata3, _resource$metadata4;
1313
+ return [getLocalizedValue(resource.form_title || ((_resource$metadata = resource.metadata) === null || _resource$metadata === void 0 ? void 0 : _resource$metadata.form_name) || resource.relation_form_name || ((_resource$metadata2 = resource.metadata) === null || _resource$metadata2 === void 0 ? void 0 : _resource$metadata2.relation_form_name), locale), getLocalizedValue(resource.title || resource.name || resource.main_field || ((_resource$metadata3 = resource.metadata) === null || _resource$metadata3 === void 0 ? void 0 : _resource$metadata3.main_field) || ((_resource$metadata4 = resource.metadata) === null || _resource$metadata4 === void 0 ? void 0 : _resource$metadata4.resource_name), locale)].filter(Boolean).join(' ');
1314
+ }).filter(Boolean).join(', ');
1315
+ }
1059
1316
  function sortBookings(bookings) {
1060
1317
  return bookings.map(function (booking, index) {
1061
1318
  return {
@@ -1067,23 +1324,23 @@ function sortBookings(bookings) {
1067
1324
  var leftStart = bookingStartTimestamp(left.booking);
1068
1325
  var rightStart = bookingStartTimestamp(right.booking);
1069
1326
  if (leftStart !== rightStart) return leftStart < rightStart ? -1 : 1;
1070
- for (var _i2 = 0, _arr = ['booking_id', 'schedule_event_id']; _i2 < _arr.length; _i2++) {
1327
+ for (var _i3 = 0, _arr = ['booking_id', 'schedule_event_id']; _i3 < _arr.length; _i3++) {
1071
1328
  var _left$booking, _right$booking;
1072
- var field = _arr[_i2];
1329
+ var field = _arr[_i3];
1073
1330
  var fieldOrder = compareOptionalValues((_left$booking = left.booking) === null || _left$booking === void 0 ? void 0 : _left$booking[field], (_right$booking = right.booking) === null || _right$booking === void 0 ? void 0 : _right$booking[field]);
1074
1331
  if (fieldOrder !== 0) return fieldOrder;
1075
1332
  }
1076
1333
  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));
1077
1334
  return bookingUidOrder || left.index - right.index;
1078
- }).map(function (_ref46) {
1079
- var booking = _ref46.booking;
1335
+ }).map(function (_ref56) {
1336
+ var booking = _ref56.booking;
1080
1337
  return booking;
1081
1338
  });
1082
1339
  }
1083
1340
  function bookingStartTimestamp(booking) {
1084
1341
  var startValues = [booking === null || booking === void 0 ? void 0 : booking.start_at, booking === null || booking === void 0 ? void 0 : booking.start_datetime, booking === null || booking === void 0 ? void 0 : booking.booking_time, isPresentId(booking === null || booking === void 0 ? void 0 : booking.start_date) ? "".concat(booking.start_date, " ").concat(stringify(booking.start_time)).trim() : undefined];
1085
- for (var _i3 = 0, _startValues = startValues; _i3 < _startValues.length; _i3++) {
1086
- var startValue = _startValues[_i3];
1342
+ for (var _i4 = 0, _startValues = startValues; _i4 < _startValues.length; _i4++) {
1343
+ var startValue = _startValues[_i4];
1087
1344
  if (!isPresentId(startValue)) continue;
1088
1345
  var timestamp = dayjs(startValue).valueOf();
1089
1346
  if (Number.isFinite(timestamp)) return timestamp;
@@ -1138,8 +1395,8 @@ function buildRefundData(params) {
1138
1395
  result.set(identity, candidate);
1139
1396
  }
1140
1397
  return result;
1141
- }, new Map()).values()).filter(function (_ref47) {
1142
- var refund = _ref47.refund;
1398
+ }, new Map()).values()).filter(function (_ref57) {
1399
+ var refund = _ref57.refund;
1143
1400
  return isPrintableRefund(refund);
1144
1401
  }).sort(function (left, right) {
1145
1402
  var leftTime = refundTimestamp(left.refund);
@@ -1147,9 +1404,9 @@ function buildRefundData(params) {
1147
1404
  if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1148
1405
  return left.index - right.index;
1149
1406
  });
1150
- return refunds.map(function (_ref48) {
1407
+ return refunds.map(function (_ref58) {
1151
1408
  var _firstPresentValue8;
1152
- var refund = _ref48.refund;
1409
+ var refund = _ref58.refund;
1153
1410
  var payment = resolveRefundPayment(refund, payments);
1154
1411
  var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
1155
1412
  var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
@@ -1287,18 +1544,34 @@ function getPointCardSnapshotRemainingPoints(snapshot) {
1287
1544
  }
1288
1545
  function buildVoucherAssets(params) {
1289
1546
  var seenVoucherKeys = new Set();
1547
+ var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1290
1548
  return normalizeArray(params.order.vouchers).flatMap(function (voucher, index) {
1291
1549
  if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
1292
1550
  var voucherKey = getVoucherAssetKey(voucher, index);
1293
1551
  if (seenVoucherKeys.has(voucherKey)) return [];
1294
1552
  seenVoucherKeys.add(voucherKey);
1295
1553
  var name = getVoucherAssetName(voucher, params.locale);
1554
+ var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
1555
+ var timeRow = isPresentId(assetTime) ? {
1556
+ item: formatDateTime(assetTime, params.locale),
1557
+ value: ''
1558
+ } : null;
1559
+ if (isTicketVoucher(voucher)) {
1560
+ var validity = getVoucherValidity(voucher, params.locale);
1561
+ return [[{
1562
+ item: name,
1563
+ value: ''
1564
+ }].concat(_toConsumableArray(validity ? [{
1565
+ item: label(params.locale, 'validity'),
1566
+ value: validity
1567
+ }] : []))];
1568
+ }
1296
1569
  var percent = getVoucherDiscountPercent(voucher);
1297
1570
  if (percent) {
1298
1571
  return [[{
1299
1572
  item: appendPercentToVoucherName(name, percent),
1300
1573
  value: formatVoucherDiscount(percent, params.locale)
1301
- }]];
1574
+ }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1302
1575
  }
1303
1576
  var balance = getVoucherBalance(voucher);
1304
1577
  return [[{
@@ -1307,9 +1580,71 @@ function buildVoucherAssets(params) {
1307
1580
  }, {
1308
1581
  item: label(params.locale, 'balance'),
1309
1582
  value: formatMoney(balance, params.currencySymbol)
1310
- }]];
1583
+ }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1311
1584
  });
1312
1585
  }
1586
+ function isTicketVoucher(voucher) {
1587
+ return stringify(voucher.tag).trim().toLowerCase() === 'ticket';
1588
+ }
1589
+ function getVoucherValidity(voucher, locale) {
1590
+ var _voucher$metadata, _voucher$metadata2, _voucher$metadata3, _voucher$metadata4, _voucher$metadata5, _voucher$metadata6, _voucher$metadata7, _voucher$metadata8, _voucher$metadata9, _voucher$metadata10, _voucher$start_time, _voucher$metadata11, _voucher$end_time, _voucher$metadata12;
1591
+ var availableTime = firstPresentValue(voucher.available_time, voucher.avaliable_time, (_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.available_time, (_voucher$metadata2 = voucher.metadata) === null || _voucher$metadata2 === void 0 ? void 0 : _voucher$metadata2.avaliable_time);
1592
+ var availableTimeText = formatVoucherAvailableTime(availableTime, locale);
1593
+ if (availableTimeText) return availableTimeText;
1594
+ var startDate = firstPresentValue(voucher.valid_from, voucher.start_at, voucher.start_date_time, voucher.start_date, (_voucher$metadata3 = voucher.metadata) === null || _voucher$metadata3 === void 0 ? void 0 : _voucher$metadata3.valid_from, (_voucher$metadata4 = voucher.metadata) === null || _voucher$metadata4 === void 0 ? void 0 : _voucher$metadata4.start_at, (_voucher$metadata5 = voucher.metadata) === null || _voucher$metadata5 === void 0 ? void 0 : _voucher$metadata5.start_date);
1595
+ var endDate = firstPresentValue(voucher.valid_to, voucher.end_at, voucher.end_date_time, voucher.expire_date, voucher.end_date, voucher.expire_time, (_voucher$metadata6 = voucher.metadata) === null || _voucher$metadata6 === void 0 ? void 0 : _voucher$metadata6.valid_to, (_voucher$metadata7 = voucher.metadata) === null || _voucher$metadata7 === void 0 ? void 0 : _voucher$metadata7.end_at, (_voucher$metadata8 = voucher.metadata) === null || _voucher$metadata8 === void 0 ? void 0 : _voucher$metadata8.expire_date, (_voucher$metadata9 = voucher.metadata) === null || _voucher$metadata9 === void 0 ? void 0 : _voucher$metadata9.end_date, (_voucher$metadata10 = voucher.metadata) === null || _voucher$metadata10 === void 0 ? void 0 : _voucher$metadata10.expire_time);
1596
+ return formatVoucherValidityRange(startDate, endDate, locale, {
1597
+ startTime: (_voucher$start_time = voucher.start_time) !== null && _voucher$start_time !== void 0 ? _voucher$start_time : (_voucher$metadata11 = voucher.metadata) === null || _voucher$metadata11 === void 0 ? void 0 : _voucher$metadata11.start_time,
1598
+ endTime: (_voucher$end_time = voucher.end_time) !== null && _voucher$end_time !== void 0 ? _voucher$end_time : (_voucher$metadata12 = voucher.metadata) === null || _voucher$metadata12 === void 0 ? void 0 : _voucher$metadata12.end_time
1599
+ });
1600
+ }
1601
+ function formatVoucherAvailableTime(value, locale) {
1602
+ if (!isPresentId(value)) return '';
1603
+ if (Array.isArray(value)) {
1604
+ return value.map(function (item) {
1605
+ return formatVoucherAvailableTime(item, locale);
1606
+ }).filter(Boolean).join(', ');
1607
+ }
1608
+ if (_typeof(value) !== 'object') return stringify(value).trim();
1609
+ var start = firstPresentValue(value.start, value.start_at, value.start_date_time, value.start_date);
1610
+ var end = firstPresentValue(value.end, value.end_at, value.end_date_time, value.expire_time, value.expire_date, value.end_date);
1611
+ if (isPresentId(start) || isPresentId(end)) {
1612
+ return formatVoucherValidityRange(start, end, locale, {
1613
+ startTime: value.start_time,
1614
+ endTime: value.end_time
1615
+ });
1616
+ }
1617
+ return getLocalizedValue(value, locale).trim();
1618
+ }
1619
+ function formatVoucherValidityRange(startValue, endValue, locale) {
1620
+ var times = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1621
+ var start = combineVoucherDateAndTime(startValue, times.startTime);
1622
+ var end = combineVoucherDateAndTime(endValue, times.endTime);
1623
+ var startText = formatVoucherValidityDate(start, locale);
1624
+ var endText = formatVoucherValidityDate(end, locale);
1625
+ if (startText && endText) {
1626
+ var parsedStart = dayjs(start);
1627
+ var parsedEnd = dayjs(end);
1628
+ var sameDay = parsedStart.isValid() && parsedEnd.isValid() && parsedStart.isSame(parsedEnd, 'day');
1629
+ return "".concat(startText, " - ").concat(sameDay && /\d{1,2}:\d{2}/.test(stringify(end)) ? parsedEnd.format('HH:mm') : endText);
1630
+ }
1631
+ return startText || endText;
1632
+ }
1633
+ function combineVoucherDateAndTime(dateValue, timeValue) {
1634
+ if (!isPresentId(dateValue) || !isPresentId(timeValue)) return dateValue;
1635
+ var dateText = stringify(dateValue).trim();
1636
+ if (/\d{1,2}:\d{2}/.test(dateText)) return dateValue;
1637
+ return "".concat(dateText, " ").concat(stringify(timeValue).trim());
1638
+ }
1639
+ function formatVoucherValidityDate(value, locale) {
1640
+ if (!isPresentId(value)) return '';
1641
+ var source = stringify(value).trim();
1642
+ var parsed = dayjs(source);
1643
+ if (!parsed.isValid()) return source;
1644
+ var hasTime = /\d{1,2}:\d{2}/.test(source);
1645
+ if (locale === 'en') return parsed.format(hasTime ? 'DD/MM/YYYY HH:mm' : 'DD/MM/YYYY');
1646
+ return parsed.format(hasTime ? 'YYYY/MM/DD HH:mm' : 'YYYY/MM/DD');
1647
+ }
1313
1648
  function getVoucherAssetKey(voucher, index) {
1314
1649
  var identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
1315
1650
  return identity === undefined ? "voucher-index:".concat(index) : "voucher:".concat(String(identity));
@@ -1318,8 +1653,8 @@ function getVoucherAssetName(voucher, locale) {
1318
1653
  return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
1319
1654
  }
1320
1655
  function getVoucherDiscountPercent(voucher) {
1321
- var _voucher$metadata;
1322
- var discountType = stringify(((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.discount_card_type) || voucher.discount_card_type).toLowerCase();
1656
+ var _voucher$metadata13;
1657
+ var discountType = stringify(((_voucher$metadata13 = voucher.metadata) === null || _voucher$metadata13 === void 0 ? void 0 : _voucher$metadata13.discount_card_type) || voucher.discount_card_type).toLowerCase();
1323
1658
  if (discountType !== 'percent' && discountType !== 'percentage') return null;
1324
1659
  var percent = new Decimal(toMoneyNumber(voucher.par_value));
1325
1660
  if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
@@ -1377,8 +1712,8 @@ function buildPaymentItems(params) {
1377
1712
  includeUsage: includeFundRecordUsage
1378
1713
  })));
1379
1714
  } else {
1380
- var _ref49, _payment$remaining_am, _payment$metadata;
1381
- var remainingAmount = (_ref49 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref49 !== void 0 ? _ref49 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
1715
+ var _ref59, _payment$remaining_am, _payment$metadata;
1716
+ var remainingAmount = (_ref59 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref59 !== void 0 ? _ref59 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
1382
1717
  if (remainingAmount !== undefined && remainingAmount !== null) {
1383
1718
  items.push({
1384
1719
  item: label(locale, 'remainingAmount'),
@@ -1532,12 +1867,12 @@ function label(locale, key) {
1532
1867
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
1533
1868
  }
1534
1869
  function getLocalizedValue(value, locale) {
1535
- var _ref50, _ref51, _ref52, _ref53, _ref54, _ref55, _value$locale2;
1870
+ var _ref60, _ref61, _ref62, _ref63, _ref64, _ref65, _value$locale2;
1536
1871
  if (value === undefined || value === null) return '';
1537
1872
  if (_typeof(value) !== 'object') return stringify(value);
1538
1873
  var dashedLocale = locale.replace('_', '-');
1539
1874
  var underscoredLocale = locale.replace('-', '_');
1540
- return stringify((_ref50 = (_ref51 = (_ref52 = (_ref53 = (_ref54 = (_ref55 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref55 !== void 0 ? _ref55 : value[underscoredLocale]) !== null && _ref54 !== void 0 ? _ref54 : value.original) !== null && _ref53 !== void 0 ? _ref53 : value.auto) !== null && _ref52 !== void 0 ? _ref52 : value.default) !== null && _ref51 !== void 0 ? _ref51 : value.en) !== null && _ref50 !== void 0 ? _ref50 : '');
1875
+ return stringify((_ref60 = (_ref61 = (_ref62 = (_ref63 = (_ref64 = (_ref65 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref65 !== void 0 ? _ref65 : value[underscoredLocale]) !== null && _ref64 !== void 0 ? _ref64 : value.original) !== null && _ref63 !== void 0 ? _ref63 : value.auto) !== null && _ref62 !== void 0 ? _ref62 : value.default) !== null && _ref61 !== void 0 ? _ref61 : value.en) !== null && _ref60 !== void 0 ? _ref60 : '');
1541
1876
  }
1542
1877
  function resolveServiceTypeLabelKey(serviceType, order) {
1543
1878
  var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');