@pisell/pisellos 2.3.109 → 2.3.110
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/modules/OpenData/index.d.ts +1 -1
- package/dist/modules/OpenData/index.js +19 -11
- package/dist/modules/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +22 -21
- package/dist/server/index.js +4 -5
- package/dist/server/utils/small-ticket.d.ts +7 -5
- package/dist/server/utils/small-ticket.js +653 -138
- package/dist/solution/BookingTicket/index.d.ts +6 -0
- package/dist/solution/BookingTicket/index.js +548 -485
- package/dist/utils/os-private-payload.d.ts +5 -0
- package/dist/utils/os-private-payload.js +17 -0
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/OpenData/index.d.ts +1 -1
- package/lib/modules/OpenData/index.js +9 -1
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +15 -18
- package/lib/server/index.js +4 -5
- package/lib/server/utils/small-ticket.d.ts +7 -5
- package/lib/server/utils/small-ticket.js +504 -65
- package/lib/solution/BookingTicket/index.d.ts +6 -0
- package/lib/solution/BookingTicket/index.js +32 -3
- package/lib/utils/os-private-payload.d.ts +5 -0
- package/lib/utils/os-private-payload.js +22 -0
- package/package.json +1 -1
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
var _excluded = ["isMarkup"];
|
|
1
2
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
3
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
4
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
5
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
7
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
8
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
9
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
10
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
11
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
13
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
15
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
16
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -35,13 +39,20 @@ var LABELS = {
|
|
|
35
39
|
eftpos: 'Eftpos',
|
|
36
40
|
wallet: 'Wallet',
|
|
37
41
|
giftCard: 'Gift card',
|
|
42
|
+
pointCard: 'Point card',
|
|
38
43
|
balance: 'Balance',
|
|
44
|
+
validity: 'Validity',
|
|
39
45
|
remainingAmount: 'Remaining amount',
|
|
40
46
|
redeemPoints: 'Redeem points',
|
|
41
|
-
remainingPoints: '
|
|
47
|
+
remainingPoints: 'Points balance',
|
|
42
48
|
table: 'Table',
|
|
49
|
+
bookingId: 'Booking ID',
|
|
50
|
+
bookingDateTime: 'Date & time',
|
|
51
|
+
bookingResource: 'Resource',
|
|
52
|
+
bookingHolder: 'Holder',
|
|
43
53
|
orderDiscount: 'Order discount',
|
|
44
54
|
manualDiscount: 'Manual discount',
|
|
55
|
+
manualMarkup: 'Manual markup',
|
|
45
56
|
payProcessingFee: 'Pay processing fee',
|
|
46
57
|
surchargeIncluded: 'Surcharge(Included)',
|
|
47
58
|
rounding: 'Rounding',
|
|
@@ -67,13 +78,20 @@ var LABELS = {
|
|
|
67
78
|
eftpos: '刷卡支付',
|
|
68
79
|
wallet: '钱包支付',
|
|
69
80
|
giftCard: '礼品卡',
|
|
81
|
+
pointCard: '积分卡',
|
|
70
82
|
balance: '余额',
|
|
83
|
+
validity: '有效期',
|
|
71
84
|
remainingAmount: '剩余金额',
|
|
72
85
|
redeemPoints: '本次使用积分',
|
|
73
|
-
remainingPoints: '
|
|
86
|
+
remainingPoints: '积分余额',
|
|
74
87
|
table: '桌台',
|
|
88
|
+
bookingId: '预约编号',
|
|
89
|
+
bookingDateTime: '日期和时间',
|
|
90
|
+
bookingResource: '资源',
|
|
91
|
+
bookingHolder: '预约人',
|
|
75
92
|
orderDiscount: '整单折扣',
|
|
76
93
|
manualDiscount: '手动折扣',
|
|
94
|
+
manualMarkup: '手动加价',
|
|
77
95
|
payProcessingFee: '支付手续费',
|
|
78
96
|
surchargeIncluded: '手续费(已含)',
|
|
79
97
|
rounding: '抹零',
|
|
@@ -99,13 +117,20 @@ var LABELS = {
|
|
|
99
117
|
eftpos: '刷卡支付',
|
|
100
118
|
wallet: '錢包支付',
|
|
101
119
|
giftCard: '禮品卡',
|
|
120
|
+
pointCard: '積分卡',
|
|
102
121
|
balance: '餘額',
|
|
122
|
+
validity: '有效期',
|
|
103
123
|
remainingAmount: '剩餘金額',
|
|
104
124
|
redeemPoints: '本次使用積分',
|
|
105
|
-
remainingPoints: '
|
|
125
|
+
remainingPoints: '積分餘額',
|
|
106
126
|
table: '桌台',
|
|
127
|
+
bookingId: '預約編號',
|
|
128
|
+
bookingDateTime: '日期和時間',
|
|
129
|
+
bookingResource: '資源',
|
|
130
|
+
bookingHolder: '預約人',
|
|
107
131
|
orderDiscount: '整單折扣',
|
|
108
132
|
manualDiscount: '手動折扣',
|
|
133
|
+
manualMarkup: '手動加價',
|
|
109
134
|
payProcessingFee: '支付手續費',
|
|
110
135
|
surchargeIncluded: '手續費(已含)',
|
|
111
136
|
rounding: '抹零',
|
|
@@ -129,13 +154,20 @@ var LABELS = {
|
|
|
129
154
|
eftpos: 'カード',
|
|
130
155
|
wallet: 'ウォレット',
|
|
131
156
|
giftCard: 'ギフトカード',
|
|
157
|
+
pointCard: 'ポイントカード',
|
|
132
158
|
balance: '残高',
|
|
159
|
+
validity: '有効期限',
|
|
133
160
|
remainingAmount: '残高',
|
|
134
161
|
redeemPoints: '利用ポイント',
|
|
135
|
-
remainingPoints: '
|
|
162
|
+
remainingPoints: 'ポイント残高',
|
|
136
163
|
table: 'テーブル',
|
|
164
|
+
bookingId: '予約ID',
|
|
165
|
+
bookingDateTime: '日時',
|
|
166
|
+
bookingResource: 'リソース',
|
|
167
|
+
bookingHolder: '予約者',
|
|
137
168
|
orderDiscount: '注文割引',
|
|
138
169
|
manualDiscount: '手動割引',
|
|
170
|
+
manualMarkup: '手動値上げ',
|
|
139
171
|
payProcessingFee: '決済手数料',
|
|
140
172
|
rounding: '端数調整',
|
|
141
173
|
gross: '総重量',
|
|
@@ -160,13 +192,20 @@ var LABELS = {
|
|
|
160
192
|
eftpos: 'Cartão',
|
|
161
193
|
wallet: 'Carteira',
|
|
162
194
|
giftCard: 'Cartão-presente',
|
|
195
|
+
pointCard: 'Cartão de pontos',
|
|
163
196
|
balance: 'Saldo',
|
|
197
|
+
validity: 'Validade',
|
|
164
198
|
remainingAmount: 'Saldo restante',
|
|
165
199
|
redeemPoints: 'Pontos utilizados',
|
|
166
|
-
remainingPoints: '
|
|
200
|
+
remainingPoints: 'Saldo de pontos',
|
|
167
201
|
table: 'Mesa',
|
|
202
|
+
bookingId: 'ID da reserva',
|
|
203
|
+
bookingDateTime: 'Data e hora',
|
|
204
|
+
bookingResource: 'Recurso',
|
|
205
|
+
bookingHolder: 'Titular',
|
|
168
206
|
orderDiscount: 'Desconto do pedido',
|
|
169
207
|
manualDiscount: 'Desconto manual',
|
|
208
|
+
manualMarkup: 'Acréscimo manual',
|
|
170
209
|
payProcessingFee: 'Taxa de processamento',
|
|
171
210
|
rounding: 'Arredondamento',
|
|
172
211
|
gross: 'Peso bruto',
|
|
@@ -250,14 +289,14 @@ function buildLocaleData(params) {
|
|
|
250
289
|
});
|
|
251
290
|
}
|
|
252
291
|
function buildBaseData(params) {
|
|
253
|
-
var _order$metadata;
|
|
292
|
+
var _financials$amountGap, _order$metadata;
|
|
254
293
|
var order = params.order,
|
|
255
294
|
shopInfo = params.shopInfo,
|
|
256
295
|
locale = params.locale,
|
|
257
296
|
currencySymbol = params.currencySymbol,
|
|
258
297
|
financials = params.financials;
|
|
259
298
|
var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
|
|
260
|
-
return _objectSpread(
|
|
299
|
+
return _objectSpread({
|
|
261
300
|
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
262
301
|
note: stringify(order.note),
|
|
263
302
|
shop_order_number: stringify(order.shop_order_number),
|
|
@@ -268,10 +307,8 @@ function buildBaseData(params) {
|
|
|
268
307
|
original_payment_status: financials.paymentStatus,
|
|
269
308
|
payment_status: financials.paymentStatus,
|
|
270
309
|
total_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
271
|
-
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol)
|
|
272
|
-
|
|
273
|
-
amount_gap: formatMoney(financials.amountGap, currencySymbol)
|
|
274
|
-
} : {}), {}, {
|
|
310
|
+
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol),
|
|
311
|
+
amount_gap: formatCalculatedMoney((_financials$amountGap = financials.amountGap) !== null && _financials$amountGap !== void 0 ? _financials$amountGap : 0, currencySymbol),
|
|
275
312
|
is_repeat: 0,
|
|
276
313
|
buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
|
|
277
314
|
order_no: orderNumber,
|
|
@@ -282,8 +319,9 @@ function buildBaseData(params) {
|
|
|
282
319
|
}
|
|
283
320
|
function buildProducts(order, locale, productMap) {
|
|
284
321
|
var products = Array.isArray(order.products) ? order.products : [];
|
|
285
|
-
return products.map(function (
|
|
322
|
+
return products.map(function (rawProduct) {
|
|
286
323
|
var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric, _product$product_id, _product$metadata, _product$metadata2;
|
|
324
|
+
var product = restoreReceiptDiscountHierarchy(rawProduct);
|
|
287
325
|
var quantity = toNumber((_ref = (_ref2 = (_product$product_quan = product.product_quantity) !== null && _product$product_quan !== void 0 ? _product$product_quan : product.quantity) !== null && _ref2 !== void 0 ? _ref2 : product.num) !== null && _ref !== void 0 ? _ref : 1, 1);
|
|
288
326
|
var originalPrice = (_ref3 = (_ref4 = (_ref5 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref5 !== void 0 ? _ref5 : product.payment_price) !== null && _ref4 !== void 0 ? _ref4 : product.price) !== null && _ref3 !== void 0 ? _ref3 : 0;
|
|
289
327
|
var sellingPrice = (_ref6 = (_ref7 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.payment_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : originalPrice;
|
|
@@ -323,15 +361,23 @@ function buildProducts(order, locale, productMap) {
|
|
|
323
361
|
});
|
|
324
362
|
var productNote = resolveProductNote(product, locale);
|
|
325
363
|
var basePrice = resolveProductBasePrice(product);
|
|
326
|
-
|
|
364
|
+
var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
|
|
365
|
+
var shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
|
|
366
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
327
367
|
product_title: productTitle,
|
|
328
368
|
product_quantity: quantity,
|
|
329
369
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
370
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
|
|
330
371
|
original_price: formatMoney(originalPrice, currencySymbol)
|
|
331
|
-
},
|
|
332
|
-
base_price:
|
|
372
|
+
}, shouldIncludeBasePrice ? {
|
|
373
|
+
base_price: formatCalculatedMoney(basePrice !== null && basePrice !== void 0 ? basePrice : 0, currencySymbol)
|
|
374
|
+
} : {}), {}, {
|
|
375
|
+
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol)
|
|
376
|
+
}, options.length ? {
|
|
377
|
+
options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
|
|
378
|
+
} : {}), resolvedCombinations.length ? {
|
|
379
|
+
package_items_total_price: sumCombinationTotals(resolvedCombinations, currencySymbol)
|
|
333
380
|
} : {}), {}, {
|
|
334
|
-
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
335
381
|
extension_list: extensionList
|
|
336
382
|
}, isPresentId(productUid) ? {
|
|
337
383
|
product_uid: productUid
|
|
@@ -343,13 +389,101 @@ function buildProducts(order, locale, productMap) {
|
|
|
343
389
|
options: options
|
|
344
390
|
} : {}), resolvedVariant ? {
|
|
345
391
|
variant: resolvedVariant
|
|
346
|
-
} : {}),
|
|
347
|
-
combinations:
|
|
348
|
-
} : combinations.length ? {
|
|
349
|
-
combinations: combinations
|
|
392
|
+
} : {}), resolvedCombinations.length ? {
|
|
393
|
+
combinations: resolvedCombinations
|
|
350
394
|
} : {});
|
|
351
395
|
});
|
|
352
396
|
}
|
|
397
|
+
var RECEIPT_BUNDLE_MAP_ID_KEY = 'custom_product_bundle_map_id';
|
|
398
|
+
function restoreReceiptDiscountHierarchy(source) {
|
|
399
|
+
if (!source || _typeof(source) !== 'object' || Array.isArray(source)) {
|
|
400
|
+
return source;
|
|
401
|
+
}
|
|
402
|
+
var childKey = Array.isArray(source.combinations) && source.combinations.length ? 'combinations' : Array.isArray(source.product_bundle) && source.product_bundle.length ? 'product_bundle' : null;
|
|
403
|
+
if (!childKey) return _objectSpread({}, source);
|
|
404
|
+
var children = source[childKey].map(function (child) {
|
|
405
|
+
return child && _typeof(child) === 'object' && !Array.isArray(child) ? restoreReceiptDiscountHierarchy(child) : child;
|
|
406
|
+
});
|
|
407
|
+
var restored = _objectSpread(_objectSpread({}, source), {}, _defineProperty({}, childKey, children));
|
|
408
|
+
if (!Array.isArray(source.discount_list) || !source.discount_list.length) {
|
|
409
|
+
return restored;
|
|
410
|
+
}
|
|
411
|
+
var descendantsByMapId = new Map();
|
|
412
|
+
indexReceiptDiscountTargets(children, descendantsByMapId);
|
|
413
|
+
if (!descendantsByMapId.size) return restored;
|
|
414
|
+
var ownDiscounts = [];
|
|
415
|
+
var _iterator = _createForOfIteratorHelper(source.discount_list),
|
|
416
|
+
_step;
|
|
417
|
+
try {
|
|
418
|
+
var _loop = function _loop() {
|
|
419
|
+
var discount = _step.value;
|
|
420
|
+
var mapId = getReceiptDiscountBundleMapId(discount);
|
|
421
|
+
var target = mapId ? descendantsByMapId.get(mapId) : undefined;
|
|
422
|
+
if (!target) {
|
|
423
|
+
ownDiscounts.push(discount);
|
|
424
|
+
return 1; // continue
|
|
425
|
+
}
|
|
426
|
+
var targetDiscounts = Array.isArray(target.discount_list) ? target.discount_list : [];
|
|
427
|
+
if (!targetDiscounts.some(function (item) {
|
|
428
|
+
return isSameReceiptDiscount(item, discount);
|
|
429
|
+
})) {
|
|
430
|
+
target.discount_list = [].concat(_toConsumableArray(targetDiscounts), [discount]);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
434
|
+
if (_loop()) continue;
|
|
435
|
+
}
|
|
436
|
+
} catch (err) {
|
|
437
|
+
_iterator.e(err);
|
|
438
|
+
} finally {
|
|
439
|
+
_iterator.f();
|
|
440
|
+
}
|
|
441
|
+
restored.discount_list = ownDiscounts;
|
|
442
|
+
return restored;
|
|
443
|
+
}
|
|
444
|
+
function indexReceiptDiscountTargets(nodes, targets) {
|
|
445
|
+
var _iterator2 = _createForOfIteratorHelper(nodes),
|
|
446
|
+
_step2;
|
|
447
|
+
try {
|
|
448
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
449
|
+
var node = _step2.value;
|
|
450
|
+
if (!node || _typeof(node) !== 'object' || Array.isArray(node)) continue;
|
|
451
|
+
var mapId = getReceiptBundleMapId(node);
|
|
452
|
+
if (mapId && !targets.has(mapId)) targets.set(mapId, node);
|
|
453
|
+
var children = Array.isArray(node.combinations) && node.combinations.length ? node.combinations : Array.isArray(node.product_bundle) ? node.product_bundle : [];
|
|
454
|
+
indexReceiptDiscountTargets(children, targets);
|
|
455
|
+
}
|
|
456
|
+
} catch (err) {
|
|
457
|
+
_iterator2.e(err);
|
|
458
|
+
} finally {
|
|
459
|
+
_iterator2.f();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function normalizeReceiptId(value) {
|
|
463
|
+
if (value === undefined || value === null) return null;
|
|
464
|
+
var normalized = String(value).trim();
|
|
465
|
+
return normalized ? normalized : null;
|
|
466
|
+
}
|
|
467
|
+
function getReceiptBundleMapId(node) {
|
|
468
|
+
var _node$metadata$RECEIP, _node$metadata;
|
|
469
|
+
return normalizeReceiptId((_node$metadata$RECEIP = (_node$metadata = node.metadata) === null || _node$metadata === void 0 ? void 0 : _node$metadata[RECEIPT_BUNDLE_MAP_ID_KEY]) !== null && _node$metadata$RECEIP !== void 0 ? _node$metadata$RECEIP : node._id);
|
|
470
|
+
}
|
|
471
|
+
function getReceiptDiscountBundleMapId(discount) {
|
|
472
|
+
var _discount$metadata;
|
|
473
|
+
return normalizeReceiptId(discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata[RECEIPT_BUNDLE_MAP_ID_KEY]);
|
|
474
|
+
}
|
|
475
|
+
function isSameReceiptDiscount(left, right) {
|
|
476
|
+
var _ref8, _left$discount$resour, _left$discount, _ref9, _right$discount$resou, _right$discount, _ref10, _ref11, _left$amount, _ref12, _ref13, _right$amount;
|
|
477
|
+
var leftOrderDiscountId = normalizeReceiptId(left === null || left === void 0 ? void 0 : left.order_discount_id);
|
|
478
|
+
var rightOrderDiscountId = normalizeReceiptId(right === null || right === void 0 ? void 0 : right.order_discount_id);
|
|
479
|
+
if (leftOrderDiscountId && rightOrderDiscountId) {
|
|
480
|
+
return leftOrderDiscountId === rightOrderDiscountId;
|
|
481
|
+
}
|
|
482
|
+
var leftResourceId = normalizeReceiptId((_ref8 = (_left$discount$resour = left === null || left === void 0 || (_left$discount = left.discount) === null || _left$discount === void 0 ? void 0 : _left$discount.resource_id) !== null && _left$discount$resour !== void 0 ? _left$discount$resour : left === null || left === void 0 ? void 0 : left.resource_id) !== null && _ref8 !== void 0 ? _ref8 : left === null || left === void 0 ? void 0 : left.discount_id);
|
|
483
|
+
var rightResourceId = normalizeReceiptId((_ref9 = (_right$discount$resou = right === null || right === void 0 || (_right$discount = right.discount) === null || _right$discount === void 0 ? void 0 : _right$discount.resource_id) !== null && _right$discount$resou !== void 0 ? _right$discount$resou : right === null || right === void 0 ? void 0 : right.resource_id) !== null && _ref9 !== void 0 ? _ref9 : right === null || right === void 0 ? void 0 : right.discount_id);
|
|
484
|
+
if (!leftResourceId || !rightResourceId) return false;
|
|
485
|
+
return leftResourceId === rightResourceId && getReceiptDiscountBundleMapId(left) === getReceiptDiscountBundleMapId(right) && String((_ref10 = (_ref11 = (_left$amount = left === null || left === void 0 ? void 0 : left.amount) !== null && _left$amount !== void 0 ? _left$amount : left === null || left === void 0 ? void 0 : left.value) !== null && _ref11 !== void 0 ? _ref11 : left === null || left === void 0 ? void 0 : left.discount_amount) !== null && _ref10 !== void 0 ? _ref10 : '') === String((_ref12 = (_ref13 = (_right$amount = right === null || right === void 0 ? void 0 : right.amount) !== null && _right$amount !== void 0 ? _right$amount : right === null || right === void 0 ? void 0 : right.value) !== null && _ref13 !== void 0 ? _ref13 : right === null || right === void 0 ? void 0 : right.discount_amount) !== null && _ref12 !== void 0 ? _ref12 : '');
|
|
486
|
+
}
|
|
353
487
|
function resolveProductBasePrice(product) {
|
|
354
488
|
var _product$product_vari, _product$_origin, _product$_origin2;
|
|
355
489
|
var metadata = product.metadata || {};
|
|
@@ -366,16 +500,47 @@ function normalizeProductDiscounts(params) {
|
|
|
366
500
|
locale = params.locale,
|
|
367
501
|
currencySymbol = params.currencySymbol,
|
|
368
502
|
quantity = params.quantity;
|
|
369
|
-
|
|
370
|
-
var
|
|
503
|
+
var rows = normalizeArray(product.discount_list).filter(function (discount) {
|
|
504
|
+
var _ref14, _discount$amount;
|
|
505
|
+
var amount = (_ref14 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref14 !== void 0 ? _ref14 : discount.discount_amount;
|
|
506
|
+
return isNonZero(amount);
|
|
507
|
+
}).map(function (discount) {
|
|
508
|
+
var _ref15, _discount$amount2;
|
|
371
509
|
var title = resolveDiscountTitleWithPercent(discount, locale);
|
|
372
|
-
var amount = (
|
|
373
|
-
var
|
|
510
|
+
var amount = (_ref15 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref15 !== void 0 ? _ref15 : discount.discount_amount;
|
|
511
|
+
var isMarkup = isManualMarkup(discount);
|
|
512
|
+
var totalAmount = new Decimal(toMoneyNumber(amount)).mul(quantity);
|
|
513
|
+
var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
|
|
374
514
|
return {
|
|
375
515
|
item: title,
|
|
376
|
-
value: formattedAmount
|
|
516
|
+
value: formattedAmount,
|
|
517
|
+
isMarkup: isMarkup
|
|
377
518
|
};
|
|
378
519
|
});
|
|
520
|
+
return rows.sort(function (left, right) {
|
|
521
|
+
return Number(right.isMarkup) - Number(left.isMarkup);
|
|
522
|
+
}).map(function (_ref16) {
|
|
523
|
+
var _isMarkup = _ref16.isMarkup,
|
|
524
|
+
row = _objectWithoutProperties(_ref16, _excluded);
|
|
525
|
+
return row;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
function isManualMarkup(discount) {
|
|
529
|
+
var _discount$discount, _ref17, _discount$amount3;
|
|
530
|
+
if (discount.type !== 'product') return false;
|
|
531
|
+
if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
|
|
532
|
+
var amount = (_ref17 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
|
|
533
|
+
return new Decimal(toMoneyNumber(amount)).isNegative();
|
|
534
|
+
}
|
|
535
|
+
function hasProductDiscount(product) {
|
|
536
|
+
var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
537
|
+
var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
|
|
538
|
+
var _ref18, _discount$amount4;
|
|
539
|
+
return isNonZero((_ref18 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref18 !== void 0 ? _ref18 : discount.discount_amount);
|
|
540
|
+
});
|
|
541
|
+
return hasDiscountListAmount || extensionList.some(function (row) {
|
|
542
|
+
return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
|
|
543
|
+
});
|
|
379
544
|
}
|
|
380
545
|
function buildProductExtensionList(params) {
|
|
381
546
|
var product = params.product,
|
|
@@ -442,10 +607,10 @@ function buildProductQuantityPriceText(params) {
|
|
|
442
607
|
return "".concat(quantity, " @ ").concat(currencySymbol).concat(stringify(price), " EACH");
|
|
443
608
|
}
|
|
444
609
|
function resolveDiscountTitleWithPercent(discount, locale) {
|
|
445
|
-
var _discount$
|
|
610
|
+
var _discount$discount2, _discount$discount$di, _discount$discount3;
|
|
446
611
|
var title = resolveDiscountTitle(discount, locale);
|
|
447
|
-
var percentRaw = (_discount$
|
|
448
|
-
var cardType = (_discount$discount$di = (_discount$
|
|
612
|
+
var percentRaw = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.percent;
|
|
613
|
+
var cardType = (_discount$discount$di = (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.discount_card_type) !== null && _discount$discount$di !== void 0 ? _discount$discount$di : 'percent';
|
|
449
614
|
var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
|
|
450
615
|
if (percentRaw === undefined || percentRaw === null) return title;
|
|
451
616
|
if (cardType !== 'percent') return title;
|
|
@@ -453,10 +618,12 @@ function resolveDiscountTitleWithPercent(discount, locale) {
|
|
|
453
618
|
return "".concat(title, " (").concat(percent, "%)");
|
|
454
619
|
}
|
|
455
620
|
function resolveDiscountTitle(discount, locale) {
|
|
456
|
-
var
|
|
457
|
-
var title = getLocalizedValue((
|
|
621
|
+
var _ref19, _ref20, _ref21, _ref22, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
|
|
622
|
+
var title = getLocalizedValue((_ref19 = (_ref20 = (_ref21 = (_ref22 = (_discount$discount$na = (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.title) !== null && _ref22 !== void 0 ? _ref22 : (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.message) !== null && _ref21 !== void 0 ? _ref21 : discount.name) !== null && _ref20 !== void 0 ? _ref20 : discount.title) !== null && _ref19 !== void 0 ? _ref19 : discount.message, locale);
|
|
458
623
|
if (title) return title;
|
|
459
|
-
if (discount.type === 'product')
|
|
624
|
+
if (discount.type === 'product') {
|
|
625
|
+
return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
|
|
626
|
+
}
|
|
460
627
|
return '';
|
|
461
628
|
}
|
|
462
629
|
function resolveProductTitle(params) {
|
|
@@ -479,9 +646,10 @@ function normalizeProductOptions(params) {
|
|
|
479
646
|
parentProduct = params.parentProduct;
|
|
480
647
|
var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option) ? product.product_sku.option : [];
|
|
481
648
|
return rawOptions.map(function (option) {
|
|
482
|
-
var
|
|
483
|
-
var price = (
|
|
484
|
-
var
|
|
649
|
+
var _ref23, _option$original_pric, _ref24, _option$num, _ref25, _option$value;
|
|
650
|
+
var price = (_ref23 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref23 !== void 0 ? _ref23 : option.price;
|
|
651
|
+
var quantity = toNumber((_ref24 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref24 !== void 0 ? _ref24 : 1, 1);
|
|
652
|
+
var value = (_ref25 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref25 !== void 0 ? _ref25 : option.item;
|
|
485
653
|
var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
|
|
486
654
|
option: option,
|
|
487
655
|
parentProduct: parentProduct,
|
|
@@ -490,10 +658,12 @@ function normalizeProductOptions(params) {
|
|
|
490
658
|
return _objectSpread(_objectSpread(_objectSpread({
|
|
491
659
|
name: name
|
|
492
660
|
}, option.num !== undefined || option.quantity !== undefined ? {
|
|
493
|
-
num:
|
|
661
|
+
num: quantity
|
|
494
662
|
} : {}), price !== undefined && price !== null && price !== '' ? {
|
|
495
663
|
price: formatMoney(price, currencySymbol)
|
|
496
|
-
} : {}),
|
|
664
|
+
} : {}), {}, {
|
|
665
|
+
total_price: formatCalculatedMoney(new Decimal(toMoneyNumber(price !== null && price !== void 0 ? price : 0)).mul(quantity), currencySymbol)
|
|
666
|
+
}, value !== undefined && value !== null && value !== '' ? {
|
|
497
667
|
value: getLocalizedValue(value, locale)
|
|
498
668
|
} : {});
|
|
499
669
|
});
|
|
@@ -506,7 +676,7 @@ function normalizeProductCombinations(params) {
|
|
|
506
676
|
parentProduct = params.parentProduct;
|
|
507
677
|
var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
508
678
|
return bundles.map(function (bundle) {
|
|
509
|
-
var
|
|
679
|
+
var _ref26, _bundle$num;
|
|
510
680
|
var combinationsOptions = normalizeProductOptions({
|
|
511
681
|
product: {},
|
|
512
682
|
locale: locale,
|
|
@@ -521,43 +691,127 @@ function normalizeProductCombinations(params) {
|
|
|
521
691
|
parentProduct: parentProduct
|
|
522
692
|
});
|
|
523
693
|
var productNote = resolveProductNote(bundle, locale);
|
|
524
|
-
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
|
|
525
|
-
|
|
694
|
+
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
|
|
695
|
+
var quantity = toNumber((_ref26 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
|
|
696
|
+
var formattedPrice = formatBundlePrice(bundle, currencySymbol);
|
|
697
|
+
var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
|
|
698
|
+
var explicitBasePrice = resolveCombinationBasePrice(bundle);
|
|
699
|
+
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
700
|
+
var extensionList = buildProductExtensionList({
|
|
701
|
+
product: bundle,
|
|
702
|
+
locale: locale,
|
|
703
|
+
currencySymbol: currencySymbol,
|
|
704
|
+
quantity: quantity,
|
|
705
|
+
originalPrice: formattedPrice
|
|
706
|
+
});
|
|
707
|
+
var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle, extensionList);
|
|
708
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
526
709
|
product_title: baseTitle,
|
|
527
|
-
product_quantity:
|
|
528
|
-
price:
|
|
710
|
+
product_quantity: quantity,
|
|
711
|
+
price: formattedPrice,
|
|
712
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol)
|
|
713
|
+
}, shouldIncludeBasePrice ? {
|
|
714
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
715
|
+
} : {}), {}, {
|
|
529
716
|
combinations_options: combinationsOptions
|
|
530
|
-
},
|
|
717
|
+
}, combinationsOptions.length ? {
|
|
718
|
+
options_total_price: optionsTotal
|
|
719
|
+
} : {}), nestedCombinations.length ? {
|
|
720
|
+
package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
|
|
721
|
+
} : {}), productNote ? {
|
|
531
722
|
product_note: productNote
|
|
723
|
+
} : {}), extensionList.length ? {
|
|
724
|
+
extension_list: extensionList
|
|
532
725
|
} : {}), nestedCombinations.length ? {
|
|
533
726
|
combinations: nestedCombinations
|
|
534
727
|
} : {});
|
|
535
728
|
});
|
|
536
729
|
}
|
|
537
|
-
function normalizeExistingCombinations(combinations, locale) {
|
|
730
|
+
function normalizeExistingCombinations(combinations, locale, currencySymbol) {
|
|
538
731
|
return combinations.map(function (combination) {
|
|
732
|
+
var _ref27, _ref28, _combination$product_, _firstPresentValue;
|
|
539
733
|
if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
|
|
540
734
|
return combination;
|
|
541
735
|
}
|
|
542
736
|
var productNote = resolveProductNote(combination, locale);
|
|
543
|
-
var
|
|
737
|
+
var rawOptions = Array.isArray(combination.combinations_options) ? combination.combinations_options : Array.isArray(combination.options) ? combination.options : [];
|
|
738
|
+
var normalizedOptions = normalizeProductOptions({
|
|
739
|
+
product: {},
|
|
740
|
+
locale: locale,
|
|
741
|
+
currencySymbol: currencySymbol,
|
|
742
|
+
options: rawOptions
|
|
743
|
+
});
|
|
744
|
+
var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
|
|
544
745
|
var snapshot = _objectSpread({}, combination);
|
|
545
746
|
delete snapshot.product_note;
|
|
546
747
|
delete snapshot.note;
|
|
547
|
-
|
|
748
|
+
delete snapshot.combinations;
|
|
749
|
+
delete snapshot.discount_list;
|
|
750
|
+
var quantity = toNumber((_ref27 = (_ref28 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref28 !== void 0 ? _ref28 : combination.quantity) !== null && _ref27 !== void 0 ? _ref27 : 1, 1);
|
|
751
|
+
var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
|
|
752
|
+
var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
|
|
753
|
+
return option.total_price;
|
|
754
|
+
}));
|
|
755
|
+
var explicitBasePrice = resolveCombinationBasePrice(combination, true);
|
|
756
|
+
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
757
|
+
var extensionList = buildProductExtensionList({
|
|
758
|
+
product: combination,
|
|
759
|
+
locale: locale,
|
|
760
|
+
currencySymbol: currencySymbol,
|
|
761
|
+
quantity: quantity,
|
|
762
|
+
originalPrice: unitPrice
|
|
763
|
+
});
|
|
764
|
+
var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
|
|
765
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), {}, {
|
|
766
|
+
product_quantity: quantity,
|
|
767
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
|
|
768
|
+
}, shouldIncludeBasePrice ? {
|
|
769
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
770
|
+
} : {}), Array.isArray(combination.combinations_options) ? {
|
|
771
|
+
combinations_options: normalizedOptions
|
|
772
|
+
} : Array.isArray(combination.options) ? {
|
|
773
|
+
options: normalizedOptions
|
|
774
|
+
} : {}), normalizedOptions.length ? {
|
|
775
|
+
options_total_price: formatCalculatedMoney(optionsAmount, currencySymbol)
|
|
776
|
+
} : {}), nestedCombinations.length ? {
|
|
777
|
+
package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
|
|
778
|
+
} : {}), productNote ? {
|
|
548
779
|
product_note: productNote
|
|
549
|
-
} : {}),
|
|
780
|
+
} : {}), extensionList.length ? {
|
|
781
|
+
extension_list: extensionList
|
|
782
|
+
} : {}), nestedCombinations.length ? {
|
|
550
783
|
combinations: nestedCombinations
|
|
551
784
|
} : {});
|
|
552
785
|
});
|
|
553
786
|
}
|
|
787
|
+
function sumMoneyValues(values) {
|
|
788
|
+
return values.reduce(function (sum, value) {
|
|
789
|
+
return sum.plus(toMoneyNumber(value));
|
|
790
|
+
}, new Decimal(0));
|
|
791
|
+
}
|
|
792
|
+
function resolveCombinationBasePrice(combination) {
|
|
793
|
+
var _combination$metadata;
|
|
794
|
+
var preferOriginalPrice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
795
|
+
var fallbackPrices = preferOriginalPrice ? [combination.original_price, combination.product_price, combination.price] : [combination.price, combination.original_price, combination.product_price];
|
|
796
|
+
return firstPresentValue.apply(void 0, [combination.base_price, (_combination$metadata = combination.metadata) === null || _combination$metadata === void 0 ? void 0 : _combination$metadata.source_product_price].concat(fallbackPrices));
|
|
797
|
+
}
|
|
798
|
+
function sumNormalizedOptionTotals(options, currencySymbol) {
|
|
799
|
+
return formatCalculatedMoney(sumMoneyValues(options.map(function (option) {
|
|
800
|
+
return option.total_price;
|
|
801
|
+
})), currencySymbol);
|
|
802
|
+
}
|
|
803
|
+
function sumCombinationTotals(combinations, currencySymbol) {
|
|
804
|
+
return formatCalculatedMoney(sumMoneyValues(combinations.map(function (combination) {
|
|
805
|
+
return combination.total_selling_price;
|
|
806
|
+
})), currencySymbol);
|
|
807
|
+
}
|
|
554
808
|
function resolveProductNote(product, locale) {
|
|
555
809
|
var productNote = getLocalizedValue(product.product_note, locale).trim();
|
|
556
810
|
if (productNote) return productNote;
|
|
557
811
|
return getLocalizedValue(product.note, locale).trim();
|
|
558
812
|
}
|
|
559
813
|
function resolveBundleProductTitle(params) {
|
|
560
|
-
var
|
|
814
|
+
var _ref29, _ref30, _bundle$bundle_produc;
|
|
561
815
|
var bundle = params.bundle,
|
|
562
816
|
productMap = params.productMap,
|
|
563
817
|
locale = params.locale,
|
|
@@ -570,7 +824,7 @@ function resolveBundleProductTitle(params) {
|
|
|
570
824
|
});
|
|
571
825
|
var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
|
|
572
826
|
if (parentBundleTitle) return parentBundleTitle;
|
|
573
|
-
var productId = (
|
|
827
|
+
var productId = (_ref29 = (_ref30 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref30 !== void 0 ? _ref30 : bundle.product_id) !== null && _ref29 !== void 0 ? _ref29 : bundle.id;
|
|
574
828
|
var fallbackProduct = resolveProductFromMap(productId, productMap);
|
|
575
829
|
if (!fallbackProduct) return '';
|
|
576
830
|
return getProductTitleSource(fallbackProduct, locale);
|
|
@@ -622,10 +876,10 @@ function resolveVariantTextFromSkuKey(params) {
|
|
|
622
876
|
}
|
|
623
877
|
function resolveVariantTextFromNameMap(params) {
|
|
624
878
|
if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
|
|
625
|
-
return Object.entries(params.nameMap).map(function (
|
|
626
|
-
var
|
|
627
|
-
groupPositionId =
|
|
628
|
-
value =
|
|
879
|
+
return Object.entries(params.nameMap).map(function (_ref31) {
|
|
880
|
+
var _ref32 = _slicedToArray(_ref31, 2),
|
|
881
|
+
groupPositionId = _ref32[0],
|
|
882
|
+
value = _ref32[1];
|
|
629
883
|
var group = resolveVariantGroup(params.parentProduct, groupPositionId);
|
|
630
884
|
if (!group) return '';
|
|
631
885
|
var groupName = getLocalizedValue(group.name, params.locale);
|
|
@@ -659,12 +913,12 @@ function getProductTitleSource(source, locale) {
|
|
|
659
913
|
return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
|
|
660
914
|
}
|
|
661
915
|
function resolveTitleValue(value, locale) {
|
|
662
|
-
var
|
|
916
|
+
var _ref33, _ref34, _ref35, _ref36, _value$locale;
|
|
663
917
|
if (value === undefined || value === null) return '';
|
|
664
918
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
665
919
|
var dashedLocale = locale.replace('_', '-');
|
|
666
920
|
var underscoredLocale = locale.replace('-', '_');
|
|
667
|
-
return stringify((
|
|
921
|
+
return stringify((_ref33 = (_ref34 = (_ref35 = (_ref36 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref36 !== void 0 ? _ref36 : value[underscoredLocale]) !== null && _ref35 !== void 0 ? _ref35 : value.original) !== null && _ref34 !== void 0 ? _ref34 : value.auto) !== null && _ref33 !== void 0 ? _ref33 : '');
|
|
668
922
|
}
|
|
669
923
|
function resolveOptionTitleFromParentProduct(params) {
|
|
670
924
|
var option = params.option,
|
|
@@ -682,17 +936,17 @@ function flattenOptionItems(parentProduct) {
|
|
|
682
936
|
return optionGroups.flatMap(function (group) {
|
|
683
937
|
var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
|
|
684
938
|
return items.map(function (item) {
|
|
685
|
-
var
|
|
939
|
+
var _ref37, _item$option_group_id;
|
|
686
940
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
687
|
-
option_group_id: (
|
|
941
|
+
option_group_id: (_ref37 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref37 !== void 0 ? _ref37 : group.option_group_id
|
|
688
942
|
});
|
|
689
943
|
});
|
|
690
944
|
});
|
|
691
945
|
}
|
|
692
946
|
function isOptionItemMatch(option, item) {
|
|
693
|
-
var
|
|
694
|
-
var optionItemId = (
|
|
695
|
-
var itemId = (
|
|
947
|
+
var _ref38, _option$option_group_, _ref39, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
|
|
948
|
+
var optionItemId = (_ref38 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref38 !== void 0 ? _ref38 : option.id;
|
|
949
|
+
var itemId = (_ref39 = (_item$option_group_it = item.option_group_item_id) !== null && _item$option_group_it !== void 0 ? _item$option_group_it : item.product_option_item_id) !== null && _ref39 !== void 0 ? _ref39 : item.id;
|
|
696
950
|
if (!isSameId(optionItemId, itemId)) return false;
|
|
697
951
|
var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
|
|
698
952
|
var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
|
|
@@ -702,16 +956,16 @@ function isOptionItemMatch(option, item) {
|
|
|
702
956
|
return true;
|
|
703
957
|
}
|
|
704
958
|
function resolveBundleItemFromParentProduct(params) {
|
|
705
|
-
var
|
|
959
|
+
var _ref40, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref42, _bundle$bundle_produc2;
|
|
706
960
|
var bundle = params.bundle,
|
|
707
961
|
parentProduct = params.parentProduct;
|
|
708
962
|
if (!parentProduct) return null;
|
|
709
963
|
var bundleItems = flattenBundleItems(parentProduct);
|
|
710
|
-
var bundleVariantId = (
|
|
964
|
+
var bundleVariantId = (_ref40 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref40 !== void 0 ? _ref40 : bundle.product_variant_id;
|
|
711
965
|
if (isNonZeroId(bundleVariantId)) {
|
|
712
966
|
var matchedByVariant = bundleItems.find(function (item) {
|
|
713
|
-
var
|
|
714
|
-
return isSameId((
|
|
967
|
+
var _ref41, _item$bundle_variant_;
|
|
968
|
+
return isSameId((_ref41 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref41 !== void 0 ? _ref41 : item.product_variant_id, bundleVariantId);
|
|
715
969
|
});
|
|
716
970
|
if (matchedByVariant) return matchedByVariant;
|
|
717
971
|
}
|
|
@@ -724,18 +978,18 @@ function resolveBundleItemFromParentProduct(params) {
|
|
|
724
978
|
if (matchedByBundleId) return matchedByBundleId;
|
|
725
979
|
}
|
|
726
980
|
var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
|
|
727
|
-
var bundleProductId = (
|
|
981
|
+
var bundleProductId = (_ref42 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref42 !== void 0 ? _ref42 : bundle.product_id;
|
|
728
982
|
if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
|
|
729
983
|
var matchedByGroupAndProduct = bundleItems.find(function (item) {
|
|
730
|
-
var _item$group_id,
|
|
731
|
-
return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((
|
|
984
|
+
var _item$group_id, _ref43, _item$bundle_product_;
|
|
985
|
+
return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref43 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref43 !== void 0 ? _ref43 : item.product_id, bundleProductId);
|
|
732
986
|
});
|
|
733
987
|
if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
|
|
734
988
|
}
|
|
735
989
|
if (isPresentId(bundleProductId)) {
|
|
736
990
|
return bundleItems.find(function (item) {
|
|
737
|
-
var
|
|
738
|
-
return isSameId((
|
|
991
|
+
var _ref44, _item$bundle_product_2;
|
|
992
|
+
return isSameId((_ref44 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref44 !== void 0 ? _ref44 : item.product_id, bundleProductId);
|
|
739
993
|
}) || null;
|
|
740
994
|
}
|
|
741
995
|
return null;
|
|
@@ -745,9 +999,9 @@ function flattenBundleItems(parentProduct) {
|
|
|
745
999
|
return bundleGroups.flatMap(function (group) {
|
|
746
1000
|
var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
|
|
747
1001
|
return items.map(function (item) {
|
|
748
|
-
var
|
|
1002
|
+
var _ref45, _item$group_id2;
|
|
749
1003
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
750
|
-
group_id: (
|
|
1004
|
+
group_id: (_ref45 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref45 !== void 0 ? _ref45 : group.group_id
|
|
751
1005
|
});
|
|
752
1006
|
});
|
|
753
1007
|
});
|
|
@@ -771,8 +1025,8 @@ function isSameId(left, right) {
|
|
|
771
1025
|
return String(left) === String(right);
|
|
772
1026
|
}
|
|
773
1027
|
function formatBundlePrice(bundle, currencySymbol) {
|
|
774
|
-
var
|
|
775
|
-
var value = (
|
|
1028
|
+
var _ref46, _ref47, _bundle$bundle_sellin;
|
|
1029
|
+
var value = (_ref46 = (_ref47 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref47 !== void 0 ? _ref47 : bundle.price) !== null && _ref46 !== void 0 ? _ref46 : 0;
|
|
776
1030
|
var amount = new Decimal(toMoneyNumber(value));
|
|
777
1031
|
// 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
|
|
778
1032
|
var isNegative = bundle.price_type === 'markdown';
|
|
@@ -780,7 +1034,7 @@ function formatBundlePrice(bundle, currencySymbol) {
|
|
|
780
1034
|
return formatMoney(amount, currencySymbol);
|
|
781
1035
|
}
|
|
782
1036
|
function buildFees(params) {
|
|
783
|
-
var
|
|
1037
|
+
var _firstPresentValue2, _firstPresentValue3;
|
|
784
1038
|
var order = params.order,
|
|
785
1039
|
shopInfo = params.shopInfo,
|
|
786
1040
|
locale = params.locale,
|
|
@@ -790,9 +1044,9 @@ function buildFees(params) {
|
|
|
790
1044
|
financials = params.financials;
|
|
791
1045
|
var fees = [];
|
|
792
1046
|
for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
|
|
793
|
-
var
|
|
1047
|
+
var _ref48, _surcharge$amount;
|
|
794
1048
|
var surcharge = _normalizeArray[_i];
|
|
795
|
-
var value = (
|
|
1049
|
+
var value = (_ref48 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref48 !== void 0 ? _ref48 : surcharge.total_amount;
|
|
796
1050
|
if (!isNonZero(value)) continue;
|
|
797
1051
|
fees.push({
|
|
798
1052
|
item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
|
|
@@ -815,12 +1069,6 @@ function buildFees(params) {
|
|
|
815
1069
|
});
|
|
816
1070
|
var isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
|
|
817
1071
|
var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
|
|
818
|
-
if (isNonZero(roundingAmount)) {
|
|
819
|
-
fees.push({
|
|
820
|
-
item: label(locale, 'rounding'),
|
|
821
|
-
value: formatMoney(roundingAmount, currencySymbol)
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
1072
|
var payProcessingFee = financials.payProcessingFee;
|
|
825
1073
|
if (isNonZero(payProcessingFee)) {
|
|
826
1074
|
fees.push({
|
|
@@ -829,14 +1077,16 @@ function buildFees(params) {
|
|
|
829
1077
|
});
|
|
830
1078
|
}
|
|
831
1079
|
var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
|
|
832
|
-
var productOriginalAmount = (
|
|
1080
|
+
var productOriginalAmount = (_firstPresentValue2 = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : calculateProductOriginalAmount(order);
|
|
833
1081
|
var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
|
|
1082
|
+
var itemDiscountAmount = new Decimal(toMoneyNumber(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0)).minus(toMoneyNumber(productOriginalAmount));
|
|
834
1083
|
return {
|
|
835
1084
|
fees: fees,
|
|
836
1085
|
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
837
|
-
total_amount: formatMoney((
|
|
1086
|
+
total_amount: formatMoney((_firstPresentValue3 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0, currencySymbol),
|
|
838
1087
|
original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
|
|
839
1088
|
product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
|
|
1089
|
+
item_discount_amount: formatCalculatedMoney(itemDiscountAmount, currencySymbol),
|
|
840
1090
|
expect_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
841
1091
|
product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
|
|
842
1092
|
return sum + product.product_quantity;
|
|
@@ -861,15 +1111,15 @@ function buildFees(params) {
|
|
|
861
1111
|
};
|
|
862
1112
|
}
|
|
863
1113
|
function resolveReceiptFinancials(order, summary) {
|
|
864
|
-
var
|
|
865
|
-
var totalAmount = (
|
|
1114
|
+
var _firstPresentValue4, _firstPresentValue5, _firstPresentValue6, _firstPresentValue7;
|
|
1115
|
+
var totalAmount = (_firstPresentValue4 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
|
|
866
1116
|
var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
|
|
867
1117
|
var payProcessingFee = rawPayProcessingFee !== null && rawPayProcessingFee !== void 0 ? rawPayProcessingFee : 0;
|
|
868
|
-
var orderPaidAmount = (
|
|
869
|
-
var totalRefundAmount = (
|
|
1118
|
+
var orderPaidAmount = (_firstPresentValue5 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
|
|
1119
|
+
var totalRefundAmount = (_firstPresentValue6 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
|
|
870
1120
|
var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
|
|
871
1121
|
var fallbackCustomerPaidAmount = Decimal.max(sumCustomerPaidPayments(order.payments), new Decimal(toMoneyNumber(orderPaidAmount)).plus(toMoneyNumber(payProcessingFee)));
|
|
872
|
-
var customerPaidAmount = (
|
|
1122
|
+
var customerPaidAmount = (_firstPresentValue7 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
|
|
873
1123
|
var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
|
|
874
1124
|
return {
|
|
875
1125
|
totalAmount: totalAmount,
|
|
@@ -898,9 +1148,9 @@ function resolveTaxTitle(params) {
|
|
|
898
1148
|
}
|
|
899
1149
|
function calculateProductOriginalAmount(order) {
|
|
900
1150
|
return normalizeArray(order.products).reduce(function (total, product) {
|
|
901
|
-
var
|
|
902
|
-
var quantity = toNumber((
|
|
903
|
-
var originalPrice = (
|
|
1151
|
+
var _ref49, _ref50, _product$product_quan2, _ref51, _ref52, _ref53, _product$original_pri2;
|
|
1152
|
+
var quantity = toNumber((_ref49 = (_ref50 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref50 !== void 0 ? _ref50 : product.num) !== null && _ref49 !== void 0 ? _ref49 : 1, 1);
|
|
1153
|
+
var originalPrice = (_ref51 = (_ref52 = (_ref53 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref53 !== void 0 ? _ref53 : product.payment_price) !== null && _ref52 !== void 0 ? _ref52 : product.price) !== null && _ref51 !== void 0 ? _ref51 : 0;
|
|
904
1154
|
return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
|
|
905
1155
|
}, new Decimal(0));
|
|
906
1156
|
}
|
|
@@ -948,18 +1198,14 @@ function buildAppointment(order, locale) {
|
|
|
948
1198
|
var _order$metadata13, _order$metadata14, _order$form_data;
|
|
949
1199
|
var bookings = sortBookings(normalizeArray(order.bookings));
|
|
950
1200
|
if (bookings.length) {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
product_uid: productUid
|
|
960
|
-
} : {}), isPresentId(bookingUid) ? {
|
|
961
|
-
booking_uid: bookingUid
|
|
962
|
-
} : {});
|
|
1201
|
+
var allResources = normalizeArray(order.resources || order.resource_list);
|
|
1202
|
+
return bookings.flatMap(function (booking) {
|
|
1203
|
+
return buildAppointmentRows({
|
|
1204
|
+
booking: booking,
|
|
1205
|
+
allResources: allResources,
|
|
1206
|
+
bookingCount: bookings.length,
|
|
1207
|
+
locale: locale
|
|
1208
|
+
});
|
|
963
1209
|
});
|
|
964
1210
|
}
|
|
965
1211
|
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);
|
|
@@ -969,6 +1215,104 @@ function buildAppointment(order, locale) {
|
|
|
969
1215
|
value: getLocalizedValue(tableName, locale)
|
|
970
1216
|
}];
|
|
971
1217
|
}
|
|
1218
|
+
function buildAppointmentRows(params) {
|
|
1219
|
+
var _booking$metadata, _booking$metadata2, _booking$holder$name, _booking$holder, _booking$metadata3;
|
|
1220
|
+
var booking = params.booking,
|
|
1221
|
+
allResources = params.allResources,
|
|
1222
|
+
bookingCount = params.bookingCount,
|
|
1223
|
+
locale = params.locale;
|
|
1224
|
+
var productUid = stringify(firstPresentValue(booking.product_uid, (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid)).trim();
|
|
1225
|
+
var bookingUid = stringify(firstPresentValue((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number, booking.booking_uid)).trim();
|
|
1226
|
+
var association = {
|
|
1227
|
+
product_uid: productUid,
|
|
1228
|
+
booking_uid: bookingUid
|
|
1229
|
+
};
|
|
1230
|
+
var bookingId = stringify(firstPresentValue(booking.booking_id, booking.schedule_event_id, bookingUid)).trim();
|
|
1231
|
+
var bookingTime = formatBookingRange(booking, locale);
|
|
1232
|
+
var resourceText = formatBookingResources(resolveBookingResourcesForReceipt(booking, allResources, bookingCount), locale);
|
|
1233
|
+
var holder = getLocalizedValue((_booking$holder$name = (_booking$holder = booking.holder) === null || _booking$holder === void 0 ? void 0 : _booking$holder.name) !== null && _booking$holder$name !== void 0 ? _booking$holder$name : (_booking$metadata3 = booking.metadata) === null || _booking$metadata3 === void 0 || (_booking$metadata3 = _booking$metadata3.holder) === null || _booking$metadata3 === void 0 ? void 0 : _booking$metadata3.name, locale).trim();
|
|
1234
|
+
return [_objectSpread({
|
|
1235
|
+
item: label(locale, 'bookingId'),
|
|
1236
|
+
value: bookingId
|
|
1237
|
+
}, association), _objectSpread({
|
|
1238
|
+
item: label(locale, 'bookingDateTime'),
|
|
1239
|
+
value: bookingTime
|
|
1240
|
+
}, association), _objectSpread({
|
|
1241
|
+
item: label(locale, 'bookingResource'),
|
|
1242
|
+
value: resourceText
|
|
1243
|
+
}, association), _objectSpread({
|
|
1244
|
+
item: label(locale, 'bookingHolder'),
|
|
1245
|
+
value: holder
|
|
1246
|
+
}, association)].filter(function (row) {
|
|
1247
|
+
return Boolean(row.value);
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
function formatBookingRange(booking, locale) {
|
|
1251
|
+
var startDate = stringify(booking.start_date);
|
|
1252
|
+
var startTime = stringify(booking.start_time);
|
|
1253
|
+
var endDate = stringify(booking.end_date || startDate);
|
|
1254
|
+
var endTime = stringify(booking.end_time);
|
|
1255
|
+
var start = firstValidBookingDate(booking.start_at, booking.start_datetime, booking.start_date_time, "".concat(startDate, " ").concat(startTime).trim());
|
|
1256
|
+
var end = firstValidBookingDate(booking.end_at, booking.end_datetime, booking.end_date_time, endTime ? "".concat(endDate, " ").concat(endTime).trim() : '');
|
|
1257
|
+
if (!start) {
|
|
1258
|
+
return [startDate, startTime, endTime ? "- ".concat(endDate, " ").concat(endTime) : ''].filter(Boolean).join(' ');
|
|
1259
|
+
}
|
|
1260
|
+
var dateFormat = locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD';
|
|
1261
|
+
var startText = start.format("".concat(dateFormat, " HH:mm"));
|
|
1262
|
+
if (!end) return startText;
|
|
1263
|
+
return "".concat(startText, " - ").concat(end.isSame(start, 'day') ? end.format('HH:mm') : end.format("".concat(dateFormat, " HH:mm")));
|
|
1264
|
+
}
|
|
1265
|
+
function firstValidBookingDate() {
|
|
1266
|
+
for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1267
|
+
values[_key2] = arguments[_key2];
|
|
1268
|
+
}
|
|
1269
|
+
for (var _i2 = 0, _values = values; _i2 < _values.length; _i2++) {
|
|
1270
|
+
var value = _values[_i2];
|
|
1271
|
+
if (!isPresentId(value)) continue;
|
|
1272
|
+
var parsed = dayjs(value);
|
|
1273
|
+
if (parsed.isValid()) return parsed;
|
|
1274
|
+
}
|
|
1275
|
+
return null;
|
|
1276
|
+
}
|
|
1277
|
+
function resolveBookingResourcesForReceipt(booking, allResources, bookingCount) {
|
|
1278
|
+
var _booking$metadata4;
|
|
1279
|
+
var embedded = normalizeArray(booking.resources).filter(function (resource) {
|
|
1280
|
+
return Boolean(resource) && _typeof(resource) === 'object' && !Array.isArray(resource);
|
|
1281
|
+
});
|
|
1282
|
+
var resourceIds = new Set([booking.resource_id, booking.relation_id].concat(_toConsumableArray(normalizeArray(booking.resource_ids)), _toConsumableArray(normalizeArray((_booking$metadata4 = booking.metadata) === null || _booking$metadata4 === void 0 ? void 0 : _booking$metadata4.resource_ids))).map(function (value) {
|
|
1283
|
+
return stringify(value).trim();
|
|
1284
|
+
}).filter(Boolean));
|
|
1285
|
+
var _iterator3 = _createForOfIteratorHelper(embedded),
|
|
1286
|
+
_step3;
|
|
1287
|
+
try {
|
|
1288
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1289
|
+
var _ref55, _resource$id2;
|
|
1290
|
+
var resource = _step3.value;
|
|
1291
|
+
var id = stringify((_ref55 = (_resource$id2 = resource.id) !== null && _resource$id2 !== void 0 ? _resource$id2 : resource.resource_id) !== null && _ref55 !== void 0 ? _ref55 : resource.relation_id).trim();
|
|
1292
|
+
if (id) resourceIds.add(id);
|
|
1293
|
+
}
|
|
1294
|
+
} catch (err) {
|
|
1295
|
+
_iterator3.e(err);
|
|
1296
|
+
} finally {
|
|
1297
|
+
_iterator3.f();
|
|
1298
|
+
}
|
|
1299
|
+
if (resourceIds.size) {
|
|
1300
|
+
var matched = allResources.filter(function (resource) {
|
|
1301
|
+
var _ref54, _resource$id;
|
|
1302
|
+
return resourceIds.has(stringify((_ref54 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.resource_id) !== null && _ref54 !== void 0 ? _ref54 : resource.relation_id).trim());
|
|
1303
|
+
});
|
|
1304
|
+
if (matched.length) return matched;
|
|
1305
|
+
}
|
|
1306
|
+
if (embedded.length) return embedded;
|
|
1307
|
+
if (bookingCount === 1 && allResources.length) return allResources;
|
|
1308
|
+
return [];
|
|
1309
|
+
}
|
|
1310
|
+
function formatBookingResources(resources, locale) {
|
|
1311
|
+
return resources.map(function (resource) {
|
|
1312
|
+
var _resource$metadata, _resource$metadata2, _resource$metadata3, _resource$metadata4;
|
|
1313
|
+
return [getLocalizedValue(resource.form_title || ((_resource$metadata = resource.metadata) === null || _resource$metadata === void 0 ? void 0 : _resource$metadata.form_name) || resource.relation_form_name || ((_resource$metadata2 = resource.metadata) === null || _resource$metadata2 === void 0 ? void 0 : _resource$metadata2.relation_form_name), locale), getLocalizedValue(resource.title || resource.name || resource.main_field || ((_resource$metadata3 = resource.metadata) === null || _resource$metadata3 === void 0 ? void 0 : _resource$metadata3.main_field) || ((_resource$metadata4 = resource.metadata) === null || _resource$metadata4 === void 0 ? void 0 : _resource$metadata4.resource_name), locale)].filter(Boolean).join(' ');
|
|
1314
|
+
}).filter(Boolean).join(', ');
|
|
1315
|
+
}
|
|
972
1316
|
function sortBookings(bookings) {
|
|
973
1317
|
return bookings.map(function (booking, index) {
|
|
974
1318
|
return {
|
|
@@ -980,23 +1324,23 @@ function sortBookings(bookings) {
|
|
|
980
1324
|
var leftStart = bookingStartTimestamp(left.booking);
|
|
981
1325
|
var rightStart = bookingStartTimestamp(right.booking);
|
|
982
1326
|
if (leftStart !== rightStart) return leftStart < rightStart ? -1 : 1;
|
|
983
|
-
for (var
|
|
1327
|
+
for (var _i3 = 0, _arr = ['booking_id', 'schedule_event_id']; _i3 < _arr.length; _i3++) {
|
|
984
1328
|
var _left$booking, _right$booking;
|
|
985
|
-
var field = _arr[
|
|
1329
|
+
var field = _arr[_i3];
|
|
986
1330
|
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
1331
|
if (fieldOrder !== 0) return fieldOrder;
|
|
988
1332
|
}
|
|
989
1333
|
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
1334
|
return bookingUidOrder || left.index - right.index;
|
|
991
|
-
}).map(function (
|
|
992
|
-
var booking =
|
|
1335
|
+
}).map(function (_ref56) {
|
|
1336
|
+
var booking = _ref56.booking;
|
|
993
1337
|
return booking;
|
|
994
1338
|
});
|
|
995
1339
|
}
|
|
996
1340
|
function bookingStartTimestamp(booking) {
|
|
997
1341
|
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
|
|
999
|
-
var startValue = _startValues[
|
|
1342
|
+
for (var _i4 = 0, _startValues = startValues; _i4 < _startValues.length; _i4++) {
|
|
1343
|
+
var startValue = _startValues[_i4];
|
|
1000
1344
|
if (!isPresentId(startValue)) continue;
|
|
1001
1345
|
var timestamp = dayjs(startValue).valueOf();
|
|
1002
1346
|
if (Number.isFinite(timestamp)) return timestamp;
|
|
@@ -1032,7 +1376,9 @@ function buildPaymentData(params) {
|
|
|
1032
1376
|
payment: payment,
|
|
1033
1377
|
locale: params.locale,
|
|
1034
1378
|
currencySymbol: params.currencySymbol,
|
|
1035
|
-
includeFundRecordBalance: false
|
|
1379
|
+
includeFundRecordBalance: false,
|
|
1380
|
+
includeFundRecordUsage: true,
|
|
1381
|
+
includePaymentAmount: true
|
|
1036
1382
|
});
|
|
1037
1383
|
});
|
|
1038
1384
|
}
|
|
@@ -1049,8 +1395,8 @@ function buildRefundData(params) {
|
|
|
1049
1395
|
result.set(identity, candidate);
|
|
1050
1396
|
}
|
|
1051
1397
|
return result;
|
|
1052
|
-
}, new Map()).values()).filter(function (
|
|
1053
|
-
var refund =
|
|
1398
|
+
}, new Map()).values()).filter(function (_ref57) {
|
|
1399
|
+
var refund = _ref57.refund;
|
|
1054
1400
|
return isPrintableRefund(refund);
|
|
1055
1401
|
}).sort(function (left, right) {
|
|
1056
1402
|
var leftTime = refundTimestamp(left.refund);
|
|
@@ -1058,12 +1404,12 @@ function buildRefundData(params) {
|
|
|
1058
1404
|
if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
|
|
1059
1405
|
return left.index - right.index;
|
|
1060
1406
|
});
|
|
1061
|
-
return refunds.map(function (
|
|
1062
|
-
var
|
|
1063
|
-
var refund =
|
|
1407
|
+
return refunds.map(function (_ref58) {
|
|
1408
|
+
var _firstPresentValue8;
|
|
1409
|
+
var refund = _ref58.refund;
|
|
1064
1410
|
var payment = resolveRefundPayment(refund, payments);
|
|
1065
1411
|
var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
|
|
1066
|
-
var amount = (
|
|
1412
|
+
var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
|
|
1067
1413
|
var items = [{
|
|
1068
1414
|
item: methodName,
|
|
1069
1415
|
value: formatNegativeMoney(amount, params.currencySymbol)
|
|
@@ -1120,32 +1466,112 @@ function resolveRefundPayment(refund, payments) {
|
|
|
1120
1466
|
return matchedPayment || refund;
|
|
1121
1467
|
}
|
|
1122
1468
|
function buildWallets(params) {
|
|
1123
|
-
var
|
|
1469
|
+
var displayedWalletPayments = normalizeArray(params.order.payments).filter(function (payment) {
|
|
1124
1470
|
return isPrintablePayment(payment) && !!getFundRecord(payment);
|
|
1125
|
-
})
|
|
1471
|
+
});
|
|
1472
|
+
var paymentWallets = displayedWalletPayments.map(function (payment) {
|
|
1126
1473
|
return buildPaymentItems({
|
|
1127
1474
|
payment: payment,
|
|
1128
1475
|
locale: params.locale,
|
|
1129
1476
|
currencySymbol: params.currencySymbol,
|
|
1130
|
-
includeFundRecordBalance: true
|
|
1477
|
+
includeFundRecordBalance: true,
|
|
1478
|
+
includeFundRecordUsage: false,
|
|
1479
|
+
includePaymentAmount: false
|
|
1131
1480
|
});
|
|
1132
1481
|
});
|
|
1133
|
-
|
|
1482
|
+
var displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
|
|
1483
|
+
return [].concat(_toConsumableArray(paymentWallets), _toConsumableArray(buildVoucherAssets(params)), _toConsumableArray(buildPointCardSnapshotAssets({
|
|
1484
|
+
order: params.order,
|
|
1485
|
+
locale: params.locale,
|
|
1486
|
+
displayedWalletPassIds: displayedWalletPassIds
|
|
1487
|
+
})));
|
|
1488
|
+
}
|
|
1489
|
+
function collectDisplayedWalletPassIds(payments) {
|
|
1490
|
+
var ids = new Set();
|
|
1491
|
+
payments.forEach(function (payment) {
|
|
1492
|
+
var fundRecord = getFundRecord(payment);
|
|
1493
|
+
[payment.voucher_id, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id].forEach(function (value) {
|
|
1494
|
+
var id = normalizeWalletPassId(value);
|
|
1495
|
+
if (id) ids.add(id);
|
|
1496
|
+
});
|
|
1497
|
+
});
|
|
1498
|
+
return ids;
|
|
1499
|
+
}
|
|
1500
|
+
function buildPointCardSnapshotAssets(params) {
|
|
1501
|
+
var _params$order$order_m;
|
|
1502
|
+
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;
|
|
1503
|
+
if (!Array.isArray(snapshots)) return [];
|
|
1504
|
+
var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1505
|
+
var seenSnapshotIds = new Set();
|
|
1506
|
+
return snapshots.flatMap(function (snapshot) {
|
|
1507
|
+
if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return [];
|
|
1508
|
+
var pointCard = snapshot;
|
|
1509
|
+
if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
|
|
1510
|
+
var id = normalizeWalletPassId(pointCard.id);
|
|
1511
|
+
if (!id || seenSnapshotIds.has(id)) return [];
|
|
1512
|
+
seenSnapshotIds.add(id);
|
|
1513
|
+
if (params.displayedWalletPassIds.has(id)) return [];
|
|
1514
|
+
var rows = [{
|
|
1515
|
+
item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
|
|
1516
|
+
value: ''
|
|
1517
|
+
}];
|
|
1518
|
+
var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
|
|
1519
|
+
if (remainingPoints) {
|
|
1520
|
+
rows.push({
|
|
1521
|
+
item: label(params.locale, 'remainingPoints'),
|
|
1522
|
+
value: trimDecimal(remainingPoints)
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
if (isPresentId(snapshotTime)) {
|
|
1526
|
+
rows.push({
|
|
1527
|
+
item: formatDateTime(snapshotTime, params.locale),
|
|
1528
|
+
value: ''
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
return [rows];
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
function normalizeWalletPassId(value) {
|
|
1535
|
+
if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
|
|
1536
|
+
if (typeof value !== 'string') return null;
|
|
1537
|
+
return value.trim() || null;
|
|
1538
|
+
}
|
|
1539
|
+
function getPointCardSnapshotRemainingPoints(snapshot) {
|
|
1540
|
+
if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
|
|
1541
|
+
return null;
|
|
1542
|
+
}
|
|
1543
|
+
return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
|
|
1134
1544
|
}
|
|
1135
1545
|
function buildVoucherAssets(params) {
|
|
1136
1546
|
var seenVoucherKeys = new Set();
|
|
1547
|
+
var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1137
1548
|
return normalizeArray(params.order.vouchers).flatMap(function (voucher, index) {
|
|
1138
1549
|
if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
|
|
1139
1550
|
var voucherKey = getVoucherAssetKey(voucher, index);
|
|
1140
1551
|
if (seenVoucherKeys.has(voucherKey)) return [];
|
|
1141
1552
|
seenVoucherKeys.add(voucherKey);
|
|
1142
1553
|
var name = getVoucherAssetName(voucher, params.locale);
|
|
1554
|
+
var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
|
|
1555
|
+
var timeRow = isPresentId(assetTime) ? {
|
|
1556
|
+
item: formatDateTime(assetTime, params.locale),
|
|
1557
|
+
value: ''
|
|
1558
|
+
} : null;
|
|
1559
|
+
if (isTicketVoucher(voucher)) {
|
|
1560
|
+
var validity = getVoucherValidity(voucher, params.locale);
|
|
1561
|
+
return [[{
|
|
1562
|
+
item: name,
|
|
1563
|
+
value: ''
|
|
1564
|
+
}].concat(_toConsumableArray(validity ? [{
|
|
1565
|
+
item: label(params.locale, 'validity'),
|
|
1566
|
+
value: validity
|
|
1567
|
+
}] : []))];
|
|
1568
|
+
}
|
|
1143
1569
|
var percent = getVoucherDiscountPercent(voucher);
|
|
1144
1570
|
if (percent) {
|
|
1145
1571
|
return [[{
|
|
1146
1572
|
item: appendPercentToVoucherName(name, percent),
|
|
1147
1573
|
value: formatVoucherDiscount(percent, params.locale)
|
|
1148
|
-
}]];
|
|
1574
|
+
}].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1149
1575
|
}
|
|
1150
1576
|
var balance = getVoucherBalance(voucher);
|
|
1151
1577
|
return [[{
|
|
@@ -1154,9 +1580,87 @@ function buildVoucherAssets(params) {
|
|
|
1154
1580
|
}, {
|
|
1155
1581
|
item: label(params.locale, 'balance'),
|
|
1156
1582
|
value: formatMoney(balance, params.currencySymbol)
|
|
1157
|
-
}]];
|
|
1583
|
+
}].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
function isTicketVoucher(voucher) {
|
|
1587
|
+
return stringify(voucher.tag).trim().toLowerCase() === 'ticket';
|
|
1588
|
+
}
|
|
1589
|
+
function getVoucherValidity(voucher, locale) {
|
|
1590
|
+
var _voucher$metadata, _voucher$metadata2, _voucher$metadata3, _voucher$metadata4, _voucher$metadata5, _voucher$metadata6, _voucher$metadata7, _voucher$metadata8, _voucher$metadata9, _voucher$metadata10, _voucher$start_time, _voucher$metadata11, _voucher$end_time, _voucher$metadata12;
|
|
1591
|
+
var availableTime = firstPresentValue(voucher.available_time, voucher.avaliable_time, (_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.available_time, (_voucher$metadata2 = voucher.metadata) === null || _voucher$metadata2 === void 0 ? void 0 : _voucher$metadata2.avaliable_time);
|
|
1592
|
+
var availableTimeText = formatVoucherAvailableTime(availableTime, locale);
|
|
1593
|
+
if (availableTimeText) return availableTimeText;
|
|
1594
|
+
var startDate = firstPresentValue(voucher.valid_from, voucher.start_at, voucher.start_date_time, voucher.start_date, (_voucher$metadata3 = voucher.metadata) === null || _voucher$metadata3 === void 0 ? void 0 : _voucher$metadata3.valid_from, (_voucher$metadata4 = voucher.metadata) === null || _voucher$metadata4 === void 0 ? void 0 : _voucher$metadata4.start_at, (_voucher$metadata5 = voucher.metadata) === null || _voucher$metadata5 === void 0 ? void 0 : _voucher$metadata5.start_date);
|
|
1595
|
+
var endDate = firstPresentValue(voucher.valid_to, voucher.end_at, voucher.end_date_time, voucher.expire_date, voucher.end_date, voucher.expire_time, (_voucher$metadata6 = voucher.metadata) === null || _voucher$metadata6 === void 0 ? void 0 : _voucher$metadata6.valid_to, (_voucher$metadata7 = voucher.metadata) === null || _voucher$metadata7 === void 0 ? void 0 : _voucher$metadata7.end_at, (_voucher$metadata8 = voucher.metadata) === null || _voucher$metadata8 === void 0 ? void 0 : _voucher$metadata8.expire_date, (_voucher$metadata9 = voucher.metadata) === null || _voucher$metadata9 === void 0 ? void 0 : _voucher$metadata9.end_date, (_voucher$metadata10 = voucher.metadata) === null || _voucher$metadata10 === void 0 ? void 0 : _voucher$metadata10.expire_time);
|
|
1596
|
+
return formatVoucherValidityRange(startDate, endDate, locale, {
|
|
1597
|
+
startTime: (_voucher$start_time = voucher.start_time) !== null && _voucher$start_time !== void 0 ? _voucher$start_time : (_voucher$metadata11 = voucher.metadata) === null || _voucher$metadata11 === void 0 ? void 0 : _voucher$metadata11.start_time,
|
|
1598
|
+
endTime: (_voucher$end_time = voucher.end_time) !== null && _voucher$end_time !== void 0 ? _voucher$end_time : (_voucher$metadata12 = voucher.metadata) === null || _voucher$metadata12 === void 0 ? void 0 : _voucher$metadata12.end_time
|
|
1158
1599
|
});
|
|
1159
1600
|
}
|
|
1601
|
+
function formatVoucherAvailableTime(value, locale) {
|
|
1602
|
+
if (!isPresentId(value)) return '';
|
|
1603
|
+
if (Array.isArray(value)) {
|
|
1604
|
+
return value.map(function (item) {
|
|
1605
|
+
return formatVoucherAvailableTime(item, locale);
|
|
1606
|
+
}).filter(Boolean).join(', ');
|
|
1607
|
+
}
|
|
1608
|
+
if (_typeof(value) !== 'object') return stringify(value).trim();
|
|
1609
|
+
var start = firstPresentValue(value.start, value.start_at, value.start_date_time, value.start_date);
|
|
1610
|
+
var end = firstPresentValue(value.end, value.end_at, value.end_date_time, value.expire_time, value.expire_date, value.end_date);
|
|
1611
|
+
if (isPresentId(start) || isPresentId(end)) {
|
|
1612
|
+
return formatVoucherValidityRange(start, end, locale, {
|
|
1613
|
+
startTime: value.start_time,
|
|
1614
|
+
endTime: value.end_time
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
return getLocalizedValue(value, locale).trim();
|
|
1618
|
+
}
|
|
1619
|
+
function formatVoucherValidityRange(startValue, endValue, locale) {
|
|
1620
|
+
var times = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1621
|
+
var start = combineVoucherDateAndTime(startValue, times.startTime);
|
|
1622
|
+
var end = combineVoucherDateAndTime(endValue, times.endTime);
|
|
1623
|
+
var startPart = formatVoucherValidityDate(start, locale);
|
|
1624
|
+
var endPart = formatVoucherValidityDate(end, locale);
|
|
1625
|
+
if (startPart.text && endPart.text) {
|
|
1626
|
+
var parsedStart = dayjs(start);
|
|
1627
|
+
var parsedEnd = dayjs(end);
|
|
1628
|
+
var sameDay = parsedStart.isValid() && parsedEnd.isValid() && parsedStart.isSame(parsedEnd, 'day');
|
|
1629
|
+
if (sameDay && startPart.time && endPart.time) {
|
|
1630
|
+
return "".concat(startPart.time, " - ").concat(endPart.time, " ").concat(startPart.date);
|
|
1631
|
+
}
|
|
1632
|
+
return "".concat(startPart.text, " - ").concat(endPart.text);
|
|
1633
|
+
}
|
|
1634
|
+
return startPart.text || endPart.text;
|
|
1635
|
+
}
|
|
1636
|
+
function combineVoucherDateAndTime(dateValue, timeValue) {
|
|
1637
|
+
if (!isPresentId(dateValue) || !isPresentId(timeValue)) return dateValue;
|
|
1638
|
+
var dateText = stringify(dateValue).trim();
|
|
1639
|
+
if (/\d{1,2}:\d{2}/.test(dateText)) return dateValue;
|
|
1640
|
+
return "".concat(dateText, " ").concat(stringify(timeValue).trim());
|
|
1641
|
+
}
|
|
1642
|
+
function formatVoucherValidityDate(value, locale) {
|
|
1643
|
+
if (!isPresentId(value)) return {
|
|
1644
|
+
date: '',
|
|
1645
|
+
time: '',
|
|
1646
|
+
text: ''
|
|
1647
|
+
};
|
|
1648
|
+
var source = stringify(value).trim();
|
|
1649
|
+
var parsed = dayjs(source);
|
|
1650
|
+
if (!parsed.isValid()) return {
|
|
1651
|
+
date: '',
|
|
1652
|
+
time: '',
|
|
1653
|
+
text: source
|
|
1654
|
+
};
|
|
1655
|
+
var hasTime = /\d{1,2}:\d{2}/.test(source);
|
|
1656
|
+
var date = parsed.format(locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD');
|
|
1657
|
+
var time = hasTime ? parsed.format(/\d{1,2}:\d{2}:\d{2}/.test(source) ? 'HH:mm:ss' : 'HH:mm') : '';
|
|
1658
|
+
return {
|
|
1659
|
+
date: date,
|
|
1660
|
+
time: time,
|
|
1661
|
+
text: time ? "".concat(time, " ").concat(date) : date
|
|
1662
|
+
};
|
|
1663
|
+
}
|
|
1160
1664
|
function getVoucherAssetKey(voucher, index) {
|
|
1161
1665
|
var identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
|
|
1162
1666
|
return identity === undefined ? "voucher-index:".concat(index) : "voucher:".concat(String(identity));
|
|
@@ -1165,8 +1669,8 @@ function getVoucherAssetName(voucher, locale) {
|
|
|
1165
1669
|
return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
|
|
1166
1670
|
}
|
|
1167
1671
|
function getVoucherDiscountPercent(voucher) {
|
|
1168
|
-
var _voucher$
|
|
1169
|
-
var discountType = stringify(((_voucher$
|
|
1672
|
+
var _voucher$metadata13;
|
|
1673
|
+
var discountType = stringify(((_voucher$metadata13 = voucher.metadata) === null || _voucher$metadata13 === void 0 ? void 0 : _voucher$metadata13.discount_card_type) || voucher.discount_card_type).toLowerCase();
|
|
1170
1674
|
if (discountType !== 'percent' && discountType !== 'percentage') return null;
|
|
1171
1675
|
var percent = new Decimal(toMoneyNumber(voucher.par_value));
|
|
1172
1676
|
if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
|
|
@@ -1194,11 +1698,13 @@ function buildPaymentItems(params) {
|
|
|
1194
1698
|
var payment = params.payment,
|
|
1195
1699
|
locale = params.locale,
|
|
1196
1700
|
currencySymbol = params.currencySymbol,
|
|
1197
|
-
includeFundRecordBalance = params.includeFundRecordBalance
|
|
1701
|
+
includeFundRecordBalance = params.includeFundRecordBalance,
|
|
1702
|
+
includeFundRecordUsage = params.includeFundRecordUsage,
|
|
1703
|
+
includePaymentAmount = params.includePaymentAmount;
|
|
1198
1704
|
var serviceFee = getPaymentServiceFee(payment);
|
|
1199
1705
|
var items = [{
|
|
1200
1706
|
item: paymentMethodName(payment, locale),
|
|
1201
|
-
value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
|
|
1707
|
+
value: includePaymentAmount ? formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol) : ''
|
|
1202
1708
|
}];
|
|
1203
1709
|
items.push.apply(items, _toConsumableArray(buildCashChangePaymentItems({
|
|
1204
1710
|
payment: payment,
|
|
@@ -1218,11 +1724,12 @@ function buildPaymentItems(params) {
|
|
|
1218
1724
|
fundRecord: fundRecord,
|
|
1219
1725
|
locale: locale,
|
|
1220
1726
|
currencySymbol: currencySymbol,
|
|
1221
|
-
includeBalance: includeFundRecordBalance
|
|
1727
|
+
includeBalance: includeFundRecordBalance,
|
|
1728
|
+
includeUsage: includeFundRecordUsage
|
|
1222
1729
|
})));
|
|
1223
1730
|
} else {
|
|
1224
|
-
var
|
|
1225
|
-
var remainingAmount = (
|
|
1731
|
+
var _ref59, _payment$remaining_am, _payment$metadata;
|
|
1732
|
+
var remainingAmount = (_ref59 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref59 !== void 0 ? _ref59 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
|
|
1226
1733
|
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
1227
1734
|
items.push({
|
|
1228
1735
|
item: label(locale, 'remainingAmount'),
|
|
@@ -1282,16 +1789,19 @@ function buildFundRecordPaymentItems(params) {
|
|
|
1282
1789
|
fundRecord = params.fundRecord,
|
|
1283
1790
|
locale = params.locale,
|
|
1284
1791
|
currencySymbol = params.currencySymbol,
|
|
1285
|
-
includeBalance = params.includeBalance
|
|
1792
|
+
includeBalance = params.includeBalance,
|
|
1793
|
+
includeUsage = params.includeUsage;
|
|
1286
1794
|
var items = [];
|
|
1287
1795
|
var usingBeforeValue = fundRecord.using_before_value;
|
|
1288
1796
|
var usingAfterValue = fundRecord.using_after_value;
|
|
1289
1797
|
if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
|
|
1290
1798
|
var usedPoints = new Decimal(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1799
|
+
if (includeUsage) {
|
|
1800
|
+
items.push({
|
|
1801
|
+
item: label(locale, 'redeemPoints'),
|
|
1802
|
+
value: trimDecimal(usedPoints)
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1295
1805
|
if (includeBalance) {
|
|
1296
1806
|
items.push({
|
|
1297
1807
|
item: label(locale, 'remainingPoints'),
|
|
@@ -1302,7 +1812,7 @@ function buildFundRecordPaymentItems(params) {
|
|
|
1302
1812
|
}
|
|
1303
1813
|
if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
|
|
1304
1814
|
items.push({
|
|
1305
|
-
item: label(locale, '
|
|
1815
|
+
item: label(locale, 'balance'),
|
|
1306
1816
|
value: formatMoney(usingAfterValue, currencySymbol)
|
|
1307
1817
|
});
|
|
1308
1818
|
}
|
|
@@ -1373,12 +1883,12 @@ function label(locale, key) {
|
|
|
1373
1883
|
return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
|
|
1374
1884
|
}
|
|
1375
1885
|
function getLocalizedValue(value, locale) {
|
|
1376
|
-
var
|
|
1886
|
+
var _ref60, _ref61, _ref62, _ref63, _ref64, _ref65, _value$locale2;
|
|
1377
1887
|
if (value === undefined || value === null) return '';
|
|
1378
1888
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
1379
1889
|
var dashedLocale = locale.replace('_', '-');
|
|
1380
1890
|
var underscoredLocale = locale.replace('-', '_');
|
|
1381
|
-
return stringify((
|
|
1891
|
+
return stringify((_ref60 = (_ref61 = (_ref62 = (_ref63 = (_ref64 = (_ref65 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref65 !== void 0 ? _ref65 : value[underscoredLocale]) !== null && _ref64 !== void 0 ? _ref64 : value.original) !== null && _ref63 !== void 0 ? _ref63 : value.auto) !== null && _ref62 !== void 0 ? _ref62 : value.default) !== null && _ref61 !== void 0 ? _ref61 : value.en) !== null && _ref60 !== void 0 ? _ref60 : '');
|
|
1382
1892
|
}
|
|
1383
1893
|
function resolveServiceTypeLabelKey(serviceType, order) {
|
|
1384
1894
|
var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
@@ -1420,6 +1930,11 @@ function formatMoney(value, currencySymbol) {
|
|
|
1420
1930
|
var amount = new Decimal(toMoneyNumber(value));
|
|
1421
1931
|
return "".concat(currencySymbol).concat(amount.toFixed(2));
|
|
1422
1932
|
}
|
|
1933
|
+
function formatCalculatedMoney(value, currencySymbol) {
|
|
1934
|
+
var amount = new Decimal(toMoneyNumber(value));
|
|
1935
|
+
var sign = amount.isNegative() ? '-' : '';
|
|
1936
|
+
return "".concat(sign).concat(currencySymbol).concat(amount.abs().toFixed(2));
|
|
1937
|
+
}
|
|
1423
1938
|
function formatNegativeMoney(value, currencySymbol) {
|
|
1424
1939
|
var amount = new Decimal(toMoneyNumber(value)).abs();
|
|
1425
1940
|
return "-".concat(currencySymbol).concat(amount.toFixed(2));
|