@pisell/pisellos 0.10.32 → 0.10.33

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.
@@ -1,9 +0,0 @@
1
- // 导出评估器
2
- export { PromotionEvaluator } from "./evaluator";
3
-
4
- // 导出适配器
5
- export { PromotionAdapter } from "./adapter";
6
- export { default } from "./adapter";
7
-
8
- // 导出策略配置示例常量
9
- export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
@@ -33,7 +33,7 @@ export declare class OpenDataModule extends BaseModule implements Module {
33
33
  getOpenData(): OpenDataConfig | null;
34
34
  getInvoiceLayoutConfig(): InvoiceLayoutConfig;
35
35
  getInvoiceTemplateSettings(): InvoiceTemplateSettings;
36
- ensureInvoiceTemplateSettings(target: string): Promise<InvoiceTemplateSettings>;
36
+ ensureInvoiceTemplateSettings(target: string, openDataConfig?: OpenDataConfig): Promise<InvoiceTemplateSettings>;
37
37
  private commitInvoiceTemplateSettings;
38
38
  private resolveInvoiceTemplateSettings;
39
39
  private buildInvoiceTemplateCacheKey;
@@ -233,39 +233,47 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
233
233
  }, {
234
234
  key: "ensureInvoiceTemplateSettings",
235
235
  value: function () {
236
- var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target) {
236
+ var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target, openDataConfig) {
237
237
  var normalizedTarget, config, fetchRevision, resolved;
238
238
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
239
239
  while (1) switch (_context3.prev = _context3.next) {
240
240
  case 0:
241
241
  normalizedTarget = String(target || '').trim();
242
+ if (openDataConfig && openDataConfig !== this.store.data) {
243
+ // 部分解决方案会在初始化参数中直接收到已经拉取完成的 OpenData。
244
+ // 将它纳入模块状态后再解析 Document,避免为了 Invoice 重复请求 setting,
245
+ // 同时让后续同步 getter 能校验同一份 document id 与 target。
246
+ this.fetchRevision += 1;
247
+ this.store.data = openDataConfig;
248
+ this.store.lastFetchedAt = Date.now();
249
+ }
242
250
  config = this.store.data;
243
251
  if (!(!normalizedTarget || !config)) {
244
- _context3.next = 4;
252
+ _context3.next = 5;
245
253
  break;
246
254
  }
247
255
  return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
248
- case 4:
256
+ case 5:
249
257
  fetchRevision = this.fetchRevision;
250
- _context3.next = 7;
258
+ _context3.next = 8;
251
259
  return this.resolveInvoiceTemplateSettings(config, normalizedTarget);
252
- case 7:
260
+ case 8:
253
261
  resolved = _context3.sent;
254
262
  if (!(fetchRevision !== this.fetchRevision || this.store.data !== config)) {
255
- _context3.next = 10;
263
+ _context3.next = 11;
256
264
  break;
257
265
  }
258
266
  return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
259
- case 10:
267
+ case 11:
260
268
  this.commitInvoiceTemplateSettings(normalizedTarget, resolved);
261
269
  return _context3.abrupt("return", normalizeRawInvoiceTemplateSettings(resolved.settings));
262
- case 12:
270
+ case 13:
263
271
  case "end":
264
272
  return _context3.stop();
265
273
  }
266
274
  }, _callee3, this);
267
275
  }));
268
- function ensureInvoiceTemplateSettings(_x4) {
276
+ function ensureInvoiceTemplateSettings(_x4, _x5) {
269
277
  return _ensureInvoiceTemplateSettings.apply(this, arguments);
270
278
  }
271
279
  return ensureInvoiceTemplateSettings;
@@ -367,7 +375,7 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
367
375
  }
368
376
  }, _callee4, this);
369
377
  }));
370
- function resolveInvoiceTemplateSettings(_x5, _x6) {
378
+ function resolveInvoiceTemplateSettings(_x6, _x7) {
371
379
  return _resolveInvoiceTemplateSettings.apply(this, arguments);
372
380
  }
373
381
  return resolveInvoiceTemplateSettings;
@@ -424,7 +432,7 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
424
432
  }
425
433
  }, _callee5, this);
426
434
  }));
427
- function fetchInvoiceTemplateDocument(_x7) {
435
+ function fetchInvoiceTemplateDocument(_x8) {
428
436
  return _fetchInvoiceTemplateDocument.apply(this, arguments);
429
437
  }
430
438
  return fetchInvoiceTemplateDocument;
@@ -535,7 +535,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
535
535
  generateIdempotencyToken(): string;
536
536
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
537
537
  createOrder(params: CommitOrderParams['query']): {
538
- type: "appointment_booking" | "virtual";
538
+ type: "virtual" | "appointment_booking";
539
539
  platform: string;
540
540
  sales_channel: string;
541
541
  order_sales_channel: string;
@@ -33,9 +33,12 @@ export interface SmallTicketProduct {
33
33
  product_title: string;
34
34
  product_quantity: number;
35
35
  selling_price: string;
36
+ total_selling_price: string;
36
37
  original_price: string;
37
- base_price?: string;
38
+ base_price: string;
38
39
  total_original_price: string;
40
+ options_total_price?: string;
41
+ package_items_total_price?: string;
39
42
  extension_list: any[];
40
43
  product_uid?: string | number;
41
44
  booking_uid?: string | number;
@@ -44,6 +47,7 @@ export interface SmallTicketProduct {
44
47
  name: string;
45
48
  num?: number;
46
49
  price?: string;
50
+ total_price: string;
47
51
  value?: string;
48
52
  }>;
49
53
  variant?: string;
@@ -255,14 +255,14 @@ function buildLocaleData(params) {
255
255
  });
256
256
  }
257
257
  function buildBaseData(params) {
258
- var _order$metadata;
258
+ var _financials$amountGap, _order$metadata;
259
259
  var order = params.order,
260
260
  shopInfo = params.shopInfo,
261
261
  locale = params.locale,
262
262
  currencySymbol = params.currencySymbol,
263
263
  financials = params.financials;
264
264
  var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
265
- return _objectSpread(_objectSpread({
265
+ return _objectSpread({
266
266
  shop_name: stringify(shopInfo.name || order.shop_name),
267
267
  note: stringify(order.note),
268
268
  shop_order_number: stringify(order.shop_order_number),
@@ -273,10 +273,8 @@ function buildBaseData(params) {
273
273
  original_payment_status: financials.paymentStatus,
274
274
  payment_status: financials.paymentStatus,
275
275
  total_amount: formatMoney(financials.totalAmount, currencySymbol),
276
- has_pay: formatMoney(financials.netPaymentApplied, currencySymbol)
277
- }, isPresentId(financials.amountGap) ? {
278
- amount_gap: formatMoney(financials.amountGap, currencySymbol)
279
- } : {}), {}, {
276
+ has_pay: formatMoney(financials.netPaymentApplied, currencySymbol),
277
+ amount_gap: formatCalculatedMoney((_financials$amountGap = financials.amountGap) !== null && _financials$amountGap !== void 0 ? _financials$amountGap : 0, currencySymbol),
280
278
  is_repeat: 0,
281
279
  buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
282
280
  order_no: orderNumber,
@@ -328,15 +326,20 @@ function buildProducts(order, locale, productMap) {
328
326
  });
329
327
  var productNote = resolveProductNote(product, locale);
330
328
  var basePrice = resolveProductBasePrice(product);
331
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
329
+ var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
330
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
332
331
  product_title: productTitle,
333
332
  product_quantity: quantity,
334
333
  selling_price: formatMoney(sellingPrice, currencySymbol),
335
- original_price: formatMoney(originalPrice, currencySymbol)
336
- }, isPresentId(basePrice) ? {
337
- base_price: formatMoney(basePrice, currencySymbol)
334
+ total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
335
+ original_price: formatMoney(originalPrice, currencySymbol),
336
+ base_price: formatCalculatedMoney(basePrice !== null && basePrice !== void 0 ? basePrice : 0, currencySymbol),
337
+ total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol)
338
+ }, options.length ? {
339
+ options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
340
+ } : {}), resolvedCombinations.length ? {
341
+ package_items_total_price: sumCombinationTotals(resolvedCombinations, currencySymbol)
338
342
  } : {}), {}, {
339
- total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
340
343
  extension_list: extensionList
341
344
  }, isPresentId(productUid) ? {
342
345
  product_uid: productUid
@@ -348,10 +351,8 @@ function buildProducts(order, locale, productMap) {
348
351
  options: options
349
352
  } : {}), resolvedVariant ? {
350
353
  variant: resolvedVariant
351
- } : {}), Array.isArray(product.combinations) && product.combinations.length ? {
352
- combinations: normalizeExistingCombinations(product.combinations, locale)
353
- } : combinations.length ? {
354
- combinations: combinations
354
+ } : {}), resolvedCombinations.length ? {
355
+ combinations: resolvedCombinations
355
356
  } : {});
356
357
  });
357
358
  }
@@ -488,9 +489,10 @@ function normalizeProductOptions(params) {
488
489
  parentProduct = params.parentProduct;
489
490
  var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option) ? product.product_sku.option : [];
490
491
  return rawOptions.map(function (option) {
491
- var _ref14, _option$original_pric, _ref15, _option$value, _option$num;
492
+ var _ref14, _option$original_pric, _ref15, _option$num, _ref16, _option$value;
492
493
  var price = (_ref14 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref14 !== void 0 ? _ref14 : option.price;
493
- var value = (_ref15 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref15 !== void 0 ? _ref15 : option.item;
494
+ var quantity = toNumber((_ref15 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref15 !== void 0 ? _ref15 : 1, 1);
495
+ var value = (_ref16 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref16 !== void 0 ? _ref16 : option.item;
494
496
  var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
495
497
  option: option,
496
498
  parentProduct: parentProduct,
@@ -499,10 +501,12 @@ function normalizeProductOptions(params) {
499
501
  return _objectSpread(_objectSpread(_objectSpread({
500
502
  name: name
501
503
  }, option.num !== undefined || option.quantity !== undefined ? {
502
- num: toNumber((_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity, 1)
504
+ num: quantity
503
505
  } : {}), price !== undefined && price !== null && price !== '' ? {
504
506
  price: formatMoney(price, currencySymbol)
505
- } : {}), value !== undefined && value !== null && value !== '' ? {
507
+ } : {}), {}, {
508
+ total_price: formatCalculatedMoney(new Decimal(toMoneyNumber(price !== null && price !== void 0 ? price : 0)).mul(quantity), currencySymbol)
509
+ }, value !== undefined && value !== null && value !== '' ? {
506
510
  value: getLocalizedValue(value, locale)
507
511
  } : {});
508
512
  });
@@ -515,7 +519,7 @@ function normalizeProductCombinations(params) {
515
519
  parentProduct = params.parentProduct;
516
520
  var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
517
521
  return bundles.map(function (bundle) {
518
- var _ref16, _bundle$num;
522
+ var _ref17, _bundle$num, _bundle$metadata;
519
523
  var combinationsOptions = normalizeProductOptions({
520
524
  product: {},
521
525
  locale: locale,
@@ -530,43 +534,97 @@ function normalizeProductCombinations(params) {
530
534
  parentProduct: parentProduct
531
535
  });
532
536
  var productNote = resolveProductNote(bundle, locale);
533
- var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
534
- return _objectSpread(_objectSpread({
537
+ var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
538
+ var quantity = toNumber((_ref17 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref17 !== void 0 ? _ref17 : 1, 1);
539
+ var formattedPrice = formatBundlePrice(bundle, currencySymbol);
540
+ var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
541
+ var explicitBasePrice = firstPresentValue(bundle.base_price, (_bundle$metadata = bundle.metadata) === null || _bundle$metadata === void 0 ? void 0 : _bundle$metadata.source_product_price);
542
+ var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
543
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({
535
544
  product_title: baseTitle,
536
- product_quantity: toNumber((_ref16 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref16 !== void 0 ? _ref16 : 1, 1),
537
- price: formatBundlePrice(bundle, currencySymbol),
545
+ product_quantity: quantity,
546
+ price: formattedPrice,
547
+ total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol),
548
+ base_price: formatCalculatedMoney(basePrice, currencySymbol),
538
549
  combinations_options: combinationsOptions
539
- }, productNote ? {
550
+ }, combinationsOptions.length ? {
551
+ options_total_price: optionsTotal
552
+ } : {}), nestedCombinations.length ? {
553
+ package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
554
+ } : {}), productNote ? {
540
555
  product_note: productNote
541
556
  } : {}), nestedCombinations.length ? {
542
557
  combinations: nestedCombinations
543
558
  } : {});
544
559
  });
545
560
  }
546
- function normalizeExistingCombinations(combinations, locale) {
561
+ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
547
562
  return combinations.map(function (combination) {
563
+ var _ref18, _ref19, _combination$product_, _firstPresentValue;
548
564
  if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
549
565
  return combination;
550
566
  }
551
567
  var productNote = resolveProductNote(combination, locale);
552
- var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale) : undefined;
568
+ var rawOptions = Array.isArray(combination.combinations_options) ? combination.combinations_options : Array.isArray(combination.options) ? combination.options : [];
569
+ var normalizedOptions = normalizeProductOptions({
570
+ product: {},
571
+ locale: locale,
572
+ currencySymbol: currencySymbol,
573
+ options: rawOptions
574
+ });
575
+ var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
553
576
  var snapshot = _objectSpread({}, combination);
554
577
  delete snapshot.product_note;
555
578
  delete snapshot.note;
556
- return _objectSpread(_objectSpread(_objectSpread({}, snapshot), productNote ? {
579
+ delete snapshot.combinations;
580
+ var quantity = toNumber((_ref18 = (_ref19 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref19 !== void 0 ? _ref19 : combination.quantity) !== null && _ref18 !== void 0 ? _ref18 : 1, 1);
581
+ var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
582
+ var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
583
+ return option.total_price;
584
+ }));
585
+ var explicitBasePrice = firstPresentValue(combination.base_price);
586
+ var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
587
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), {}, {
588
+ product_quantity: quantity,
589
+ total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol),
590
+ base_price: formatCalculatedMoney(basePrice, currencySymbol)
591
+ }, Array.isArray(combination.combinations_options) ? {
592
+ combinations_options: normalizedOptions
593
+ } : Array.isArray(combination.options) ? {
594
+ options: normalizedOptions
595
+ } : {}), normalizedOptions.length ? {
596
+ options_total_price: formatCalculatedMoney(optionsAmount, currencySymbol)
597
+ } : {}), nestedCombinations.length ? {
598
+ package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
599
+ } : {}), productNote ? {
557
600
  product_note: productNote
558
- } : {}), nestedCombinations ? {
601
+ } : {}), nestedCombinations.length ? {
559
602
  combinations: nestedCombinations
560
603
  } : {});
561
604
  });
562
605
  }
606
+ function sumMoneyValues(values) {
607
+ return values.reduce(function (sum, value) {
608
+ return sum.plus(toMoneyNumber(value));
609
+ }, new Decimal(0));
610
+ }
611
+ function sumNormalizedOptionTotals(options, currencySymbol) {
612
+ return formatCalculatedMoney(sumMoneyValues(options.map(function (option) {
613
+ return option.total_price;
614
+ })), currencySymbol);
615
+ }
616
+ function sumCombinationTotals(combinations, currencySymbol) {
617
+ return formatCalculatedMoney(sumMoneyValues(combinations.map(function (combination) {
618
+ return combination.total_selling_price;
619
+ })), currencySymbol);
620
+ }
563
621
  function resolveProductNote(product, locale) {
564
622
  var productNote = getLocalizedValue(product.product_note, locale).trim();
565
623
  if (productNote) return productNote;
566
624
  return getLocalizedValue(product.note, locale).trim();
567
625
  }
568
626
  function resolveBundleProductTitle(params) {
569
- var _ref17, _ref18, _bundle$bundle_produc;
627
+ var _ref20, _ref21, _bundle$bundle_produc;
570
628
  var bundle = params.bundle,
571
629
  productMap = params.productMap,
572
630
  locale = params.locale,
@@ -579,7 +637,7 @@ function resolveBundleProductTitle(params) {
579
637
  });
580
638
  var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
581
639
  if (parentBundleTitle) return parentBundleTitle;
582
- var productId = (_ref17 = (_ref18 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref18 !== void 0 ? _ref18 : bundle.product_id) !== null && _ref17 !== void 0 ? _ref17 : bundle.id;
640
+ var productId = (_ref20 = (_ref21 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref21 !== void 0 ? _ref21 : bundle.product_id) !== null && _ref20 !== void 0 ? _ref20 : bundle.id;
583
641
  var fallbackProduct = resolveProductFromMap(productId, productMap);
584
642
  if (!fallbackProduct) return '';
585
643
  return getProductTitleSource(fallbackProduct, locale);
@@ -631,10 +689,10 @@ function resolveVariantTextFromSkuKey(params) {
631
689
  }
632
690
  function resolveVariantTextFromNameMap(params) {
633
691
  if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
634
- return Object.entries(params.nameMap).map(function (_ref19) {
635
- var _ref20 = _slicedToArray(_ref19, 2),
636
- groupPositionId = _ref20[0],
637
- value = _ref20[1];
692
+ return Object.entries(params.nameMap).map(function (_ref22) {
693
+ var _ref23 = _slicedToArray(_ref22, 2),
694
+ groupPositionId = _ref23[0],
695
+ value = _ref23[1];
638
696
  var group = resolveVariantGroup(params.parentProduct, groupPositionId);
639
697
  if (!group) return '';
640
698
  var groupName = getLocalizedValue(group.name, params.locale);
@@ -668,12 +726,12 @@ function getProductTitleSource(source, locale) {
668
726
  return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
669
727
  }
670
728
  function resolveTitleValue(value, locale) {
671
- var _ref21, _ref22, _ref23, _ref24, _value$locale;
729
+ var _ref24, _ref25, _ref26, _ref27, _value$locale;
672
730
  if (value === undefined || value === null) return '';
673
731
  if (_typeof(value) !== 'object') return stringify(value);
674
732
  var dashedLocale = locale.replace('_', '-');
675
733
  var underscoredLocale = locale.replace('-', '_');
676
- return stringify((_ref21 = (_ref22 = (_ref23 = (_ref24 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref24 !== void 0 ? _ref24 : value[underscoredLocale]) !== null && _ref23 !== void 0 ? _ref23 : value.original) !== null && _ref22 !== void 0 ? _ref22 : value.auto) !== null && _ref21 !== void 0 ? _ref21 : '');
734
+ return stringify((_ref24 = (_ref25 = (_ref26 = (_ref27 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref27 !== void 0 ? _ref27 : value[underscoredLocale]) !== null && _ref26 !== void 0 ? _ref26 : value.original) !== null && _ref25 !== void 0 ? _ref25 : value.auto) !== null && _ref24 !== void 0 ? _ref24 : '');
677
735
  }
678
736
  function resolveOptionTitleFromParentProduct(params) {
679
737
  var option = params.option,
@@ -691,17 +749,17 @@ function flattenOptionItems(parentProduct) {
691
749
  return optionGroups.flatMap(function (group) {
692
750
  var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
693
751
  return items.map(function (item) {
694
- var _ref25, _item$option_group_id;
752
+ var _ref28, _item$option_group_id;
695
753
  return _objectSpread(_objectSpread({}, item), {}, {
696
- option_group_id: (_ref25 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref25 !== void 0 ? _ref25 : group.option_group_id
754
+ option_group_id: (_ref28 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref28 !== void 0 ? _ref28 : group.option_group_id
697
755
  });
698
756
  });
699
757
  });
700
758
  }
701
759
  function isOptionItemMatch(option, item) {
702
- var _ref26, _option$option_group_, _ref27, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
703
- var optionItemId = (_ref26 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref26 !== void 0 ? _ref26 : option.id;
704
- var itemId = (_ref27 = (_item$option_group_it = item.option_group_item_id) !== null && _item$option_group_it !== void 0 ? _item$option_group_it : item.product_option_item_id) !== null && _ref27 !== void 0 ? _ref27 : item.id;
760
+ var _ref29, _option$option_group_, _ref30, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
761
+ var optionItemId = (_ref29 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref29 !== void 0 ? _ref29 : option.id;
762
+ var itemId = (_ref30 = (_item$option_group_it = item.option_group_item_id) !== null && _item$option_group_it !== void 0 ? _item$option_group_it : item.product_option_item_id) !== null && _ref30 !== void 0 ? _ref30 : item.id;
705
763
  if (!isSameId(optionItemId, itemId)) return false;
706
764
  var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
707
765
  var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
@@ -711,16 +769,16 @@ function isOptionItemMatch(option, item) {
711
769
  return true;
712
770
  }
713
771
  function resolveBundleItemFromParentProduct(params) {
714
- var _ref28, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref30, _bundle$bundle_produc2;
772
+ var _ref31, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref33, _bundle$bundle_produc2;
715
773
  var bundle = params.bundle,
716
774
  parentProduct = params.parentProduct;
717
775
  if (!parentProduct) return null;
718
776
  var bundleItems = flattenBundleItems(parentProduct);
719
- var bundleVariantId = (_ref28 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref28 !== void 0 ? _ref28 : bundle.product_variant_id;
777
+ var bundleVariantId = (_ref31 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref31 !== void 0 ? _ref31 : bundle.product_variant_id;
720
778
  if (isNonZeroId(bundleVariantId)) {
721
779
  var matchedByVariant = bundleItems.find(function (item) {
722
- var _ref29, _item$bundle_variant_;
723
- return isSameId((_ref29 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref29 !== void 0 ? _ref29 : item.product_variant_id, bundleVariantId);
780
+ var _ref32, _item$bundle_variant_;
781
+ return isSameId((_ref32 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref32 !== void 0 ? _ref32 : item.product_variant_id, bundleVariantId);
724
782
  });
725
783
  if (matchedByVariant) return matchedByVariant;
726
784
  }
@@ -733,18 +791,18 @@ function resolveBundleItemFromParentProduct(params) {
733
791
  if (matchedByBundleId) return matchedByBundleId;
734
792
  }
735
793
  var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
736
- var bundleProductId = (_ref30 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref30 !== void 0 ? _ref30 : bundle.product_id;
794
+ var bundleProductId = (_ref33 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref33 !== void 0 ? _ref33 : bundle.product_id;
737
795
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
738
796
  var matchedByGroupAndProduct = bundleItems.find(function (item) {
739
- var _item$group_id, _ref31, _item$bundle_product_;
740
- return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref31 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref31 !== void 0 ? _ref31 : item.product_id, bundleProductId);
797
+ var _item$group_id, _ref34, _item$bundle_product_;
798
+ return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref34 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref34 !== void 0 ? _ref34 : item.product_id, bundleProductId);
741
799
  });
742
800
  if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
743
801
  }
744
802
  if (isPresentId(bundleProductId)) {
745
803
  return bundleItems.find(function (item) {
746
- var _ref32, _item$bundle_product_2;
747
- return isSameId((_ref32 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref32 !== void 0 ? _ref32 : item.product_id, bundleProductId);
804
+ var _ref35, _item$bundle_product_2;
805
+ return isSameId((_ref35 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref35 !== void 0 ? _ref35 : item.product_id, bundleProductId);
748
806
  }) || null;
749
807
  }
750
808
  return null;
@@ -754,9 +812,9 @@ function flattenBundleItems(parentProduct) {
754
812
  return bundleGroups.flatMap(function (group) {
755
813
  var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
756
814
  return items.map(function (item) {
757
- var _ref33, _item$group_id2;
815
+ var _ref36, _item$group_id2;
758
816
  return _objectSpread(_objectSpread({}, item), {}, {
759
- group_id: (_ref33 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref33 !== void 0 ? _ref33 : group.group_id
817
+ group_id: (_ref36 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref36 !== void 0 ? _ref36 : group.group_id
760
818
  });
761
819
  });
762
820
  });
@@ -780,8 +838,8 @@ function isSameId(left, right) {
780
838
  return String(left) === String(right);
781
839
  }
782
840
  function formatBundlePrice(bundle, currencySymbol) {
783
- var _ref34, _ref35, _bundle$bundle_sellin;
784
- var value = (_ref34 = (_ref35 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref35 !== void 0 ? _ref35 : bundle.price) !== null && _ref34 !== void 0 ? _ref34 : 0;
841
+ var _ref37, _ref38, _bundle$bundle_sellin;
842
+ var value = (_ref37 = (_ref38 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref38 !== void 0 ? _ref38 : bundle.price) !== null && _ref37 !== void 0 ? _ref37 : 0;
785
843
  var amount = new Decimal(toMoneyNumber(value));
786
844
  // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
787
845
  var isNegative = bundle.price_type === 'markdown';
@@ -789,7 +847,7 @@ function formatBundlePrice(bundle, currencySymbol) {
789
847
  return formatMoney(amount, currencySymbol);
790
848
  }
791
849
  function buildFees(params) {
792
- var _firstPresentValue, _firstPresentValue2;
850
+ var _firstPresentValue2, _firstPresentValue3;
793
851
  var order = params.order,
794
852
  shopInfo = params.shopInfo,
795
853
  locale = params.locale,
@@ -799,9 +857,9 @@ function buildFees(params) {
799
857
  financials = params.financials;
800
858
  var fees = [];
801
859
  for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
802
- var _ref36, _surcharge$amount;
860
+ var _ref39, _surcharge$amount;
803
861
  var surcharge = _normalizeArray[_i];
804
- var value = (_ref36 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref36 !== void 0 ? _ref36 : surcharge.total_amount;
862
+ var value = (_ref39 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref39 !== void 0 ? _ref39 : surcharge.total_amount;
805
863
  if (!isNonZero(value)) continue;
806
864
  fees.push({
807
865
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
@@ -838,14 +896,16 @@ function buildFees(params) {
838
896
  });
839
897
  }
840
898
  var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
841
- var productOriginalAmount = (_firstPresentValue = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : calculateProductOriginalAmount(order);
899
+ var productOriginalAmount = (_firstPresentValue2 = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : calculateProductOriginalAmount(order);
842
900
  var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
901
+ var itemDiscountAmount = new Decimal(toMoneyNumber(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0)).minus(toMoneyNumber(productOriginalAmount));
843
902
  return {
844
903
  fees: fees,
845
904
  countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
846
- total_amount: formatMoney((_firstPresentValue2 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : 0, currencySymbol),
905
+ total_amount: formatMoney((_firstPresentValue3 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0, currencySymbol),
847
906
  original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
848
907
  product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
908
+ item_discount_amount: formatCalculatedMoney(itemDiscountAmount, currencySymbol),
849
909
  expect_amount: formatMoney(financials.totalAmount, currencySymbol),
850
910
  product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
851
911
  return sum + product.product_quantity;
@@ -870,15 +930,15 @@ function buildFees(params) {
870
930
  };
871
931
  }
872
932
  function resolveReceiptFinancials(order, summary) {
873
- var _firstPresentValue3, _firstPresentValue4, _firstPresentValue5, _firstPresentValue6;
874
- var totalAmount = (_firstPresentValue3 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0;
933
+ var _firstPresentValue4, _firstPresentValue5, _firstPresentValue6, _firstPresentValue7;
934
+ var totalAmount = (_firstPresentValue4 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
875
935
  var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
876
936
  var payProcessingFee = rawPayProcessingFee !== null && rawPayProcessingFee !== void 0 ? rawPayProcessingFee : 0;
877
- var orderPaidAmount = (_firstPresentValue4 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
878
- var totalRefundAmount = (_firstPresentValue5 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
937
+ var orderPaidAmount = (_firstPresentValue5 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
938
+ var totalRefundAmount = (_firstPresentValue6 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
879
939
  var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
880
940
  var fallbackCustomerPaidAmount = Decimal.max(sumCustomerPaidPayments(order.payments), new Decimal(toMoneyNumber(orderPaidAmount)).plus(toMoneyNumber(payProcessingFee)));
881
- var customerPaidAmount = (_firstPresentValue6 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
941
+ var customerPaidAmount = (_firstPresentValue7 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
882
942
  var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
883
943
  return {
884
944
  totalAmount: totalAmount,
@@ -907,9 +967,9 @@ function resolveTaxTitle(params) {
907
967
  }
908
968
  function calculateProductOriginalAmount(order) {
909
969
  return normalizeArray(order.products).reduce(function (total, product) {
910
- var _ref37, _ref38, _product$product_quan2, _ref39, _ref40, _ref41, _product$original_pri2;
911
- var quantity = toNumber((_ref37 = (_ref38 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref38 !== void 0 ? _ref38 : product.num) !== null && _ref37 !== void 0 ? _ref37 : 1, 1);
912
- var originalPrice = (_ref39 = (_ref40 = (_ref41 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref41 !== void 0 ? _ref41 : product.payment_price) !== null && _ref40 !== void 0 ? _ref40 : product.price) !== null && _ref39 !== void 0 ? _ref39 : 0;
970
+ var _ref40, _ref41, _product$product_quan2, _ref42, _ref43, _ref44, _product$original_pri2;
971
+ var quantity = toNumber((_ref40 = (_ref41 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref41 !== void 0 ? _ref41 : product.num) !== null && _ref40 !== void 0 ? _ref40 : 1, 1);
972
+ var originalPrice = (_ref42 = (_ref43 = (_ref44 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref44 !== void 0 ? _ref44 : product.payment_price) !== null && _ref43 !== void 0 ? _ref43 : product.price) !== null && _ref42 !== void 0 ? _ref42 : 0;
913
973
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
914
974
  }, new Decimal(0));
915
975
  }
@@ -997,8 +1057,8 @@ function sortBookings(bookings) {
997
1057
  }
998
1058
  var bookingUidOrder = compareOptionalValues(firstPresentValue((_left$booking2 = left.booking) === null || _left$booking2 === void 0 || (_left$booking2 = _left$booking2.metadata) === null || _left$booking2 === void 0 ? void 0 : _left$booking2.unique_identification_number, (_left$booking3 = left.booking) === null || _left$booking3 === void 0 ? void 0 : _left$booking3.booking_uid), firstPresentValue((_right$booking2 = right.booking) === null || _right$booking2 === void 0 || (_right$booking2 = _right$booking2.metadata) === null || _right$booking2 === void 0 ? void 0 : _right$booking2.unique_identification_number, (_right$booking3 = right.booking) === null || _right$booking3 === void 0 ? void 0 : _right$booking3.booking_uid));
999
1059
  return bookingUidOrder || left.index - right.index;
1000
- }).map(function (_ref42) {
1001
- var booking = _ref42.booking;
1060
+ }).map(function (_ref45) {
1061
+ var booking = _ref45.booking;
1002
1062
  return booking;
1003
1063
  });
1004
1064
  }
@@ -1060,8 +1120,8 @@ function buildRefundData(params) {
1060
1120
  result.set(identity, candidate);
1061
1121
  }
1062
1122
  return result;
1063
- }, new Map()).values()).filter(function (_ref43) {
1064
- var refund = _ref43.refund;
1123
+ }, new Map()).values()).filter(function (_ref46) {
1124
+ var refund = _ref46.refund;
1065
1125
  return isPrintableRefund(refund);
1066
1126
  }).sort(function (left, right) {
1067
1127
  var leftTime = refundTimestamp(left.refund);
@@ -1069,12 +1129,12 @@ function buildRefundData(params) {
1069
1129
  if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1070
1130
  return left.index - right.index;
1071
1131
  });
1072
- return refunds.map(function (_ref44) {
1073
- var _firstPresentValue7;
1074
- var refund = _ref44.refund;
1132
+ return refunds.map(function (_ref47) {
1133
+ var _firstPresentValue8;
1134
+ var refund = _ref47.refund;
1075
1135
  var payment = resolveRefundPayment(refund, payments);
1076
1136
  var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
1077
- var amount = (_firstPresentValue7 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
1137
+ var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
1078
1138
  var items = [{
1079
1139
  item: methodName,
1080
1140
  value: formatNegativeMoney(amount, params.currencySymbol)
@@ -1292,8 +1352,8 @@ function buildPaymentItems(params) {
1292
1352
  includeUsage: includeFundRecordUsage
1293
1353
  })));
1294
1354
  } else {
1295
- var _ref45, _payment$remaining_am, _payment$metadata;
1296
- var remainingAmount = (_ref45 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref45 !== void 0 ? _ref45 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
1355
+ var _ref48, _payment$remaining_am, _payment$metadata;
1356
+ var remainingAmount = (_ref48 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref48 !== void 0 ? _ref48 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
1297
1357
  if (remainingAmount !== undefined && remainingAmount !== null) {
1298
1358
  items.push({
1299
1359
  item: label(locale, 'remainingAmount'),
@@ -1447,12 +1507,12 @@ function label(locale, key) {
1447
1507
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
1448
1508
  }
1449
1509
  function getLocalizedValue(value, locale) {
1450
- var _ref46, _ref47, _ref48, _ref49, _ref50, _ref51, _value$locale2;
1510
+ var _ref49, _ref50, _ref51, _ref52, _ref53, _ref54, _value$locale2;
1451
1511
  if (value === undefined || value === null) return '';
1452
1512
  if (_typeof(value) !== 'object') return stringify(value);
1453
1513
  var dashedLocale = locale.replace('_', '-');
1454
1514
  var underscoredLocale = locale.replace('-', '_');
1455
- return stringify((_ref46 = (_ref47 = (_ref48 = (_ref49 = (_ref50 = (_ref51 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref51 !== void 0 ? _ref51 : value[underscoredLocale]) !== null && _ref50 !== void 0 ? _ref50 : value.original) !== null && _ref49 !== void 0 ? _ref49 : value.auto) !== null && _ref48 !== void 0 ? _ref48 : value.default) !== null && _ref47 !== void 0 ? _ref47 : value.en) !== null && _ref46 !== void 0 ? _ref46 : '');
1515
+ return stringify((_ref49 = (_ref50 = (_ref51 = (_ref52 = (_ref53 = (_ref54 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref54 !== void 0 ? _ref54 : value[underscoredLocale]) !== null && _ref53 !== void 0 ? _ref53 : value.original) !== null && _ref52 !== void 0 ? _ref52 : value.auto) !== null && _ref51 !== void 0 ? _ref51 : value.default) !== null && _ref50 !== void 0 ? _ref50 : value.en) !== null && _ref49 !== void 0 ? _ref49 : '');
1456
1516
  }
1457
1517
  function resolveServiceTypeLabelKey(serviceType, order) {
1458
1518
  var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
@@ -1494,6 +1554,11 @@ function formatMoney(value, currencySymbol) {
1494
1554
  var amount = new Decimal(toMoneyNumber(value));
1495
1555
  return "".concat(currencySymbol).concat(amount.toFixed(2));
1496
1556
  }
1557
+ function formatCalculatedMoney(value, currencySymbol) {
1558
+ var amount = new Decimal(toMoneyNumber(value));
1559
+ var sign = amount.isNegative() ? '-' : '';
1560
+ return "".concat(sign).concat(currencySymbol).concat(amount.abs().toFixed(2));
1561
+ }
1497
1562
  function formatNegativeMoney(value, currencySymbol) {
1498
1563
  var amount = new Decimal(toMoneyNumber(value)).abs();
1499
1564
  return "-".concat(currencySymbol).concat(amount.toFixed(2));