@pisell/pisellos 2.2.301 → 2.2.303

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 (152) hide show
  1. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  2. package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
  3. package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  4. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  5. package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
  6. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  7. package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
  8. package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
  9. package/dist/model/strategy/adapter/itemRule/type.js +19 -1
  10. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +10 -7
  11. package/dist/modules/Discount/index.d.ts +2 -0
  12. package/dist/modules/Discount/index.js +41 -5
  13. package/dist/modules/Discount/types.d.ts +21 -0
  14. package/dist/modules/OpenData/index.d.ts +15 -2
  15. package/dist/modules/OpenData/index.js +307 -19
  16. package/dist/modules/OpenData/types.d.ts +55 -0
  17. package/dist/modules/OpenData/types.js +7 -1
  18. package/dist/modules/OpenData/utils.d.ts +21 -1
  19. package/dist/modules/OpenData/utils.js +138 -0
  20. package/dist/modules/Order/index.d.ts +50 -7
  21. package/dist/modules/Order/index.js +1690 -815
  22. package/dist/modules/Order/salesNotes.d.ts +31 -0
  23. package/dist/modules/Order/salesNotes.js +492 -0
  24. package/dist/modules/Order/types.d.ts +117 -10
  25. package/dist/modules/Order/types.js +6 -1
  26. package/dist/modules/Order/utils/virtualSettlement.d.ts +63 -0
  27. package/dist/modules/Order/utils/virtualSettlement.js +284 -0
  28. package/dist/modules/Order/utils.d.ts +5 -1
  29. package/dist/modules/Order/utils.js +138 -33
  30. package/dist/modules/Payment/walletpass.js +20 -21
  31. package/dist/modules/Product/types.d.ts +23 -0
  32. package/dist/modules/ProductList/index.d.ts +2 -1
  33. package/dist/modules/ProductList/index.js +100 -20
  34. package/dist/modules/ProductList/types.d.ts +10 -0
  35. package/dist/modules/Rules/index.d.ts +5 -0
  36. package/dist/modules/Rules/index.js +30 -14
  37. package/dist/modules/SalesSummary/index.d.ts +1 -0
  38. package/dist/modules/SalesSummary/index.js +4 -3
  39. package/dist/modules/SalesSummary/types.d.ts +1 -0
  40. package/dist/modules/SalesSummary/utils.d.ts +1 -0
  41. package/dist/modules/SalesSummary/utils.js +21 -1
  42. package/dist/plugins/request.d.ts +2 -1
  43. package/dist/plugins/request.js +4 -2
  44. package/dist/server/index.d.ts +21 -0
  45. package/dist/server/index.js +1774 -1285
  46. package/dist/server/modules/order/types.d.ts +50 -0
  47. package/dist/server/modules/order/types.js +2 -0
  48. package/dist/server/utils/small-ticket.d.ts +4 -1
  49. package/dist/server/utils/small-ticket.js +461 -96
  50. package/dist/solution/BaseSales/index.d.ts +26 -3
  51. package/dist/solution/BaseSales/index.js +1492 -873
  52. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
  53. package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  54. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  55. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +72 -9
  56. package/dist/solution/BookingByStep/index.d.ts +1 -1
  57. package/dist/solution/BookingTicket/index.d.ts +8 -3
  58. package/dist/solution/BookingTicket/index.js +558 -443
  59. package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
  60. package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
  61. package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
  62. package/dist/solution/RegisterAndLogin/config.js +95 -40
  63. package/dist/solution/RegisterAndLogin/index.js +4 -1
  64. package/dist/solution/Sales/index.d.ts +16 -1
  65. package/dist/solution/Sales/index.js +338 -63
  66. package/dist/solution/Sales/types.d.ts +10 -0
  67. package/dist/solution/ScanOrder/index.d.ts +1 -0
  68. package/dist/solution/ScanOrder/index.js +31 -27
  69. package/dist/solution/ScanOrder/utils.d.ts +1 -0
  70. package/dist/solution/ScanOrder/utils.js +2 -0
  71. package/dist/solution/UnifiedBookingSales/index.d.ts +20 -6
  72. package/dist/solution/UnifiedBookingSales/index.js +874 -527
  73. package/dist/solution/UnifiedBookingSales/types.d.ts +21 -2
  74. package/dist/solution/VenueBooking/index.d.ts +1 -0
  75. package/dist/solution/VenueBooking/index.js +8 -4
  76. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  77. package/lib/model/strategy/adapter/dataVariant/evaluator.js +137 -6
  78. package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  79. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  80. package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
  81. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  82. package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
  83. package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
  84. package/lib/model/strategy/adapter/itemRule/type.js +19 -1
  85. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  86. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +4 -0
  87. package/lib/modules/Discount/index.d.ts +2 -0
  88. package/lib/modules/Discount/index.js +34 -2
  89. package/lib/modules/Discount/types.d.ts +21 -0
  90. package/lib/modules/OpenData/index.d.ts +15 -2
  91. package/lib/modules/OpenData/index.js +230 -3
  92. package/lib/modules/OpenData/types.d.ts +55 -0
  93. package/lib/modules/OpenData/types.js +9 -1
  94. package/lib/modules/OpenData/utils.d.ts +21 -1
  95. package/lib/modules/OpenData/utils.js +126 -0
  96. package/lib/modules/Order/index.d.ts +50 -7
  97. package/lib/modules/Order/index.js +704 -64
  98. package/lib/modules/Order/salesNotes.d.ts +31 -0
  99. package/lib/modules/Order/salesNotes.js +382 -0
  100. package/lib/modules/Order/types.d.ts +117 -10
  101. package/lib/modules/Order/types.js +5 -1
  102. package/lib/modules/Order/utils/virtualSettlement.d.ts +63 -0
  103. package/lib/modules/Order/utils/virtualSettlement.js +262 -0
  104. package/lib/modules/Order/utils.d.ts +5 -1
  105. package/lib/modules/Order/utils.js +127 -21
  106. package/lib/modules/Payment/walletpass.js +14 -11
  107. package/lib/modules/Product/types.d.ts +23 -0
  108. package/lib/modules/ProductList/index.d.ts +2 -1
  109. package/lib/modules/ProductList/index.js +47 -2
  110. package/lib/modules/ProductList/types.d.ts +10 -0
  111. package/lib/modules/Rules/index.d.ts +5 -0
  112. package/lib/modules/Rules/index.js +22 -12
  113. package/lib/modules/SalesSummary/index.d.ts +1 -0
  114. package/lib/modules/SalesSummary/index.js +4 -2
  115. package/lib/modules/SalesSummary/types.d.ts +1 -0
  116. package/lib/modules/SalesSummary/utils.d.ts +1 -0
  117. package/lib/modules/SalesSummary/utils.js +17 -1
  118. package/lib/plugins/request.d.ts +2 -1
  119. package/lib/plugins/request.js +3 -2
  120. package/lib/server/index.d.ts +21 -0
  121. package/lib/server/index.js +492 -108
  122. package/lib/server/modules/order/types.d.ts +50 -0
  123. package/lib/server/modules/order/types.js +1 -0
  124. package/lib/server/utils/small-ticket.d.ts +4 -1
  125. package/lib/server/utils/small-ticket.js +427 -72
  126. package/lib/solution/BaseSales/index.d.ts +26 -3
  127. package/lib/solution/BaseSales/index.js +439 -30
  128. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
  129. package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  130. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  131. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +38 -0
  132. package/lib/solution/BookingByStep/index.d.ts +1 -1
  133. package/lib/solution/BookingTicket/index.d.ts +8 -3
  134. package/lib/solution/BookingTicket/index.js +60 -15
  135. package/lib/solution/BookingTicket/utils/addProductDecision.js +1 -0
  136. package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
  137. package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
  138. package/lib/solution/RegisterAndLogin/config.js +49 -8
  139. package/lib/solution/RegisterAndLogin/index.js +4 -1
  140. package/lib/solution/Sales/index.d.ts +16 -1
  141. package/lib/solution/Sales/index.js +168 -1
  142. package/lib/solution/Sales/types.d.ts +10 -0
  143. package/lib/solution/ScanOrder/index.d.ts +1 -0
  144. package/lib/solution/ScanOrder/index.js +5 -1
  145. package/lib/solution/ScanOrder/utils.d.ts +1 -0
  146. package/lib/solution/ScanOrder/utils.js +1 -0
  147. package/lib/solution/UnifiedBookingSales/index.d.ts +20 -6
  148. package/lib/solution/UnifiedBookingSales/index.js +169 -16
  149. package/lib/solution/UnifiedBookingSales/types.d.ts +21 -2
  150. package/lib/solution/VenueBooking/index.d.ts +1 -0
  151. package/lib/solution/VenueBooking/index.js +5 -1
  152. package/package.json +1 -1
@@ -35,6 +35,7 @@ var LABELS = {
35
35
  eftpos: 'Eftpos',
36
36
  wallet: 'Wallet',
37
37
  giftCard: 'Gift card',
38
+ balance: 'Balance',
38
39
  remainingAmount: 'Remaining amount',
39
40
  redeemPoints: 'Redeem points',
40
41
  remainingPoints: 'Remaining points',
@@ -45,7 +46,9 @@ var LABELS = {
45
46
  surchargeIncluded: 'Surcharge(Included)',
46
47
  rounding: 'Rounding',
47
48
  gross: 'Gross',
48
- tare: 'Tare'
49
+ tare: 'Tare',
50
+ handoverTime: 'Handover time',
51
+ refund: 'Refund'
49
52
  },
50
53
  zh_CN: {
51
54
  contactName: '联系人姓名',
@@ -64,6 +67,7 @@ var LABELS = {
64
67
  eftpos: '刷卡支付',
65
68
  wallet: '钱包支付',
66
69
  giftCard: '礼品卡',
70
+ balance: '余额',
67
71
  remainingAmount: '剩余金额',
68
72
  redeemPoints: '本次使用积分',
69
73
  remainingPoints: '剩余积分',
@@ -74,7 +78,9 @@ var LABELS = {
74
78
  surchargeIncluded: '手续费(已含)',
75
79
  rounding: '抹零',
76
80
  gross: '重量',
77
- tare: '去皮'
81
+ tare: '去皮',
82
+ handoverTime: '交付时间',
83
+ refund: '退款'
78
84
  },
79
85
  zh_HK: {
80
86
  contactName: '聯絡人姓名',
@@ -93,6 +99,7 @@ var LABELS = {
93
99
  eftpos: '刷卡支付',
94
100
  wallet: '錢包支付',
95
101
  giftCard: '禮品卡',
102
+ balance: '餘額',
96
103
  remainingAmount: '剩餘金額',
97
104
  redeemPoints: '本次使用積分',
98
105
  remainingPoints: '剩餘積分',
@@ -103,13 +110,69 @@ var LABELS = {
103
110
  surchargeIncluded: '手續費(已含)',
104
111
  rounding: '抹零',
105
112
  gross: '重量',
106
- tare: '去皮'
113
+ tare: '去皮',
114
+ handoverTime: '交付時間',
115
+ refund: '退款'
107
116
  },
108
117
  ja: {
118
+ contactName: '連絡先名',
119
+ contactMobile: '連絡先電話',
120
+ email: 'メール',
121
+ dineIn: '店内飲食',
122
+ takeAway: 'テイクアウト',
123
+ delivery: '配達',
124
+ pickUp: '受け取り',
125
+ shopService: '店内飲食',
126
+ pickUpTime: '受取時間',
127
+ asap: 'できるだけ早く',
128
+ cash: '現金',
129
+ eftpos: 'カード',
130
+ wallet: 'ウォレット',
131
+ giftCard: 'ギフトカード',
132
+ balance: '残高',
133
+ remainingAmount: '残高',
134
+ redeemPoints: '利用ポイント',
135
+ remainingPoints: '残りポイント',
136
+ table: 'テーブル',
137
+ orderDiscount: '注文割引',
138
+ manualDiscount: '手動割引',
139
+ payProcessingFee: '決済手数料',
140
+ rounding: '端数調整',
141
+ gross: '総重量',
142
+ tare: '風袋',
143
+ handoverTime: '受け渡し時間',
144
+ refund: '返金',
109
145
  cashReceived: 'お預かり',
110
146
  changeDue: 'お釣り'
111
147
  },
112
148
  pt: {
149
+ contactName: 'Nome de contato',
150
+ contactMobile: 'Celular de contato',
151
+ email: 'e-mail',
152
+ dineIn: 'Consumo no local',
153
+ takeAway: 'Para levar',
154
+ delivery: 'Entrega',
155
+ pickUp: 'Recolha',
156
+ shopService: 'Consumo no local',
157
+ pickUpTime: 'Hora de recolha',
158
+ asap: 'Assim que possível',
159
+ cash: 'Dinheiro',
160
+ eftpos: 'Cartão',
161
+ wallet: 'Carteira',
162
+ giftCard: 'Cartão-presente',
163
+ balance: 'Saldo',
164
+ remainingAmount: 'Saldo restante',
165
+ redeemPoints: 'Pontos utilizados',
166
+ remainingPoints: 'Pontos restantes',
167
+ table: 'Mesa',
168
+ orderDiscount: 'Desconto do pedido',
169
+ manualDiscount: 'Desconto manual',
170
+ payProcessingFee: 'Taxa de processamento',
171
+ rounding: 'Arredondamento',
172
+ gross: 'Peso bruto',
173
+ tare: 'Tara',
174
+ handoverTime: 'Hora de entrega',
175
+ refund: 'Reembolso',
113
176
  cashReceived: 'Dinheiro recebido',
114
177
  changeDue: 'Troco'
115
178
  }
@@ -140,11 +203,15 @@ function buildLocaleData(params) {
140
203
  var products = buildProducts(order, locale, productMap);
141
204
  var summary = getSummary(order);
142
205
  var currencySymbol = getCurrencySymbol(order, shopInfo);
143
- return {
206
+ var financials = resolveReceiptFinancials(order, summary);
207
+ var delivery = buildDelivery(order, locale);
208
+ return _objectSpread(_objectSpread({
144
209
  base_data: buildBaseData({
145
210
  order: order,
146
211
  shopInfo: shopInfo,
147
- locale: locale
212
+ locale: locale,
213
+ currencySymbol: currencySymbol,
214
+ financials: financials
148
215
  }),
149
216
  products: products,
150
217
  fees: buildFees({
@@ -153,11 +220,14 @@ function buildLocaleData(params) {
153
220
  locale: locale,
154
221
  products: products,
155
222
  summary: summary,
156
- currencySymbol: currencySymbol
223
+ currencySymbol: currencySymbol,
224
+ financials: financials
157
225
  }),
158
226
  customer: buildCustomer(order, locale),
159
- appointment: buildAppointment(order, locale),
160
- // delivery: buildDelivery(order, locale),
227
+ appointment: buildAppointment(order, locale)
228
+ }, delivery.length ? {
229
+ delivery: delivery
230
+ } : {}), {}, {
161
231
  resources: buildResources(order, locale),
162
232
  payment_data: buildPaymentData({
163
233
  order: order,
@@ -171,17 +241,23 @@ function buildLocaleData(params) {
171
241
  }),
172
242
  tickets: Array.isArray(order.tickets) ? order.tickets : [],
173
243
  source_shop: [],
174
- refund_data: [],
244
+ refund_data: buildRefundData({
245
+ order: order,
246
+ locale: locale,
247
+ currencySymbol: currencySymbol
248
+ }),
175
249
  expend_data: []
176
- };
250
+ });
177
251
  }
178
252
  function buildBaseData(params) {
179
253
  var _order$metadata;
180
254
  var order = params.order,
181
255
  shopInfo = params.shopInfo,
182
- locale = params.locale;
256
+ locale = params.locale,
257
+ currencySymbol = params.currencySymbol,
258
+ financials = params.financials;
183
259
  var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
184
- return _objectSpread({
260
+ return _objectSpread(_objectSpread({
185
261
  shop_name: stringify(shopInfo.name || order.shop_name),
186
262
  note: stringify(order.note),
187
263
  shop_order_number: stringify(order.shop_order_number),
@@ -189,7 +265,13 @@ function buildBaseData(params) {
189
265
  shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
190
266
  shop_phone: stringify(shopInfo.phone || order.shop_phone),
191
267
  shop_address: stringify(shopInfo.receipt_address || shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
192
- original_payment_status: stringify(order.payment_status),
268
+ original_payment_status: financials.paymentStatus,
269
+ payment_status: financials.paymentStatus,
270
+ 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
+ } : {}), {}, {
193
275
  is_repeat: 0,
194
276
  buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
195
277
  order_no: orderNumber,
@@ -239,28 +321,46 @@ function buildProducts(order, locale, productMap) {
239
321
  quantity: quantity,
240
322
  originalPrice: originalPrice
241
323
  });
242
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
324
+ var productNote = resolveProductNote(product, locale);
325
+ var basePrice = resolveProductBasePrice(product);
326
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
243
327
  product_title: productTitle,
244
328
  product_quantity: quantity,
245
329
  selling_price: formatMoney(sellingPrice, currencySymbol),
246
- original_price: formatMoney(originalPrice, currencySymbol),
330
+ original_price: formatMoney(originalPrice, currencySymbol)
331
+ }, isPresentId(basePrice) ? {
332
+ base_price: formatMoney(basePrice, currencySymbol)
333
+ } : {}), {}, {
247
334
  total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
248
335
  extension_list: extensionList
249
336
  }, isPresentId(productUid) ? {
250
337
  product_uid: productUid
251
338
  } : {}), isPresentId(bookingUid) ? {
252
339
  booking_uid: bookingUid
340
+ } : {}), productNote ? {
341
+ product_note: productNote
253
342
  } : {}), options.length ? {
254
343
  options: options
255
344
  } : {}), resolvedVariant ? {
256
345
  variant: resolvedVariant
257
- } : {}), Array.isArray(product.combinations) ? {
258
- combinations: product.combinations
346
+ } : {}), Array.isArray(product.combinations) && product.combinations.length ? {
347
+ combinations: normalizeExistingCombinations(product.combinations, locale)
259
348
  } : combinations.length ? {
260
349
  combinations: combinations
261
350
  } : {});
262
351
  });
263
352
  }
353
+ function resolveProductBasePrice(product) {
354
+ var _product$product_vari, _product$_origin, _product$_origin2;
355
+ var metadata = product.metadata || {};
356
+ var origin = product._origin || metadata.origin || {};
357
+ var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
358
+ var variant = Array.isArray(origin.variant) && isPresentId(variantId) ? origin.variant.find(function (item) {
359
+ return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
360
+ }) : undefined;
361
+ var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
362
+ return firstPresentValue(metadata.source_product_price, variant === null || variant === void 0 ? void 0 : variant.price, (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.price, (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
363
+ }
264
364
  function normalizeProductDiscounts(params) {
265
365
  var product = params.product,
266
366
  locale = params.locale,
@@ -420,15 +520,42 @@ function normalizeProductCombinations(params) {
420
520
  locale: locale,
421
521
  parentProduct: parentProduct
422
522
  });
423
- var optionTitle = buildOptionTitleSuffix(combinationsOptions);
424
- return {
425
- product_title: "".concat(baseTitle).concat(optionTitle),
523
+ var productNote = resolveProductNote(bundle, locale);
524
+ var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
525
+ return _objectSpread(_objectSpread({
526
+ product_title: baseTitle,
426
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),
427
528
  price: formatBundlePrice(bundle, currencySymbol),
428
529
  combinations_options: combinationsOptions
429
- };
530
+ }, productNote ? {
531
+ product_note: productNote
532
+ } : {}), nestedCombinations.length ? {
533
+ combinations: nestedCombinations
534
+ } : {});
430
535
  });
431
536
  }
537
+ function normalizeExistingCombinations(combinations, locale) {
538
+ return combinations.map(function (combination) {
539
+ if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
540
+ return combination;
541
+ }
542
+ var productNote = resolveProductNote(combination, locale);
543
+ var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale) : undefined;
544
+ var snapshot = _objectSpread({}, combination);
545
+ delete snapshot.product_note;
546
+ delete snapshot.note;
547
+ return _objectSpread(_objectSpread(_objectSpread({}, snapshot), productNote ? {
548
+ product_note: productNote
549
+ } : {}), nestedCombinations ? {
550
+ combinations: nestedCombinations
551
+ } : {});
552
+ });
553
+ }
554
+ function resolveProductNote(product, locale) {
555
+ var productNote = getLocalizedValue(product.product_note, locale).trim();
556
+ if (productNote) return productNote;
557
+ return getLocalizedValue(product.note, locale).trim();
558
+ }
432
559
  function resolveBundleProductTitle(params) {
433
560
  var _ref16, _ref17, _bundle$bundle_produc;
434
561
  var bundle = params.bundle,
@@ -453,13 +580,13 @@ function resolveProductFromMap(productId, productMap) {
453
580
  return productMap[productId] || productMap[String(productId)] || null;
454
581
  }
455
582
  function resolveProductVariantText(params) {
456
- var _product$product_vari;
583
+ var _product$product_vari2;
457
584
  var product = params.product,
458
585
  parentProduct = params.parentProduct,
459
586
  locale = params.locale;
460
587
  if (product.variant) return getLocalizedValue(product.variant, locale);
461
588
  if (!parentProduct) return '';
462
- var productVariantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
589
+ var productVariantId = (_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : product.variant_id;
463
590
  if (!isNonZeroId(productVariantId)) return '';
464
591
  var matchedVariant = normalizeArray(parentProduct.variant).find(function (variant) {
465
592
  return isSameId(variant.id, productVariantId);
@@ -643,16 +770,6 @@ function isSameId(left, right) {
643
770
  if (!isPresentId(left) || !isPresentId(right)) return false;
644
771
  return String(left) === String(right);
645
772
  }
646
- function buildOptionTitleSuffix(options) {
647
- var text = options.map(function (option) {
648
- var _option$num2;
649
- var name = stringify(option.name).trim();
650
- if (!name) return '';
651
- var quantity = (_option$num2 = option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1;
652
- return "".concat(name, " x ").concat(quantity);
653
- }).filter(Boolean).join(', ');
654
- return text ? "(".concat(text, ")") : '';
655
- }
656
773
  function formatBundlePrice(bundle, currencySymbol) {
657
774
  var _ref33, _ref34, _bundle$bundle_sellin;
658
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;
@@ -663,13 +780,14 @@ function formatBundlePrice(bundle, currencySymbol) {
663
780
  return formatMoney(amount, currencySymbol);
664
781
  }
665
782
  function buildFees(params) {
666
- var _ref36, _order$shop_discount, _firstPresentValue;
783
+ var _firstPresentValue, _firstPresentValue2;
667
784
  var order = params.order,
668
785
  shopInfo = params.shopInfo,
669
786
  locale = params.locale,
670
787
  products = params.products,
671
788
  summary = params.summary,
672
- currencySymbol = params.currencySymbol;
789
+ currencySymbol = params.currencySymbol,
790
+ financials = params.financials;
673
791
  var fees = [];
674
792
  for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
675
793
  var _ref35, _surcharge$amount;
@@ -681,67 +799,108 @@ function buildFees(params) {
681
799
  value: formatMoney(value, currencySymbol)
682
800
  });
683
801
  }
684
- var discountAmount = (_ref36 = (_order$shop_discount = order.shop_discount) !== null && _order$shop_discount !== void 0 ? _order$shop_discount : summary.discount_amount) !== null && _ref36 !== void 0 ? _ref36 : order.discount_amount;
802
+ var discountAmount = firstPresentValue(order.shop_discount, summary.discount_amount, order.discount_amount);
685
803
  if (isNonZero(discountAmount)) {
686
804
  fees.push({
687
805
  item: label(locale, 'orderDiscount'),
688
806
  value: formatNegativeMoney(discountAmount, currencySymbol)
689
807
  });
690
808
  }
691
- var taxFee = summary.tax_fee || order.tax_fee;
692
- if (isNonZero(taxFee)) {
693
- fees.push({
694
- item: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
695
- value: formatMoney(taxFee, currencySymbol)
696
- });
697
- }
698
- var roundingAmount = summary.rounding_amount || order.rounding_amount;
809
+ var taxFee = firstPresentValue(summary.tax_fee, order.tax_fee);
810
+ var taxTitle = resolveTaxTitle({
811
+ summary: summary,
812
+ order: order,
813
+ shopInfo: shopInfo,
814
+ locale: locale
815
+ });
816
+ var isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
817
+ var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
699
818
  if (isNonZero(roundingAmount)) {
700
819
  fees.push({
701
820
  item: label(locale, 'rounding'),
702
821
  value: formatMoney(roundingAmount, currencySymbol)
703
822
  });
704
823
  }
705
- var payProcessingFee = summary.pay_service_charge_amount || order.pay_service_charge_amount;
824
+ var payProcessingFee = financials.payProcessingFee;
706
825
  if (isNonZero(payProcessingFee)) {
707
826
  fees.push({
708
827
  item: label(locale, 'payProcessingFee'),
709
828
  value: formatMoney(payProcessingFee, currencySymbol)
710
829
  });
711
830
  }
712
- var productExpectAmount = summary.product_expect_amount || summary.product_amount || order.product_expect_amount;
831
+ var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
713
832
  var productOriginalAmount = (_firstPresentValue = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : calculateProductOriginalAmount(order);
714
833
  var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
715
834
  return {
716
835
  fees: fees,
717
- countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
718
- total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
836
+ 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),
719
838
  original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
720
- product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
721
- expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
722
- product_quantity: toNumber(summary.product_quantity || products.reduce(function (sum, product) {
839
+ product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
840
+ expect_amount: formatMoney(financials.totalAmount, currencySymbol),
841
+ product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
723
842
  return sum + product.product_quantity;
724
- }, 0), 0),
725
- has_pay: formatMoney(calculateReceiptPaidAmount(order, summary), currencySymbol),
843
+ }, 0)), 0),
844
+ has_pay: formatMoney(financials.orderPaidAmount, currencySymbol),
726
845
  payment_method: '',
727
- tax_title: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
728
- total_refund_amount: formatMoney(summary.total_refund_amount || order.total_refund_amount, currencySymbol)
729
- }, isNonZero(roundingAmount) ? {
846
+ tax_title: taxTitle,
847
+ total_refund_amount: formatMoney(financials.totalRefundAmount, currencySymbol),
848
+ customer_paid_amount: formatMoney(financials.customerPaidAmount, currencySymbol),
849
+ net_payment_applied: formatMoney(financials.netPaymentApplied, currencySymbol)
850
+ }, isPresentId(roundingAmount) ? {
730
851
  rounding_amount: formatMoney(roundingAmount, currencySymbol)
731
852
  } : {}), isNonZero(totalSavingsAmount) ? {
732
853
  order_total_discount: formatMoney(totalSavingsAmount, currencySymbol)
733
- } : {}), isNonZero(payProcessingFee) ? {
854
+ } : {}), financials.hasPayProcessingFee ? {
734
855
  pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
735
- } : {}), isNonZero(taxFee) ? {
856
+ } : {}), isPresentId(taxFee) ? {
736
857
  tax_fee: formatMoney(taxFee, currencySymbol)
858
+ } : {}), isPresentId(isPriceIncludeTax) ? {
859
+ is_price_include_tax: normalizeBooleanFlag(isPriceIncludeTax)
737
860
  } : {})
738
861
  };
739
862
  }
863
+ 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;
866
+ var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
867
+ 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;
870
+ var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
871
+ 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;
873
+ var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
874
+ return {
875
+ totalAmount: totalAmount,
876
+ orderPaidAmount: orderPaidAmount,
877
+ payProcessingFee: payProcessingFee,
878
+ customerPaidAmount: customerPaidAmount,
879
+ totalRefundAmount: totalRefundAmount,
880
+ netPaymentApplied: netPaymentApplied,
881
+ amountGap: amountGap,
882
+ paymentStatus: resolveReceiptPaymentStatus({
883
+ order: order,
884
+ summary: summary
885
+ }),
886
+ hasPayProcessingFee: isPresentId(rawPayProcessingFee)
887
+ };
888
+ }
889
+ function resolveReceiptPaymentStatus(params) {
890
+ return [params.order.payment_status, params.summary.payment_status, params.order.original_payment_status].map(function (status) {
891
+ return stringify(status).trim();
892
+ }).find(Boolean) || '';
893
+ }
894
+ function resolveTaxTitle(params) {
895
+ return [params.summary.tax_title, params.order.tax_title, params.shopInfo.tax_title].map(function (title) {
896
+ return getLocalizedValue(title, params.locale).trim();
897
+ }).find(Boolean) || 'Tax';
898
+ }
740
899
  function calculateProductOriginalAmount(order) {
741
900
  return normalizeArray(order.products).reduce(function (total, product) {
742
- var _ref37, _ref38, _product$product_quan2, _ref39, _ref40, _ref41, _product$original_pri2;
743
- var quantity = toNumber((_ref37 = (_ref38 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref38 !== void 0 ? _ref38 : product.num) !== null && _ref37 !== void 0 ? _ref37 : 1, 1);
744
- var originalPrice = (_ref39 = (_ref40 = (_ref41 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref41 !== void 0 ? _ref41 : product.payment_price) !== null && _ref40 !== void 0 ? _ref40 : product.price) !== null && _ref39 !== void 0 ? _ref39 : 0;
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;
745
904
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
746
905
  }, new Decimal(0));
747
906
  }
@@ -765,27 +924,29 @@ function normalizeCustomerDisplayValue(value) {
765
924
  return text;
766
925
  }
767
926
  function buildDelivery(order, locale) {
768
- var _order$metadata2;
769
- var serviceType = stringify(((_order$metadata2 = order.metadata) === null || _order$metadata2 === void 0 ? void 0 : _order$metadata2.service_type) || order.service_type || order.delivery_type);
770
- if (!serviceType) return [];
771
- var serviceTypeLabelKey = serviceTypeToLabelKey(serviceType);
927
+ var _order$metadata2, _order$metadata3, _order$metadata4, _order$metadata5, _order$metadata6, _order$metadata7, _order$metadata8, _order$metadata9, _order$metadata10, _order$metadata11, _order$metadata12;
928
+ var deliveryType = stringify(order.delivery_type).trim();
929
+ var serviceType = deliveryType || stringify(firstPresentValue((_order$metadata2 = order.metadata) === null || _order$metadata2 === void 0 ? void 0 : _order$metadata2.service_type, order.service_type)).trim();
930
+ var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType, order);
931
+ if (!serviceTypeLabelKey) return [];
772
932
  var items = [{
773
933
  item: '',
774
934
  value: label(locale, serviceTypeLabelKey),
775
935
  size: 2,
776
936
  align: 'left'
777
937
  }];
778
- if (serviceType === 'shop_server' || serviceType === 'shop_service') {
938
+ var handoverTime = firstPresentValue(order.handover_time, order.handover_at, order.pickup_time, order.pickup_at, order.scheduled_pickup_time, order.delivery_time, order.delivery_at, order.scheduled_delivery_time, order.fulfillment_time, order.fulfillment_at, (_order$metadata3 = order.metadata) === null || _order$metadata3 === void 0 ? void 0 : _order$metadata3.handover_time, (_order$metadata4 = order.metadata) === null || _order$metadata4 === void 0 ? void 0 : _order$metadata4.handover_at, (_order$metadata5 = order.metadata) === null || _order$metadata5 === void 0 ? void 0 : _order$metadata5.pickup_time, (_order$metadata6 = order.metadata) === null || _order$metadata6 === void 0 ? void 0 : _order$metadata6.pickup_at, (_order$metadata7 = order.metadata) === null || _order$metadata7 === void 0 ? void 0 : _order$metadata7.scheduled_pickup_time, (_order$metadata8 = order.metadata) === null || _order$metadata8 === void 0 ? void 0 : _order$metadata8.delivery_time, (_order$metadata9 = order.metadata) === null || _order$metadata9 === void 0 ? void 0 : _order$metadata9.delivery_at, (_order$metadata10 = order.metadata) === null || _order$metadata10 === void 0 ? void 0 : _order$metadata10.scheduled_delivery_time, (_order$metadata11 = order.metadata) === null || _order$metadata11 === void 0 ? void 0 : _order$metadata11.fulfillment_time, (_order$metadata12 = order.metadata) === null || _order$metadata12 === void 0 ? void 0 : _order$metadata12.fulfillment_at);
939
+ if (isPresentId(handoverTime)) {
779
940
  items.push({
780
- item: label(locale, 'pickUpTime'),
781
- value: label(locale, 'asap')
941
+ item: label(locale, 'handoverTime'),
942
+ value: formatDateTime(handoverTime, locale)
782
943
  });
783
944
  }
784
945
  return items;
785
946
  }
786
947
  function buildAppointment(order, locale) {
787
- var _order$metadata3, _order$metadata4, _order$form_data;
788
- var bookings = normalizeArray(order.bookings);
948
+ var _order$metadata13, _order$metadata14, _order$form_data;
949
+ var bookings = sortBookings(normalizeArray(order.bookings));
789
950
  if (bookings.length) {
790
951
  return bookings.map(function (booking) {
791
952
  var _booking$metadata, _booking$metadata2;
@@ -801,13 +962,57 @@ function buildAppointment(order, locale) {
801
962
  } : {});
802
963
  });
803
964
  }
804
- var tableName = order.table_name || ((_order$metadata3 = order.metadata) === null || _order$metadata3 === void 0 ? void 0 : _order$metadata3.table_name) || ((_order$metadata4 = order.metadata) === null || _order$metadata4 === void 0 || (_order$metadata4 = _order$metadata4.table) === null || _order$metadata4 === void 0 ? void 0 : _order$metadata4.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
965
+ 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);
805
966
  if (!tableName) return [];
806
967
  return [{
807
968
  item: label(locale, 'table'),
808
969
  value: getLocalizedValue(tableName, locale)
809
970
  }];
810
971
  }
972
+ function sortBookings(bookings) {
973
+ return bookings.map(function (booking, index) {
974
+ return {
975
+ booking: booking,
976
+ index: index
977
+ };
978
+ }).sort(function (left, right) {
979
+ var _left$booking2, _left$booking3, _right$booking2, _right$booking3;
980
+ var leftStart = bookingStartTimestamp(left.booking);
981
+ var rightStart = bookingStartTimestamp(right.booking);
982
+ if (leftStart !== rightStart) return leftStart < rightStart ? -1 : 1;
983
+ for (var _i2 = 0, _arr = ['booking_id', 'schedule_event_id']; _i2 < _arr.length; _i2++) {
984
+ var _left$booking, _right$booking;
985
+ var field = _arr[_i2];
986
+ 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
+ if (fieldOrder !== 0) return fieldOrder;
988
+ }
989
+ 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
+ return bookingUidOrder || left.index - right.index;
991
+ }).map(function (_ref41) {
992
+ var booking = _ref41.booking;
993
+ return booking;
994
+ });
995
+ }
996
+ function bookingStartTimestamp(booking) {
997
+ 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];
1000
+ if (!isPresentId(startValue)) continue;
1001
+ var timestamp = dayjs(startValue).valueOf();
1002
+ if (Number.isFinite(timestamp)) return timestamp;
1003
+ }
1004
+ return Number.POSITIVE_INFINITY;
1005
+ }
1006
+ function compareOptionalValues(left, right) {
1007
+ var hasLeft = isPresentId(left);
1008
+ var hasRight = isPresentId(right);
1009
+ if (!hasLeft && !hasRight) return 0;
1010
+ if (!hasLeft) return 1;
1011
+ if (!hasRight) return -1;
1012
+ return String(left).localeCompare(String(right), undefined, {
1013
+ numeric: true
1014
+ });
1015
+ }
811
1016
  function buildResources(order, locale) {
812
1017
  return normalizeArray(order.resources || order.resource_list).map(function (resource) {
813
1018
  return {
@@ -831,8 +1036,91 @@ function buildPaymentData(params) {
831
1036
  });
832
1037
  });
833
1038
  }
1039
+ function buildRefundData(params) {
1040
+ var payments = normalizeArray(params.order.payments);
1041
+ var refunds = Array.from(normalizeArray(params.order.refunds).reduce(function (result, refund, index) {
1042
+ var identity = refundIdentity(refund, index);
1043
+ var candidate = {
1044
+ refund: refund,
1045
+ index: index
1046
+ };
1047
+ var existing = result.get(identity);
1048
+ if (!existing || shouldPreferRefundCandidate(candidate, existing)) {
1049
+ result.set(identity, candidate);
1050
+ }
1051
+ return result;
1052
+ }, new Map()).values()).filter(function (_ref42) {
1053
+ var refund = _ref42.refund;
1054
+ return isPrintableRefund(refund);
1055
+ }).sort(function (left, right) {
1056
+ var leftTime = refundTimestamp(left.refund);
1057
+ var rightTime = refundTimestamp(right.refund);
1058
+ if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1059
+ return left.index - right.index;
1060
+ });
1061
+ return refunds.map(function (_ref43) {
1062
+ var _firstPresentValue7;
1063
+ var refund = _ref43.refund;
1064
+ var payment = resolveRefundPayment(refund, payments);
1065
+ 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;
1067
+ var items = [{
1068
+ item: methodName,
1069
+ value: formatNegativeMoney(amount, params.currencySymbol)
1070
+ }];
1071
+ var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
1072
+ if (isPresentId(occurredAt)) {
1073
+ items.push({
1074
+ item: formatDateTime(occurredAt, params.locale),
1075
+ value: ''
1076
+ });
1077
+ }
1078
+ return items;
1079
+ });
1080
+ }
1081
+ function refundIdentity(refund, index) {
1082
+ if (isPresentId(refund.order_refund_id)) return "refund-id:".concat(refund.order_refund_id);
1083
+ if (isPresentId(refund.refund_number)) return "refund-number:".concat(refund.refund_number);
1084
+ return "refund-index:".concat(index);
1085
+ }
1086
+ function shouldPreferRefundCandidate(candidate, existing) {
1087
+ var candidatePrintable = isPrintableRefund(candidate.refund);
1088
+ var existingPrintable = isPrintableRefund(existing.refund);
1089
+ if (candidatePrintable !== existingPrintable) return candidatePrintable;
1090
+ var candidateTime = refundFreshnessTimestamp(candidate.refund);
1091
+ var existingTime = refundFreshnessTimestamp(existing.refund);
1092
+ if (candidateTime !== existingTime) return candidateTime > existingTime;
1093
+ return candidate.index > existing.index;
1094
+ }
1095
+ function refundFreshnessTimestamp(refund) {
1096
+ var timestampValue = firstPresentValue(refund.updated_at, refund.refunded_at, refund.refund_time, refund.created_at);
1097
+ if (!isPresentId(timestampValue)) return Number.NEGATIVE_INFINITY;
1098
+ var timestamp = dayjs(timestampValue).valueOf();
1099
+ return Number.isFinite(timestamp) ? timestamp : Number.NEGATIVE_INFINITY;
1100
+ }
1101
+ function refundTimestamp(refund) {
1102
+ var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
1103
+ if (!isPresentId(occurredAt)) return Number.POSITIVE_INFINITY;
1104
+ var timestamp = dayjs(occurredAt).valueOf();
1105
+ return Number.isFinite(timestamp) ? timestamp : Number.POSITIVE_INFINITY;
1106
+ }
1107
+ function isPrintableRefund(refund) {
1108
+ var status = stringify(refund.status).trim().toLowerCase();
1109
+ if (!status) return true;
1110
+ return !['pending', 'payment_pending', 'payment_processing', 'refund_processing', 'processing', 'failed', 'error', 'cancelled', 'canceled', 'voided'].includes(status);
1111
+ }
1112
+ function resolveRefundPayment(refund, payments) {
1113
+ if (refund.payment && _typeof(refund.payment) === 'object' && !Array.isArray(refund.payment)) {
1114
+ return refund.payment;
1115
+ }
1116
+ var orderPaymentId = firstPresentValue(refund.order_payment_id, refund.payment_id);
1117
+ var matchedPayment = payments.find(function (payment) {
1118
+ return isSameId(firstPresentValue(payment.order_payment_id, payment.id), orderPaymentId);
1119
+ });
1120
+ return matchedPayment || refund;
1121
+ }
834
1122
  function buildWallets(params) {
835
- return normalizeArray(params.order.payments).filter(function (payment) {
1123
+ var paymentWallets = normalizeArray(params.order.payments).filter(function (payment) {
836
1124
  return isPrintablePayment(payment) && !!getFundRecord(payment);
837
1125
  }).map(function (payment) {
838
1126
  return buildPaymentItems({
@@ -842,6 +1130,65 @@ function buildWallets(params) {
842
1130
  includeFundRecordBalance: true
843
1131
  });
844
1132
  });
1133
+ return [].concat(_toConsumableArray(paymentWallets), _toConsumableArray(buildVoucherAssets(params)));
1134
+ }
1135
+ function buildVoucherAssets(params) {
1136
+ var seenVoucherKeys = new Set();
1137
+ return normalizeArray(params.order.vouchers).flatMap(function (voucher, index) {
1138
+ if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
1139
+ var voucherKey = getVoucherAssetKey(voucher, index);
1140
+ if (seenVoucherKeys.has(voucherKey)) return [];
1141
+ seenVoucherKeys.add(voucherKey);
1142
+ var name = getVoucherAssetName(voucher, params.locale);
1143
+ var percent = getVoucherDiscountPercent(voucher);
1144
+ if (percent) {
1145
+ return [[{
1146
+ item: appendPercentToVoucherName(name, percent),
1147
+ value: formatVoucherDiscount(percent, params.locale)
1148
+ }]];
1149
+ }
1150
+ var balance = getVoucherBalance(voucher);
1151
+ return [[{
1152
+ item: name,
1153
+ value: ''
1154
+ }, {
1155
+ item: label(params.locale, 'balance'),
1156
+ value: formatMoney(balance, params.currencySymbol)
1157
+ }]];
1158
+ });
1159
+ }
1160
+ function getVoucherAssetKey(voucher, index) {
1161
+ var identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
1162
+ return identity === undefined ? "voucher-index:".concat(index) : "voucher:".concat(String(identity));
1163
+ }
1164
+ function getVoucherAssetName(voucher, locale) {
1165
+ return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
1166
+ }
1167
+ 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();
1170
+ if (discountType !== 'percent' && discountType !== 'percentage') return null;
1171
+ var percent = new Decimal(toMoneyNumber(voucher.par_value));
1172
+ if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
1173
+ return percent;
1174
+ }
1175
+ function appendPercentToVoucherName(name, percent) {
1176
+ if (/\d+(?:\.\d+)?\s*(?:%|折)|\boff\b/i.test(name)) return name;
1177
+ var separator = /^(?:[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FD-\u30FF\u31F0-\u31FF\u32D0-\u32FE\u3300-\u3357\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFA6D\uFA70-\uFAD9\uFF66-\uFF6F\uFF71-\uFF9D]|\uD81B[\uDFE2\uDFE3\uDFF0\uDFF1]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67]|\uD83C\uDE00|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])/.test(name) ? '' : ' ';
1178
+ return "".concat(trimDecimal(percent), "%").concat(separator).concat(name);
1179
+ }
1180
+ function formatVoucherDiscount(percent, locale) {
1181
+ var normalizedLocale = normalizeLocaleKey(locale);
1182
+ if (normalizedLocale === 'zh_CN' || normalizedLocale === 'zh_HK') {
1183
+ return "".concat(trimDecimal(percent), "% OFF");
1184
+ }
1185
+ if (normalizedLocale === 'pt') return "Desconto ".concat(trimDecimal(percent), "%");
1186
+ return normalizedLocale === 'en' ? "Discount ".concat(trimDecimal(percent), "% OFF") : "".concat(trimDecimal(percent), "% OFF");
1187
+ }
1188
+ function getVoucherBalance(voucher) {
1189
+ var parValue = new Decimal(toMoneyNumber(voucher.par_value));
1190
+ var usedParValue = new Decimal(toMoneyNumber(voucher.used_par_value));
1191
+ return Decimal.max(parValue.minus(usedParValue), 0);
845
1192
  }
846
1193
  function buildPaymentItems(params) {
847
1194
  var payment = params.payment,
@@ -874,8 +1221,8 @@ function buildPaymentItems(params) {
874
1221
  includeBalance: includeFundRecordBalance
875
1222
  })));
876
1223
  } else {
877
- var _ref42, _payment$remaining_am, _payment$metadata;
878
- var remainingAmount = (_ref42 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref42 !== void 0 ? _ref42 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
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;
879
1226
  if (remainingAmount !== undefined && remainingAmount !== null) {
880
1227
  items.push({
881
1228
  item: label(locale, 'remainingAmount'),
@@ -1026,20 +1373,37 @@ function label(locale, key) {
1026
1373
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
1027
1374
  }
1028
1375
  function getLocalizedValue(value, locale) {
1029
- var _ref43, _ref44, _ref45, _ref46, _ref47, _ref48, _value$locale2;
1376
+ var _ref45, _ref46, _ref47, _ref48, _ref49, _ref50, _value$locale2;
1030
1377
  if (value === undefined || value === null) return '';
1031
1378
  if (_typeof(value) !== 'object') return stringify(value);
1032
1379
  var dashedLocale = locale.replace('_', '-');
1033
1380
  var underscoredLocale = locale.replace('-', '_');
1034
- return stringify((_ref43 = (_ref44 = (_ref45 = (_ref46 = (_ref47 = (_ref48 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref48 !== void 0 ? _ref48 : value[underscoredLocale]) !== null && _ref47 !== void 0 ? _ref47 : value.original) !== null && _ref46 !== void 0 ? _ref46 : value.auto) !== null && _ref45 !== void 0 ? _ref45 : value.default) !== null && _ref44 !== void 0 ? _ref44 : value.en) !== null && _ref43 !== void 0 ? _ref43 : '');
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 : '');
1382
+ }
1383
+ function resolveServiceTypeLabelKey(serviceType, order) {
1384
+ var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
1385
+ if (['', 'nil', 'none', 'unknown'].includes(normalized)) return null;
1386
+ if (['pickup', 'pick_up', 'self_pickup'].includes(normalized)) return 'pickUp';
1387
+ if (['delivery', 'shipping', 'local_delivery'].includes(normalized)) return 'delivery';
1388
+ if (['takeaway', 'take_away'].includes(normalized)) return 'takeAway';
1389
+ if (['dine_in', 'dinein'].includes(normalized)) return 'dineIn';
1390
+ if (['shop_service', 'shop_server'].includes(normalized)) {
1391
+ return resolveShopServiceLabelKey(order);
1392
+ }
1393
+ return null;
1394
+ }
1395
+ function resolveShopServiceLabelKey(order) {
1396
+ var _order$metadata15, _order$shop_service_t;
1397
+ var rawShopServiceType = firstPresentValue((_order$metadata15 = order.metadata) === null || _order$metadata15 === void 0 || (_order$metadata15 = _order$metadata15.shop_service_type) === null || _order$metadata15 === void 0 ? void 0 : _order$metadata15.server_type, (_order$shop_service_t = order.shop_service_type) === null || _order$shop_service_t === void 0 ? void 0 : _order$shop_service_t.server_type, typeof order.shop_service_type === 'string' ? order.shop_service_type : undefined);
1398
+ if (!isPresentId(rawShopServiceType)) return 'dineIn';
1399
+ var normalized = stringify(rawShopServiceType).trim().toLowerCase().replace(/[\s-]+/g, '_');
1400
+ if (['takeaway', 'take_away'].includes(normalized)) return 'takeAway';
1401
+ if (['dine_in', 'dinein'].includes(normalized)) return 'dineIn';
1402
+ return null;
1035
1403
  }
1036
- function serviceTypeToLabelKey(serviceType) {
1037
- var normalized = serviceType.toLowerCase();
1038
- if (normalized.includes('take')) return 'takeAway';
1039
- if (normalized.includes('delivery')) return 'delivery';
1040
- if (normalized.includes('pick')) return 'pickUp';
1041
- if (normalized.includes('shop')) return 'shopService';
1042
- return 'dineIn';
1404
+ function normalizeBooleanFlag(value) {
1405
+ if (value === true || value === 1 || stringify(value).trim() === '1') return 1;
1406
+ return 0;
1043
1407
  }
1044
1408
  function buildShopAddress(shopInfo) {
1045
1409
  return [shopInfo.address_street, shopInfo.address_detail, shopInfo.city, shopInfo.province, shopInfo.country, shopInfo.zip].filter(Boolean).join(', ');
@@ -1060,18 +1424,19 @@ function formatNegativeMoney(value, currencySymbol) {
1060
1424
  var amount = new Decimal(toMoneyNumber(value)).abs();
1061
1425
  return "-".concat(currencySymbol).concat(amount.toFixed(2));
1062
1426
  }
1063
- function calculateReceiptPaidAmount(order, summary) {
1064
- var _summary$pay_service_, _summary$total_amount;
1065
- var paidAmount = sumPayments(order.payments);
1066
- var payProcessingFee = new Decimal(toMoneyNumber((_summary$pay_service_ = summary.pay_service_charge_amount) !== null && _summary$pay_service_ !== void 0 ? _summary$pay_service_ : order.pay_service_charge_amount));
1067
- if (payProcessingFee.lte(0)) return paidAmount;
1068
- var totalAmount = new Decimal(toMoneyNumber((_summary$total_amount = summary.total_amount) !== null && _summary$total_amount !== void 0 ? _summary$total_amount : order.total_amount));
1069
- if (totalAmount.gt(0) && paidAmount.gte(totalAmount)) return paidAmount;
1070
- var paidAmountWithFee = paidAmount.plus(payProcessingFee);
1071
- if (totalAmount.gt(0) && paidAmountWithFee.gt(totalAmount)) return totalAmount;
1072
- return paidAmountWithFee;
1073
- }
1074
- function sumPayments(payments) {
1427
+ function sumAppliedPayments(payments) {
1428
+ return normalizeArray(payments).filter(function (payment) {
1429
+ return isPrintablePayment(payment);
1430
+ }).reduce(function (sum, payment) {
1431
+ if (isPresentId(payment.origin_amount)) {
1432
+ return sum.plus(toMoneyNumber(payment.origin_amount));
1433
+ }
1434
+ var amount = new Decimal(toMoneyNumber(payment.amount));
1435
+ var serviceFee = Decimal.max(toMoneyNumber(payment.service_fee), 0);
1436
+ return sum.plus(Decimal.max(amount.minus(serviceFee), 0));
1437
+ }, new Decimal(0));
1438
+ }
1439
+ function sumCustomerPaidPayments(payments) {
1075
1440
  return normalizeArray(payments).filter(function (payment) {
1076
1441
  return isPrintablePayment(payment);
1077
1442
  }).reduce(function (sum, payment) {
@@ -1082,7 +1447,7 @@ function sumPayments(payments) {
1082
1447
  function isPrintablePayment(payment) {
1083
1448
  var status = stringify(payment.status).toLowerCase();
1084
1449
  if (!status) return true;
1085
- return ['paid', 'success', 'succeeded', 'completed'].includes(status);
1450
+ return ['paid', 'success', 'succeeded', 'completed', 'partially_refunded', 'refunded'].includes(status);
1086
1451
  }
1087
1452
  function normalizeArray(value) {
1088
1453
  return Array.isArray(value) ? value : [];