@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.
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/OpenData/index.d.ts +1 -0
- package/dist/modules/OpenData/index.js +21 -16
- package/dist/modules/Order/index.d.ts +9 -0
- package/dist/modules/Order/index.js +237 -146
- package/dist/modules/Order/types.d.ts +10 -0
- package/dist/modules/Order/utils.js +7 -5
- package/dist/modules/Payment/index.d.ts +0 -13
- package/dist/modules/Payment/index.js +449 -833
- package/dist/plugins/request.d.ts +1 -0
- package/dist/server/index.d.ts +142 -0
- package/dist/server/index.js +2208 -824
- package/dist/server/modules/index.d.ts +2 -0
- package/dist/server/modules/index.js +2 -0
- package/dist/server/modules/order/index.d.ts +7 -0
- package/dist/server/modules/order/index.js +375 -337
- package/dist/server/modules/order/types.d.ts +15 -0
- package/dist/server/modules/order/types.js +8 -0
- package/dist/server/modules/payment/index.d.ts +28 -0
- package/dist/server/modules/payment/index.js +305 -0
- package/dist/server/modules/payment/types.d.ts +9 -0
- package/dist/server/modules/payment/types.js +1 -0
- package/dist/server/utils/small-ticket.d.ts +69 -0
- package/dist/server/utils/small-ticket.js +528 -0
- package/dist/solution/BaseSales/index.d.ts +10 -3
- package/dist/solution/BaseSales/index.js +307 -198
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +8 -1
- package/dist/solution/BookingTicket/index.js +444 -264
- package/dist/solution/BookingTicket/types.d.ts +2 -1
- package/dist/solution/BookingTicket/types.js +3 -1
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +51 -52
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/modules/OpenData/index.d.ts +1 -0
- package/lib/modules/OpenData/index.js +6 -4
- package/lib/modules/Order/index.d.ts +9 -0
- package/lib/modules/Order/index.js +64 -4
- package/lib/modules/Order/types.d.ts +10 -0
- package/lib/modules/Order/utils.js +4 -3
- package/lib/modules/Payment/index.d.ts +0 -13
- package/lib/modules/Payment/index.js +6 -149
- package/lib/plugins/request.d.ts +1 -0
- package/lib/server/index.d.ts +142 -0
- package/lib/server/index.js +867 -49
- package/lib/server/modules/index.d.ts +2 -0
- package/lib/server/modules/index.js +3 -0
- package/lib/server/modules/order/index.d.ts +7 -0
- package/lib/server/modules/order/index.js +21 -7
- package/lib/server/modules/order/types.d.ts +15 -0
- package/lib/server/modules/payment/index.d.ts +28 -0
- package/lib/server/modules/payment/index.js +192 -0
- package/lib/server/modules/payment/types.d.ts +9 -0
- package/lib/server/modules/payment/types.js +17 -0
- package/lib/server/utils/small-ticket.d.ts +69 -0
- package/lib/server/utils/small-ticket.js +555 -0
- package/lib/solution/BaseSales/index.d.ts +10 -3
- package/lib/solution/BaseSales/index.js +98 -6
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +8 -1
- package/lib/solution/BookingTicket/index.js +109 -2
- package/lib/solution/BookingTicket/types.d.ts +2 -1
- package/lib/solution/BookingTicket/types.js +5 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +1 -2
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +17 -3
- package/package.json +1 -1
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/server/utils/small-ticket.ts
|
|
30
|
+
var small_ticket_exports = {};
|
|
31
|
+
__export(small_ticket_exports, {
|
|
32
|
+
buildSmallTicketData: () => buildSmallTicketData,
|
|
33
|
+
hasSmallTicketData: () => hasSmallTicketData
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(small_ticket_exports);
|
|
36
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
37
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
38
|
+
var DEFAULT_LOCALES = ["en", "zh_CN"];
|
|
39
|
+
var LABELS = {
|
|
40
|
+
en: {
|
|
41
|
+
contactName: "Contact name",
|
|
42
|
+
contactMobile: "Contact Mobile",
|
|
43
|
+
email: "email",
|
|
44
|
+
dineIn: "Dine-in",
|
|
45
|
+
takeAway: "Take away",
|
|
46
|
+
delivery: "Delivery",
|
|
47
|
+
pickUp: "Pick-up",
|
|
48
|
+
shopService: "Dine-in",
|
|
49
|
+
pickUpTime: "Pick-up time",
|
|
50
|
+
asap: "ASAP",
|
|
51
|
+
cash: "Cash",
|
|
52
|
+
eftpos: "Eftpos",
|
|
53
|
+
wallet: "Wallet",
|
|
54
|
+
giftCard: "Gift card",
|
|
55
|
+
remainingAmount: "Remaining amount",
|
|
56
|
+
redeemPoints: "Redeem points",
|
|
57
|
+
remainingPoints: "Remaining points",
|
|
58
|
+
table: "Table",
|
|
59
|
+
orderDiscount: "Order discount",
|
|
60
|
+
payProcessingFee: "Pay processing fee",
|
|
61
|
+
rounding: "Rounding"
|
|
62
|
+
},
|
|
63
|
+
zh_CN: {
|
|
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
|
+
zh_HK: {
|
|
87
|
+
contactName: "聯絡人姓名",
|
|
88
|
+
contactMobile: "聯絡電話",
|
|
89
|
+
email: "電郵",
|
|
90
|
+
dineIn: "堂食",
|
|
91
|
+
takeAway: "外帶",
|
|
92
|
+
delivery: "配送",
|
|
93
|
+
pickUp: "自取",
|
|
94
|
+
shopService: "堂食",
|
|
95
|
+
pickUpTime: "取餐時間",
|
|
96
|
+
asap: "盡快",
|
|
97
|
+
cash: "現金支付",
|
|
98
|
+
eftpos: "刷卡支付",
|
|
99
|
+
wallet: "錢包支付",
|
|
100
|
+
giftCard: "禮品卡",
|
|
101
|
+
remainingAmount: "剩餘金額",
|
|
102
|
+
redeemPoints: "本次使用積分",
|
|
103
|
+
remainingPoints: "剩餘積分",
|
|
104
|
+
table: "桌台",
|
|
105
|
+
orderDiscount: "整單折扣",
|
|
106
|
+
payProcessingFee: "支付手續費",
|
|
107
|
+
rounding: "抹零"
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
function buildSmallTicketData(params) {
|
|
111
|
+
const order = params.order || {};
|
|
112
|
+
const shopInfo = params.shopInfo || {};
|
|
113
|
+
const locales = resolveLocales(shopInfo, params.locales);
|
|
114
|
+
const productMap = params.productMap || {};
|
|
115
|
+
return locales.reduce((data, locale) => {
|
|
116
|
+
data[locale] = buildLocaleData({ order, shopInfo, locale, productMap });
|
|
117
|
+
return data;
|
|
118
|
+
}, {});
|
|
119
|
+
}
|
|
120
|
+
function hasSmallTicketData(value) {
|
|
121
|
+
return !!value && typeof value === "object" && Object.keys(value).length > 0;
|
|
122
|
+
}
|
|
123
|
+
function buildLocaleData(params) {
|
|
124
|
+
const { order, shopInfo, locale, productMap } = params;
|
|
125
|
+
const products = buildProducts(order, locale, productMap);
|
|
126
|
+
const summary = getSummary(order);
|
|
127
|
+
const currencySymbol = getCurrencySymbol(order, shopInfo);
|
|
128
|
+
return {
|
|
129
|
+
base_data: buildBaseData({ order, shopInfo, locale }),
|
|
130
|
+
products,
|
|
131
|
+
fees: buildFees({ order, shopInfo, locale, products, summary, currencySymbol }),
|
|
132
|
+
customer: buildCustomer(order, locale),
|
|
133
|
+
appointment: buildAppointment(order, locale),
|
|
134
|
+
delivery: buildDelivery(order, locale),
|
|
135
|
+
resources: buildResources(order, locale),
|
|
136
|
+
payment_data: buildPaymentData({ order, locale, currencySymbol }),
|
|
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 _a;
|
|
145
|
+
const { order, shopInfo, locale } = params;
|
|
146
|
+
const orderNumber = stringify(
|
|
147
|
+
order.order_number || order.shop_full_order_number || order.shop_order_number || order.external_sale_number
|
|
148
|
+
);
|
|
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 || ((_a = order.metadata) == null ? void 0 : _a.buzzer)),
|
|
160
|
+
order_no: orderNumber,
|
|
161
|
+
order_time: formatDateTime(order.created_at || order.sales_time || /* @__PURE__ */ new Date(), locale)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function buildProducts(order, locale, productMap) {
|
|
165
|
+
const products = Array.isArray(order.products) ? order.products : [];
|
|
166
|
+
return products.map((product) => {
|
|
167
|
+
const quantity = toNumber(product.product_quantity ?? product.quantity ?? product.num ?? 1, 1);
|
|
168
|
+
const originalPrice = product.original_price ?? product.selling_price ?? product.payment_price ?? product.price ?? 0;
|
|
169
|
+
const sellingPrice = product.selling_price ?? product.payment_price ?? product.price ?? originalPrice;
|
|
170
|
+
const productTitle = resolveProductTitle({ product, productMap, locale });
|
|
171
|
+
return {
|
|
172
|
+
product_title: productTitle,
|
|
173
|
+
product_quantity: quantity,
|
|
174
|
+
selling_price: formatMoney(sellingPrice, getCurrencySymbol(order, null)),
|
|
175
|
+
original_price: formatMoney(originalPrice, getCurrencySymbol(order, null)),
|
|
176
|
+
total_original_price: formatMoney(new import_decimal.default(toMoneyNumber(originalPrice)).mul(quantity), getCurrencySymbol(order, null)),
|
|
177
|
+
extension_list: Array.isArray(product.extension_list) ? product.extension_list : [],
|
|
178
|
+
...Array.isArray(product.options) ? {
|
|
179
|
+
options: product.options.map((option) => ({
|
|
180
|
+
name: getLocalizedValue(option.name || option.title, locale),
|
|
181
|
+
value: getLocalizedValue(option.value || option.option || option.item, locale)
|
|
182
|
+
}))
|
|
183
|
+
} : {},
|
|
184
|
+
...product.variant ? { variant: getLocalizedValue(product.variant, locale) } : {},
|
|
185
|
+
...Array.isArray(product.combinations) ? { combinations: product.combinations } : {}
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function resolveProductTitle(params) {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
const { product, productMap, locale } = params;
|
|
192
|
+
const ownTitle = getLocalizedValue(
|
|
193
|
+
product.product_title || product.title || product.name || ((_a = product.product) == null ? void 0 : _a.title),
|
|
194
|
+
locale
|
|
195
|
+
);
|
|
196
|
+
if (ownTitle)
|
|
197
|
+
return ownTitle;
|
|
198
|
+
const productId = product.product_id ?? product.id;
|
|
199
|
+
const fallbackProduct = productId !== void 0 && productId !== null ? productMap[productId] || productMap[String(productId)] : null;
|
|
200
|
+
if (!fallbackProduct)
|
|
201
|
+
return "";
|
|
202
|
+
return getLocalizedValue(
|
|
203
|
+
fallbackProduct.product_title || fallbackProduct.title || fallbackProduct.name || fallbackProduct.format_title || ((_b = fallbackProduct.product) == null ? void 0 : _b.title),
|
|
204
|
+
locale
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
function buildFees(params) {
|
|
208
|
+
const { order, shopInfo, locale, products, summary, currencySymbol } = params;
|
|
209
|
+
const fees = [];
|
|
210
|
+
for (const surcharge of normalizeArray(order.surcharges || summary.surcharges)) {
|
|
211
|
+
const value = surcharge.amount ?? surcharge.value ?? surcharge.total_amount;
|
|
212
|
+
if (!isNonZero(value))
|
|
213
|
+
continue;
|
|
214
|
+
fees.push({
|
|
215
|
+
item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
|
|
216
|
+
value: formatMoney(value, currencySymbol)
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const discountAmount = summary.discount_amount || order.discount_amount || order.shop_discount;
|
|
220
|
+
if (isNonZero(discountAmount)) {
|
|
221
|
+
fees.push({
|
|
222
|
+
item: label(locale, "orderDiscount"),
|
|
223
|
+
value: formatMoney(new import_decimal.default(toMoneyNumber(discountAmount)).neg(), currencySymbol)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const taxFee = summary.tax_fee || order.tax_fee;
|
|
227
|
+
if (isNonZero(taxFee)) {
|
|
228
|
+
fees.push({
|
|
229
|
+
item: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
|
|
230
|
+
value: formatMoney(taxFee, currencySymbol)
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
const roundingAmount = summary.rounding_amount || order.rounding_amount;
|
|
234
|
+
if (isNonZero(roundingAmount)) {
|
|
235
|
+
fees.push({
|
|
236
|
+
item: label(locale, "rounding"),
|
|
237
|
+
value: formatMoney(roundingAmount, currencySymbol)
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const payProcessingFee = summary.pay_service_charge_amount || order.pay_service_charge_amount;
|
|
241
|
+
if (isNonZero(payProcessingFee)) {
|
|
242
|
+
fees.push({
|
|
243
|
+
item: label(locale, "payProcessingFee"),
|
|
244
|
+
value: formatMoney(payProcessingFee, currencySymbol)
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
fees,
|
|
249
|
+
countFee: {
|
|
250
|
+
total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
|
|
251
|
+
product_expect_amount: formatMoney(
|
|
252
|
+
summary.product_expect_amount || summary.product_amount || order.product_expect_amount,
|
|
253
|
+
currencySymbol
|
|
254
|
+
),
|
|
255
|
+
expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
|
|
256
|
+
product_quantity: toNumber(
|
|
257
|
+
summary.product_quantity || products.reduce((sum, product) => sum + product.product_quantity, 0),
|
|
258
|
+
0
|
|
259
|
+
),
|
|
260
|
+
has_pay: formatMoney(sumPayments(order.payments), currencySymbol),
|
|
261
|
+
payment_method: "",
|
|
262
|
+
tax_title: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
|
|
263
|
+
total_refund_amount: formatMoney(summary.total_refund_amount || order.total_refund_amount, currencySymbol),
|
|
264
|
+
...isNonZero(roundingAmount) ? { rounding_amount: formatMoney(roundingAmount, currencySymbol) } : {},
|
|
265
|
+
...isNonZero(discountAmount) ? { order_total_discount: formatMoney(discountAmount, currencySymbol) } : {},
|
|
266
|
+
...isNonZero(payProcessingFee) ? { pay_processing_fee: formatMoney(payProcessingFee, currencySymbol) } : {},
|
|
267
|
+
...isNonZero(taxFee) ? { tax_fee: formatMoney(taxFee, currencySymbol) } : {}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function buildCustomer(order, locale) {
|
|
272
|
+
var _a, _b, _c, _d;
|
|
273
|
+
return [
|
|
274
|
+
{ item: label(locale, "contactName"), value: normalizeCustomerDisplayValue(order.customer_name || ((_a = order.customer) == null ? void 0 : _a.name) || ((_b = order.customer) == null ? void 0 : _b.display_name)) },
|
|
275
|
+
{ item: label(locale, "contactMobile"), value: stringify(order.phone || ((_c = order.customer) == null ? void 0 : _c.phone)) },
|
|
276
|
+
{ item: label(locale, "email"), value: stringify(order.email || ((_d = order.customer) == null ? void 0 : _d.email)) }
|
|
277
|
+
];
|
|
278
|
+
}
|
|
279
|
+
function normalizeCustomerDisplayValue(value) {
|
|
280
|
+
const text = stringify(value).trim();
|
|
281
|
+
if (!text)
|
|
282
|
+
return "";
|
|
283
|
+
if (text.toLowerCase() === "select a customer")
|
|
284
|
+
return "";
|
|
285
|
+
return text;
|
|
286
|
+
}
|
|
287
|
+
function buildDelivery(order, locale) {
|
|
288
|
+
var _a;
|
|
289
|
+
const serviceType = stringify(((_a = order.metadata) == null ? void 0 : _a.service_type) || order.service_type || order.delivery_type);
|
|
290
|
+
if (!serviceType)
|
|
291
|
+
return [];
|
|
292
|
+
const serviceTypeLabelKey = serviceTypeToLabelKey(serviceType);
|
|
293
|
+
const items = [
|
|
294
|
+
{
|
|
295
|
+
item: "",
|
|
296
|
+
value: label(locale, serviceTypeLabelKey),
|
|
297
|
+
size: 2,
|
|
298
|
+
align: "left"
|
|
299
|
+
}
|
|
300
|
+
];
|
|
301
|
+
if (serviceType === "shop_server" || serviceType === "shop_service") {
|
|
302
|
+
items.push({
|
|
303
|
+
item: label(locale, "pickUpTime"),
|
|
304
|
+
value: label(locale, "asap")
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return items;
|
|
308
|
+
}
|
|
309
|
+
function buildAppointment(order, locale) {
|
|
310
|
+
var _a, _b, _c, _d;
|
|
311
|
+
const tableName = order.table_name || ((_a = order.metadata) == null ? void 0 : _a.table_name) || ((_c = (_b = order.metadata) == null ? void 0 : _b.table) == null ? void 0 : _c.name) || ((_d = order.form_data) == null ? void 0 : _d.table_name);
|
|
312
|
+
if (!tableName)
|
|
313
|
+
return [];
|
|
314
|
+
return [
|
|
315
|
+
{
|
|
316
|
+
item: label(locale, "table"),
|
|
317
|
+
value: getLocalizedValue(tableName, locale)
|
|
318
|
+
}
|
|
319
|
+
];
|
|
320
|
+
}
|
|
321
|
+
function buildResources(order, locale) {
|
|
322
|
+
return normalizeArray(order.resources || order.resource_list).map((resource) => ({
|
|
323
|
+
id: resource.id || resource.resource_id || "",
|
|
324
|
+
code: "",
|
|
325
|
+
title: getLocalizedValue(resource.title || resource.name, locale),
|
|
326
|
+
form_title: getLocalizedValue(resource.form_title || resource.type || "", locale)
|
|
327
|
+
}));
|
|
328
|
+
}
|
|
329
|
+
function buildPaymentData(params) {
|
|
330
|
+
const payments = normalizeArray(params.order.payments);
|
|
331
|
+
return payments.filter((payment) => isPrintablePayment(payment)).map((payment) => {
|
|
332
|
+
var _a;
|
|
333
|
+
const items = [
|
|
334
|
+
{
|
|
335
|
+
item: paymentMethodName(payment, params.locale),
|
|
336
|
+
value: formatMoney(payment.amount ?? payment.origin_amount, params.currencySymbol)
|
|
337
|
+
}
|
|
338
|
+
];
|
|
339
|
+
const fundRecord = getFundRecord(payment);
|
|
340
|
+
if (fundRecord) {
|
|
341
|
+
items.push(...buildFundRecordPaymentItems({ payment, fundRecord, locale: params.locale, currencySymbol: params.currencySymbol }));
|
|
342
|
+
} else {
|
|
343
|
+
const remainingAmount = payment.remaining_amount ?? payment.balance ?? ((_a = payment.metadata) == null ? void 0 : _a.remaining_amount);
|
|
344
|
+
if (remainingAmount !== void 0 && remainingAmount !== null) {
|
|
345
|
+
items.push({
|
|
346
|
+
item: label(params.locale, "remainingAmount"),
|
|
347
|
+
value: formatMoney(remainingAmount, params.currencySymbol)
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
items.push({
|
|
352
|
+
item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || /* @__PURE__ */ new Date(), params.locale),
|
|
353
|
+
value: ""
|
|
354
|
+
});
|
|
355
|
+
return items;
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
function buildFundRecordPaymentItems(params) {
|
|
359
|
+
const { payment, fundRecord, locale, currencySymbol } = params;
|
|
360
|
+
const items = [];
|
|
361
|
+
const usingBeforeValue = fundRecord.using_before_value;
|
|
362
|
+
const usingAfterValue = fundRecord.using_after_value;
|
|
363
|
+
if (isPointCardPayment(payment) && usingBeforeValue !== void 0 && usingAfterValue !== void 0) {
|
|
364
|
+
const usedPoints = new import_decimal.default(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
|
|
365
|
+
items.push({
|
|
366
|
+
item: label(locale, "redeemPoints"),
|
|
367
|
+
value: trimDecimal(usedPoints)
|
|
368
|
+
});
|
|
369
|
+
items.push({
|
|
370
|
+
item: label(locale, "remainingPoints"),
|
|
371
|
+
value: trimDecimal(new import_decimal.default(toMoneyNumber(usingAfterValue)))
|
|
372
|
+
});
|
|
373
|
+
return items;
|
|
374
|
+
}
|
|
375
|
+
if (usingAfterValue !== void 0 && usingAfterValue !== null) {
|
|
376
|
+
items.push({
|
|
377
|
+
item: label(locale, "remainingAmount"),
|
|
378
|
+
value: formatMoney(usingAfterValue, currencySymbol)
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return items;
|
|
382
|
+
}
|
|
383
|
+
function getFundRecord(payment) {
|
|
384
|
+
const fundRecord = payment.fund_record;
|
|
385
|
+
if (!fundRecord || typeof fundRecord !== "object" || Array.isArray(fundRecord))
|
|
386
|
+
return null;
|
|
387
|
+
if (!fundRecord.voucher_id && !fundRecord.code)
|
|
388
|
+
return null;
|
|
389
|
+
return fundRecord;
|
|
390
|
+
}
|
|
391
|
+
function isPointCardPayment(payment) {
|
|
392
|
+
var _a;
|
|
393
|
+
const code = stringify(payment.code || payment.payment_method).toUpperCase();
|
|
394
|
+
const type = stringify(payment.type || ((_a = payment.fund_record) == null ? void 0 : _a.tag)).toLowerCase();
|
|
395
|
+
return code === "POINTCARD" || type === "point_card";
|
|
396
|
+
}
|
|
397
|
+
function maskMachineCode(code) {
|
|
398
|
+
const text = stringify(code);
|
|
399
|
+
if (text.length <= 6)
|
|
400
|
+
return text;
|
|
401
|
+
return `${text.slice(0, 2)}**${text.slice(-4)}`;
|
|
402
|
+
}
|
|
403
|
+
function trimDecimal(value) {
|
|
404
|
+
return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, "");
|
|
405
|
+
}
|
|
406
|
+
function getFundRecordPaymentName(payment, locale) {
|
|
407
|
+
const fundRecord = getFundRecord(payment);
|
|
408
|
+
if (!fundRecord)
|
|
409
|
+
return "";
|
|
410
|
+
const name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
|
|
411
|
+
const code = maskMachineCode(fundRecord.code);
|
|
412
|
+
if (!name && !code)
|
|
413
|
+
return "";
|
|
414
|
+
if (!code)
|
|
415
|
+
return name;
|
|
416
|
+
const fallbackName = getLocalizedValue(
|
|
417
|
+
payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code,
|
|
418
|
+
locale
|
|
419
|
+
);
|
|
420
|
+
return `${name || fallbackName}(${code})`;
|
|
421
|
+
}
|
|
422
|
+
function appendMachineCodeToName(name, payment) {
|
|
423
|
+
const fundRecord = getFundRecord(payment);
|
|
424
|
+
if (!(fundRecord == null ? void 0 : fundRecord.code))
|
|
425
|
+
return name;
|
|
426
|
+
return `${name}(${maskMachineCode(fundRecord.code)})`;
|
|
427
|
+
}
|
|
428
|
+
function paymentMethodName(payment, locale) {
|
|
429
|
+
const fundRecordName = getFundRecordPaymentName(payment, locale);
|
|
430
|
+
if (fundRecordName)
|
|
431
|
+
return fundRecordName;
|
|
432
|
+
const raw = payment.name || payment.title || payment.payment_method_name || payment.method_name;
|
|
433
|
+
if (raw)
|
|
434
|
+
return appendMachineCodeToName(getLocalizedValue(raw, locale), payment);
|
|
435
|
+
const code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
|
|
436
|
+
if (code.includes("cash"))
|
|
437
|
+
return label(locale, "cash");
|
|
438
|
+
if (code.includes("eftpos") || code.includes("card"))
|
|
439
|
+
return label(locale, "eftpos");
|
|
440
|
+
if (code.includes("wallet"))
|
|
441
|
+
return label(locale, "wallet");
|
|
442
|
+
if (code.includes("gift"))
|
|
443
|
+
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 ? void 0 : shopInfo.currency_symbol) || order.shop_symbol || "$") || "$";
|
|
451
|
+
}
|
|
452
|
+
function resolveLocales(shopInfo, locales) {
|
|
453
|
+
const preferred = [
|
|
454
|
+
...locales || [],
|
|
455
|
+
shopInfo.primary_locale,
|
|
456
|
+
...DEFAULT_LOCALES
|
|
457
|
+
].filter(Boolean);
|
|
458
|
+
return Array.from(new Set(preferred.map(normalizeLocaleKey)));
|
|
459
|
+
}
|
|
460
|
+
function normalizeLocaleKey(locale) {
|
|
461
|
+
return locale.replace("-", "_");
|
|
462
|
+
}
|
|
463
|
+
function label(locale, key) {
|
|
464
|
+
var _a;
|
|
465
|
+
return ((_a = LABELS[locale]) == null ? void 0 : _a[key]) || LABELS.en[key] || key;
|
|
466
|
+
}
|
|
467
|
+
function getLocalizedValue(value, locale) {
|
|
468
|
+
if (value === void 0 || value === null)
|
|
469
|
+
return "";
|
|
470
|
+
if (typeof value !== "object")
|
|
471
|
+
return stringify(value);
|
|
472
|
+
const dashedLocale = locale.replace("_", "-");
|
|
473
|
+
return stringify(
|
|
474
|
+
value[locale] ?? value[dashedLocale] ?? value.default ?? value.en ?? value.zh_CN ?? value["zh-CN"] ?? Object.values(value).find((item) => typeof item === "string" || typeof item === "number") ?? ""
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
function serviceTypeToLabelKey(serviceType) {
|
|
478
|
+
const normalized = serviceType.toLowerCase();
|
|
479
|
+
if (normalized.includes("take"))
|
|
480
|
+
return "takeAway";
|
|
481
|
+
if (normalized.includes("delivery"))
|
|
482
|
+
return "delivery";
|
|
483
|
+
if (normalized.includes("pick"))
|
|
484
|
+
return "pickUp";
|
|
485
|
+
if (normalized.includes("shop"))
|
|
486
|
+
return "shopService";
|
|
487
|
+
return "dineIn";
|
|
488
|
+
}
|
|
489
|
+
function buildShopAddress(shopInfo) {
|
|
490
|
+
return [
|
|
491
|
+
shopInfo.address_street,
|
|
492
|
+
shopInfo.address_detail,
|
|
493
|
+
shopInfo.city,
|
|
494
|
+
shopInfo.province,
|
|
495
|
+
shopInfo.country,
|
|
496
|
+
shopInfo.zip
|
|
497
|
+
].filter(Boolean).join(", ");
|
|
498
|
+
}
|
|
499
|
+
function formatDateTime(value, locale) {
|
|
500
|
+
const date = (0, import_dayjs.default)(value);
|
|
501
|
+
if (!date.isValid())
|
|
502
|
+
return stringify(value);
|
|
503
|
+
if (locale === "en")
|
|
504
|
+
return date.format("HH:mm:ss DD/MM/YYYY");
|
|
505
|
+
return date.format("YYYY/MM/DD HH:mm:ss");
|
|
506
|
+
}
|
|
507
|
+
function formatMoney(value, currencySymbol) {
|
|
508
|
+
if (value instanceof import_decimal.default)
|
|
509
|
+
return `${currencySymbol}${value.toFixed(2)}`;
|
|
510
|
+
if (typeof value === "string" && value.trim().startsWith(currencySymbol))
|
|
511
|
+
return value;
|
|
512
|
+
const amount = new import_decimal.default(toMoneyNumber(value));
|
|
513
|
+
return `${currencySymbol}${amount.toFixed(2)}`;
|
|
514
|
+
}
|
|
515
|
+
function sumPayments(payments) {
|
|
516
|
+
return normalizeArray(payments).filter((payment) => isPrintablePayment(payment)).reduce((sum, payment) => {
|
|
517
|
+
return sum.plus(toMoneyNumber(payment.amount ?? payment.origin_amount));
|
|
518
|
+
}, new import_decimal.default(0));
|
|
519
|
+
}
|
|
520
|
+
function isPrintablePayment(payment) {
|
|
521
|
+
const status = stringify(payment.status).toLowerCase();
|
|
522
|
+
if (!status)
|
|
523
|
+
return true;
|
|
524
|
+
return ["paid", "success", "succeeded", "completed"].includes(status);
|
|
525
|
+
}
|
|
526
|
+
function normalizeArray(value) {
|
|
527
|
+
return Array.isArray(value) ? value : [];
|
|
528
|
+
}
|
|
529
|
+
function isNonZero(value) {
|
|
530
|
+
return !new import_decimal.default(toMoneyNumber(value)).isZero();
|
|
531
|
+
}
|
|
532
|
+
function toMoneyNumber(value) {
|
|
533
|
+
if (value instanceof import_decimal.default)
|
|
534
|
+
return value.toString();
|
|
535
|
+
if (typeof value === "number")
|
|
536
|
+
return Number.isFinite(value) ? value : 0;
|
|
537
|
+
if (typeof value !== "string")
|
|
538
|
+
return 0;
|
|
539
|
+
const normalized = value.replace(/[^\d.-]/g, "");
|
|
540
|
+
return normalized || 0;
|
|
541
|
+
}
|
|
542
|
+
function toNumber(value, fallback) {
|
|
543
|
+
const numberValue = Number(value);
|
|
544
|
+
return Number.isFinite(numberValue) ? numberValue : fallback;
|
|
545
|
+
}
|
|
546
|
+
function stringify(value) {
|
|
547
|
+
if (value === void 0 || value === null)
|
|
548
|
+
return "";
|
|
549
|
+
return String(value);
|
|
550
|
+
}
|
|
551
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
552
|
+
0 && (module.exports = {
|
|
553
|
+
buildSmallTicketData,
|
|
554
|
+
hasSmallTicketData
|
|
555
|
+
});
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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<
|
|
220
|
+
getPaymentMethodsAsync(): Promise<PaymentMethod[]>;
|
|
221
|
+
/** 同步读取初始化时缓存的支付方式列表。 */
|
|
222
|
+
getPaymentMethods(): PaymentMethod[];
|
|
216
223
|
/** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */
|
|
217
224
|
roundAmount(params: {
|
|
218
225
|
amount: string | number;
|