@pisell/pisellos 2.3.109 → 2.3.111

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.
Files changed (30) hide show
  1. package/dist/modules/OpenData/index.d.ts +1 -1
  2. package/dist/modules/OpenData/index.js +19 -11
  3. package/dist/modules/Order/index.d.ts +1 -0
  4. package/dist/modules/Order/index.js +22 -21
  5. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
  6. package/dist/modules/Payment/cashRecommendationAlgorithm.js +17 -367
  7. package/dist/server/index.js +4 -5
  8. package/dist/server/utils/small-ticket.d.ts +8 -5
  9. package/dist/server/utils/small-ticket.js +678 -140
  10. package/dist/solution/BookingByStep/index.d.ts +1 -1
  11. package/dist/solution/BookingTicket/index.d.ts +6 -0
  12. package/dist/solution/BookingTicket/index.js +548 -485
  13. package/dist/utils/os-private-payload.d.ts +5 -0
  14. package/dist/utils/os-private-payload.js +17 -0
  15. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  16. package/lib/modules/OpenData/index.d.ts +1 -1
  17. package/lib/modules/OpenData/index.js +9 -1
  18. package/lib/modules/Order/index.d.ts +1 -0
  19. package/lib/modules/Order/index.js +15 -18
  20. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +4 -5
  21. package/lib/modules/Payment/cashRecommendationAlgorithm.js +9 -354
  22. package/lib/server/index.js +4 -5
  23. package/lib/server/utils/small-ticket.d.ts +8 -5
  24. package/lib/server/utils/small-ticket.js +524 -65
  25. package/lib/solution/BookingByStep/index.d.ts +1 -1
  26. package/lib/solution/BookingTicket/index.d.ts +6 -0
  27. package/lib/solution/BookingTicket/index.js +32 -3
  28. package/lib/utils/os-private-payload.d.ts +5 -0
  29. package/lib/utils/os-private-payload.js +22 -0
  30. package/package.json +1 -1
@@ -27,13 +27,20 @@ const LABELS = {
27
27
  eftpos: 'Eftpos',
28
28
  wallet: 'Wallet',
29
29
  giftCard: 'Gift card',
30
+ pointCard: 'Point card',
30
31
  balance: 'Balance',
32
+ validity: 'Validity',
31
33
  remainingAmount: 'Remaining amount',
32
34
  redeemPoints: 'Redeem points',
33
- remainingPoints: 'Remaining points',
35
+ remainingPoints: 'Points balance',
34
36
  table: 'Table',
37
+ bookingId: 'Booking ID',
38
+ bookingDateTime: 'Date & time',
39
+ bookingResource: 'Resource',
40
+ bookingHolder: 'Holder',
35
41
  orderDiscount: 'Order discount',
36
42
  manualDiscount: 'Manual discount',
43
+ manualMarkup: 'Manual markup',
37
44
  payProcessingFee: 'Pay processing fee',
38
45
  surchargeIncluded: 'Surcharge(Included)',
39
46
  rounding: 'Rounding',
@@ -59,13 +66,20 @@ const LABELS = {
59
66
  eftpos: '刷卡支付',
60
67
  wallet: '钱包支付',
61
68
  giftCard: '礼品卡',
69
+ pointCard: '积分卡',
62
70
  balance: '余额',
71
+ validity: '有效期',
63
72
  remainingAmount: '剩余金额',
64
73
  redeemPoints: '本次使用积分',
65
- remainingPoints: '剩余积分',
74
+ remainingPoints: '积分余额',
66
75
  table: '桌台',
76
+ bookingId: '预约编号',
77
+ bookingDateTime: '日期和时间',
78
+ bookingResource: '资源',
79
+ bookingHolder: '预约人',
67
80
  orderDiscount: '整单折扣',
68
81
  manualDiscount: '手动折扣',
82
+ manualMarkup: '手动加价',
69
83
  payProcessingFee: '支付手续费',
70
84
  surchargeIncluded: '手续费(已含)',
71
85
  rounding: '抹零',
@@ -91,13 +105,20 @@ const LABELS = {
91
105
  eftpos: '刷卡支付',
92
106
  wallet: '錢包支付',
93
107
  giftCard: '禮品卡',
108
+ pointCard: '積分卡',
94
109
  balance: '餘額',
110
+ validity: '有效期',
95
111
  remainingAmount: '剩餘金額',
96
112
  redeemPoints: '本次使用積分',
97
- remainingPoints: '剩餘積分',
113
+ remainingPoints: '積分餘額',
98
114
  table: '桌台',
115
+ bookingId: '預約編號',
116
+ bookingDateTime: '日期和時間',
117
+ bookingResource: '資源',
118
+ bookingHolder: '預約人',
99
119
  orderDiscount: '整單折扣',
100
120
  manualDiscount: '手動折扣',
121
+ manualMarkup: '手動加價',
101
122
  payProcessingFee: '支付手續費',
102
123
  surchargeIncluded: '手續費(已含)',
103
124
  rounding: '抹零',
@@ -121,13 +142,20 @@ const LABELS = {
121
142
  eftpos: 'カード',
122
143
  wallet: 'ウォレット',
123
144
  giftCard: 'ギフトカード',
145
+ pointCard: 'ポイントカード',
124
146
  balance: '残高',
147
+ validity: '有効期限',
125
148
  remainingAmount: '残高',
126
149
  redeemPoints: '利用ポイント',
127
- remainingPoints: '残りポイント',
150
+ remainingPoints: 'ポイント残高',
128
151
  table: 'テーブル',
152
+ bookingId: '予約ID',
153
+ bookingDateTime: '日時',
154
+ bookingResource: 'リソース',
155
+ bookingHolder: '予約者',
129
156
  orderDiscount: '注文割引',
130
157
  manualDiscount: '手動割引',
158
+ manualMarkup: '手動値上げ',
131
159
  payProcessingFee: '決済手数料',
132
160
  rounding: '端数調整',
133
161
  gross: '総重量',
@@ -152,13 +180,20 @@ const LABELS = {
152
180
  eftpos: 'Cartão',
153
181
  wallet: 'Carteira',
154
182
  giftCard: 'Cartão-presente',
183
+ pointCard: 'Cartão de pontos',
155
184
  balance: 'Saldo',
185
+ validity: 'Validade',
156
186
  remainingAmount: 'Saldo restante',
157
187
  redeemPoints: 'Pontos utilizados',
158
- remainingPoints: 'Pontos restantes',
188
+ remainingPoints: 'Saldo de pontos',
159
189
  table: 'Mesa',
190
+ bookingId: 'ID da reserva',
191
+ bookingDateTime: 'Data e hora',
192
+ bookingResource: 'Recurso',
193
+ bookingHolder: 'Titular',
160
194
  orderDiscount: 'Desconto do pedido',
161
195
  manualDiscount: 'Desconto manual',
196
+ manualMarkup: 'Acréscimo manual',
162
197
  payProcessingFee: 'Taxa de processamento',
163
198
  rounding: 'Arredondamento',
164
199
  gross: 'Peso bruto',
@@ -264,9 +299,7 @@ function buildBaseData(params) {
264
299
  payment_status: financials.paymentStatus,
265
300
  total_amount: formatMoney(financials.totalAmount, currencySymbol),
266
301
  has_pay: formatMoney(financials.netPaymentApplied, currencySymbol),
267
- ...(isPresentId(financials.amountGap) ? {
268
- amount_gap: formatMoney(financials.amountGap, currencySymbol)
269
- } : {}),
302
+ amount_gap: formatCalculatedMoney(financials.amountGap ?? 0, currencySymbol),
270
303
  is_repeat: 0,
271
304
  buzzer: stringify(order.buzzer || order.pickup_number || order.metadata?.buzzer),
272
305
  order_no: orderNumber,
@@ -278,7 +311,9 @@ function buildBaseData(params) {
278
311
  }
279
312
  function buildProducts(order, locale, productMap) {
280
313
  const products = Array.isArray(order.products) ? order.products : [];
281
- return products.map(product => {
314
+ const allergyByProductUid = buildProductAllergyMap(order, locale);
315
+ return products.map(rawProduct => {
316
+ const product = restoreReceiptDiscountHierarchy(rawProduct);
282
317
  const quantity = toNumber(product.product_quantity ?? product.quantity ?? product.num ?? 1, 1);
283
318
  const originalPrice = product.original_price ?? product.selling_price ?? product.payment_price ?? product.price ?? 0;
284
319
  const sellingPrice = product.selling_price ?? product.payment_price ?? product.price ?? originalPrice;
@@ -317,16 +352,26 @@ function buildProducts(order, locale, productMap) {
317
352
  originalPrice
318
353
  });
319
354
  const productNote = resolveProductNote(product, locale);
355
+ const allergy = isPresentId(productUid) ? allergyByProductUid.get(String(productUid).trim()) || '' : '';
320
356
  const basePrice = resolveProductBasePrice(product);
357
+ const resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
358
+ const shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
321
359
  return {
322
360
  product_title: productTitle,
323
361
  product_quantity: quantity,
324
362
  selling_price: formatMoney(sellingPrice, currencySymbol),
363
+ total_selling_price: formatCalculatedMoney(new _decimal.default(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
325
364
  original_price: formatMoney(originalPrice, currencySymbol),
326
- ...(isPresentId(basePrice) ? {
327
- base_price: formatMoney(basePrice, currencySymbol)
365
+ ...(shouldIncludeBasePrice ? {
366
+ base_price: formatCalculatedMoney(basePrice ?? 0, currencySymbol)
328
367
  } : {}),
329
368
  total_original_price: formatMoney(new _decimal.default(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
369
+ ...(options.length ? {
370
+ options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
371
+ } : {}),
372
+ ...(resolvedCombinations.length ? {
373
+ package_items_total_price: sumCombinationTotals(resolvedCombinations, currencySymbol)
374
+ } : {}),
330
375
  extension_list: extensionList,
331
376
  ...(isPresentId(productUid) ? {
332
377
  product_uid: productUid
@@ -337,20 +382,88 @@ function buildProducts(order, locale, productMap) {
337
382
  ...(productNote ? {
338
383
  product_note: productNote
339
384
  } : {}),
385
+ ...(allergy ? {
386
+ allergy
387
+ } : {}),
340
388
  ...(options.length ? {
341
389
  options
342
390
  } : {}),
343
391
  ...(resolvedVariant ? {
344
392
  variant: resolvedVariant
345
393
  } : {}),
346
- ...(Array.isArray(product.combinations) && product.combinations.length ? {
347
- combinations: normalizeExistingCombinations(product.combinations, locale)
348
- } : combinations.length ? {
349
- combinations
394
+ ...(resolvedCombinations.length ? {
395
+ combinations: resolvedCombinations
350
396
  } : {})
351
397
  };
352
398
  });
353
399
  }
400
+ const RECEIPT_BUNDLE_MAP_ID_KEY = 'custom_product_bundle_map_id';
401
+ function restoreReceiptDiscountHierarchy(source) {
402
+ if (!source || typeof source !== 'object' || Array.isArray(source)) {
403
+ return source;
404
+ }
405
+ const childKey = Array.isArray(source.combinations) && source.combinations.length ? 'combinations' : Array.isArray(source.product_bundle) && source.product_bundle.length ? 'product_bundle' : null;
406
+ if (!childKey) return {
407
+ ...source
408
+ };
409
+ const children = source[childKey].map(child => child && typeof child === 'object' && !Array.isArray(child) ? restoreReceiptDiscountHierarchy(child) : child);
410
+ const restored = {
411
+ ...source,
412
+ [childKey]: children
413
+ };
414
+ if (!Array.isArray(source.discount_list) || !source.discount_list.length) {
415
+ return restored;
416
+ }
417
+ const descendantsByMapId = new Map();
418
+ indexReceiptDiscountTargets(children, descendantsByMapId);
419
+ if (!descendantsByMapId.size) return restored;
420
+ const ownDiscounts = [];
421
+ for (const discount of source.discount_list) {
422
+ const mapId = getReceiptDiscountBundleMapId(discount);
423
+ const target = mapId ? descendantsByMapId.get(mapId) : undefined;
424
+ if (!target) {
425
+ ownDiscounts.push(discount);
426
+ continue;
427
+ }
428
+ const targetDiscounts = Array.isArray(target.discount_list) ? target.discount_list : [];
429
+ if (!targetDiscounts.some(item => isSameReceiptDiscount(item, discount))) {
430
+ target.discount_list = [...targetDiscounts, discount];
431
+ }
432
+ }
433
+ restored.discount_list = ownDiscounts;
434
+ return restored;
435
+ }
436
+ function indexReceiptDiscountTargets(nodes, targets) {
437
+ for (const node of nodes) {
438
+ if (!node || typeof node !== 'object' || Array.isArray(node)) continue;
439
+ const mapId = getReceiptBundleMapId(node);
440
+ if (mapId && !targets.has(mapId)) targets.set(mapId, node);
441
+ const children = Array.isArray(node.combinations) && node.combinations.length ? node.combinations : Array.isArray(node.product_bundle) ? node.product_bundle : [];
442
+ indexReceiptDiscountTargets(children, targets);
443
+ }
444
+ }
445
+ function normalizeReceiptId(value) {
446
+ if (value === undefined || value === null) return null;
447
+ const normalized = String(value).trim();
448
+ return normalized ? normalized : null;
449
+ }
450
+ function getReceiptBundleMapId(node) {
451
+ return normalizeReceiptId(node.metadata?.[RECEIPT_BUNDLE_MAP_ID_KEY] ?? node._id);
452
+ }
453
+ function getReceiptDiscountBundleMapId(discount) {
454
+ return normalizeReceiptId(discount?.metadata?.[RECEIPT_BUNDLE_MAP_ID_KEY]);
455
+ }
456
+ function isSameReceiptDiscount(left, right) {
457
+ const leftOrderDiscountId = normalizeReceiptId(left?.order_discount_id);
458
+ const rightOrderDiscountId = normalizeReceiptId(right?.order_discount_id);
459
+ if (leftOrderDiscountId && rightOrderDiscountId) {
460
+ return leftOrderDiscountId === rightOrderDiscountId;
461
+ }
462
+ const leftResourceId = normalizeReceiptId(left?.discount?.resource_id ?? left?.resource_id ?? left?.discount_id);
463
+ const rightResourceId = normalizeReceiptId(right?.discount?.resource_id ?? right?.resource_id ?? right?.discount_id);
464
+ if (!leftResourceId || !rightResourceId) return false;
465
+ return leftResourceId === rightResourceId && getReceiptDiscountBundleMapId(left) === getReceiptDiscountBundleMapId(right) && String(left?.amount ?? left?.value ?? left?.discount_amount ?? '') === String(right?.amount ?? right?.value ?? right?.discount_amount ?? '');
466
+ }
354
467
  function resolveProductBasePrice(product) {
355
468
  const metadata = product.metadata || {};
356
469
  const origin = product._origin || metadata.origin || {};
@@ -366,15 +479,35 @@ function normalizeProductDiscounts(params) {
366
479
  currencySymbol,
367
480
  quantity
368
481
  } = params;
369
- return normalizeArray(product.discount_list).map(discount => {
482
+ const rows = normalizeArray(product.discount_list).filter(discount => {
483
+ const amount = discount.amount ?? discount.value ?? discount.discount_amount;
484
+ return isNonZero(amount);
485
+ }).map(discount => {
370
486
  const title = resolveDiscountTitleWithPercent(discount, locale);
371
487
  const amount = discount.amount ?? discount.value ?? discount.discount_amount;
372
- const formattedAmount = formatNegativeMoney(new _decimal.default(toMoneyNumber(amount)).mul(quantity), currencySymbol);
488
+ const isMarkup = isManualMarkup(discount);
489
+ const totalAmount = new _decimal.default(toMoneyNumber(amount)).mul(quantity);
490
+ const formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
373
491
  return {
374
492
  item: title,
375
- value: formattedAmount
493
+ value: formattedAmount,
494
+ isMarkup
376
495
  };
377
496
  });
497
+ return rows.sort((left, right) => Number(right.isMarkup) - Number(left.isMarkup)).map(({
498
+ isMarkup: _isMarkup,
499
+ ...row
500
+ }) => row);
501
+ }
502
+ function isManualMarkup(discount) {
503
+ if (discount.type !== 'product') return false;
504
+ if (discount.discount?.discount_type === 'change_price') return true;
505
+ const amount = discount.amount ?? discount.value ?? discount.discount_amount;
506
+ return new _decimal.default(toMoneyNumber(amount)).isNegative();
507
+ }
508
+ function hasProductDiscount(product, extensionList = []) {
509
+ const hasDiscountListAmount = normalizeArray(product.discount_list).some(discount => isNonZero(discount.amount ?? discount.value ?? discount.discount_amount));
510
+ return hasDiscountListAmount || extensionList.some(row => /^\s*-/.test(stringify(row?.value)));
378
511
  }
379
512
  function buildProductExtensionList(params) {
380
513
  const {
@@ -457,7 +590,9 @@ function resolveDiscountTitleWithPercent(discount, locale) {
457
590
  function resolveDiscountTitle(discount, locale) {
458
591
  const title = getLocalizedValue(discount.discount?.name ?? discount.discount?.title ?? discount.discount?.message ?? discount.name ?? discount.title ?? discount.message, locale);
459
592
  if (title) return title;
460
- if (discount.type === 'product') return label(locale, 'manualDiscount');
593
+ if (discount.type === 'product') {
594
+ return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
595
+ }
461
596
  return '';
462
597
  }
463
598
  function resolveProductTitle(params) {
@@ -483,6 +618,7 @@ function normalizeProductOptions(params) {
483
618
  const rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray(product.product_sku?.option) ? product.product_sku.option : [];
484
619
  return rawOptions.map(option => {
485
620
  const price = option.original_price ?? option.add_price ?? option.price;
621
+ const quantity = toNumber(option.num ?? option.quantity ?? 1, 1);
486
622
  const value = option.value ?? option.option ?? option.item;
487
623
  const name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
488
624
  option,
@@ -492,11 +628,12 @@ function normalizeProductOptions(params) {
492
628
  return {
493
629
  name,
494
630
  ...(option.num !== undefined || option.quantity !== undefined ? {
495
- num: toNumber(option.num ?? option.quantity, 1)
631
+ num: quantity
496
632
  } : {}),
497
633
  ...(price !== undefined && price !== null && price !== '' ? {
498
634
  price: formatMoney(price, currencySymbol)
499
635
  } : {}),
636
+ total_price: formatCalculatedMoney(new _decimal.default(toMoneyNumber(price ?? 0)).mul(quantity), currencySymbol),
500
637
  ...(value !== undefined && value !== null && value !== '' ? {
501
638
  value: getLocalizedValue(value, locale)
502
639
  } : {})
@@ -527,49 +664,144 @@ function normalizeProductCombinations(params) {
527
664
  parentProduct
528
665
  });
529
666
  const productNote = resolveProductNote(bundle, locale);
530
- const nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
667
+ const nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
668
+ const quantity = toNumber(bundle.num ?? bundle.quantity ?? 1, 1);
669
+ const formattedPrice = formatBundlePrice(bundle, currencySymbol);
670
+ const optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
671
+ const explicitBasePrice = resolveCombinationBasePrice(bundle);
672
+ const basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
673
+ const extensionList = buildProductExtensionList({
674
+ product: bundle,
675
+ locale,
676
+ currencySymbol,
677
+ quantity,
678
+ originalPrice: formattedPrice
679
+ });
680
+ const shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle, extensionList);
531
681
  return {
532
682
  product_title: baseTitle,
533
- product_quantity: toNumber(bundle.num ?? bundle.quantity ?? 1, 1),
534
- price: formatBundlePrice(bundle, currencySymbol),
683
+ product_quantity: quantity,
684
+ price: formattedPrice,
685
+ total_selling_price: formatCalculatedMoney(new _decimal.default(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol),
686
+ ...(shouldIncludeBasePrice ? {
687
+ base_price: formatCalculatedMoney(basePrice, currencySymbol)
688
+ } : {}),
535
689
  combinations_options: combinationsOptions,
690
+ ...(combinationsOptions.length ? {
691
+ options_total_price: optionsTotal
692
+ } : {}),
693
+ ...(nestedCombinations.length ? {
694
+ package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
695
+ } : {}),
536
696
  ...(productNote ? {
537
697
  product_note: productNote
538
698
  } : {}),
699
+ ...(extensionList.length ? {
700
+ extension_list: extensionList
701
+ } : {}),
539
702
  ...(nestedCombinations.length ? {
540
703
  combinations: nestedCombinations
541
704
  } : {})
542
705
  };
543
706
  });
544
707
  }
545
- function normalizeExistingCombinations(combinations, locale) {
708
+ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
546
709
  return combinations.map(combination => {
547
710
  if (!combination || typeof combination !== 'object' || Array.isArray(combination)) {
548
711
  return combination;
549
712
  }
550
713
  const productNote = resolveProductNote(combination, locale);
551
- const nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale) : undefined;
714
+ const rawOptions = Array.isArray(combination.combinations_options) ? combination.combinations_options : Array.isArray(combination.options) ? combination.options : [];
715
+ const normalizedOptions = normalizeProductOptions({
716
+ product: {},
717
+ locale,
718
+ currencySymbol,
719
+ options: rawOptions
720
+ });
721
+ const nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
552
722
  const snapshot = {
553
723
  ...combination
554
724
  };
555
725
  delete snapshot.product_note;
556
726
  delete snapshot.note;
727
+ delete snapshot.combinations;
728
+ delete snapshot.discount_list;
729
+ const quantity = toNumber(combination.product_quantity ?? combination.num ?? combination.quantity ?? 1, 1);
730
+ const unitPrice = firstPresentValue(combination.selling_price, combination.price, combination.original_price) ?? 0;
731
+ const optionsAmount = sumMoneyValues(normalizedOptions.map(option => option.total_price));
732
+ const explicitBasePrice = resolveCombinationBasePrice(combination, true);
733
+ const basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
734
+ const extensionList = buildProductExtensionList({
735
+ product: combination,
736
+ locale,
737
+ currencySymbol,
738
+ quantity,
739
+ originalPrice: unitPrice
740
+ });
741
+ const shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
557
742
  return {
558
743
  ...snapshot,
744
+ product_quantity: quantity,
745
+ total_selling_price: formatCalculatedMoney(new _decimal.default(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol),
746
+ ...(shouldIncludeBasePrice ? {
747
+ base_price: formatCalculatedMoney(basePrice, currencySymbol)
748
+ } : {}),
749
+ ...(Array.isArray(combination.combinations_options) ? {
750
+ combinations_options: normalizedOptions
751
+ } : Array.isArray(combination.options) ? {
752
+ options: normalizedOptions
753
+ } : {}),
754
+ ...(normalizedOptions.length ? {
755
+ options_total_price: formatCalculatedMoney(optionsAmount, currencySymbol)
756
+ } : {}),
757
+ ...(nestedCombinations.length ? {
758
+ package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
759
+ } : {}),
559
760
  ...(productNote ? {
560
761
  product_note: productNote
561
762
  } : {}),
562
- ...(nestedCombinations ? {
763
+ ...(extensionList.length ? {
764
+ extension_list: extensionList
765
+ } : {}),
766
+ ...(nestedCombinations.length ? {
563
767
  combinations: nestedCombinations
564
768
  } : {})
565
769
  };
566
770
  });
567
771
  }
772
+ function sumMoneyValues(values) {
773
+ return values.reduce((sum, value) => sum.plus(toMoneyNumber(value)), new _decimal.default(0));
774
+ }
775
+ function resolveCombinationBasePrice(combination, preferOriginalPrice = false) {
776
+ const fallbackPrices = preferOriginalPrice ? [combination.original_price, combination.product_price, combination.price] : [combination.price, combination.original_price, combination.product_price];
777
+ return firstPresentValue(combination.base_price, combination.metadata?.source_product_price, ...fallbackPrices);
778
+ }
779
+ function sumNormalizedOptionTotals(options, currencySymbol) {
780
+ return formatCalculatedMoney(sumMoneyValues(options.map(option => option.total_price)), currencySymbol);
781
+ }
782
+ function sumCombinationTotals(combinations, currencySymbol) {
783
+ return formatCalculatedMoney(sumMoneyValues(combinations.map(combination => combination.total_selling_price)), currencySymbol);
784
+ }
568
785
  function resolveProductNote(product, locale) {
569
786
  const productNote = getLocalizedValue(product.product_note, locale).trim();
570
787
  if (productNote) return productNote;
571
788
  return getLocalizedValue(product.note, locale).trim();
572
789
  }
790
+ function buildProductAllergyMap(order, locale) {
791
+ const allergyByProductUid = new Map();
792
+ for (const note of normalizeArray(order.notes)) {
793
+ if (!note || typeof note !== 'object' || Array.isArray(note) || String(note.note_type || '').trim() !== 'allergy') {
794
+ continue;
795
+ }
796
+ const content = getLocalizedValue(note.content?.text, locale).trim();
797
+ if (!content) continue;
798
+ const relation = normalizeArray(note.note_relations).find(item => item && typeof item === 'object' && !Array.isArray(item) && item.relation_type === 'about' && item.target_type === 'order_detail' && Number(item.is_primary) === 1);
799
+ const productUid = String(relation?.target_uuid ?? '').trim();
800
+ if (!productUid || allergyByProductUid.has(productUid)) continue;
801
+ allergyByProductUid.set(productUid, content);
802
+ }
803
+ return allergyByProductUid;
804
+ }
573
805
  function resolveBundleProductTitle(params) {
574
806
  const {
575
807
  bundle,
@@ -795,12 +1027,6 @@ function buildFees(params) {
795
1027
  });
796
1028
  const isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
797
1029
  const roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
798
- if (isNonZero(roundingAmount)) {
799
- fees.push({
800
- item: label(locale, 'rounding'),
801
- value: formatMoney(roundingAmount, currencySymbol)
802
- });
803
- }
804
1030
  const payProcessingFee = financials.payProcessingFee;
805
1031
  if (isNonZero(payProcessingFee)) {
806
1032
  fees.push({
@@ -811,12 +1037,14 @@ function buildFees(params) {
811
1037
  const productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
812
1038
  const productOriginalAmount = firstPresentValue(summary.product_original_amount, order.product_original_amount) ?? calculateProductOriginalAmount(order);
813
1039
  const totalSavingsAmount = new _decimal.default(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
1040
+ const itemDiscountAmount = new _decimal.default(toMoneyNumber(productExpectAmount ?? 0)).minus(toMoneyNumber(productOriginalAmount));
814
1041
  return {
815
1042
  fees,
816
1043
  countFee: {
817
1044
  total_amount: formatMoney(firstPresentValue(summary.total_amount, order.total_amount) ?? 0, currencySymbol),
818
1045
  original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
819
1046
  product_expect_amount: formatMoney(productExpectAmount ?? 0, currencySymbol),
1047
+ item_discount_amount: formatCalculatedMoney(itemDiscountAmount, currencySymbol),
820
1048
  expect_amount: formatMoney(financials.totalAmount, currencySymbol),
821
1049
  product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce((sum, product) => sum + product.product_quantity, 0)), 0),
822
1050
  has_pay: formatMoney(financials.orderPaidAmount, currencySymbol),
@@ -922,24 +1150,13 @@ function buildDelivery(order, locale) {
922
1150
  function buildAppointment(order, locale) {
923
1151
  const bookings = sortBookings(normalizeArray(order.bookings));
924
1152
  if (bookings.length) {
925
- return bookings.map(booking => {
926
- const snapshot = {
927
- ...booking
928
- };
929
- delete snapshot.product_uid;
930
- delete snapshot.booking_uid;
931
- const productUid = firstPresentValue(booking.product_uid, booking.metadata?.product_uid);
932
- const bookingUid = firstPresentValue(booking.metadata?.unique_identification_number, booking.booking_uid);
933
- return {
934
- ...snapshot,
935
- ...(isPresentId(productUid) ? {
936
- product_uid: productUid
937
- } : {}),
938
- ...(isPresentId(bookingUid) ? {
939
- booking_uid: bookingUid
940
- } : {})
941
- };
942
- });
1153
+ const allResources = normalizeArray(order.resources || order.resource_list);
1154
+ return bookings.flatMap(booking => buildAppointmentRows({
1155
+ booking,
1156
+ allResources,
1157
+ bookingCount: bookings.length,
1158
+ locale
1159
+ }));
943
1160
  }
944
1161
  const tableName = order.table_name || order.metadata?.table_name || order.metadata?.table?.name || order.form_data?.table_name;
945
1162
  if (!tableName) return [];
@@ -948,6 +1165,82 @@ function buildAppointment(order, locale) {
948
1165
  value: getLocalizedValue(tableName, locale)
949
1166
  }];
950
1167
  }
1168
+ function buildAppointmentRows(params) {
1169
+ const {
1170
+ booking,
1171
+ allResources,
1172
+ bookingCount,
1173
+ locale
1174
+ } = params;
1175
+ const productUid = stringify(firstPresentValue(booking.product_uid, booking.metadata?.product_uid)).trim();
1176
+ const bookingUid = stringify(firstPresentValue(booking.metadata?.unique_identification_number, booking.booking_uid)).trim();
1177
+ const association = {
1178
+ product_uid: productUid,
1179
+ booking_uid: bookingUid
1180
+ };
1181
+ const bookingId = stringify(firstPresentValue(booking.booking_id, booking.schedule_event_id, bookingUid)).trim();
1182
+ const bookingTime = formatBookingRange(booking, locale);
1183
+ const resourceText = formatBookingResources(resolveBookingResourcesForReceipt(booking, allResources, bookingCount), locale);
1184
+ const holder = getLocalizedValue(booking.holder?.name ?? booking.metadata?.holder?.name, locale).trim();
1185
+ return [{
1186
+ item: label(locale, 'bookingId'),
1187
+ value: bookingId,
1188
+ ...association
1189
+ }, {
1190
+ item: label(locale, 'bookingDateTime'),
1191
+ value: bookingTime,
1192
+ ...association
1193
+ }, {
1194
+ item: label(locale, 'bookingResource'),
1195
+ value: resourceText,
1196
+ ...association
1197
+ }, {
1198
+ item: label(locale, 'bookingHolder'),
1199
+ value: holder,
1200
+ ...association
1201
+ }].filter(row => Boolean(row.value));
1202
+ }
1203
+ function formatBookingRange(booking, locale) {
1204
+ const startDate = stringify(booking.start_date);
1205
+ const startTime = stringify(booking.start_time);
1206
+ const endDate = stringify(booking.end_date || startDate);
1207
+ const endTime = stringify(booking.end_time);
1208
+ const start = firstValidBookingDate(booking.start_at, booking.start_datetime, booking.start_date_time, `${startDate} ${startTime}`.trim());
1209
+ const end = firstValidBookingDate(booking.end_at, booking.end_datetime, booking.end_date_time, endTime ? `${endDate} ${endTime}`.trim() : '');
1210
+ if (!start) {
1211
+ return [startDate, startTime, endTime ? `- ${endDate} ${endTime}` : ''].filter(Boolean).join(' ');
1212
+ }
1213
+ const dateFormat = locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD';
1214
+ const startText = start.format(`${dateFormat} HH:mm`);
1215
+ if (!end) return startText;
1216
+ return `${startText} - ${end.isSame(start, 'day') ? end.format('HH:mm') : end.format(`${dateFormat} HH:mm`)}`;
1217
+ }
1218
+ function firstValidBookingDate(...values) {
1219
+ for (const value of values) {
1220
+ if (!isPresentId(value)) continue;
1221
+ const parsed = (0, _dayjs.default)(value);
1222
+ if (parsed.isValid()) return parsed;
1223
+ }
1224
+ return null;
1225
+ }
1226
+ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount) {
1227
+ const embedded = normalizeArray(booking.resources).filter(resource => Boolean(resource) && typeof resource === 'object' && !Array.isArray(resource));
1228
+ const resourceIds = new Set([booking.resource_id, booking.relation_id, ...normalizeArray(booking.resource_ids), ...normalizeArray(booking.metadata?.resource_ids)].map(value => stringify(value).trim()).filter(Boolean));
1229
+ for (const resource of embedded) {
1230
+ const id = stringify(resource.id ?? resource.resource_id ?? resource.relation_id).trim();
1231
+ if (id) resourceIds.add(id);
1232
+ }
1233
+ if (resourceIds.size) {
1234
+ const matched = allResources.filter(resource => resourceIds.has(stringify(resource.id ?? resource.resource_id ?? resource.relation_id).trim()));
1235
+ if (matched.length) return matched;
1236
+ }
1237
+ if (embedded.length) return embedded;
1238
+ if (bookingCount === 1 && allResources.length) return allResources;
1239
+ return [];
1240
+ }
1241
+ function formatBookingResources(resources, locale) {
1242
+ return resources.map(resource => [getLocalizedValue(resource.form_title || resource.metadata?.form_name || resource.relation_form_name || resource.metadata?.relation_form_name, locale), getLocalizedValue(resource.title || resource.name || resource.main_field || resource.metadata?.main_field || resource.metadata?.resource_name, locale)].filter(Boolean).join(' ')).filter(Boolean).join(', ');
1243
+ }
951
1244
  function sortBookings(bookings) {
952
1245
  return bookings.map((booking, index) => ({
953
1246
  booking,
@@ -999,7 +1292,9 @@ function buildPaymentData(params) {
999
1292
  payment,
1000
1293
  locale: params.locale,
1001
1294
  currencySymbol: params.currencySymbol,
1002
- includeFundRecordBalance: false
1295
+ includeFundRecordBalance: false,
1296
+ includeFundRecordUsage: true,
1297
+ includePaymentAmount: true
1003
1298
  }));
1004
1299
  }
1005
1300
  function buildRefundData(params) {
@@ -1083,28 +1378,107 @@ function resolveRefundPayment(refund, payments) {
1083
1378
  return matchedPayment || refund;
1084
1379
  }
1085
1380
  function buildWallets(params) {
1086
- const paymentWallets = normalizeArray(params.order.payments).filter(payment => isPrintablePayment(payment) && !!getFundRecord(payment)).map(payment => buildPaymentItems({
1381
+ const displayedWalletPayments = normalizeArray(params.order.payments).filter(payment => isPrintablePayment(payment) && !!getFundRecord(payment));
1382
+ const paymentWallets = displayedWalletPayments.map(payment => buildPaymentItems({
1087
1383
  payment,
1088
1384
  locale: params.locale,
1089
1385
  currencySymbol: params.currencySymbol,
1090
- includeFundRecordBalance: true
1386
+ includeFundRecordBalance: true,
1387
+ includeFundRecordUsage: false,
1388
+ includePaymentAmount: false
1091
1389
  }));
1092
- return [...paymentWallets, ...buildVoucherAssets(params)];
1390
+ const displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
1391
+ return [...paymentWallets, ...buildVoucherAssets(params), ...buildPointCardSnapshotAssets({
1392
+ order: params.order,
1393
+ locale: params.locale,
1394
+ displayedWalletPassIds
1395
+ })];
1396
+ }
1397
+ function collectDisplayedWalletPassIds(payments) {
1398
+ const ids = new Set();
1399
+ payments.forEach(payment => {
1400
+ const fundRecord = getFundRecord(payment);
1401
+ [payment.voucher_id, fundRecord?.voucher_id].forEach(value => {
1402
+ const id = normalizeWalletPassId(value);
1403
+ if (id) ids.add(id);
1404
+ });
1405
+ });
1406
+ return ids;
1407
+ }
1408
+ function buildPointCardSnapshotAssets(params) {
1409
+ const snapshots = params.order.order_meta_list?.point_cards_snapshot;
1410
+ if (!Array.isArray(snapshots)) return [];
1411
+ const snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1412
+ const seenSnapshotIds = new Set();
1413
+ return snapshots.flatMap(snapshot => {
1414
+ if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) return [];
1415
+ const pointCard = snapshot;
1416
+ if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
1417
+ const id = normalizeWalletPassId(pointCard.id);
1418
+ if (!id || seenSnapshotIds.has(id)) return [];
1419
+ seenSnapshotIds.add(id);
1420
+ if (params.displayedWalletPassIds.has(id)) return [];
1421
+ const rows = [{
1422
+ item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1423
+ value: ''
1424
+ }];
1425
+ const remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
1426
+ if (remainingPoints) {
1427
+ rows.push({
1428
+ item: label(params.locale, 'remainingPoints'),
1429
+ value: trimDecimal(remainingPoints)
1430
+ });
1431
+ }
1432
+ if (isPresentId(snapshotTime)) {
1433
+ rows.push({
1434
+ item: formatDateTime(snapshotTime, params.locale),
1435
+ value: ''
1436
+ });
1437
+ }
1438
+ return [rows];
1439
+ });
1440
+ }
1441
+ function normalizeWalletPassId(value) {
1442
+ if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
1443
+ if (typeof value !== 'string') return null;
1444
+ return value.trim() || null;
1445
+ }
1446
+ function getPointCardSnapshotRemainingPoints(snapshot) {
1447
+ if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
1448
+ return null;
1449
+ }
1450
+ return _decimal.default.max(new _decimal.default(snapshot.par_value).minus(new _decimal.default(snapshot.used_par_value)), 0);
1093
1451
  }
1094
1452
  function buildVoucherAssets(params) {
1095
1453
  const seenVoucherKeys = new Set();
1454
+ const fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1096
1455
  return normalizeArray(params.order.vouchers).flatMap((voucher, index) => {
1097
1456
  if (!voucher || typeof voucher !== 'object' || Array.isArray(voucher)) return [];
1098
1457
  const voucherKey = getVoucherAssetKey(voucher, index);
1099
1458
  if (seenVoucherKeys.has(voucherKey)) return [];
1100
1459
  seenVoucherKeys.add(voucherKey);
1101
1460
  const name = getVoucherAssetName(voucher, params.locale);
1461
+ const assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
1462
+ const timeRow = isPresentId(assetTime) ? {
1463
+ item: formatDateTime(assetTime, params.locale),
1464
+ value: ''
1465
+ } : null;
1466
+ if (isTicketVoucher(voucher)) {
1467
+ const validity = getVoucherValidity(voucher, params.locale);
1468
+ return [[{
1469
+ item: name,
1470
+ value: ''
1471
+ }, ...(validity ? [{
1472
+ item: label(params.locale, 'validity'),
1473
+ value: validity
1474
+ }] : [])]];
1475
+ }
1102
1476
  const percent = getVoucherDiscountPercent(voucher);
1103
1477
  if (percent) {
1104
1478
  return [[{
1105
1479
  item: appendPercentToVoucherName(name, percent),
1106
1480
  value: formatVoucherDiscount(percent, params.locale)
1107
- }]];
1481
+ }, ...(timeRow ? [timeRow] : [])]];
1108
1482
  }
1109
1483
  const balance = getVoucherBalance(voucher);
1110
1484
  return [[{
@@ -1113,9 +1487,83 @@ function buildVoucherAssets(params) {
1113
1487
  }, {
1114
1488
  item: label(params.locale, 'balance'),
1115
1489
  value: formatMoney(balance, params.currencySymbol)
1116
- }]];
1490
+ }, ...(timeRow ? [timeRow] : [])]];
1491
+ });
1492
+ }
1493
+ function isTicketVoucher(voucher) {
1494
+ return stringify(voucher.tag).trim().toLowerCase() === 'ticket';
1495
+ }
1496
+ function getVoucherValidity(voucher, locale) {
1497
+ const availableTime = firstPresentValue(voucher.available_time, voucher.avaliable_time, voucher.metadata?.available_time, voucher.metadata?.avaliable_time);
1498
+ const availableTimeText = formatVoucherAvailableTime(availableTime, locale);
1499
+ if (availableTimeText) return availableTimeText;
1500
+ const startDate = firstPresentValue(voucher.valid_from, voucher.start_at, voucher.start_date_time, voucher.start_date, voucher.metadata?.valid_from, voucher.metadata?.start_at, voucher.metadata?.start_date);
1501
+ const endDate = firstPresentValue(voucher.valid_to, voucher.end_at, voucher.end_date_time, voucher.expire_date, voucher.end_date, voucher.expire_time, voucher.metadata?.valid_to, voucher.metadata?.end_at, voucher.metadata?.expire_date, voucher.metadata?.end_date, voucher.metadata?.expire_time);
1502
+ return formatVoucherValidityRange(startDate, endDate, locale, {
1503
+ startTime: voucher.start_time ?? voucher.metadata?.start_time,
1504
+ endTime: voucher.end_time ?? voucher.metadata?.end_time
1117
1505
  });
1118
1506
  }
1507
+ function formatVoucherAvailableTime(value, locale) {
1508
+ if (!isPresentId(value)) return '';
1509
+ if (Array.isArray(value)) {
1510
+ return value.map(item => formatVoucherAvailableTime(item, locale)).filter(Boolean).join(', ');
1511
+ }
1512
+ if (typeof value !== 'object') return stringify(value).trim();
1513
+ const start = firstPresentValue(value.start, value.start_at, value.start_date_time, value.start_date);
1514
+ const end = firstPresentValue(value.end, value.end_at, value.end_date_time, value.expire_time, value.expire_date, value.end_date);
1515
+ if (isPresentId(start) || isPresentId(end)) {
1516
+ return formatVoucherValidityRange(start, end, locale, {
1517
+ startTime: value.start_time,
1518
+ endTime: value.end_time
1519
+ });
1520
+ }
1521
+ return getLocalizedValue(value, locale).trim();
1522
+ }
1523
+ function formatVoucherValidityRange(startValue, endValue, locale, times = {}) {
1524
+ const start = combineVoucherDateAndTime(startValue, times.startTime);
1525
+ const end = combineVoucherDateAndTime(endValue, times.endTime);
1526
+ const startPart = formatVoucherValidityDate(start, locale);
1527
+ const endPart = formatVoucherValidityDate(end, locale);
1528
+ if (startPart.text && endPart.text) {
1529
+ const parsedStart = (0, _dayjs.default)(start);
1530
+ const parsedEnd = (0, _dayjs.default)(end);
1531
+ const sameDay = parsedStart.isValid() && parsedEnd.isValid() && parsedStart.isSame(parsedEnd, 'day');
1532
+ if (sameDay && startPart.time && endPart.time) {
1533
+ return `${startPart.time} - ${endPart.time} ${startPart.date}`;
1534
+ }
1535
+ return `${startPart.text} - ${endPart.text}`;
1536
+ }
1537
+ return startPart.text || endPart.text;
1538
+ }
1539
+ function combineVoucherDateAndTime(dateValue, timeValue) {
1540
+ if (!isPresentId(dateValue) || !isPresentId(timeValue)) return dateValue;
1541
+ const dateText = stringify(dateValue).trim();
1542
+ if (/\d{1,2}:\d{2}/.test(dateText)) return dateValue;
1543
+ return `${dateText} ${stringify(timeValue).trim()}`;
1544
+ }
1545
+ function formatVoucherValidityDate(value, locale) {
1546
+ if (!isPresentId(value)) return {
1547
+ date: '',
1548
+ time: '',
1549
+ text: ''
1550
+ };
1551
+ const source = stringify(value).trim();
1552
+ const parsed = (0, _dayjs.default)(source);
1553
+ if (!parsed.isValid()) return {
1554
+ date: '',
1555
+ time: '',
1556
+ text: source
1557
+ };
1558
+ const hasTime = /\d{1,2}:\d{2}/.test(source);
1559
+ const date = parsed.format(locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD');
1560
+ const time = hasTime ? parsed.format(/\d{1,2}:\d{2}:\d{2}/.test(source) ? 'HH:mm:ss' : 'HH:mm') : '';
1561
+ return {
1562
+ date,
1563
+ time,
1564
+ text: time ? `${time} ${date}` : date
1565
+ };
1566
+ }
1119
1567
  function getVoucherAssetKey(voucher, index) {
1120
1568
  const identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
1121
1569
  return identity === undefined ? `voucher-index:${index}` : `voucher:${String(identity)}`;
@@ -1153,12 +1601,14 @@ function buildPaymentItems(params) {
1153
1601
  payment,
1154
1602
  locale,
1155
1603
  currencySymbol,
1156
- includeFundRecordBalance
1604
+ includeFundRecordBalance,
1605
+ includeFundRecordUsage,
1606
+ includePaymentAmount
1157
1607
  } = params;
1158
1608
  const serviceFee = getPaymentServiceFee(payment);
1159
1609
  const items = [{
1160
1610
  item: paymentMethodName(payment, locale),
1161
- value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
1611
+ value: includePaymentAmount ? formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol) : ''
1162
1612
  }];
1163
1613
  items.push(...buildCashChangePaymentItems({
1164
1614
  payment,
@@ -1178,7 +1628,8 @@ function buildPaymentItems(params) {
1178
1628
  fundRecord,
1179
1629
  locale,
1180
1630
  currencySymbol,
1181
- includeBalance: includeFundRecordBalance
1631
+ includeBalance: includeFundRecordBalance,
1632
+ includeUsage: includeFundRecordUsage
1182
1633
  }));
1183
1634
  } else {
1184
1635
  const remainingAmount = payment.remaining_amount ?? payment.balance ?? payment.metadata?.remaining_amount;
@@ -1242,17 +1693,20 @@ function buildFundRecordPaymentItems(params) {
1242
1693
  fundRecord,
1243
1694
  locale,
1244
1695
  currencySymbol,
1245
- includeBalance
1696
+ includeBalance,
1697
+ includeUsage
1246
1698
  } = params;
1247
1699
  const items = [];
1248
1700
  const usingBeforeValue = fundRecord.using_before_value;
1249
1701
  const usingAfterValue = fundRecord.using_after_value;
1250
1702
  if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
1251
1703
  const usedPoints = new _decimal.default(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
1252
- items.push({
1253
- item: label(locale, 'redeemPoints'),
1254
- value: trimDecimal(usedPoints)
1255
- });
1704
+ if (includeUsage) {
1705
+ items.push({
1706
+ item: label(locale, 'redeemPoints'),
1707
+ value: trimDecimal(usedPoints)
1708
+ });
1709
+ }
1256
1710
  if (includeBalance) {
1257
1711
  items.push({
1258
1712
  item: label(locale, 'remainingPoints'),
@@ -1263,7 +1717,7 @@ function buildFundRecordPaymentItems(params) {
1263
1717
  }
1264
1718
  if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
1265
1719
  items.push({
1266
- item: label(locale, 'remainingAmount'),
1720
+ item: label(locale, 'balance'),
1267
1721
  value: formatMoney(usingAfterValue, currencySymbol)
1268
1722
  });
1269
1723
  }
@@ -1377,6 +1831,11 @@ function formatMoney(value, currencySymbol) {
1377
1831
  const amount = new _decimal.default(toMoneyNumber(value));
1378
1832
  return `${currencySymbol}${amount.toFixed(2)}`;
1379
1833
  }
1834
+ function formatCalculatedMoney(value, currencySymbol) {
1835
+ const amount = new _decimal.default(toMoneyNumber(value));
1836
+ const sign = amount.isNegative() ? '-' : '';
1837
+ return `${sign}${currencySymbol}${amount.abs().toFixed(2)}`;
1838
+ }
1380
1839
  function formatNegativeMoney(value, currencySymbol) {
1381
1840
  const amount = new _decimal.default(toMoneyNumber(value)).abs();
1382
1841
  return `-${currencySymbol}${amount.toFixed(2)}`;