@pisell/pisellos 2.3.109 → 2.3.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/modules/OpenData/index.d.ts +1 -1
  2. package/dist/modules/OpenData/index.js +19 -11
  3. package/dist/modules/Order/index.d.ts +1 -0
  4. package/dist/modules/Order/index.js +22 -21
  5. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
  6. package/dist/modules/Payment/cashRecommendationAlgorithm.js +17 -367
  7. package/dist/server/index.js +4 -5
  8. package/dist/server/utils/small-ticket.d.ts +8 -5
  9. package/dist/server/utils/small-ticket.js +678 -140
  10. package/dist/solution/BookingByStep/index.d.ts +1 -1
  11. package/dist/solution/BookingTicket/index.d.ts +6 -0
  12. package/dist/solution/BookingTicket/index.js +548 -485
  13. package/dist/utils/os-private-payload.d.ts +5 -0
  14. package/dist/utils/os-private-payload.js +17 -0
  15. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  16. package/lib/modules/OpenData/index.d.ts +1 -1
  17. package/lib/modules/OpenData/index.js +9 -1
  18. package/lib/modules/Order/index.d.ts +1 -0
  19. package/lib/modules/Order/index.js +15 -18
  20. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
  21. package/lib/modules/Payment/cashRecommendationAlgorithm.js +9 -354
  22. package/lib/server/index.js +4 -5
  23. package/lib/server/utils/small-ticket.d.ts +8 -5
  24. package/lib/server/utils/small-ticket.js +524 -65
  25. package/lib/solution/BookingByStep/index.d.ts +1 -1
  26. package/lib/solution/BookingTicket/index.d.ts +6 -0
  27. package/lib/solution/BookingTicket/index.js +32 -3
  28. package/lib/utils/os-private-payload.d.ts +5 -0
  29. package/lib/utils/os-private-payload.js +22 -0
  30. package/package.json +1 -1
@@ -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; }
@@ -35,13 +39,20 @@ var LABELS = {
35
39
  eftpos: 'Eftpos',
36
40
  wallet: 'Wallet',
37
41
  giftCard: 'Gift card',
42
+ pointCard: 'Point card',
38
43
  balance: 'Balance',
44
+ validity: 'Validity',
39
45
  remainingAmount: 'Remaining amount',
40
46
  redeemPoints: 'Redeem points',
41
- remainingPoints: 'Remaining points',
47
+ remainingPoints: 'Points balance',
42
48
  table: 'Table',
49
+ bookingId: 'Booking ID',
50
+ bookingDateTime: 'Date & time',
51
+ bookingResource: 'Resource',
52
+ bookingHolder: 'Holder',
43
53
  orderDiscount: 'Order discount',
44
54
  manualDiscount: 'Manual discount',
55
+ manualMarkup: 'Manual markup',
45
56
  payProcessingFee: 'Pay processing fee',
46
57
  surchargeIncluded: 'Surcharge(Included)',
47
58
  rounding: 'Rounding',
@@ -67,13 +78,20 @@ var LABELS = {
67
78
  eftpos: '刷卡支付',
68
79
  wallet: '钱包支付',
69
80
  giftCard: '礼品卡',
81
+ pointCard: '积分卡',
70
82
  balance: '余额',
83
+ validity: '有效期',
71
84
  remainingAmount: '剩余金额',
72
85
  redeemPoints: '本次使用积分',
73
- remainingPoints: '剩余积分',
86
+ remainingPoints: '积分余额',
74
87
  table: '桌台',
88
+ bookingId: '预约编号',
89
+ bookingDateTime: '日期和时间',
90
+ bookingResource: '资源',
91
+ bookingHolder: '预约人',
75
92
  orderDiscount: '整单折扣',
76
93
  manualDiscount: '手动折扣',
94
+ manualMarkup: '手动加价',
77
95
  payProcessingFee: '支付手续费',
78
96
  surchargeIncluded: '手续费(已含)',
79
97
  rounding: '抹零',
@@ -99,13 +117,20 @@ var LABELS = {
99
117
  eftpos: '刷卡支付',
100
118
  wallet: '錢包支付',
101
119
  giftCard: '禮品卡',
120
+ pointCard: '積分卡',
102
121
  balance: '餘額',
122
+ validity: '有效期',
103
123
  remainingAmount: '剩餘金額',
104
124
  redeemPoints: '本次使用積分',
105
- remainingPoints: '剩餘積分',
125
+ remainingPoints: '積分餘額',
106
126
  table: '桌台',
127
+ bookingId: '預約編號',
128
+ bookingDateTime: '日期和時間',
129
+ bookingResource: '資源',
130
+ bookingHolder: '預約人',
107
131
  orderDiscount: '整單折扣',
108
132
  manualDiscount: '手動折扣',
133
+ manualMarkup: '手動加價',
109
134
  payProcessingFee: '支付手續費',
110
135
  surchargeIncluded: '手續費(已含)',
111
136
  rounding: '抹零',
@@ -129,13 +154,20 @@ var LABELS = {
129
154
  eftpos: 'カード',
130
155
  wallet: 'ウォレット',
131
156
  giftCard: 'ギフトカード',
157
+ pointCard: 'ポイントカード',
132
158
  balance: '残高',
159
+ validity: '有効期限',
133
160
  remainingAmount: '残高',
134
161
  redeemPoints: '利用ポイント',
135
- remainingPoints: '残りポイント',
162
+ remainingPoints: 'ポイント残高',
136
163
  table: 'テーブル',
164
+ bookingId: '予約ID',
165
+ bookingDateTime: '日時',
166
+ bookingResource: 'リソース',
167
+ bookingHolder: '予約者',
137
168
  orderDiscount: '注文割引',
138
169
  manualDiscount: '手動割引',
170
+ manualMarkup: '手動値上げ',
139
171
  payProcessingFee: '決済手数料',
140
172
  rounding: '端数調整',
141
173
  gross: '総重量',
@@ -160,13 +192,20 @@ var LABELS = {
160
192
  eftpos: 'Cartão',
161
193
  wallet: 'Carteira',
162
194
  giftCard: 'Cartão-presente',
195
+ pointCard: 'Cartão de pontos',
163
196
  balance: 'Saldo',
197
+ validity: 'Validade',
164
198
  remainingAmount: 'Saldo restante',
165
199
  redeemPoints: 'Pontos utilizados',
166
- remainingPoints: 'Pontos restantes',
200
+ remainingPoints: 'Saldo de pontos',
167
201
  table: 'Mesa',
202
+ bookingId: 'ID da reserva',
203
+ bookingDateTime: 'Data e hora',
204
+ bookingResource: 'Recurso',
205
+ bookingHolder: 'Titular',
168
206
  orderDiscount: 'Desconto do pedido',
169
207
  manualDiscount: 'Desconto manual',
208
+ manualMarkup: 'Acréscimo manual',
170
209
  payProcessingFee: 'Taxa de processamento',
171
210
  rounding: 'Arredondamento',
172
211
  gross: 'Peso bruto',
@@ -250,14 +289,14 @@ function buildLocaleData(params) {
250
289
  });
251
290
  }
252
291
  function buildBaseData(params) {
253
- var _order$metadata;
292
+ var _financials$amountGap, _order$metadata;
254
293
  var order = params.order,
255
294
  shopInfo = params.shopInfo,
256
295
  locale = params.locale,
257
296
  currencySymbol = params.currencySymbol,
258
297
  financials = params.financials;
259
298
  var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
260
- return _objectSpread(_objectSpread({
299
+ return _objectSpread({
261
300
  shop_name: stringify(shopInfo.name || order.shop_name),
262
301
  note: stringify(order.note),
263
302
  shop_order_number: stringify(order.shop_order_number),
@@ -268,10 +307,8 @@ function buildBaseData(params) {
268
307
  original_payment_status: financials.paymentStatus,
269
308
  payment_status: financials.paymentStatus,
270
309
  total_amount: formatMoney(financials.totalAmount, currencySymbol),
271
- has_pay: formatMoney(financials.netPaymentApplied, currencySymbol)
272
- }, isPresentId(financials.amountGap) ? {
273
- amount_gap: formatMoney(financials.amountGap, currencySymbol)
274
- } : {}), {}, {
310
+ has_pay: formatMoney(financials.netPaymentApplied, currencySymbol),
311
+ amount_gap: formatCalculatedMoney((_financials$amountGap = financials.amountGap) !== null && _financials$amountGap !== void 0 ? _financials$amountGap : 0, currencySymbol),
275
312
  is_repeat: 0,
276
313
  buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
277
314
  order_no: orderNumber,
@@ -282,8 +319,10 @@ function buildBaseData(params) {
282
319
  }
283
320
  function buildProducts(order, locale, productMap) {
284
321
  var products = Array.isArray(order.products) ? order.products : [];
285
- return products.map(function (product) {
322
+ var allergyByProductUid = buildProductAllergyMap(order, locale);
323
+ return products.map(function (rawProduct) {
286
324
  var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric, _product$product_id, _product$metadata, _product$metadata2;
325
+ var product = restoreReceiptDiscountHierarchy(rawProduct);
287
326
  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);
288
327
  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;
289
328
  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;
@@ -322,16 +361,25 @@ function buildProducts(order, locale, productMap) {
322
361
  originalPrice: originalPrice
323
362
  });
324
363
  var productNote = resolveProductNote(product, locale);
364
+ var allergy = isPresentId(productUid) ? allergyByProductUid.get(String(productUid).trim()) || '' : '';
325
365
  var basePrice = resolveProductBasePrice(product);
326
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
366
+ var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
367
+ var shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
368
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
327
369
  product_title: productTitle,
328
370
  product_quantity: quantity,
329
371
  selling_price: formatMoney(sellingPrice, currencySymbol),
372
+ total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
330
373
  original_price: formatMoney(originalPrice, currencySymbol)
331
- }, isPresentId(basePrice) ? {
332
- base_price: formatMoney(basePrice, currencySymbol)
374
+ }, shouldIncludeBasePrice ? {
375
+ base_price: formatCalculatedMoney(basePrice !== null && basePrice !== void 0 ? basePrice : 0, currencySymbol)
376
+ } : {}), {}, {
377
+ total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol)
378
+ }, options.length ? {
379
+ options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
380
+ } : {}), resolvedCombinations.length ? {
381
+ package_items_total_price: sumCombinationTotals(resolvedCombinations, currencySymbol)
333
382
  } : {}), {}, {
334
- total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
335
383
  extension_list: extensionList
336
384
  }, isPresentId(productUid) ? {
337
385
  product_uid: productUid
@@ -339,17 +387,107 @@ function buildProducts(order, locale, productMap) {
339
387
  booking_uid: bookingUid
340
388
  } : {}), productNote ? {
341
389
  product_note: productNote
390
+ } : {}), allergy ? {
391
+ allergy: allergy
342
392
  } : {}), options.length ? {
343
393
  options: options
344
394
  } : {}), resolvedVariant ? {
345
395
  variant: resolvedVariant
346
- } : {}), Array.isArray(product.combinations) && product.combinations.length ? {
347
- combinations: normalizeExistingCombinations(product.combinations, locale)
348
- } : combinations.length ? {
349
- combinations: combinations
396
+ } : {}), resolvedCombinations.length ? {
397
+ combinations: resolvedCombinations
350
398
  } : {});
351
399
  });
352
400
  }
401
+ var RECEIPT_BUNDLE_MAP_ID_KEY = 'custom_product_bundle_map_id';
402
+ function restoreReceiptDiscountHierarchy(source) {
403
+ if (!source || _typeof(source) !== 'object' || Array.isArray(source)) {
404
+ return source;
405
+ }
406
+ var childKey = Array.isArray(source.combinations) && source.combinations.length ? 'combinations' : Array.isArray(source.product_bundle) && source.product_bundle.length ? 'product_bundle' : null;
407
+ if (!childKey) return _objectSpread({}, source);
408
+ var children = source[childKey].map(function (child) {
409
+ return child && _typeof(child) === 'object' && !Array.isArray(child) ? restoreReceiptDiscountHierarchy(child) : child;
410
+ });
411
+ var restored = _objectSpread(_objectSpread({}, source), {}, _defineProperty({}, childKey, children));
412
+ if (!Array.isArray(source.discount_list) || !source.discount_list.length) {
413
+ return restored;
414
+ }
415
+ var descendantsByMapId = new Map();
416
+ indexReceiptDiscountTargets(children, descendantsByMapId);
417
+ if (!descendantsByMapId.size) return restored;
418
+ var ownDiscounts = [];
419
+ var _iterator = _createForOfIteratorHelper(source.discount_list),
420
+ _step;
421
+ try {
422
+ var _loop = function _loop() {
423
+ var discount = _step.value;
424
+ var mapId = getReceiptDiscountBundleMapId(discount);
425
+ var target = mapId ? descendantsByMapId.get(mapId) : undefined;
426
+ if (!target) {
427
+ ownDiscounts.push(discount);
428
+ return 1; // continue
429
+ }
430
+ var targetDiscounts = Array.isArray(target.discount_list) ? target.discount_list : [];
431
+ if (!targetDiscounts.some(function (item) {
432
+ return isSameReceiptDiscount(item, discount);
433
+ })) {
434
+ target.discount_list = [].concat(_toConsumableArray(targetDiscounts), [discount]);
435
+ }
436
+ };
437
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
438
+ if (_loop()) continue;
439
+ }
440
+ } catch (err) {
441
+ _iterator.e(err);
442
+ } finally {
443
+ _iterator.f();
444
+ }
445
+ restored.discount_list = ownDiscounts;
446
+ return restored;
447
+ }
448
+ function indexReceiptDiscountTargets(nodes, targets) {
449
+ var _iterator2 = _createForOfIteratorHelper(nodes),
450
+ _step2;
451
+ try {
452
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
453
+ var node = _step2.value;
454
+ if (!node || _typeof(node) !== 'object' || Array.isArray(node)) continue;
455
+ var mapId = getReceiptBundleMapId(node);
456
+ if (mapId && !targets.has(mapId)) targets.set(mapId, node);
457
+ var children = Array.isArray(node.combinations) && node.combinations.length ? node.combinations : Array.isArray(node.product_bundle) ? node.product_bundle : [];
458
+ indexReceiptDiscountTargets(children, targets);
459
+ }
460
+ } catch (err) {
461
+ _iterator2.e(err);
462
+ } finally {
463
+ _iterator2.f();
464
+ }
465
+ }
466
+ function normalizeReceiptId(value) {
467
+ if (value === undefined || value === null) return null;
468
+ var normalized = String(value).trim();
469
+ return normalized ? normalized : null;
470
+ }
471
+ function getReceiptBundleMapId(node) {
472
+ var _node$metadata$RECEIP, _node$metadata;
473
+ 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);
474
+ }
475
+ function getReceiptDiscountBundleMapId(discount) {
476
+ var _discount$metadata;
477
+ 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]);
478
+ }
479
+ function isSameReceiptDiscount(left, right) {
480
+ var _ref8, _left$discount$resour, _left$discount, _ref9, _right$discount$resou, _right$discount, _ref10, _ref11, _left$amount, _ref12, _ref13, _right$amount;
481
+ var leftOrderDiscountId = normalizeReceiptId(left === null || left === void 0 ? void 0 : left.order_discount_id);
482
+ var rightOrderDiscountId = normalizeReceiptId(right === null || right === void 0 ? void 0 : right.order_discount_id);
483
+ if (leftOrderDiscountId && rightOrderDiscountId) {
484
+ return leftOrderDiscountId === rightOrderDiscountId;
485
+ }
486
+ 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);
487
+ 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);
488
+ if (!leftResourceId || !rightResourceId) return false;
489
+ 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 : '');
490
+ }
353
491
  function resolveProductBasePrice(product) {
354
492
  var _product$product_vari, _product$_origin, _product$_origin2;
355
493
  var metadata = product.metadata || {};
@@ -366,16 +504,47 @@ function normalizeProductDiscounts(params) {
366
504
  locale = params.locale,
367
505
  currencySymbol = params.currencySymbol,
368
506
  quantity = params.quantity;
369
- return normalizeArray(product.discount_list).map(function (discount) {
370
- var _ref8, _discount$amount;
507
+ var rows = normalizeArray(product.discount_list).filter(function (discount) {
508
+ var _ref14, _discount$amount;
509
+ var amount = (_ref14 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref14 !== void 0 ? _ref14 : discount.discount_amount;
510
+ return isNonZero(amount);
511
+ }).map(function (discount) {
512
+ var _ref15, _discount$amount2;
371
513
  var title = resolveDiscountTitleWithPercent(discount, locale);
372
- var amount = (_ref8 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref8 !== void 0 ? _ref8 : discount.discount_amount;
373
- var formattedAmount = formatNegativeMoney(new Decimal(toMoneyNumber(amount)).mul(quantity), currencySymbol);
514
+ var amount = (_ref15 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref15 !== void 0 ? _ref15 : discount.discount_amount;
515
+ var isMarkup = isManualMarkup(discount);
516
+ var totalAmount = new Decimal(toMoneyNumber(amount)).mul(quantity);
517
+ var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
374
518
  return {
375
519
  item: title,
376
- value: formattedAmount
520
+ value: formattedAmount,
521
+ isMarkup: isMarkup
377
522
  };
378
523
  });
524
+ return rows.sort(function (left, right) {
525
+ return Number(right.isMarkup) - Number(left.isMarkup);
526
+ }).map(function (_ref16) {
527
+ var _isMarkup = _ref16.isMarkup,
528
+ row = _objectWithoutProperties(_ref16, _excluded);
529
+ return row;
530
+ });
531
+ }
532
+ function isManualMarkup(discount) {
533
+ var _discount$discount, _ref17, _discount$amount3;
534
+ if (discount.type !== 'product') return false;
535
+ if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
536
+ var amount = (_ref17 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
537
+ return new Decimal(toMoneyNumber(amount)).isNegative();
538
+ }
539
+ function hasProductDiscount(product) {
540
+ var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
541
+ var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
542
+ var _ref18, _discount$amount4;
543
+ return isNonZero((_ref18 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref18 !== void 0 ? _ref18 : discount.discount_amount);
544
+ });
545
+ return hasDiscountListAmount || extensionList.some(function (row) {
546
+ return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
547
+ });
379
548
  }
380
549
  function buildProductExtensionList(params) {
381
550
  var product = params.product,
@@ -442,10 +611,10 @@ function buildProductQuantityPriceText(params) {
442
611
  return "".concat(quantity, " @ ").concat(currencySymbol).concat(stringify(price), " EACH");
443
612
  }
444
613
  function resolveDiscountTitleWithPercent(discount, locale) {
445
- var _discount$discount, _discount$discount$di, _discount$discount2;
614
+ var _discount$discount2, _discount$discount$di, _discount$discount3;
446
615
  var title = resolveDiscountTitle(discount, locale);
447
- var percentRaw = (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.percent;
448
- 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';
616
+ var percentRaw = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.percent;
617
+ 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';
449
618
  var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
450
619
  if (percentRaw === undefined || percentRaw === null) return title;
451
620
  if (cardType !== 'percent') return title;
@@ -453,10 +622,12 @@ function resolveDiscountTitleWithPercent(discount, locale) {
453
622
  return "".concat(title, " (").concat(percent, "%)");
454
623
  }
455
624
  function resolveDiscountTitle(discount, locale) {
456
- var _ref9, _ref10, _ref11, _ref12, _discount$discount$na, _discount$discount3, _discount$discount4, _discount$discount5;
457
- var title = getLocalizedValue((_ref9 = (_ref10 = (_ref11 = (_ref12 = (_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 && _ref12 !== void 0 ? _ref12 : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.message) !== null && _ref11 !== void 0 ? _ref11 : discount.name) !== null && _ref10 !== void 0 ? _ref10 : discount.title) !== null && _ref9 !== void 0 ? _ref9 : discount.message, locale);
625
+ var _ref19, _ref20, _ref21, _ref22, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
626
+ 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);
458
627
  if (title) return title;
459
- if (discount.type === 'product') return label(locale, 'manualDiscount');
628
+ if (discount.type === 'product') {
629
+ return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
630
+ }
460
631
  return '';
461
632
  }
462
633
  function resolveProductTitle(params) {
@@ -479,9 +650,10 @@ function normalizeProductOptions(params) {
479
650
  parentProduct = params.parentProduct;
480
651
  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 : [];
481
652
  return rawOptions.map(function (option) {
482
- var _ref13, _option$original_pric, _ref14, _option$value, _option$num;
483
- var price = (_ref13 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref13 !== void 0 ? _ref13 : option.price;
484
- var value = (_ref14 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref14 !== void 0 ? _ref14 : option.item;
653
+ var _ref23, _option$original_pric, _ref24, _option$num, _ref25, _option$value;
654
+ 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;
655
+ var quantity = toNumber((_ref24 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref24 !== void 0 ? _ref24 : 1, 1);
656
+ var value = (_ref25 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref25 !== void 0 ? _ref25 : option.item;
485
657
  var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
486
658
  option: option,
487
659
  parentProduct: parentProduct,
@@ -490,10 +662,12 @@ function normalizeProductOptions(params) {
490
662
  return _objectSpread(_objectSpread(_objectSpread({
491
663
  name: name
492
664
  }, option.num !== undefined || option.quantity !== undefined ? {
493
- num: toNumber((_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity, 1)
665
+ num: quantity
494
666
  } : {}), price !== undefined && price !== null && price !== '' ? {
495
667
  price: formatMoney(price, currencySymbol)
496
- } : {}), value !== undefined && value !== null && value !== '' ? {
668
+ } : {}), {}, {
669
+ total_price: formatCalculatedMoney(new Decimal(toMoneyNumber(price !== null && price !== void 0 ? price : 0)).mul(quantity), currencySymbol)
670
+ }, value !== undefined && value !== null && value !== '' ? {
497
671
  value: getLocalizedValue(value, locale)
498
672
  } : {});
499
673
  });
@@ -506,7 +680,7 @@ function normalizeProductCombinations(params) {
506
680
  parentProduct = params.parentProduct;
507
681
  var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
508
682
  return bundles.map(function (bundle) {
509
- var _ref15, _bundle$num;
683
+ var _ref26, _bundle$num;
510
684
  var combinationsOptions = normalizeProductOptions({
511
685
  product: {},
512
686
  locale: locale,
@@ -521,43 +695,146 @@ function normalizeProductCombinations(params) {
521
695
  parentProduct: parentProduct
522
696
  });
523
697
  var productNote = resolveProductNote(bundle, locale);
524
- var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
525
- return _objectSpread(_objectSpread({
698
+ var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
699
+ var quantity = toNumber((_ref26 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
700
+ var formattedPrice = formatBundlePrice(bundle, currencySymbol);
701
+ var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
702
+ var explicitBasePrice = resolveCombinationBasePrice(bundle);
703
+ var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
704
+ var extensionList = buildProductExtensionList({
705
+ product: bundle,
706
+ locale: locale,
707
+ currencySymbol: currencySymbol,
708
+ quantity: quantity,
709
+ originalPrice: formattedPrice
710
+ });
711
+ var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle, extensionList);
712
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
526
713
  product_title: baseTitle,
527
- product_quantity: toNumber((_ref15 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref15 !== void 0 ? _ref15 : 1, 1),
528
- price: formatBundlePrice(bundle, currencySymbol),
714
+ product_quantity: quantity,
715
+ price: formattedPrice,
716
+ total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol)
717
+ }, shouldIncludeBasePrice ? {
718
+ base_price: formatCalculatedMoney(basePrice, currencySymbol)
719
+ } : {}), {}, {
529
720
  combinations_options: combinationsOptions
530
- }, productNote ? {
721
+ }, combinationsOptions.length ? {
722
+ options_total_price: optionsTotal
723
+ } : {}), nestedCombinations.length ? {
724
+ package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
725
+ } : {}), productNote ? {
531
726
  product_note: productNote
727
+ } : {}), extensionList.length ? {
728
+ extension_list: extensionList
532
729
  } : {}), nestedCombinations.length ? {
533
730
  combinations: nestedCombinations
534
731
  } : {});
535
732
  });
536
733
  }
537
- function normalizeExistingCombinations(combinations, locale) {
734
+ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
538
735
  return combinations.map(function (combination) {
736
+ var _ref27, _ref28, _combination$product_, _firstPresentValue;
539
737
  if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
540
738
  return combination;
541
739
  }
542
740
  var productNote = resolveProductNote(combination, locale);
543
- var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale) : undefined;
741
+ var rawOptions = Array.isArray(combination.combinations_options) ? combination.combinations_options : Array.isArray(combination.options) ? combination.options : [];
742
+ var normalizedOptions = normalizeProductOptions({
743
+ product: {},
744
+ locale: locale,
745
+ currencySymbol: currencySymbol,
746
+ options: rawOptions
747
+ });
748
+ var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
544
749
  var snapshot = _objectSpread({}, combination);
545
750
  delete snapshot.product_note;
546
751
  delete snapshot.note;
547
- return _objectSpread(_objectSpread(_objectSpread({}, snapshot), productNote ? {
752
+ delete snapshot.combinations;
753
+ delete snapshot.discount_list;
754
+ 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);
755
+ var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
756
+ var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
757
+ return option.total_price;
758
+ }));
759
+ var explicitBasePrice = resolveCombinationBasePrice(combination, true);
760
+ var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
761
+ var extensionList = buildProductExtensionList({
762
+ product: combination,
763
+ locale: locale,
764
+ currencySymbol: currencySymbol,
765
+ quantity: quantity,
766
+ originalPrice: unitPrice
767
+ });
768
+ var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
769
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), {}, {
770
+ product_quantity: quantity,
771
+ total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
772
+ }, shouldIncludeBasePrice ? {
773
+ base_price: formatCalculatedMoney(basePrice, currencySymbol)
774
+ } : {}), Array.isArray(combination.combinations_options) ? {
775
+ combinations_options: normalizedOptions
776
+ } : Array.isArray(combination.options) ? {
777
+ options: normalizedOptions
778
+ } : {}), normalizedOptions.length ? {
779
+ options_total_price: formatCalculatedMoney(optionsAmount, currencySymbol)
780
+ } : {}), nestedCombinations.length ? {
781
+ package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
782
+ } : {}), productNote ? {
548
783
  product_note: productNote
549
- } : {}), nestedCombinations ? {
784
+ } : {}), extensionList.length ? {
785
+ extension_list: extensionList
786
+ } : {}), nestedCombinations.length ? {
550
787
  combinations: nestedCombinations
551
788
  } : {});
552
789
  });
553
790
  }
791
+ function sumMoneyValues(values) {
792
+ return values.reduce(function (sum, value) {
793
+ return sum.plus(toMoneyNumber(value));
794
+ }, new Decimal(0));
795
+ }
796
+ function resolveCombinationBasePrice(combination) {
797
+ var _combination$metadata;
798
+ var preferOriginalPrice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
799
+ var fallbackPrices = preferOriginalPrice ? [combination.original_price, combination.product_price, combination.price] : [combination.price, combination.original_price, combination.product_price];
800
+ 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));
801
+ }
802
+ function sumNormalizedOptionTotals(options, currencySymbol) {
803
+ return formatCalculatedMoney(sumMoneyValues(options.map(function (option) {
804
+ return option.total_price;
805
+ })), currencySymbol);
806
+ }
807
+ function sumCombinationTotals(combinations, currencySymbol) {
808
+ return formatCalculatedMoney(sumMoneyValues(combinations.map(function (combination) {
809
+ return combination.total_selling_price;
810
+ })), currencySymbol);
811
+ }
554
812
  function resolveProductNote(product, locale) {
555
813
  var productNote = getLocalizedValue(product.product_note, locale).trim();
556
814
  if (productNote) return productNote;
557
815
  return getLocalizedValue(product.note, locale).trim();
558
816
  }
817
+ function buildProductAllergyMap(order, locale) {
818
+ var allergyByProductUid = new Map();
819
+ for (var _i = 0, _normalizeArray = normalizeArray(order.notes); _i < _normalizeArray.length; _i++) {
820
+ var _note$content, _relation$target_uuid;
821
+ var note = _normalizeArray[_i];
822
+ if (!note || _typeof(note) !== 'object' || Array.isArray(note) || String(note.note_type || '').trim() !== 'allergy') {
823
+ continue;
824
+ }
825
+ var content = getLocalizedValue((_note$content = note.content) === null || _note$content === void 0 ? void 0 : _note$content.text, locale).trim();
826
+ if (!content) continue;
827
+ var relation = normalizeArray(note.note_relations).find(function (item) {
828
+ return item && _typeof(item) === 'object' && !Array.isArray(item) && item.relation_type === 'about' && item.target_type === 'order_detail' && Number(item.is_primary) === 1;
829
+ });
830
+ var productUid = String((_relation$target_uuid = relation === null || relation === void 0 ? void 0 : relation.target_uuid) !== null && _relation$target_uuid !== void 0 ? _relation$target_uuid : '').trim();
831
+ if (!productUid || allergyByProductUid.has(productUid)) continue;
832
+ allergyByProductUid.set(productUid, content);
833
+ }
834
+ return allergyByProductUid;
835
+ }
559
836
  function resolveBundleProductTitle(params) {
560
- var _ref16, _ref17, _bundle$bundle_produc;
837
+ var _ref29, _ref30, _bundle$bundle_produc;
561
838
  var bundle = params.bundle,
562
839
  productMap = params.productMap,
563
840
  locale = params.locale,
@@ -570,7 +847,7 @@ function resolveBundleProductTitle(params) {
570
847
  });
571
848
  var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
572
849
  if (parentBundleTitle) return parentBundleTitle;
573
- var productId = (_ref16 = (_ref17 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref17 !== void 0 ? _ref17 : bundle.product_id) !== null && _ref16 !== void 0 ? _ref16 : bundle.id;
850
+ 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;
574
851
  var fallbackProduct = resolveProductFromMap(productId, productMap);
575
852
  if (!fallbackProduct) return '';
576
853
  return getProductTitleSource(fallbackProduct, locale);
@@ -622,10 +899,10 @@ function resolveVariantTextFromSkuKey(params) {
622
899
  }
623
900
  function resolveVariantTextFromNameMap(params) {
624
901
  if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
625
- return Object.entries(params.nameMap).map(function (_ref18) {
626
- var _ref19 = _slicedToArray(_ref18, 2),
627
- groupPositionId = _ref19[0],
628
- value = _ref19[1];
902
+ return Object.entries(params.nameMap).map(function (_ref31) {
903
+ var _ref32 = _slicedToArray(_ref31, 2),
904
+ groupPositionId = _ref32[0],
905
+ value = _ref32[1];
629
906
  var group = resolveVariantGroup(params.parentProduct, groupPositionId);
630
907
  if (!group) return '';
631
908
  var groupName = getLocalizedValue(group.name, params.locale);
@@ -659,12 +936,12 @@ function getProductTitleSource(source, locale) {
659
936
  return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
660
937
  }
661
938
  function resolveTitleValue(value, locale) {
662
- var _ref20, _ref21, _ref22, _ref23, _value$locale;
939
+ var _ref33, _ref34, _ref35, _ref36, _value$locale;
663
940
  if (value === undefined || value === null) return '';
664
941
  if (_typeof(value) !== 'object') return stringify(value);
665
942
  var dashedLocale = locale.replace('_', '-');
666
943
  var underscoredLocale = locale.replace('-', '_');
667
- return stringify((_ref20 = (_ref21 = (_ref22 = (_ref23 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref23 !== void 0 ? _ref23 : value[underscoredLocale]) !== null && _ref22 !== void 0 ? _ref22 : value.original) !== null && _ref21 !== void 0 ? _ref21 : value.auto) !== null && _ref20 !== void 0 ? _ref20 : '');
944
+ 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 : '');
668
945
  }
669
946
  function resolveOptionTitleFromParentProduct(params) {
670
947
  var option = params.option,
@@ -682,17 +959,17 @@ function flattenOptionItems(parentProduct) {
682
959
  return optionGroups.flatMap(function (group) {
683
960
  var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
684
961
  return items.map(function (item) {
685
- var _ref24, _item$option_group_id;
962
+ var _ref37, _item$option_group_id;
686
963
  return _objectSpread(_objectSpread({}, item), {}, {
687
- option_group_id: (_ref24 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref24 !== void 0 ? _ref24 : group.option_group_id
964
+ 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
688
965
  });
689
966
  });
690
967
  });
691
968
  }
692
969
  function isOptionItemMatch(option, item) {
693
- var _ref25, _option$option_group_, _ref26, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
694
- var optionItemId = (_ref25 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref25 !== void 0 ? _ref25 : option.id;
695
- var itemId = (_ref26 = (_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 && _ref26 !== void 0 ? _ref26 : item.id;
970
+ var _ref38, _option$option_group_, _ref39, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
971
+ 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;
972
+ 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;
696
973
  if (!isSameId(optionItemId, itemId)) return false;
697
974
  var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
698
975
  var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
@@ -702,16 +979,16 @@ function isOptionItemMatch(option, item) {
702
979
  return true;
703
980
  }
704
981
  function resolveBundleItemFromParentProduct(params) {
705
- var _ref27, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref29, _bundle$bundle_produc2;
982
+ var _ref40, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref42, _bundle$bundle_produc2;
706
983
  var bundle = params.bundle,
707
984
  parentProduct = params.parentProduct;
708
985
  if (!parentProduct) return null;
709
986
  var bundleItems = flattenBundleItems(parentProduct);
710
- var bundleVariantId = (_ref27 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref27 !== void 0 ? _ref27 : bundle.product_variant_id;
987
+ 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;
711
988
  if (isNonZeroId(bundleVariantId)) {
712
989
  var matchedByVariant = bundleItems.find(function (item) {
713
- var _ref28, _item$bundle_variant_;
714
- return isSameId((_ref28 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref28 !== void 0 ? _ref28 : item.product_variant_id, bundleVariantId);
990
+ var _ref41, _item$bundle_variant_;
991
+ 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);
715
992
  });
716
993
  if (matchedByVariant) return matchedByVariant;
717
994
  }
@@ -724,18 +1001,18 @@ function resolveBundleItemFromParentProduct(params) {
724
1001
  if (matchedByBundleId) return matchedByBundleId;
725
1002
  }
726
1003
  var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
727
- var bundleProductId = (_ref29 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref29 !== void 0 ? _ref29 : bundle.product_id;
1004
+ 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;
728
1005
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
729
1006
  var matchedByGroupAndProduct = bundleItems.find(function (item) {
730
- var _item$group_id, _ref30, _item$bundle_product_;
731
- return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref30 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref30 !== void 0 ? _ref30 : item.product_id, bundleProductId);
1007
+ var _item$group_id, _ref43, _item$bundle_product_;
1008
+ 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);
732
1009
  });
733
1010
  if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
734
1011
  }
735
1012
  if (isPresentId(bundleProductId)) {
736
1013
  return bundleItems.find(function (item) {
737
- var _ref31, _item$bundle_product_2;
738
- return isSameId((_ref31 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref31 !== void 0 ? _ref31 : item.product_id, bundleProductId);
1014
+ var _ref44, _item$bundle_product_2;
1015
+ 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);
739
1016
  }) || null;
740
1017
  }
741
1018
  return null;
@@ -745,9 +1022,9 @@ function flattenBundleItems(parentProduct) {
745
1022
  return bundleGroups.flatMap(function (group) {
746
1023
  var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
747
1024
  return items.map(function (item) {
748
- var _ref32, _item$group_id2;
1025
+ var _ref45, _item$group_id2;
749
1026
  return _objectSpread(_objectSpread({}, item), {}, {
750
- group_id: (_ref32 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref32 !== void 0 ? _ref32 : group.group_id
1027
+ 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
751
1028
  });
752
1029
  });
753
1030
  });
@@ -771,8 +1048,8 @@ function isSameId(left, right) {
771
1048
  return String(left) === String(right);
772
1049
  }
773
1050
  function formatBundlePrice(bundle, currencySymbol) {
774
- var _ref33, _ref34, _bundle$bundle_sellin;
775
- var value = (_ref33 = (_ref34 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref34 !== void 0 ? _ref34 : bundle.price) !== null && _ref33 !== void 0 ? _ref33 : 0;
1051
+ var _ref46, _ref47, _bundle$bundle_sellin;
1052
+ 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;
776
1053
  var amount = new Decimal(toMoneyNumber(value));
777
1054
  // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
778
1055
  var isNegative = bundle.price_type === 'markdown';
@@ -780,7 +1057,7 @@ function formatBundlePrice(bundle, currencySymbol) {
780
1057
  return formatMoney(amount, currencySymbol);
781
1058
  }
782
1059
  function buildFees(params) {
783
- var _firstPresentValue, _firstPresentValue2;
1060
+ var _firstPresentValue2, _firstPresentValue3;
784
1061
  var order = params.order,
785
1062
  shopInfo = params.shopInfo,
786
1063
  locale = params.locale,
@@ -789,10 +1066,10 @@ function buildFees(params) {
789
1066
  currencySymbol = params.currencySymbol,
790
1067
  financials = params.financials;
791
1068
  var fees = [];
792
- for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
793
- var _ref35, _surcharge$amount;
794
- var surcharge = _normalizeArray[_i];
795
- var value = (_ref35 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref35 !== void 0 ? _ref35 : surcharge.total_amount;
1069
+ for (var _i2 = 0, _normalizeArray2 = normalizeArray(order.surcharges || summary.surcharges); _i2 < _normalizeArray2.length; _i2++) {
1070
+ var _ref48, _surcharge$amount;
1071
+ var surcharge = _normalizeArray2[_i2];
1072
+ var value = (_ref48 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref48 !== void 0 ? _ref48 : surcharge.total_amount;
796
1073
  if (!isNonZero(value)) continue;
797
1074
  fees.push({
798
1075
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
@@ -815,12 +1092,6 @@ function buildFees(params) {
815
1092
  });
816
1093
  var isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
817
1094
  var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
818
- if (isNonZero(roundingAmount)) {
819
- fees.push({
820
- item: label(locale, 'rounding'),
821
- value: formatMoney(roundingAmount, currencySymbol)
822
- });
823
- }
824
1095
  var payProcessingFee = financials.payProcessingFee;
825
1096
  if (isNonZero(payProcessingFee)) {
826
1097
  fees.push({
@@ -829,14 +1100,16 @@ function buildFees(params) {
829
1100
  });
830
1101
  }
831
1102
  var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
832
- var productOriginalAmount = (_firstPresentValue = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : calculateProductOriginalAmount(order);
1103
+ var productOriginalAmount = (_firstPresentValue2 = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : calculateProductOriginalAmount(order);
833
1104
  var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
1105
+ var itemDiscountAmount = new Decimal(toMoneyNumber(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0)).minus(toMoneyNumber(productOriginalAmount));
834
1106
  return {
835
1107
  fees: fees,
836
1108
  countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
837
- total_amount: formatMoney((_firstPresentValue2 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : 0, currencySymbol),
1109
+ total_amount: formatMoney((_firstPresentValue3 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0, currencySymbol),
838
1110
  original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
839
1111
  product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
1112
+ item_discount_amount: formatCalculatedMoney(itemDiscountAmount, currencySymbol),
840
1113
  expect_amount: formatMoney(financials.totalAmount, currencySymbol),
841
1114
  product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
842
1115
  return sum + product.product_quantity;
@@ -861,15 +1134,15 @@ function buildFees(params) {
861
1134
  };
862
1135
  }
863
1136
  function resolveReceiptFinancials(order, summary) {
864
- var _firstPresentValue3, _firstPresentValue4, _firstPresentValue5, _firstPresentValue6;
865
- var totalAmount = (_firstPresentValue3 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0;
1137
+ var _firstPresentValue4, _firstPresentValue5, _firstPresentValue6, _firstPresentValue7;
1138
+ var totalAmount = (_firstPresentValue4 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
866
1139
  var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
867
1140
  var payProcessingFee = rawPayProcessingFee !== null && rawPayProcessingFee !== void 0 ? rawPayProcessingFee : 0;
868
- var orderPaidAmount = (_firstPresentValue4 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
869
- var totalRefundAmount = (_firstPresentValue5 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
1141
+ var orderPaidAmount = (_firstPresentValue5 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
1142
+ var totalRefundAmount = (_firstPresentValue6 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
870
1143
  var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
871
1144
  var fallbackCustomerPaidAmount = Decimal.max(sumCustomerPaidPayments(order.payments), new Decimal(toMoneyNumber(orderPaidAmount)).plus(toMoneyNumber(payProcessingFee)));
872
- var customerPaidAmount = (_firstPresentValue6 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
1145
+ var customerPaidAmount = (_firstPresentValue7 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
873
1146
  var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
874
1147
  return {
875
1148
  totalAmount: totalAmount,
@@ -898,9 +1171,9 @@ function resolveTaxTitle(params) {
898
1171
  }
899
1172
  function calculateProductOriginalAmount(order) {
900
1173
  return normalizeArray(order.products).reduce(function (total, product) {
901
- var _ref36, _ref37, _product$product_quan2, _ref38, _ref39, _ref40, _product$original_pri2;
902
- var quantity = toNumber((_ref36 = (_ref37 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref37 !== void 0 ? _ref37 : product.num) !== null && _ref36 !== void 0 ? _ref36 : 1, 1);
903
- var originalPrice = (_ref38 = (_ref39 = (_ref40 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref40 !== void 0 ? _ref40 : product.payment_price) !== null && _ref39 !== void 0 ? _ref39 : product.price) !== null && _ref38 !== void 0 ? _ref38 : 0;
1174
+ var _ref49, _ref50, _product$product_quan2, _ref51, _ref52, _ref53, _product$original_pri2;
1175
+ 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);
1176
+ 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;
904
1177
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
905
1178
  }, new Decimal(0));
906
1179
  }
@@ -948,18 +1221,14 @@ function buildAppointment(order, locale) {
948
1221
  var _order$metadata13, _order$metadata14, _order$form_data;
949
1222
  var bookings = sortBookings(normalizeArray(order.bookings));
950
1223
  if (bookings.length) {
951
- return bookings.map(function (booking) {
952
- var _booking$metadata, _booking$metadata2;
953
- var snapshot = _objectSpread({}, booking);
954
- delete snapshot.product_uid;
955
- delete snapshot.booking_uid;
956
- var productUid = firstPresentValue(booking.product_uid, (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid);
957
- var bookingUid = firstPresentValue((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number, booking.booking_uid);
958
- return _objectSpread(_objectSpread(_objectSpread({}, snapshot), isPresentId(productUid) ? {
959
- product_uid: productUid
960
- } : {}), isPresentId(bookingUid) ? {
961
- booking_uid: bookingUid
962
- } : {});
1224
+ var allResources = normalizeArray(order.resources || order.resource_list);
1225
+ return bookings.flatMap(function (booking) {
1226
+ return buildAppointmentRows({
1227
+ booking: booking,
1228
+ allResources: allResources,
1229
+ bookingCount: bookings.length,
1230
+ locale: locale
1231
+ });
963
1232
  });
964
1233
  }
965
1234
  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);
@@ -969,6 +1238,104 @@ function buildAppointment(order, locale) {
969
1238
  value: getLocalizedValue(tableName, locale)
970
1239
  }];
971
1240
  }
1241
+ function buildAppointmentRows(params) {
1242
+ var _booking$metadata, _booking$metadata2, _booking$holder$name, _booking$holder, _booking$metadata3;
1243
+ var booking = params.booking,
1244
+ allResources = params.allResources,
1245
+ bookingCount = params.bookingCount,
1246
+ locale = params.locale;
1247
+ var productUid = stringify(firstPresentValue(booking.product_uid, (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid)).trim();
1248
+ var bookingUid = stringify(firstPresentValue((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number, booking.booking_uid)).trim();
1249
+ var association = {
1250
+ product_uid: productUid,
1251
+ booking_uid: bookingUid
1252
+ };
1253
+ var bookingId = stringify(firstPresentValue(booking.booking_id, booking.schedule_event_id, bookingUid)).trim();
1254
+ var bookingTime = formatBookingRange(booking, locale);
1255
+ var resourceText = formatBookingResources(resolveBookingResourcesForReceipt(booking, allResources, bookingCount), locale);
1256
+ 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();
1257
+ return [_objectSpread({
1258
+ item: label(locale, 'bookingId'),
1259
+ value: bookingId
1260
+ }, association), _objectSpread({
1261
+ item: label(locale, 'bookingDateTime'),
1262
+ value: bookingTime
1263
+ }, association), _objectSpread({
1264
+ item: label(locale, 'bookingResource'),
1265
+ value: resourceText
1266
+ }, association), _objectSpread({
1267
+ item: label(locale, 'bookingHolder'),
1268
+ value: holder
1269
+ }, association)].filter(function (row) {
1270
+ return Boolean(row.value);
1271
+ });
1272
+ }
1273
+ function formatBookingRange(booking, locale) {
1274
+ var startDate = stringify(booking.start_date);
1275
+ var startTime = stringify(booking.start_time);
1276
+ var endDate = stringify(booking.end_date || startDate);
1277
+ var endTime = stringify(booking.end_time);
1278
+ var start = firstValidBookingDate(booking.start_at, booking.start_datetime, booking.start_date_time, "".concat(startDate, " ").concat(startTime).trim());
1279
+ var end = firstValidBookingDate(booking.end_at, booking.end_datetime, booking.end_date_time, endTime ? "".concat(endDate, " ").concat(endTime).trim() : '');
1280
+ if (!start) {
1281
+ return [startDate, startTime, endTime ? "- ".concat(endDate, " ").concat(endTime) : ''].filter(Boolean).join(' ');
1282
+ }
1283
+ var dateFormat = locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD';
1284
+ var startText = start.format("".concat(dateFormat, " HH:mm"));
1285
+ if (!end) return startText;
1286
+ return "".concat(startText, " - ").concat(end.isSame(start, 'day') ? end.format('HH:mm') : end.format("".concat(dateFormat, " HH:mm")));
1287
+ }
1288
+ function firstValidBookingDate() {
1289
+ for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1290
+ values[_key2] = arguments[_key2];
1291
+ }
1292
+ for (var _i3 = 0, _values = values; _i3 < _values.length; _i3++) {
1293
+ var value = _values[_i3];
1294
+ if (!isPresentId(value)) continue;
1295
+ var parsed = dayjs(value);
1296
+ if (parsed.isValid()) return parsed;
1297
+ }
1298
+ return null;
1299
+ }
1300
+ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount) {
1301
+ var _booking$metadata4;
1302
+ var embedded = normalizeArray(booking.resources).filter(function (resource) {
1303
+ return Boolean(resource) && _typeof(resource) === 'object' && !Array.isArray(resource);
1304
+ });
1305
+ 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) {
1306
+ return stringify(value).trim();
1307
+ }).filter(Boolean));
1308
+ var _iterator3 = _createForOfIteratorHelper(embedded),
1309
+ _step3;
1310
+ try {
1311
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1312
+ var _ref55, _resource$id2;
1313
+ var resource = _step3.value;
1314
+ 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();
1315
+ if (id) resourceIds.add(id);
1316
+ }
1317
+ } catch (err) {
1318
+ _iterator3.e(err);
1319
+ } finally {
1320
+ _iterator3.f();
1321
+ }
1322
+ if (resourceIds.size) {
1323
+ var matched = allResources.filter(function (resource) {
1324
+ var _ref54, _resource$id;
1325
+ 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());
1326
+ });
1327
+ if (matched.length) return matched;
1328
+ }
1329
+ if (embedded.length) return embedded;
1330
+ if (bookingCount === 1 && allResources.length) return allResources;
1331
+ return [];
1332
+ }
1333
+ function formatBookingResources(resources, locale) {
1334
+ return resources.map(function (resource) {
1335
+ var _resource$metadata, _resource$metadata2, _resource$metadata3, _resource$metadata4;
1336
+ 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(' ');
1337
+ }).filter(Boolean).join(', ');
1338
+ }
972
1339
  function sortBookings(bookings) {
973
1340
  return bookings.map(function (booking, index) {
974
1341
  return {
@@ -980,23 +1347,23 @@ function sortBookings(bookings) {
980
1347
  var leftStart = bookingStartTimestamp(left.booking);
981
1348
  var rightStart = bookingStartTimestamp(right.booking);
982
1349
  if (leftStart !== rightStart) return leftStart < rightStart ? -1 : 1;
983
- for (var _i2 = 0, _arr = ['booking_id', 'schedule_event_id']; _i2 < _arr.length; _i2++) {
1350
+ for (var _i4 = 0, _arr = ['booking_id', 'schedule_event_id']; _i4 < _arr.length; _i4++) {
984
1351
  var _left$booking, _right$booking;
985
- var field = _arr[_i2];
1352
+ var field = _arr[_i4];
986
1353
  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]);
987
1354
  if (fieldOrder !== 0) return fieldOrder;
988
1355
  }
989
1356
  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));
990
1357
  return bookingUidOrder || left.index - right.index;
991
- }).map(function (_ref41) {
992
- var booking = _ref41.booking;
1358
+ }).map(function (_ref56) {
1359
+ var booking = _ref56.booking;
993
1360
  return booking;
994
1361
  });
995
1362
  }
996
1363
  function bookingStartTimestamp(booking) {
997
1364
  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];
998
- for (var _i3 = 0, _startValues = startValues; _i3 < _startValues.length; _i3++) {
999
- var startValue = _startValues[_i3];
1365
+ for (var _i5 = 0, _startValues = startValues; _i5 < _startValues.length; _i5++) {
1366
+ var startValue = _startValues[_i5];
1000
1367
  if (!isPresentId(startValue)) continue;
1001
1368
  var timestamp = dayjs(startValue).valueOf();
1002
1369
  if (Number.isFinite(timestamp)) return timestamp;
@@ -1032,7 +1399,9 @@ function buildPaymentData(params) {
1032
1399
  payment: payment,
1033
1400
  locale: params.locale,
1034
1401
  currencySymbol: params.currencySymbol,
1035
- includeFundRecordBalance: false
1402
+ includeFundRecordBalance: false,
1403
+ includeFundRecordUsage: true,
1404
+ includePaymentAmount: true
1036
1405
  });
1037
1406
  });
1038
1407
  }
@@ -1049,8 +1418,8 @@ function buildRefundData(params) {
1049
1418
  result.set(identity, candidate);
1050
1419
  }
1051
1420
  return result;
1052
- }, new Map()).values()).filter(function (_ref42) {
1053
- var refund = _ref42.refund;
1421
+ }, new Map()).values()).filter(function (_ref57) {
1422
+ var refund = _ref57.refund;
1054
1423
  return isPrintableRefund(refund);
1055
1424
  }).sort(function (left, right) {
1056
1425
  var leftTime = refundTimestamp(left.refund);
@@ -1058,12 +1427,12 @@ function buildRefundData(params) {
1058
1427
  if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1059
1428
  return left.index - right.index;
1060
1429
  });
1061
- return refunds.map(function (_ref43) {
1062
- var _firstPresentValue7;
1063
- var refund = _ref43.refund;
1430
+ return refunds.map(function (_ref58) {
1431
+ var _firstPresentValue8;
1432
+ var refund = _ref58.refund;
1064
1433
  var payment = resolveRefundPayment(refund, payments);
1065
1434
  var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
1066
- var amount = (_firstPresentValue7 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
1435
+ var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
1067
1436
  var items = [{
1068
1437
  item: methodName,
1069
1438
  value: formatNegativeMoney(amount, params.currencySymbol)
@@ -1120,32 +1489,112 @@ function resolveRefundPayment(refund, payments) {
1120
1489
  return matchedPayment || refund;
1121
1490
  }
1122
1491
  function buildWallets(params) {
1123
- var paymentWallets = normalizeArray(params.order.payments).filter(function (payment) {
1492
+ var displayedWalletPayments = normalizeArray(params.order.payments).filter(function (payment) {
1124
1493
  return isPrintablePayment(payment) && !!getFundRecord(payment);
1125
- }).map(function (payment) {
1494
+ });
1495
+ var paymentWallets = displayedWalletPayments.map(function (payment) {
1126
1496
  return buildPaymentItems({
1127
1497
  payment: payment,
1128
1498
  locale: params.locale,
1129
1499
  currencySymbol: params.currencySymbol,
1130
- includeFundRecordBalance: true
1500
+ includeFundRecordBalance: true,
1501
+ includeFundRecordUsage: false,
1502
+ includePaymentAmount: false
1131
1503
  });
1132
1504
  });
1133
- return [].concat(_toConsumableArray(paymentWallets), _toConsumableArray(buildVoucherAssets(params)));
1505
+ var displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
1506
+ return [].concat(_toConsumableArray(paymentWallets), _toConsumableArray(buildVoucherAssets(params)), _toConsumableArray(buildPointCardSnapshotAssets({
1507
+ order: params.order,
1508
+ locale: params.locale,
1509
+ displayedWalletPassIds: displayedWalletPassIds
1510
+ })));
1511
+ }
1512
+ function collectDisplayedWalletPassIds(payments) {
1513
+ var ids = new Set();
1514
+ payments.forEach(function (payment) {
1515
+ var fundRecord = getFundRecord(payment);
1516
+ [payment.voucher_id, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id].forEach(function (value) {
1517
+ var id = normalizeWalletPassId(value);
1518
+ if (id) ids.add(id);
1519
+ });
1520
+ });
1521
+ return ids;
1522
+ }
1523
+ function buildPointCardSnapshotAssets(params) {
1524
+ var _params$order$order_m;
1525
+ var snapshots = (_params$order$order_m = params.order.order_meta_list) === null || _params$order$order_m === void 0 ? void 0 : _params$order$order_m.point_cards_snapshot;
1526
+ if (!Array.isArray(snapshots)) return [];
1527
+ var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1528
+ var seenSnapshotIds = new Set();
1529
+ return snapshots.flatMap(function (snapshot) {
1530
+ if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return [];
1531
+ var pointCard = snapshot;
1532
+ if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
1533
+ var id = normalizeWalletPassId(pointCard.id);
1534
+ if (!id || seenSnapshotIds.has(id)) return [];
1535
+ seenSnapshotIds.add(id);
1536
+ if (params.displayedWalletPassIds.has(id)) return [];
1537
+ var rows = [{
1538
+ item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1539
+ value: ''
1540
+ }];
1541
+ var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
1542
+ if (remainingPoints) {
1543
+ rows.push({
1544
+ item: label(params.locale, 'remainingPoints'),
1545
+ value: trimDecimal(remainingPoints)
1546
+ });
1547
+ }
1548
+ if (isPresentId(snapshotTime)) {
1549
+ rows.push({
1550
+ item: formatDateTime(snapshotTime, params.locale),
1551
+ value: ''
1552
+ });
1553
+ }
1554
+ return [rows];
1555
+ });
1556
+ }
1557
+ function normalizeWalletPassId(value) {
1558
+ if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
1559
+ if (typeof value !== 'string') return null;
1560
+ return value.trim() || null;
1561
+ }
1562
+ function getPointCardSnapshotRemainingPoints(snapshot) {
1563
+ if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
1564
+ return null;
1565
+ }
1566
+ return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
1134
1567
  }
1135
1568
  function buildVoucherAssets(params) {
1136
1569
  var seenVoucherKeys = new Set();
1570
+ var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1137
1571
  return normalizeArray(params.order.vouchers).flatMap(function (voucher, index) {
1138
1572
  if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
1139
1573
  var voucherKey = getVoucherAssetKey(voucher, index);
1140
1574
  if (seenVoucherKeys.has(voucherKey)) return [];
1141
1575
  seenVoucherKeys.add(voucherKey);
1142
1576
  var name = getVoucherAssetName(voucher, params.locale);
1577
+ var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
1578
+ var timeRow = isPresentId(assetTime) ? {
1579
+ item: formatDateTime(assetTime, params.locale),
1580
+ value: ''
1581
+ } : null;
1582
+ if (isTicketVoucher(voucher)) {
1583
+ var validity = getVoucherValidity(voucher, params.locale);
1584
+ return [[{
1585
+ item: name,
1586
+ value: ''
1587
+ }].concat(_toConsumableArray(validity ? [{
1588
+ item: label(params.locale, 'validity'),
1589
+ value: validity
1590
+ }] : []))];
1591
+ }
1143
1592
  var percent = getVoucherDiscountPercent(voucher);
1144
1593
  if (percent) {
1145
1594
  return [[{
1146
1595
  item: appendPercentToVoucherName(name, percent),
1147
1596
  value: formatVoucherDiscount(percent, params.locale)
1148
- }]];
1597
+ }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1149
1598
  }
1150
1599
  var balance = getVoucherBalance(voucher);
1151
1600
  return [[{
@@ -1154,9 +1603,87 @@ function buildVoucherAssets(params) {
1154
1603
  }, {
1155
1604
  item: label(params.locale, 'balance'),
1156
1605
  value: formatMoney(balance, params.currencySymbol)
1157
- }]];
1606
+ }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1607
+ });
1608
+ }
1609
+ function isTicketVoucher(voucher) {
1610
+ return stringify(voucher.tag).trim().toLowerCase() === 'ticket';
1611
+ }
1612
+ function getVoucherValidity(voucher, locale) {
1613
+ 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;
1614
+ 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);
1615
+ var availableTimeText = formatVoucherAvailableTime(availableTime, locale);
1616
+ if (availableTimeText) return availableTimeText;
1617
+ 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);
1618
+ 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);
1619
+ return formatVoucherValidityRange(startDate, endDate, locale, {
1620
+ 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,
1621
+ 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
1158
1622
  });
1159
1623
  }
1624
+ function formatVoucherAvailableTime(value, locale) {
1625
+ if (!isPresentId(value)) return '';
1626
+ if (Array.isArray(value)) {
1627
+ return value.map(function (item) {
1628
+ return formatVoucherAvailableTime(item, locale);
1629
+ }).filter(Boolean).join(', ');
1630
+ }
1631
+ if (_typeof(value) !== 'object') return stringify(value).trim();
1632
+ var start = firstPresentValue(value.start, value.start_at, value.start_date_time, value.start_date);
1633
+ var end = firstPresentValue(value.end, value.end_at, value.end_date_time, value.expire_time, value.expire_date, value.end_date);
1634
+ if (isPresentId(start) || isPresentId(end)) {
1635
+ return formatVoucherValidityRange(start, end, locale, {
1636
+ startTime: value.start_time,
1637
+ endTime: value.end_time
1638
+ });
1639
+ }
1640
+ return getLocalizedValue(value, locale).trim();
1641
+ }
1642
+ function formatVoucherValidityRange(startValue, endValue, locale) {
1643
+ var times = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1644
+ var start = combineVoucherDateAndTime(startValue, times.startTime);
1645
+ var end = combineVoucherDateAndTime(endValue, times.endTime);
1646
+ var startPart = formatVoucherValidityDate(start, locale);
1647
+ var endPart = formatVoucherValidityDate(end, locale);
1648
+ if (startPart.text && endPart.text) {
1649
+ var parsedStart = dayjs(start);
1650
+ var parsedEnd = dayjs(end);
1651
+ var sameDay = parsedStart.isValid() && parsedEnd.isValid() && parsedStart.isSame(parsedEnd, 'day');
1652
+ if (sameDay && startPart.time && endPart.time) {
1653
+ return "".concat(startPart.time, " - ").concat(endPart.time, " ").concat(startPart.date);
1654
+ }
1655
+ return "".concat(startPart.text, " - ").concat(endPart.text);
1656
+ }
1657
+ return startPart.text || endPart.text;
1658
+ }
1659
+ function combineVoucherDateAndTime(dateValue, timeValue) {
1660
+ if (!isPresentId(dateValue) || !isPresentId(timeValue)) return dateValue;
1661
+ var dateText = stringify(dateValue).trim();
1662
+ if (/\d{1,2}:\d{2}/.test(dateText)) return dateValue;
1663
+ return "".concat(dateText, " ").concat(stringify(timeValue).trim());
1664
+ }
1665
+ function formatVoucherValidityDate(value, locale) {
1666
+ if (!isPresentId(value)) return {
1667
+ date: '',
1668
+ time: '',
1669
+ text: ''
1670
+ };
1671
+ var source = stringify(value).trim();
1672
+ var parsed = dayjs(source);
1673
+ if (!parsed.isValid()) return {
1674
+ date: '',
1675
+ time: '',
1676
+ text: source
1677
+ };
1678
+ var hasTime = /\d{1,2}:\d{2}/.test(source);
1679
+ var date = parsed.format(locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD');
1680
+ var time = hasTime ? parsed.format(/\d{1,2}:\d{2}:\d{2}/.test(source) ? 'HH:mm:ss' : 'HH:mm') : '';
1681
+ return {
1682
+ date: date,
1683
+ time: time,
1684
+ text: time ? "".concat(time, " ").concat(date) : date
1685
+ };
1686
+ }
1160
1687
  function getVoucherAssetKey(voucher, index) {
1161
1688
  var identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
1162
1689
  return identity === undefined ? "voucher-index:".concat(index) : "voucher:".concat(String(identity));
@@ -1165,8 +1692,8 @@ function getVoucherAssetName(voucher, locale) {
1165
1692
  return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
1166
1693
  }
1167
1694
  function getVoucherDiscountPercent(voucher) {
1168
- var _voucher$metadata;
1169
- var discountType = stringify(((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.discount_card_type) || voucher.discount_card_type).toLowerCase();
1695
+ var _voucher$metadata13;
1696
+ var discountType = stringify(((_voucher$metadata13 = voucher.metadata) === null || _voucher$metadata13 === void 0 ? void 0 : _voucher$metadata13.discount_card_type) || voucher.discount_card_type).toLowerCase();
1170
1697
  if (discountType !== 'percent' && discountType !== 'percentage') return null;
1171
1698
  var percent = new Decimal(toMoneyNumber(voucher.par_value));
1172
1699
  if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
@@ -1194,11 +1721,13 @@ function buildPaymentItems(params) {
1194
1721
  var payment = params.payment,
1195
1722
  locale = params.locale,
1196
1723
  currencySymbol = params.currencySymbol,
1197
- includeFundRecordBalance = params.includeFundRecordBalance;
1724
+ includeFundRecordBalance = params.includeFundRecordBalance,
1725
+ includeFundRecordUsage = params.includeFundRecordUsage,
1726
+ includePaymentAmount = params.includePaymentAmount;
1198
1727
  var serviceFee = getPaymentServiceFee(payment);
1199
1728
  var items = [{
1200
1729
  item: paymentMethodName(payment, locale),
1201
- value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
1730
+ value: includePaymentAmount ? formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol) : ''
1202
1731
  }];
1203
1732
  items.push.apply(items, _toConsumableArray(buildCashChangePaymentItems({
1204
1733
  payment: payment,
@@ -1218,11 +1747,12 @@ function buildPaymentItems(params) {
1218
1747
  fundRecord: fundRecord,
1219
1748
  locale: locale,
1220
1749
  currencySymbol: currencySymbol,
1221
- includeBalance: includeFundRecordBalance
1750
+ includeBalance: includeFundRecordBalance,
1751
+ includeUsage: includeFundRecordUsage
1222
1752
  })));
1223
1753
  } else {
1224
- var _ref44, _payment$remaining_am, _payment$metadata;
1225
- var remainingAmount = (_ref44 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref44 !== void 0 ? _ref44 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
1754
+ var _ref59, _payment$remaining_am, _payment$metadata;
1755
+ 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;
1226
1756
  if (remainingAmount !== undefined && remainingAmount !== null) {
1227
1757
  items.push({
1228
1758
  item: label(locale, 'remainingAmount'),
@@ -1282,16 +1812,19 @@ function buildFundRecordPaymentItems(params) {
1282
1812
  fundRecord = params.fundRecord,
1283
1813
  locale = params.locale,
1284
1814
  currencySymbol = params.currencySymbol,
1285
- includeBalance = params.includeBalance;
1815
+ includeBalance = params.includeBalance,
1816
+ includeUsage = params.includeUsage;
1286
1817
  var items = [];
1287
1818
  var usingBeforeValue = fundRecord.using_before_value;
1288
1819
  var usingAfterValue = fundRecord.using_after_value;
1289
1820
  if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
1290
1821
  var usedPoints = new Decimal(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
1291
- items.push({
1292
- item: label(locale, 'redeemPoints'),
1293
- value: trimDecimal(usedPoints)
1294
- });
1822
+ if (includeUsage) {
1823
+ items.push({
1824
+ item: label(locale, 'redeemPoints'),
1825
+ value: trimDecimal(usedPoints)
1826
+ });
1827
+ }
1295
1828
  if (includeBalance) {
1296
1829
  items.push({
1297
1830
  item: label(locale, 'remainingPoints'),
@@ -1302,7 +1835,7 @@ function buildFundRecordPaymentItems(params) {
1302
1835
  }
1303
1836
  if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
1304
1837
  items.push({
1305
- item: label(locale, 'remainingAmount'),
1838
+ item: label(locale, 'balance'),
1306
1839
  value: formatMoney(usingAfterValue, currencySymbol)
1307
1840
  });
1308
1841
  }
@@ -1373,12 +1906,12 @@ function label(locale, key) {
1373
1906
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
1374
1907
  }
1375
1908
  function getLocalizedValue(value, locale) {
1376
- var _ref45, _ref46, _ref47, _ref48, _ref49, _ref50, _value$locale2;
1909
+ var _ref60, _ref61, _ref62, _ref63, _ref64, _ref65, _value$locale2;
1377
1910
  if (value === undefined || value === null) return '';
1378
1911
  if (_typeof(value) !== 'object') return stringify(value);
1379
1912
  var dashedLocale = locale.replace('_', '-');
1380
1913
  var underscoredLocale = locale.replace('-', '_');
1381
- return stringify((_ref45 = (_ref46 = (_ref47 = (_ref48 = (_ref49 = (_ref50 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref50 !== void 0 ? _ref50 : value[underscoredLocale]) !== null && _ref49 !== void 0 ? _ref49 : value.original) !== null && _ref48 !== void 0 ? _ref48 : value.auto) !== null && _ref47 !== void 0 ? _ref47 : value.default) !== null && _ref46 !== void 0 ? _ref46 : value.en) !== null && _ref45 !== void 0 ? _ref45 : '');
1914
+ 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 : '');
1382
1915
  }
1383
1916
  function resolveServiceTypeLabelKey(serviceType, order) {
1384
1917
  var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
@@ -1420,6 +1953,11 @@ function formatMoney(value, currencySymbol) {
1420
1953
  var amount = new Decimal(toMoneyNumber(value));
1421
1954
  return "".concat(currencySymbol).concat(amount.toFixed(2));
1422
1955
  }
1956
+ function formatCalculatedMoney(value, currencySymbol) {
1957
+ var amount = new Decimal(toMoneyNumber(value));
1958
+ var sign = amount.isNegative() ? '-' : '';
1959
+ return "".concat(sign).concat(currencySymbol).concat(amount.abs().toFixed(2));
1960
+ }
1423
1961
  function formatNegativeMoney(value, currencySymbol) {
1424
1962
  var amount = new Decimal(toMoneyNumber(value)).abs();
1425
1963
  return "-".concat(currencySymbol).concat(amount.toFixed(2));