@pisell/pisellos 2.2.204 → 2.2.206

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 (68) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/OpenData/index.d.ts +1 -0
  3. package/dist/modules/OpenData/index.js +21 -16
  4. package/dist/modules/Order/index.d.ts +9 -0
  5. package/dist/modules/Order/index.js +237 -146
  6. package/dist/modules/Order/types.d.ts +10 -0
  7. package/dist/modules/Order/utils.js +7 -5
  8. package/dist/modules/Payment/index.d.ts +0 -13
  9. package/dist/modules/Payment/index.js +449 -833
  10. package/dist/plugins/request.d.ts +1 -0
  11. package/dist/server/index.d.ts +142 -0
  12. package/dist/server/index.js +2208 -824
  13. package/dist/server/modules/index.d.ts +2 -0
  14. package/dist/server/modules/index.js +2 -0
  15. package/dist/server/modules/order/index.d.ts +7 -0
  16. package/dist/server/modules/order/index.js +375 -337
  17. package/dist/server/modules/order/types.d.ts +15 -0
  18. package/dist/server/modules/order/types.js +8 -0
  19. package/dist/server/modules/payment/index.d.ts +28 -0
  20. package/dist/server/modules/payment/index.js +305 -0
  21. package/dist/server/modules/payment/types.d.ts +9 -0
  22. package/dist/server/modules/payment/types.js +1 -0
  23. package/dist/server/utils/small-ticket.d.ts +69 -0
  24. package/dist/server/utils/small-ticket.js +528 -0
  25. package/dist/solution/BaseSales/index.d.ts +10 -3
  26. package/dist/solution/BaseSales/index.js +307 -198
  27. package/dist/solution/BookingByStep/index.d.ts +1 -1
  28. package/dist/solution/BookingTicket/index.d.ts +8 -1
  29. package/dist/solution/BookingTicket/index.js +444 -264
  30. package/dist/solution/BookingTicket/types.d.ts +2 -1
  31. package/dist/solution/BookingTicket/types.js +3 -1
  32. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +51 -52
  33. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  34. package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
  35. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  36. package/lib/modules/OpenData/index.d.ts +1 -0
  37. package/lib/modules/OpenData/index.js +6 -4
  38. package/lib/modules/Order/index.d.ts +9 -0
  39. package/lib/modules/Order/index.js +64 -4
  40. package/lib/modules/Order/types.d.ts +10 -0
  41. package/lib/modules/Order/utils.js +4 -3
  42. package/lib/modules/Payment/index.d.ts +0 -13
  43. package/lib/modules/Payment/index.js +6 -149
  44. package/lib/plugins/request.d.ts +1 -0
  45. package/lib/server/index.d.ts +142 -0
  46. package/lib/server/index.js +867 -49
  47. package/lib/server/modules/index.d.ts +2 -0
  48. package/lib/server/modules/index.js +3 -0
  49. package/lib/server/modules/order/index.d.ts +7 -0
  50. package/lib/server/modules/order/index.js +21 -7
  51. package/lib/server/modules/order/types.d.ts +15 -0
  52. package/lib/server/modules/payment/index.d.ts +28 -0
  53. package/lib/server/modules/payment/index.js +192 -0
  54. package/lib/server/modules/payment/types.d.ts +9 -0
  55. package/lib/server/modules/payment/types.js +17 -0
  56. package/lib/server/utils/small-ticket.d.ts +69 -0
  57. package/lib/server/utils/small-ticket.js +555 -0
  58. package/lib/solution/BaseSales/index.d.ts +10 -3
  59. package/lib/solution/BaseSales/index.js +98 -6
  60. package/lib/solution/BookingByStep/index.d.ts +1 -1
  61. package/lib/solution/BookingTicket/index.d.ts +8 -1
  62. package/lib/solution/BookingTicket/index.js +109 -2
  63. package/lib/solution/BookingTicket/types.d.ts +2 -1
  64. package/lib/solution/BookingTicket/types.js +5 -0
  65. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +1 -2
  66. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  67. package/lib/solution/BookingTicket/utils/scan/index.js +17 -3
  68. package/package.json +1 -1
@@ -0,0 +1,528 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ 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."); }
3
+ 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); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ 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; }
7
+ 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; }
8
+ 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; }
9
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
11
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
13
+ import dayjs from 'dayjs';
14
+ import Decimal from 'decimal.js';
15
+ var DEFAULT_LOCALES = ['en', 'zh_CN'];
16
+ var LABELS = {
17
+ en: {
18
+ contactName: 'Contact name',
19
+ contactMobile: 'Contact Mobile',
20
+ email: 'email',
21
+ dineIn: 'Dine-in',
22
+ takeAway: 'Take away',
23
+ delivery: 'Delivery',
24
+ pickUp: 'Pick-up',
25
+ shopService: 'Dine-in',
26
+ pickUpTime: 'Pick-up time',
27
+ asap: 'ASAP',
28
+ cash: 'Cash',
29
+ eftpos: 'Eftpos',
30
+ wallet: 'Wallet',
31
+ giftCard: 'Gift card',
32
+ remainingAmount: 'Remaining amount',
33
+ redeemPoints: 'Redeem points',
34
+ remainingPoints: 'Remaining points',
35
+ table: 'Table',
36
+ orderDiscount: 'Order discount',
37
+ payProcessingFee: 'Pay processing fee',
38
+ rounding: 'Rounding'
39
+ },
40
+ zh_CN: {
41
+ contactName: '联系人姓名',
42
+ contactMobile: '联系电话',
43
+ email: '邮箱',
44
+ dineIn: '堂食',
45
+ takeAway: '外带',
46
+ delivery: '配送',
47
+ pickUp: '自提',
48
+ shopService: '堂食',
49
+ pickUpTime: '取餐时间',
50
+ asap: '尽快',
51
+ cash: '现金支付',
52
+ eftpos: '刷卡支付',
53
+ wallet: '钱包支付',
54
+ giftCard: '礼品卡',
55
+ remainingAmount: '剩余金额',
56
+ redeemPoints: '本次使用积分',
57
+ remainingPoints: '剩余积分',
58
+ table: '桌台',
59
+ orderDiscount: '整单折扣',
60
+ payProcessingFee: '支付手续费',
61
+ rounding: '抹零'
62
+ },
63
+ zh_HK: {
64
+ contactName: '聯絡人姓名',
65
+ contactMobile: '聯絡電話',
66
+ email: '電郵',
67
+ dineIn: '堂食',
68
+ takeAway: '外帶',
69
+ delivery: '配送',
70
+ pickUp: '自取',
71
+ shopService: '堂食',
72
+ pickUpTime: '取餐時間',
73
+ asap: '盡快',
74
+ cash: '現金支付',
75
+ eftpos: '刷卡支付',
76
+ wallet: '錢包支付',
77
+ giftCard: '禮品卡',
78
+ remainingAmount: '剩餘金額',
79
+ redeemPoints: '本次使用積分',
80
+ remainingPoints: '剩餘積分',
81
+ table: '桌台',
82
+ orderDiscount: '整單折扣',
83
+ payProcessingFee: '支付手續費',
84
+ rounding: '抹零'
85
+ }
86
+ };
87
+ export function buildSmallTicketData(params) {
88
+ var order = params.order || {};
89
+ var shopInfo = params.shopInfo || {};
90
+ var locales = resolveLocales(shopInfo, params.locales);
91
+ var productMap = params.productMap || {};
92
+ return locales.reduce(function (data, locale) {
93
+ data[locale] = buildLocaleData({
94
+ order: order,
95
+ shopInfo: shopInfo,
96
+ locale: locale,
97
+ productMap: productMap
98
+ });
99
+ return data;
100
+ }, {});
101
+ }
102
+ export function hasSmallTicketData(value) {
103
+ return !!value && _typeof(value) === 'object' && Object.keys(value).length > 0;
104
+ }
105
+ function buildLocaleData(params) {
106
+ var order = params.order,
107
+ shopInfo = params.shopInfo,
108
+ locale = params.locale,
109
+ productMap = params.productMap;
110
+ var products = buildProducts(order, locale, productMap);
111
+ var summary = getSummary(order);
112
+ var currencySymbol = getCurrencySymbol(order, shopInfo);
113
+ return {
114
+ base_data: buildBaseData({
115
+ order: order,
116
+ shopInfo: shopInfo,
117
+ locale: locale
118
+ }),
119
+ products: products,
120
+ fees: buildFees({
121
+ order: order,
122
+ shopInfo: shopInfo,
123
+ locale: locale,
124
+ products: products,
125
+ summary: summary,
126
+ currencySymbol: currencySymbol
127
+ }),
128
+ customer: buildCustomer(order, locale),
129
+ appointment: buildAppointment(order, locale),
130
+ delivery: buildDelivery(order, locale),
131
+ resources: buildResources(order, locale),
132
+ payment_data: buildPaymentData({
133
+ order: order,
134
+ locale: locale,
135
+ currencySymbol: currencySymbol
136
+ }),
137
+ tickets: Array.isArray(order.tickets) ? order.tickets : [],
138
+ source_shop: [],
139
+ refund_data: [],
140
+ expend_data: []
141
+ };
142
+ }
143
+ function buildBaseData(params) {
144
+ var _order$metadata;
145
+ var order = params.order,
146
+ shopInfo = params.shopInfo,
147
+ locale = params.locale;
148
+ var orderNumber = stringify(order.order_number || order.shop_full_order_number || order.shop_order_number || order.external_sale_number);
149
+ return {
150
+ shop_name: stringify(shopInfo.name || order.shop_name),
151
+ note: stringify(order.note),
152
+ shop_order_number: stringify(order.shop_order_number),
153
+ order_number: orderNumber,
154
+ shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
155
+ shop_phone: stringify(shopInfo.phone || order.shop_phone),
156
+ shop_address: stringify(shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
157
+ original_payment_status: stringify(order.payment_status),
158
+ is_repeat: 0,
159
+ buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
160
+ order_no: orderNumber,
161
+ order_time: formatDateTime(order.created_at || order.sales_time || new Date(), locale)
162
+ };
163
+ }
164
+ function buildProducts(order, locale, productMap) {
165
+ var products = Array.isArray(order.products) ? order.products : [];
166
+ return products.map(function (product) {
167
+ var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric;
168
+ 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);
169
+ 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;
170
+ 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;
171
+ var productTitle = resolveProductTitle({
172
+ product: product,
173
+ productMap: productMap,
174
+ locale: locale
175
+ });
176
+ return _objectSpread(_objectSpread(_objectSpread({
177
+ product_title: productTitle,
178
+ product_quantity: quantity,
179
+ selling_price: formatMoney(sellingPrice, getCurrencySymbol(order, null)),
180
+ original_price: formatMoney(originalPrice, getCurrencySymbol(order, null)),
181
+ total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), getCurrencySymbol(order, null)),
182
+ extension_list: Array.isArray(product.extension_list) ? product.extension_list : []
183
+ }, Array.isArray(product.options) ? {
184
+ options: product.options.map(function (option) {
185
+ return {
186
+ name: getLocalizedValue(option.name || option.title, locale),
187
+ value: getLocalizedValue(option.value || option.option || option.item, locale)
188
+ };
189
+ })
190
+ } : {}), product.variant ? {
191
+ variant: getLocalizedValue(product.variant, locale)
192
+ } : {}), Array.isArray(product.combinations) ? {
193
+ combinations: product.combinations
194
+ } : {});
195
+ });
196
+ }
197
+ function resolveProductTitle(params) {
198
+ var _product$product, _product$product_id, _fallbackProduct$prod;
199
+ var product = params.product,
200
+ productMap = params.productMap,
201
+ locale = params.locale;
202
+ var ownTitle = getLocalizedValue(product.product_title || product.title || product.name || ((_product$product = product.product) === null || _product$product === void 0 ? void 0 : _product$product.title), locale);
203
+ if (ownTitle) return ownTitle;
204
+ var productId = (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product.id;
205
+ var fallbackProduct = productId !== undefined && productId !== null ? productMap[productId] || productMap[String(productId)] : null;
206
+ if (!fallbackProduct) return '';
207
+ return getLocalizedValue(fallbackProduct.product_title || fallbackProduct.title || fallbackProduct.name || fallbackProduct.format_title || ((_fallbackProduct$prod = fallbackProduct.product) === null || _fallbackProduct$prod === void 0 ? void 0 : _fallbackProduct$prod.title), locale);
208
+ }
209
+ function buildFees(params) {
210
+ var order = params.order,
211
+ shopInfo = params.shopInfo,
212
+ locale = params.locale,
213
+ products = params.products,
214
+ summary = params.summary,
215
+ currencySymbol = params.currencySymbol;
216
+ var fees = [];
217
+ for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
218
+ var _ref8, _surcharge$amount;
219
+ var surcharge = _normalizeArray[_i];
220
+ var value = (_ref8 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref8 !== void 0 ? _ref8 : surcharge.total_amount;
221
+ if (!isNonZero(value)) continue;
222
+ fees.push({
223
+ item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
224
+ value: formatMoney(value, currencySymbol)
225
+ });
226
+ }
227
+ var discountAmount = summary.discount_amount || order.discount_amount || order.shop_discount;
228
+ if (isNonZero(discountAmount)) {
229
+ fees.push({
230
+ item: label(locale, 'orderDiscount'),
231
+ value: formatMoney(new Decimal(toMoneyNumber(discountAmount)).neg(), currencySymbol)
232
+ });
233
+ }
234
+ var taxFee = summary.tax_fee || order.tax_fee;
235
+ if (isNonZero(taxFee)) {
236
+ fees.push({
237
+ item: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
238
+ value: formatMoney(taxFee, currencySymbol)
239
+ });
240
+ }
241
+ var roundingAmount = summary.rounding_amount || order.rounding_amount;
242
+ if (isNonZero(roundingAmount)) {
243
+ fees.push({
244
+ item: label(locale, 'rounding'),
245
+ value: formatMoney(roundingAmount, currencySymbol)
246
+ });
247
+ }
248
+ var payProcessingFee = summary.pay_service_charge_amount || order.pay_service_charge_amount;
249
+ if (isNonZero(payProcessingFee)) {
250
+ fees.push({
251
+ item: label(locale, 'payProcessingFee'),
252
+ value: formatMoney(payProcessingFee, currencySymbol)
253
+ });
254
+ }
255
+ return {
256
+ fees: fees,
257
+ countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
258
+ total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
259
+ product_expect_amount: formatMoney(summary.product_expect_amount || summary.product_amount || order.product_expect_amount, currencySymbol),
260
+ expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
261
+ product_quantity: toNumber(summary.product_quantity || products.reduce(function (sum, product) {
262
+ return sum + product.product_quantity;
263
+ }, 0), 0),
264
+ has_pay: formatMoney(sumPayments(order.payments), currencySymbol),
265
+ payment_method: '',
266
+ tax_title: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
267
+ total_refund_amount: formatMoney(summary.total_refund_amount || order.total_refund_amount, currencySymbol)
268
+ }, isNonZero(roundingAmount) ? {
269
+ rounding_amount: formatMoney(roundingAmount, currencySymbol)
270
+ } : {}), isNonZero(discountAmount) ? {
271
+ order_total_discount: formatMoney(discountAmount, currencySymbol)
272
+ } : {}), isNonZero(payProcessingFee) ? {
273
+ pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
274
+ } : {}), isNonZero(taxFee) ? {
275
+ tax_fee: formatMoney(taxFee, currencySymbol)
276
+ } : {})
277
+ };
278
+ }
279
+ function buildCustomer(order, locale) {
280
+ var _order$customer, _order$customer2, _order$customer3, _order$customer4;
281
+ return [{
282
+ item: label(locale, 'contactName'),
283
+ value: normalizeCustomerDisplayValue(order.customer_name || ((_order$customer = order.customer) === null || _order$customer === void 0 ? void 0 : _order$customer.name) || ((_order$customer2 = order.customer) === null || _order$customer2 === void 0 ? void 0 : _order$customer2.display_name))
284
+ }, {
285
+ item: label(locale, 'contactMobile'),
286
+ value: stringify(order.phone || ((_order$customer3 = order.customer) === null || _order$customer3 === void 0 ? void 0 : _order$customer3.phone))
287
+ }, {
288
+ item: label(locale, 'email'),
289
+ value: stringify(order.email || ((_order$customer4 = order.customer) === null || _order$customer4 === void 0 ? void 0 : _order$customer4.email))
290
+ }];
291
+ }
292
+ function normalizeCustomerDisplayValue(value) {
293
+ var text = stringify(value).trim();
294
+ if (!text) return '';
295
+ if (text.toLowerCase() === 'select a customer') return '';
296
+ return text;
297
+ }
298
+ function buildDelivery(order, locale) {
299
+ var _order$metadata2;
300
+ var serviceType = stringify(((_order$metadata2 = order.metadata) === null || _order$metadata2 === void 0 ? void 0 : _order$metadata2.service_type) || order.service_type || order.delivery_type);
301
+ if (!serviceType) return [];
302
+ var serviceTypeLabelKey = serviceTypeToLabelKey(serviceType);
303
+ var items = [{
304
+ item: '',
305
+ value: label(locale, serviceTypeLabelKey),
306
+ size: 2,
307
+ align: 'left'
308
+ }];
309
+ if (serviceType === 'shop_server' || serviceType === 'shop_service') {
310
+ items.push({
311
+ item: label(locale, 'pickUpTime'),
312
+ value: label(locale, 'asap')
313
+ });
314
+ }
315
+ return items;
316
+ }
317
+ function buildAppointment(order, locale) {
318
+ var _order$metadata3, _order$metadata4, _order$form_data;
319
+ 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);
320
+ if (!tableName) return [];
321
+ return [{
322
+ item: label(locale, 'table'),
323
+ value: getLocalizedValue(tableName, locale)
324
+ }];
325
+ }
326
+ function buildResources(order, locale) {
327
+ return normalizeArray(order.resources || order.resource_list).map(function (resource) {
328
+ return {
329
+ id: resource.id || resource.resource_id || '',
330
+ code: '',
331
+ title: getLocalizedValue(resource.title || resource.name, locale),
332
+ form_title: getLocalizedValue(resource.form_title || resource.type || '', locale)
333
+ };
334
+ });
335
+ }
336
+ function buildPaymentData(params) {
337
+ var payments = normalizeArray(params.order.payments);
338
+ return payments.filter(function (payment) {
339
+ return isPrintablePayment(payment);
340
+ }).map(function (payment) {
341
+ var _payment$amount;
342
+ var items = [{
343
+ item: paymentMethodName(payment, params.locale),
344
+ value: formatMoney((_payment$amount = payment.amount) !== null && _payment$amount !== void 0 ? _payment$amount : payment.origin_amount, params.currencySymbol)
345
+ }];
346
+ var fundRecord = getFundRecord(payment);
347
+ if (fundRecord) {
348
+ items.push.apply(items, _toConsumableArray(buildFundRecordPaymentItems({
349
+ payment: payment,
350
+ fundRecord: fundRecord,
351
+ locale: params.locale,
352
+ currencySymbol: params.currencySymbol
353
+ })));
354
+ } else {
355
+ var _ref9, _payment$remaining_am, _payment$metadata;
356
+ var remainingAmount = (_ref9 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref9 !== void 0 ? _ref9 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
357
+ if (remainingAmount !== undefined && remainingAmount !== null) {
358
+ items.push({
359
+ item: label(params.locale, 'remainingAmount'),
360
+ value: formatMoney(remainingAmount, params.currencySymbol)
361
+ });
362
+ }
363
+ }
364
+ items.push({
365
+ item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), params.locale),
366
+ value: ''
367
+ });
368
+ return items;
369
+ });
370
+ }
371
+ function buildFundRecordPaymentItems(params) {
372
+ var payment = params.payment,
373
+ fundRecord = params.fundRecord,
374
+ locale = params.locale,
375
+ currencySymbol = params.currencySymbol;
376
+ var items = [];
377
+ var usingBeforeValue = fundRecord.using_before_value;
378
+ var usingAfterValue = fundRecord.using_after_value;
379
+ if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
380
+ var usedPoints = new Decimal(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
381
+ items.push({
382
+ item: label(locale, 'redeemPoints'),
383
+ value: trimDecimal(usedPoints)
384
+ });
385
+ items.push({
386
+ item: label(locale, 'remainingPoints'),
387
+ value: trimDecimal(new Decimal(toMoneyNumber(usingAfterValue)))
388
+ });
389
+ return items;
390
+ }
391
+ if (usingAfterValue !== undefined && usingAfterValue !== null) {
392
+ items.push({
393
+ item: label(locale, 'remainingAmount'),
394
+ value: formatMoney(usingAfterValue, currencySymbol)
395
+ });
396
+ }
397
+ return items;
398
+ }
399
+ function getFundRecord(payment) {
400
+ var fundRecord = payment.fund_record;
401
+ if (!fundRecord || _typeof(fundRecord) !== 'object' || Array.isArray(fundRecord)) return null;
402
+ if (!fundRecord.voucher_id && !fundRecord.code) return null;
403
+ return fundRecord;
404
+ }
405
+ function isPointCardPayment(payment) {
406
+ var _payment$fund_record;
407
+ var code = stringify(payment.code || payment.payment_method).toUpperCase();
408
+ var type = stringify(payment.type || ((_payment$fund_record = payment.fund_record) === null || _payment$fund_record === void 0 ? void 0 : _payment$fund_record.tag)).toLowerCase();
409
+ return code === 'POINTCARD' || type === 'point_card';
410
+ }
411
+ function maskMachineCode(code) {
412
+ var text = stringify(code);
413
+ if (text.length <= 6) return text;
414
+ return "".concat(text.slice(0, 2), "**").concat(text.slice(-4));
415
+ }
416
+ function trimDecimal(value) {
417
+ return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
418
+ }
419
+ function getFundRecordPaymentName(payment, locale) {
420
+ var fundRecord = getFundRecord(payment);
421
+ if (!fundRecord) return '';
422
+ var name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
423
+ var code = maskMachineCode(fundRecord.code);
424
+ if (!name && !code) return '';
425
+ if (!code) return name;
426
+ var fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
427
+ return "".concat(name || fallbackName, "(").concat(code, ")");
428
+ }
429
+ function appendMachineCodeToName(name, payment) {
430
+ var fundRecord = getFundRecord(payment);
431
+ if (!(fundRecord !== null && fundRecord !== void 0 && fundRecord.code)) return name;
432
+ return "".concat(name, "(").concat(maskMachineCode(fundRecord.code), ")");
433
+ }
434
+ function paymentMethodName(payment, locale) {
435
+ var fundRecordName = getFundRecordPaymentName(payment, locale);
436
+ if (fundRecordName) return fundRecordName;
437
+ var raw = payment.name || payment.title || payment.payment_method_name || payment.method_name;
438
+ if (raw) return appendMachineCodeToName(getLocalizedValue(raw, locale), payment);
439
+ var code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
440
+ if (code.includes('cash')) return label(locale, 'cash');
441
+ if (code.includes('eftpos') || code.includes('card')) return label(locale, 'eftpos');
442
+ if (code.includes('wallet')) return label(locale, 'wallet');
443
+ if (code.includes('gift')) return label(locale, 'giftCard');
444
+ return stringify(payment.code || payment.type || payment.payment_method || payment.method);
445
+ }
446
+ function getSummary(order) {
447
+ return order.summary && _typeof(order.summary) === 'object' ? order.summary : order;
448
+ }
449
+ function getCurrencySymbol(order, shopInfo) {
450
+ return stringify(order.currency_symbol || (shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.currency_symbol) || order.shop_symbol || '$') || '$';
451
+ }
452
+ function resolveLocales(shopInfo, locales) {
453
+ var preferred = [].concat(_toConsumableArray(locales || []), [shopInfo.primary_locale], DEFAULT_LOCALES).filter(Boolean);
454
+ return Array.from(new Set(preferred.map(normalizeLocaleKey)));
455
+ }
456
+ function normalizeLocaleKey(locale) {
457
+ return locale.replace('-', '_');
458
+ }
459
+ function label(locale, key) {
460
+ var _LABELS$locale;
461
+ return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
462
+ }
463
+ function getLocalizedValue(value, locale) {
464
+ var _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _value$locale;
465
+ if (value === undefined || value === null) return '';
466
+ if (_typeof(value) !== 'object') return stringify(value);
467
+ var dashedLocale = locale.replace('_', '-');
468
+ return stringify((_ref10 = (_ref11 = (_ref12 = (_ref13 = (_ref14 = (_ref15 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref15 !== void 0 ? _ref15 : value.default) !== null && _ref14 !== void 0 ? _ref14 : value.en) !== null && _ref13 !== void 0 ? _ref13 : value.zh_CN) !== null && _ref12 !== void 0 ? _ref12 : value['zh-CN']) !== null && _ref11 !== void 0 ? _ref11 : Object.values(value).find(function (item) {
469
+ return typeof item === 'string' || typeof item === 'number';
470
+ })) !== null && _ref10 !== void 0 ? _ref10 : '');
471
+ }
472
+ function serviceTypeToLabelKey(serviceType) {
473
+ var normalized = serviceType.toLowerCase();
474
+ if (normalized.includes('take')) return 'takeAway';
475
+ if (normalized.includes('delivery')) return 'delivery';
476
+ if (normalized.includes('pick')) return 'pickUp';
477
+ if (normalized.includes('shop')) return 'shopService';
478
+ return 'dineIn';
479
+ }
480
+ function buildShopAddress(shopInfo) {
481
+ return [shopInfo.address_street, shopInfo.address_detail, shopInfo.city, shopInfo.province, shopInfo.country, shopInfo.zip].filter(Boolean).join(', ');
482
+ }
483
+ function formatDateTime(value, locale) {
484
+ var date = dayjs(value);
485
+ if (!date.isValid()) return stringify(value);
486
+ if (locale === 'en') return date.format('HH:mm:ss DD/MM/YYYY');
487
+ return date.format('YYYY/MM/DD HH:mm:ss');
488
+ }
489
+ function formatMoney(value, currencySymbol) {
490
+ if (value instanceof Decimal) return "".concat(currencySymbol).concat(value.toFixed(2));
491
+ if (typeof value === 'string' && value.trim().startsWith(currencySymbol)) return value;
492
+ var amount = new Decimal(toMoneyNumber(value));
493
+ return "".concat(currencySymbol).concat(amount.toFixed(2));
494
+ }
495
+ function sumPayments(payments) {
496
+ return normalizeArray(payments).filter(function (payment) {
497
+ return isPrintablePayment(payment);
498
+ }).reduce(function (sum, payment) {
499
+ var _payment$amount2;
500
+ return sum.plus(toMoneyNumber((_payment$amount2 = payment.amount) !== null && _payment$amount2 !== void 0 ? _payment$amount2 : payment.origin_amount));
501
+ }, new Decimal(0));
502
+ }
503
+ function isPrintablePayment(payment) {
504
+ var status = stringify(payment.status).toLowerCase();
505
+ if (!status) return true;
506
+ return ['paid', 'success', 'succeeded', 'completed'].includes(status);
507
+ }
508
+ function normalizeArray(value) {
509
+ return Array.isArray(value) ? value : [];
510
+ }
511
+ function isNonZero(value) {
512
+ return !new Decimal(toMoneyNumber(value)).isZero();
513
+ }
514
+ function toMoneyNumber(value) {
515
+ if (value instanceof Decimal) return value.toString();
516
+ if (typeof value === 'number') return Number.isFinite(value) ? value : 0;
517
+ if (typeof value !== 'string') return 0;
518
+ var normalized = value.replace(/[^\d.-]/g, '');
519
+ return normalized || 0;
520
+ }
521
+ function toNumber(value, fallback) {
522
+ var numberValue = Number(value);
523
+ return Number.isFinite(numberValue) ? numberValue : fallback;
524
+ }
525
+ function stringify(value) {
526
+ if (value === undefined || value === null) return '';
527
+ return String(value);
528
+ }
@@ -9,10 +9,12 @@ import { RequestPlugin, WindowPlugin } from '../../plugins';
9
9
  export * from './types';
10
10
  import { ProductList } from '../../modules/ProductList';
11
11
  import { PaymentModule } from '../../modules/Payment';
12
+ import type { PaymentMethod } from '../../modules/Payment/types';
12
13
  import type { SalesSummaryModule } from '../../modules/SalesSummary';
13
14
  import type { ScheduleModule } from '../../modules/Schedule';
14
15
  import { QuotationModule } from '../../modules/Quotation';
15
16
  import type { ISalesDetail, ISalesDetailHeader, ISalesBooking, ISalesPayment, ISalesSurcharge } from './utils/parseSalesResponse';
17
+ import { AppPlugin } from '../../plugins/app';
16
18
  import { type TransformBaseProductToOrderProductParams } from './utils/transformBaseProductToOrderProduct';
17
19
  export interface BaseSalesState {
18
20
  order?: OrderModule;
@@ -28,7 +30,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
28
30
  isSolution: boolean;
29
31
  protected initializeOptions: ModuleOptions;
30
32
  private logger;
31
- private appPlugin;
33
+ protected appPlugin: AppPlugin;
32
34
  protected store: BaseSalesState;
33
35
  protected otherParams: Record<string, any>;
34
36
  protected cacheId: string | undefined;
@@ -41,6 +43,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
41
43
  protected currentSalesDetail: ISalesDetail | null;
42
44
  protected discountConfigCacheKey: string | null;
43
45
  protected hasManualDiscountSelection: boolean;
46
+ private paymentMethodsCache;
44
47
  constructor(name?: string, version?: string);
45
48
  /**
46
49
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -59,6 +62,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
59
62
  * 记录错误日志
60
63
  */
61
64
  private logError;
65
+ private hydrateOrderPaymentNames;
62
66
  get payment(): PaymentModule | undefined;
63
67
  private getCurrentOrderCustomerId;
64
68
  private applyQuotationScheduleResolver;
@@ -83,7 +87,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
83
87
  * sessionStorage 损坏时静默忽略,按空状态注册。
84
88
  */
85
89
  protected readSessionCacheData(): Record<string, any>;
86
- private getAppData;
90
+ protected getAppData<T>(key: string): T | undefined;
87
91
  private syncAppDataToTempOrder;
88
92
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
89
93
  destroy(): Promise<void>;
@@ -181,6 +185,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
181
185
  smallTicketDataFlag?: number;
182
186
  enhancePayload?: SubmitPayloadEnhancer;
183
187
  }): Promise<T>;
188
+ printLocalOrderReceipt<T = any>(): Promise<T>;
184
189
  private getSubmitPaymentStatus;
185
190
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
186
191
  /** 读取当前 BaseSales 订单上下文中的 Sales 协议支付项。 */
@@ -212,7 +217,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
212
217
  email: string;
213
218
  };
214
219
  /** 获取可用支付方式列表,供 PaymentModal 渲染支付选项。 */
215
- getPaymentMethodsAsync(): Promise<any[]>;
220
+ getPaymentMethodsAsync(): Promise<PaymentMethod[]>;
221
+ /** 同步读取初始化时缓存的支付方式列表。 */
222
+ getPaymentMethods(): PaymentMethod[];
216
223
  /** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */
217
224
  roundAmount(params: {
218
225
  amount: string | number;