@pisell/pisellos 2.3.117 → 2.3.119

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.
@@ -31,6 +31,9 @@ export interface SmallTicketItem {
31
31
  product_uid?: string | number;
32
32
  booking_uid?: string | number;
33
33
  }
34
+ export type SmallTicketDeliveryItem = Omit<SmallTicketItem, 'value'> & {
35
+ value?: string;
36
+ };
34
37
  export interface SmallTicketProduct {
35
38
  product_title: string;
36
39
  product_quantity: number;
@@ -66,7 +69,7 @@ export interface SmallTicketLocaleData {
66
69
  };
67
70
  customer: SmallTicketItem[];
68
71
  appointment: SmallTicketAppointment;
69
- delivery?: SmallTicketItem[];
72
+ delivery?: SmallTicketDeliveryItem[];
70
73
  resources: Array<{
71
74
  id: string | number;
72
75
  code: string;
@@ -61,6 +61,7 @@ var LABELS = {
61
61
  remainingAmount: 'Remaining amount',
62
62
  redeemPoints: 'Redeem points',
63
63
  remainingPoints: 'Points balance',
64
+ entitlementRemaining: 'Remaining',
64
65
  table: 'Table',
65
66
  bookingId: 'Booking ID',
66
67
  bookingDateTime: 'Date & time',
@@ -105,6 +106,7 @@ var LABELS = {
105
106
  remainingAmount: '剩余金额',
106
107
  redeemPoints: '本次使用积分',
107
108
  remainingPoints: '积分余额',
109
+ entitlementRemaining: '剩余次数',
108
110
  table: '桌台',
109
111
  bookingId: '预约编号',
110
112
  bookingDateTime: '日期和时间',
@@ -149,6 +151,7 @@ var LABELS = {
149
151
  remainingAmount: '剩餘金額',
150
152
  redeemPoints: '本次使用積分',
151
153
  remainingPoints: '積分餘額',
154
+ entitlementRemaining: '剩餘次數',
152
155
  table: '桌台',
153
156
  bookingId: '預約編號',
154
157
  bookingDateTime: '日期和時間',
@@ -191,6 +194,7 @@ var LABELS = {
191
194
  remainingAmount: '残高',
192
195
  redeemPoints: '利用ポイント',
193
196
  remainingPoints: 'ポイント残高',
197
+ entitlementRemaining: '残り回数',
194
198
  table: 'テーブル',
195
199
  bookingId: '予約ID',
196
200
  bookingDateTime: '日時',
@@ -234,6 +238,7 @@ var LABELS = {
234
238
  remainingAmount: 'Saldo restante',
235
239
  redeemPoints: 'Pontos utilizados',
236
240
  remainingPoints: 'Saldo de pontos',
241
+ entitlementRemaining: 'Utilizações restantes',
237
242
  table: 'Mesa',
238
243
  bookingId: 'ID da reserva',
239
244
  bookingDateTime: 'Data e hora',
@@ -549,7 +554,8 @@ function normalizeProductDiscounts(params) {
549
554
  var title = resolveDiscountTitleWithPercent(discount, locale);
550
555
  var amount = (_ref15 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref15 !== void 0 ? _ref15 : discount.discount_amount;
551
556
  var isMarkup = isManualMarkup(discount);
552
- var totalAmount = new Decimal(toMoneyNumber(amount)).mul(quantity);
557
+ var isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
558
+ var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount ? 1 : quantity);
553
559
  var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
554
560
  return {
555
561
  item: title,
@@ -649,6 +655,9 @@ function buildProductQuantityPriceText(params) {
649
655
  function resolveDiscountTitleWithPercent(discount, locale) {
650
656
  var _discount$discount2, _discount$discount$di, _discount$discount3;
651
657
  var title = resolveDiscountTitle(discount, locale);
658
+ if (getProductWalletDiscountType(discount) === 'entitlement_pass') {
659
+ return title;
660
+ }
652
661
  var percentRaw = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.percent;
653
662
  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';
654
663
  var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
@@ -1238,10 +1247,8 @@ function buildDelivery(order, locale) {
1238
1247
  var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType);
1239
1248
  if (!serviceTypeLabelKey) return [];
1240
1249
  var items = [{
1241
- item: '',
1242
- value: label(locale, serviceTypeLabelKey),
1243
- size: 2,
1244
- align: 'left'
1250
+ item: label(locale, serviceTypeLabelKey),
1251
+ size: 2
1245
1252
  }];
1246
1253
  var handoverTime = firstPresentValue(order.handover_time, order.handover_at, order.pickup_time, order.pickup_at, order.scheduled_pickup_time, order.delivery_time, order.delivery_at, order.scheduled_delivery_time, order.fulfillment_time, order.fulfillment_at, (_order$metadata3 = order.metadata) === null || _order$metadata3 === void 0 ? void 0 : _order$metadata3.handover_time, (_order$metadata4 = order.metadata) === null || _order$metadata4 === void 0 ? void 0 : _order$metadata4.handover_at, (_order$metadata5 = order.metadata) === null || _order$metadata5 === void 0 ? void 0 : _order$metadata5.pickup_time, (_order$metadata6 = order.metadata) === null || _order$metadata6 === void 0 ? void 0 : _order$metadata6.pickup_at, (_order$metadata7 = order.metadata) === null || _order$metadata7 === void 0 ? void 0 : _order$metadata7.scheduled_pickup_time, (_order$metadata8 = order.metadata) === null || _order$metadata8 === void 0 ? void 0 : _order$metadata8.delivery_time, (_order$metadata9 = order.metadata) === null || _order$metadata9 === void 0 ? void 0 : _order$metadata9.delivery_at, (_order$metadata10 = order.metadata) === null || _order$metadata10 === void 0 ? void 0 : _order$metadata10.scheduled_delivery_time, (_order$metadata11 = order.metadata) === null || _order$metadata11 === void 0 ? void 0 : _order$metadata11.fulfillment_time, (_order$metadata12 = order.metadata) === null || _order$metadata12 === void 0 ? void 0 : _order$metadata12.fulfillment_at);
1247
1254
  if (isPresentId(handoverTime)) {
@@ -1540,43 +1547,323 @@ function buildWallets(params) {
1540
1547
  virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
1541
1548
  });
1542
1549
  });
1543
- var displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
1544
- return [].concat(_toConsumableArray(paymentWallets), _toConsumableArray(buildVoucherAssets(params)), _toConsumableArray(buildPointCardSnapshotAssets({
1550
+ var displayedWalletAssetIdentities = collectDisplayedWalletAssetIdentities(displayedWalletPayments);
1551
+ var voucherWallets = buildVoucherAssets(_objectSpread(_objectSpread({}, params), {}, {
1552
+ displayedWalletAssetIdentities: displayedWalletAssetIdentities
1553
+ }));
1554
+ var productDiscountWallets = buildProductDiscountAssets(_objectSpread(_objectSpread({}, params), {}, {
1555
+ displayedWalletAssetIdentities: displayedWalletAssetIdentities
1556
+ }));
1557
+ return [].concat(_toConsumableArray(paymentWallets), voucherWallets, productDiscountWallets, _toConsumableArray(buildPointCardSnapshotAssets({
1545
1558
  order: params.order,
1546
1559
  locale: params.locale,
1547
- displayedWalletPassIds: displayedWalletPassIds
1560
+ displayedWalletAssetIdentities: displayedWalletAssetIdentities
1548
1561
  })), _toConsumableArray(buildVirtualCurrencySnapshotAssets({
1549
1562
  snapshots: virtualCurrencySnapshots.items,
1550
1563
  order: params.order,
1551
1564
  locale: params.locale,
1552
- displayedWalletPassIds: displayedWalletPassIds
1565
+ displayedWalletAssetIdentities: displayedWalletAssetIdentities
1553
1566
  })));
1554
1567
  }
1555
- function collectDisplayedWalletPassIds(payments) {
1556
- var ids = new Set();
1568
+ function collectDisplayedWalletAssetIdentities(payments) {
1569
+ var identities = [];
1557
1570
  payments.forEach(function (payment) {
1558
1571
  var fundRecord = getFundRecord(payment);
1559
- [payment.voucher_id, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id].forEach(function (value) {
1560
- var id = normalizeWalletPassId(value);
1561
- if (id) ids.add(id);
1572
+ var ids = Array.from(new Set([fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id].map(function (value) {
1573
+ return normalizeWalletPassId(value);
1574
+ }).filter(function (value) {
1575
+ return !!value;
1576
+ })));
1577
+ var codes = normalizeWalletAssetCodes(fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.code, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.encoded);
1578
+ if (!ids.length) {
1579
+ registerWalletAssetIdentity(identities, {
1580
+ id: null,
1581
+ codes: codes
1582
+ });
1583
+ return;
1584
+ }
1585
+ ids.forEach(function (id) {
1586
+ registerWalletAssetIdentity(identities, {
1587
+ id: id,
1588
+ codes: codes
1589
+ });
1562
1590
  });
1563
1591
  });
1564
- return ids;
1592
+ return identities;
1593
+ }
1594
+ var PRODUCT_WALLET_DISCOUNT_TYPES = new Set(['good_pass', 'discount_card', 'product_discount_card', 'entitlement_pass']);
1595
+ function buildProductDiscountAssets(params) {
1596
+ var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1597
+ return collectProductWalletDiscountAssets(params.order).flatMap(function (asset) {
1598
+ var _getProductWalletDisc;
1599
+ if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1600
+ id: asset.id,
1601
+ codes: asset.codes
1602
+ })) return [];
1603
+ var name = getProductWalletDiscountName(asset, params.locale);
1604
+ var assetTime = (_getProductWalletDisc = getProductWalletDiscountTime(asset)) !== null && _getProductWalletDisc !== void 0 ? _getProductWalletDisc : fallbackAssetTime;
1605
+ var timeRow = isPresentId(assetTime) ? {
1606
+ item: formatDateTime(assetTime, params.locale),
1607
+ value: ''
1608
+ } : null;
1609
+ if (asset.type === 'entitlement_pass') {
1610
+ var remaining = getProductEntitlementBalance(asset);
1611
+ return [[{
1612
+ item: name,
1613
+ value: ''
1614
+ }].concat(_toConsumableArray(remaining ? [{
1615
+ item: label(params.locale, 'entitlementRemaining'),
1616
+ value: formatEntitlementUses(remaining, params.locale)
1617
+ }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1618
+ }
1619
+ var percent = getProductWalletDiscountPercent(asset);
1620
+ if (percent) {
1621
+ return [[{
1622
+ item: appendPercentToVoucherName(name, percent),
1623
+ value: formatVoucherDiscount(percent, params.locale)
1624
+ }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1625
+ }
1626
+ var balance = getProductWalletMoneyBalance(asset);
1627
+ return [[{
1628
+ item: name,
1629
+ value: ''
1630
+ }].concat(_toConsumableArray(balance ? [{
1631
+ item: label(params.locale, 'balance'),
1632
+ value: formatMoney(balance, params.currencySymbol)
1633
+ }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1634
+ });
1635
+ }
1636
+ function collectProductWalletDiscountAssets(order) {
1637
+ var assets = [];
1638
+ var assetsById = new Map();
1639
+ normalizeArray(order.products).forEach(function (rawProduct) {
1640
+ if (!rawProduct || _typeof(rawProduct) !== 'object') return;
1641
+ visitProductWalletDiscounts(restoreReceiptDiscountHierarchy(rawProduct), assets, assetsById);
1642
+ });
1643
+ return assets;
1644
+ }
1645
+ function visitProductWalletDiscounts(product, assets, assetsById) {
1646
+ normalizeArray(product.discount_list).forEach(function (record) {
1647
+ if (!record || _typeof(record) !== 'object' || Array.isArray(record)) return;
1648
+ var type = getProductWalletDiscountType(record);
1649
+ if (!type) return;
1650
+ var id = getProductWalletDiscountAssetId(record);
1651
+ if (!id) return;
1652
+ var codes = getProductWalletDiscountCodes(record);
1653
+ var existing = assetsById.get(id);
1654
+ if (existing) {
1655
+ existing.records.push(record);
1656
+ existing.codes = Array.from(new Set([].concat(_toConsumableArray(existing.codes), codes)));
1657
+ return;
1658
+ }
1659
+ var asset = {
1660
+ id: id,
1661
+ type: type,
1662
+ codes: codes,
1663
+ records: [record]
1664
+ };
1665
+ assetsById.set(id, asset);
1666
+ assets.push(asset);
1667
+ });
1668
+ for (var _i6 = 0, _arr2 = ['combinations', 'product_bundle', 'bundle']; _i6 < _arr2.length; _i6++) {
1669
+ var childKey = _arr2[_i6];
1670
+ normalizeArray(product[childKey]).forEach(function (child) {
1671
+ if (!child || _typeof(child) !== 'object' || Array.isArray(child)) return;
1672
+ visitProductWalletDiscounts(child, assets, assetsById);
1673
+ });
1674
+ }
1675
+ }
1676
+ function getProductWalletDiscountType(record) {
1677
+ for (var _i7 = 0, _arr3 = [record.tag, record.type, (_record$discount = record.discount) === null || _record$discount === void 0 ? void 0 : _record$discount.tag, (_record$discount2 = record.discount) === null || _record$discount2 === void 0 ? void 0 : _record$discount2.type]; _i7 < _arr3.length; _i7++) {
1678
+ var _record$discount, _record$discount2;
1679
+ var value = _arr3[_i7];
1680
+ var type = stringify(value).trim().toLowerCase();
1681
+ if (PRODUCT_WALLET_DISCOUNT_TYPES.has(type)) return type;
1682
+ }
1683
+ return null;
1684
+ }
1685
+ function getProductWalletDiscountAssetId(record) {
1686
+ for (var _i8 = 0, _arr4 = [(_record$discount3 = record.discount) === null || _record$discount3 === void 0 ? void 0 : _record$discount3.resource_id, record.resource_id, record.id, record.discount_id]; _i8 < _arr4.length; _i8++) {
1687
+ var _record$discount3;
1688
+ var value = _arr4[_i8];
1689
+ var id = normalizeWalletPassId(value);
1690
+ if (id && id !== '0') return id;
1691
+ }
1692
+ return null;
1693
+ }
1694
+ function getProductWalletDiscountCodes(record) {
1695
+ var _record$discount4, _record$discount5;
1696
+ return normalizeWalletAssetCodes(record.code, record.encoded, (_record$discount4 = record.discount) === null || _record$discount4 === void 0 ? void 0 : _record$discount4.code, (_record$discount5 = record.discount) === null || _record$discount5 === void 0 ? void 0 : _record$discount5.encoded);
1697
+ }
1698
+ function getProductWalletDiscountName(asset, locale) {
1699
+ var _iterator4 = _createForOfIteratorHelper(asset.records),
1700
+ _step4;
1701
+ try {
1702
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1703
+ var record = _step4.value;
1704
+ for (var _i9 = 0, _arr5 = [(_record$discount6 = record.discount) === null || _record$discount6 === void 0 ? void 0 : _record$discount6.title, (_record$discount7 = record.discount) === null || _record$discount7 === void 0 ? void 0 : _record$discount7.name, (_record$discount8 = record.discount) === null || _record$discount8 === void 0 ? void 0 : _record$discount8.message, record.product_name, record.format_title, record.title, record.name, record.message]; _i9 < _arr5.length; _i9++) {
1705
+ var _record$discount6, _record$discount7, _record$discount8;
1706
+ var value = _arr5[_i9];
1707
+ var name = getLocalizedValue(value, locale).trim();
1708
+ if (name) return name;
1709
+ }
1710
+ }
1711
+ } catch (err) {
1712
+ _iterator4.e(err);
1713
+ } finally {
1714
+ _iterator4.f();
1715
+ }
1716
+ return asset.codes[0] || label(locale, 'giftCard');
1717
+ }
1718
+ function getProductWalletDiscountTime(asset) {
1719
+ for (var _i10 = 0, _arr6 = ['updated_at', 'created_at', 'collection_time']; _i10 < _arr6.length; _i10++) {
1720
+ var field = _arr6[_i10];
1721
+ var _iterator5 = _createForOfIteratorHelper(asset.records),
1722
+ _step5;
1723
+ try {
1724
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1725
+ var _record$discount9;
1726
+ var record = _step5.value;
1727
+ var value = firstPresentValue(record[field], (_record$discount9 = record.discount) === null || _record$discount9 === void 0 ? void 0 : _record$discount9[field]);
1728
+ if (isPresentId(value)) return value;
1729
+ }
1730
+ } catch (err) {
1731
+ _iterator5.e(err);
1732
+ } finally {
1733
+ _iterator5.f();
1734
+ }
1735
+ }
1736
+ return undefined;
1737
+ }
1738
+ function getProductEntitlementBalance(asset) {
1739
+ var _iterator6 = _createForOfIteratorHelper(asset.records),
1740
+ _step6;
1741
+ try {
1742
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1743
+ var record = _step6.value;
1744
+ var balance = getProductDiscountEntitlementBalance(record);
1745
+ if (balance) return balance;
1746
+ }
1747
+ } catch (err) {
1748
+ _iterator6.e(err);
1749
+ } finally {
1750
+ _iterator6.f();
1751
+ }
1752
+ return null;
1753
+ }
1754
+ function getProductDiscountEntitlementBalance(record) {
1755
+ var _record$metadata, _record$discount10, _record$discount11;
1756
+ return getEntitlementBalance((_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.balance, record.balance, (_record$discount10 = record.discount) === null || _record$discount10 === void 0 || (_record$discount10 = _record$discount10.metadata) === null || _record$discount10 === void 0 ? void 0 : _record$discount10.balance, (_record$discount11 = record.discount) === null || _record$discount11 === void 0 ? void 0 : _record$discount11.balance);
1757
+ }
1758
+ function getEntitlementBalance() {
1759
+ for (var _len3 = arguments.length, values = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1760
+ values[_key3] = arguments[_key3];
1761
+ }
1762
+ for (var _i11 = 0, _values2 = values; _i11 < _values2.length; _i11++) {
1763
+ var value = _values2[_i11];
1764
+ if (!isNumericAmount(value)) continue;
1765
+ var balance = new Decimal(value);
1766
+ if (balance.isFinite() && balance.isInteger() && balance.gte(0)) {
1767
+ return balance;
1768
+ }
1769
+ }
1770
+ return null;
1771
+ }
1772
+ function formatEntitlementUses(value, locale) {
1773
+ var count = value.toFixed(0);
1774
+ switch (normalizeLocaleKey(locale)) {
1775
+ case 'zh_CN':
1776
+ case 'zh_HK':
1777
+ return "".concat(count, "\u6B21");
1778
+ case 'ja':
1779
+ return "".concat(count, "\u56DE");
1780
+ case 'pt':
1781
+ return "".concat(count, " ").concat(value.eq(1) ? 'utilização' : 'utilizações');
1782
+ default:
1783
+ return "".concat(count, " ").concat(value.eq(1) ? 'use' : 'uses');
1784
+ }
1785
+ }
1786
+ function getProductWalletDiscountPercent(asset) {
1787
+ if (asset.type !== 'discount_card' && asset.type !== 'product_discount_card') return null;
1788
+ var _iterator7 = _createForOfIteratorHelper(asset.records),
1789
+ _step7;
1790
+ try {
1791
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1792
+ var _record$metadata2, _record$discount12, _record$discount13, _record$discount14;
1793
+ var record = _step7.value;
1794
+ var discountType = stringify(firstPresentValue(record.discount_card_type, (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.discount_card_type, (_record$discount12 = record.discount) === null || _record$discount12 === void 0 ? void 0 : _record$discount12.discount_card_type, (_record$discount13 = record.discount) === null || _record$discount13 === void 0 || (_record$discount13 = _record$discount13.metadata) === null || _record$discount13 === void 0 ? void 0 : _record$discount13.discount_card_type)).trim().toLowerCase();
1795
+ if (discountType && discountType !== 'percent' && discountType !== 'percentage') continue;
1796
+ var candidates = [record.percent, (_record$discount14 = record.discount) === null || _record$discount14 === void 0 ? void 0 : _record$discount14.percent];
1797
+ if (discountType === 'percent' || discountType === 'percentage') {
1798
+ var _record$discount15;
1799
+ candidates.push(record.par_value, (_record$discount15 = record.discount) === null || _record$discount15 === void 0 ? void 0 : _record$discount15.par_value);
1800
+ }
1801
+ for (var _i12 = 0, _candidates = candidates; _i12 < _candidates.length; _i12++) {
1802
+ var value = _candidates[_i12];
1803
+ if (!isNumericAmount(value)) continue;
1804
+ var percent = new Decimal(value);
1805
+ if (percent.isFinite() && percent.gt(0) && percent.lte(100)) {
1806
+ return percent;
1807
+ }
1808
+ }
1809
+ }
1810
+ } catch (err) {
1811
+ _iterator7.e(err);
1812
+ } finally {
1813
+ _iterator7.f();
1814
+ }
1815
+ return null;
1816
+ }
1817
+ function getProductWalletMoneyBalance(asset) {
1818
+ var _iterator8 = _createForOfIteratorHelper(asset.records),
1819
+ _step8;
1820
+ try {
1821
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1822
+ var record = _step8.value;
1823
+ for (var _i13 = 0, _arr7 = [(_record$metadata3 = record.metadata) === null || _record$metadata3 === void 0 ? void 0 : _record$metadata3.balance, record.balance, (_record$discount16 = record.discount) === null || _record$discount16 === void 0 || (_record$discount16 = _record$discount16.metadata) === null || _record$discount16 === void 0 ? void 0 : _record$discount16.balance, (_record$discount17 = record.discount) === null || _record$discount17 === void 0 ? void 0 : _record$discount17.balance]; _i13 < _arr7.length; _i13++) {
1824
+ var _record$metadata3, _record$discount16, _record$discount17;
1825
+ var value = _arr7[_i13];
1826
+ if (!isNumericAmount(value)) continue;
1827
+ return Decimal.max(new Decimal(value), 0);
1828
+ }
1829
+ }
1830
+ } catch (err) {
1831
+ _iterator8.e(err);
1832
+ } finally {
1833
+ _iterator8.f();
1834
+ }
1835
+ var _iterator9 = _createForOfIteratorHelper(asset.records),
1836
+ _step9;
1837
+ try {
1838
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1839
+ var _record$discount18, _record$discount19;
1840
+ var _record = _step9.value;
1841
+ var parValue = firstPresentValue(_record.par_value, (_record$discount18 = _record.discount) === null || _record$discount18 === void 0 ? void 0 : _record$discount18.par_value);
1842
+ var usedParValue = firstPresentValue(_record.used_par_value, (_record$discount19 = _record.discount) === null || _record$discount19 === void 0 ? void 0 : _record$discount19.used_par_value);
1843
+ if (!isNumericAmount(parValue) || !isNumericAmount(usedParValue)) continue;
1844
+ return Decimal.max(new Decimal(parValue).minus(new Decimal(usedParValue)), 0);
1845
+ }
1846
+ } catch (err) {
1847
+ _iterator9.e(err);
1848
+ } finally {
1849
+ _iterator9.f();
1850
+ }
1851
+ return null;
1565
1852
  }
1566
1853
  function buildPointCardSnapshotAssets(params) {
1567
1854
  var _params$order$order_m;
1568
1855
  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;
1569
1856
  if (!Array.isArray(snapshots)) return [];
1570
1857
  var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1571
- var seenSnapshotIds = new Set();
1572
1858
  return snapshots.flatMap(function (snapshot) {
1573
1859
  if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return [];
1574
1860
  var pointCard = snapshot;
1575
1861
  if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
1576
- var id = normalizeWalletPassId(pointCard.id);
1577
- if (!id || seenSnapshotIds.has(id)) return [];
1578
- seenSnapshotIds.add(id);
1579
- if (params.displayedWalletPassIds.has(id)) return [];
1862
+ var assetId = normalizeWalletPassId(pointCard.id);
1863
+ if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1864
+ id: assetId,
1865
+ codes: []
1866
+ })) return [];
1580
1867
  var rows = [{
1581
1868
  item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1582
1869
  value: ''
@@ -1622,8 +1909,8 @@ function collectVirtualCurrencySnapshots(order) {
1622
1909
  }
1623
1910
  function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
1624
1911
  var fundRecord = getFundRecord(payment);
1625
- for (var _i6 = 0, _arr2 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i6 < _arr2.length; _i6++) {
1626
- var value = _arr2[_i6];
1912
+ for (var _i14 = 0, _arr8 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i14 < _arr8.length; _i14++) {
1913
+ var value = _arr8[_i14];
1627
1914
  var id = normalizeWalletPassId(value);
1628
1915
  if (!id) continue;
1629
1916
  var snapshot = snapshotsById.get(id);
@@ -1634,8 +1921,11 @@ function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
1634
1921
  function buildVirtualCurrencySnapshotAssets(params) {
1635
1922
  var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1636
1923
  return params.snapshots.flatMap(function (virtualCurrency) {
1637
- var id = normalizeWalletPassId(virtualCurrency.id);
1638
- if (!id || params.displayedWalletPassIds.has(id)) return [];
1924
+ var assetId = normalizeWalletPassId(virtualCurrency.id);
1925
+ if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1926
+ id: assetId,
1927
+ codes: []
1928
+ })) return [];
1639
1929
  var rows = [{
1640
1930
  item: stringify(virtualCurrency.product_name).trim(),
1641
1931
  value: ''
@@ -1670,8 +1960,8 @@ function getNonEmptyLocalizedValue(value, locale) {
1670
1960
  if (_typeof(value) !== 'object' || Array.isArray(value)) return stringify(value).trim();
1671
1961
  var dashedLocale = locale.replace('_', '-');
1672
1962
  var underscoredLocale = locale.replace('-', '_');
1673
- for (var _i7 = 0, _arr3 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i7 < _arr3.length; _i7++) {
1674
- var candidate = _arr3[_i7];
1963
+ for (var _i15 = 0, _arr9 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i15 < _arr9.length; _i15++) {
1964
+ var candidate = _arr9[_i15];
1675
1965
  var text = stringify(candidate).trim();
1676
1966
  if (text) return text;
1677
1967
  }
@@ -1687,6 +1977,66 @@ function normalizeWalletPassId(value) {
1687
1977
  if (typeof value !== 'string') return null;
1688
1978
  return value.trim() || null;
1689
1979
  }
1980
+ function firstNormalizedWalletAssetId() {
1981
+ for (var _len4 = arguments.length, values = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1982
+ values[_key4] = arguments[_key4];
1983
+ }
1984
+ for (var _i16 = 0, _values3 = values; _i16 < _values3.length; _i16++) {
1985
+ var value = _values3[_i16];
1986
+ var id = normalizeWalletPassId(value);
1987
+ if (id) return id;
1988
+ }
1989
+ return null;
1990
+ }
1991
+ function normalizeWalletAssetCodes() {
1992
+ for (var _len5 = arguments.length, values = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1993
+ values[_key5] = arguments[_key5];
1994
+ }
1995
+ return Array.from(new Set(values.map(function (value) {
1996
+ return normalizeWalletPassId(value);
1997
+ }).filter(function (value) {
1998
+ return !!value;
1999
+ })));
2000
+ }
2001
+ function registerWalletAssetIdentity(identities, candidate) {
2002
+ if (!candidate.id && !candidate.codes.length) return;
2003
+ var existing = identities.find(function (identity) {
2004
+ return isSameWalletAssetIdentity(identity, candidate);
2005
+ });
2006
+ if (existing) {
2007
+ mergeWalletAssetIdentity(existing, candidate);
2008
+ return;
2009
+ }
2010
+ identities.push({
2011
+ id: candidate.id,
2012
+ codes: _toConsumableArray(candidate.codes)
2013
+ });
2014
+ }
2015
+ function claimWalletAssetIdentity(identities, candidate) {
2016
+ if (!candidate.id && !candidate.codes.length) return true;
2017
+ var existing = identities.find(function (identity) {
2018
+ return isSameWalletAssetIdentity(identity, candidate);
2019
+ });
2020
+ if (existing) {
2021
+ mergeWalletAssetIdentity(existing, candidate);
2022
+ return false;
2023
+ }
2024
+ identities.push({
2025
+ id: candidate.id,
2026
+ codes: _toConsumableArray(candidate.codes)
2027
+ });
2028
+ return true;
2029
+ }
2030
+ function isSameWalletAssetIdentity(left, right) {
2031
+ if (left.id && right.id) return left.id === right.id;
2032
+ return left.codes.some(function (code) {
2033
+ return right.codes.includes(code);
2034
+ });
2035
+ }
2036
+ function mergeWalletAssetIdentity(target, source) {
2037
+ if (!target.id && source.id) target.id = source.id;
2038
+ target.codes = Array.from(new Set([].concat(_toConsumableArray(target.codes), _toConsumableArray(source.codes))));
2039
+ }
1690
2040
  function getPointCardSnapshotRemainingPoints(snapshot) {
1691
2041
  if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
1692
2042
  return null;
@@ -1694,19 +2044,27 @@ function getPointCardSnapshotRemainingPoints(snapshot) {
1694
2044
  return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
1695
2045
  }
1696
2046
  function buildVoucherAssets(params) {
1697
- var seenVoucherKeys = new Set();
1698
2047
  var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1699
- return normalizeArray(params.order.vouchers).flatMap(function (voucher, index) {
2048
+ return normalizeArray(params.order.vouchers).flatMap(function (voucher) {
1700
2049
  if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
1701
- var voucherKey = getVoucherAssetKey(voucher, index);
1702
- if (seenVoucherKeys.has(voucherKey)) return [];
1703
- seenVoucherKeys.add(voucherKey);
2050
+ if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, getVoucherAssetIdentity(voucher))) return [];
1704
2051
  var name = getVoucherAssetName(voucher, params.locale);
1705
2052
  var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
1706
2053
  var timeRow = isPresentId(assetTime) ? {
1707
2054
  item: formatDateTime(assetTime, params.locale),
1708
2055
  value: ''
1709
2056
  } : null;
2057
+ if (isEntitlementVoucher(voucher)) {
2058
+ var _voucher$metadata;
2059
+ var remaining = getEntitlementBalance((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.balance, voucher.balance);
2060
+ return [[{
2061
+ item: name,
2062
+ value: ''
2063
+ }].concat(_toConsumableArray(remaining ? [{
2064
+ item: label(params.locale, 'entitlementRemaining'),
2065
+ value: formatEntitlementUses(remaining, params.locale)
2066
+ }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
2067
+ }
1710
2068
  if (isTicketVoucher(voucher)) {
1711
2069
  var validity = getVoucherValidity(voucher, params.locale);
1712
2070
  return [[{
@@ -1735,19 +2093,24 @@ function buildVoucherAssets(params) {
1735
2093
  });
1736
2094
  }
1737
2095
  var TICKET_VOUCHER_TAGS = new Set(['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket']);
2096
+ function isEntitlementVoucher(voucher) {
2097
+ return [voucher.tag, voucher.type].some(function (value) {
2098
+ return stringify(value).trim().toLowerCase() === 'entitlement_pass';
2099
+ });
2100
+ }
1738
2101
  function isTicketVoucher(voucher) {
1739
2102
  return TICKET_VOUCHER_TAGS.has(stringify(voucher.tag).trim().toLowerCase());
1740
2103
  }
1741
2104
  function getVoucherValidity(voucher, locale) {
1742
- 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;
1743
- 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);
2105
+ var _voucher$metadata2, _voucher$metadata3, _voucher$metadata4, _voucher$metadata5, _voucher$metadata6, _voucher$metadata7, _voucher$metadata8, _voucher$metadata9, _voucher$metadata10, _voucher$metadata11, _voucher$start_time, _voucher$metadata12, _voucher$end_time, _voucher$metadata13;
2106
+ var availableTime = firstPresentValue(voucher.available_time, voucher.avaliable_time, (_voucher$metadata2 = voucher.metadata) === null || _voucher$metadata2 === void 0 ? void 0 : _voucher$metadata2.available_time, (_voucher$metadata3 = voucher.metadata) === null || _voucher$metadata3 === void 0 ? void 0 : _voucher$metadata3.avaliable_time);
1744
2107
  var availableTimeText = formatVoucherAvailableTime(availableTime, locale);
1745
2108
  if (availableTimeText) return availableTimeText;
1746
- 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);
1747
- 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);
2109
+ var startDate = firstPresentValue(voucher.valid_from, voucher.start_at, voucher.start_date_time, voucher.start_date, (_voucher$metadata4 = voucher.metadata) === null || _voucher$metadata4 === void 0 ? void 0 : _voucher$metadata4.valid_from, (_voucher$metadata5 = voucher.metadata) === null || _voucher$metadata5 === void 0 ? void 0 : _voucher$metadata5.start_at, (_voucher$metadata6 = voucher.metadata) === null || _voucher$metadata6 === void 0 ? void 0 : _voucher$metadata6.start_date);
2110
+ var endDate = firstPresentValue(voucher.valid_to, voucher.end_at, voucher.end_date_time, voucher.expire_date, voucher.end_date, voucher.expire_time, (_voucher$metadata7 = voucher.metadata) === null || _voucher$metadata7 === void 0 ? void 0 : _voucher$metadata7.valid_to, (_voucher$metadata8 = voucher.metadata) === null || _voucher$metadata8 === void 0 ? void 0 : _voucher$metadata8.end_at, (_voucher$metadata9 = voucher.metadata) === null || _voucher$metadata9 === void 0 ? void 0 : _voucher$metadata9.expire_date, (_voucher$metadata10 = voucher.metadata) === null || _voucher$metadata10 === void 0 ? void 0 : _voucher$metadata10.end_date, (_voucher$metadata11 = voucher.metadata) === null || _voucher$metadata11 === void 0 ? void 0 : _voucher$metadata11.expire_time);
1748
2111
  return formatVoucherValidityRange(startDate, endDate, locale, {
1749
- 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,
1750
- 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
2112
+ startTime: (_voucher$start_time = voucher.start_time) !== null && _voucher$start_time !== void 0 ? _voucher$start_time : (_voucher$metadata12 = voucher.metadata) === null || _voucher$metadata12 === void 0 ? void 0 : _voucher$metadata12.start_time,
2113
+ endTime: (_voucher$end_time = voucher.end_time) !== null && _voucher$end_time !== void 0 ? _voucher$end_time : (_voucher$metadata13 = voucher.metadata) === null || _voucher$metadata13 === void 0 ? void 0 : _voucher$metadata13.end_time
1751
2114
  });
1752
2115
  }
1753
2116
  function formatVoucherAvailableTime(value, locale) {
@@ -1813,16 +2176,18 @@ function formatVoucherValidityDate(value, locale) {
1813
2176
  text: time ? "".concat(time, " ").concat(date) : date
1814
2177
  };
1815
2178
  }
1816
- function getVoucherAssetKey(voucher, index) {
1817
- var identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
1818
- return identity === undefined ? "voucher-index:".concat(index) : "voucher:".concat(String(identity));
2179
+ function getVoucherAssetIdentity(voucher) {
2180
+ return {
2181
+ id: firstNormalizedWalletAssetId(voucher.voucher_id, voucher.id),
2182
+ codes: normalizeWalletAssetCodes(voucher.code, voucher.encoded)
2183
+ };
1819
2184
  }
1820
2185
  function getVoucherAssetName(voucher, locale) {
1821
2186
  return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
1822
2187
  }
1823
2188
  function getVoucherDiscountPercent(voucher) {
1824
- var _voucher$metadata13;
1825
- var discountType = stringify(((_voucher$metadata13 = voucher.metadata) === null || _voucher$metadata13 === void 0 ? void 0 : _voucher$metadata13.discount_card_type) || voucher.discount_card_type).toLowerCase();
2189
+ var _voucher$metadata14;
2190
+ var discountType = stringify(((_voucher$metadata14 = voucher.metadata) === null || _voucher$metadata14 === void 0 ? void 0 : _voucher$metadata14.discount_card_type) || voucher.discount_card_type).toLowerCase();
1826
2191
  if (discountType !== 'percent' && discountType !== 'percentage') return null;
1827
2192
  var percent = new Decimal(toMoneyNumber(voucher.par_value));
1828
2193
  if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
@@ -1842,6 +2207,12 @@ function formatVoucherDiscount(percent, locale) {
1842
2207
  return normalizedLocale === 'en' ? "Discount ".concat(trimDecimal(percent), "% OFF") : "".concat(trimDecimal(percent), "% OFF");
1843
2208
  }
1844
2209
  function getVoucherBalance(voucher) {
2210
+ for (var _i17 = 0, _arr10 = [(_voucher$metadata15 = voucher.metadata) === null || _voucher$metadata15 === void 0 ? void 0 : _voucher$metadata15.balance, voucher.balance]; _i17 < _arr10.length; _i17++) {
2211
+ var _voucher$metadata15;
2212
+ var value = _arr10[_i17];
2213
+ if (!isNumericAmount(value)) continue;
2214
+ return Decimal.max(new Decimal(value), 0);
2215
+ }
1845
2216
  var parValue = new Decimal(toMoneyNumber(voucher.par_value));
1846
2217
  var usedParValue = new Decimal(toMoneyNumber(voucher.used_par_value));
1847
2218
  return Decimal.max(parValue.minus(usedParValue), 0);
@@ -31,6 +31,9 @@ export interface SmallTicketItem {
31
31
  product_uid?: string | number;
32
32
  booking_uid?: string | number;
33
33
  }
34
+ export type SmallTicketDeliveryItem = Omit<SmallTicketItem, 'value'> & {
35
+ value?: string;
36
+ };
34
37
  export interface SmallTicketProduct {
35
38
  product_title: string;
36
39
  product_quantity: number;
@@ -66,7 +69,7 @@ export interface SmallTicketLocaleData {
66
69
  };
67
70
  customer: SmallTicketItem[];
68
71
  appointment: SmallTicketAppointment;
69
- delivery?: SmallTicketItem[];
72
+ delivery?: SmallTicketDeliveryItem[];
70
73
  resources: Array<{
71
74
  id: string | number;
72
75
  code: string;
@@ -49,6 +49,7 @@ const LABELS = {
49
49
  remainingAmount: 'Remaining amount',
50
50
  redeemPoints: 'Redeem points',
51
51
  remainingPoints: 'Points balance',
52
+ entitlementRemaining: 'Remaining',
52
53
  table: 'Table',
53
54
  bookingId: 'Booking ID',
54
55
  bookingDateTime: 'Date & time',
@@ -93,6 +94,7 @@ const LABELS = {
93
94
  remainingAmount: '剩余金额',
94
95
  redeemPoints: '本次使用积分',
95
96
  remainingPoints: '积分余额',
97
+ entitlementRemaining: '剩余次数',
96
98
  table: '桌台',
97
99
  bookingId: '预约编号',
98
100
  bookingDateTime: '日期和时间',
@@ -137,6 +139,7 @@ const LABELS = {
137
139
  remainingAmount: '剩餘金額',
138
140
  redeemPoints: '本次使用積分',
139
141
  remainingPoints: '積分餘額',
142
+ entitlementRemaining: '剩餘次數',
140
143
  table: '桌台',
141
144
  bookingId: '預約編號',
142
145
  bookingDateTime: '日期和時間',
@@ -179,6 +182,7 @@ const LABELS = {
179
182
  remainingAmount: '残高',
180
183
  redeemPoints: '利用ポイント',
181
184
  remainingPoints: 'ポイント残高',
185
+ entitlementRemaining: '残り回数',
182
186
  table: 'テーブル',
183
187
  bookingId: '予約ID',
184
188
  bookingDateTime: '日時',
@@ -222,6 +226,7 @@ const LABELS = {
222
226
  remainingAmount: 'Saldo restante',
223
227
  redeemPoints: 'Pontos utilizados',
224
228
  remainingPoints: 'Saldo de pontos',
229
+ entitlementRemaining: 'Utilizações restantes',
225
230
  table: 'Mesa',
226
231
  bookingId: 'ID da reserva',
227
232
  bookingDateTime: 'Data e hora',
@@ -522,7 +527,8 @@ function normalizeProductDiscounts(params) {
522
527
  const title = resolveDiscountTitleWithPercent(discount, locale);
523
528
  const amount = discount.amount ?? discount.value ?? discount.discount_amount;
524
529
  const isMarkup = isManualMarkup(discount);
525
- const totalAmount = new _decimal.default(toMoneyNumber(amount)).mul(quantity);
530
+ const isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
531
+ const totalAmount = new _decimal.default(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount ? 1 : quantity);
526
532
  const formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
527
533
  return {
528
534
  item: title,
@@ -615,6 +621,9 @@ function buildProductQuantityPriceText(params) {
615
621
  }
616
622
  function resolveDiscountTitleWithPercent(discount, locale) {
617
623
  const title = resolveDiscountTitle(discount, locale);
624
+ if (getProductWalletDiscountType(discount) === 'entitlement_pass') {
625
+ return title;
626
+ }
618
627
  const percentRaw = discount.discount?.percent;
619
628
  const cardType = discount.discount?.discount_card_type ?? 'percent';
620
629
  const percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
@@ -1168,10 +1177,8 @@ function buildDelivery(order, locale) {
1168
1177
  const serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType);
1169
1178
  if (!serviceTypeLabelKey) return [];
1170
1179
  const items = [{
1171
- item: '',
1172
- value: label(locale, serviceTypeLabelKey),
1173
- size: 2,
1174
- align: 'left'
1180
+ item: label(locale, serviceTypeLabelKey),
1181
+ size: 2
1175
1182
  }];
1176
1183
  const handoverTime = firstPresentValue(order.handover_time, order.handover_at, order.pickup_time, order.pickup_at, order.scheduled_pickup_time, order.delivery_time, order.delivery_at, order.scheduled_delivery_time, order.fulfillment_time, order.fulfillment_at, order.metadata?.handover_time, order.metadata?.handover_at, order.metadata?.pickup_time, order.metadata?.pickup_at, order.metadata?.scheduled_pickup_time, order.metadata?.delivery_time, order.metadata?.delivery_at, order.metadata?.scheduled_delivery_time, order.metadata?.fulfillment_time, order.metadata?.fulfillment_at);
1177
1184
  if (isPresentId(handoverTime)) {
@@ -1427,42 +1434,244 @@ function buildWallets(params) {
1427
1434
  virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
1428
1435
  });
1429
1436
  });
1430
- const displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
1431
- return [...paymentWallets, ...buildVoucherAssets(params), ...buildPointCardSnapshotAssets({
1437
+ const displayedWalletAssetIdentities = collectDisplayedWalletAssetIdentities(displayedWalletPayments);
1438
+ const voucherWallets = buildVoucherAssets({
1439
+ ...params,
1440
+ displayedWalletAssetIdentities
1441
+ });
1442
+ const productDiscountWallets = buildProductDiscountAssets({
1443
+ ...params,
1444
+ displayedWalletAssetIdentities
1445
+ });
1446
+ return [...paymentWallets, ...voucherWallets, ...productDiscountWallets, ...buildPointCardSnapshotAssets({
1432
1447
  order: params.order,
1433
1448
  locale: params.locale,
1434
- displayedWalletPassIds
1449
+ displayedWalletAssetIdentities
1435
1450
  }), ...buildVirtualCurrencySnapshotAssets({
1436
1451
  snapshots: virtualCurrencySnapshots.items,
1437
1452
  order: params.order,
1438
1453
  locale: params.locale,
1439
- displayedWalletPassIds
1454
+ displayedWalletAssetIdentities
1440
1455
  })];
1441
1456
  }
1442
- function collectDisplayedWalletPassIds(payments) {
1443
- const ids = new Set();
1457
+ function collectDisplayedWalletAssetIdentities(payments) {
1458
+ const identities = [];
1444
1459
  payments.forEach(payment => {
1445
1460
  const fundRecord = getFundRecord(payment);
1446
- [payment.voucher_id, fundRecord?.voucher_id].forEach(value => {
1447
- const id = normalizeWalletPassId(value);
1448
- if (id) ids.add(id);
1461
+ const ids = Array.from(new Set([fundRecord?.voucher_id, payment.voucher_id].map(value => normalizeWalletPassId(value)).filter(value => !!value)));
1462
+ const codes = normalizeWalletAssetCodes(fundRecord?.code, fundRecord?.encoded);
1463
+ if (!ids.length) {
1464
+ registerWalletAssetIdentity(identities, {
1465
+ id: null,
1466
+ codes
1467
+ });
1468
+ return;
1469
+ }
1470
+ ids.forEach(id => {
1471
+ registerWalletAssetIdentity(identities, {
1472
+ id,
1473
+ codes
1474
+ });
1449
1475
  });
1450
1476
  });
1451
- return ids;
1477
+ return identities;
1478
+ }
1479
+ const PRODUCT_WALLET_DISCOUNT_TYPES = new Set(['good_pass', 'discount_card', 'product_discount_card', 'entitlement_pass']);
1480
+ function buildProductDiscountAssets(params) {
1481
+ const fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1482
+ return collectProductWalletDiscountAssets(params.order).flatMap(asset => {
1483
+ if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1484
+ id: asset.id,
1485
+ codes: asset.codes
1486
+ })) return [];
1487
+ const name = getProductWalletDiscountName(asset, params.locale);
1488
+ const assetTime = getProductWalletDiscountTime(asset) ?? fallbackAssetTime;
1489
+ const timeRow = isPresentId(assetTime) ? {
1490
+ item: formatDateTime(assetTime, params.locale),
1491
+ value: ''
1492
+ } : null;
1493
+ if (asset.type === 'entitlement_pass') {
1494
+ const remaining = getProductEntitlementBalance(asset);
1495
+ return [[{
1496
+ item: name,
1497
+ value: ''
1498
+ }, ...(remaining ? [{
1499
+ item: label(params.locale, 'entitlementRemaining'),
1500
+ value: formatEntitlementUses(remaining, params.locale)
1501
+ }] : []), ...(timeRow ? [timeRow] : [])]];
1502
+ }
1503
+ const percent = getProductWalletDiscountPercent(asset);
1504
+ if (percent) {
1505
+ return [[{
1506
+ item: appendPercentToVoucherName(name, percent),
1507
+ value: formatVoucherDiscount(percent, params.locale)
1508
+ }, ...(timeRow ? [timeRow] : [])]];
1509
+ }
1510
+ const balance = getProductWalletMoneyBalance(asset);
1511
+ return [[{
1512
+ item: name,
1513
+ value: ''
1514
+ }, ...(balance ? [{
1515
+ item: label(params.locale, 'balance'),
1516
+ value: formatMoney(balance, params.currencySymbol)
1517
+ }] : []), ...(timeRow ? [timeRow] : [])]];
1518
+ });
1519
+ }
1520
+ function collectProductWalletDiscountAssets(order) {
1521
+ const assets = [];
1522
+ const assetsById = new Map();
1523
+ normalizeArray(order.products).forEach(rawProduct => {
1524
+ if (!rawProduct || typeof rawProduct !== 'object') return;
1525
+ visitProductWalletDiscounts(restoreReceiptDiscountHierarchy(rawProduct), assets, assetsById);
1526
+ });
1527
+ return assets;
1528
+ }
1529
+ function visitProductWalletDiscounts(product, assets, assetsById) {
1530
+ normalizeArray(product.discount_list).forEach(record => {
1531
+ if (!record || typeof record !== 'object' || Array.isArray(record)) return;
1532
+ const type = getProductWalletDiscountType(record);
1533
+ if (!type) return;
1534
+ const id = getProductWalletDiscountAssetId(record);
1535
+ if (!id) return;
1536
+ const codes = getProductWalletDiscountCodes(record);
1537
+ const existing = assetsById.get(id);
1538
+ if (existing) {
1539
+ existing.records.push(record);
1540
+ existing.codes = Array.from(new Set([...existing.codes, ...codes]));
1541
+ return;
1542
+ }
1543
+ const asset = {
1544
+ id,
1545
+ type,
1546
+ codes,
1547
+ records: [record]
1548
+ };
1549
+ assetsById.set(id, asset);
1550
+ assets.push(asset);
1551
+ });
1552
+ for (const childKey of ['combinations', 'product_bundle', 'bundle']) {
1553
+ normalizeArray(product[childKey]).forEach(child => {
1554
+ if (!child || typeof child !== 'object' || Array.isArray(child)) return;
1555
+ visitProductWalletDiscounts(child, assets, assetsById);
1556
+ });
1557
+ }
1558
+ }
1559
+ function getProductWalletDiscountType(record) {
1560
+ for (const value of [record.tag, record.type, record.discount?.tag, record.discount?.type]) {
1561
+ const type = stringify(value).trim().toLowerCase();
1562
+ if (PRODUCT_WALLET_DISCOUNT_TYPES.has(type)) return type;
1563
+ }
1564
+ return null;
1565
+ }
1566
+ function getProductWalletDiscountAssetId(record) {
1567
+ for (const value of [record.discount?.resource_id, record.resource_id, record.id, record.discount_id]) {
1568
+ const id = normalizeWalletPassId(value);
1569
+ if (id && id !== '0') return id;
1570
+ }
1571
+ return null;
1572
+ }
1573
+ function getProductWalletDiscountCodes(record) {
1574
+ return normalizeWalletAssetCodes(record.code, record.encoded, record.discount?.code, record.discount?.encoded);
1575
+ }
1576
+ function getProductWalletDiscountName(asset, locale) {
1577
+ for (const record of asset.records) {
1578
+ for (const value of [record.discount?.title, record.discount?.name, record.discount?.message, record.product_name, record.format_title, record.title, record.name, record.message]) {
1579
+ const name = getLocalizedValue(value, locale).trim();
1580
+ if (name) return name;
1581
+ }
1582
+ }
1583
+ return asset.codes[0] || label(locale, 'giftCard');
1584
+ }
1585
+ function getProductWalletDiscountTime(asset) {
1586
+ for (const field of ['updated_at', 'created_at', 'collection_time']) {
1587
+ for (const record of asset.records) {
1588
+ const value = firstPresentValue(record[field], record.discount?.[field]);
1589
+ if (isPresentId(value)) return value;
1590
+ }
1591
+ }
1592
+ return undefined;
1593
+ }
1594
+ function getProductEntitlementBalance(asset) {
1595
+ for (const record of asset.records) {
1596
+ const balance = getProductDiscountEntitlementBalance(record);
1597
+ if (balance) return balance;
1598
+ }
1599
+ return null;
1600
+ }
1601
+ function getProductDiscountEntitlementBalance(record) {
1602
+ return getEntitlementBalance(record.metadata?.balance, record.balance, record.discount?.metadata?.balance, record.discount?.balance);
1603
+ }
1604
+ function getEntitlementBalance(...values) {
1605
+ for (const value of values) {
1606
+ if (!isNumericAmount(value)) continue;
1607
+ const balance = new _decimal.default(value);
1608
+ if (balance.isFinite() && balance.isInteger() && balance.gte(0)) {
1609
+ return balance;
1610
+ }
1611
+ }
1612
+ return null;
1613
+ }
1614
+ function formatEntitlementUses(value, locale) {
1615
+ const count = value.toFixed(0);
1616
+ switch (normalizeLocaleKey(locale)) {
1617
+ case 'zh_CN':
1618
+ case 'zh_HK':
1619
+ return `${count}次`;
1620
+ case 'ja':
1621
+ return `${count}回`;
1622
+ case 'pt':
1623
+ return `${count} ${value.eq(1) ? 'utilização' : 'utilizações'}`;
1624
+ default:
1625
+ return `${count} ${value.eq(1) ? 'use' : 'uses'}`;
1626
+ }
1627
+ }
1628
+ function getProductWalletDiscountPercent(asset) {
1629
+ if (asset.type !== 'discount_card' && asset.type !== 'product_discount_card') return null;
1630
+ for (const record of asset.records) {
1631
+ const discountType = stringify(firstPresentValue(record.discount_card_type, record.metadata?.discount_card_type, record.discount?.discount_card_type, record.discount?.metadata?.discount_card_type)).trim().toLowerCase();
1632
+ if (discountType && discountType !== 'percent' && discountType !== 'percentage') continue;
1633
+ const candidates = [record.percent, record.discount?.percent];
1634
+ if (discountType === 'percent' || discountType === 'percentage') {
1635
+ candidates.push(record.par_value, record.discount?.par_value);
1636
+ }
1637
+ for (const value of candidates) {
1638
+ if (!isNumericAmount(value)) continue;
1639
+ const percent = new _decimal.default(value);
1640
+ if (percent.isFinite() && percent.gt(0) && percent.lte(100)) {
1641
+ return percent;
1642
+ }
1643
+ }
1644
+ }
1645
+ return null;
1646
+ }
1647
+ function getProductWalletMoneyBalance(asset) {
1648
+ for (const record of asset.records) {
1649
+ for (const value of [record.metadata?.balance, record.balance, record.discount?.metadata?.balance, record.discount?.balance]) {
1650
+ if (!isNumericAmount(value)) continue;
1651
+ return _decimal.default.max(new _decimal.default(value), 0);
1652
+ }
1653
+ }
1654
+ for (const record of asset.records) {
1655
+ const parValue = firstPresentValue(record.par_value, record.discount?.par_value);
1656
+ const usedParValue = firstPresentValue(record.used_par_value, record.discount?.used_par_value);
1657
+ if (!isNumericAmount(parValue) || !isNumericAmount(usedParValue)) continue;
1658
+ return _decimal.default.max(new _decimal.default(parValue).minus(new _decimal.default(usedParValue)), 0);
1659
+ }
1660
+ return null;
1452
1661
  }
1453
1662
  function buildPointCardSnapshotAssets(params) {
1454
1663
  const snapshots = params.order.order_meta_list?.point_cards_snapshot;
1455
1664
  if (!Array.isArray(snapshots)) return [];
1456
1665
  const snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1457
- const seenSnapshotIds = new Set();
1458
1666
  return snapshots.flatMap(snapshot => {
1459
1667
  if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) return [];
1460
1668
  const pointCard = snapshot;
1461
1669
  if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
1462
- const id = normalizeWalletPassId(pointCard.id);
1463
- if (!id || seenSnapshotIds.has(id)) return [];
1464
- seenSnapshotIds.add(id);
1465
- if (params.displayedWalletPassIds.has(id)) return [];
1670
+ const assetId = normalizeWalletPassId(pointCard.id);
1671
+ if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1672
+ id: assetId,
1673
+ codes: []
1674
+ })) return [];
1466
1675
  const rows = [{
1467
1676
  item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1468
1677
  value: ''
@@ -1518,8 +1727,11 @@ function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
1518
1727
  function buildVirtualCurrencySnapshotAssets(params) {
1519
1728
  const snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1520
1729
  return params.snapshots.flatMap(virtualCurrency => {
1521
- const id = normalizeWalletPassId(virtualCurrency.id);
1522
- if (!id || params.displayedWalletPassIds.has(id)) return [];
1730
+ const assetId = normalizeWalletPassId(virtualCurrency.id);
1731
+ if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1732
+ id: assetId,
1733
+ codes: []
1734
+ })) return [];
1523
1735
  const rows = [{
1524
1736
  item: stringify(virtualCurrency.product_name).trim(),
1525
1737
  value: ''
@@ -1570,6 +1782,49 @@ function normalizeWalletPassId(value) {
1570
1782
  if (typeof value !== 'string') return null;
1571
1783
  return value.trim() || null;
1572
1784
  }
1785
+ function firstNormalizedWalletAssetId(...values) {
1786
+ for (const value of values) {
1787
+ const id = normalizeWalletPassId(value);
1788
+ if (id) return id;
1789
+ }
1790
+ return null;
1791
+ }
1792
+ function normalizeWalletAssetCodes(...values) {
1793
+ return Array.from(new Set(values.map(value => normalizeWalletPassId(value)).filter(value => !!value)));
1794
+ }
1795
+ function registerWalletAssetIdentity(identities, candidate) {
1796
+ if (!candidate.id && !candidate.codes.length) return;
1797
+ const existing = identities.find(identity => isSameWalletAssetIdentity(identity, candidate));
1798
+ if (existing) {
1799
+ mergeWalletAssetIdentity(existing, candidate);
1800
+ return;
1801
+ }
1802
+ identities.push({
1803
+ id: candidate.id,
1804
+ codes: [...candidate.codes]
1805
+ });
1806
+ }
1807
+ function claimWalletAssetIdentity(identities, candidate) {
1808
+ if (!candidate.id && !candidate.codes.length) return true;
1809
+ const existing = identities.find(identity => isSameWalletAssetIdentity(identity, candidate));
1810
+ if (existing) {
1811
+ mergeWalletAssetIdentity(existing, candidate);
1812
+ return false;
1813
+ }
1814
+ identities.push({
1815
+ id: candidate.id,
1816
+ codes: [...candidate.codes]
1817
+ });
1818
+ return true;
1819
+ }
1820
+ function isSameWalletAssetIdentity(left, right) {
1821
+ if (left.id && right.id) return left.id === right.id;
1822
+ return left.codes.some(code => right.codes.includes(code));
1823
+ }
1824
+ function mergeWalletAssetIdentity(target, source) {
1825
+ if (!target.id && source.id) target.id = source.id;
1826
+ target.codes = Array.from(new Set([...target.codes, ...source.codes]));
1827
+ }
1573
1828
  function getPointCardSnapshotRemainingPoints(snapshot) {
1574
1829
  if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
1575
1830
  return null;
@@ -1577,19 +1832,26 @@ function getPointCardSnapshotRemainingPoints(snapshot) {
1577
1832
  return _decimal.default.max(new _decimal.default(snapshot.par_value).minus(new _decimal.default(snapshot.used_par_value)), 0);
1578
1833
  }
1579
1834
  function buildVoucherAssets(params) {
1580
- const seenVoucherKeys = new Set();
1581
1835
  const fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1582
- return normalizeArray(params.order.vouchers).flatMap((voucher, index) => {
1836
+ return normalizeArray(params.order.vouchers).flatMap(voucher => {
1583
1837
  if (!voucher || typeof voucher !== 'object' || Array.isArray(voucher)) return [];
1584
- const voucherKey = getVoucherAssetKey(voucher, index);
1585
- if (seenVoucherKeys.has(voucherKey)) return [];
1586
- seenVoucherKeys.add(voucherKey);
1838
+ if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, getVoucherAssetIdentity(voucher))) return [];
1587
1839
  const name = getVoucherAssetName(voucher, params.locale);
1588
1840
  const assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
1589
1841
  const timeRow = isPresentId(assetTime) ? {
1590
1842
  item: formatDateTime(assetTime, params.locale),
1591
1843
  value: ''
1592
1844
  } : null;
1845
+ if (isEntitlementVoucher(voucher)) {
1846
+ const remaining = getEntitlementBalance(voucher.metadata?.balance, voucher.balance);
1847
+ return [[{
1848
+ item: name,
1849
+ value: ''
1850
+ }, ...(remaining ? [{
1851
+ item: label(params.locale, 'entitlementRemaining'),
1852
+ value: formatEntitlementUses(remaining, params.locale)
1853
+ }] : []), ...(timeRow ? [timeRow] : [])]];
1854
+ }
1593
1855
  if (isTicketVoucher(voucher)) {
1594
1856
  const validity = getVoucherValidity(voucher, params.locale);
1595
1857
  return [[{
@@ -1618,6 +1880,9 @@ function buildVoucherAssets(params) {
1618
1880
  });
1619
1881
  }
1620
1882
  const TICKET_VOUCHER_TAGS = new Set(['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket']);
1883
+ function isEntitlementVoucher(voucher) {
1884
+ return [voucher.tag, voucher.type].some(value => stringify(value).trim().toLowerCase() === 'entitlement_pass');
1885
+ }
1621
1886
  function isTicketVoucher(voucher) {
1622
1887
  return TICKET_VOUCHER_TAGS.has(stringify(voucher.tag).trim().toLowerCase());
1623
1888
  }
@@ -1692,9 +1957,11 @@ function formatVoucherValidityDate(value, locale) {
1692
1957
  text: time ? `${time} ${date}` : date
1693
1958
  };
1694
1959
  }
1695
- function getVoucherAssetKey(voucher, index) {
1696
- const identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
1697
- return identity === undefined ? `voucher-index:${index}` : `voucher:${String(identity)}`;
1960
+ function getVoucherAssetIdentity(voucher) {
1961
+ return {
1962
+ id: firstNormalizedWalletAssetId(voucher.voucher_id, voucher.id),
1963
+ codes: normalizeWalletAssetCodes(voucher.code, voucher.encoded)
1964
+ };
1698
1965
  }
1699
1966
  function getVoucherAssetName(voucher, locale) {
1700
1967
  return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
@@ -1720,6 +1987,10 @@ function formatVoucherDiscount(percent, locale) {
1720
1987
  return normalizedLocale === 'en' ? `Discount ${trimDecimal(percent)}% OFF` : `${trimDecimal(percent)}% OFF`;
1721
1988
  }
1722
1989
  function getVoucherBalance(voucher) {
1990
+ for (const value of [voucher.metadata?.balance, voucher.balance]) {
1991
+ if (!isNumericAmount(value)) continue;
1992
+ return _decimal.default.max(new _decimal.default(value), 0);
1993
+ }
1723
1994
  const parValue = new _decimal.default(toMoneyNumber(voucher.par_value));
1724
1995
  const usedParValue = new _decimal.default(toMoneyNumber(voucher.used_par_value));
1725
1996
  return _decimal.default.max(parValue.minus(usedParValue), 0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.117",
4
+ "version": "2.3.119",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",