@pisell/pisellos 0.10.88 → 0.10.91

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 (227) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
  6. package/dist/model/strategy/adapter/itemRule/type.js +10 -0
  7. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  8. package/dist/model/strategy/adapter/promotion/evaluator.js +103 -112
  9. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  10. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  11. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  12. package/dist/modules/BookingContext/utils/index.js +1 -0
  13. package/dist/modules/BookingContext/utils/productExtend.d.ts +21 -0
  14. package/dist/modules/BookingContext/utils/productExtend.js +132 -33
  15. package/dist/modules/BookingContext/utils/resources.js +1 -1
  16. package/dist/modules/Cart/index.js +4 -3
  17. package/dist/modules/Cart/types.d.ts +2 -0
  18. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  19. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  20. package/dist/modules/Date/index.d.ts +1 -1
  21. package/dist/modules/Date/index.js +60 -14
  22. package/dist/modules/Date/types.d.ts +5 -0
  23. package/dist/modules/OpenData/salesSettings.js +1 -1
  24. package/dist/modules/OpenData/types.d.ts +9 -0
  25. package/dist/modules/OpenData/utils.d.ts +1 -1
  26. package/dist/modules/OpenData/utils.js +3 -2
  27. package/dist/modules/Order/index.d.ts +22 -7
  28. package/dist/modules/Order/index.js +1565 -1161
  29. package/dist/modules/Order/localEftposState.d.ts +13 -0
  30. package/dist/modules/Order/localEftposState.js +39 -0
  31. package/dist/modules/Order/types.d.ts +33 -11
  32. package/dist/modules/Order/types.js +2 -2
  33. package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
  34. package/dist/modules/Order/unpaidAmountGap.js +72 -0
  35. package/dist/modules/Order/utils.d.ts +4 -1
  36. package/dist/modules/Order/utils.js +185 -129
  37. package/dist/modules/Payment/walletpass.js +32 -6
  38. package/dist/modules/Product/types.d.ts +16 -0
  39. package/dist/modules/ProductList/index.js +1 -1
  40. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  41. package/dist/modules/ResourcePlanner/planner.js +383 -24
  42. package/dist/modules/ResourcePlanner/types.d.ts +42 -0
  43. package/dist/modules/Rules/index.js +86 -54
  44. package/dist/modules/Schedule/index.d.ts +7 -1
  45. package/dist/modules/Schedule/index.js +155 -39
  46. package/dist/modules/Schedule/types.d.ts +2 -0
  47. package/dist/modules/bookingReadValidation.d.ts +6 -0
  48. package/dist/modules/bookingReadValidation.js +72 -0
  49. package/dist/plugins/request.d.ts +2 -0
  50. package/dist/server/index.d.ts +9 -0
  51. package/dist/server/index.js +1928 -1462
  52. package/dist/server/modules/form/index.d.ts +19 -0
  53. package/dist/server/modules/form/index.js +205 -0
  54. package/dist/server/modules/form/types.d.ts +13 -0
  55. package/dist/server/modules/form/types.js +3 -0
  56. package/dist/server/modules/index.d.ts +3 -0
  57. package/dist/server/modules/index.js +4 -0
  58. package/dist/server/modules/order/index.d.ts +21 -0
  59. package/dist/server/modules/order/index.js +1399 -831
  60. package/dist/server/modules/order/types.d.ts +3 -0
  61. package/dist/server/modules/order/utils/filterOrders.js +20 -0
  62. package/dist/server/modules/products/index.d.ts +28 -7
  63. package/dist/server/modules/products/index.js +1295 -769
  64. package/dist/server/modules/products/replication.d.ts +8 -0
  65. package/dist/server/modules/products/replication.js +69 -0
  66. package/dist/server/modules/products/types.d.ts +12 -1
  67. package/dist/server/modules/products/types.js +4 -0
  68. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  69. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  70. package/dist/shared/receipt/small-ticket.d.ts +1 -0
  71. package/dist/shared/receipt/small-ticket.js +58 -26
  72. package/dist/shared/receipt/templateVisibility.d.ts +3 -0
  73. package/dist/shared/receipt/templateVisibility.js +6 -2
  74. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  75. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  76. package/dist/solution/BaseSales/index.d.ts +22 -6
  77. package/dist/solution/BaseSales/index.js +1881 -1347
  78. package/dist/solution/BaseSales/pickupTiming.d.ts +4 -0
  79. package/dist/solution/BaseSales/pickupTiming.js +35 -8
  80. package/dist/solution/BaseSales/types.d.ts +4 -0
  81. package/dist/solution/BaseSales/types.js +1 -0
  82. package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  83. package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
  84. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  85. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
  86. package/dist/solution/BookingByStep/index.d.ts +19 -3
  87. package/dist/solution/BookingByStep/index.js +681 -361
  88. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  89. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  90. package/dist/solution/BookingTicket/index.d.ts +6 -0
  91. package/dist/solution/BookingTicket/index.js +666 -593
  92. package/dist/solution/BookingTicket/types.d.ts +1 -1
  93. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  94. package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
  95. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +7 -7
  96. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  97. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  98. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
  99. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  100. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +33 -62
  101. package/dist/solution/OrderInvoicePreview/index.js +4 -3
  102. package/dist/solution/Sales/index.js +1 -1
  103. package/dist/solution/ScanOrder/index.d.ts +2 -0
  104. package/dist/solution/ScanOrder/index.js +230 -97
  105. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  106. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  107. package/dist/solution/ScanOrder/types.d.ts +3 -0
  108. package/dist/solution/UnifiedBookingSales/index.d.ts +42 -10
  109. package/dist/solution/UnifiedBookingSales/index.js +2493 -1496
  110. package/dist/solution/UnifiedBookingSales/salesSettings.js +1 -1
  111. package/dist/solution/UnifiedBookingSales/types.d.ts +20 -5
  112. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  113. package/dist/utils/pos-receipt-auto-print.js +14 -0
  114. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  115. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  116. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  117. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  118. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  119. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  120. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  121. package/lib/model/strategy/adapter/promotion/evaluator.js +22 -21
  122. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  123. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  124. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  125. package/lib/modules/BookingContext/utils/index.js +11 -0
  126. package/lib/modules/BookingContext/utils/productExtend.d.ts +21 -0
  127. package/lib/modules/BookingContext/utils/productExtend.js +104 -5
  128. package/lib/modules/BookingContext/utils/resources.js +1 -1
  129. package/lib/modules/Cart/index.js +4 -2
  130. package/lib/modules/Cart/types.d.ts +2 -0
  131. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  132. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  133. package/lib/modules/Date/index.d.ts +1 -1
  134. package/lib/modules/Date/index.js +28 -5
  135. package/lib/modules/Date/types.d.ts +5 -0
  136. package/lib/modules/OpenData/salesSettings.js +1 -1
  137. package/lib/modules/OpenData/types.d.ts +9 -0
  138. package/lib/modules/OpenData/utils.d.ts +1 -1
  139. package/lib/modules/OpenData/utils.js +3 -2
  140. package/lib/modules/Order/index.d.ts +22 -7
  141. package/lib/modules/Order/index.js +457 -174
  142. package/lib/modules/Order/localEftposState.d.ts +13 -0
  143. package/lib/modules/Order/localEftposState.js +44 -0
  144. package/lib/modules/Order/types.d.ts +33 -11
  145. package/lib/modules/Order/types.js +2 -2
  146. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  147. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  148. package/lib/modules/Order/utils.d.ts +4 -1
  149. package/lib/modules/Order/utils.js +51 -3
  150. package/lib/modules/Payment/walletpass.js +23 -1
  151. package/lib/modules/Product/types.d.ts +16 -0
  152. package/lib/modules/ProductList/index.js +1 -1
  153. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  154. package/lib/modules/ResourcePlanner/planner.js +299 -9
  155. package/lib/modules/ResourcePlanner/types.d.ts +42 -0
  156. package/lib/modules/Rules/index.js +32 -3
  157. package/lib/modules/Schedule/index.d.ts +7 -1
  158. package/lib/modules/Schedule/index.js +68 -4
  159. package/lib/modules/Schedule/types.d.ts +2 -0
  160. package/lib/modules/bookingReadValidation.d.ts +6 -0
  161. package/lib/modules/bookingReadValidation.js +56 -0
  162. package/lib/plugins/request.d.ts +2 -0
  163. package/lib/server/index.d.ts +9 -0
  164. package/lib/server/index.js +279 -30
  165. package/lib/server/modules/form/index.d.ts +19 -0
  166. package/lib/server/modules/form/index.js +73 -0
  167. package/lib/server/modules/form/types.d.ts +13 -0
  168. package/lib/server/modules/form/types.js +9 -0
  169. package/lib/server/modules/index.d.ts +3 -0
  170. package/lib/server/modules/index.js +15 -1
  171. package/lib/server/modules/order/index.d.ts +21 -0
  172. package/lib/server/modules/order/index.js +344 -35
  173. package/lib/server/modules/order/types.d.ts +3 -0
  174. package/lib/server/modules/order/utils/filterOrders.js +18 -0
  175. package/lib/server/modules/products/index.d.ts +28 -7
  176. package/lib/server/modules/products/index.js +224 -62
  177. package/lib/server/modules/products/replication.d.ts +8 -0
  178. package/lib/server/modules/products/replication.js +30 -0
  179. package/lib/server/modules/products/types.d.ts +12 -1
  180. package/lib/server/modules/products/types.js +3 -0
  181. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  182. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  183. package/lib/shared/receipt/small-ticket.d.ts +1 -0
  184. package/lib/shared/receipt/small-ticket.js +53 -25
  185. package/lib/shared/receipt/templateVisibility.d.ts +3 -0
  186. package/lib/shared/receipt/templateVisibility.js +6 -2
  187. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  188. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  189. package/lib/solution/BaseSales/index.d.ts +22 -6
  190. package/lib/solution/BaseSales/index.js +347 -59
  191. package/lib/solution/BaseSales/pickupTiming.d.ts +4 -0
  192. package/lib/solution/BaseSales/pickupTiming.js +24 -3
  193. package/lib/solution/BaseSales/types.d.ts +4 -0
  194. package/lib/solution/BaseSales/types.js +1 -0
  195. package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  196. package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
  197. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  198. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  199. package/lib/solution/BookingByStep/index.d.ts +19 -3
  200. package/lib/solution/BookingByStep/index.js +229 -17
  201. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  202. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  203. package/lib/solution/BookingTicket/index.d.ts +6 -0
  204. package/lib/solution/BookingTicket/index.js +40 -5
  205. package/lib/solution/BookingTicket/types.d.ts +1 -1
  206. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  207. package/lib/solution/BookingTicket/utils/addProductDecision.js +34 -4
  208. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +7 -7
  209. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  210. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  211. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
  212. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  213. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +17 -34
  214. package/lib/solution/OrderInvoicePreview/index.js +1 -0
  215. package/lib/solution/Sales/index.js +1 -1
  216. package/lib/solution/ScanOrder/index.d.ts +2 -0
  217. package/lib/solution/ScanOrder/index.js +131 -22
  218. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  219. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  220. package/lib/solution/ScanOrder/types.d.ts +3 -0
  221. package/lib/solution/UnifiedBookingSales/index.d.ts +42 -10
  222. package/lib/solution/UnifiedBookingSales/index.js +717 -144
  223. package/lib/solution/UnifiedBookingSales/salesSettings.js +1 -1
  224. package/lib/solution/UnifiedBookingSales/types.d.ts +20 -5
  225. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  226. package/lib/utils/pos-receipt-auto-print.js +13 -0
  227. package/package.json +1 -1
@@ -93,6 +93,19 @@ class PickupTimingController {
93
93
  if (runtime.scheduleRequest === request) runtime.scheduleRequest = undefined;
94
94
  }
95
95
  }
96
+
97
+ /** Preserve an existing POS choice without adding it to the shared settings cache. */
98
+ getEffectiveConfig(config) {
99
+ if (!this.host.isPos()) return config;
100
+ const serviceType = this.host.getOrder().getTempOrder()?.metadata?.shop_service_data?.service_type;
101
+ if (serviceType !== 'dine_in' && serviceType !== 'takeaway' || config.handoverModes.includes(serviceType)) {
102
+ return config;
103
+ }
104
+ return {
105
+ ...config,
106
+ handoverModes: [...config.handoverModes, serviceType]
107
+ };
108
+ }
96
109
  async snapshot(includeSchedule, tolerateScheduleError = false) {
97
110
  const runtime = this.getRuntime();
98
111
  const config = await this.loadConfig(runtime);
@@ -116,7 +129,11 @@ class PickupTimingController {
116
129
  error
117
130
  };
118
131
  this.latest = result;
119
- return result;
132
+ // Read the live order after async loading; cached snapshots retain only configured modes.
133
+ return {
134
+ ...result,
135
+ config: this.getEffectiveConfig(config)
136
+ };
120
137
  }
121
138
  async getAvailability(params = {}) {
122
139
  // `force` remains accepted for older callers; refresh recomputes time using the runtime catalog.
@@ -150,7 +167,7 @@ class PickupTimingController {
150
167
  const order = this.host.getOrder();
151
168
  const tempOrder = order.getTempOrder();
152
169
  const booking = order.getPickupTimingBooking();
153
- const config = this.latest?.scope === this.host.getScope() ? this.latest.config : undefined;
170
+ const config = this.latest?.scope === this.host.getScope() ? this.getEffectiveConfig(this.latest.config) : undefined;
154
171
  const storedServiceType = String(tempOrder?.metadata?.shop_service_data?.service_type || '');
155
172
  const serviceType = config?.handoverModes.length ? config.handoverModes.includes(storedServiceType) ? storedServiceType : config.handoverModes[0] : storedServiceType;
156
173
  const details = serviceType === 'pick_up' ? booking?.metadata.fulfillment_timing : undefined;
@@ -202,7 +219,11 @@ class PickupTimingController {
202
219
  return this.getSelection();
203
220
  }
204
221
  if (selection.serviceType !== 'pick_up') {
205
- order.updateTempOrderServiceType(selection.serviceType);
222
+ if (this.host.setServiceType) {
223
+ await this.host.setServiceType(selection.serviceType);
224
+ } else {
225
+ order.updateTempOrderServiceType(selection.serviceType);
226
+ }
206
227
  return this.getSelection();
207
228
  }
208
229
  const slot = selection.mode === 'asap' ? (0, _FulfillmentTiming.getAsapPickupTiming)({
@@ -13,6 +13,7 @@ import type { SubmitPayloadEnhancer } from '../../modules/Order/utils';
13
13
  export declare const BaseSalesHookNames: {
14
14
  readonly onInited: "onInited";
15
15
  readonly onDestroy: "onDestroy";
16
+ readonly onOrderSessionChanged: "onOrderSessionChanged";
16
17
  readonly onRetryInit: "onRetryInit";
17
18
  readonly onRefresh: "onRefresh";
18
19
  readonly onCartValidationChanged: "onCartValidationChanged";
@@ -348,6 +349,9 @@ export interface BaseSalesProductBookingPriceResult {
348
349
  unit_price: string;
349
350
  total_price: string;
350
351
  quantity: number;
352
+ pricing_method?: {
353
+ type: 'fixed_price' | 'duration_based';
354
+ };
351
355
  duration?: BaseSalesQuotationDurationConfig;
352
356
  quotation_shelf_id: number;
353
357
  segments: BaseSalesProductBookingPriceSegment[];
@@ -12,6 +12,7 @@ exports.createBaseSalesHook = createBaseSalesHook;
12
12
  const BaseSalesHookNames = exports.BaseSalesHookNames = {
13
13
  onInited: 'onInited',
14
14
  onDestroy: 'onDestroy',
15
+ onOrderSessionChanged: 'onOrderSessionChanged',
15
16
  onRetryInit: 'onRetryInit',
16
17
  onRefresh: 'onRefresh',
17
18
  onCartValidationChanged: 'onCartValidationChanged',
@@ -0,0 +1,21 @@
1
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult, BaseSalesQuotationDurationConfig } from '../types';
2
+ export interface PosDurationPricingPlan {
3
+ duration: BaseSalesQuotationDurationConfig;
4
+ segments: Array<{
5
+ start: string;
6
+ end: string;
7
+ }>;
8
+ }
9
+ export declare function durationPricingUnavailable(message: string): Error & {
10
+ code: string;
11
+ };
12
+ export declare function hasDurationBasedPricing(product: Record<string, any> | null | undefined): boolean;
13
+ /** Days/Flexible retain their existing quotation behavior. */
14
+ export declare function usesPosDurationPricing(product: Record<string, any> | null | undefined): boolean;
15
+ /** A hydrated catalog can already be fixed while its order/quote still contains an applied duration price. */
16
+ export declare function hasAppliedPosDurationPricing(product: Record<string, any> | null | undefined): boolean;
17
+ export declare function buildPosDurationPricingPlan(params: BaseSalesCalculateProductBookingPriceParams, product: Record<string, any>): PosDurationPricingPlan;
18
+ /** Never use a previously accumulated order price as one unit's fallback. */
19
+ export declare function resolveDurationPricingProduct(product: Record<string, any>, selected: Record<string, any>): Record<string, any>;
20
+ export declare function combinePosDurationPrices(plan: PosDurationPricingPlan, prices: BaseSalesProductBookingPriceResult[]): BaseSalesProductBookingPriceResult;
21
+ export declare function forEachPriceQueryGroup<T>(groups: T[], resolve: (group: T) => Promise<void>, concurrency: number): Promise<void>;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildPosDurationPricingPlan = buildPosDurationPricingPlan;
7
+ exports.combinePosDurationPrices = combinePosDurationPrices;
8
+ exports.durationPricingUnavailable = durationPricingUnavailable;
9
+ exports.forEachPriceQueryGroup = forEachPriceQueryGroup;
10
+ exports.hasAppliedPosDurationPricing = hasAppliedPosDurationPricing;
11
+ exports.hasDurationBasedPricing = hasDurationBasedPricing;
12
+ exports.resolveDurationPricingProduct = resolveDurationPricingProduct;
13
+ exports.usesPosDurationPricing = usesPosDurationPricing;
14
+ var _dayjs = _interopRequireDefault(require("dayjs"));
15
+ var _decimal = _interopRequireDefault(require("decimal.js"));
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ function durationPricingUnavailable(message) {
18
+ return Object.assign(new Error(message), {
19
+ code: 'DURATION_PRICING_UNAVAILABLE'
20
+ });
21
+ }
22
+ function hasDurationBasedPricing(product) {
23
+ return product?.pricing_method?.type === 'duration_based';
24
+ }
25
+
26
+ /** Days/Flexible retain their existing quotation behavior. */
27
+ function usesPosDurationPricing(product) {
28
+ const type = String(product?.duration?.type || '').trim().toLowerCase();
29
+ return hasDurationBasedPricing(product) && !['day', 'days', 'flexible'].includes(type);
30
+ }
31
+
32
+ /** A hydrated catalog can already be fixed while its order/quote still contains an applied duration price. */
33
+ function hasAppliedPosDurationPricing(product) {
34
+ return usesPosDurationPricing(product?._extend?.bookingPriceQuote) || usesPosDurationPricing(product?._extend?.bookingPrice?.quote) || usesPosDurationPricing(product?.metadata);
35
+ }
36
+ function bookingDateTime(date, time) {
37
+ const dateText = typeof date === 'string' ? date.trim() : '';
38
+ const timeText = typeof time === 'string' ? time.trim() : '';
39
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(dateText) || !/^\d{2}:\d{2}(?::\d{2})?$/.test(timeText)) {
40
+ throw durationPricingUnavailable('A valid booking start and end are required for duration pricing.');
41
+ }
42
+ const text = `${dateText} ${timeText.length === 5 ? `${timeText}:00` : timeText}`;
43
+ const value = (0, _dayjs.default)(text);
44
+ if (!value.isValid() || value.format('YYYY-MM-DD HH:mm:ss') !== text) {
45
+ throw durationPricingUnavailable('The booking time is invalid for duration pricing.');
46
+ }
47
+ return value;
48
+ }
49
+ function buildPosDurationPricingPlan(params, product) {
50
+ const type = String(product.duration?.type || '').trim().toLowerCase();
51
+ const value = Number(product.duration?.value);
52
+ const minutes = ['hour', 'hours'].includes(type) ? value * 60 : value;
53
+ if (!['minute', 'minutes', 'hour', 'hours'].includes(type) || !Number.isFinite(minutes) || minutes <= 0) {
54
+ throw durationPricingUnavailable('A positive fixed billing duration is required.');
55
+ }
56
+ const start = bookingDateTime(params.booking?.start_date, params.booking?.start_time);
57
+ const end = bookingDateTime(params.booking?.end_date, params.booking?.end_time);
58
+ const count = end.diff(start) / (minutes * 60_000);
59
+ if (!Number.isInteger(count) || count < 1 || count > 10_000) {
60
+ throw durationPricingUnavailable('The booking duration must be a whole multiple of its billing duration.');
61
+ }
62
+ return {
63
+ duration: {
64
+ type: 'minutes',
65
+ value: minutes
66
+ },
67
+ segments: Array.from({
68
+ length: count
69
+ }, (_, index) => ({
70
+ start: start.add(index * minutes, 'minute').format('YYYY-MM-DD HH:mm:ss'),
71
+ end: start.add((index + 1) * minutes, 'minute').format('YYYY-MM-DD HH:mm:ss')
72
+ }))
73
+ };
74
+ }
75
+
76
+ /** Never use a previously accumulated order price as one unit's fallback. */
77
+ function resolveDurationPricingProduct(product, selected) {
78
+ const variantId = Number(selected.product_variant_id ?? selected.variant_id ?? 0);
79
+ const authoritativeVariantId = Number(product.product_variant_id ?? product.variant_id ?? 0);
80
+ const variant = variantId > 0 && Array.isArray(product.variant) ? product.variant.find(item => Number(item?.id) === variantId) : undefined;
81
+ if (variantId > 0 && !variant && authoritativeVariantId !== variantId) {
82
+ throw durationPricingUnavailable('The selected SKU is missing from the authoritative price response.');
83
+ }
84
+ const appliedFields = product._dataVariant?.appliedFields;
85
+ const hasAppliedPrice = Array.isArray(appliedFields) && ['price', 'selling_price', 'original_price', 'base_price'].some(field => appliedFields.includes(field));
86
+ const priceSource = variantId > 0 && authoritativeVariantId !== variantId && !hasAppliedPrice ? variant : product;
87
+ const price = priceSource?.price ?? priceSource?.selling_price ?? priceSource?.base_price ?? priceSource?.original_price;
88
+ if (!(typeof price === 'number' || typeof price === 'string' && price.trim() !== '') || !Number.isFinite(Number(price)) || Number(price) < 0) {
89
+ throw durationPricingUnavailable('An authoritative price is required for every billing unit.');
90
+ }
91
+ return {
92
+ ...product,
93
+ price
94
+ };
95
+ }
96
+ function combinePosDurationPrices(plan, prices) {
97
+ if (prices.length !== plan.segments.length || prices.length === 0) {
98
+ throw durationPricingUnavailable('The duration price is incomplete.');
99
+ }
100
+ const unitPrice = prices.reduce((sum, price) => sum.plus(price.unit_price), new _decimal.default(0));
101
+ return {
102
+ ...prices[0],
103
+ pricing_method: {
104
+ type: 'duration_based'
105
+ },
106
+ duration: plan.duration,
107
+ unit_price: unitPrice.toFixed(2),
108
+ total_price: unitPrice.times(prices[0].quantity).toFixed(2),
109
+ quotation_shelf_id: prices.find(price => price.quotation_shelf_id)?.quotation_shelf_id || 0,
110
+ segments: prices.map((price, index) => ({
111
+ ...price.segments[0],
112
+ start_datetime: plan.segments[index].start,
113
+ end_datetime: plan.segments[index].end,
114
+ time_point: plan.segments[index].start,
115
+ unit_price: price.unit_price,
116
+ total_price: price.unit_price,
117
+ quantity: 1
118
+ })),
119
+ // Options are composed by the caller; bundle pricing belongs to the first unit only.
120
+ product_bundle: prices[0].product_bundle
121
+ };
122
+ }
123
+ async function forEachPriceQueryGroup(groups, resolve, concurrency) {
124
+ let next = 0;
125
+ await Promise.all(Array.from({
126
+ length: Math.min(groups.length, concurrency)
127
+ }, async () => {
128
+ while (next < groups.length) {
129
+ const group = groups[next++];
130
+ await resolve(group);
131
+ }
132
+ }));
133
+ }
@@ -55,6 +55,8 @@ export interface TransformBaseProductToOrderProductParams {
55
55
  fallbackProductId?: number | string | null;
56
56
  sourceProduct?: ProductData | Record<string, any> | null;
57
57
  sourceItem?: ProductData | Record<string, any> | null;
58
+ /** Validated booking quote's pre-discount main price, excluding options/bundles. */
59
+ quotedSourceProductPrice?: number | string;
58
60
  }
59
61
  export type BaseProductOrderProductInput = Partial<OrderProduct> & OrderProductIdentity & {
60
62
  _origin?: Record<string, any>;
@@ -156,7 +156,7 @@ function transformBaseProductToOrderProduct(params) {
156
156
  // 售价仍由 line_total - bundle 推导。
157
157
  const catalogSourcePrice = matchedVariant?.price ?? matchedVariant?.base_price ?? origin?.price ?? origin?.base_price ?? sourceProduct?.price ?? sourceProduct?.selling_price ?? sourceProduct?.base_price;
158
158
  const weighedSourcePrice = (0, _weighedProduct.resolveWeighedSourcePrice)(payload.product_sku ?? origin.product_sku, payload._extend?.weighing ?? origin._extend?.weighing);
159
- const sourceProductPrice = toPriceString(weighedSourcePrice ?? (hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice), '0.00');
159
+ const sourceProductPrice = toPriceString(params.quotedSourceProductPrice ?? weighedSourcePrice ?? (hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice), '0.00');
160
160
  const explicitLineTotal = payload.line_total ?? payload.total ?? payload._extend?.total;
161
161
  const hasExplicitLineTotal = Number.isFinite(Number(explicitLineTotal));
162
162
  const lineCompositeTotal = toPriceString(explicitLineTotal, sourceProductPrice);
@@ -20,9 +20,20 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
20
20
  private shopStore;
21
21
  private store;
22
22
  private otherParams;
23
+ private scheduleRuntimeParams;
23
24
  private cacheId;
24
25
  private otherData;
25
26
  private platform;
27
+ private productDetailGeneration;
28
+ private sessionAvailabilityRequestVersion;
29
+ private lifecycleGeneration;
30
+ private disposed;
31
+ private resourcePreparation?;
32
+ private staleSelection;
33
+ private resourceSelectionKey;
34
+ /** Semantic selection token for async UI transitions. */
35
+ getBookingSelectionKey(): string;
36
+ private refreshCurrentProductSchedule;
26
37
  initialize(core: PisellCore, options: any): Promise<void>;
27
38
  initStep(stepList: (keyof BookingByStepState)[]): void;
28
39
  getCurrentStep(): {
@@ -108,7 +119,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
108
119
  * }
109
120
  * @memberof BookingByStepImpl
110
121
  */
111
- loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<ITime[]>;
122
+ loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, assertCurrent, }: LoadScheduleAvailableDateParams): Promise<ITime[]>;
112
123
  addAccount(account: Account | IHolder, extra?: {
113
124
  type: 'account' | 'holder';
114
125
  customerId: number;
@@ -152,7 +163,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
152
163
  startDate?: string;
153
164
  endDate?: string;
154
165
  type?: 'month' | 'day';
166
+ assertCurrent?: () => void;
155
167
  }): Promise<ITime[]>;
168
+ /** Prepare the exact cart/date selection before synchronous resource checks. */
169
+ prepareResourcesForCurrentSelection(): Promise<void>;
156
170
  /**
157
171
  * 获取购物车汇总信息
158
172
  */
@@ -210,6 +224,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
210
224
  * product: ProductData;
211
225
  * date?: { startTime: string; endTime: string } | null;
212
226
  * account?: Account | null;
227
+ * isLegacyOrder?: boolean;
213
228
  * })} {
214
229
  * product,
215
230
  * date,
@@ -218,13 +233,14 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
218
233
  * @return {*}
219
234
  * @memberof BookingByStepImpl
220
235
  */
221
- addProductToCart({ product, date, account, }: {
236
+ addProductToCart({ product, date, account, isLegacyOrder, }: {
222
237
  product: ProductData;
223
238
  date?: {
224
239
  startTime: string;
225
240
  endTime: string;
226
241
  } | null;
227
242
  account?: Account | null;
243
+ isLegacyOrder?: boolean;
228
244
  }): {
229
245
  success: boolean;
230
246
  errorCode?: string;
@@ -326,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
342
  date: string;
327
343
  status: string;
328
344
  week: string;
329
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
345
+ weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
330
346
  }[]>;
331
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
348
  private getScheduleDataByIds;