@pisell/pisellos 2.2.205 → 2.2.207

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 (44) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  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 +230 -145
  6. package/dist/modules/Order/types.d.ts +10 -0
  7. package/dist/modules/Order/utils.js +7 -5
  8. package/dist/server/index.d.ts +136 -0
  9. package/dist/server/index.js +2055 -781
  10. package/dist/server/modules/order/index.d.ts +7 -0
  11. package/dist/server/modules/order/index.js +375 -337
  12. package/dist/server/modules/order/types.d.ts +15 -0
  13. package/dist/server/modules/order/types.js +8 -0
  14. package/dist/server/utils/small-ticket.d.ts +69 -0
  15. package/dist/server/utils/small-ticket.js +528 -0
  16. package/dist/solution/BaseSales/index.d.ts +4 -2
  17. package/dist/solution/BaseSales/index.js +248 -188
  18. package/dist/solution/BookingByStep/index.d.ts +1 -1
  19. package/dist/solution/BookingTicket/index.d.ts +8 -1
  20. package/dist/solution/BookingTicket/index.js +443 -263
  21. package/dist/solution/BookingTicket/types.d.ts +2 -1
  22. package/dist/solution/BookingTicket/types.js +3 -1
  23. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  24. package/lib/modules/OpenData/index.d.ts +1 -0
  25. package/lib/modules/OpenData/index.js +6 -4
  26. package/lib/modules/Order/index.d.ts +9 -0
  27. package/lib/modules/Order/index.js +59 -3
  28. package/lib/modules/Order/types.d.ts +10 -0
  29. package/lib/modules/Order/utils.js +4 -3
  30. package/lib/server/index.d.ts +136 -0
  31. package/lib/server/index.js +823 -50
  32. package/lib/server/modules/order/index.d.ts +7 -0
  33. package/lib/server/modules/order/index.js +21 -7
  34. package/lib/server/modules/order/types.d.ts +15 -0
  35. package/lib/server/utils/small-ticket.d.ts +69 -0
  36. package/lib/server/utils/small-ticket.js +555 -0
  37. package/lib/solution/BaseSales/index.d.ts +4 -2
  38. package/lib/solution/BaseSales/index.js +47 -1
  39. package/lib/solution/BookingByStep/index.d.ts +1 -1
  40. package/lib/solution/BookingTicket/index.d.ts +8 -1
  41. package/lib/solution/BookingTicket/index.js +108 -1
  42. package/lib/solution/BookingTicket/types.d.ts +2 -1
  43. package/lib/solution/BookingTicket/types.js +5 -0
  44. package/package.json +1 -1
@@ -524,6 +524,21 @@ export interface OrderAblyEventPayload {
524
524
  order_id?: OrderId;
525
525
  timestamp: number;
526
526
  }
527
+ /**
528
+ * 订单变更广播载荷。
529
+ * 用于保留原有全量列表通知能力,同时让订阅方可按 changedOrders 做增量处理。
530
+ *
531
+ * @example
532
+ * const changedOrders = payload.changedOrders
533
+ */
534
+ export interface OrderChangedPayload {
535
+ /** 当前订单 store 全量列表,兼容既有重算列表订阅 */
536
+ list: OrderData[];
537
+ /** 本次明确发生变更的订单;全量刷新等无法确定 delta 的场景可为空 */
538
+ changedOrders: OrderData[];
539
+ /** 触发来源,便于订阅者区分 pubsub / 远端覆盖 / 清空等场景 */
540
+ source?: string;
541
+ }
527
542
  /**
528
543
  * OrderSyncMessage - pubsub 同步消息结构
529
544
  */
@@ -127,6 +127,14 @@
127
127
  * Ably 事件载荷
128
128
  */
129
129
 
130
+ /**
131
+ * 订单变更广播载荷。
132
+ * 用于保留原有全量列表通知能力,同时让订阅方可按 changedOrders 做增量处理。
133
+ *
134
+ * @example
135
+ * const changedOrders = payload.changedOrders
136
+ */
137
+
130
138
  /**
131
139
  * OrderSyncMessage - pubsub 同步消息结构
132
140
  */
@@ -0,0 +1,69 @@
1
+ export interface SmallTicketShopInfo {
2
+ name?: string;
3
+ phone?: string;
4
+ address?: string;
5
+ address_street?: string;
6
+ address_detail?: string;
7
+ city?: string;
8
+ province?: string;
9
+ country?: string;
10
+ zip?: string;
11
+ tax_number?: string;
12
+ tax_title?: string;
13
+ currency_symbol?: string;
14
+ currency_code?: string;
15
+ primary_locale?: string;
16
+ timezone?: string;
17
+ [key: string]: any;
18
+ }
19
+ export interface BuildSmallTicketDataParams {
20
+ order: Record<string, any>;
21
+ shopInfo?: SmallTicketShopInfo | null;
22
+ locales?: string[];
23
+ productMap?: Record<string | number, Record<string, any>>;
24
+ }
25
+ export interface SmallTicketItem {
26
+ item: string;
27
+ value: string;
28
+ size?: number;
29
+ align?: string;
30
+ }
31
+ export interface SmallTicketProduct {
32
+ product_title: string;
33
+ product_quantity: number;
34
+ selling_price: string;
35
+ original_price: string;
36
+ total_original_price: string;
37
+ extension_list: any[];
38
+ options?: Array<{
39
+ name: string;
40
+ value: string;
41
+ }>;
42
+ variant?: string;
43
+ combinations?: any[];
44
+ }
45
+ export interface SmallTicketLocaleData {
46
+ base_data: Record<string, any>;
47
+ products: SmallTicketProduct[];
48
+ fees: {
49
+ fees: SmallTicketItem[];
50
+ countFee: Record<string, any>;
51
+ };
52
+ customer: SmallTicketItem[];
53
+ appointment: SmallTicketItem[];
54
+ delivery: SmallTicketItem[];
55
+ resources: Array<{
56
+ id: string | number;
57
+ code: string;
58
+ title: string;
59
+ form_title: string;
60
+ }>;
61
+ payment_data: SmallTicketItem[][];
62
+ tickets: any[];
63
+ source_shop: any[];
64
+ refund_data: any[];
65
+ expend_data: any[];
66
+ }
67
+ export type SmallTicketData = Record<string, SmallTicketLocaleData>;
68
+ export declare function buildSmallTicketData(params: BuildSmallTicketDataParams): SmallTicketData;
69
+ export declare function hasSmallTicketData(value: any): boolean;
@@ -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
+ }
@@ -14,6 +14,7 @@ import type { SalesSummaryModule } from '../../modules/SalesSummary';
14
14
  import type { ScheduleModule } from '../../modules/Schedule';
15
15
  import { QuotationModule } from '../../modules/Quotation';
16
16
  import type { ISalesDetail, ISalesDetailHeader, ISalesBooking, ISalesPayment, ISalesSurcharge } from './utils/parseSalesResponse';
17
+ import { AppPlugin } from '../../plugins/app';
17
18
  import { type TransformBaseProductToOrderProductParams } from './utils/transformBaseProductToOrderProduct';
18
19
  export interface BaseSalesState {
19
20
  order?: OrderModule;
@@ -29,7 +30,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
29
30
  isSolution: boolean;
30
31
  protected initializeOptions: ModuleOptions;
31
32
  private logger;
32
- private appPlugin;
33
+ protected appPlugin: AppPlugin;
33
34
  protected store: BaseSalesState;
34
35
  protected otherParams: Record<string, any>;
35
36
  protected cacheId: string | undefined;
@@ -86,7 +87,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
86
87
  * sessionStorage 损坏时静默忽略,按空状态注册。
87
88
  */
88
89
  protected readSessionCacheData(): Record<string, any>;
89
- private getAppData;
90
+ protected getAppData<T>(key: string): T | undefined;
90
91
  private syncAppDataToTempOrder;
91
92
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
92
93
  destroy(): Promise<void>;
@@ -184,6 +185,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
184
185
  smallTicketDataFlag?: number;
185
186
  enhancePayload?: SubmitPayloadEnhancer;
186
187
  }): Promise<T>;
188
+ printLocalOrderReceipt<T = any>(): Promise<T>;
187
189
  private getSubmitPaymentStatus;
188
190
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
189
191
  /** 读取当前 BaseSales 订单上下文中的 Sales 协议支付项。 */