@pisell/pisellos 0.10.32 → 0.10.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/OpenData/index.d.ts +1 -1
- package/dist/modules/OpenData/index.js +19 -11
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/server/utils/small-ticket.d.ts +5 -1
- package/dist/server/utils/small-ticket.js +146 -81
- package/dist/solution/BookingTicket/index.d.ts +6 -0
- package/dist/solution/BookingTicket/index.js +548 -485
- 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 -1
- package/lib/server/utils/small-ticket.d.ts +5 -1
- package/lib/server/utils/small-ticket.js +78 -18
- package/lib/solution/BookingTicket/index.d.ts +6 -0
- package/lib/solution/BookingTicket/index.js +32 -3
- package/package.json +1 -1
|
@@ -39,7 +39,7 @@ var LABELS = {
|
|
|
39
39
|
balance: 'Balance',
|
|
40
40
|
remainingAmount: 'Remaining amount',
|
|
41
41
|
redeemPoints: 'Redeem points',
|
|
42
|
-
remainingPoints: '
|
|
42
|
+
remainingPoints: 'Points balance',
|
|
43
43
|
table: 'Table',
|
|
44
44
|
orderDiscount: 'Order discount',
|
|
45
45
|
manualDiscount: 'Manual discount',
|
|
@@ -255,14 +255,14 @@ function buildLocaleData(params) {
|
|
|
255
255
|
});
|
|
256
256
|
}
|
|
257
257
|
function buildBaseData(params) {
|
|
258
|
-
var _order$metadata;
|
|
258
|
+
var _financials$amountGap, _order$metadata;
|
|
259
259
|
var order = params.order,
|
|
260
260
|
shopInfo = params.shopInfo,
|
|
261
261
|
locale = params.locale,
|
|
262
262
|
currencySymbol = params.currencySymbol,
|
|
263
263
|
financials = params.financials;
|
|
264
264
|
var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
|
|
265
|
-
return _objectSpread(
|
|
265
|
+
return _objectSpread({
|
|
266
266
|
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
267
267
|
note: stringify(order.note),
|
|
268
268
|
shop_order_number: stringify(order.shop_order_number),
|
|
@@ -273,10 +273,8 @@ function buildBaseData(params) {
|
|
|
273
273
|
original_payment_status: financials.paymentStatus,
|
|
274
274
|
payment_status: financials.paymentStatus,
|
|
275
275
|
total_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
276
|
-
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol)
|
|
277
|
-
|
|
278
|
-
amount_gap: formatMoney(financials.amountGap, currencySymbol)
|
|
279
|
-
} : {}), {}, {
|
|
276
|
+
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol),
|
|
277
|
+
amount_gap: formatCalculatedMoney((_financials$amountGap = financials.amountGap) !== null && _financials$amountGap !== void 0 ? _financials$amountGap : 0, currencySymbol),
|
|
280
278
|
is_repeat: 0,
|
|
281
279
|
buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
|
|
282
280
|
order_no: orderNumber,
|
|
@@ -328,15 +326,20 @@ function buildProducts(order, locale, productMap) {
|
|
|
328
326
|
});
|
|
329
327
|
var productNote = resolveProductNote(product, locale);
|
|
330
328
|
var basePrice = resolveProductBasePrice(product);
|
|
331
|
-
|
|
329
|
+
var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
|
|
330
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
332
331
|
product_title: productTitle,
|
|
333
332
|
product_quantity: quantity,
|
|
334
333
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
base_price:
|
|
334
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
|
|
335
|
+
original_price: formatMoney(originalPrice, currencySymbol),
|
|
336
|
+
base_price: formatCalculatedMoney(basePrice !== null && basePrice !== void 0 ? basePrice : 0, currencySymbol),
|
|
337
|
+
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol)
|
|
338
|
+
}, options.length ? {
|
|
339
|
+
options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
|
|
340
|
+
} : {}), resolvedCombinations.length ? {
|
|
341
|
+
package_items_total_price: sumCombinationTotals(resolvedCombinations, currencySymbol)
|
|
338
342
|
} : {}), {}, {
|
|
339
|
-
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
340
343
|
extension_list: extensionList
|
|
341
344
|
}, isPresentId(productUid) ? {
|
|
342
345
|
product_uid: productUid
|
|
@@ -348,10 +351,8 @@ function buildProducts(order, locale, productMap) {
|
|
|
348
351
|
options: options
|
|
349
352
|
} : {}), resolvedVariant ? {
|
|
350
353
|
variant: resolvedVariant
|
|
351
|
-
} : {}),
|
|
352
|
-
combinations:
|
|
353
|
-
} : combinations.length ? {
|
|
354
|
-
combinations: combinations
|
|
354
|
+
} : {}), resolvedCombinations.length ? {
|
|
355
|
+
combinations: resolvedCombinations
|
|
355
356
|
} : {});
|
|
356
357
|
});
|
|
357
358
|
}
|
|
@@ -488,9 +489,10 @@ function normalizeProductOptions(params) {
|
|
|
488
489
|
parentProduct = params.parentProduct;
|
|
489
490
|
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 : [];
|
|
490
491
|
return rawOptions.map(function (option) {
|
|
491
|
-
var _ref14, _option$original_pric, _ref15, _option$
|
|
492
|
+
var _ref14, _option$original_pric, _ref15, _option$num, _ref16, _option$value;
|
|
492
493
|
var price = (_ref14 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref14 !== void 0 ? _ref14 : option.price;
|
|
493
|
-
var
|
|
494
|
+
var quantity = toNumber((_ref15 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref15 !== void 0 ? _ref15 : 1, 1);
|
|
495
|
+
var value = (_ref16 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref16 !== void 0 ? _ref16 : option.item;
|
|
494
496
|
var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
|
|
495
497
|
option: option,
|
|
496
498
|
parentProduct: parentProduct,
|
|
@@ -499,10 +501,12 @@ function normalizeProductOptions(params) {
|
|
|
499
501
|
return _objectSpread(_objectSpread(_objectSpread({
|
|
500
502
|
name: name
|
|
501
503
|
}, option.num !== undefined || option.quantity !== undefined ? {
|
|
502
|
-
num:
|
|
504
|
+
num: quantity
|
|
503
505
|
} : {}), price !== undefined && price !== null && price !== '' ? {
|
|
504
506
|
price: formatMoney(price, currencySymbol)
|
|
505
|
-
} : {}),
|
|
507
|
+
} : {}), {}, {
|
|
508
|
+
total_price: formatCalculatedMoney(new Decimal(toMoneyNumber(price !== null && price !== void 0 ? price : 0)).mul(quantity), currencySymbol)
|
|
509
|
+
}, value !== undefined && value !== null && value !== '' ? {
|
|
506
510
|
value: getLocalizedValue(value, locale)
|
|
507
511
|
} : {});
|
|
508
512
|
});
|
|
@@ -515,7 +519,7 @@ function normalizeProductCombinations(params) {
|
|
|
515
519
|
parentProduct = params.parentProduct;
|
|
516
520
|
var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
517
521
|
return bundles.map(function (bundle) {
|
|
518
|
-
var
|
|
522
|
+
var _ref17, _bundle$num, _bundle$metadata;
|
|
519
523
|
var combinationsOptions = normalizeProductOptions({
|
|
520
524
|
product: {},
|
|
521
525
|
locale: locale,
|
|
@@ -530,43 +534,97 @@ function normalizeProductCombinations(params) {
|
|
|
530
534
|
parentProduct: parentProduct
|
|
531
535
|
});
|
|
532
536
|
var productNote = resolveProductNote(bundle, locale);
|
|
533
|
-
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
|
|
534
|
-
|
|
537
|
+
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
|
|
538
|
+
var quantity = toNumber((_ref17 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref17 !== void 0 ? _ref17 : 1, 1);
|
|
539
|
+
var formattedPrice = formatBundlePrice(bundle, currencySymbol);
|
|
540
|
+
var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
|
|
541
|
+
var explicitBasePrice = firstPresentValue(bundle.base_price, (_bundle$metadata = bundle.metadata) === null || _bundle$metadata === void 0 ? void 0 : _bundle$metadata.source_product_price);
|
|
542
|
+
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
543
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
535
544
|
product_title: baseTitle,
|
|
536
|
-
product_quantity:
|
|
537
|
-
price:
|
|
545
|
+
product_quantity: quantity,
|
|
546
|
+
price: formattedPrice,
|
|
547
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol),
|
|
548
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol),
|
|
538
549
|
combinations_options: combinationsOptions
|
|
539
|
-
},
|
|
550
|
+
}, combinationsOptions.length ? {
|
|
551
|
+
options_total_price: optionsTotal
|
|
552
|
+
} : {}), nestedCombinations.length ? {
|
|
553
|
+
package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
|
|
554
|
+
} : {}), productNote ? {
|
|
540
555
|
product_note: productNote
|
|
541
556
|
} : {}), nestedCombinations.length ? {
|
|
542
557
|
combinations: nestedCombinations
|
|
543
558
|
} : {});
|
|
544
559
|
});
|
|
545
560
|
}
|
|
546
|
-
function normalizeExistingCombinations(combinations, locale) {
|
|
561
|
+
function normalizeExistingCombinations(combinations, locale, currencySymbol) {
|
|
547
562
|
return combinations.map(function (combination) {
|
|
563
|
+
var _ref18, _ref19, _combination$product_, _firstPresentValue;
|
|
548
564
|
if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
|
|
549
565
|
return combination;
|
|
550
566
|
}
|
|
551
567
|
var productNote = resolveProductNote(combination, locale);
|
|
552
|
-
var
|
|
568
|
+
var rawOptions = Array.isArray(combination.combinations_options) ? combination.combinations_options : Array.isArray(combination.options) ? combination.options : [];
|
|
569
|
+
var normalizedOptions = normalizeProductOptions({
|
|
570
|
+
product: {},
|
|
571
|
+
locale: locale,
|
|
572
|
+
currencySymbol: currencySymbol,
|
|
573
|
+
options: rawOptions
|
|
574
|
+
});
|
|
575
|
+
var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
|
|
553
576
|
var snapshot = _objectSpread({}, combination);
|
|
554
577
|
delete snapshot.product_note;
|
|
555
578
|
delete snapshot.note;
|
|
556
|
-
|
|
579
|
+
delete snapshot.combinations;
|
|
580
|
+
var quantity = toNumber((_ref18 = (_ref19 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref19 !== void 0 ? _ref19 : combination.quantity) !== null && _ref18 !== void 0 ? _ref18 : 1, 1);
|
|
581
|
+
var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
|
|
582
|
+
var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
|
|
583
|
+
return option.total_price;
|
|
584
|
+
}));
|
|
585
|
+
var explicitBasePrice = firstPresentValue(combination.base_price);
|
|
586
|
+
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
587
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), {}, {
|
|
588
|
+
product_quantity: quantity,
|
|
589
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol),
|
|
590
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
591
|
+
}, Array.isArray(combination.combinations_options) ? {
|
|
592
|
+
combinations_options: normalizedOptions
|
|
593
|
+
} : Array.isArray(combination.options) ? {
|
|
594
|
+
options: normalizedOptions
|
|
595
|
+
} : {}), normalizedOptions.length ? {
|
|
596
|
+
options_total_price: formatCalculatedMoney(optionsAmount, currencySymbol)
|
|
597
|
+
} : {}), nestedCombinations.length ? {
|
|
598
|
+
package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
|
|
599
|
+
} : {}), productNote ? {
|
|
557
600
|
product_note: productNote
|
|
558
|
-
} : {}), nestedCombinations ? {
|
|
601
|
+
} : {}), nestedCombinations.length ? {
|
|
559
602
|
combinations: nestedCombinations
|
|
560
603
|
} : {});
|
|
561
604
|
});
|
|
562
605
|
}
|
|
606
|
+
function sumMoneyValues(values) {
|
|
607
|
+
return values.reduce(function (sum, value) {
|
|
608
|
+
return sum.plus(toMoneyNumber(value));
|
|
609
|
+
}, new Decimal(0));
|
|
610
|
+
}
|
|
611
|
+
function sumNormalizedOptionTotals(options, currencySymbol) {
|
|
612
|
+
return formatCalculatedMoney(sumMoneyValues(options.map(function (option) {
|
|
613
|
+
return option.total_price;
|
|
614
|
+
})), currencySymbol);
|
|
615
|
+
}
|
|
616
|
+
function sumCombinationTotals(combinations, currencySymbol) {
|
|
617
|
+
return formatCalculatedMoney(sumMoneyValues(combinations.map(function (combination) {
|
|
618
|
+
return combination.total_selling_price;
|
|
619
|
+
})), currencySymbol);
|
|
620
|
+
}
|
|
563
621
|
function resolveProductNote(product, locale) {
|
|
564
622
|
var productNote = getLocalizedValue(product.product_note, locale).trim();
|
|
565
623
|
if (productNote) return productNote;
|
|
566
624
|
return getLocalizedValue(product.note, locale).trim();
|
|
567
625
|
}
|
|
568
626
|
function resolveBundleProductTitle(params) {
|
|
569
|
-
var
|
|
627
|
+
var _ref20, _ref21, _bundle$bundle_produc;
|
|
570
628
|
var bundle = params.bundle,
|
|
571
629
|
productMap = params.productMap,
|
|
572
630
|
locale = params.locale,
|
|
@@ -579,7 +637,7 @@ function resolveBundleProductTitle(params) {
|
|
|
579
637
|
});
|
|
580
638
|
var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
|
|
581
639
|
if (parentBundleTitle) return parentBundleTitle;
|
|
582
|
-
var productId = (
|
|
640
|
+
var productId = (_ref20 = (_ref21 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref21 !== void 0 ? _ref21 : bundle.product_id) !== null && _ref20 !== void 0 ? _ref20 : bundle.id;
|
|
583
641
|
var fallbackProduct = resolveProductFromMap(productId, productMap);
|
|
584
642
|
if (!fallbackProduct) return '';
|
|
585
643
|
return getProductTitleSource(fallbackProduct, locale);
|
|
@@ -631,10 +689,10 @@ function resolveVariantTextFromSkuKey(params) {
|
|
|
631
689
|
}
|
|
632
690
|
function resolveVariantTextFromNameMap(params) {
|
|
633
691
|
if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
|
|
634
|
-
return Object.entries(params.nameMap).map(function (
|
|
635
|
-
var
|
|
636
|
-
groupPositionId =
|
|
637
|
-
value =
|
|
692
|
+
return Object.entries(params.nameMap).map(function (_ref22) {
|
|
693
|
+
var _ref23 = _slicedToArray(_ref22, 2),
|
|
694
|
+
groupPositionId = _ref23[0],
|
|
695
|
+
value = _ref23[1];
|
|
638
696
|
var group = resolveVariantGroup(params.parentProduct, groupPositionId);
|
|
639
697
|
if (!group) return '';
|
|
640
698
|
var groupName = getLocalizedValue(group.name, params.locale);
|
|
@@ -668,12 +726,12 @@ function getProductTitleSource(source, locale) {
|
|
|
668
726
|
return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
|
|
669
727
|
}
|
|
670
728
|
function resolveTitleValue(value, locale) {
|
|
671
|
-
var
|
|
729
|
+
var _ref24, _ref25, _ref26, _ref27, _value$locale;
|
|
672
730
|
if (value === undefined || value === null) return '';
|
|
673
731
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
674
732
|
var dashedLocale = locale.replace('_', '-');
|
|
675
733
|
var underscoredLocale = locale.replace('-', '_');
|
|
676
|
-
return stringify((
|
|
734
|
+
return stringify((_ref24 = (_ref25 = (_ref26 = (_ref27 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref27 !== void 0 ? _ref27 : value[underscoredLocale]) !== null && _ref26 !== void 0 ? _ref26 : value.original) !== null && _ref25 !== void 0 ? _ref25 : value.auto) !== null && _ref24 !== void 0 ? _ref24 : '');
|
|
677
735
|
}
|
|
678
736
|
function resolveOptionTitleFromParentProduct(params) {
|
|
679
737
|
var option = params.option,
|
|
@@ -691,17 +749,17 @@ function flattenOptionItems(parentProduct) {
|
|
|
691
749
|
return optionGroups.flatMap(function (group) {
|
|
692
750
|
var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
|
|
693
751
|
return items.map(function (item) {
|
|
694
|
-
var
|
|
752
|
+
var _ref28, _item$option_group_id;
|
|
695
753
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
696
|
-
option_group_id: (
|
|
754
|
+
option_group_id: (_ref28 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref28 !== void 0 ? _ref28 : group.option_group_id
|
|
697
755
|
});
|
|
698
756
|
});
|
|
699
757
|
});
|
|
700
758
|
}
|
|
701
759
|
function isOptionItemMatch(option, item) {
|
|
702
|
-
var
|
|
703
|
-
var optionItemId = (
|
|
704
|
-
var itemId = (
|
|
760
|
+
var _ref29, _option$option_group_, _ref30, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
|
|
761
|
+
var optionItemId = (_ref29 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref29 !== void 0 ? _ref29 : option.id;
|
|
762
|
+
var itemId = (_ref30 = (_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 && _ref30 !== void 0 ? _ref30 : item.id;
|
|
705
763
|
if (!isSameId(optionItemId, itemId)) return false;
|
|
706
764
|
var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
|
|
707
765
|
var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
|
|
@@ -711,16 +769,16 @@ function isOptionItemMatch(option, item) {
|
|
|
711
769
|
return true;
|
|
712
770
|
}
|
|
713
771
|
function resolveBundleItemFromParentProduct(params) {
|
|
714
|
-
var
|
|
772
|
+
var _ref31, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref33, _bundle$bundle_produc2;
|
|
715
773
|
var bundle = params.bundle,
|
|
716
774
|
parentProduct = params.parentProduct;
|
|
717
775
|
if (!parentProduct) return null;
|
|
718
776
|
var bundleItems = flattenBundleItems(parentProduct);
|
|
719
|
-
var bundleVariantId = (
|
|
777
|
+
var bundleVariantId = (_ref31 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref31 !== void 0 ? _ref31 : bundle.product_variant_id;
|
|
720
778
|
if (isNonZeroId(bundleVariantId)) {
|
|
721
779
|
var matchedByVariant = bundleItems.find(function (item) {
|
|
722
|
-
var
|
|
723
|
-
return isSameId((
|
|
780
|
+
var _ref32, _item$bundle_variant_;
|
|
781
|
+
return isSameId((_ref32 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref32 !== void 0 ? _ref32 : item.product_variant_id, bundleVariantId);
|
|
724
782
|
});
|
|
725
783
|
if (matchedByVariant) return matchedByVariant;
|
|
726
784
|
}
|
|
@@ -733,18 +791,18 @@ function resolveBundleItemFromParentProduct(params) {
|
|
|
733
791
|
if (matchedByBundleId) return matchedByBundleId;
|
|
734
792
|
}
|
|
735
793
|
var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
|
|
736
|
-
var bundleProductId = (
|
|
794
|
+
var bundleProductId = (_ref33 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref33 !== void 0 ? _ref33 : bundle.product_id;
|
|
737
795
|
if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
|
|
738
796
|
var matchedByGroupAndProduct = bundleItems.find(function (item) {
|
|
739
|
-
var _item$group_id,
|
|
740
|
-
return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((
|
|
797
|
+
var _item$group_id, _ref34, _item$bundle_product_;
|
|
798
|
+
return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref34 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref34 !== void 0 ? _ref34 : item.product_id, bundleProductId);
|
|
741
799
|
});
|
|
742
800
|
if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
|
|
743
801
|
}
|
|
744
802
|
if (isPresentId(bundleProductId)) {
|
|
745
803
|
return bundleItems.find(function (item) {
|
|
746
|
-
var
|
|
747
|
-
return isSameId((
|
|
804
|
+
var _ref35, _item$bundle_product_2;
|
|
805
|
+
return isSameId((_ref35 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref35 !== void 0 ? _ref35 : item.product_id, bundleProductId);
|
|
748
806
|
}) || null;
|
|
749
807
|
}
|
|
750
808
|
return null;
|
|
@@ -754,9 +812,9 @@ function flattenBundleItems(parentProduct) {
|
|
|
754
812
|
return bundleGroups.flatMap(function (group) {
|
|
755
813
|
var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
|
|
756
814
|
return items.map(function (item) {
|
|
757
|
-
var
|
|
815
|
+
var _ref36, _item$group_id2;
|
|
758
816
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
759
|
-
group_id: (
|
|
817
|
+
group_id: (_ref36 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref36 !== void 0 ? _ref36 : group.group_id
|
|
760
818
|
});
|
|
761
819
|
});
|
|
762
820
|
});
|
|
@@ -780,8 +838,8 @@ function isSameId(left, right) {
|
|
|
780
838
|
return String(left) === String(right);
|
|
781
839
|
}
|
|
782
840
|
function formatBundlePrice(bundle, currencySymbol) {
|
|
783
|
-
var
|
|
784
|
-
var value = (
|
|
841
|
+
var _ref37, _ref38, _bundle$bundle_sellin;
|
|
842
|
+
var value = (_ref37 = (_ref38 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref38 !== void 0 ? _ref38 : bundle.price) !== null && _ref37 !== void 0 ? _ref37 : 0;
|
|
785
843
|
var amount = new Decimal(toMoneyNumber(value));
|
|
786
844
|
// 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
|
|
787
845
|
var isNegative = bundle.price_type === 'markdown';
|
|
@@ -789,7 +847,7 @@ function formatBundlePrice(bundle, currencySymbol) {
|
|
|
789
847
|
return formatMoney(amount, currencySymbol);
|
|
790
848
|
}
|
|
791
849
|
function buildFees(params) {
|
|
792
|
-
var
|
|
850
|
+
var _firstPresentValue2, _firstPresentValue3;
|
|
793
851
|
var order = params.order,
|
|
794
852
|
shopInfo = params.shopInfo,
|
|
795
853
|
locale = params.locale,
|
|
@@ -799,9 +857,9 @@ function buildFees(params) {
|
|
|
799
857
|
financials = params.financials;
|
|
800
858
|
var fees = [];
|
|
801
859
|
for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
|
|
802
|
-
var
|
|
860
|
+
var _ref39, _surcharge$amount;
|
|
803
861
|
var surcharge = _normalizeArray[_i];
|
|
804
|
-
var value = (
|
|
862
|
+
var value = (_ref39 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref39 !== void 0 ? _ref39 : surcharge.total_amount;
|
|
805
863
|
if (!isNonZero(value)) continue;
|
|
806
864
|
fees.push({
|
|
807
865
|
item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
|
|
@@ -838,14 +896,16 @@ function buildFees(params) {
|
|
|
838
896
|
});
|
|
839
897
|
}
|
|
840
898
|
var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
|
|
841
|
-
var productOriginalAmount = (
|
|
899
|
+
var productOriginalAmount = (_firstPresentValue2 = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : calculateProductOriginalAmount(order);
|
|
842
900
|
var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
|
|
901
|
+
var itemDiscountAmount = new Decimal(toMoneyNumber(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0)).minus(toMoneyNumber(productOriginalAmount));
|
|
843
902
|
return {
|
|
844
903
|
fees: fees,
|
|
845
904
|
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
846
|
-
total_amount: formatMoney((
|
|
905
|
+
total_amount: formatMoney((_firstPresentValue3 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0, currencySymbol),
|
|
847
906
|
original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
|
|
848
907
|
product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
|
|
908
|
+
item_discount_amount: formatCalculatedMoney(itemDiscountAmount, currencySymbol),
|
|
849
909
|
expect_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
850
910
|
product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
|
|
851
911
|
return sum + product.product_quantity;
|
|
@@ -870,15 +930,15 @@ function buildFees(params) {
|
|
|
870
930
|
};
|
|
871
931
|
}
|
|
872
932
|
function resolveReceiptFinancials(order, summary) {
|
|
873
|
-
var
|
|
874
|
-
var totalAmount = (
|
|
933
|
+
var _firstPresentValue4, _firstPresentValue5, _firstPresentValue6, _firstPresentValue7;
|
|
934
|
+
var totalAmount = (_firstPresentValue4 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
|
|
875
935
|
var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
|
|
876
936
|
var payProcessingFee = rawPayProcessingFee !== null && rawPayProcessingFee !== void 0 ? rawPayProcessingFee : 0;
|
|
877
|
-
var orderPaidAmount = (
|
|
878
|
-
var totalRefundAmount = (
|
|
937
|
+
var orderPaidAmount = (_firstPresentValue5 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
|
|
938
|
+
var totalRefundAmount = (_firstPresentValue6 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
|
|
879
939
|
var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
|
|
880
940
|
var fallbackCustomerPaidAmount = Decimal.max(sumCustomerPaidPayments(order.payments), new Decimal(toMoneyNumber(orderPaidAmount)).plus(toMoneyNumber(payProcessingFee)));
|
|
881
|
-
var customerPaidAmount = (
|
|
941
|
+
var customerPaidAmount = (_firstPresentValue7 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
|
|
882
942
|
var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
|
|
883
943
|
return {
|
|
884
944
|
totalAmount: totalAmount,
|
|
@@ -907,9 +967,9 @@ function resolveTaxTitle(params) {
|
|
|
907
967
|
}
|
|
908
968
|
function calculateProductOriginalAmount(order) {
|
|
909
969
|
return normalizeArray(order.products).reduce(function (total, product) {
|
|
910
|
-
var
|
|
911
|
-
var quantity = toNumber((
|
|
912
|
-
var originalPrice = (
|
|
970
|
+
var _ref40, _ref41, _product$product_quan2, _ref42, _ref43, _ref44, _product$original_pri2;
|
|
971
|
+
var quantity = toNumber((_ref40 = (_ref41 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref41 !== void 0 ? _ref41 : product.num) !== null && _ref40 !== void 0 ? _ref40 : 1, 1);
|
|
972
|
+
var originalPrice = (_ref42 = (_ref43 = (_ref44 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref44 !== void 0 ? _ref44 : product.payment_price) !== null && _ref43 !== void 0 ? _ref43 : product.price) !== null && _ref42 !== void 0 ? _ref42 : 0;
|
|
913
973
|
return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
|
|
914
974
|
}, new Decimal(0));
|
|
915
975
|
}
|
|
@@ -997,8 +1057,8 @@ function sortBookings(bookings) {
|
|
|
997
1057
|
}
|
|
998
1058
|
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));
|
|
999
1059
|
return bookingUidOrder || left.index - right.index;
|
|
1000
|
-
}).map(function (
|
|
1001
|
-
var booking =
|
|
1060
|
+
}).map(function (_ref45) {
|
|
1061
|
+
var booking = _ref45.booking;
|
|
1002
1062
|
return booking;
|
|
1003
1063
|
});
|
|
1004
1064
|
}
|
|
@@ -1060,8 +1120,8 @@ function buildRefundData(params) {
|
|
|
1060
1120
|
result.set(identity, candidate);
|
|
1061
1121
|
}
|
|
1062
1122
|
return result;
|
|
1063
|
-
}, new Map()).values()).filter(function (
|
|
1064
|
-
var refund =
|
|
1123
|
+
}, new Map()).values()).filter(function (_ref46) {
|
|
1124
|
+
var refund = _ref46.refund;
|
|
1065
1125
|
return isPrintableRefund(refund);
|
|
1066
1126
|
}).sort(function (left, right) {
|
|
1067
1127
|
var leftTime = refundTimestamp(left.refund);
|
|
@@ -1069,12 +1129,12 @@ function buildRefundData(params) {
|
|
|
1069
1129
|
if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
|
|
1070
1130
|
return left.index - right.index;
|
|
1071
1131
|
});
|
|
1072
|
-
return refunds.map(function (
|
|
1073
|
-
var
|
|
1074
|
-
var refund =
|
|
1132
|
+
return refunds.map(function (_ref47) {
|
|
1133
|
+
var _firstPresentValue8;
|
|
1134
|
+
var refund = _ref47.refund;
|
|
1075
1135
|
var payment = resolveRefundPayment(refund, payments);
|
|
1076
1136
|
var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
|
|
1077
|
-
var amount = (
|
|
1137
|
+
var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
|
|
1078
1138
|
var items = [{
|
|
1079
1139
|
item: methodName,
|
|
1080
1140
|
value: formatNegativeMoney(amount, params.currencySymbol)
|
|
@@ -1292,8 +1352,8 @@ function buildPaymentItems(params) {
|
|
|
1292
1352
|
includeUsage: includeFundRecordUsage
|
|
1293
1353
|
})));
|
|
1294
1354
|
} else {
|
|
1295
|
-
var
|
|
1296
|
-
var remainingAmount = (
|
|
1355
|
+
var _ref48, _payment$remaining_am, _payment$metadata;
|
|
1356
|
+
var remainingAmount = (_ref48 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref48 !== void 0 ? _ref48 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
|
|
1297
1357
|
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
1298
1358
|
items.push({
|
|
1299
1359
|
item: label(locale, 'remainingAmount'),
|
|
@@ -1447,12 +1507,12 @@ function label(locale, key) {
|
|
|
1447
1507
|
return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
|
|
1448
1508
|
}
|
|
1449
1509
|
function getLocalizedValue(value, locale) {
|
|
1450
|
-
var
|
|
1510
|
+
var _ref49, _ref50, _ref51, _ref52, _ref53, _ref54, _value$locale2;
|
|
1451
1511
|
if (value === undefined || value === null) return '';
|
|
1452
1512
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
1453
1513
|
var dashedLocale = locale.replace('_', '-');
|
|
1454
1514
|
var underscoredLocale = locale.replace('-', '_');
|
|
1455
|
-
return stringify((
|
|
1515
|
+
return stringify((_ref49 = (_ref50 = (_ref51 = (_ref52 = (_ref53 = (_ref54 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref54 !== void 0 ? _ref54 : value[underscoredLocale]) !== null && _ref53 !== void 0 ? _ref53 : value.original) !== null && _ref52 !== void 0 ? _ref52 : value.auto) !== null && _ref51 !== void 0 ? _ref51 : value.default) !== null && _ref50 !== void 0 ? _ref50 : value.en) !== null && _ref49 !== void 0 ? _ref49 : '');
|
|
1456
1516
|
}
|
|
1457
1517
|
function resolveServiceTypeLabelKey(serviceType, order) {
|
|
1458
1518
|
var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
@@ -1494,6 +1554,11 @@ function formatMoney(value, currencySymbol) {
|
|
|
1494
1554
|
var amount = new Decimal(toMoneyNumber(value));
|
|
1495
1555
|
return "".concat(currencySymbol).concat(amount.toFixed(2));
|
|
1496
1556
|
}
|
|
1557
|
+
function formatCalculatedMoney(value, currencySymbol) {
|
|
1558
|
+
var amount = new Decimal(toMoneyNumber(value));
|
|
1559
|
+
var sign = amount.isNegative() ? '-' : '';
|
|
1560
|
+
return "".concat(sign).concat(currencySymbol).concat(amount.abs().toFixed(2));
|
|
1561
|
+
}
|
|
1497
1562
|
function formatNegativeMoney(value, currencySymbol) {
|
|
1498
1563
|
var amount = new Decimal(toMoneyNumber(value)).abs();
|
|
1499
1564
|
return "-".concat(currencySymbol).concat(amount.toFixed(2));
|
|
@@ -45,6 +45,12 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
45
45
|
*/
|
|
46
46
|
protected createSubModule(moduleName: string): Module | null;
|
|
47
47
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
48
|
+
private getInjectedOpenDataConfig;
|
|
49
|
+
/**
|
|
50
|
+
* 在解决方案对外 ready 前准备 Invoice Document;失败只降级模板,不阻断销售。
|
|
51
|
+
* 已由页面取得的 OpenData 直接交给模块接管,没有注入数据时再走 target-scoped 加载。
|
|
52
|
+
*/
|
|
53
|
+
private prepareInvoiceTemplateAtSolutionReady;
|
|
48
54
|
protected getBookingTicketBusinessCode(): string | null;
|
|
49
55
|
private getIdGeneratorPlugin;
|
|
50
56
|
private loadOpenDataConfig;
|