@pisell/pisellos 2.3.114 → 2.3.115

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.
@@ -1489,17 +1489,20 @@ function resolveRefundPayment(refund, payments) {
1489
1489
  return matchedPayment || refund;
1490
1490
  }
1491
1491
  function buildWallets(params) {
1492
+ var virtualCurrencySnapshots = collectVirtualCurrencySnapshots(params.order);
1492
1493
  var displayedWalletPayments = normalizeArray(params.order.payments).filter(function (payment) {
1493
1494
  return isPrintablePayment(payment) && !!getFundRecord(payment);
1494
1495
  });
1495
1496
  var paymentWallets = displayedWalletPayments.map(function (payment) {
1497
+ var virtualCurrencySnapshot = findVirtualCurrencySnapshotForPayment(payment, virtualCurrencySnapshots.byId);
1496
1498
  return buildPaymentItems({
1497
1499
  payment: payment,
1498
1500
  locale: params.locale,
1499
1501
  currencySymbol: params.currencySymbol,
1500
1502
  includeFundRecordBalance: true,
1501
1503
  includeFundRecordUsage: false,
1502
- includePaymentAmount: false
1504
+ includePaymentAmount: false,
1505
+ virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
1503
1506
  });
1504
1507
  });
1505
1508
  var displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
@@ -1507,6 +1510,11 @@ function buildWallets(params) {
1507
1510
  order: params.order,
1508
1511
  locale: params.locale,
1509
1512
  displayedWalletPassIds: displayedWalletPassIds
1513
+ })), _toConsumableArray(buildVirtualCurrencySnapshotAssets({
1514
+ snapshots: virtualCurrencySnapshots.items,
1515
+ order: params.order,
1516
+ locale: params.locale,
1517
+ displayedWalletPassIds: displayedWalletPassIds
1510
1518
  })));
1511
1519
  }
1512
1520
  function collectDisplayedWalletPassIds(payments) {
@@ -1554,6 +1562,91 @@ function buildPointCardSnapshotAssets(params) {
1554
1562
  return [rows];
1555
1563
  });
1556
1564
  }
1565
+ function collectVirtualCurrencySnapshots(order) {
1566
+ var _order$order_meta_lis;
1567
+ var items = [];
1568
+ var byId = new Map();
1569
+ var snapshots = (_order$order_meta_lis = order.order_meta_list) === null || _order$order_meta_lis === void 0 ? void 0 : _order$order_meta_lis.virtual_currency_snapshot;
1570
+ if (!Array.isArray(snapshots)) return {
1571
+ items: items,
1572
+ byId: byId
1573
+ };
1574
+ snapshots.forEach(function (snapshot) {
1575
+ if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return;
1576
+ var virtualCurrency = snapshot;
1577
+ if (stringify(virtualCurrency.tag).trim().toLowerCase() !== 'virtual_currency') return;
1578
+ var id = normalizeWalletPassId(virtualCurrency.id);
1579
+ if (!id || byId.has(id)) return;
1580
+ byId.set(id, virtualCurrency);
1581
+ items.push(virtualCurrency);
1582
+ });
1583
+ return {
1584
+ items: items,
1585
+ byId: byId
1586
+ };
1587
+ }
1588
+ function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
1589
+ var fundRecord = getFundRecord(payment);
1590
+ for (var _i6 = 0, _arr2 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i6 < _arr2.length; _i6++) {
1591
+ var value = _arr2[_i6];
1592
+ var id = normalizeWalletPassId(value);
1593
+ if (!id) continue;
1594
+ var snapshot = snapshotsById.get(id);
1595
+ if (snapshot) return snapshot;
1596
+ }
1597
+ return undefined;
1598
+ }
1599
+ function buildVirtualCurrencySnapshotAssets(params) {
1600
+ var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1601
+ return params.snapshots.flatMap(function (virtualCurrency) {
1602
+ var id = normalizeWalletPassId(virtualCurrency.id);
1603
+ if (!id || params.displayedWalletPassIds.has(id)) return [];
1604
+ var rows = [{
1605
+ item: stringify(virtualCurrency.product_name).trim(),
1606
+ value: ''
1607
+ }];
1608
+ var balance = getVirtualCurrencySnapshotBalance(virtualCurrency);
1609
+ if (balance) {
1610
+ rows.push({
1611
+ item: label(params.locale, 'balance'),
1612
+ value: formatVirtualCurrencyBalance(balance, getVirtualCurrencySnapshotUnit(virtualCurrency, params.locale))
1613
+ });
1614
+ }
1615
+ if (isPresentId(snapshotTime)) {
1616
+ rows.push({
1617
+ item: formatDateTime(snapshotTime, params.locale),
1618
+ value: ''
1619
+ });
1620
+ }
1621
+ return [rows];
1622
+ });
1623
+ }
1624
+ function getVirtualCurrencySnapshotBalance(snapshot) {
1625
+ if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
1626
+ return null;
1627
+ }
1628
+ return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
1629
+ }
1630
+ function getVirtualCurrencySnapshotUnit(snapshot, locale) {
1631
+ return getNonEmptyLocalizedValue(snapshot.name, locale);
1632
+ }
1633
+ function getNonEmptyLocalizedValue(value, locale) {
1634
+ if (value === undefined || value === null) return '';
1635
+ if (_typeof(value) !== 'object' || Array.isArray(value)) return stringify(value).trim();
1636
+ var dashedLocale = locale.replace('_', '-');
1637
+ var underscoredLocale = locale.replace('-', '_');
1638
+ for (var _i7 = 0, _arr3 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i7 < _arr3.length; _i7++) {
1639
+ var candidate = _arr3[_i7];
1640
+ var text = stringify(candidate).trim();
1641
+ if (text) return text;
1642
+ }
1643
+ return '';
1644
+ }
1645
+ function formatVirtualCurrencyBalance(value, unit) {
1646
+ var amount = trimDecimal(value);
1647
+ var normalizedUnit = unit.trim();
1648
+ return normalizedUnit ? "".concat(amount, " ").concat(normalizedUnit) : amount;
1649
+ }
1557
1650
  function normalizeWalletPassId(value) {
1558
1651
  if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
1559
1652
  if (typeof value !== 'string') return null;
@@ -1724,7 +1817,8 @@ function buildPaymentItems(params) {
1724
1817
  currencySymbol = params.currencySymbol,
1725
1818
  includeFundRecordBalance = params.includeFundRecordBalance,
1726
1819
  includeFundRecordUsage = params.includeFundRecordUsage,
1727
- includePaymentAmount = params.includePaymentAmount;
1820
+ includePaymentAmount = params.includePaymentAmount,
1821
+ virtualCurrencyUnit = params.virtualCurrencyUnit;
1728
1822
  var serviceFee = getPaymentServiceFee(payment);
1729
1823
  var items = [{
1730
1824
  item: paymentMethodName(payment, locale),
@@ -1749,7 +1843,8 @@ function buildPaymentItems(params) {
1749
1843
  locale: locale,
1750
1844
  currencySymbol: currencySymbol,
1751
1845
  includeBalance: includeFundRecordBalance,
1752
- includeUsage: includeFundRecordUsage
1846
+ includeUsage: includeFundRecordUsage,
1847
+ virtualCurrencyUnit: virtualCurrencyUnit
1753
1848
  })));
1754
1849
  } else {
1755
1850
  var _ref59, _payment$remaining_am, _payment$metadata;
@@ -1814,7 +1909,8 @@ function buildFundRecordPaymentItems(params) {
1814
1909
  locale = params.locale,
1815
1910
  currencySymbol = params.currencySymbol,
1816
1911
  includeBalance = params.includeBalance,
1817
- includeUsage = params.includeUsage;
1912
+ includeUsage = params.includeUsage,
1913
+ virtualCurrencyUnit = params.virtualCurrencyUnit;
1818
1914
  var items = [];
1819
1915
  var usingBeforeValue = fundRecord.using_before_value;
1820
1916
  var usingAfterValue = fundRecord.using_after_value;
@@ -1835,6 +1931,14 @@ function buildFundRecordPaymentItems(params) {
1835
1931
  return items;
1836
1932
  }
1837
1933
  if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
1934
+ if (virtualCurrencyUnit !== undefined) {
1935
+ if (!isNumericAmount(usingAfterValue)) return items;
1936
+ items.push({
1937
+ item: label(locale, 'balance'),
1938
+ value: formatVirtualCurrencyBalance(new Decimal(usingAfterValue), virtualCurrencyUnit)
1939
+ });
1940
+ return items;
1941
+ }
1838
1942
  items.push({
1839
1943
  item: label(locale, 'balance'),
1840
1944
  value: formatMoney(usingAfterValue, currencySymbol)
@@ -273,6 +273,12 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
273
273
  private mergeHistoricalDiscountList;
274
274
  private shouldSkipAutoApplyFetchedDiscountsInEditMode;
275
275
  private mergeCurrentDiscountSelectionState;
276
+ private resolveDiscountConfigCustomerId;
277
+ /**
278
+ * Stable across notifyTempOrderChanged's immutable object replacement, while
279
+ * still distinguishing two local orders for the same customer.
280
+ */
281
+ private getDiscountConfigOrderIdentityKey;
276
282
  loadDiscountConfig(params?: {
277
283
  customerId?: number;
278
284
  action?: 'create' | 'edit';