@pisell/pisellos 2.2.259 → 2.2.260

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 (103) hide show
  1. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +49 -0
  2. package/dist/model/strategy/adapter/dataVariant/adapter.js +152 -0
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +87 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.js +755 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  6. package/dist/model/strategy/adapter/dataVariant/examples.js +282 -0
  7. package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  8. package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
  9. package/dist/model/strategy/adapter/dataVariant/type.d.ts +146 -0
  10. package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
  11. package/dist/model/strategy/adapter/index.d.ts +4 -0
  12. package/dist/model/strategy/adapter/index.js +5 -1
  13. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +13 -17
  14. package/dist/modules/Order/index.d.ts +1 -32
  15. package/dist/modules/Order/index.js +288 -615
  16. package/dist/modules/Order/types.d.ts +2 -20
  17. package/dist/modules/Order/utils.d.ts +0 -4
  18. package/dist/modules/Order/utils.js +28 -114
  19. package/dist/modules/Product/index.d.ts +1 -1
  20. package/dist/modules/Product/types.d.ts +22 -0
  21. package/dist/modules/ProductList/index.d.ts +1 -1
  22. package/dist/modules/ProductList/index.js +4 -2
  23. package/dist/modules/ProductList/types.d.ts +2 -0
  24. package/dist/modules/Rules/index.d.ts +3 -3
  25. package/dist/modules/Rules/index.js +3 -8
  26. package/dist/modules/Rules/types.d.ts +1 -2
  27. package/dist/modules/SalesSummary/index.d.ts +3 -7
  28. package/dist/modules/SalesSummary/index.js +39 -67
  29. package/dist/modules/SalesSummary/types.d.ts +0 -1
  30. package/dist/modules/SalesSummary/utils.js +1 -2
  31. package/dist/modules/SurchargeList/index.d.ts +4 -6
  32. package/dist/modules/SurchargeList/index.js +39 -62
  33. package/dist/modules/SurchargeList/types.d.ts +2 -6
  34. package/dist/server/index.d.ts +50 -3
  35. package/dist/server/index.js +1040 -1075
  36. package/dist/server/modules/order/index.d.ts +3 -22
  37. package/dist/server/modules/order/index.js +316 -398
  38. package/dist/server/modules/products/index.d.ts +26 -7
  39. package/dist/server/modules/products/index.js +166 -76
  40. package/dist/server/modules/products/types.d.ts +14 -0
  41. package/dist/solution/BaseSales/index.d.ts +2 -22
  42. package/dist/solution/BaseSales/index.js +701 -995
  43. package/dist/solution/BaseSales/types.d.ts +0 -1
  44. package/dist/solution/BaseSales/types.js +1 -2
  45. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -6
  46. package/dist/solution/BookingByStep/index.d.ts +1 -1
  47. package/dist/solution/BookingTicket/index.d.ts +0 -8
  48. package/dist/solution/BookingTicket/index.js +6 -153
  49. package/dist/solution/BookingTicket/types.d.ts +2 -0
  50. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +49 -0
  51. package/lib/model/strategy/adapter/dataVariant/adapter.js +139 -0
  52. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +87 -0
  53. package/lib/model/strategy/adapter/dataVariant/evaluator.js +564 -0
  54. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  55. package/lib/model/strategy/adapter/dataVariant/examples.js +295 -0
  56. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  57. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  58. package/lib/model/strategy/adapter/dataVariant/type.d.ts +146 -0
  59. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  60. package/lib/model/strategy/adapter/index.d.ts +4 -0
  61. package/lib/model/strategy/adapter/index.js +13 -2
  62. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +1 -11
  63. package/lib/modules/Order/index.d.ts +1 -32
  64. package/lib/modules/Order/index.js +64 -402
  65. package/lib/modules/Order/types.d.ts +2 -20
  66. package/lib/modules/Order/utils.d.ts +0 -4
  67. package/lib/modules/Order/utils.js +2 -84
  68. package/lib/modules/Product/index.d.ts +1 -1
  69. package/lib/modules/Product/types.d.ts +22 -0
  70. package/lib/modules/ProductList/index.d.ts +1 -1
  71. package/lib/modules/ProductList/index.js +4 -2
  72. package/lib/modules/ProductList/types.d.ts +2 -0
  73. package/lib/modules/Rules/index.d.ts +3 -3
  74. package/lib/modules/Rules/index.js +3 -4
  75. package/lib/modules/Rules/types.d.ts +1 -2
  76. package/lib/modules/SalesSummary/index.d.ts +3 -7
  77. package/lib/modules/SalesSummary/index.js +11 -28
  78. package/lib/modules/SalesSummary/types.d.ts +0 -1
  79. package/lib/modules/SalesSummary/utils.js +0 -2
  80. package/lib/modules/SurchargeList/index.d.ts +4 -6
  81. package/lib/modules/SurchargeList/index.js +21 -41
  82. package/lib/modules/SurchargeList/types.d.ts +2 -6
  83. package/lib/server/index.d.ts +50 -3
  84. package/lib/server/index.js +215 -244
  85. package/lib/server/modules/order/index.d.ts +3 -22
  86. package/lib/server/modules/order/index.js +53 -103
  87. package/lib/server/modules/products/index.d.ts +26 -7
  88. package/lib/server/modules/products/index.js +113 -35
  89. package/lib/server/modules/products/types.d.ts +14 -0
  90. package/lib/solution/BaseSales/index.d.ts +2 -22
  91. package/lib/solution/BaseSales/index.js +60 -246
  92. package/lib/solution/BaseSales/types.d.ts +0 -1
  93. package/lib/solution/BaseSales/types.js +1 -2
  94. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -6
  95. package/lib/solution/BookingByStep/index.d.ts +1 -1
  96. package/lib/solution/BookingTicket/index.d.ts +0 -8
  97. package/lib/solution/BookingTicket/index.js +0 -101
  98. package/lib/solution/BookingTicket/types.d.ts +2 -0
  99. package/package.json +1 -1
  100. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +0 -5
  101. package/dist/modules/Order/utils/bundleDiscountHydration.js +0 -144
  102. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +0 -5
  103. package/lib/modules/Order/utils/bundleDiscountHydration.js +0 -139
@@ -40,7 +40,6 @@ var import_dayjs = __toESM(require("dayjs"));
40
40
  var import_cartPromotion = require("../../solution/BaseSales/utils/cartPromotion");
41
41
  var import_utils3 = require("../../solution/ScanOrder/utils");
42
42
  var import_manualProductDiscount = require("./utils/manualProductDiscount");
43
- var import_bundleDiscountHydration = require("./utils/bundleDiscountHydration");
44
43
  var import_Discount = require("../Discount");
45
44
  var import_Rules = require("../Rules");
46
45
  var import_types2 = require("../Rules/types");
@@ -65,23 +64,6 @@ function isManualProductDiscountProduct(product) {
65
64
  var _a, _b;
66
65
  return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
67
66
  }
68
- var ORDER_PAYMENT_STATUS_PAID = "paid";
69
- var ORDER_PAYMENT_STATUS_PENDING = "payment_pending";
70
- function isVoucherPaymentRecord(payment) {
71
- return (payment == null ? void 0 : payment.voucher_id) !== void 0 && Number(payment.voucher_id) !== 0;
72
- }
73
- function hasSyncedOrderPaymentRecord(payment) {
74
- return (payment == null ? void 0 : payment.order_payment_id) !== void 0 && payment.order_payment_id !== null;
75
- }
76
- function isPendingVoucherPaymentRecord(payment) {
77
- return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PENDING;
78
- }
79
- function isPaidPaymentRecord(payment) {
80
- return (payment == null ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PAID;
81
- }
82
- function isCommittedVoucherPaymentRecord(payment) {
83
- return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) !== "voided" && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
84
- }
85
67
  var OrderModule = class extends import_BaseModule.BaseModule {
86
68
  constructor(name, version) {
87
69
  super(name || "order", version);
@@ -109,7 +91,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
109
91
  collectHydratedEditDiscounts(products) {
110
92
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
111
93
  const discountMap = /* @__PURE__ */ new Map();
112
- for (const product of (0, import_bundleDiscountHydration.expandHydratedProductsForDiscountCollection)(products)) {
94
+ for (const product of products || []) {
113
95
  for (const item of (product == null ? void 0 : product.discount_list) || []) {
114
96
  const type = (item == null ? void 0 : item.type) ?? (item == null ? void 0 : item.tag);
115
97
  if (!type || type === "product")
@@ -132,21 +114,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
132
114
  discount: item == null ? void 0 : item.discount,
133
115
  _num: Number(((_e = item == null ? void 0 : item.metadata) == null ? void 0 : _e.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1
134
116
  };
135
- const existed = discountMap.get(key);
136
- if (existed) {
137
- existed.amount = Number(existed.amount || 0) + amount;
138
- existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
139
- existed.balance = String(Number(existed.balance || 0) + amount);
140
- existed.applicableProductDetails = [
141
- ...existed.applicableProductDetails || [],
142
- detail
143
- ];
144
- existed.appliedProductDetails = [
145
- ...existed.appliedProductDetails || [],
146
- detail
147
- ];
148
- continue;
149
- }
150
117
  discountMap.set(key, {
151
118
  id: key,
152
119
  product_name: "",
@@ -269,21 +236,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
269
236
  product.metadata.main_product_selling_price = newMainSellingPrice;
270
237
  product.metadata.price_schema_version = 2;
271
238
  }
272
- if (Array.isArray(product.product_bundle)) {
273
- product.product_bundle = product.product_bundle.map((bundle) => {
274
- const hasBundleDiscount = Array.isArray(bundle == null ? void 0 : bundle.discount_list) && bundle.discount_list.length > 0;
275
- if (hasBundleDiscount)
276
- return bundle;
277
- const restoredPrice = (bundle == null ? void 0 : bundle.original_price) ?? (bundle == null ? void 0 : bundle.product_price) ?? (bundle == null ? void 0 : bundle.price);
278
- if (restoredPrice === void 0 || restoredPrice === null || restoredPrice === "")
279
- return bundle;
280
- return {
281
- ...bundle,
282
- price: restoredPrice,
283
- bundle_selling_price: restoredPrice
284
- };
285
- });
286
- }
287
239
  product.selling_price = (0, import_utils.composeLinePrice)({
288
240
  mainPrice: newMainSellingPrice,
289
241
  bundle: product.product_bundle
@@ -482,7 +434,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
482
434
  });
483
435
  }
484
436
  async scanCode(code, customerId) {
485
- var _a, _b, _c, _d;
437
+ var _a, _b, _c, _d, _e;
486
438
  const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
487
439
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
488
440
  const rulesModule = this.store.rules;
@@ -518,17 +470,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
518
470
  };
519
471
  }
520
472
  const tempOrder = this.store.tempOrder;
521
- const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record) || [];
473
+ const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
522
474
  const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
523
475
  productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
524
476
  oldDiscountList: this.getDiscountList(),
525
477
  newDiscountList: withScanList,
526
478
  orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0),
527
479
  holders,
528
- isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product)
480
+ isFormSubject: !!((_d = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form"
529
481
  }) || { isAvailable: false, discountList: this.getDiscountList() };
530
482
  if (isAvailable && newDiscountList) {
531
- (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
483
+ (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(newDiscountList);
532
484
  this.applyDiscount();
533
485
  }
534
486
  return {
@@ -540,26 +492,24 @@ var OrderModule = class extends import_BaseModule.BaseModule {
540
492
  };
541
493
  }
542
494
  applyDiscount() {
543
- var _a, _b, _c, _d;
495
+ var _a, _b, _c, _d, _e;
544
496
  const tempOrder = this.store.tempOrder;
545
497
  if (!tempOrder)
546
498
  return;
547
- this.syncLinkedBookingHoldersToProducts(tempOrder);
548
499
  delete tempOrder.discount_list;
549
- const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
550
- const shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
551
- if (shouldSkipDiscountCalculation)
500
+ if (this.shouldSkipDiscountCalculation(tempOrder))
552
501
  return;
553
502
  const rulesModule = this.store.rules;
554
503
  if (!rulesModule)
555
504
  return;
556
- const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record) || [];
505
+ const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
506
+ const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
557
507
  const result = rulesModule.calcDiscount({
558
508
  productList: tempOrder.products,
559
509
  discountList,
560
510
  holders,
561
- isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
562
- orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0)
511
+ isFormSubject: !!((_c = tempOrder.holder) == null ? void 0 : _c.type) && tempOrder.holder.type === "form",
512
+ orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
563
513
  });
564
514
  if (result == null ? void 0 : result.productList) {
565
515
  const previousProductsByUid = (0, import_utils.indexOrderProductsByUid)(tempOrder.products);
@@ -588,7 +538,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
588
538
  result.productList || tempOrder.products,
589
539
  result.discountList
590
540
  );
591
- (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(result.discountList);
541
+ (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
592
542
  }
593
543
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(
594
544
  (product) => this.productHasCustomerBoundDiscount(product)
@@ -866,8 +816,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
866
816
  return (0, import_utils.mapPaymentItemsToOrderPayments)(payments, {
867
817
  includeVoided: false
868
818
  }).reduce((sum, payment) => {
869
- if (!isPaidPaymentRecord(payment))
870
- return sum;
871
819
  return sum.plus(this.calculatePaymentEffectiveAmount(payment));
872
820
  }, new import_decimal.default(0));
873
821
  }
@@ -877,33 +825,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
877
825
  normalizeDepositAmount(amount) {
878
826
  return import_decimal.default.max(new import_decimal.default(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
879
827
  }
880
- getLastOrderDepositSnapshot() {
881
- var _a;
882
- const lastOrderInfo = this.store.lastOrderInfo;
883
- if (!lastOrderInfo || typeof lastOrderInfo !== "object")
884
- return null;
885
- const rawDepositAmount = lastOrderInfo.deposit_amount ?? ((_a = lastOrderInfo.summary) == null ? void 0 : _a.deposit_amount);
886
- const depositAmount = this.normalizeDepositAmount(rawDepositAmount ?? 0);
887
- const hasDepositAmount = new import_decimal.default(depositAmount).gt(0);
888
- const isDeposit = Number(lastOrderInfo.is_deposit) === 1 || hasDepositAmount;
889
- if (!isDeposit || !hasDepositAmount)
890
- return null;
891
- return {
892
- isDeposit: 1,
893
- depositAmount
894
- };
895
- }
896
- getLastOrderSubmitSnapshot() {
897
- const lastOrderInfo = this.store.lastOrderInfo;
898
- if (!lastOrderInfo || typeof lastOrderInfo !== "object")
899
- return {};
900
- const businessCode = lastOrderInfo.business_code;
901
- const type = lastOrderInfo.type;
902
- return {
903
- ...typeof businessCode === "string" && businessCode ? { businessCode } : {},
904
- ...typeof type === "string" && type ? { type } : {}
905
- };
906
- }
907
828
  applyDepositAmountToSummary(tempOrder, summary, amount) {
908
829
  const depositAmount = this.normalizeDepositAmount(amount);
909
830
  const hasDepositAmount = new import_decimal.default(depositAmount).gt(0);
@@ -922,27 +843,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
922
843
  tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
923
844
  return nextSummary;
924
845
  }
925
- applyLastOrderDepositSnapshot(tempOrder, summary) {
926
- const snapshot = this.getLastOrderDepositSnapshot();
927
- if (!snapshot)
928
- return summary;
929
- const existedDeposit = summary.deposit && typeof summary.deposit === "object" ? summary.deposit : void 0;
930
- const nextSummary = {
931
- ...summary,
932
- deposit_amount: snapshot.depositAmount,
933
- deposit: {
934
- ...existedDeposit || {},
935
- total: snapshot.depositAmount,
936
- deposit_policy_ids: (existedDeposit == null ? void 0 : existedDeposit.deposit_policy_ids) || [],
937
- hasDeposit: true
938
- }
939
- };
940
- tempOrder.deposit_amount = snapshot.depositAmount;
941
- tempOrder.is_deposit = tempOrder.is_deposit === 0 && new import_decimal.default(tempOrder.deposit_amount || 0).gt(0) ? 0 : snapshot.isDeposit;
942
- return nextSummary;
943
- }
944
846
  isDepositOrder(tempOrder, depositAmount) {
945
- return tempOrder.is_deposit === 1 && depositAmount.gt(0);
847
+ return tempOrder.is_deposit === 1 || depositAmount.gt(0);
946
848
  }
947
849
  getOrderExpectedAmount(summary) {
948
850
  return new import_decimal.default(summary.expect_amount || summary.total_amount || 0);
@@ -955,37 +857,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
955
857
  return false;
956
858
  return params.paidAmount.gte(depositAmount);
957
859
  }
958
- getPaymentCompletion(payments) {
959
- const tempOrder = this.ensureTempOrder();
960
- const summary = this.store.summary || (0, import_utils.createEmptySummary)();
961
- const paymentList = payments || tempOrder.payments || [];
962
- const refundAmount = this.getSummaryRefundAmount(summary);
963
- const netPaidAmount = import_decimal.default.max(
964
- this.calculatePaymentTotal(paymentList).minus(refundAmount),
965
- 0
966
- );
967
- const depositAmount = this.getDepositAmount(tempOrder, summary);
968
- const orderExpectedAmount = this.getOrderExpectedAmount(summary);
969
- const isDepositFullyPaid = this.isDepositCovered({
970
- tempOrder,
971
- summary,
972
- paidAmount: netPaidAmount
973
- });
974
- const isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
975
- const paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? "deposit" : "normal";
976
- return {
977
- isFullyPaid: isOrderFullyPaid,
978
- isOrderFullyPaid,
979
- isDepositFullyPaid,
980
- paymentStage,
981
- depositAmount: depositAmount.toFixed(2),
982
- orderExpectedAmount: orderExpectedAmount.toFixed(2)
983
- };
984
- }
985
860
  calculateDepositPaidAmount(payments) {
986
861
  return (payments || []).reduce((sum, payment) => {
987
862
  const paymentRecord = payment;
988
- if (!isPaidPaymentRecord(paymentRecord))
863
+ if ((paymentRecord == null ? void 0 : paymentRecord.status) !== "paid")
989
864
  return sum;
990
865
  const isDepositPayment = paymentRecord.type === "deposit" || paymentRecord.order_payment_type === "deposit";
991
866
  if (!isDepositPayment)
@@ -1136,7 +1011,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1136
1011
  return (payments || []).reduce(
1137
1012
  (summary, payment) => {
1138
1013
  const paymentRecord = payment;
1139
- if (!isPaidPaymentRecord(paymentRecord))
1014
+ if ((paymentRecord == null ? void 0 : paymentRecord.status) !== "paid")
1140
1015
  return summary;
1141
1016
  return {
1142
1017
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
@@ -1470,15 +1345,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1470
1345
  });
1471
1346
  return currentAmountGap === snapshotAmountGap;
1472
1347
  }
1473
- hasShopDiscountChangedFromSnapshot(tempOrder, snapshot) {
1474
- const snapshotSummary = snapshot.summary && typeof snapshot.summary === "object" ? snapshot.summary : {};
1475
- const snapshotShopDiscount = snapshot.shop_discount ?? snapshotSummary.shop_discount;
1476
- if (snapshotShopDiscount === void 0 || snapshotShopDiscount === null || snapshotShopDiscount === "") {
1477
- return !new import_decimal.default(tempOrder.shop_discount || 0).equals(0);
1478
- }
1479
- return !new import_decimal.default(tempOrder.shop_discount || 0).equals(snapshotShopDiscount || 0);
1480
- }
1481
- restoreOriginalSnapshotIfProductsUnchanged(tempOrder, snapshot) {
1348
+ restoreOriginalSnapshotIfProductsUnchanged(tempOrder) {
1349
+ const snapshot = this.getOriginalSalesSnapshot(tempOrder);
1350
+ if (!snapshot)
1351
+ return null;
1482
1352
  const currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
1483
1353
  if (currentFingerprint !== snapshot.productFingerprint) {
1484
1354
  const currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
@@ -1567,7 +1437,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1567
1437
  }
1568
1438
  restoreOrder() {
1569
1439
  var _a, _b;
1570
- this.logInfo("restoreOrder start", {});
1571
1440
  const freshTempOrder = this.createDefaultTempOrderInstance();
1572
1441
  this.ensureExternalSaleNumber(freshTempOrder);
1573
1442
  this.store.tempOrder = freshTempOrder;
@@ -1646,7 +1515,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1646
1515
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1647
1516
  });
1648
1517
  return {
1649
- isDeposit: tempOrder.is_deposit === 1,
1518
+ isDeposit: tempOrder.is_deposit === 1 || depositAmount !== "0.00",
1650
1519
  depositAmount,
1651
1520
  expectAmount: summary.expect_amount || "0.00",
1652
1521
  totalAmount: summary.total_amount || "0.00",
@@ -1793,47 +1662,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1793
1662
  const records = Array.isArray(source) ? source : [source];
1794
1663
  return records.filter((record) => record !== void 0 && record !== null && record !== "");
1795
1664
  }
1796
- setProductHolderFromBooking(product, booking) {
1797
- if (!product || !booking)
1798
- return;
1799
- const holderRecords = this.collectBookingHolderRecords(booking);
1800
- if (!product.metadata || typeof product.metadata !== "object") {
1801
- product.metadata = {};
1802
- }
1803
- product.metadata.holder_id = holderRecords.length > 0 ? holderRecords : null;
1804
- }
1805
- syncLinkedBookingHoldersToProducts(tempOrder) {
1806
- const bookings = tempOrder.bookings || [];
1807
- const products = tempOrder.products || [];
1808
- if (!bookings.length || !products.length)
1809
- return;
1810
- const bookingByProductUid = /* @__PURE__ */ new Map();
1811
- const bookingByBookingUid = /* @__PURE__ */ new Map();
1812
- bookings.forEach((booking) => {
1813
- var _a, _b;
1814
- if (!booking || typeof booking !== "object")
1815
- return;
1816
- const productUid = booking.product_uid || ((_a = booking.metadata) == null ? void 0 : _a.product_uid);
1817
- if (productUid !== void 0 && productUid !== null && String(productUid) !== "") {
1818
- bookingByProductUid.set(String(productUid), booking);
1819
- }
1820
- const bookingUid = ((_b = booking.metadata) == null ? void 0 : _b.unique_identification_number) || booking.booking_uid;
1821
- if (bookingUid !== void 0 && bookingUid !== null && String(bookingUid) !== "") {
1822
- bookingByBookingUid.set(String(bookingUid), booking);
1823
- }
1824
- });
1825
- products.forEach((product) => {
1826
- var _a, _b;
1827
- if (!product || typeof product !== "object")
1828
- return;
1829
- const productUid = ((_a = product.metadata) == null ? void 0 : _a.unique_identification_number) || product.unique_identification_number;
1830
- const bookingUid = product.booking_uid || ((_b = product.metadata) == null ? void 0 : _b.booking_uid);
1831
- const linkedBooking = (productUid !== void 0 && productUid !== null && String(productUid) !== "" ? bookingByProductUid.get(String(productUid)) : void 0) || (bookingUid !== void 0 && bookingUid !== null && String(bookingUid) !== "" ? bookingByBookingUid.get(String(bookingUid)) : void 0);
1832
- if (linkedBooking) {
1833
- this.setProductHolderFromBooking(product, linkedBooking);
1834
- }
1835
- });
1836
- }
1837
1665
  /**
1838
1666
  * 按 form_record 顺序读取 booking holder 的主字段名称。
1839
1667
  *
@@ -1913,7 +1741,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1913
1741
  if (nextHolder || hasHolderSource || bookings.length === 0) {
1914
1742
  tempOrder.holder = nextHolder;
1915
1743
  }
1916
- this.syncLinkedBookingHoldersToProducts(tempOrder);
1917
1744
  }
1918
1745
  getBookingUniqueIdentificationNumber(booking) {
1919
1746
  var _a;
@@ -1973,24 +1800,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1973
1800
  hasDeposit: true
1974
1801
  } : void 0
1975
1802
  };
1976
- const isExistingDepositDisabled = tempOrder.is_deposit === 0 && new import_decimal.default(tempOrder.deposit_amount || 0).gt(0);
1977
1803
  tempOrder.deposit_amount = depositAmount;
1978
- tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
1979
- return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
1804
+ tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
1805
+ return nextSummary;
1980
1806
  }
1981
1807
  async recalculateSummary(options) {
1982
- var _a;
1983
1808
  const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
1984
1809
  if (!tempOrder)
1985
1810
  return null;
1986
1811
  this.sanitizeTempOrderProducts(tempOrder);
1987
- const originalSnapshot = this.getOriginalSalesSnapshot(tempOrder);
1988
- const hasShopDiscountChanged = originalSnapshot ? this.hasShopDiscountChangedFromSnapshot(tempOrder, originalSnapshot) : false;
1989
- const shouldReuseOriginalSnapshot = originalSnapshot && !hasShopDiscountChanged;
1990
- const snapshotSummary = shouldReuseOriginalSnapshot ? this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder, originalSnapshot) : null;
1812
+ const snapshotSummary = this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder);
1991
1813
  if (snapshotSummary)
1992
1814
  return snapshotSummary;
1993
- const shouldFullRecalculateFromSnapshot = Boolean(originalSnapshot);
1815
+ const shouldFullRecalculateFromSnapshot = Boolean(this.getOriginalSalesSnapshot(tempOrder));
1994
1816
  const summaryProducts = shouldFullRecalculateFromSnapshot ? (0, import_lodash_es.cloneDeep)(tempOrder.products || []) : tempOrder.products;
1995
1817
  if (shouldFullRecalculateFromSnapshot) {
1996
1818
  this.clearPersistedAmountFieldsForFullRecalc(summaryProducts || []);
@@ -2037,8 +1859,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2037
1859
  const salesSummaryResult = await salesSummary.getSummary({
2038
1860
  products: summaryProducts,
2039
1861
  isPriceIncludeTax: tempOrder.is_price_include_tax,
2040
- shopDiscount: tempOrder.shop_discount,
2041
- ...((_a = this.otherParams) == null ? void 0 : _a.channel) ? { channel: this.otherParams.channel } : {}
1862
+ shopDiscount: tempOrder.shop_discount
2042
1863
  });
2043
1864
  if (shouldFullRecalculateFromSnapshot) {
2044
1865
  tempOrder.products = summaryProducts;
@@ -2325,7 +2146,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2325
2146
  if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
2326
2147
  (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
2327
2148
  this.clearCustomerBoundDiscounts(tempOrder);
2328
- this.applyDiscount();
2329
2149
  }
2330
2150
  this.persistTempOrder();
2331
2151
  this.saveDraftInBackground();
@@ -2483,153 +2303,49 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2483
2303
  this.persistTempOrder();
2484
2304
  return tempOrder.payments;
2485
2305
  }
2486
- confirmPendingVoucherPaymentsInList(payments) {
2487
- return (payments || []).map((payment) => {
2488
- if (!isPendingVoucherPaymentRecord(payment))
2489
- return payment;
2490
- return {
2491
- ...payment,
2492
- status: ORDER_PAYMENT_STATUS_PAID
2493
- };
2494
- });
2495
- }
2496
- discardPendingVoucherPaymentsFromList(payments) {
2497
- return (payments || []).filter((payment) => !isPendingVoucherPaymentRecord(payment));
2498
- }
2499
- prepareVoucherPaymentsForSubmit(payments, confirmPendingVoucherPayments = true) {
2500
- const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments || []);
2501
- return confirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : this.discardPendingVoucherPaymentsFromList(mappedPayments);
2502
- }
2503
- applyPaymentLifecycleChange(tempOrder, options) {
2504
- this.updateTempOrderPaymentStatus(tempOrder);
2505
- if ((options == null ? void 0 : options.persist) !== false) {
2506
- this.persistTempOrder();
2507
- }
2508
- if ((options == null ? void 0 : options.recalculateSummary) === false)
2509
- return;
2510
- const logContext = (options == null ? void 0 : options.logContext) || "payment lifecycle change";
2511
- void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
2512
- this.logError(`recalculate summary after ${logContext} failed`, {
2513
- error: error instanceof Error ? error.message : String(error)
2514
- });
2515
- });
2516
- }
2517
- confirmPendingVoucherPayments(options) {
2518
- const tempOrder = this.ensureTempOrder();
2519
- const payments = tempOrder.payments || [];
2520
- const hasPendingVoucher = payments.some((payment) => isPendingVoucherPaymentRecord(payment));
2521
- if (!hasPendingVoucher)
2522
- return payments;
2523
- tempOrder.payments = this.confirmPendingVoucherPaymentsInList(payments);
2524
- this.applyPaymentLifecycleChange(tempOrder, {
2525
- ...options,
2526
- logContext: "confirmPendingVoucherPayments"
2527
- });
2528
- return tempOrder.payments;
2529
- }
2530
- discardPendingVoucherPayments(options) {
2531
- const tempOrder = this.ensureTempOrder();
2532
- const payments = tempOrder.payments || [];
2533
- const nextPayments = this.discardPendingVoucherPaymentsFromList(payments);
2534
- if (nextPayments.length === payments.length)
2535
- return payments;
2536
- tempOrder.payments = nextPayments;
2537
- this.applyPaymentLifecycleChange(tempOrder, {
2538
- ...options,
2539
- logContext: "discardPendingVoucherPayments"
2540
- });
2541
- return tempOrder.payments;
2542
- }
2543
2306
  /**
2544
2307
  * 覆盖当前订单中的 wallet pass 支付项。
2545
2308
  *
2546
2309
  * 判断口径与 PaymentModal 保持一致:voucher_id 存在且不为 0 的支付项
2547
2310
  * 视为 wallet pass;其它支付项保持不变。
2548
2311
  */
2549
- updateVoucherOrderPayments(payments, options) {
2312
+ updateVoucherOrderPayments(payments) {
2550
2313
  const tempOrder = this.ensureTempOrder();
2551
- const isOrderPaymentType = (value) => {
2552
- return value === "normal" || value === "deposit";
2314
+ const isVoucherPayment = (payment) => {
2315
+ return payment.voucher_id !== void 0 && Number(payment.voucher_id) !== 0;
2553
2316
  };
2554
- const voucherOrderPaymentType = this.resolveNextOrderPaymentType(tempOrder);
2555
- const withVoucherPaymentType = (payment) => {
2556
- const paymentRecord = payment;
2557
- if (!isVoucherPaymentRecord(paymentRecord))
2558
- return payment;
2559
- const explicitPaymentType = isOrderPaymentType(paymentRecord.order_payment_type) ? paymentRecord.order_payment_type : isOrderPaymentType(paymentRecord.type) ? paymentRecord.type : void 0;
2560
- const nextPaymentType = explicitPaymentType || voucherOrderPaymentType;
2561
- const shouldPreserveCustomPaymentType = paymentRecord.custom_payment_type === void 0 && paymentRecord.type !== void 0 && !isOrderPaymentType(paymentRecord.type);
2562
- return {
2563
- ...paymentRecord,
2564
- ...shouldPreserveCustomPaymentType ? { custom_payment_type: paymentRecord.type } : {},
2565
- type: nextPaymentType,
2566
- order_payment_type: nextPaymentType
2567
- };
2568
- };
2569
- const normalizeVoucherPaymentStatus = (payment) => {
2570
- const paymentRecord = payment;
2571
- if (!isVoucherPaymentRecord(paymentRecord))
2572
- return payment;
2573
- if (hasSyncedOrderPaymentRecord(paymentRecord) && (paymentRecord.status === void 0 || paymentRecord.status === "active")) {
2574
- return {
2575
- ...paymentRecord,
2576
- status: ORDER_PAYMENT_STATUS_PAID
2577
- };
2578
- }
2579
- if (paymentRecord.status !== void 0 && paymentRecord.status !== "active") {
2580
- return payment;
2581
- }
2582
- return {
2583
- ...paymentRecord,
2584
- status: (options == null ? void 0 : options.status) || ORDER_PAYMENT_STATUS_PENDING
2585
- };
2317
+ const hasSyncedOrderPayment = (payment) => {
2318
+ return payment.order_payment_id !== void 0 && payment.order_payment_id !== null;
2586
2319
  };
2587
2320
  const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(
2588
2321
  payments.map(
2589
- (payment) => this.normalizePaymentSource(
2590
- normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
2591
- { defaultPaid: false }
2592
- )
2322
+ (payment) => this.normalizePaymentSource(payment, { defaultPaid: true })
2593
2323
  )
2594
2324
  ).filter((payment) => {
2595
- return isVoucherPaymentRecord(payment);
2325
+ return isVoucherPayment(payment);
2596
2326
  });
2597
2327
  const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
2598
- return !isVoucherPaymentRecord(payment);
2328
+ return !isVoucherPayment(payment);
2599
2329
  });
2600
- const normalizeCommittedVoucherPayment = (payment) => {
2601
- if (hasSyncedOrderPaymentRecord(payment) && (payment.status === void 0 || payment.status === "active")) {
2602
- return {
2603
- ...payment,
2604
- status: ORDER_PAYMENT_STATUS_PAID
2605
- };
2606
- }
2607
- return payment;
2608
- };
2609
- const committedVoucherPayments = (tempOrder.payments || []).filter((payment) => isCommittedVoucherPaymentRecord(payment)).map((payment) => normalizeCommittedVoucherPayment(payment));
2610
- const committedVoucherPaymentIds = new Set(
2611
- committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
2612
- );
2613
- const committedVoucherIds = new Set(
2614
- committedVoucherPayments.map((payment) => String(payment.voucher_id))
2330
+ const syncedVoucherPayments = (tempOrder.payments || []).filter((payment) => {
2331
+ return isVoucherPayment(payment) && hasSyncedOrderPayment(payment);
2332
+ });
2333
+ const syncedVoucherPaymentIds = new Set(
2334
+ syncedVoucherPayments.map((payment) => String(payment.order_payment_id))
2615
2335
  );
2616
2336
  const replaceableVouchers = mappedVouchers.filter((payment) => {
2617
- if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
2618
- return false;
2619
- }
2620
- if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
2621
- return false;
2622
- }
2623
- return true;
2337
+ if (!hasSyncedOrderPayment(payment))
2338
+ return true;
2339
+ return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
2624
2340
  });
2625
2341
  const cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
2626
2342
  vouchers: replaceableVouchers,
2627
2343
  nonVoucherPayments: [
2628
2344
  ...nonVoucherPayments,
2629
- ...committedVoucherPayments
2345
+ ...syncedVoucherPayments
2630
2346
  ]
2631
2347
  });
2632
- tempOrder.payments = [...nonVoucherPayments, ...committedVoucherPayments, ...cappedVouchers];
2348
+ tempOrder.payments = [...nonVoucherPayments, ...syncedVoucherPayments, ...cappedVouchers];
2633
2349
  this.updateTempOrderPaymentStatus(tempOrder);
2634
2350
  this.persistTempOrder();
2635
2351
  void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
@@ -2845,6 +2561,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2845
2561
  */
2846
2562
  async addProductToOrder(product, booking) {
2847
2563
  const tempOrder = this.ensureTempOrder();
2564
+ debugger;
2848
2565
  if (booking) {
2849
2566
  const productRecord = product;
2850
2567
  const splitCount = (0, import_utils3.getSafeProductNum)(
@@ -2867,10 +2584,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2867
2584
  }
2868
2585
  await this.appendProductLineToTempOrder(tempOrder, product, booking);
2869
2586
  await this.finalizeProductOrderMutation(tempOrder);
2870
- this.logInfo("addProductToOrder success", {
2871
- product_id: product.product_id,
2872
- with_booking: !!booking
2873
- });
2874
2587
  return tempOrder.products;
2875
2588
  }
2876
2589
  /**
@@ -2912,9 +2625,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2912
2625
  await this.appendProductLineToTempOrder(tempOrder, product, booking);
2913
2626
  }
2914
2627
  await this.finalizeProductOrderMutation(tempOrder, options);
2915
- this.logInfo("addProductsToOrder success", {
2916
- itemsCount: items.length
2917
- });
2918
2628
  return tempOrder.products;
2919
2629
  }
2920
2630
  hasGoodPassDiscount(product) {
@@ -3137,9 +2847,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3137
2847
  this.sanitizeTempOrderProducts(tempOrder);
3138
2848
  await this.recalculateSummary({ createIfMissing: true });
3139
2849
  this.persistTempOrder();
3140
- this.logInfo("updateOrderProduct success", {
3141
- params
3142
- });
3143
2850
  return tempOrder.products;
3144
2851
  }
3145
2852
  async updateOrderProducts(paramsList) {
@@ -3151,9 +2858,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3151
2858
  this.applyOrderProductUpdateToTempOrder(tempOrder, params);
3152
2859
  });
3153
2860
  await this.finalizeAfterProductsMutation(tempOrder);
3154
- this.logInfo("updateOrderProduct success", {
3155
- paramsList
3156
- });
3157
2861
  return tempOrder.products;
3158
2862
  }
3159
2863
  async updateOrderProductQuantity(params) {
@@ -3218,9 +2922,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3218
2922
  this.sanitizeTempOrderProducts(tempOrder);
3219
2923
  await this.recalculateSummary({ createIfMissing: true });
3220
2924
  this.persistTempOrder();
3221
- this.logInfo("updateOrderProductQuantity success", {
3222
- params
3223
- });
3224
2925
  return tempOrder.products;
3225
2926
  }
3226
2927
  updateOrderBooking(params) {
@@ -3322,9 +3023,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3322
3023
  });
3323
3024
  }
3324
3025
  await this.finalizeAfterProductsMutation(tempOrder);
3325
- this.logInfo("removeProductsFromOrder success", {
3326
- identities
3327
- });
3328
3026
  return tempOrder.products;
3329
3027
  }
3330
3028
  async removeProductFromOrder(identity) {
@@ -3350,7 +3048,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3350
3048
  this.sanitizeTempOrderProducts(tempOrder);
3351
3049
  await this.recalculateSummary({ createIfMissing: true });
3352
3050
  this.persistTempOrder();
3353
- this.logInfo("clearOrderCartLines success", {});
3354
3051
  return tempOrder;
3355
3052
  }
3356
3053
  // ─── TempOrder: 提交 ───
@@ -3411,55 +3108,37 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3411
3108
  async runSubmitTempOrder(params) {
3412
3109
  var _a, _b, _c, _d, _e;
3413
3110
  const tempOrder = this.ensureTempOrder();
3414
- const shouldConfirmPendingVoucherPayments = (params == null ? void 0 : params.confirmPendingVoucherPayments) !== false;
3415
- const hasPaymentOverride = (params == null ? void 0 : params.payments) !== void 0;
3416
- const preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit(
3417
- (params == null ? void 0 : params.payments) || [],
3418
- shouldConfirmPendingVoucherPayments
3419
- ) : void 0;
3420
- if (!hasPaymentOverride) {
3421
- if (shouldConfirmPendingVoucherPayments) {
3422
- this.confirmPendingVoucherPayments({
3423
- persist: false,
3424
- recalculateSummary: false
3425
- });
3426
- } else {
3427
- this.discardPendingVoucherPayments({
3428
- persist: false,
3429
- recalculateSummary: false
3430
- });
3431
- }
3432
- }
3433
3111
  this.persistTempOrder();
3434
3112
  const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
3435
3113
  const effectiveCacheId = (params == null ? void 0 : params.cacheId) ?? this.cacheId;
3114
+ const hasPaymentOverride = (params == null ? void 0 : params.payments) !== void 0;
3436
3115
  const hasPaymentStatusOverride = (params == null ? void 0 : params.paymentStatus) !== void 0;
3437
3116
  const hasSmallTicketDataFlagOverride = (params == null ? void 0 : params.smallTicketDataFlag) !== void 0;
3438
3117
  const enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || (params == null ? void 0 : params.enhancePayload) ? (payload2, ctx) => {
3439
3118
  const nextPayload = {
3440
3119
  ...payload2,
3441
3120
  ...hasPaymentOverride ? {
3442
- payments: preparedPaymentOverride || []
3121
+ payments: (0, import_utils.mapPaymentItemsToOrderPayments)(
3122
+ (params == null ? void 0 : params.payments) || []
3123
+ )
3443
3124
  } : {},
3444
- ...hasPaymentStatusOverride && !shouldConfirmPendingVoucherPayments ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
3125
+ ...hasPaymentStatusOverride ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
3445
3126
  ...hasSmallTicketDataFlagOverride ? { small_ticket_data_flag: params == null ? void 0 : params.smallTicketDataFlag } : {}
3446
3127
  };
3447
3128
  const enhancedPayload = (params == null ? void 0 : params.enhancePayload) ? params.enhancePayload(nextPayload, ctx) : nextPayload;
3448
3129
  return enhancedPayload;
3449
3130
  } : void 0;
3450
- const submitSnapshot = this.getLastOrderSubmitSnapshot();
3451
3131
  const payload = (0, import_utils.buildSubmitPayload)({
3452
3132
  tempOrder,
3453
3133
  cacheId: effectiveCacheId,
3454
3134
  platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
3455
- businessCode: submitSnapshot.businessCode ?? (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
3135
+ businessCode: (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
3456
3136
  channel: params == null ? void 0 : params.channel,
3457
- type: submitSnapshot.type ?? (params == null ? void 0 : params.type),
3137
+ type: params == null ? void 0 : params.type,
3458
3138
  summary: latestSummary,
3459
3139
  request_unique_idempotency_token: params == null ? void 0 : params.request_unique_idempotency_token,
3460
3140
  enhance: enhancePayload
3461
3141
  });
3462
- console.log("[Order.runSubmitTempOrder.payload]", payload);
3463
3142
  if (params == null ? void 0 : params.syncMode) {
3464
3143
  payload.sync_mode = true;
3465
3144
  }
@@ -3507,10 +3186,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3507
3186
  this.logInfo("runSubmitTempOrder: 提交成功", {
3508
3187
  submittedOrderId,
3509
3188
  result,
3510
- tempOrder: {
3511
- ...tempOrder,
3512
- _extend: void 0
3513
- }
3189
+ tempOrder
3514
3190
  });
3515
3191
  if (submittedOrderId !== null && submittedOrderId !== void 0) {
3516
3192
  tempOrder.order_id = submittedOrderId;
@@ -3596,33 +3272,31 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3596
3272
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3597
3273
  params.payments || []
3598
3274
  );
3599
- const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
3600
- const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
3601
- const completion = this.getPaymentCompletion(effectivePayments);
3602
- const paidPaymentTotal = this.calculatePaymentTotal(effectivePayments);
3603
- const paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || "paid" : paidPaymentTotal.gt(0) ? "partially_paid" : "payment_processing";
3604
- tempOrder.payments = effectivePayments;
3275
+ const paymentTotal = this.calculatePaymentTotal(mappedPayments);
3276
+ const targetAmount = this.getPaymentTargetAmount();
3277
+ const isFullyPaid = targetAmount.lte(0) ? true : paymentTotal.gte(targetAmount);
3278
+ const paymentStatus = isFullyPaid ? params.paymentStatus || "paid" : "partially_paid";
3279
+ tempOrder.payments = mappedPayments;
3605
3280
  tempOrder.payment_status = paymentStatus;
3606
3281
  this.persistTempOrder();
3607
3282
  await this.saveDraft();
3608
3283
  if (!params.submitWhenPaid) {
3609
- return completion;
3284
+ return { isFullyPaid };
3610
3285
  }
3611
3286
  if (this.store.syncState === "submitting") {
3612
- return completion;
3287
+ return { isFullyPaid };
3613
3288
  }
3614
3289
  this.store.syncState = "submitting";
3615
3290
  const paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(
3616
3291
  tempOrder,
3617
- effectivePayments
3292
+ mappedPayments
3618
3293
  );
3619
3294
  const submitResult = await this.submitTempOrder({
3620
- payments: effectivePayments,
3295
+ payments: mappedPayments,
3621
3296
  paymentStatus,
3622
3297
  smallTicketDataFlag: params.smallTicketDataFlag,
3623
3298
  businessCode: params.businessCode,
3624
3299
  channel: params.channel,
3625
- confirmPendingVoucherPayments: true,
3626
3300
  enhancePayload: (payload) => {
3627
3301
  const nextPayload = {
3628
3302
  ...payload,
@@ -3631,7 +3305,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3631
3305
  return nextPayload;
3632
3306
  }
3633
3307
  });
3634
- return { ...completion, submitResult };
3308
+ return { isFullyPaid, submitResult };
3635
3309
  }
3636
3310
  createOrder(params) {
3637
3311
  var _a;
@@ -3957,7 +3631,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3957
3631
  products: (0, import_lodash_es.cloneDeep)(nextTempOrder.products || []),
3958
3632
  payments: (0, import_lodash_es.cloneDeep)(nextTempOrder.payments || []),
3959
3633
  surcharges: (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []),
3960
- shop_discount: nextTempOrder.shop_discount || "0.00",
3961
3634
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
3962
3635
  }
3963
3636
  };
@@ -3966,10 +3639,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3966
3639
  const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
3967
3640
  const shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
3968
3641
  if (!shouldSkipEmptyDiscountSync) {
3969
- OrderModule.populateSavedAmounts(
3970
- nextTempOrder.products,
3971
- hydratedEditDiscounts
3972
- );
3973
3642
  await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(hydratedEditDiscounts));
3974
3643
  await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(hydratedEditDiscounts));
3975
3644
  }
@@ -4123,7 +3792,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4123
3792
  product.booking_uid = linkedBookingUid;
4124
3793
  product.metadata.booking_uid = linkedBookingUid;
4125
3794
  });
4126
- this.syncLinkedBookingHoldersToProducts(tempOrder);
4127
3795
  }
4128
3796
  pickHydratedDisplayText(value) {
4129
3797
  if (value === void 0 || value === null)
@@ -4175,7 +3843,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4175
3843
  return normalized;
4176
3844
  }
4177
3845
  normalizeHydratedOrderProduct(product) {
4178
- let row = { ...product || {} };
3846
+ const row = { ...product || {} };
4179
3847
  if (row.num === void 0 && row.product_quantity !== void 0) {
4180
3848
  row.num = row.product_quantity;
4181
3849
  }
@@ -4196,7 +3864,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4196
3864
  if (row.booking_uid && !row.metadata.booking_uid) {
4197
3865
  row.metadata.booking_uid = row.booking_uid;
4198
3866
  }
4199
- row = (0, import_bundleDiscountHydration.restoreHydratedBundleDiscounts)(row, import_utils.normalizeOrderProductDiscountList);
4200
3867
  const existingIdentity = row.metadata.unique_identification_number || row.unique_identification_number;
4201
3868
  if (!existingIdentity) {
4202
3869
  row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
@@ -4216,8 +3883,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4216
3883
  };
4217
3884
  if (result.metadata)
4218
3885
  delete result.metadata.price_schema_version;
4219
- const restored = (0, import_bundleDiscountHydration.restoreHydratedBundleDiscounts)(result, import_utils.normalizeOrderProductDiscountList);
4220
- return this.sanitizeOrderProductForTempOrder(restored);
3886
+ return this.sanitizeOrderProductForTempOrder(result);
4221
3887
  }
4222
3888
  getLastOrderInfo() {
4223
3889
  var _a;
@@ -4231,10 +3897,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4231
3897
  });
4232
3898
  return res;
4233
3899
  }
4234
- getVouchers() {
4235
- var _a;
4236
- return ((_a = this.store.tempOrder) == null ? void 0 : _a.vouchers) || [];
4237
- }
4238
3900
  };
4239
3901
  // Annotate the CommonJS export names for ESM import in node:
4240
3902
  0 && (module.exports = {