@pisell/pisellos 2.3.5 → 2.3.7

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 (40) hide show
  1. package/dist/core/index.js +1 -1
  2. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  3. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
  4. package/dist/modules/Order/index.d.ts +12 -1
  5. package/dist/modules/Order/index.js +260 -160
  6. package/dist/modules/Order/types.d.ts +5 -0
  7. package/dist/modules/Order/utils.d.ts +4 -0
  8. package/dist/modules/Order/utils.js +31 -0
  9. package/dist/modules/Product/index.d.ts +1 -1
  10. package/dist/modules/Rules/index.d.ts +3 -3
  11. package/dist/modules/Rules/index.js +8 -3
  12. package/dist/modules/Rules/types.d.ts +2 -1
  13. package/dist/server/index.js +4 -3
  14. package/dist/server/modules/order/index.d.ts +4 -4
  15. package/dist/server/modules/order/index.js +4 -4
  16. package/dist/solution/BaseSales/index.js +93 -68
  17. package/dist/solution/BaseSales/types.d.ts +1 -0
  18. package/dist/solution/BaseSales/types.js +2 -1
  19. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -2
  20. package/dist/solution/BookingByStep/index.d.ts +1 -1
  21. package/lib/core/index.js +1 -1
  22. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
  23. package/lib/modules/Order/index.d.ts +12 -1
  24. package/lib/modules/Order/index.js +135 -26
  25. package/lib/modules/Order/types.d.ts +5 -0
  26. package/lib/modules/Order/utils.d.ts +4 -0
  27. package/lib/modules/Order/utils.js +39 -0
  28. package/lib/modules/Product/index.d.ts +1 -1
  29. package/lib/modules/Rules/index.d.ts +3 -3
  30. package/lib/modules/Rules/index.js +4 -3
  31. package/lib/modules/Rules/types.d.ts +2 -1
  32. package/lib/server/index.js +1 -4
  33. package/lib/server/modules/order/index.d.ts +4 -4
  34. package/lib/server/modules/order/index.js +4 -4
  35. package/lib/solution/BaseSales/index.js +40 -19
  36. package/lib/solution/BaseSales/types.d.ts +1 -0
  37. package/lib/solution/BaseSales/types.js +2 -1
  38. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -5
  39. package/lib/solution/BookingByStep/index.d.ts +1 -1
  40. package/package.json +1 -1
@@ -142,6 +142,14 @@ function resolveMainProductPrice(product, fallback) {
142
142
  const parsed = Number(value);
143
143
  return Number.isFinite(parsed) ? parsed : fallback;
144
144
  }
145
+ function mapOrderBundleToOtherBundle(bundle) {
146
+ return bundle.map((item) => {
147
+ return {
148
+ ...item,
149
+ original_price: item.original_price ?? item.bundle_selling_price ?? item.price
150
+ };
151
+ });
152
+ }
145
153
  function synthesizeProductResourceFromBooking(booking) {
146
154
  const rows = booking == null ? void 0 : booking.resources;
147
155
  if (!Array.isArray(rows) || rows.length === 0)
@@ -191,7 +199,9 @@ function buildCacheItemFromOrderLine(input) {
191
199
  const other = {
192
200
  product_variant_id: product.product_variant_id ?? 0,
193
201
  option: (0, import_utils.getProductSkuOptions)(product),
194
- bundle: Array.isArray(product.product_bundle) ? [...product.product_bundle] : []
202
+ bundle: mapOrderBundleToOtherBundle(
203
+ Array.isArray(product.product_bundle) ? product.product_bundle : []
204
+ )
195
205
  };
196
206
  const extend = {
197
207
  start_date: startDate ? (0, import_dayjs.default)(startDate) : void 0,
@@ -154,10 +154,21 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
154
154
  private calculatePaymentTotal;
155
155
  private getDepositAmount;
156
156
  private normalizeDepositAmount;
157
+ private getLastOrderDepositSnapshot;
158
+ private getLastOrderSubmitSnapshot;
157
159
  private applyDepositAmountToSummary;
160
+ private applyLastOrderDepositSnapshot;
158
161
  private isDepositOrder;
159
162
  private getOrderExpectedAmount;
160
163
  private isDepositCovered;
164
+ getPaymentCompletion(payments?: OrderPaymentSource[]): {
165
+ isFullyPaid: boolean;
166
+ isOrderFullyPaid: boolean;
167
+ isDepositFullyPaid: boolean;
168
+ paymentStage: 'deposit' | 'normal';
169
+ depositAmount: string;
170
+ orderExpectedAmount: string;
171
+ };
161
172
  private calculateDepositPaidAmount;
162
173
  private resolveNextOrderPaymentType;
163
174
  private normalizePaymentSource;
@@ -431,7 +442,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
431
442
  generateIdempotencyToken(): string;
432
443
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
433
444
  createOrder(params: CommitOrderParams['query']): {
434
- type: "appointment_booking" | "virtual";
445
+ type: "virtual" | "appointment_booking";
435
446
  platform: string;
436
447
  sales_channel: string;
437
448
  order_sales_channel: string;
@@ -236,6 +236,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
236
236
  product.metadata.main_product_selling_price = newMainSellingPrice;
237
237
  product.metadata.price_schema_version = 2;
238
238
  }
239
+ if (Array.isArray(product.product_bundle)) {
240
+ product.product_bundle = product.product_bundle.map((bundle) => {
241
+ const hasBundleDiscount = Array.isArray(bundle == null ? void 0 : bundle.discount_list) && bundle.discount_list.length > 0;
242
+ if (hasBundleDiscount)
243
+ return bundle;
244
+ const restoredPrice = (bundle == null ? void 0 : bundle.original_price) ?? (bundle == null ? void 0 : bundle.product_price) ?? (bundle == null ? void 0 : bundle.price);
245
+ if (restoredPrice === void 0 || restoredPrice === null || restoredPrice === "")
246
+ return bundle;
247
+ return {
248
+ ...bundle,
249
+ price: restoredPrice,
250
+ bundle_selling_price: restoredPrice
251
+ };
252
+ });
253
+ }
239
254
  product.selling_price = (0, import_utils.composeLinePrice)({
240
255
  mainPrice: newMainSellingPrice,
241
256
  bundle: product.product_bundle
@@ -434,7 +449,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
434
449
  });
435
450
  }
436
451
  async scanCode(code, customerId) {
437
- var _a, _b, _c, _d, _e;
452
+ var _a, _b, _c, _d;
438
453
  const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
439
454
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
440
455
  const rulesModule = this.store.rules;
@@ -470,17 +485,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
470
485
  };
471
486
  }
472
487
  const tempOrder = this.store.tempOrder;
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 }] : [];
488
+ const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record) || [];
474
489
  const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
475
490
  productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
476
491
  oldDiscountList: this.getDiscountList(),
477
492
  newDiscountList: withScanList,
478
493
  orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0),
479
494
  holders,
480
- isFormSubject: !!((_d = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form"
495
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product)
481
496
  }) || { isAvailable: false, discountList: this.getDiscountList() };
482
497
  if (isAvailable && newDiscountList) {
483
- (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(newDiscountList);
498
+ (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
484
499
  this.applyDiscount();
485
500
  }
486
501
  return {
@@ -492,24 +507,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
492
507
  };
493
508
  }
494
509
  applyDiscount() {
495
- var _a, _b, _c, _d, _e;
510
+ var _a, _b, _c, _d;
496
511
  const tempOrder = this.store.tempOrder;
497
512
  if (!tempOrder)
498
513
  return;
499
514
  delete tempOrder.discount_list;
500
- if (this.shouldSkipDiscountCalculation(tempOrder))
515
+ const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
516
+ const shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
517
+ if (shouldSkipDiscountCalculation)
501
518
  return;
502
519
  const rulesModule = this.store.rules;
503
520
  if (!rulesModule)
504
521
  return;
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 }] : [];
522
+ const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record) || [];
507
523
  const result = rulesModule.calcDiscount({
508
524
  productList: tempOrder.products,
509
525
  discountList,
510
526
  holders,
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)
527
+ isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
528
+ orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0)
513
529
  });
514
530
  if (result == null ? void 0 : result.productList) {
515
531
  const previousProductsByUid = (0, import_utils.indexOrderProductsByUid)(tempOrder.products);
@@ -538,7 +554,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
538
554
  result.productList || tempOrder.products,
539
555
  result.discountList
540
556
  );
541
- (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
557
+ (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(result.discountList);
542
558
  }
543
559
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(
544
560
  (product) => this.productHasCustomerBoundDiscount(product)
@@ -825,6 +841,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
825
841
  normalizeDepositAmount(amount) {
826
842
  return import_decimal.default.max(new import_decimal.default(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
827
843
  }
844
+ getLastOrderDepositSnapshot() {
845
+ var _a;
846
+ const lastOrderInfo = this.store.lastOrderInfo;
847
+ if (!lastOrderInfo || typeof lastOrderInfo !== "object")
848
+ return null;
849
+ const rawDepositAmount = lastOrderInfo.deposit_amount ?? ((_a = lastOrderInfo.summary) == null ? void 0 : _a.deposit_amount);
850
+ const depositAmount = this.normalizeDepositAmount(rawDepositAmount ?? 0);
851
+ const hasDepositAmount = new import_decimal.default(depositAmount).gt(0);
852
+ const isDeposit = Number(lastOrderInfo.is_deposit) === 1 || hasDepositAmount;
853
+ if (!isDeposit || !hasDepositAmount)
854
+ return null;
855
+ return {
856
+ isDeposit: 1,
857
+ depositAmount
858
+ };
859
+ }
860
+ getLastOrderSubmitSnapshot() {
861
+ const lastOrderInfo = this.store.lastOrderInfo;
862
+ if (!lastOrderInfo || typeof lastOrderInfo !== "object")
863
+ return {};
864
+ const businessCode = lastOrderInfo.business_code;
865
+ const type = lastOrderInfo.type;
866
+ return {
867
+ ...typeof businessCode === "string" && businessCode ? { businessCode } : {},
868
+ ...typeof type === "string" && type ? { type } : {}
869
+ };
870
+ }
828
871
  applyDepositAmountToSummary(tempOrder, summary, amount) {
829
872
  const depositAmount = this.normalizeDepositAmount(amount);
830
873
  const hasDepositAmount = new import_decimal.default(depositAmount).gt(0);
@@ -843,8 +886,27 @@ var OrderModule = class extends import_BaseModule.BaseModule {
843
886
  tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
844
887
  return nextSummary;
845
888
  }
889
+ applyLastOrderDepositSnapshot(tempOrder, summary) {
890
+ const snapshot = this.getLastOrderDepositSnapshot();
891
+ if (!snapshot)
892
+ return summary;
893
+ const existedDeposit = summary.deposit && typeof summary.deposit === "object" ? summary.deposit : void 0;
894
+ const nextSummary = {
895
+ ...summary,
896
+ deposit_amount: snapshot.depositAmount,
897
+ deposit: {
898
+ ...existedDeposit || {},
899
+ total: snapshot.depositAmount,
900
+ deposit_policy_ids: (existedDeposit == null ? void 0 : existedDeposit.deposit_policy_ids) || [],
901
+ hasDeposit: true
902
+ }
903
+ };
904
+ tempOrder.deposit_amount = snapshot.depositAmount;
905
+ tempOrder.is_deposit = tempOrder.is_deposit === 0 && new import_decimal.default(tempOrder.deposit_amount || 0).gt(0) ? 0 : snapshot.isDeposit;
906
+ return nextSummary;
907
+ }
846
908
  isDepositOrder(tempOrder, depositAmount) {
847
- return tempOrder.is_deposit === 1 || depositAmount.gt(0);
909
+ return tempOrder.is_deposit === 1 && depositAmount.gt(0);
848
910
  }
849
911
  getOrderExpectedAmount(summary) {
850
912
  return new import_decimal.default(summary.expect_amount || summary.total_amount || 0);
@@ -857,6 +919,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
857
919
  return false;
858
920
  return params.paidAmount.gte(depositAmount);
859
921
  }
922
+ getPaymentCompletion(payments) {
923
+ const tempOrder = this.ensureTempOrder();
924
+ const summary = this.store.summary || (0, import_utils.createEmptySummary)();
925
+ const paymentList = payments || tempOrder.payments || [];
926
+ const refundAmount = this.getSummaryRefundAmount(summary);
927
+ const netPaidAmount = import_decimal.default.max(
928
+ this.calculatePaymentTotal(paymentList).minus(refundAmount),
929
+ 0
930
+ );
931
+ const depositAmount = this.getDepositAmount(tempOrder, summary);
932
+ const orderExpectedAmount = this.getOrderExpectedAmount(summary);
933
+ const isDepositFullyPaid = this.isDepositCovered({
934
+ tempOrder,
935
+ summary,
936
+ paidAmount: netPaidAmount
937
+ });
938
+ const isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
939
+ const paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? "deposit" : "normal";
940
+ return {
941
+ isFullyPaid: isOrderFullyPaid,
942
+ isOrderFullyPaid,
943
+ isDepositFullyPaid,
944
+ paymentStage,
945
+ depositAmount: depositAmount.toFixed(2),
946
+ orderExpectedAmount: orderExpectedAmount.toFixed(2)
947
+ };
948
+ }
860
949
  calculateDepositPaidAmount(payments) {
861
950
  return (payments || []).reduce((sum, payment) => {
862
951
  const paymentRecord = payment;
@@ -1515,7 +1604,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1515
1604
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
1516
1605
  });
1517
1606
  return {
1518
- isDeposit: tempOrder.is_deposit === 1 || depositAmount !== "0.00",
1607
+ isDeposit: tempOrder.is_deposit === 1,
1519
1608
  depositAmount,
1520
1609
  expectAmount: summary.expect_amount || "0.00",
1521
1610
  totalAmount: summary.total_amount || "0.00",
@@ -1800,9 +1889,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1800
1889
  hasDeposit: true
1801
1890
  } : void 0
1802
1891
  };
1892
+ const isExistingDepositDisabled = tempOrder.is_deposit === 0 && new import_decimal.default(tempOrder.deposit_amount || 0).gt(0);
1803
1893
  tempOrder.deposit_amount = depositAmount;
1804
- tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
1805
- return nextSummary;
1894
+ tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
1895
+ return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
1806
1896
  }
1807
1897
  async recalculateSummary(options) {
1808
1898
  const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
@@ -2146,6 +2236,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2146
2236
  if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
2147
2237
  (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
2148
2238
  this.clearCustomerBoundDiscounts(tempOrder);
2239
+ this.applyDiscount();
2149
2240
  }
2150
2241
  this.persistTempOrder();
2151
2242
  this.saveDraftInBackground();
@@ -2317,9 +2408,27 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2317
2408
  const hasSyncedOrderPayment = (payment) => {
2318
2409
  return payment.order_payment_id !== void 0 && payment.order_payment_id !== null;
2319
2410
  };
2411
+ const isOrderPaymentType = (value) => {
2412
+ return value === "normal" || value === "deposit";
2413
+ };
2414
+ const voucherOrderPaymentType = this.resolveNextOrderPaymentType(tempOrder);
2415
+ const withVoucherPaymentType = (payment) => {
2416
+ const paymentRecord = payment;
2417
+ if (!isVoucherPayment(paymentRecord))
2418
+ return payment;
2419
+ const explicitPaymentType = isOrderPaymentType(paymentRecord.order_payment_type) ? paymentRecord.order_payment_type : isOrderPaymentType(paymentRecord.type) ? paymentRecord.type : void 0;
2420
+ const nextPaymentType = explicitPaymentType || voucherOrderPaymentType;
2421
+ const shouldPreserveCustomPaymentType = paymentRecord.custom_payment_type === void 0 && paymentRecord.type !== void 0 && !isOrderPaymentType(paymentRecord.type);
2422
+ return {
2423
+ ...paymentRecord,
2424
+ ...shouldPreserveCustomPaymentType ? { custom_payment_type: paymentRecord.type } : {},
2425
+ type: nextPaymentType,
2426
+ order_payment_type: nextPaymentType
2427
+ };
2428
+ };
2320
2429
  const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(
2321
2430
  payments.map(
2322
- (payment) => this.normalizePaymentSource(payment, { defaultPaid: true })
2431
+ (payment) => this.normalizePaymentSource(withVoucherPaymentType(payment), { defaultPaid: true })
2323
2432
  )
2324
2433
  ).filter((payment) => {
2325
2434
  return isVoucherPayment(payment);
@@ -2561,7 +2670,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2561
2670
  */
2562
2671
  async addProductToOrder(product, booking) {
2563
2672
  const tempOrder = this.ensureTempOrder();
2564
- debugger;
2565
2673
  if (booking) {
2566
2674
  const productRecord = product;
2567
2675
  const splitCount = (0, import_utils3.getSafeProductNum)(
@@ -3128,13 +3236,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3128
3236
  const enhancedPayload = (params == null ? void 0 : params.enhancePayload) ? params.enhancePayload(nextPayload, ctx) : nextPayload;
3129
3237
  return enhancedPayload;
3130
3238
  } : void 0;
3239
+ const submitSnapshot = this.getLastOrderSubmitSnapshot();
3131
3240
  const payload = (0, import_utils.buildSubmitPayload)({
3132
3241
  tempOrder,
3133
3242
  cacheId: effectiveCacheId,
3134
3243
  platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
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),
3244
+ 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),
3136
3245
  channel: params == null ? void 0 : params.channel,
3137
- type: params == null ? void 0 : params.type,
3246
+ type: submitSnapshot.type ?? (params == null ? void 0 : params.type),
3138
3247
  summary: latestSummary,
3139
3248
  request_unique_idempotency_token: params == null ? void 0 : params.request_unique_idempotency_token,
3140
3249
  enhance: enhancePayload
@@ -3272,19 +3381,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3272
3381
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3273
3382
  params.payments || []
3274
3383
  );
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";
3384
+ const completion = this.getPaymentCompletion(mappedPayments);
3385
+ const paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || "paid" : "partially_paid";
3279
3386
  tempOrder.payments = mappedPayments;
3280
3387
  tempOrder.payment_status = paymentStatus;
3281
3388
  this.persistTempOrder();
3282
3389
  await this.saveDraft();
3283
3390
  if (!params.submitWhenPaid) {
3284
- return { isFullyPaid };
3391
+ return completion;
3285
3392
  }
3286
3393
  if (this.store.syncState === "submitting") {
3287
- return { isFullyPaid };
3394
+ return completion;
3288
3395
  }
3289
3396
  this.store.syncState = "submitting";
3290
3397
  const paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(
@@ -3305,7 +3412,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3305
3412
  return nextPayload;
3306
3413
  }
3307
3414
  });
3308
- return { isFullyPaid, submitResult };
3415
+ return { ...completion, submitResult };
3309
3416
  }
3310
3417
  createOrder(params) {
3311
3418
  var _a;
@@ -3892,6 +3999,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3892
3999
  async getOrderInfo(order_id) {
3893
4000
  const res = await this.request.get(`/order/sales/${order_id}`, {
3894
4001
  with: ["products", "bookings"]
4002
+ }, {
4003
+ osServer: true
3895
4004
  });
3896
4005
  return res;
3897
4006
  }
@@ -540,6 +540,11 @@ export interface SyncPaymentsToOrderParams {
540
540
  }
541
541
  export interface SyncPaymentsToOrderResult<T = any> {
542
542
  isFullyPaid: boolean;
543
+ isOrderFullyPaid: boolean;
544
+ isDepositFullyPaid: boolean;
545
+ paymentStage: 'deposit' | 'normal';
546
+ depositAmount: string;
547
+ orderExpectedAmount: string;
543
548
  submitResult?: T;
544
549
  }
545
550
  export interface OrderIdentitySnapshot {
@@ -254,6 +254,10 @@ export declare function clearTempOrderHolderAssignments(tempOrder: OrderTempOrde
254
254
  * getOrderProductLineUid({ metadata: { unique_identification_number: 'line-1' } }); // 'line-1'
255
255
  */
256
256
  export declare function getOrderProductLineUid(product: Record<string, any> | null | undefined): string | null;
257
+ export declare function getRuntimeProductOrigin(tempOrder: OrderTempOrder | null | undefined, product: any): Record<string, any> | null;
258
+ export declare function isHolderConfigRequired(holderConfig: any): boolean;
259
+ export declare function productRequiresFormSubject(tempOrder: OrderTempOrder | null | undefined, product: any): boolean;
260
+ export declare function resolveIsFormSubject(tempOrder: OrderTempOrder | null | undefined, product?: any): boolean;
257
261
  /**
258
262
  * 判断展示字段是否为空(含 i18n 对象全空)。
259
263
  *
@@ -49,9 +49,11 @@ __export(utils_exports, {
49
49
  getBundleSignedUnit: () => getBundleSignedUnit,
50
50
  getOrderProductLineUid: () => getOrderProductLineUid,
51
51
  getProductSkuOptions: () => getProductSkuOptions,
52
+ getRuntimeProductOrigin: () => getRuntimeProductOrigin,
52
53
  hasAssignedHolderId: () => hasAssignedHolderId,
53
54
  indexOrderProductsByUid: () => indexOrderProductsByUid,
54
55
  isEmptyOrderProductDisplayValue: () => isEmptyOrderProductDisplayValue,
56
+ isHolderConfigRequired: () => isHolderConfigRequired,
55
57
  isMarkdownBundle: () => isMarkdownBundle,
56
58
  isTempOrder: () => isTempOrder,
57
59
  mapPaymentItemToOrderPayment: () => mapPaymentItemToOrderPayment,
@@ -65,7 +67,9 @@ __export(utils_exports, {
65
67
  normalizeProductSkuOptions: () => normalizeProductSkuOptions,
66
68
  normalizeSubmitBooking: () => normalizeSubmitBooking,
67
69
  normalizeSubmitCollectPaxValue: () => normalizeSubmitCollectPaxValue,
70
+ productRequiresFormSubject: () => productRequiresFormSubject,
68
71
  resolveEffectivePerUnitDiscount: () => resolveEffectivePerUnitDiscount,
72
+ resolveIsFormSubject: () => resolveIsFormSubject,
69
73
  resolveManualDiscountMessage: () => import_manualProductDiscount.resolveManualDiscountMessage,
70
74
  resolveManualDiscountOriginTotal: () => import_manualProductDiscount.resolveManualDiscountOriginTotal,
71
75
  resolveManualDiscountReasonFromSources: () => import_manualProductDiscount.resolveManualDiscountReasonFromSources,
@@ -1094,6 +1098,37 @@ function getOrderProductLineUid(product) {
1094
1098
  return null;
1095
1099
  return String(uid);
1096
1100
  }
1101
+ function getRuntimeProductOrigin(tempOrder, product) {
1102
+ var _a, _b, _c, _d, _e, _f;
1103
+ const uid = getOrderProductLineUid(product);
1104
+ if (uid && ((_c = (_b = (_a = tempOrder == null ? void 0 : tempOrder._extend) == null ? void 0 : _a.productsByUid) == null ? void 0 : _b[uid]) == null ? void 0 : _c.origin)) {
1105
+ return tempOrder._extend.productsByUid[uid].origin;
1106
+ }
1107
+ const matchedProduct = ((tempOrder == null ? void 0 : tempOrder.products) || []).find((item) => item === product || getOrderProductLineUid(item) === uid || String((item == null ? void 0 : item.product_id) ?? (item == null ? void 0 : item.id) ?? "") === String((product == null ? void 0 : product.product_id) ?? (product == null ? void 0 : product.id) ?? ""));
1108
+ const matchedUid = matchedProduct ? getOrderProductLineUid(matchedProduct) : "";
1109
+ return matchedUid ? ((_f = (_e = (_d = tempOrder == null ? void 0 : tempOrder._extend) == null ? void 0 : _d.productsByUid) == null ? void 0 : _e[matchedUid]) == null ? void 0 : _f.origin) || null : null;
1110
+ }
1111
+ function isHolderConfigRequired(holderConfig) {
1112
+ if (!holderConfig || typeof holderConfig !== "object")
1113
+ return false;
1114
+ if (holderConfig.status === "disable")
1115
+ return false;
1116
+ return Number(holderConfig.required) === 1;
1117
+ }
1118
+ function productRequiresFormSubject(tempOrder, product) {
1119
+ const runtimeOrigin = getRuntimeProductOrigin(tempOrder, product);
1120
+ return isHolderConfigRequired(product == null ? void 0 : product.holder_config) || isHolderConfigRequired(runtimeOrigin == null ? void 0 : runtimeOrigin.holder_config);
1121
+ }
1122
+ function resolveIsFormSubject(tempOrder, product) {
1123
+ var _a;
1124
+ if (((_a = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _a.type) === "form")
1125
+ return true;
1126
+ if (product)
1127
+ return productRequiresFormSubject(tempOrder, product);
1128
+ return ((tempOrder == null ? void 0 : tempOrder.products) || []).some(
1129
+ (item) => productRequiresFormSubject(tempOrder, item)
1130
+ );
1131
+ }
1097
1132
  function isEmptyOrderProductDisplayValue(value) {
1098
1133
  if (value === void 0 || value === null)
1099
1134
  return true;
@@ -1174,9 +1209,11 @@ function indexOrderProductsByUid(products) {
1174
1209
  getBundleSignedUnit,
1175
1210
  getOrderProductLineUid,
1176
1211
  getProductSkuOptions,
1212
+ getRuntimeProductOrigin,
1177
1213
  hasAssignedHolderId,
1178
1214
  indexOrderProductsByUid,
1179
1215
  isEmptyOrderProductDisplayValue,
1216
+ isHolderConfigRequired,
1180
1217
  isMarkdownBundle,
1181
1218
  isTempOrder,
1182
1219
  mapPaymentItemToOrderPayment,
@@ -1190,7 +1227,9 @@ function indexOrderProductsByUid(products) {
1190
1227
  normalizeProductSkuOptions,
1191
1228
  normalizeSubmitBooking,
1192
1229
  normalizeSubmitCollectPaxValue,
1230
+ productRequiresFormSubject,
1193
1231
  resolveEffectivePerUnitDiscount,
1232
+ resolveIsFormSubject,
1194
1233
  resolveManualDiscountMessage,
1195
1234
  resolveManualDiscountOriginTotal,
1196
1235
  resolveManualDiscountReasonFromSources,
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult, UnavailableReason } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, UnavailableReason } from './types';
4
4
  import { Discount } from '../Discount/types';
5
5
  import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
6
6
  import { WindowPlugin } from '../../plugins';
@@ -24,7 +24,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
24
24
  holders: {
25
25
  form_record_id: number;
26
26
  }[];
27
- isFormSubject: boolean;
27
+ isFormSubject: RulesFormSubject;
28
28
  }): {
29
29
  isAvailable: boolean;
30
30
  discountList: Discount[];
@@ -43,7 +43,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
43
43
  holders: {
44
44
  form_record_id: number;
45
45
  }[];
46
- isFormSubject: boolean;
46
+ isFormSubject: RulesFormSubject;
47
47
  orderTotalAmount: number;
48
48
  }, options?: {
49
49
  isSelected?: boolean;
@@ -70,7 +70,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
70
70
  var _a;
71
71
  if (((_a = discount.holder) == null ? void 0 : _a.holder_type) !== "form")
72
72
  return true;
73
- const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : void 0;
73
+ const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id || holders[0] : void 0;
74
74
  const productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
75
75
  if (!product.isNeedHolder)
76
76
  return true;
@@ -207,6 +207,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
207
207
  orderTotalAmount
208
208
  }, options) {
209
209
  var _a;
210
+ const resolveIsFormSubject = (product) => typeof isFormSubject === "function" ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
210
211
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
211
212
  const editModeDiscount = [];
212
213
  const addModeDiscount = [];
@@ -596,7 +597,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
596
597
  const isHolderMatch = this.checkHolderMatch(
597
598
  discount,
598
599
  {
599
- isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
600
+ isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
600
601
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
601
602
  },
602
603
  holders
@@ -767,7 +768,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
767
768
  const isHolderMatch = this.checkHolderMatch(
768
769
  discount,
769
770
  {
770
- isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
771
+ isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
771
772
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
772
773
  },
773
774
  holders
@@ -22,6 +22,7 @@ export interface DiscountResult {
22
22
  productList: any[];
23
23
  discountList: any[];
24
24
  }
25
+ export type RulesFormSubject = boolean | ((product: any) => boolean);
25
26
  export interface RulesModuleAPI {
26
27
  setRulesList: (rulesList: Rules[]) => Promise<void>;
27
28
  clear: () => Promise<void>;
@@ -31,7 +32,7 @@ export interface RulesModuleAPI {
31
32
  holders: {
32
33
  form_record_id: number;
33
34
  }[];
34
- isFormSubject: boolean;
35
+ isFormSubject: RulesFormSubject;
35
36
  orderTotalAmount: number;
36
37
  }) => DiscountResult;
37
38
  }
@@ -737,7 +737,7 @@ var Server = class {
737
737
  };
738
738
  } catch (error) {
739
739
  const errorMessage = error instanceof Error ? error.message : String(error);
740
- this.logError("handleOrderSalesDetail: 请求失败", {
740
+ this.logInfo("handleOrderSalesDetail: 请求失败", {
741
741
  lookup,
742
742
  backendPath,
743
743
  error: errorMessage
@@ -2925,11 +2925,8 @@ var Server = class {
2925
2925
  );
2926
2926
  }
2927
2927
  shouldBuildSmallTicketData(order) {
2928
- var _a;
2929
2928
  if (!order || typeof order !== "object")
2930
2929
  return false;
2931
- if ((0, import_small_ticket.hasSmallTicketData)((_a = order.payment_info) == null ? void 0 : _a.small_ticket_data))
2932
- return false;
2933
2930
  return Number(order.small_ticket_data_flag ?? order.smallTicketDataFlag ?? 0) === 1;
2934
2931
  }
2935
2932
  shouldPrintSyncedOrder(params) {
@@ -31,10 +31,10 @@ export declare class OrderModule extends BaseModule implements Module {
31
31
  private emitOrdersChanged;
32
32
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
33
33
  /**
34
- * 记录信息日志
35
- * @param title 日志标题
36
- * @param metadata 日志元数据
37
- */
34
+ * 记录信息日志
35
+ * @param title 日志标题
36
+ * @param metadata 日志元数据
37
+ */
38
38
  private logInfo;
39
39
  /**
40
40
  * 记录错误日志
@@ -109,10 +109,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
109
109
  });
110
110
  }
111
111
  /**
112
- * 记录信息日志
113
- * @param title 日志标题
114
- * @param metadata 日志元数据
115
- */
112
+ * 记录信息日志
113
+ * @param title 日志标题
114
+ * @param metadata 日志元数据
115
+ */
116
116
  logInfo(title, metadata) {
117
117
  try {
118
118
  if (this.logger) {