@pisell/pisellos 0.10.28 → 0.10.30
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 +3 -1
- 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 +543 -101
- 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/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/Discount/index.js +4 -1
- package/lib/modules/Discount/types.d.ts +14 -4
- package/lib/modules/Order/index.d.ts +3 -1
- 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 +507 -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,13 @@ 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
|
+
pointCard: 'Point card',
|
|
39
|
+
balance: 'Balance',
|
|
36
40
|
remainingAmount: 'Remaining amount',
|
|
37
41
|
redeemPoints: 'Redeem points',
|
|
38
42
|
remainingPoints: 'Remaining points',
|
|
@@ -40,9 +44,12 @@ var LABELS = {
|
|
|
40
44
|
orderDiscount: 'Order discount',
|
|
41
45
|
manualDiscount: 'Manual discount',
|
|
42
46
|
payProcessingFee: 'Pay processing fee',
|
|
47
|
+
surchargeIncluded: 'Surcharge(Included)',
|
|
43
48
|
rounding: 'Rounding',
|
|
44
49
|
gross: 'Gross',
|
|
45
|
-
tare: 'Tare'
|
|
50
|
+
tare: 'Tare',
|
|
51
|
+
handoverTime: 'Handover time',
|
|
52
|
+
refund: 'Refund'
|
|
46
53
|
},
|
|
47
54
|
zh_CN: {
|
|
48
55
|
contactName: '联系人姓名',
|
|
@@ -56,9 +63,13 @@ var LABELS = {
|
|
|
56
63
|
pickUpTime: '取餐时间',
|
|
57
64
|
asap: '尽快',
|
|
58
65
|
cash: '现金支付',
|
|
66
|
+
cashReceived: '收取现金',
|
|
67
|
+
changeDue: '找零',
|
|
59
68
|
eftpos: '刷卡支付',
|
|
60
69
|
wallet: '钱包支付',
|
|
61
70
|
giftCard: '礼品卡',
|
|
71
|
+
pointCard: '积分卡',
|
|
72
|
+
balance: '余额',
|
|
62
73
|
remainingAmount: '剩余金额',
|
|
63
74
|
redeemPoints: '本次使用积分',
|
|
64
75
|
remainingPoints: '剩余积分',
|
|
@@ -66,9 +77,12 @@ var LABELS = {
|
|
|
66
77
|
orderDiscount: '整单折扣',
|
|
67
78
|
manualDiscount: '手动折扣',
|
|
68
79
|
payProcessingFee: '支付手续费',
|
|
80
|
+
surchargeIncluded: '手续费(已含)',
|
|
69
81
|
rounding: '抹零',
|
|
70
82
|
gross: '重量',
|
|
71
|
-
tare: '去皮'
|
|
83
|
+
tare: '去皮',
|
|
84
|
+
handoverTime: '交付时间',
|
|
85
|
+
refund: '退款'
|
|
72
86
|
},
|
|
73
87
|
zh_HK: {
|
|
74
88
|
contactName: '聯絡人姓名',
|
|
@@ -82,9 +96,13 @@ var LABELS = {
|
|
|
82
96
|
pickUpTime: '取餐時間',
|
|
83
97
|
asap: '盡快',
|
|
84
98
|
cash: '現金支付',
|
|
99
|
+
cashReceived: '收取現金',
|
|
100
|
+
changeDue: '找零',
|
|
85
101
|
eftpos: '刷卡支付',
|
|
86
102
|
wallet: '錢包支付',
|
|
87
103
|
giftCard: '禮品卡',
|
|
104
|
+
pointCard: '積分卡',
|
|
105
|
+
balance: '餘額',
|
|
88
106
|
remainingAmount: '剩餘金額',
|
|
89
107
|
redeemPoints: '本次使用積分',
|
|
90
108
|
remainingPoints: '剩餘積分',
|
|
@@ -92,9 +110,12 @@ var LABELS = {
|
|
|
92
110
|
orderDiscount: '整單折扣',
|
|
93
111
|
manualDiscount: '手動折扣',
|
|
94
112
|
payProcessingFee: '支付手續費',
|
|
113
|
+
surchargeIncluded: '手續費(已含)',
|
|
95
114
|
rounding: '抹零',
|
|
96
115
|
gross: '重量',
|
|
97
|
-
tare: '去皮'
|
|
116
|
+
tare: '去皮',
|
|
117
|
+
handoverTime: '交付時間',
|
|
118
|
+
refund: '退款'
|
|
98
119
|
},
|
|
99
120
|
ja: {
|
|
100
121
|
contactName: '連絡先名',
|
|
@@ -111,6 +132,8 @@ var LABELS = {
|
|
|
111
132
|
eftpos: 'カード',
|
|
112
133
|
wallet: 'ウォレット',
|
|
113
134
|
giftCard: 'ギフトカード',
|
|
135
|
+
pointCard: 'ポイントカード',
|
|
136
|
+
balance: '残高',
|
|
114
137
|
remainingAmount: '残高',
|
|
115
138
|
redeemPoints: '利用ポイント',
|
|
116
139
|
remainingPoints: '残りポイント',
|
|
@@ -120,7 +143,11 @@ var LABELS = {
|
|
|
120
143
|
payProcessingFee: '決済手数料',
|
|
121
144
|
rounding: '端数調整',
|
|
122
145
|
gross: '総重量',
|
|
123
|
-
tare: '風袋'
|
|
146
|
+
tare: '風袋',
|
|
147
|
+
handoverTime: '受け渡し時間',
|
|
148
|
+
refund: '返金',
|
|
149
|
+
cashReceived: 'お預かり',
|
|
150
|
+
changeDue: 'お釣り'
|
|
124
151
|
},
|
|
125
152
|
pt: {
|
|
126
153
|
contactName: 'Nome de contato',
|
|
@@ -137,6 +164,8 @@ var LABELS = {
|
|
|
137
164
|
eftpos: 'Cartão',
|
|
138
165
|
wallet: 'Carteira',
|
|
139
166
|
giftCard: 'Cartão-presente',
|
|
167
|
+
pointCard: 'Cartão de pontos',
|
|
168
|
+
balance: 'Saldo',
|
|
140
169
|
remainingAmount: 'Saldo restante',
|
|
141
170
|
redeemPoints: 'Pontos utilizados',
|
|
142
171
|
remainingPoints: 'Pontos restantes',
|
|
@@ -146,7 +175,11 @@ var LABELS = {
|
|
|
146
175
|
payProcessingFee: 'Taxa de processamento',
|
|
147
176
|
rounding: 'Arredondamento',
|
|
148
177
|
gross: 'Peso bruto',
|
|
149
|
-
tare: 'Tara'
|
|
178
|
+
tare: 'Tara',
|
|
179
|
+
handoverTime: 'Hora de entrega',
|
|
180
|
+
refund: 'Reembolso',
|
|
181
|
+
cashReceived: 'Dinheiro recebido',
|
|
182
|
+
changeDue: 'Troco'
|
|
150
183
|
}
|
|
151
184
|
};
|
|
152
185
|
export function buildSmallTicketData(params) {
|
|
@@ -175,11 +208,15 @@ function buildLocaleData(params) {
|
|
|
175
208
|
var products = buildProducts(order, locale, productMap);
|
|
176
209
|
var summary = getSummary(order);
|
|
177
210
|
var currencySymbol = getCurrencySymbol(order, shopInfo);
|
|
178
|
-
|
|
211
|
+
var financials = resolveReceiptFinancials(order, summary);
|
|
212
|
+
var delivery = buildDelivery(order, locale);
|
|
213
|
+
return _objectSpread(_objectSpread({
|
|
179
214
|
base_data: buildBaseData({
|
|
180
215
|
order: order,
|
|
181
216
|
shopInfo: shopInfo,
|
|
182
|
-
locale: locale
|
|
217
|
+
locale: locale,
|
|
218
|
+
currencySymbol: currencySymbol,
|
|
219
|
+
financials: financials
|
|
183
220
|
}),
|
|
184
221
|
products: products,
|
|
185
222
|
fees: buildFees({
|
|
@@ -188,11 +225,14 @@ function buildLocaleData(params) {
|
|
|
188
225
|
locale: locale,
|
|
189
226
|
products: products,
|
|
190
227
|
summary: summary,
|
|
191
|
-
currencySymbol: currencySymbol
|
|
228
|
+
currencySymbol: currencySymbol,
|
|
229
|
+
financials: financials
|
|
192
230
|
}),
|
|
193
231
|
customer: buildCustomer(order, locale),
|
|
194
|
-
appointment: buildAppointment(order, locale)
|
|
195
|
-
|
|
232
|
+
appointment: buildAppointment(order, locale)
|
|
233
|
+
}, delivery.length ? {
|
|
234
|
+
delivery: delivery
|
|
235
|
+
} : {}), {}, {
|
|
196
236
|
resources: buildResources(order, locale),
|
|
197
237
|
payment_data: buildPaymentData({
|
|
198
238
|
order: order,
|
|
@@ -206,17 +246,23 @@ function buildLocaleData(params) {
|
|
|
206
246
|
}),
|
|
207
247
|
tickets: Array.isArray(order.tickets) ? order.tickets : [],
|
|
208
248
|
source_shop: [],
|
|
209
|
-
refund_data:
|
|
249
|
+
refund_data: buildRefundData({
|
|
250
|
+
order: order,
|
|
251
|
+
locale: locale,
|
|
252
|
+
currencySymbol: currencySymbol
|
|
253
|
+
}),
|
|
210
254
|
expend_data: []
|
|
211
|
-
};
|
|
255
|
+
});
|
|
212
256
|
}
|
|
213
257
|
function buildBaseData(params) {
|
|
214
258
|
var _order$metadata;
|
|
215
259
|
var order = params.order,
|
|
216
260
|
shopInfo = params.shopInfo,
|
|
217
|
-
locale = params.locale
|
|
261
|
+
locale = params.locale,
|
|
262
|
+
currencySymbol = params.currencySymbol,
|
|
263
|
+
financials = params.financials;
|
|
218
264
|
var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
|
|
219
|
-
return _objectSpread({
|
|
265
|
+
return _objectSpread(_objectSpread({
|
|
220
266
|
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
221
267
|
note: stringify(order.note),
|
|
222
268
|
shop_order_number: stringify(order.shop_order_number),
|
|
@@ -224,7 +270,13 @@ function buildBaseData(params) {
|
|
|
224
270
|
shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
|
|
225
271
|
shop_phone: stringify(shopInfo.phone || order.shop_phone),
|
|
226
272
|
shop_address: stringify(shopInfo.receipt_address || shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
|
|
227
|
-
original_payment_status:
|
|
273
|
+
original_payment_status: financials.paymentStatus,
|
|
274
|
+
payment_status: financials.paymentStatus,
|
|
275
|
+
total_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
276
|
+
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol)
|
|
277
|
+
}, isPresentId(financials.amountGap) ? {
|
|
278
|
+
amount_gap: formatMoney(financials.amountGap, currencySymbol)
|
|
279
|
+
} : {}), {}, {
|
|
228
280
|
is_repeat: 0,
|
|
229
281
|
buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
|
|
230
282
|
order_no: orderNumber,
|
|
@@ -274,28 +326,46 @@ function buildProducts(order, locale, productMap) {
|
|
|
274
326
|
quantity: quantity,
|
|
275
327
|
originalPrice: originalPrice
|
|
276
328
|
});
|
|
277
|
-
|
|
329
|
+
var productNote = resolveProductNote(product, locale);
|
|
330
|
+
var basePrice = resolveProductBasePrice(product);
|
|
331
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
278
332
|
product_title: productTitle,
|
|
279
333
|
product_quantity: quantity,
|
|
280
334
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
281
|
-
original_price: formatMoney(originalPrice, currencySymbol)
|
|
335
|
+
original_price: formatMoney(originalPrice, currencySymbol)
|
|
336
|
+
}, isPresentId(basePrice) ? {
|
|
337
|
+
base_price: formatMoney(basePrice, currencySymbol)
|
|
338
|
+
} : {}), {}, {
|
|
282
339
|
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
283
340
|
extension_list: extensionList
|
|
284
341
|
}, isPresentId(productUid) ? {
|
|
285
342
|
product_uid: productUid
|
|
286
343
|
} : {}), isPresentId(bookingUid) ? {
|
|
287
344
|
booking_uid: bookingUid
|
|
345
|
+
} : {}), productNote ? {
|
|
346
|
+
product_note: productNote
|
|
288
347
|
} : {}), options.length ? {
|
|
289
348
|
options: options
|
|
290
349
|
} : {}), resolvedVariant ? {
|
|
291
350
|
variant: resolvedVariant
|
|
292
|
-
} : {}), Array.isArray(product.combinations) ? {
|
|
293
|
-
combinations: product.combinations
|
|
351
|
+
} : {}), Array.isArray(product.combinations) && product.combinations.length ? {
|
|
352
|
+
combinations: normalizeExistingCombinations(product.combinations, locale)
|
|
294
353
|
} : combinations.length ? {
|
|
295
354
|
combinations: combinations
|
|
296
355
|
} : {});
|
|
297
356
|
});
|
|
298
357
|
}
|
|
358
|
+
function resolveProductBasePrice(product) {
|
|
359
|
+
var _product$product_vari, _product$_origin, _product$_origin2;
|
|
360
|
+
var metadata = product.metadata || {};
|
|
361
|
+
var origin = product._origin || metadata.origin || {};
|
|
362
|
+
var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
|
|
363
|
+
var variant = Array.isArray(origin.variant) && isPresentId(variantId) ? origin.variant.find(function (item) {
|
|
364
|
+
return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
|
|
365
|
+
}) : undefined;
|
|
366
|
+
var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
|
|
367
|
+
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);
|
|
368
|
+
}
|
|
299
369
|
function normalizeProductDiscounts(params) {
|
|
300
370
|
var product = params.product,
|
|
301
371
|
locale = params.locale,
|
|
@@ -455,15 +525,42 @@ function normalizeProductCombinations(params) {
|
|
|
455
525
|
locale: locale,
|
|
456
526
|
parentProduct: parentProduct
|
|
457
527
|
});
|
|
458
|
-
var
|
|
459
|
-
|
|
460
|
-
|
|
528
|
+
var productNote = resolveProductNote(bundle, locale);
|
|
529
|
+
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
|
|
530
|
+
return _objectSpread(_objectSpread({
|
|
531
|
+
product_title: baseTitle,
|
|
461
532
|
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
533
|
price: formatBundlePrice(bundle, currencySymbol),
|
|
463
534
|
combinations_options: combinationsOptions
|
|
464
|
-
}
|
|
535
|
+
}, productNote ? {
|
|
536
|
+
product_note: productNote
|
|
537
|
+
} : {}), nestedCombinations.length ? {
|
|
538
|
+
combinations: nestedCombinations
|
|
539
|
+
} : {});
|
|
465
540
|
});
|
|
466
541
|
}
|
|
542
|
+
function normalizeExistingCombinations(combinations, locale) {
|
|
543
|
+
return combinations.map(function (combination) {
|
|
544
|
+
if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
|
|
545
|
+
return combination;
|
|
546
|
+
}
|
|
547
|
+
var productNote = resolveProductNote(combination, locale);
|
|
548
|
+
var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale) : undefined;
|
|
549
|
+
var snapshot = _objectSpread({}, combination);
|
|
550
|
+
delete snapshot.product_note;
|
|
551
|
+
delete snapshot.note;
|
|
552
|
+
return _objectSpread(_objectSpread(_objectSpread({}, snapshot), productNote ? {
|
|
553
|
+
product_note: productNote
|
|
554
|
+
} : {}), nestedCombinations ? {
|
|
555
|
+
combinations: nestedCombinations
|
|
556
|
+
} : {});
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
function resolveProductNote(product, locale) {
|
|
560
|
+
var productNote = getLocalizedValue(product.product_note, locale).trim();
|
|
561
|
+
if (productNote) return productNote;
|
|
562
|
+
return getLocalizedValue(product.note, locale).trim();
|
|
563
|
+
}
|
|
467
564
|
function resolveBundleProductTitle(params) {
|
|
468
565
|
var _ref16, _ref17, _bundle$bundle_produc;
|
|
469
566
|
var bundle = params.bundle,
|
|
@@ -488,13 +585,13 @@ function resolveProductFromMap(productId, productMap) {
|
|
|
488
585
|
return productMap[productId] || productMap[String(productId)] || null;
|
|
489
586
|
}
|
|
490
587
|
function resolveProductVariantText(params) {
|
|
491
|
-
var _product$
|
|
588
|
+
var _product$product_vari2;
|
|
492
589
|
var product = params.product,
|
|
493
590
|
parentProduct = params.parentProduct,
|
|
494
591
|
locale = params.locale;
|
|
495
592
|
if (product.variant) return getLocalizedValue(product.variant, locale);
|
|
496
593
|
if (!parentProduct) return '';
|
|
497
|
-
var productVariantId = (_product$
|
|
594
|
+
var productVariantId = (_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : product.variant_id;
|
|
498
595
|
if (!isNonZeroId(productVariantId)) return '';
|
|
499
596
|
var matchedVariant = normalizeArray(parentProduct.variant).find(function (variant) {
|
|
500
597
|
return isSameId(variant.id, productVariantId);
|
|
@@ -678,16 +775,6 @@ function isSameId(left, right) {
|
|
|
678
775
|
if (!isPresentId(left) || !isPresentId(right)) return false;
|
|
679
776
|
return String(left) === String(right);
|
|
680
777
|
}
|
|
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
778
|
function formatBundlePrice(bundle, currencySymbol) {
|
|
692
779
|
var _ref33, _ref34, _bundle$bundle_sellin;
|
|
693
780
|
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 +785,14 @@ function formatBundlePrice(bundle, currencySymbol) {
|
|
|
698
785
|
return formatMoney(amount, currencySymbol);
|
|
699
786
|
}
|
|
700
787
|
function buildFees(params) {
|
|
701
|
-
var
|
|
788
|
+
var _firstPresentValue, _firstPresentValue2;
|
|
702
789
|
var order = params.order,
|
|
703
790
|
shopInfo = params.shopInfo,
|
|
704
791
|
locale = params.locale,
|
|
705
792
|
products = params.products,
|
|
706
793
|
summary = params.summary,
|
|
707
|
-
currencySymbol = params.currencySymbol
|
|
794
|
+
currencySymbol = params.currencySymbol,
|
|
795
|
+
financials = params.financials;
|
|
708
796
|
var fees = [];
|
|
709
797
|
for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
|
|
710
798
|
var _ref35, _surcharge$amount;
|
|
@@ -716,67 +804,108 @@ function buildFees(params) {
|
|
|
716
804
|
value: formatMoney(value, currencySymbol)
|
|
717
805
|
});
|
|
718
806
|
}
|
|
719
|
-
var discountAmount = (
|
|
807
|
+
var discountAmount = firstPresentValue(order.shop_discount, summary.discount_amount, order.discount_amount);
|
|
720
808
|
if (isNonZero(discountAmount)) {
|
|
721
809
|
fees.push({
|
|
722
810
|
item: label(locale, 'orderDiscount'),
|
|
723
811
|
value: formatNegativeMoney(discountAmount, currencySymbol)
|
|
724
812
|
});
|
|
725
813
|
}
|
|
726
|
-
var taxFee = summary.tax_fee
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
var
|
|
814
|
+
var taxFee = firstPresentValue(summary.tax_fee, order.tax_fee);
|
|
815
|
+
var taxTitle = resolveTaxTitle({
|
|
816
|
+
summary: summary,
|
|
817
|
+
order: order,
|
|
818
|
+
shopInfo: shopInfo,
|
|
819
|
+
locale: locale
|
|
820
|
+
});
|
|
821
|
+
var isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
|
|
822
|
+
var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
|
|
734
823
|
if (isNonZero(roundingAmount)) {
|
|
735
824
|
fees.push({
|
|
736
825
|
item: label(locale, 'rounding'),
|
|
737
826
|
value: formatMoney(roundingAmount, currencySymbol)
|
|
738
827
|
});
|
|
739
828
|
}
|
|
740
|
-
var payProcessingFee =
|
|
829
|
+
var payProcessingFee = financials.payProcessingFee;
|
|
741
830
|
if (isNonZero(payProcessingFee)) {
|
|
742
831
|
fees.push({
|
|
743
832
|
item: label(locale, 'payProcessingFee'),
|
|
744
833
|
value: formatMoney(payProcessingFee, currencySymbol)
|
|
745
834
|
});
|
|
746
835
|
}
|
|
747
|
-
var productExpectAmount = summary.product_expect_amount
|
|
836
|
+
var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
|
|
748
837
|
var productOriginalAmount = (_firstPresentValue = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : calculateProductOriginalAmount(order);
|
|
749
838
|
var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
|
|
750
839
|
return {
|
|
751
840
|
fees: fees,
|
|
752
|
-
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
753
|
-
total_amount: formatMoney(summary.total_amount
|
|
841
|
+
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
842
|
+
total_amount: formatMoney((_firstPresentValue2 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : 0, currencySymbol),
|
|
754
843
|
original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
|
|
755
|
-
product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
|
|
756
|
-
expect_amount: formatMoney(
|
|
757
|
-
product_quantity: toNumber(summary.product_quantity
|
|
844
|
+
product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
|
|
845
|
+
expect_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
846
|
+
product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
|
|
758
847
|
return sum + product.product_quantity;
|
|
759
|
-
}, 0), 0),
|
|
760
|
-
has_pay: formatMoney(
|
|
848
|
+
}, 0)), 0),
|
|
849
|
+
has_pay: formatMoney(financials.orderPaidAmount, currencySymbol),
|
|
761
850
|
payment_method: '',
|
|
762
|
-
tax_title:
|
|
763
|
-
total_refund_amount: formatMoney(
|
|
764
|
-
|
|
851
|
+
tax_title: taxTitle,
|
|
852
|
+
total_refund_amount: formatMoney(financials.totalRefundAmount, currencySymbol),
|
|
853
|
+
customer_paid_amount: formatMoney(financials.customerPaidAmount, currencySymbol),
|
|
854
|
+
net_payment_applied: formatMoney(financials.netPaymentApplied, currencySymbol)
|
|
855
|
+
}, isPresentId(roundingAmount) ? {
|
|
765
856
|
rounding_amount: formatMoney(roundingAmount, currencySymbol)
|
|
766
857
|
} : {}), isNonZero(totalSavingsAmount) ? {
|
|
767
858
|
order_total_discount: formatMoney(totalSavingsAmount, currencySymbol)
|
|
768
|
-
} : {}),
|
|
859
|
+
} : {}), financials.hasPayProcessingFee ? {
|
|
769
860
|
pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
|
|
770
|
-
} : {}),
|
|
861
|
+
} : {}), isPresentId(taxFee) ? {
|
|
771
862
|
tax_fee: formatMoney(taxFee, currencySymbol)
|
|
863
|
+
} : {}), isPresentId(isPriceIncludeTax) ? {
|
|
864
|
+
is_price_include_tax: normalizeBooleanFlag(isPriceIncludeTax)
|
|
772
865
|
} : {})
|
|
773
866
|
};
|
|
774
867
|
}
|
|
868
|
+
function resolveReceiptFinancials(order, summary) {
|
|
869
|
+
var _firstPresentValue3, _firstPresentValue4, _firstPresentValue5, _firstPresentValue6;
|
|
870
|
+
var totalAmount = (_firstPresentValue3 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0;
|
|
871
|
+
var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
|
|
872
|
+
var payProcessingFee = rawPayProcessingFee !== null && rawPayProcessingFee !== void 0 ? rawPayProcessingFee : 0;
|
|
873
|
+
var orderPaidAmount = (_firstPresentValue4 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
|
|
874
|
+
var totalRefundAmount = (_firstPresentValue5 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
|
|
875
|
+
var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
|
|
876
|
+
var fallbackCustomerPaidAmount = Decimal.max(sumCustomerPaidPayments(order.payments), new Decimal(toMoneyNumber(orderPaidAmount)).plus(toMoneyNumber(payProcessingFee)));
|
|
877
|
+
var customerPaidAmount = (_firstPresentValue6 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
|
|
878
|
+
var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
|
|
879
|
+
return {
|
|
880
|
+
totalAmount: totalAmount,
|
|
881
|
+
orderPaidAmount: orderPaidAmount,
|
|
882
|
+
payProcessingFee: payProcessingFee,
|
|
883
|
+
customerPaidAmount: customerPaidAmount,
|
|
884
|
+
totalRefundAmount: totalRefundAmount,
|
|
885
|
+
netPaymentApplied: netPaymentApplied,
|
|
886
|
+
amountGap: amountGap,
|
|
887
|
+
paymentStatus: resolveReceiptPaymentStatus({
|
|
888
|
+
order: order,
|
|
889
|
+
summary: summary
|
|
890
|
+
}),
|
|
891
|
+
hasPayProcessingFee: isPresentId(rawPayProcessingFee)
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
function resolveReceiptPaymentStatus(params) {
|
|
895
|
+
return [params.order.payment_status, params.summary.payment_status, params.order.original_payment_status].map(function (status) {
|
|
896
|
+
return stringify(status).trim();
|
|
897
|
+
}).find(Boolean) || '';
|
|
898
|
+
}
|
|
899
|
+
function resolveTaxTitle(params) {
|
|
900
|
+
return [params.summary.tax_title, params.order.tax_title, params.shopInfo.tax_title].map(function (title) {
|
|
901
|
+
return getLocalizedValue(title, params.locale).trim();
|
|
902
|
+
}).find(Boolean) || 'Tax';
|
|
903
|
+
}
|
|
775
904
|
function calculateProductOriginalAmount(order) {
|
|
776
905
|
return normalizeArray(order.products).reduce(function (total, product) {
|
|
777
|
-
var
|
|
778
|
-
var quantity = toNumber((
|
|
779
|
-
var originalPrice = (
|
|
906
|
+
var _ref36, _ref37, _product$product_quan2, _ref38, _ref39, _ref40, _product$original_pri2;
|
|
907
|
+
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);
|
|
908
|
+
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
909
|
return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
|
|
781
910
|
}, new Decimal(0));
|
|
782
911
|
}
|
|
@@ -800,27 +929,29 @@ function normalizeCustomerDisplayValue(value) {
|
|
|
800
929
|
return text;
|
|
801
930
|
}
|
|
802
931
|
function buildDelivery(order, locale) {
|
|
803
|
-
var _order$metadata2;
|
|
804
|
-
var
|
|
805
|
-
|
|
806
|
-
var serviceTypeLabelKey =
|
|
932
|
+
var _order$metadata2, _order$metadata3, _order$metadata4, _order$metadata5, _order$metadata6, _order$metadata7, _order$metadata8, _order$metadata9, _order$metadata10, _order$metadata11, _order$metadata12;
|
|
933
|
+
var deliveryType = stringify(order.delivery_type).trim();
|
|
934
|
+
var serviceType = deliveryType || stringify(firstPresentValue((_order$metadata2 = order.metadata) === null || _order$metadata2 === void 0 ? void 0 : _order$metadata2.service_type, order.service_type)).trim();
|
|
935
|
+
var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType, order);
|
|
936
|
+
if (!serviceTypeLabelKey) return [];
|
|
807
937
|
var items = [{
|
|
808
938
|
item: '',
|
|
809
939
|
value: label(locale, serviceTypeLabelKey),
|
|
810
940
|
size: 2,
|
|
811
941
|
align: 'left'
|
|
812
942
|
}];
|
|
813
|
-
|
|
943
|
+
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);
|
|
944
|
+
if (isPresentId(handoverTime)) {
|
|
814
945
|
items.push({
|
|
815
|
-
item: label(locale, '
|
|
816
|
-
value:
|
|
946
|
+
item: label(locale, 'handoverTime'),
|
|
947
|
+
value: formatDateTime(handoverTime, locale)
|
|
817
948
|
});
|
|
818
949
|
}
|
|
819
950
|
return items;
|
|
820
951
|
}
|
|
821
952
|
function buildAppointment(order, locale) {
|
|
822
|
-
var _order$
|
|
823
|
-
var bookings = normalizeArray(order.bookings);
|
|
953
|
+
var _order$metadata13, _order$metadata14, _order$form_data;
|
|
954
|
+
var bookings = sortBookings(normalizeArray(order.bookings));
|
|
824
955
|
if (bookings.length) {
|
|
825
956
|
return bookings.map(function (booking) {
|
|
826
957
|
var _booking$metadata, _booking$metadata2;
|
|
@@ -836,13 +967,57 @@ function buildAppointment(order, locale) {
|
|
|
836
967
|
} : {});
|
|
837
968
|
});
|
|
838
969
|
}
|
|
839
|
-
var tableName = order.table_name || ((_order$
|
|
970
|
+
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
971
|
if (!tableName) return [];
|
|
841
972
|
return [{
|
|
842
973
|
item: label(locale, 'table'),
|
|
843
974
|
value: getLocalizedValue(tableName, locale)
|
|
844
975
|
}];
|
|
845
976
|
}
|
|
977
|
+
function sortBookings(bookings) {
|
|
978
|
+
return bookings.map(function (booking, index) {
|
|
979
|
+
return {
|
|
980
|
+
booking: booking,
|
|
981
|
+
index: index
|
|
982
|
+
};
|
|
983
|
+
}).sort(function (left, right) {
|
|
984
|
+
var _left$booking2, _left$booking3, _right$booking2, _right$booking3;
|
|
985
|
+
var leftStart = bookingStartTimestamp(left.booking);
|
|
986
|
+
var rightStart = bookingStartTimestamp(right.booking);
|
|
987
|
+
if (leftStart !== rightStart) return leftStart < rightStart ? -1 : 1;
|
|
988
|
+
for (var _i2 = 0, _arr = ['booking_id', 'schedule_event_id']; _i2 < _arr.length; _i2++) {
|
|
989
|
+
var _left$booking, _right$booking;
|
|
990
|
+
var field = _arr[_i2];
|
|
991
|
+
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]);
|
|
992
|
+
if (fieldOrder !== 0) return fieldOrder;
|
|
993
|
+
}
|
|
994
|
+
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));
|
|
995
|
+
return bookingUidOrder || left.index - right.index;
|
|
996
|
+
}).map(function (_ref41) {
|
|
997
|
+
var booking = _ref41.booking;
|
|
998
|
+
return booking;
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
function bookingStartTimestamp(booking) {
|
|
1002
|
+
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];
|
|
1003
|
+
for (var _i3 = 0, _startValues = startValues; _i3 < _startValues.length; _i3++) {
|
|
1004
|
+
var startValue = _startValues[_i3];
|
|
1005
|
+
if (!isPresentId(startValue)) continue;
|
|
1006
|
+
var timestamp = dayjs(startValue).valueOf();
|
|
1007
|
+
if (Number.isFinite(timestamp)) return timestamp;
|
|
1008
|
+
}
|
|
1009
|
+
return Number.POSITIVE_INFINITY;
|
|
1010
|
+
}
|
|
1011
|
+
function compareOptionalValues(left, right) {
|
|
1012
|
+
var hasLeft = isPresentId(left);
|
|
1013
|
+
var hasRight = isPresentId(right);
|
|
1014
|
+
if (!hasLeft && !hasRight) return 0;
|
|
1015
|
+
if (!hasLeft) return 1;
|
|
1016
|
+
if (!hasRight) return -1;
|
|
1017
|
+
return String(left).localeCompare(String(right), undefined, {
|
|
1018
|
+
numeric: true
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
846
1021
|
function buildResources(order, locale) {
|
|
847
1022
|
return normalizeArray(order.resources || order.resource_list).map(function (resource) {
|
|
848
1023
|
return {
|
|
@@ -866,10 +1041,94 @@ function buildPaymentData(params) {
|
|
|
866
1041
|
});
|
|
867
1042
|
});
|
|
868
1043
|
}
|
|
1044
|
+
function buildRefundData(params) {
|
|
1045
|
+
var payments = normalizeArray(params.order.payments);
|
|
1046
|
+
var refunds = Array.from(normalizeArray(params.order.refunds).reduce(function (result, refund, index) {
|
|
1047
|
+
var identity = refundIdentity(refund, index);
|
|
1048
|
+
var candidate = {
|
|
1049
|
+
refund: refund,
|
|
1050
|
+
index: index
|
|
1051
|
+
};
|
|
1052
|
+
var existing = result.get(identity);
|
|
1053
|
+
if (!existing || shouldPreferRefundCandidate(candidate, existing)) {
|
|
1054
|
+
result.set(identity, candidate);
|
|
1055
|
+
}
|
|
1056
|
+
return result;
|
|
1057
|
+
}, new Map()).values()).filter(function (_ref42) {
|
|
1058
|
+
var refund = _ref42.refund;
|
|
1059
|
+
return isPrintableRefund(refund);
|
|
1060
|
+
}).sort(function (left, right) {
|
|
1061
|
+
var leftTime = refundTimestamp(left.refund);
|
|
1062
|
+
var rightTime = refundTimestamp(right.refund);
|
|
1063
|
+
if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
|
|
1064
|
+
return left.index - right.index;
|
|
1065
|
+
});
|
|
1066
|
+
return refunds.map(function (_ref43) {
|
|
1067
|
+
var _firstPresentValue7;
|
|
1068
|
+
var refund = _ref43.refund;
|
|
1069
|
+
var payment = resolveRefundPayment(refund, payments);
|
|
1070
|
+
var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
|
|
1071
|
+
var amount = (_firstPresentValue7 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
|
|
1072
|
+
var items = [{
|
|
1073
|
+
item: methodName,
|
|
1074
|
+
value: formatNegativeMoney(amount, params.currencySymbol)
|
|
1075
|
+
}];
|
|
1076
|
+
var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
|
|
1077
|
+
if (isPresentId(occurredAt)) {
|
|
1078
|
+
items.push({
|
|
1079
|
+
item: formatDateTime(occurredAt, params.locale),
|
|
1080
|
+
value: ''
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
return items;
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
function refundIdentity(refund, index) {
|
|
1087
|
+
if (isPresentId(refund.order_refund_id)) return "refund-id:".concat(refund.order_refund_id);
|
|
1088
|
+
if (isPresentId(refund.refund_number)) return "refund-number:".concat(refund.refund_number);
|
|
1089
|
+
return "refund-index:".concat(index);
|
|
1090
|
+
}
|
|
1091
|
+
function shouldPreferRefundCandidate(candidate, existing) {
|
|
1092
|
+
var candidatePrintable = isPrintableRefund(candidate.refund);
|
|
1093
|
+
var existingPrintable = isPrintableRefund(existing.refund);
|
|
1094
|
+
if (candidatePrintable !== existingPrintable) return candidatePrintable;
|
|
1095
|
+
var candidateTime = refundFreshnessTimestamp(candidate.refund);
|
|
1096
|
+
var existingTime = refundFreshnessTimestamp(existing.refund);
|
|
1097
|
+
if (candidateTime !== existingTime) return candidateTime > existingTime;
|
|
1098
|
+
return candidate.index > existing.index;
|
|
1099
|
+
}
|
|
1100
|
+
function refundFreshnessTimestamp(refund) {
|
|
1101
|
+
var timestampValue = firstPresentValue(refund.updated_at, refund.refunded_at, refund.refund_time, refund.created_at);
|
|
1102
|
+
if (!isPresentId(timestampValue)) return Number.NEGATIVE_INFINITY;
|
|
1103
|
+
var timestamp = dayjs(timestampValue).valueOf();
|
|
1104
|
+
return Number.isFinite(timestamp) ? timestamp : Number.NEGATIVE_INFINITY;
|
|
1105
|
+
}
|
|
1106
|
+
function refundTimestamp(refund) {
|
|
1107
|
+
var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
|
|
1108
|
+
if (!isPresentId(occurredAt)) return Number.POSITIVE_INFINITY;
|
|
1109
|
+
var timestamp = dayjs(occurredAt).valueOf();
|
|
1110
|
+
return Number.isFinite(timestamp) ? timestamp : Number.POSITIVE_INFINITY;
|
|
1111
|
+
}
|
|
1112
|
+
function isPrintableRefund(refund) {
|
|
1113
|
+
var status = stringify(refund.status).trim().toLowerCase();
|
|
1114
|
+
if (!status) return true;
|
|
1115
|
+
return !['pending', 'payment_pending', 'payment_processing', 'refund_processing', 'processing', 'failed', 'error', 'cancelled', 'canceled', 'voided'].includes(status);
|
|
1116
|
+
}
|
|
1117
|
+
function resolveRefundPayment(refund, payments) {
|
|
1118
|
+
if (refund.payment && _typeof(refund.payment) === 'object' && !Array.isArray(refund.payment)) {
|
|
1119
|
+
return refund.payment;
|
|
1120
|
+
}
|
|
1121
|
+
var orderPaymentId = firstPresentValue(refund.order_payment_id, refund.payment_id);
|
|
1122
|
+
var matchedPayment = payments.find(function (payment) {
|
|
1123
|
+
return isSameId(firstPresentValue(payment.order_payment_id, payment.id), orderPaymentId);
|
|
1124
|
+
});
|
|
1125
|
+
return matchedPayment || refund;
|
|
1126
|
+
}
|
|
869
1127
|
function buildWallets(params) {
|
|
870
|
-
|
|
1128
|
+
var displayedWalletPayments = normalizeArray(params.order.payments).filter(function (payment) {
|
|
871
1129
|
return isPrintablePayment(payment) && !!getFundRecord(payment);
|
|
872
|
-
})
|
|
1130
|
+
});
|
|
1131
|
+
var paymentWallets = displayedWalletPayments.map(function (payment) {
|
|
873
1132
|
return buildPaymentItems({
|
|
874
1133
|
payment: payment,
|
|
875
1134
|
locale: params.locale,
|
|
@@ -877,17 +1136,141 @@ function buildWallets(params) {
|
|
|
877
1136
|
includeFundRecordBalance: true
|
|
878
1137
|
});
|
|
879
1138
|
});
|
|
1139
|
+
var displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
|
|
1140
|
+
return [].concat(_toConsumableArray(paymentWallets), _toConsumableArray(buildVoucherAssets(params)), _toConsumableArray(buildPointCardSnapshotAssets({
|
|
1141
|
+
order: params.order,
|
|
1142
|
+
locale: params.locale,
|
|
1143
|
+
displayedWalletPassIds: displayedWalletPassIds
|
|
1144
|
+
})));
|
|
1145
|
+
}
|
|
1146
|
+
function collectDisplayedWalletPassIds(payments) {
|
|
1147
|
+
var ids = new Set();
|
|
1148
|
+
payments.forEach(function (payment) {
|
|
1149
|
+
var fundRecord = getFundRecord(payment);
|
|
1150
|
+
[payment.voucher_id, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id].forEach(function (value) {
|
|
1151
|
+
var id = normalizeWalletPassId(value);
|
|
1152
|
+
if (id) ids.add(id);
|
|
1153
|
+
});
|
|
1154
|
+
});
|
|
1155
|
+
return ids;
|
|
1156
|
+
}
|
|
1157
|
+
function buildPointCardSnapshotAssets(params) {
|
|
1158
|
+
var _params$order$order_m;
|
|
1159
|
+
var snapshots = (_params$order$order_m = params.order.order_meta_list) === null || _params$order$order_m === void 0 ? void 0 : _params$order$order_m.point_cards_snapshot;
|
|
1160
|
+
if (!Array.isArray(snapshots)) return [];
|
|
1161
|
+
var seenSnapshotIds = new Set();
|
|
1162
|
+
return snapshots.flatMap(function (snapshot) {
|
|
1163
|
+
if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return [];
|
|
1164
|
+
var pointCard = snapshot;
|
|
1165
|
+
if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
|
|
1166
|
+
var id = normalizeWalletPassId(pointCard.id);
|
|
1167
|
+
if (!id || seenSnapshotIds.has(id)) return [];
|
|
1168
|
+
seenSnapshotIds.add(id);
|
|
1169
|
+
if (params.displayedWalletPassIds.has(id)) return [];
|
|
1170
|
+
var rows = [{
|
|
1171
|
+
item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
|
|
1172
|
+
value: ''
|
|
1173
|
+
}];
|
|
1174
|
+
var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
|
|
1175
|
+
if (remainingPoints) {
|
|
1176
|
+
rows.push({
|
|
1177
|
+
item: label(params.locale, 'remainingPoints'),
|
|
1178
|
+
value: trimDecimal(remainingPoints)
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
return [rows];
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
function normalizeWalletPassId(value) {
|
|
1185
|
+
if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
|
|
1186
|
+
if (typeof value !== 'string') return null;
|
|
1187
|
+
return value.trim() || null;
|
|
1188
|
+
}
|
|
1189
|
+
function getPointCardSnapshotRemainingPoints(snapshot) {
|
|
1190
|
+
if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
|
|
1191
|
+
return null;
|
|
1192
|
+
}
|
|
1193
|
+
return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
|
|
1194
|
+
}
|
|
1195
|
+
function buildVoucherAssets(params) {
|
|
1196
|
+
var seenVoucherKeys = new Set();
|
|
1197
|
+
return normalizeArray(params.order.vouchers).flatMap(function (voucher, index) {
|
|
1198
|
+
if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
|
|
1199
|
+
var voucherKey = getVoucherAssetKey(voucher, index);
|
|
1200
|
+
if (seenVoucherKeys.has(voucherKey)) return [];
|
|
1201
|
+
seenVoucherKeys.add(voucherKey);
|
|
1202
|
+
var name = getVoucherAssetName(voucher, params.locale);
|
|
1203
|
+
var percent = getVoucherDiscountPercent(voucher);
|
|
1204
|
+
if (percent) {
|
|
1205
|
+
return [[{
|
|
1206
|
+
item: appendPercentToVoucherName(name, percent),
|
|
1207
|
+
value: formatVoucherDiscount(percent, params.locale)
|
|
1208
|
+
}]];
|
|
1209
|
+
}
|
|
1210
|
+
var balance = getVoucherBalance(voucher);
|
|
1211
|
+
return [[{
|
|
1212
|
+
item: name,
|
|
1213
|
+
value: ''
|
|
1214
|
+
}, {
|
|
1215
|
+
item: label(params.locale, 'balance'),
|
|
1216
|
+
value: formatMoney(balance, params.currencySymbol)
|
|
1217
|
+
}]];
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
function getVoucherAssetKey(voucher, index) {
|
|
1221
|
+
var identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
|
|
1222
|
+
return identity === undefined ? "voucher-index:".concat(index) : "voucher:".concat(String(identity));
|
|
1223
|
+
}
|
|
1224
|
+
function getVoucherAssetName(voucher, locale) {
|
|
1225
|
+
return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
|
|
1226
|
+
}
|
|
1227
|
+
function getVoucherDiscountPercent(voucher) {
|
|
1228
|
+
var _voucher$metadata;
|
|
1229
|
+
var discountType = stringify(((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.discount_card_type) || voucher.discount_card_type).toLowerCase();
|
|
1230
|
+
if (discountType !== 'percent' && discountType !== 'percentage') return null;
|
|
1231
|
+
var percent = new Decimal(toMoneyNumber(voucher.par_value));
|
|
1232
|
+
if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
|
|
1233
|
+
return percent;
|
|
1234
|
+
}
|
|
1235
|
+
function appendPercentToVoucherName(name, percent) {
|
|
1236
|
+
if (/\d+(?:\.\d+)?\s*(?:%|折)|\boff\b/i.test(name)) return name;
|
|
1237
|
+
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) ? '' : ' ';
|
|
1238
|
+
return "".concat(trimDecimal(percent), "%").concat(separator).concat(name);
|
|
1239
|
+
}
|
|
1240
|
+
function formatVoucherDiscount(percent, locale) {
|
|
1241
|
+
var normalizedLocale = normalizeLocaleKey(locale);
|
|
1242
|
+
if (normalizedLocale === 'zh_CN' || normalizedLocale === 'zh_HK') {
|
|
1243
|
+
return "".concat(trimDecimal(percent), "% OFF");
|
|
1244
|
+
}
|
|
1245
|
+
if (normalizedLocale === 'pt') return "Desconto ".concat(trimDecimal(percent), "%");
|
|
1246
|
+
return normalizedLocale === 'en' ? "Discount ".concat(trimDecimal(percent), "% OFF") : "".concat(trimDecimal(percent), "% OFF");
|
|
1247
|
+
}
|
|
1248
|
+
function getVoucherBalance(voucher) {
|
|
1249
|
+
var parValue = new Decimal(toMoneyNumber(voucher.par_value));
|
|
1250
|
+
var usedParValue = new Decimal(toMoneyNumber(voucher.used_par_value));
|
|
1251
|
+
return Decimal.max(parValue.minus(usedParValue), 0);
|
|
880
1252
|
}
|
|
881
1253
|
function buildPaymentItems(params) {
|
|
882
|
-
var _payment$amount;
|
|
883
1254
|
var payment = params.payment,
|
|
884
1255
|
locale = params.locale,
|
|
885
1256
|
currencySymbol = params.currencySymbol,
|
|
886
1257
|
includeFundRecordBalance = params.includeFundRecordBalance;
|
|
1258
|
+
var serviceFee = getPaymentServiceFee(payment);
|
|
887
1259
|
var items = [{
|
|
888
1260
|
item: paymentMethodName(payment, locale),
|
|
889
|
-
value: formatMoney((
|
|
1261
|
+
value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
|
|
890
1262
|
}];
|
|
1263
|
+
items.push.apply(items, _toConsumableArray(buildCashChangePaymentItems({
|
|
1264
|
+
payment: payment,
|
|
1265
|
+
locale: locale,
|
|
1266
|
+
currencySymbol: currencySymbol
|
|
1267
|
+
})));
|
|
1268
|
+
if (serviceFee.gt(0)) {
|
|
1269
|
+
items.push({
|
|
1270
|
+
item: label(locale, 'surchargeIncluded'),
|
|
1271
|
+
value: formatMoney(serviceFee, currencySymbol)
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
891
1274
|
var fundRecord = getFundRecord(payment);
|
|
892
1275
|
if (fundRecord) {
|
|
893
1276
|
items.push.apply(items, _toConsumableArray(buildFundRecordPaymentItems({
|
|
@@ -898,8 +1281,8 @@ function buildPaymentItems(params) {
|
|
|
898
1281
|
includeBalance: includeFundRecordBalance
|
|
899
1282
|
})));
|
|
900
1283
|
} else {
|
|
901
|
-
var
|
|
902
|
-
var remainingAmount = (
|
|
1284
|
+
var _ref44, _payment$remaining_am, _payment$metadata;
|
|
1285
|
+
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
1286
|
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
904
1287
|
items.push({
|
|
905
1288
|
item: label(locale, 'remainingAmount'),
|
|
@@ -913,6 +1296,47 @@ function buildPaymentItems(params) {
|
|
|
913
1296
|
});
|
|
914
1297
|
return items;
|
|
915
1298
|
}
|
|
1299
|
+
function getPaymentServiceFee(payment) {
|
|
1300
|
+
return new Decimal(toMoneyNumber(payment.service_fee));
|
|
1301
|
+
}
|
|
1302
|
+
function resolveReceiptPaymentAmount(payment, serviceFee) {
|
|
1303
|
+
var _payment$amount;
|
|
1304
|
+
var amount = new Decimal(toMoneyNumber((_payment$amount = payment.amount) !== null && _payment$amount !== void 0 ? _payment$amount : payment.origin_amount));
|
|
1305
|
+
var hasAmount = payment.amount !== undefined && payment.amount !== null && payment.amount !== '';
|
|
1306
|
+
var hasOriginAmount = payment.origin_amount !== undefined && payment.origin_amount !== null && payment.origin_amount !== '';
|
|
1307
|
+
if (!hasAmount || !hasOriginAmount || serviceFee.lte(0)) return amount;
|
|
1308
|
+
var originAmount = new Decimal(toMoneyNumber(payment.origin_amount));
|
|
1309
|
+
return amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
|
|
1310
|
+
}
|
|
1311
|
+
function buildCashChangePaymentItems(params) {
|
|
1312
|
+
var payment = params.payment,
|
|
1313
|
+
locale = params.locale,
|
|
1314
|
+
currencySymbol = params.currencySymbol;
|
|
1315
|
+
if (!shouldDisplayCashChange(payment)) return [];
|
|
1316
|
+
return [{
|
|
1317
|
+
item: label(locale, 'cashReceived'),
|
|
1318
|
+
value: formatMoney(payment.metadata.actual_paid_amount, currencySymbol)
|
|
1319
|
+
}, {
|
|
1320
|
+
item: label(locale, 'changeDue'),
|
|
1321
|
+
value: formatMoney(payment.metadata.change_given_amount, currencySymbol)
|
|
1322
|
+
}];
|
|
1323
|
+
}
|
|
1324
|
+
function shouldDisplayCashChange(payment) {
|
|
1325
|
+
var _payment$code, _payment$metadata2, _payment$metadata3;
|
|
1326
|
+
if (stringify(payment.status).toLowerCase() !== 'paid') return false;
|
|
1327
|
+
var paymentMethod = stringify((_payment$code = payment.code) !== null && _payment$code !== void 0 ? _payment$code : payment.payment_method).toUpperCase();
|
|
1328
|
+
if (paymentMethod !== 'CASHMANUAL') return false;
|
|
1329
|
+
var actualPaidAmount = (_payment$metadata2 = payment.metadata) === null || _payment$metadata2 === void 0 ? void 0 : _payment$metadata2.actual_paid_amount;
|
|
1330
|
+
var changeGivenAmount = (_payment$metadata3 = payment.metadata) === null || _payment$metadata3 === void 0 ? void 0 : _payment$metadata3.change_given_amount;
|
|
1331
|
+
if (!isNumericAmount(actualPaidAmount) || !isNumericAmount(changeGivenAmount)) return false;
|
|
1332
|
+
return new Decimal(changeGivenAmount).toDecimalPlaces(2).gt(0);
|
|
1333
|
+
}
|
|
1334
|
+
function isNumericAmount(value) {
|
|
1335
|
+
if (typeof value === 'number') return Number.isFinite(value);
|
|
1336
|
+
if (typeof value !== 'string') return false;
|
|
1337
|
+
var normalized = value.trim();
|
|
1338
|
+
return normalized !== '' && /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(normalized);
|
|
1339
|
+
}
|
|
916
1340
|
function buildFundRecordPaymentItems(params) {
|
|
917
1341
|
var payment = params.payment,
|
|
918
1342
|
fundRecord = params.fundRecord,
|
|
@@ -1009,20 +1433,37 @@ function label(locale, key) {
|
|
|
1009
1433
|
return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
|
|
1010
1434
|
}
|
|
1011
1435
|
function getLocalizedValue(value, locale) {
|
|
1012
|
-
var
|
|
1436
|
+
var _ref45, _ref46, _ref47, _ref48, _ref49, _ref50, _value$locale2;
|
|
1013
1437
|
if (value === undefined || value === null) return '';
|
|
1014
1438
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
1015
1439
|
var dashedLocale = locale.replace('_', '-');
|
|
1016
1440
|
var underscoredLocale = locale.replace('-', '_');
|
|
1017
|
-
return stringify((
|
|
1441
|
+
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 : '');
|
|
1442
|
+
}
|
|
1443
|
+
function resolveServiceTypeLabelKey(serviceType, order) {
|
|
1444
|
+
var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
1445
|
+
if (['', 'nil', 'none', 'unknown'].includes(normalized)) return null;
|
|
1446
|
+
if (['pickup', 'pick_up', 'self_pickup'].includes(normalized)) return 'pickUp';
|
|
1447
|
+
if (['delivery', 'shipping', 'local_delivery'].includes(normalized)) return 'delivery';
|
|
1448
|
+
if (['takeaway', 'take_away'].includes(normalized)) return 'takeAway';
|
|
1449
|
+
if (['dine_in', 'dinein'].includes(normalized)) return 'dineIn';
|
|
1450
|
+
if (['shop_service', 'shop_server'].includes(normalized)) {
|
|
1451
|
+
return resolveShopServiceLabelKey(order);
|
|
1452
|
+
}
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
function resolveShopServiceLabelKey(order) {
|
|
1456
|
+
var _order$metadata15, _order$shop_service_t;
|
|
1457
|
+
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);
|
|
1458
|
+
if (!isPresentId(rawShopServiceType)) return 'dineIn';
|
|
1459
|
+
var normalized = stringify(rawShopServiceType).trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
1460
|
+
if (['takeaway', 'take_away'].includes(normalized)) return 'takeAway';
|
|
1461
|
+
if (['dine_in', 'dinein'].includes(normalized)) return 'dineIn';
|
|
1462
|
+
return null;
|
|
1018
1463
|
}
|
|
1019
|
-
function
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
if (normalized.includes('delivery')) return 'delivery';
|
|
1023
|
-
if (normalized.includes('pick')) return 'pickUp';
|
|
1024
|
-
if (normalized.includes('shop')) return 'shopService';
|
|
1025
|
-
return 'dineIn';
|
|
1464
|
+
function normalizeBooleanFlag(value) {
|
|
1465
|
+
if (value === true || value === 1 || stringify(value).trim() === '1') return 1;
|
|
1466
|
+
return 0;
|
|
1026
1467
|
}
|
|
1027
1468
|
function buildShopAddress(shopInfo) {
|
|
1028
1469
|
return [shopInfo.address_street, shopInfo.address_detail, shopInfo.city, shopInfo.province, shopInfo.country, shopInfo.zip].filter(Boolean).join(', ');
|
|
@@ -1043,18 +1484,19 @@ function formatNegativeMoney(value, currencySymbol) {
|
|
|
1043
1484
|
var amount = new Decimal(toMoneyNumber(value)).abs();
|
|
1044
1485
|
return "-".concat(currencySymbol).concat(amount.toFixed(2));
|
|
1045
1486
|
}
|
|
1046
|
-
function
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1487
|
+
function sumAppliedPayments(payments) {
|
|
1488
|
+
return normalizeArray(payments).filter(function (payment) {
|
|
1489
|
+
return isPrintablePayment(payment);
|
|
1490
|
+
}).reduce(function (sum, payment) {
|
|
1491
|
+
if (isPresentId(payment.origin_amount)) {
|
|
1492
|
+
return sum.plus(toMoneyNumber(payment.origin_amount));
|
|
1493
|
+
}
|
|
1494
|
+
var amount = new Decimal(toMoneyNumber(payment.amount));
|
|
1495
|
+
var serviceFee = Decimal.max(toMoneyNumber(payment.service_fee), 0);
|
|
1496
|
+
return sum.plus(Decimal.max(amount.minus(serviceFee), 0));
|
|
1497
|
+
}, new Decimal(0));
|
|
1498
|
+
}
|
|
1499
|
+
function sumCustomerPaidPayments(payments) {
|
|
1058
1500
|
return normalizeArray(payments).filter(function (payment) {
|
|
1059
1501
|
return isPrintablePayment(payment);
|
|
1060
1502
|
}).reduce(function (sum, payment) {
|
|
@@ -1065,7 +1507,7 @@ function sumPayments(payments) {
|
|
|
1065
1507
|
function isPrintablePayment(payment) {
|
|
1066
1508
|
var status = stringify(payment.status).toLowerCase();
|
|
1067
1509
|
if (!status) return true;
|
|
1068
|
-
return ['paid', 'success', 'succeeded', 'completed'].includes(status);
|
|
1510
|
+
return ['paid', 'success', 'succeeded', 'completed', 'partially_refunded', 'refunded'].includes(status);
|
|
1069
1511
|
}
|
|
1070
1512
|
function normalizeArray(value) {
|
|
1071
1513
|
return Array.isArray(value) ? value : [];
|