@pisell/pisellos 0.10.28 → 0.10.29
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/core/index.d.ts +7 -0
- package/dist/core/index.js +108 -65
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +13 -2
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/Discount/index.js +4 -1
- package/dist/modules/Discount/types.d.ts +14 -4
- package/dist/modules/Order/index.d.ts +4 -2
- package/dist/modules/Order/index.js +89 -16
- package/dist/modules/Order/types.d.ts +13 -0
- package/dist/modules/Order/utils.d.ts +17 -2
- package/dist/modules/Order/utils.js +133 -27
- package/dist/modules/Quotation/index.d.ts +6 -0
- package/dist/modules/Quotation/index.js +77 -25
- package/dist/modules/ResourcePlanner/planner.js +14 -4
- package/dist/modules/ResourcePlanner/types.d.ts +2 -0
- package/dist/plugins/request.d.ts +1 -0
- package/dist/server/index.d.ts +13 -2
- package/dist/server/index.js +1531 -1230
- package/dist/server/modules/floor-plan/index.d.ts +4 -0
- package/dist/server/modules/floor-plan/index.js +240 -98
- package/dist/server/modules/menu/index.js +48 -23
- package/dist/server/modules/order/index.d.ts +17 -7
- package/dist/server/modules/order/index.js +419 -207
- package/dist/server/modules/order/types.d.ts +50 -0
- package/dist/server/modules/order/types.js +2 -0
- package/dist/server/modules/products/index.d.ts +10 -4
- package/dist/server/modules/products/index.js +177 -84
- package/dist/server/modules/resource/index.js +21 -13
- package/dist/server/utils/product.d.ts +1 -1
- package/dist/server/utils/product.js +186 -22
- package/dist/server/utils/small-ticket.d.ts +4 -1
- package/dist/server/utils/small-ticket.js +482 -100
- package/dist/solution/BaseSales/index.d.ts +3 -3
- package/dist/solution/BaseSales/index.js +171 -198
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/Sales/index.d.ts +7 -0
- package/dist/solution/Sales/index.js +87 -31
- package/dist/solution/UnifiedBookingSales/index.d.ts +2 -2
- package/dist/solution/UnifiedBookingSales/index.js +38 -21
- package/lib/core/index.d.ts +7 -0
- package/lib/core/index.js +20 -2
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +12 -2
- package/lib/modules/Discount/index.js +4 -1
- package/lib/modules/Discount/types.d.ts +14 -4
- package/lib/modules/Order/index.d.ts +4 -2
- package/lib/modules/Order/index.js +69 -1
- package/lib/modules/Order/types.d.ts +13 -0
- package/lib/modules/Order/utils.d.ts +17 -2
- package/lib/modules/Order/utils.js +131 -18
- package/lib/modules/Quotation/index.d.ts +6 -0
- package/lib/modules/Quotation/index.js +52 -8
- package/lib/modules/ResourcePlanner/planner.js +9 -1
- package/lib/modules/ResourcePlanner/types.d.ts +2 -0
- package/lib/plugins/request.d.ts +1 -0
- package/lib/server/index.d.ts +13 -2
- package/lib/server/index.js +210 -19
- package/lib/server/modules/floor-plan/index.d.ts +4 -0
- package/lib/server/modules/floor-plan/index.js +60 -7
- package/lib/server/modules/menu/index.js +26 -4
- package/lib/server/modules/order/index.d.ts +17 -7
- package/lib/server/modules/order/index.js +194 -57
- package/lib/server/modules/order/types.d.ts +50 -0
- package/lib/server/modules/order/types.js +1 -0
- package/lib/server/modules/products/index.d.ts +10 -4
- package/lib/server/modules/products/index.js +93 -23
- package/lib/server/modules/resource/index.js +12 -2
- package/lib/server/utils/product.d.ts +1 -1
- package/lib/server/utils/product.js +163 -3
- package/lib/server/utils/small-ticket.d.ts +4 -1
- package/lib/server/utils/small-ticket.js +448 -75
- package/lib/solution/BaseSales/index.d.ts +3 -3
- package/lib/solution/BaseSales/index.js +9 -14
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/Sales/index.d.ts +7 -0
- package/lib/solution/Sales/index.js +48 -3
- package/lib/solution/UnifiedBookingSales/index.d.ts +2 -2
- package/lib/solution/UnifiedBookingSales/index.js +19 -3
- package/package.json +1 -1
|
@@ -30,9 +30,12 @@ var LABELS = {
|
|
|
30
30
|
pickUpTime: 'Pick-up time',
|
|
31
31
|
asap: 'ASAP',
|
|
32
32
|
cash: 'Cash',
|
|
33
|
+
cashReceived: 'Cash received',
|
|
34
|
+
changeDue: 'Change due',
|
|
33
35
|
eftpos: 'Eftpos',
|
|
34
36
|
wallet: 'Wallet',
|
|
35
37
|
giftCard: 'Gift card',
|
|
38
|
+
balance: 'Balance',
|
|
36
39
|
remainingAmount: 'Remaining amount',
|
|
37
40
|
redeemPoints: 'Redeem points',
|
|
38
41
|
remainingPoints: 'Remaining points',
|
|
@@ -40,9 +43,12 @@ var LABELS = {
|
|
|
40
43
|
orderDiscount: 'Order discount',
|
|
41
44
|
manualDiscount: 'Manual discount',
|
|
42
45
|
payProcessingFee: 'Pay processing fee',
|
|
46
|
+
surchargeIncluded: 'Surcharge(Included)',
|
|
43
47
|
rounding: 'Rounding',
|
|
44
48
|
gross: 'Gross',
|
|
45
|
-
tare: 'Tare'
|
|
49
|
+
tare: 'Tare',
|
|
50
|
+
handoverTime: 'Handover time',
|
|
51
|
+
refund: 'Refund'
|
|
46
52
|
},
|
|
47
53
|
zh_CN: {
|
|
48
54
|
contactName: '联系人姓名',
|
|
@@ -56,9 +62,12 @@ var LABELS = {
|
|
|
56
62
|
pickUpTime: '取餐时间',
|
|
57
63
|
asap: '尽快',
|
|
58
64
|
cash: '现金支付',
|
|
65
|
+
cashReceived: '收取现金',
|
|
66
|
+
changeDue: '找零',
|
|
59
67
|
eftpos: '刷卡支付',
|
|
60
68
|
wallet: '钱包支付',
|
|
61
69
|
giftCard: '礼品卡',
|
|
70
|
+
balance: '余额',
|
|
62
71
|
remainingAmount: '剩余金额',
|
|
63
72
|
redeemPoints: '本次使用积分',
|
|
64
73
|
remainingPoints: '剩余积分',
|
|
@@ -66,9 +75,12 @@ var LABELS = {
|
|
|
66
75
|
orderDiscount: '整单折扣',
|
|
67
76
|
manualDiscount: '手动折扣',
|
|
68
77
|
payProcessingFee: '支付手续费',
|
|
78
|
+
surchargeIncluded: '手续费(已含)',
|
|
69
79
|
rounding: '抹零',
|
|
70
80
|
gross: '重量',
|
|
71
|
-
tare: '去皮'
|
|
81
|
+
tare: '去皮',
|
|
82
|
+
handoverTime: '交付时间',
|
|
83
|
+
refund: '退款'
|
|
72
84
|
},
|
|
73
85
|
zh_HK: {
|
|
74
86
|
contactName: '聯絡人姓名',
|
|
@@ -82,9 +94,12 @@ var LABELS = {
|
|
|
82
94
|
pickUpTime: '取餐時間',
|
|
83
95
|
asap: '盡快',
|
|
84
96
|
cash: '現金支付',
|
|
97
|
+
cashReceived: '收取現金',
|
|
98
|
+
changeDue: '找零',
|
|
85
99
|
eftpos: '刷卡支付',
|
|
86
100
|
wallet: '錢包支付',
|
|
87
101
|
giftCard: '禮品卡',
|
|
102
|
+
balance: '餘額',
|
|
88
103
|
remainingAmount: '剩餘金額',
|
|
89
104
|
redeemPoints: '本次使用積分',
|
|
90
105
|
remainingPoints: '剩餘積分',
|
|
@@ -92,9 +107,12 @@ var LABELS = {
|
|
|
92
107
|
orderDiscount: '整單折扣',
|
|
93
108
|
manualDiscount: '手動折扣',
|
|
94
109
|
payProcessingFee: '支付手續費',
|
|
110
|
+
surchargeIncluded: '手續費(已含)',
|
|
95
111
|
rounding: '抹零',
|
|
96
112
|
gross: '重量',
|
|
97
|
-
tare: '去皮'
|
|
113
|
+
tare: '去皮',
|
|
114
|
+
handoverTime: '交付時間',
|
|
115
|
+
refund: '退款'
|
|
98
116
|
},
|
|
99
117
|
ja: {
|
|
100
118
|
contactName: '連絡先名',
|
|
@@ -111,6 +129,7 @@ var LABELS = {
|
|
|
111
129
|
eftpos: 'カード',
|
|
112
130
|
wallet: 'ウォレット',
|
|
113
131
|
giftCard: 'ギフトカード',
|
|
132
|
+
balance: '残高',
|
|
114
133
|
remainingAmount: '残高',
|
|
115
134
|
redeemPoints: '利用ポイント',
|
|
116
135
|
remainingPoints: '残りポイント',
|
|
@@ -120,7 +139,11 @@ var LABELS = {
|
|
|
120
139
|
payProcessingFee: '決済手数料',
|
|
121
140
|
rounding: '端数調整',
|
|
122
141
|
gross: '総重量',
|
|
123
|
-
tare: '風袋'
|
|
142
|
+
tare: '風袋',
|
|
143
|
+
handoverTime: '受け渡し時間',
|
|
144
|
+
refund: '返金',
|
|
145
|
+
cashReceived: 'お預かり',
|
|
146
|
+
changeDue: 'お釣り'
|
|
124
147
|
},
|
|
125
148
|
pt: {
|
|
126
149
|
contactName: 'Nome de contato',
|
|
@@ -137,6 +160,7 @@ var LABELS = {
|
|
|
137
160
|
eftpos: 'Cartão',
|
|
138
161
|
wallet: 'Carteira',
|
|
139
162
|
giftCard: 'Cartão-presente',
|
|
163
|
+
balance: 'Saldo',
|
|
140
164
|
remainingAmount: 'Saldo restante',
|
|
141
165
|
redeemPoints: 'Pontos utilizados',
|
|
142
166
|
remainingPoints: 'Pontos restantes',
|
|
@@ -146,7 +170,11 @@ var LABELS = {
|
|
|
146
170
|
payProcessingFee: 'Taxa de processamento',
|
|
147
171
|
rounding: 'Arredondamento',
|
|
148
172
|
gross: 'Peso bruto',
|
|
149
|
-
tare: 'Tara'
|
|
173
|
+
tare: 'Tara',
|
|
174
|
+
handoverTime: 'Hora de entrega',
|
|
175
|
+
refund: 'Reembolso',
|
|
176
|
+
cashReceived: 'Dinheiro recebido',
|
|
177
|
+
changeDue: 'Troco'
|
|
150
178
|
}
|
|
151
179
|
};
|
|
152
180
|
export function buildSmallTicketData(params) {
|
|
@@ -175,11 +203,15 @@ function buildLocaleData(params) {
|
|
|
175
203
|
var products = buildProducts(order, locale, productMap);
|
|
176
204
|
var summary = getSummary(order);
|
|
177
205
|
var currencySymbol = getCurrencySymbol(order, shopInfo);
|
|
178
|
-
|
|
206
|
+
var financials = resolveReceiptFinancials(order, summary);
|
|
207
|
+
var delivery = buildDelivery(order, locale);
|
|
208
|
+
return _objectSpread(_objectSpread({
|
|
179
209
|
base_data: buildBaseData({
|
|
180
210
|
order: order,
|
|
181
211
|
shopInfo: shopInfo,
|
|
182
|
-
locale: locale
|
|
212
|
+
locale: locale,
|
|
213
|
+
currencySymbol: currencySymbol,
|
|
214
|
+
financials: financials
|
|
183
215
|
}),
|
|
184
216
|
products: products,
|
|
185
217
|
fees: buildFees({
|
|
@@ -188,11 +220,14 @@ function buildLocaleData(params) {
|
|
|
188
220
|
locale: locale,
|
|
189
221
|
products: products,
|
|
190
222
|
summary: summary,
|
|
191
|
-
currencySymbol: currencySymbol
|
|
223
|
+
currencySymbol: currencySymbol,
|
|
224
|
+
financials: financials
|
|
192
225
|
}),
|
|
193
226
|
customer: buildCustomer(order, locale),
|
|
194
|
-
appointment: buildAppointment(order, locale)
|
|
195
|
-
|
|
227
|
+
appointment: buildAppointment(order, locale)
|
|
228
|
+
}, delivery.length ? {
|
|
229
|
+
delivery: delivery
|
|
230
|
+
} : {}), {}, {
|
|
196
231
|
resources: buildResources(order, locale),
|
|
197
232
|
payment_data: buildPaymentData({
|
|
198
233
|
order: order,
|
|
@@ -206,17 +241,23 @@ function buildLocaleData(params) {
|
|
|
206
241
|
}),
|
|
207
242
|
tickets: Array.isArray(order.tickets) ? order.tickets : [],
|
|
208
243
|
source_shop: [],
|
|
209
|
-
refund_data:
|
|
244
|
+
refund_data: buildRefundData({
|
|
245
|
+
order: order,
|
|
246
|
+
locale: locale,
|
|
247
|
+
currencySymbol: currencySymbol
|
|
248
|
+
}),
|
|
210
249
|
expend_data: []
|
|
211
|
-
};
|
|
250
|
+
});
|
|
212
251
|
}
|
|
213
252
|
function buildBaseData(params) {
|
|
214
253
|
var _order$metadata;
|
|
215
254
|
var order = params.order,
|
|
216
255
|
shopInfo = params.shopInfo,
|
|
217
|
-
locale = params.locale
|
|
256
|
+
locale = params.locale,
|
|
257
|
+
currencySymbol = params.currencySymbol,
|
|
258
|
+
financials = params.financials;
|
|
218
259
|
var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
|
|
219
|
-
return _objectSpread({
|
|
260
|
+
return _objectSpread(_objectSpread({
|
|
220
261
|
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
221
262
|
note: stringify(order.note),
|
|
222
263
|
shop_order_number: stringify(order.shop_order_number),
|
|
@@ -224,7 +265,13 @@ function buildBaseData(params) {
|
|
|
224
265
|
shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
|
|
225
266
|
shop_phone: stringify(shopInfo.phone || order.shop_phone),
|
|
226
267
|
shop_address: stringify(shopInfo.receipt_address || shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
|
|
227
|
-
original_payment_status:
|
|
268
|
+
original_payment_status: financials.paymentStatus,
|
|
269
|
+
payment_status: financials.paymentStatus,
|
|
270
|
+
total_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
271
|
+
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol)
|
|
272
|
+
}, isPresentId(financials.amountGap) ? {
|
|
273
|
+
amount_gap: formatMoney(financials.amountGap, currencySymbol)
|
|
274
|
+
} : {}), {}, {
|
|
228
275
|
is_repeat: 0,
|
|
229
276
|
buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
|
|
230
277
|
order_no: orderNumber,
|
|
@@ -274,28 +321,46 @@ function buildProducts(order, locale, productMap) {
|
|
|
274
321
|
quantity: quantity,
|
|
275
322
|
originalPrice: originalPrice
|
|
276
323
|
});
|
|
277
|
-
|
|
324
|
+
var productNote = resolveProductNote(product, locale);
|
|
325
|
+
var basePrice = resolveProductBasePrice(product);
|
|
326
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
278
327
|
product_title: productTitle,
|
|
279
328
|
product_quantity: quantity,
|
|
280
329
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
281
|
-
original_price: formatMoney(originalPrice, currencySymbol)
|
|
330
|
+
original_price: formatMoney(originalPrice, currencySymbol)
|
|
331
|
+
}, isPresentId(basePrice) ? {
|
|
332
|
+
base_price: formatMoney(basePrice, currencySymbol)
|
|
333
|
+
} : {}), {}, {
|
|
282
334
|
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
283
335
|
extension_list: extensionList
|
|
284
336
|
}, isPresentId(productUid) ? {
|
|
285
337
|
product_uid: productUid
|
|
286
338
|
} : {}), isPresentId(bookingUid) ? {
|
|
287
339
|
booking_uid: bookingUid
|
|
340
|
+
} : {}), productNote ? {
|
|
341
|
+
product_note: productNote
|
|
288
342
|
} : {}), options.length ? {
|
|
289
343
|
options: options
|
|
290
344
|
} : {}), resolvedVariant ? {
|
|
291
345
|
variant: resolvedVariant
|
|
292
|
-
} : {}), Array.isArray(product.combinations) ? {
|
|
293
|
-
combinations: product.combinations
|
|
346
|
+
} : {}), Array.isArray(product.combinations) && product.combinations.length ? {
|
|
347
|
+
combinations: normalizeExistingCombinations(product.combinations, locale)
|
|
294
348
|
} : combinations.length ? {
|
|
295
349
|
combinations: combinations
|
|
296
350
|
} : {});
|
|
297
351
|
});
|
|
298
352
|
}
|
|
353
|
+
function resolveProductBasePrice(product) {
|
|
354
|
+
var _product$product_vari, _product$_origin, _product$_origin2;
|
|
355
|
+
var metadata = product.metadata || {};
|
|
356
|
+
var origin = product._origin || metadata.origin || {};
|
|
357
|
+
var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
|
|
358
|
+
var variant = Array.isArray(origin.variant) && isPresentId(variantId) ? origin.variant.find(function (item) {
|
|
359
|
+
return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
|
|
360
|
+
}) : undefined;
|
|
361
|
+
var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
|
|
362
|
+
return firstPresentValue(metadata.source_product_price, variant === null || variant === void 0 ? void 0 : variant.price, (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.price, (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
|
|
363
|
+
}
|
|
299
364
|
function normalizeProductDiscounts(params) {
|
|
300
365
|
var product = params.product,
|
|
301
366
|
locale = params.locale,
|
|
@@ -455,15 +520,42 @@ function normalizeProductCombinations(params) {
|
|
|
455
520
|
locale: locale,
|
|
456
521
|
parentProduct: parentProduct
|
|
457
522
|
});
|
|
458
|
-
var
|
|
459
|
-
|
|
460
|
-
|
|
523
|
+
var productNote = resolveProductNote(bundle, locale);
|
|
524
|
+
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
|
|
525
|
+
return _objectSpread(_objectSpread({
|
|
526
|
+
product_title: baseTitle,
|
|
461
527
|
product_quantity: toNumber((_ref15 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref15 !== void 0 ? _ref15 : 1, 1),
|
|
462
528
|
price: formatBundlePrice(bundle, currencySymbol),
|
|
463
529
|
combinations_options: combinationsOptions
|
|
464
|
-
}
|
|
530
|
+
}, productNote ? {
|
|
531
|
+
product_note: productNote
|
|
532
|
+
} : {}), nestedCombinations.length ? {
|
|
533
|
+
combinations: nestedCombinations
|
|
534
|
+
} : {});
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
function normalizeExistingCombinations(combinations, locale) {
|
|
538
|
+
return combinations.map(function (combination) {
|
|
539
|
+
if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
|
|
540
|
+
return combination;
|
|
541
|
+
}
|
|
542
|
+
var productNote = resolveProductNote(combination, locale);
|
|
543
|
+
var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale) : undefined;
|
|
544
|
+
var snapshot = _objectSpread({}, combination);
|
|
545
|
+
delete snapshot.product_note;
|
|
546
|
+
delete snapshot.note;
|
|
547
|
+
return _objectSpread(_objectSpread(_objectSpread({}, snapshot), productNote ? {
|
|
548
|
+
product_note: productNote
|
|
549
|
+
} : {}), nestedCombinations ? {
|
|
550
|
+
combinations: nestedCombinations
|
|
551
|
+
} : {});
|
|
465
552
|
});
|
|
466
553
|
}
|
|
554
|
+
function resolveProductNote(product, locale) {
|
|
555
|
+
var productNote = getLocalizedValue(product.product_note, locale).trim();
|
|
556
|
+
if (productNote) return productNote;
|
|
557
|
+
return getLocalizedValue(product.note, locale).trim();
|
|
558
|
+
}
|
|
467
559
|
function resolveBundleProductTitle(params) {
|
|
468
560
|
var _ref16, _ref17, _bundle$bundle_produc;
|
|
469
561
|
var bundle = params.bundle,
|
|
@@ -488,13 +580,13 @@ function resolveProductFromMap(productId, productMap) {
|
|
|
488
580
|
return productMap[productId] || productMap[String(productId)] || null;
|
|
489
581
|
}
|
|
490
582
|
function resolveProductVariantText(params) {
|
|
491
|
-
var _product$
|
|
583
|
+
var _product$product_vari2;
|
|
492
584
|
var product = params.product,
|
|
493
585
|
parentProduct = params.parentProduct,
|
|
494
586
|
locale = params.locale;
|
|
495
587
|
if (product.variant) return getLocalizedValue(product.variant, locale);
|
|
496
588
|
if (!parentProduct) return '';
|
|
497
|
-
var productVariantId = (_product$
|
|
589
|
+
var productVariantId = (_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : product.variant_id;
|
|
498
590
|
if (!isNonZeroId(productVariantId)) return '';
|
|
499
591
|
var matchedVariant = normalizeArray(parentProduct.variant).find(function (variant) {
|
|
500
592
|
return isSameId(variant.id, productVariantId);
|
|
@@ -678,16 +770,6 @@ function isSameId(left, right) {
|
|
|
678
770
|
if (!isPresentId(left) || !isPresentId(right)) return false;
|
|
679
771
|
return String(left) === String(right);
|
|
680
772
|
}
|
|
681
|
-
function buildOptionTitleSuffix(options) {
|
|
682
|
-
var text = options.map(function (option) {
|
|
683
|
-
var _option$num2;
|
|
684
|
-
var name = stringify(option.name).trim();
|
|
685
|
-
if (!name) return '';
|
|
686
|
-
var quantity = (_option$num2 = option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1;
|
|
687
|
-
return "".concat(name, " x ").concat(quantity);
|
|
688
|
-
}).filter(Boolean).join(', ');
|
|
689
|
-
return text ? "(".concat(text, ")") : '';
|
|
690
|
-
}
|
|
691
773
|
function formatBundlePrice(bundle, currencySymbol) {
|
|
692
774
|
var _ref33, _ref34, _bundle$bundle_sellin;
|
|
693
775
|
var value = (_ref33 = (_ref34 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref34 !== void 0 ? _ref34 : bundle.price) !== null && _ref33 !== void 0 ? _ref33 : 0;
|
|
@@ -698,13 +780,14 @@ function formatBundlePrice(bundle, currencySymbol) {
|
|
|
698
780
|
return formatMoney(amount, currencySymbol);
|
|
699
781
|
}
|
|
700
782
|
function buildFees(params) {
|
|
701
|
-
var
|
|
783
|
+
var _firstPresentValue, _firstPresentValue2;
|
|
702
784
|
var order = params.order,
|
|
703
785
|
shopInfo = params.shopInfo,
|
|
704
786
|
locale = params.locale,
|
|
705
787
|
products = params.products,
|
|
706
788
|
summary = params.summary,
|
|
707
|
-
currencySymbol = params.currencySymbol
|
|
789
|
+
currencySymbol = params.currencySymbol,
|
|
790
|
+
financials = params.financials;
|
|
708
791
|
var fees = [];
|
|
709
792
|
for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
|
|
710
793
|
var _ref35, _surcharge$amount;
|
|
@@ -716,67 +799,108 @@ function buildFees(params) {
|
|
|
716
799
|
value: formatMoney(value, currencySymbol)
|
|
717
800
|
});
|
|
718
801
|
}
|
|
719
|
-
var discountAmount = (
|
|
802
|
+
var discountAmount = firstPresentValue(order.shop_discount, summary.discount_amount, order.discount_amount);
|
|
720
803
|
if (isNonZero(discountAmount)) {
|
|
721
804
|
fees.push({
|
|
722
805
|
item: label(locale, 'orderDiscount'),
|
|
723
806
|
value: formatNegativeMoney(discountAmount, currencySymbol)
|
|
724
807
|
});
|
|
725
808
|
}
|
|
726
|
-
var taxFee = summary.tax_fee
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
var
|
|
809
|
+
var taxFee = firstPresentValue(summary.tax_fee, order.tax_fee);
|
|
810
|
+
var taxTitle = resolveTaxTitle({
|
|
811
|
+
summary: summary,
|
|
812
|
+
order: order,
|
|
813
|
+
shopInfo: shopInfo,
|
|
814
|
+
locale: locale
|
|
815
|
+
});
|
|
816
|
+
var isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
|
|
817
|
+
var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
|
|
734
818
|
if (isNonZero(roundingAmount)) {
|
|
735
819
|
fees.push({
|
|
736
820
|
item: label(locale, 'rounding'),
|
|
737
821
|
value: formatMoney(roundingAmount, currencySymbol)
|
|
738
822
|
});
|
|
739
823
|
}
|
|
740
|
-
var payProcessingFee =
|
|
824
|
+
var payProcessingFee = financials.payProcessingFee;
|
|
741
825
|
if (isNonZero(payProcessingFee)) {
|
|
742
826
|
fees.push({
|
|
743
827
|
item: label(locale, 'payProcessingFee'),
|
|
744
828
|
value: formatMoney(payProcessingFee, currencySymbol)
|
|
745
829
|
});
|
|
746
830
|
}
|
|
747
|
-
var productExpectAmount = summary.product_expect_amount
|
|
831
|
+
var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
|
|
748
832
|
var productOriginalAmount = (_firstPresentValue = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : calculateProductOriginalAmount(order);
|
|
749
833
|
var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
|
|
750
834
|
return {
|
|
751
835
|
fees: fees,
|
|
752
|
-
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
753
|
-
total_amount: formatMoney(summary.total_amount
|
|
836
|
+
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
837
|
+
total_amount: formatMoney((_firstPresentValue2 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : 0, currencySymbol),
|
|
754
838
|
original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
|
|
755
|
-
product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
|
|
756
|
-
expect_amount: formatMoney(
|
|
757
|
-
product_quantity: toNumber(summary.product_quantity
|
|
839
|
+
product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
|
|
840
|
+
expect_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
841
|
+
product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
|
|
758
842
|
return sum + product.product_quantity;
|
|
759
|
-
}, 0), 0),
|
|
760
|
-
has_pay: formatMoney(
|
|
843
|
+
}, 0)), 0),
|
|
844
|
+
has_pay: formatMoney(financials.orderPaidAmount, currencySymbol),
|
|
761
845
|
payment_method: '',
|
|
762
|
-
tax_title:
|
|
763
|
-
total_refund_amount: formatMoney(
|
|
764
|
-
|
|
846
|
+
tax_title: taxTitle,
|
|
847
|
+
total_refund_amount: formatMoney(financials.totalRefundAmount, currencySymbol),
|
|
848
|
+
customer_paid_amount: formatMoney(financials.customerPaidAmount, currencySymbol),
|
|
849
|
+
net_payment_applied: formatMoney(financials.netPaymentApplied, currencySymbol)
|
|
850
|
+
}, isPresentId(roundingAmount) ? {
|
|
765
851
|
rounding_amount: formatMoney(roundingAmount, currencySymbol)
|
|
766
852
|
} : {}), isNonZero(totalSavingsAmount) ? {
|
|
767
853
|
order_total_discount: formatMoney(totalSavingsAmount, currencySymbol)
|
|
768
|
-
} : {}),
|
|
854
|
+
} : {}), financials.hasPayProcessingFee ? {
|
|
769
855
|
pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
|
|
770
|
-
} : {}),
|
|
856
|
+
} : {}), isPresentId(taxFee) ? {
|
|
771
857
|
tax_fee: formatMoney(taxFee, currencySymbol)
|
|
858
|
+
} : {}), isPresentId(isPriceIncludeTax) ? {
|
|
859
|
+
is_price_include_tax: normalizeBooleanFlag(isPriceIncludeTax)
|
|
772
860
|
} : {})
|
|
773
861
|
};
|
|
774
862
|
}
|
|
863
|
+
function resolveReceiptFinancials(order, summary) {
|
|
864
|
+
var _firstPresentValue3, _firstPresentValue4, _firstPresentValue5, _firstPresentValue6;
|
|
865
|
+
var totalAmount = (_firstPresentValue3 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0;
|
|
866
|
+
var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
|
|
867
|
+
var payProcessingFee = rawPayProcessingFee !== null && rawPayProcessingFee !== void 0 ? rawPayProcessingFee : 0;
|
|
868
|
+
var orderPaidAmount = (_firstPresentValue4 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
|
|
869
|
+
var totalRefundAmount = (_firstPresentValue5 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
|
|
870
|
+
var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
|
|
871
|
+
var fallbackCustomerPaidAmount = Decimal.max(sumCustomerPaidPayments(order.payments), new Decimal(toMoneyNumber(orderPaidAmount)).plus(toMoneyNumber(payProcessingFee)));
|
|
872
|
+
var customerPaidAmount = (_firstPresentValue6 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
|
|
873
|
+
var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
|
|
874
|
+
return {
|
|
875
|
+
totalAmount: totalAmount,
|
|
876
|
+
orderPaidAmount: orderPaidAmount,
|
|
877
|
+
payProcessingFee: payProcessingFee,
|
|
878
|
+
customerPaidAmount: customerPaidAmount,
|
|
879
|
+
totalRefundAmount: totalRefundAmount,
|
|
880
|
+
netPaymentApplied: netPaymentApplied,
|
|
881
|
+
amountGap: amountGap,
|
|
882
|
+
paymentStatus: resolveReceiptPaymentStatus({
|
|
883
|
+
order: order,
|
|
884
|
+
summary: summary
|
|
885
|
+
}),
|
|
886
|
+
hasPayProcessingFee: isPresentId(rawPayProcessingFee)
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
function resolveReceiptPaymentStatus(params) {
|
|
890
|
+
return [params.order.payment_status, params.summary.payment_status, params.order.original_payment_status].map(function (status) {
|
|
891
|
+
return stringify(status).trim();
|
|
892
|
+
}).find(Boolean) || '';
|
|
893
|
+
}
|
|
894
|
+
function resolveTaxTitle(params) {
|
|
895
|
+
return [params.summary.tax_title, params.order.tax_title, params.shopInfo.tax_title].map(function (title) {
|
|
896
|
+
return getLocalizedValue(title, params.locale).trim();
|
|
897
|
+
}).find(Boolean) || 'Tax';
|
|
898
|
+
}
|
|
775
899
|
function calculateProductOriginalAmount(order) {
|
|
776
900
|
return normalizeArray(order.products).reduce(function (total, product) {
|
|
777
|
-
var
|
|
778
|
-
var quantity = toNumber((
|
|
779
|
-
var originalPrice = (
|
|
901
|
+
var _ref36, _ref37, _product$product_quan2, _ref38, _ref39, _ref40, _product$original_pri2;
|
|
902
|
+
var quantity = toNumber((_ref36 = (_ref37 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref37 !== void 0 ? _ref37 : product.num) !== null && _ref36 !== void 0 ? _ref36 : 1, 1);
|
|
903
|
+
var originalPrice = (_ref38 = (_ref39 = (_ref40 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref40 !== void 0 ? _ref40 : product.payment_price) !== null && _ref39 !== void 0 ? _ref39 : product.price) !== null && _ref38 !== void 0 ? _ref38 : 0;
|
|
780
904
|
return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
|
|
781
905
|
}, new Decimal(0));
|
|
782
906
|
}
|
|
@@ -800,27 +924,29 @@ function normalizeCustomerDisplayValue(value) {
|
|
|
800
924
|
return text;
|
|
801
925
|
}
|
|
802
926
|
function buildDelivery(order, locale) {
|
|
803
|
-
var _order$metadata2;
|
|
804
|
-
var
|
|
805
|
-
|
|
806
|
-
var serviceTypeLabelKey =
|
|
927
|
+
var _order$metadata2, _order$metadata3, _order$metadata4, _order$metadata5, _order$metadata6, _order$metadata7, _order$metadata8, _order$metadata9, _order$metadata10, _order$metadata11, _order$metadata12;
|
|
928
|
+
var deliveryType = stringify(order.delivery_type).trim();
|
|
929
|
+
var serviceType = deliveryType || stringify(firstPresentValue((_order$metadata2 = order.metadata) === null || _order$metadata2 === void 0 ? void 0 : _order$metadata2.service_type, order.service_type)).trim();
|
|
930
|
+
var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType, order);
|
|
931
|
+
if (!serviceTypeLabelKey) return [];
|
|
807
932
|
var items = [{
|
|
808
933
|
item: '',
|
|
809
934
|
value: label(locale, serviceTypeLabelKey),
|
|
810
935
|
size: 2,
|
|
811
936
|
align: 'left'
|
|
812
937
|
}];
|
|
813
|
-
|
|
938
|
+
var handoverTime = firstPresentValue(order.handover_time, order.handover_at, order.pickup_time, order.pickup_at, order.scheduled_pickup_time, order.delivery_time, order.delivery_at, order.scheduled_delivery_time, order.fulfillment_time, order.fulfillment_at, (_order$metadata3 = order.metadata) === null || _order$metadata3 === void 0 ? void 0 : _order$metadata3.handover_time, (_order$metadata4 = order.metadata) === null || _order$metadata4 === void 0 ? void 0 : _order$metadata4.handover_at, (_order$metadata5 = order.metadata) === null || _order$metadata5 === void 0 ? void 0 : _order$metadata5.pickup_time, (_order$metadata6 = order.metadata) === null || _order$metadata6 === void 0 ? void 0 : _order$metadata6.pickup_at, (_order$metadata7 = order.metadata) === null || _order$metadata7 === void 0 ? void 0 : _order$metadata7.scheduled_pickup_time, (_order$metadata8 = order.metadata) === null || _order$metadata8 === void 0 ? void 0 : _order$metadata8.delivery_time, (_order$metadata9 = order.metadata) === null || _order$metadata9 === void 0 ? void 0 : _order$metadata9.delivery_at, (_order$metadata10 = order.metadata) === null || _order$metadata10 === void 0 ? void 0 : _order$metadata10.scheduled_delivery_time, (_order$metadata11 = order.metadata) === null || _order$metadata11 === void 0 ? void 0 : _order$metadata11.fulfillment_time, (_order$metadata12 = order.metadata) === null || _order$metadata12 === void 0 ? void 0 : _order$metadata12.fulfillment_at);
|
|
939
|
+
if (isPresentId(handoverTime)) {
|
|
814
940
|
items.push({
|
|
815
|
-
item: label(locale, '
|
|
816
|
-
value:
|
|
941
|
+
item: label(locale, 'handoverTime'),
|
|
942
|
+
value: formatDateTime(handoverTime, locale)
|
|
817
943
|
});
|
|
818
944
|
}
|
|
819
945
|
return items;
|
|
820
946
|
}
|
|
821
947
|
function buildAppointment(order, locale) {
|
|
822
|
-
var _order$
|
|
823
|
-
var bookings = normalizeArray(order.bookings);
|
|
948
|
+
var _order$metadata13, _order$metadata14, _order$form_data;
|
|
949
|
+
var bookings = sortBookings(normalizeArray(order.bookings));
|
|
824
950
|
if (bookings.length) {
|
|
825
951
|
return bookings.map(function (booking) {
|
|
826
952
|
var _booking$metadata, _booking$metadata2;
|
|
@@ -836,13 +962,57 @@ function buildAppointment(order, locale) {
|
|
|
836
962
|
} : {});
|
|
837
963
|
});
|
|
838
964
|
}
|
|
839
|
-
var tableName = order.table_name || ((_order$
|
|
965
|
+
var tableName = order.table_name || ((_order$metadata13 = order.metadata) === null || _order$metadata13 === void 0 ? void 0 : _order$metadata13.table_name) || ((_order$metadata14 = order.metadata) === null || _order$metadata14 === void 0 || (_order$metadata14 = _order$metadata14.table) === null || _order$metadata14 === void 0 ? void 0 : _order$metadata14.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
|
|
840
966
|
if (!tableName) return [];
|
|
841
967
|
return [{
|
|
842
968
|
item: label(locale, 'table'),
|
|
843
969
|
value: getLocalizedValue(tableName, locale)
|
|
844
970
|
}];
|
|
845
971
|
}
|
|
972
|
+
function sortBookings(bookings) {
|
|
973
|
+
return bookings.map(function (booking, index) {
|
|
974
|
+
return {
|
|
975
|
+
booking: booking,
|
|
976
|
+
index: index
|
|
977
|
+
};
|
|
978
|
+
}).sort(function (left, right) {
|
|
979
|
+
var _left$booking2, _left$booking3, _right$booking2, _right$booking3;
|
|
980
|
+
var leftStart = bookingStartTimestamp(left.booking);
|
|
981
|
+
var rightStart = bookingStartTimestamp(right.booking);
|
|
982
|
+
if (leftStart !== rightStart) return leftStart < rightStart ? -1 : 1;
|
|
983
|
+
for (var _i2 = 0, _arr = ['booking_id', 'schedule_event_id']; _i2 < _arr.length; _i2++) {
|
|
984
|
+
var _left$booking, _right$booking;
|
|
985
|
+
var field = _arr[_i2];
|
|
986
|
+
var fieldOrder = compareOptionalValues((_left$booking = left.booking) === null || _left$booking === void 0 ? void 0 : _left$booking[field], (_right$booking = right.booking) === null || _right$booking === void 0 ? void 0 : _right$booking[field]);
|
|
987
|
+
if (fieldOrder !== 0) return fieldOrder;
|
|
988
|
+
}
|
|
989
|
+
var bookingUidOrder = compareOptionalValues(firstPresentValue((_left$booking2 = left.booking) === null || _left$booking2 === void 0 || (_left$booking2 = _left$booking2.metadata) === null || _left$booking2 === void 0 ? void 0 : _left$booking2.unique_identification_number, (_left$booking3 = left.booking) === null || _left$booking3 === void 0 ? void 0 : _left$booking3.booking_uid), firstPresentValue((_right$booking2 = right.booking) === null || _right$booking2 === void 0 || (_right$booking2 = _right$booking2.metadata) === null || _right$booking2 === void 0 ? void 0 : _right$booking2.unique_identification_number, (_right$booking3 = right.booking) === null || _right$booking3 === void 0 ? void 0 : _right$booking3.booking_uid));
|
|
990
|
+
return bookingUidOrder || left.index - right.index;
|
|
991
|
+
}).map(function (_ref41) {
|
|
992
|
+
var booking = _ref41.booking;
|
|
993
|
+
return booking;
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
function bookingStartTimestamp(booking) {
|
|
997
|
+
var startValues = [booking === null || booking === void 0 ? void 0 : booking.start_at, booking === null || booking === void 0 ? void 0 : booking.start_datetime, booking === null || booking === void 0 ? void 0 : booking.booking_time, isPresentId(booking === null || booking === void 0 ? void 0 : booking.start_date) ? "".concat(booking.start_date, " ").concat(stringify(booking.start_time)).trim() : undefined];
|
|
998
|
+
for (var _i3 = 0, _startValues = startValues; _i3 < _startValues.length; _i3++) {
|
|
999
|
+
var startValue = _startValues[_i3];
|
|
1000
|
+
if (!isPresentId(startValue)) continue;
|
|
1001
|
+
var timestamp = dayjs(startValue).valueOf();
|
|
1002
|
+
if (Number.isFinite(timestamp)) return timestamp;
|
|
1003
|
+
}
|
|
1004
|
+
return Number.POSITIVE_INFINITY;
|
|
1005
|
+
}
|
|
1006
|
+
function compareOptionalValues(left, right) {
|
|
1007
|
+
var hasLeft = isPresentId(left);
|
|
1008
|
+
var hasRight = isPresentId(right);
|
|
1009
|
+
if (!hasLeft && !hasRight) return 0;
|
|
1010
|
+
if (!hasLeft) return 1;
|
|
1011
|
+
if (!hasRight) return -1;
|
|
1012
|
+
return String(left).localeCompare(String(right), undefined, {
|
|
1013
|
+
numeric: true
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
846
1016
|
function buildResources(order, locale) {
|
|
847
1017
|
return normalizeArray(order.resources || order.resource_list).map(function (resource) {
|
|
848
1018
|
return {
|
|
@@ -866,8 +1036,91 @@ function buildPaymentData(params) {
|
|
|
866
1036
|
});
|
|
867
1037
|
});
|
|
868
1038
|
}
|
|
1039
|
+
function buildRefundData(params) {
|
|
1040
|
+
var payments = normalizeArray(params.order.payments);
|
|
1041
|
+
var refunds = Array.from(normalizeArray(params.order.refunds).reduce(function (result, refund, index) {
|
|
1042
|
+
var identity = refundIdentity(refund, index);
|
|
1043
|
+
var candidate = {
|
|
1044
|
+
refund: refund,
|
|
1045
|
+
index: index
|
|
1046
|
+
};
|
|
1047
|
+
var existing = result.get(identity);
|
|
1048
|
+
if (!existing || shouldPreferRefundCandidate(candidate, existing)) {
|
|
1049
|
+
result.set(identity, candidate);
|
|
1050
|
+
}
|
|
1051
|
+
return result;
|
|
1052
|
+
}, new Map()).values()).filter(function (_ref42) {
|
|
1053
|
+
var refund = _ref42.refund;
|
|
1054
|
+
return isPrintableRefund(refund);
|
|
1055
|
+
}).sort(function (left, right) {
|
|
1056
|
+
var leftTime = refundTimestamp(left.refund);
|
|
1057
|
+
var rightTime = refundTimestamp(right.refund);
|
|
1058
|
+
if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
|
|
1059
|
+
return left.index - right.index;
|
|
1060
|
+
});
|
|
1061
|
+
return refunds.map(function (_ref43) {
|
|
1062
|
+
var _firstPresentValue7;
|
|
1063
|
+
var refund = _ref43.refund;
|
|
1064
|
+
var payment = resolveRefundPayment(refund, payments);
|
|
1065
|
+
var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
|
|
1066
|
+
var amount = (_firstPresentValue7 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
|
|
1067
|
+
var items = [{
|
|
1068
|
+
item: methodName,
|
|
1069
|
+
value: formatNegativeMoney(amount, params.currencySymbol)
|
|
1070
|
+
}];
|
|
1071
|
+
var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
|
|
1072
|
+
if (isPresentId(occurredAt)) {
|
|
1073
|
+
items.push({
|
|
1074
|
+
item: formatDateTime(occurredAt, params.locale),
|
|
1075
|
+
value: ''
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
return items;
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
function refundIdentity(refund, index) {
|
|
1082
|
+
if (isPresentId(refund.order_refund_id)) return "refund-id:".concat(refund.order_refund_id);
|
|
1083
|
+
if (isPresentId(refund.refund_number)) return "refund-number:".concat(refund.refund_number);
|
|
1084
|
+
return "refund-index:".concat(index);
|
|
1085
|
+
}
|
|
1086
|
+
function shouldPreferRefundCandidate(candidate, existing) {
|
|
1087
|
+
var candidatePrintable = isPrintableRefund(candidate.refund);
|
|
1088
|
+
var existingPrintable = isPrintableRefund(existing.refund);
|
|
1089
|
+
if (candidatePrintable !== existingPrintable) return candidatePrintable;
|
|
1090
|
+
var candidateTime = refundFreshnessTimestamp(candidate.refund);
|
|
1091
|
+
var existingTime = refundFreshnessTimestamp(existing.refund);
|
|
1092
|
+
if (candidateTime !== existingTime) return candidateTime > existingTime;
|
|
1093
|
+
return candidate.index > existing.index;
|
|
1094
|
+
}
|
|
1095
|
+
function refundFreshnessTimestamp(refund) {
|
|
1096
|
+
var timestampValue = firstPresentValue(refund.updated_at, refund.refunded_at, refund.refund_time, refund.created_at);
|
|
1097
|
+
if (!isPresentId(timestampValue)) return Number.NEGATIVE_INFINITY;
|
|
1098
|
+
var timestamp = dayjs(timestampValue).valueOf();
|
|
1099
|
+
return Number.isFinite(timestamp) ? timestamp : Number.NEGATIVE_INFINITY;
|
|
1100
|
+
}
|
|
1101
|
+
function refundTimestamp(refund) {
|
|
1102
|
+
var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
|
|
1103
|
+
if (!isPresentId(occurredAt)) return Number.POSITIVE_INFINITY;
|
|
1104
|
+
var timestamp = dayjs(occurredAt).valueOf();
|
|
1105
|
+
return Number.isFinite(timestamp) ? timestamp : Number.POSITIVE_INFINITY;
|
|
1106
|
+
}
|
|
1107
|
+
function isPrintableRefund(refund) {
|
|
1108
|
+
var status = stringify(refund.status).trim().toLowerCase();
|
|
1109
|
+
if (!status) return true;
|
|
1110
|
+
return !['pending', 'payment_pending', 'payment_processing', 'refund_processing', 'processing', 'failed', 'error', 'cancelled', 'canceled', 'voided'].includes(status);
|
|
1111
|
+
}
|
|
1112
|
+
function resolveRefundPayment(refund, payments) {
|
|
1113
|
+
if (refund.payment && _typeof(refund.payment) === 'object' && !Array.isArray(refund.payment)) {
|
|
1114
|
+
return refund.payment;
|
|
1115
|
+
}
|
|
1116
|
+
var orderPaymentId = firstPresentValue(refund.order_payment_id, refund.payment_id);
|
|
1117
|
+
var matchedPayment = payments.find(function (payment) {
|
|
1118
|
+
return isSameId(firstPresentValue(payment.order_payment_id, payment.id), orderPaymentId);
|
|
1119
|
+
});
|
|
1120
|
+
return matchedPayment || refund;
|
|
1121
|
+
}
|
|
869
1122
|
function buildWallets(params) {
|
|
870
|
-
|
|
1123
|
+
var paymentWallets = normalizeArray(params.order.payments).filter(function (payment) {
|
|
871
1124
|
return isPrintablePayment(payment) && !!getFundRecord(payment);
|
|
872
1125
|
}).map(function (payment) {
|
|
873
1126
|
return buildPaymentItems({
|
|
@@ -877,17 +1130,87 @@ function buildWallets(params) {
|
|
|
877
1130
|
includeFundRecordBalance: true
|
|
878
1131
|
});
|
|
879
1132
|
});
|
|
1133
|
+
return [].concat(_toConsumableArray(paymentWallets), _toConsumableArray(buildVoucherAssets(params)));
|
|
1134
|
+
}
|
|
1135
|
+
function buildVoucherAssets(params) {
|
|
1136
|
+
var seenVoucherKeys = new Set();
|
|
1137
|
+
return normalizeArray(params.order.vouchers).flatMap(function (voucher, index) {
|
|
1138
|
+
if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
|
|
1139
|
+
var voucherKey = getVoucherAssetKey(voucher, index);
|
|
1140
|
+
if (seenVoucherKeys.has(voucherKey)) return [];
|
|
1141
|
+
seenVoucherKeys.add(voucherKey);
|
|
1142
|
+
var name = getVoucherAssetName(voucher, params.locale);
|
|
1143
|
+
var percent = getVoucherDiscountPercent(voucher);
|
|
1144
|
+
if (percent) {
|
|
1145
|
+
return [[{
|
|
1146
|
+
item: appendPercentToVoucherName(name, percent),
|
|
1147
|
+
value: formatVoucherDiscount(percent, params.locale)
|
|
1148
|
+
}]];
|
|
1149
|
+
}
|
|
1150
|
+
var balance = getVoucherBalance(voucher);
|
|
1151
|
+
return [[{
|
|
1152
|
+
item: name,
|
|
1153
|
+
value: ''
|
|
1154
|
+
}, {
|
|
1155
|
+
item: label(params.locale, 'balance'),
|
|
1156
|
+
value: formatMoney(balance, params.currencySymbol)
|
|
1157
|
+
}]];
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
function getVoucherAssetKey(voucher, index) {
|
|
1161
|
+
var identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
|
|
1162
|
+
return identity === undefined ? "voucher-index:".concat(index) : "voucher:".concat(String(identity));
|
|
1163
|
+
}
|
|
1164
|
+
function getVoucherAssetName(voucher, locale) {
|
|
1165
|
+
return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
|
|
1166
|
+
}
|
|
1167
|
+
function getVoucherDiscountPercent(voucher) {
|
|
1168
|
+
var _voucher$metadata;
|
|
1169
|
+
var discountType = stringify(((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.discount_card_type) || voucher.discount_card_type).toLowerCase();
|
|
1170
|
+
if (discountType !== 'percent' && discountType !== 'percentage') return null;
|
|
1171
|
+
var percent = new Decimal(toMoneyNumber(voucher.par_value));
|
|
1172
|
+
if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
|
|
1173
|
+
return percent;
|
|
1174
|
+
}
|
|
1175
|
+
function appendPercentToVoucherName(name, percent) {
|
|
1176
|
+
if (/\d+(?:\.\d+)?\s*(?:%|折)|\boff\b/i.test(name)) return name;
|
|
1177
|
+
var separator = /^(?:[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FD-\u30FF\u31F0-\u31FF\u32D0-\u32FE\u3300-\u3357\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFA6D\uFA70-\uFAD9\uFF66-\uFF6F\uFF71-\uFF9D]|\uD81B[\uDFE2\uDFE3\uDFF0\uDFF1]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67]|\uD83C\uDE00|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])/.test(name) ? '' : ' ';
|
|
1178
|
+
return "".concat(trimDecimal(percent), "%").concat(separator).concat(name);
|
|
1179
|
+
}
|
|
1180
|
+
function formatVoucherDiscount(percent, locale) {
|
|
1181
|
+
var normalizedLocale = normalizeLocaleKey(locale);
|
|
1182
|
+
if (normalizedLocale === 'zh_CN' || normalizedLocale === 'zh_HK') {
|
|
1183
|
+
return "".concat(trimDecimal(percent), "% OFF");
|
|
1184
|
+
}
|
|
1185
|
+
if (normalizedLocale === 'pt') return "Desconto ".concat(trimDecimal(percent), "%");
|
|
1186
|
+
return normalizedLocale === 'en' ? "Discount ".concat(trimDecimal(percent), "% OFF") : "".concat(trimDecimal(percent), "% OFF");
|
|
1187
|
+
}
|
|
1188
|
+
function getVoucherBalance(voucher) {
|
|
1189
|
+
var parValue = new Decimal(toMoneyNumber(voucher.par_value));
|
|
1190
|
+
var usedParValue = new Decimal(toMoneyNumber(voucher.used_par_value));
|
|
1191
|
+
return Decimal.max(parValue.minus(usedParValue), 0);
|
|
880
1192
|
}
|
|
881
1193
|
function buildPaymentItems(params) {
|
|
882
|
-
var _payment$amount;
|
|
883
1194
|
var payment = params.payment,
|
|
884
1195
|
locale = params.locale,
|
|
885
1196
|
currencySymbol = params.currencySymbol,
|
|
886
1197
|
includeFundRecordBalance = params.includeFundRecordBalance;
|
|
1198
|
+
var serviceFee = getPaymentServiceFee(payment);
|
|
887
1199
|
var items = [{
|
|
888
1200
|
item: paymentMethodName(payment, locale),
|
|
889
|
-
value: formatMoney((
|
|
1201
|
+
value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
|
|
890
1202
|
}];
|
|
1203
|
+
items.push.apply(items, _toConsumableArray(buildCashChangePaymentItems({
|
|
1204
|
+
payment: payment,
|
|
1205
|
+
locale: locale,
|
|
1206
|
+
currencySymbol: currencySymbol
|
|
1207
|
+
})));
|
|
1208
|
+
if (serviceFee.gt(0)) {
|
|
1209
|
+
items.push({
|
|
1210
|
+
item: label(locale, 'surchargeIncluded'),
|
|
1211
|
+
value: formatMoney(serviceFee, currencySymbol)
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
891
1214
|
var fundRecord = getFundRecord(payment);
|
|
892
1215
|
if (fundRecord) {
|
|
893
1216
|
items.push.apply(items, _toConsumableArray(buildFundRecordPaymentItems({
|
|
@@ -898,8 +1221,8 @@ function buildPaymentItems(params) {
|
|
|
898
1221
|
includeBalance: includeFundRecordBalance
|
|
899
1222
|
})));
|
|
900
1223
|
} else {
|
|
901
|
-
var
|
|
902
|
-
var remainingAmount = (
|
|
1224
|
+
var _ref44, _payment$remaining_am, _payment$metadata;
|
|
1225
|
+
var remainingAmount = (_ref44 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref44 !== void 0 ? _ref44 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
|
|
903
1226
|
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
904
1227
|
items.push({
|
|
905
1228
|
item: label(locale, 'remainingAmount'),
|
|
@@ -913,6 +1236,47 @@ function buildPaymentItems(params) {
|
|
|
913
1236
|
});
|
|
914
1237
|
return items;
|
|
915
1238
|
}
|
|
1239
|
+
function getPaymentServiceFee(payment) {
|
|
1240
|
+
return new Decimal(toMoneyNumber(payment.service_fee));
|
|
1241
|
+
}
|
|
1242
|
+
function resolveReceiptPaymentAmount(payment, serviceFee) {
|
|
1243
|
+
var _payment$amount;
|
|
1244
|
+
var amount = new Decimal(toMoneyNumber((_payment$amount = payment.amount) !== null && _payment$amount !== void 0 ? _payment$amount : payment.origin_amount));
|
|
1245
|
+
var hasAmount = payment.amount !== undefined && payment.amount !== null && payment.amount !== '';
|
|
1246
|
+
var hasOriginAmount = payment.origin_amount !== undefined && payment.origin_amount !== null && payment.origin_amount !== '';
|
|
1247
|
+
if (!hasAmount || !hasOriginAmount || serviceFee.lte(0)) return amount;
|
|
1248
|
+
var originAmount = new Decimal(toMoneyNumber(payment.origin_amount));
|
|
1249
|
+
return amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
|
|
1250
|
+
}
|
|
1251
|
+
function buildCashChangePaymentItems(params) {
|
|
1252
|
+
var payment = params.payment,
|
|
1253
|
+
locale = params.locale,
|
|
1254
|
+
currencySymbol = params.currencySymbol;
|
|
1255
|
+
if (!shouldDisplayCashChange(payment)) return [];
|
|
1256
|
+
return [{
|
|
1257
|
+
item: label(locale, 'cashReceived'),
|
|
1258
|
+
value: formatMoney(payment.metadata.actual_paid_amount, currencySymbol)
|
|
1259
|
+
}, {
|
|
1260
|
+
item: label(locale, 'changeDue'),
|
|
1261
|
+
value: formatMoney(payment.metadata.change_given_amount, currencySymbol)
|
|
1262
|
+
}];
|
|
1263
|
+
}
|
|
1264
|
+
function shouldDisplayCashChange(payment) {
|
|
1265
|
+
var _payment$code, _payment$metadata2, _payment$metadata3;
|
|
1266
|
+
if (stringify(payment.status).toLowerCase() !== 'paid') return false;
|
|
1267
|
+
var paymentMethod = stringify((_payment$code = payment.code) !== null && _payment$code !== void 0 ? _payment$code : payment.payment_method).toUpperCase();
|
|
1268
|
+
if (paymentMethod !== 'CASHMANUAL') return false;
|
|
1269
|
+
var actualPaidAmount = (_payment$metadata2 = payment.metadata) === null || _payment$metadata2 === void 0 ? void 0 : _payment$metadata2.actual_paid_amount;
|
|
1270
|
+
var changeGivenAmount = (_payment$metadata3 = payment.metadata) === null || _payment$metadata3 === void 0 ? void 0 : _payment$metadata3.change_given_amount;
|
|
1271
|
+
if (!isNumericAmount(actualPaidAmount) || !isNumericAmount(changeGivenAmount)) return false;
|
|
1272
|
+
return new Decimal(changeGivenAmount).toDecimalPlaces(2).gt(0);
|
|
1273
|
+
}
|
|
1274
|
+
function isNumericAmount(value) {
|
|
1275
|
+
if (typeof value === 'number') return Number.isFinite(value);
|
|
1276
|
+
if (typeof value !== 'string') return false;
|
|
1277
|
+
var normalized = value.trim();
|
|
1278
|
+
return normalized !== '' && /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(normalized);
|
|
1279
|
+
}
|
|
916
1280
|
function buildFundRecordPaymentItems(params) {
|
|
917
1281
|
var payment = params.payment,
|
|
918
1282
|
fundRecord = params.fundRecord,
|
|
@@ -1009,20 +1373,37 @@ function label(locale, key) {
|
|
|
1009
1373
|
return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
|
|
1010
1374
|
}
|
|
1011
1375
|
function getLocalizedValue(value, locale) {
|
|
1012
|
-
var
|
|
1376
|
+
var _ref45, _ref46, _ref47, _ref48, _ref49, _ref50, _value$locale2;
|
|
1013
1377
|
if (value === undefined || value === null) return '';
|
|
1014
1378
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
1015
1379
|
var dashedLocale = locale.replace('_', '-');
|
|
1016
1380
|
var underscoredLocale = locale.replace('-', '_');
|
|
1017
|
-
return stringify((
|
|
1381
|
+
return stringify((_ref45 = (_ref46 = (_ref47 = (_ref48 = (_ref49 = (_ref50 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref50 !== void 0 ? _ref50 : value[underscoredLocale]) !== null && _ref49 !== void 0 ? _ref49 : value.original) !== null && _ref48 !== void 0 ? _ref48 : value.auto) !== null && _ref47 !== void 0 ? _ref47 : value.default) !== null && _ref46 !== void 0 ? _ref46 : value.en) !== null && _ref45 !== void 0 ? _ref45 : '');
|
|
1382
|
+
}
|
|
1383
|
+
function resolveServiceTypeLabelKey(serviceType, order) {
|
|
1384
|
+
var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
1385
|
+
if (['', 'nil', 'none', 'unknown'].includes(normalized)) return null;
|
|
1386
|
+
if (['pickup', 'pick_up', 'self_pickup'].includes(normalized)) return 'pickUp';
|
|
1387
|
+
if (['delivery', 'shipping', 'local_delivery'].includes(normalized)) return 'delivery';
|
|
1388
|
+
if (['takeaway', 'take_away'].includes(normalized)) return 'takeAway';
|
|
1389
|
+
if (['dine_in', 'dinein'].includes(normalized)) return 'dineIn';
|
|
1390
|
+
if (['shop_service', 'shop_server'].includes(normalized)) {
|
|
1391
|
+
return resolveShopServiceLabelKey(order);
|
|
1392
|
+
}
|
|
1393
|
+
return null;
|
|
1018
1394
|
}
|
|
1019
|
-
function
|
|
1020
|
-
var
|
|
1021
|
-
|
|
1022
|
-
if (
|
|
1023
|
-
|
|
1024
|
-
if (
|
|
1025
|
-
return 'dineIn';
|
|
1395
|
+
function resolveShopServiceLabelKey(order) {
|
|
1396
|
+
var _order$metadata15, _order$shop_service_t;
|
|
1397
|
+
var rawShopServiceType = firstPresentValue((_order$metadata15 = order.metadata) === null || _order$metadata15 === void 0 || (_order$metadata15 = _order$metadata15.shop_service_type) === null || _order$metadata15 === void 0 ? void 0 : _order$metadata15.server_type, (_order$shop_service_t = order.shop_service_type) === null || _order$shop_service_t === void 0 ? void 0 : _order$shop_service_t.server_type, typeof order.shop_service_type === 'string' ? order.shop_service_type : undefined);
|
|
1398
|
+
if (!isPresentId(rawShopServiceType)) return 'dineIn';
|
|
1399
|
+
var normalized = stringify(rawShopServiceType).trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
1400
|
+
if (['takeaway', 'take_away'].includes(normalized)) return 'takeAway';
|
|
1401
|
+
if (['dine_in', 'dinein'].includes(normalized)) return 'dineIn';
|
|
1402
|
+
return null;
|
|
1403
|
+
}
|
|
1404
|
+
function normalizeBooleanFlag(value) {
|
|
1405
|
+
if (value === true || value === 1 || stringify(value).trim() === '1') return 1;
|
|
1406
|
+
return 0;
|
|
1026
1407
|
}
|
|
1027
1408
|
function buildShopAddress(shopInfo) {
|
|
1028
1409
|
return [shopInfo.address_street, shopInfo.address_detail, shopInfo.city, shopInfo.province, shopInfo.country, shopInfo.zip].filter(Boolean).join(', ');
|
|
@@ -1043,18 +1424,19 @@ function formatNegativeMoney(value, currencySymbol) {
|
|
|
1043
1424
|
var amount = new Decimal(toMoneyNumber(value)).abs();
|
|
1044
1425
|
return "-".concat(currencySymbol).concat(amount.toFixed(2));
|
|
1045
1426
|
}
|
|
1046
|
-
function
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1427
|
+
function sumAppliedPayments(payments) {
|
|
1428
|
+
return normalizeArray(payments).filter(function (payment) {
|
|
1429
|
+
return isPrintablePayment(payment);
|
|
1430
|
+
}).reduce(function (sum, payment) {
|
|
1431
|
+
if (isPresentId(payment.origin_amount)) {
|
|
1432
|
+
return sum.plus(toMoneyNumber(payment.origin_amount));
|
|
1433
|
+
}
|
|
1434
|
+
var amount = new Decimal(toMoneyNumber(payment.amount));
|
|
1435
|
+
var serviceFee = Decimal.max(toMoneyNumber(payment.service_fee), 0);
|
|
1436
|
+
return sum.plus(Decimal.max(amount.minus(serviceFee), 0));
|
|
1437
|
+
}, new Decimal(0));
|
|
1438
|
+
}
|
|
1439
|
+
function sumCustomerPaidPayments(payments) {
|
|
1058
1440
|
return normalizeArray(payments).filter(function (payment) {
|
|
1059
1441
|
return isPrintablePayment(payment);
|
|
1060
1442
|
}).reduce(function (sum, payment) {
|
|
@@ -1065,7 +1447,7 @@ function sumPayments(payments) {
|
|
|
1065
1447
|
function isPrintablePayment(payment) {
|
|
1066
1448
|
var status = stringify(payment.status).toLowerCase();
|
|
1067
1449
|
if (!status) return true;
|
|
1068
|
-
return ['paid', 'success', 'succeeded', 'completed'].includes(status);
|
|
1450
|
+
return ['paid', 'success', 'succeeded', 'completed', 'partially_refunded', 'refunded'].includes(status);
|
|
1069
1451
|
}
|
|
1070
1452
|
function normalizeArray(value) {
|
|
1071
1453
|
return Array.isArray(value) ? value : [];
|