@pisell/pisellos 2.2.181 → 2.2.182

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 (175) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/BookingContext/index.d.ts +37 -0
  3. package/dist/modules/BookingContext/index.js +436 -0
  4. package/dist/modules/BookingContext/types.d.ts +102 -0
  5. package/dist/modules/BookingContext/types.js +51 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  7. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +276 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  9. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  11. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  12. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  13. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  15. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  16. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  17. package/dist/modules/BookingContext/utils/index.js +11 -0
  18. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  19. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  20. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  21. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  23. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  25. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  26. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  27. package/dist/modules/BookingContext/utils/resources.js +486 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  29. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  31. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  32. package/dist/modules/Customer/index.d.ts +6 -0
  33. package/dist/modules/Customer/index.js +129 -83
  34. package/dist/modules/Customer/types.d.ts +2 -0
  35. package/dist/modules/Discount/index.js +4 -3
  36. package/dist/modules/Discount/types.d.ts +1 -0
  37. package/dist/modules/Order/index.d.ts +101 -10
  38. package/dist/modules/Order/index.js +1444 -490
  39. package/dist/modules/Order/types.d.ts +201 -18
  40. package/dist/modules/Order/types.js +31 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  43. package/dist/modules/Order/utils.d.ts +83 -1
  44. package/dist/modules/Order/utils.js +405 -61
  45. package/dist/modules/Product/index.d.ts +1 -1
  46. package/dist/modules/Quotation/index.d.ts +0 -1
  47. package/dist/modules/Quotation/index.js +23 -21
  48. package/dist/modules/Rules/index.d.ts +4 -0
  49. package/dist/modules/Rules/index.js +43 -39
  50. package/dist/modules/Rules/types.d.ts +1 -0
  51. package/dist/modules/SalesSummary/index.js +4 -2
  52. package/dist/modules/SalesSummary/utils.js +21 -7
  53. package/dist/modules/Schedule/index.js +6 -2
  54. package/dist/modules/index.d.ts +1 -0
  55. package/dist/modules/index.js +2 -1
  56. package/dist/server/index.js +87 -29
  57. package/dist/server/modules/order/index.d.ts +23 -0
  58. package/dist/server/modules/order/index.js +123 -46
  59. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  60. package/dist/server/modules/products/index.d.ts +1 -1
  61. package/dist/server/modules/products/index.js +130 -113
  62. package/dist/server/modules/schedule/index.js +13 -6
  63. package/dist/solution/BaseSales/index.d.ts +89 -7
  64. package/dist/solution/BaseSales/index.js +1489 -366
  65. package/dist/solution/BaseSales/types.d.ts +67 -1
  66. package/dist/solution/BaseSales/types.js +3 -1
  67. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  68. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  69. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  70. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  71. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  72. package/dist/solution/BaseSales/utils.js +46 -8
  73. package/dist/solution/BookingByStep/index.d.ts +1 -1
  74. package/dist/solution/BookingTicket/index.d.ts +152 -2
  75. package/dist/solution/BookingTicket/index.js +848 -184
  76. package/dist/solution/BookingTicket/types.d.ts +2 -0
  77. package/dist/solution/BookingTicket/types.js +3 -0
  78. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  79. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  80. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  81. package/dist/solution/ScanOrder/index.d.ts +9 -3
  82. package/dist/solution/ScanOrder/index.js +231 -128
  83. package/dist/solution/ScanOrder/utils.js +46 -8
  84. package/dist/solution/VenueBooking/index.d.ts +5 -2
  85. package/dist/solution/VenueBooking/index.js +103 -55
  86. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  87. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  88. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  89. package/lib/modules/BookingContext/index.d.ts +37 -0
  90. package/lib/modules/BookingContext/index.js +297 -0
  91. package/lib/modules/BookingContext/types.d.ts +102 -0
  92. package/lib/modules/BookingContext/types.js +34 -0
  93. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  94. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +271 -0
  95. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  96. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  97. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  98. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  99. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  100. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  101. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  102. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  103. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  104. package/lib/modules/BookingContext/utils/index.js +43 -0
  105. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  106. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  107. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  108. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  109. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  110. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  111. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  112. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  113. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  114. package/lib/modules/BookingContext/utils/resources.js +377 -0
  115. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  116. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  117. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  118. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  119. package/lib/modules/Customer/index.d.ts +6 -0
  120. package/lib/modules/Customer/index.js +26 -11
  121. package/lib/modules/Customer/types.d.ts +2 -0
  122. package/lib/modules/Discount/index.js +5 -1
  123. package/lib/modules/Discount/types.d.ts +1 -0
  124. package/lib/modules/Order/index.d.ts +101 -10
  125. package/lib/modules/Order/index.js +751 -114
  126. package/lib/modules/Order/types.d.ts +201 -18
  127. package/lib/modules/Order/types.js +1 -0
  128. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  129. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  130. package/lib/modules/Order/utils.d.ts +83 -1
  131. package/lib/modules/Order/utils.js +340 -22
  132. package/lib/modules/Product/index.d.ts +1 -1
  133. package/lib/modules/Quotation/index.d.ts +0 -1
  134. package/lib/modules/Quotation/index.js +18 -15
  135. package/lib/modules/Rules/index.d.ts +4 -0
  136. package/lib/modules/Rules/index.js +26 -27
  137. package/lib/modules/Rules/types.d.ts +1 -0
  138. package/lib/modules/SalesSummary/index.js +4 -2
  139. package/lib/modules/SalesSummary/utils.js +21 -7
  140. package/lib/modules/Schedule/index.js +3 -1
  141. package/lib/modules/index.d.ts +1 -0
  142. package/lib/modules/index.js +3 -1
  143. package/lib/server/index.js +41 -4
  144. package/lib/server/modules/order/index.d.ts +23 -0
  145. package/lib/server/modules/order/index.js +46 -14
  146. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  147. package/lib/server/modules/products/index.d.ts +1 -1
  148. package/lib/server/modules/products/index.js +30 -20
  149. package/lib/server/modules/schedule/index.js +2 -1
  150. package/lib/solution/BaseSales/index.d.ts +89 -7
  151. package/lib/solution/BaseSales/index.js +742 -23
  152. package/lib/solution/BaseSales/types.d.ts +67 -1
  153. package/lib/solution/BaseSales/types.js +3 -1
  154. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  155. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  156. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  157. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  158. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  159. package/lib/solution/BaseSales/utils.js +46 -6
  160. package/lib/solution/BookingByStep/index.d.ts +1 -1
  161. package/lib/solution/BookingTicket/index.d.ts +152 -2
  162. package/lib/solution/BookingTicket/index.js +389 -9
  163. package/lib/solution/BookingTicket/types.d.ts +2 -0
  164. package/lib/solution/BookingTicket/types.js +6 -0
  165. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  166. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  167. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  168. package/lib/solution/ScanOrder/index.d.ts +9 -3
  169. package/lib/solution/ScanOrder/index.js +147 -66
  170. package/lib/solution/ScanOrder/utils.js +46 -6
  171. package/lib/solution/VenueBooking/index.d.ts +5 -2
  172. package/lib/solution/VenueBooking/index.js +50 -14
  173. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  174. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  175. package/package.json +1 -1
@@ -0,0 +1,7 @@
1
+ import type { QuotationModule } from '../../../modules/Quotation';
2
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../types';
3
+ interface BuildBaseSalesQuotationPriceParams extends BaseSalesCalculateProductBookingPriceParams {
4
+ quotation?: Pick<QuotationModule, 'getPriceForProduct' | 'getQuotationShelfId'> | null;
5
+ }
6
+ export declare function calculateBaseSalesProductBookingPrice(params: BuildBaseSalesQuotationPriceParams): BaseSalesProductBookingPriceResult;
7
+ export {};
@@ -0,0 +1,277 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/solution/BaseSales/utils/quotationPrice.ts
30
+ var quotationPrice_exports = {};
31
+ __export(quotationPrice_exports, {
32
+ calculateBaseSalesProductBookingPrice: () => calculateBaseSalesProductBookingPrice
33
+ });
34
+ module.exports = __toCommonJS(quotationPrice_exports);
35
+ var import_dayjs = __toESM(require("dayjs"));
36
+ var import_decimal = __toESM(require("decimal.js"));
37
+ function toFiniteNumber(value, fallback = 0) {
38
+ const parsedValue = Number(value);
39
+ if (!Number.isFinite(parsedValue))
40
+ return fallback;
41
+ return parsedValue;
42
+ }
43
+ function toPositiveInt(value, fallback = 1) {
44
+ const parsedValue = Math.floor(Number(value));
45
+ if (!Number.isFinite(parsedValue) || parsedValue < 1)
46
+ return fallback;
47
+ return parsedValue;
48
+ }
49
+ function toPriceString(value) {
50
+ return new import_decimal.default(Number(value) || 0).toDecimalPlaces(2).toFixed(2);
51
+ }
52
+ function normalizeDateTime(value) {
53
+ if (typeof value !== "string" || !value.trim())
54
+ return null;
55
+ const normalized = value.includes(":") ? value : `${value} 00:00:00`;
56
+ const datetime = (0, import_dayjs.default)(normalized);
57
+ if (!datetime.isValid())
58
+ return null;
59
+ return datetime;
60
+ }
61
+ function buildBookingDateTime(date, time) {
62
+ if (typeof date !== "string" || !date.trim())
63
+ return null;
64
+ const timeText = typeof time === "string" && time.trim() ? time.trim() : "00:00";
65
+ const datetime = (0, import_dayjs.default)(`${date.trim()} ${timeText}`);
66
+ if (!datetime.isValid())
67
+ return null;
68
+ return datetime;
69
+ }
70
+ function getDurationUnit(type) {
71
+ const normalizedType = String(type || "").toLowerCase();
72
+ if (normalizedType === "day" || normalizedType === "days")
73
+ return "day";
74
+ if (normalizedType === "minute" || normalizedType === "minutes")
75
+ return "minute";
76
+ return null;
77
+ }
78
+ function getProductId(product) {
79
+ const productId = toFiniteNumber(product.product_id ?? product.id, NaN);
80
+ if (!Number.isFinite(productId))
81
+ return null;
82
+ return productId;
83
+ }
84
+ function getProductVariantId(product) {
85
+ const variantId = toFiniteNumber(
86
+ product.product_variant_id ?? product.variant_id,
87
+ 0
88
+ );
89
+ if (!Number.isFinite(variantId) || variantId <= 0)
90
+ return void 0;
91
+ return variantId;
92
+ }
93
+ function getFallbackPrice(params) {
94
+ const product = params.product || {};
95
+ return toPriceString(
96
+ params.fallback_price ?? product.price ?? product.selling_price ?? product.original_price ?? 0
97
+ );
98
+ }
99
+ function getProductQuantity(product) {
100
+ return toPositiveInt(product.num ?? product.quantity, 1);
101
+ }
102
+ function getBundleProductId(bundle) {
103
+ const productId = toFiniteNumber(
104
+ bundle.bundle_product_id ?? bundle._bundle_product_id,
105
+ NaN
106
+ );
107
+ if (!Number.isFinite(productId))
108
+ return null;
109
+ return productId;
110
+ }
111
+ function getBundleVariantId(bundle) {
112
+ const variantId = toFiniteNumber(
113
+ bundle.bundle_variant_id ?? bundle.variant_id,
114
+ 0
115
+ );
116
+ if (!Number.isFinite(variantId) || variantId <= 0)
117
+ return void 0;
118
+ return variantId;
119
+ }
120
+ function getBundleFallbackPrice(bundle) {
121
+ return toPriceString(
122
+ bundle.bundle_selling_price ?? bundle.price ?? bundle.original_price ?? bundle.base_price ?? 0
123
+ );
124
+ }
125
+ function shouldSplitByDuration(duration, start, end) {
126
+ if (!duration)
127
+ return false;
128
+ if (!start || !end || !end.isAfter(start))
129
+ return false;
130
+ const unit = getDurationUnit(duration.type);
131
+ const value = toFiniteNumber(duration.value);
132
+ return !!unit && value > 0;
133
+ }
134
+ function buildTimeSegments(params) {
135
+ const booking = params.booking || {};
136
+ const explicitDatetime = normalizeDateTime(params.datetime);
137
+ const bookingStart = buildBookingDateTime(booking.start_date, booking.start_time);
138
+ const start = bookingStart || explicitDatetime || (0, import_dayjs.default)();
139
+ const bookingEnd = buildBookingDateTime(booking.end_date, booking.end_time);
140
+ if (!shouldSplitByDuration(params.duration, start, bookingEnd)) {
141
+ return [{ start }];
142
+ }
143
+ const unit = getDurationUnit(params.duration.type);
144
+ const value = toFiniteNumber(params.duration.value);
145
+ const segments = [];
146
+ let cursor = start;
147
+ let guard = 0;
148
+ while (cursor.isBefore(bookingEnd) && guard < 1e4) {
149
+ const next = cursor.add(value, unit);
150
+ segments.push({
151
+ start: cursor,
152
+ end: next.isBefore(bookingEnd) ? next : bookingEnd ?? void 0
153
+ });
154
+ cursor = next;
155
+ guard += 1;
156
+ }
157
+ return segments.length ? segments : [{ start }];
158
+ }
159
+ function formatTimePoint(datetime) {
160
+ return datetime.format("YYYY-MM-DD HH:mm:ss");
161
+ }
162
+ function buildPriceSegment(params) {
163
+ const timePoint = formatTimePoint(params.segment.start);
164
+ const quotedPrice = params.quotation && params.productId !== null ? params.quotation.getPriceForProduct({
165
+ productId: params.productId,
166
+ variantId: params.variantId,
167
+ datetime: timePoint,
168
+ customer_id: params.customerId
169
+ }) : null;
170
+ const unitPrice = toPriceString(quotedPrice ?? params.fallbackPrice);
171
+ const quotationShelfId = quotedPrice !== null && params.quotation && params.productId !== null ? params.quotation.getQuotationShelfId({
172
+ productId: params.productId,
173
+ variantId: params.variantId,
174
+ datetime: timePoint,
175
+ customer_id: params.customerId
176
+ }) : 0;
177
+ return {
178
+ start_datetime: timePoint,
179
+ end_datetime: params.segment.end ? formatTimePoint(params.segment.end) : void 0,
180
+ time_point: timePoint,
181
+ unit_price: unitPrice,
182
+ quantity: 1,
183
+ total_price: unitPrice,
184
+ quotation_shelf_id: quotationShelfId,
185
+ source: quotedPrice !== null ? "quotation" : "fallback"
186
+ };
187
+ }
188
+ function calculatePriceForProduct(params) {
189
+ var _a;
190
+ const segments = params.segments.map((segment) => buildPriceSegment({
191
+ quotation: params.quotation,
192
+ productId: params.productId,
193
+ variantId: params.variantId,
194
+ customerId: params.customerId,
195
+ fallbackPrice: params.fallbackPrice,
196
+ segment
197
+ }));
198
+ const unitPrice = segments.reduce(
199
+ (total, segment) => total.plus(segment.total_price),
200
+ new import_decimal.default(0)
201
+ );
202
+ const totalPrice = unitPrice.times(params.quantity);
203
+ const quotationShelfId = ((_a = segments.find((segment) => segment.quotation_shelf_id)) == null ? void 0 : _a.quotation_shelf_id) || 0;
204
+ return {
205
+ unitPrice,
206
+ totalPrice,
207
+ quotationShelfId,
208
+ segments
209
+ };
210
+ }
211
+ function calculateBundlePrices(params, segments) {
212
+ var _a;
213
+ const bundleList = ((_a = params.product) == null ? void 0 : _a.product_bundle) || [];
214
+ if (!bundleList.length)
215
+ return void 0;
216
+ return bundleList.map((bundle) => {
217
+ const productId = getBundleProductId(bundle);
218
+ const variantId = getBundleVariantId(bundle);
219
+ const quantity = getProductQuantity(bundle);
220
+ const price = calculatePriceForProduct({
221
+ quotation: params.quotation,
222
+ productId,
223
+ variantId,
224
+ customerId: params.customer_id,
225
+ quantity,
226
+ fallbackPrice: getBundleFallbackPrice(bundle),
227
+ segments
228
+ });
229
+ return {
230
+ bundle_id: bundle.bundle_id ?? bundle.id,
231
+ group_id: bundle.group_id,
232
+ bundle_group_id: bundle.bundle_group_id,
233
+ bundle_product_id: productId,
234
+ bundle_variant_id: variantId ?? 0,
235
+ unit_price: price.unitPrice.toDecimalPlaces(2).toFixed(2),
236
+ total_price: price.totalPrice.toDecimalPlaces(2).toFixed(2),
237
+ quantity,
238
+ quotation_shelf_id: price.quotationShelfId,
239
+ source: price.segments.some((segment) => segment.source === "quotation") ? "quotation" : "fallback",
240
+ segments: price.segments
241
+ };
242
+ });
243
+ }
244
+ function calculateBaseSalesProductBookingPrice(params) {
245
+ const product = params.product || {};
246
+ const productId = getProductId(product);
247
+ const variantId = getProductVariantId(product);
248
+ const productQuantity = getProductQuantity(product);
249
+ const fallbackPrice = getFallbackPrice(params);
250
+ const timeSegments = buildTimeSegments(params);
251
+ const price = calculatePriceForProduct({
252
+ quotation: params.quotation,
253
+ productId,
254
+ variantId,
255
+ customerId: params.customer_id,
256
+ quantity: productQuantity,
257
+ fallbackPrice,
258
+ segments: timeSegments
259
+ });
260
+ const bundlePrices = calculateBundlePrices(params, timeSegments);
261
+ return {
262
+ product_id: productId,
263
+ product_variant_id: variantId ?? 0,
264
+ customer_id: params.customer_id,
265
+ unit_price: price.unitPrice.toDecimalPlaces(2).toFixed(2),
266
+ total_price: price.totalPrice.toDecimalPlaces(2).toFixed(2),
267
+ quantity: productQuantity,
268
+ duration: params.duration,
269
+ quotation_shelf_id: price.quotationShelfId,
270
+ segments: price.segments,
271
+ ...bundlePrices ? { product_bundle: bundlePrices } : {}
272
+ };
273
+ }
274
+ // Annotate the CommonJS export names for ESM import in node:
275
+ 0 && (module.exports = {
276
+ calculateBaseSalesProductBookingPrice
277
+ });
@@ -22,6 +22,7 @@ __export(transformBaseProductToOrderProduct_exports, {
22
22
  transformBaseProductToOrderProduct: () => transformBaseProductToOrderProduct
23
23
  });
24
24
  module.exports = __toCommonJS(transformBaseProductToOrderProduct_exports);
25
+ var import_manualProductDiscount = require("../../../modules/Order/utils/manualProductDiscount");
25
26
  function toNumber(value, fallback = 0) {
26
27
  const parsedValue = Number(value);
27
28
  if (!Number.isFinite(parsedValue))
@@ -62,13 +63,23 @@ function normalizeOptionItems(optionItems) {
62
63
  };
63
64
  });
64
65
  }
65
- function normalizeBundleItems(bundleItems) {
66
+ function normalizeBundleItems(bundleItems, preferPriceField = false) {
66
67
  if (!Array.isArray(bundleItems))
67
68
  return [];
68
- return bundleItems.map((bundleItem) => ({
69
- ...bundleItem,
70
- option: normalizeOptionItems(bundleItem == null ? void 0 : bundleItem.option)
71
- }));
69
+ return bundleItems.map((bundleItem) => {
70
+ const unitSelling = preferPriceField ? bundleItem.price ?? bundleItem.bundle_selling_price ?? bundleItem.custom_price ?? bundleItem.product_price ?? "0" : bundleItem.bundle_selling_price ?? bundleItem.price ?? bundleItem.custom_price ?? bundleItem.product_price ?? "0";
71
+ const unitStr = toPriceString(unitSelling, "0.00");
72
+ const num = toSafePositiveInt((bundleItem == null ? void 0 : bundleItem.num) ?? (bundleItem == null ? void 0 : bundleItem.quantity), 1);
73
+ return {
74
+ ...bundleItem,
75
+ num,
76
+ quantity: (bundleItem == null ? void 0 : bundleItem.quantity) ?? num,
77
+ price: bundleItem.price ?? unitStr,
78
+ bundle_selling_price: unitStr,
79
+ original_price: bundleItem.original_price ?? bundleItem.product_price ?? bundleItem.price ?? unitStr,
80
+ option: normalizeOptionItems(bundleItem == null ? void 0 : bundleItem.option)
81
+ };
82
+ });
72
83
  }
73
84
  function findVariantById(origin, variantId) {
74
85
  if (!origin || !variantId || variantId <= 0)
@@ -77,7 +88,7 @@ function findVariantById(origin, variantId) {
77
88
  return variants.find((variant) => Number(variant == null ? void 0 : variant.id) === variantId) || null;
78
89
  }
79
90
  function transformBaseProductToOrderProduct(params) {
80
- var _a, _b;
91
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
81
92
  const { payload, fallbackProductId = null } = params;
82
93
  if (!payload || typeof payload !== "object")
83
94
  return null;
@@ -101,13 +112,52 @@ function transformBaseProductToOrderProduct(params) {
101
112
  payload.price ?? payload.selling_price ?? (matchedVariant == null ? void 0 : matchedVariant.price) ?? (matchedVariant == null ? void 0 : matchedVariant.base_price) ?? (origin == null ? void 0 : origin.price) ?? (origin == null ? void 0 : origin.base_price) ?? (sourceProduct == null ? void 0 : sourceProduct.price) ?? (sourceProduct == null ? void 0 : sourceProduct.selling_price) ?? (sourceProduct == null ? void 0 : sourceProduct.base_price),
102
113
  "0.00"
103
114
  );
115
+ const lineCompositeTotal = toPriceString(
116
+ payload.line_total ?? payload.total ?? ((_c = payload._extend) == null ? void 0 : _c.total),
117
+ sourceProductPrice
118
+ );
119
+ const hasPriceOverride = payload.price_override !== void 0 && payload.price_override !== null && payload.price_override !== "";
104
120
  const productOptionItem = normalizeOptionItems(
105
121
  payload.option ?? payload.options ?? payload.product_option_item
106
122
  );
107
123
  const productBundle = normalizeBundleItems(
108
- payload.bundle ?? payload.product_bundle
124
+ payload.bundle ?? payload.product_bundle,
125
+ hasPriceOverride
109
126
  );
110
- const uniqueIdentificationNumber = payload.unique_identification_number ?? payload.unique;
127
+ const uniqueIdentificationNumber = payload.unique_identification_number;
128
+ const resolvedQuantity = toSafePositiveInt(payload.quantity ?? payload.num, 1);
129
+ const originTotal = (0, import_manualProductDiscount.resolveManualDiscountOriginTotal)({
130
+ originTotal: payload.origin_total,
131
+ extendOriginTotal: (_d = payload._extend) == null ? void 0 : _d.origin_total,
132
+ originExtendOriginTotal: (_e = origin == null ? void 0 : origin._extend) == null ? void 0 : _e.origin_total,
133
+ sourceExtendOriginTotal: (_f = sourceProduct == null ? void 0 : sourceProduct._extend) == null ? void 0 : _f.origin_total,
134
+ catalogUnitPrice: (origin == null ? void 0 : origin.base_price) ?? (origin == null ? void 0 : origin.price) ?? (sourceProduct == null ? void 0 : sourceProduct.base_price) ?? (sourceProduct == null ? void 0 : sourceProduct.price),
135
+ quantity: resolvedQuantity
136
+ });
137
+ const sellingTotal = Number(
138
+ payload.line_total ?? payload.total ?? ((_g = payload._extend) == null ? void 0 : _g.total) ?? lineCompositeTotal
139
+ );
140
+ const discountReason = (0, import_manualProductDiscount.resolveManualDiscountReasonFromSources)({
141
+ discountReason: payload.discount_reason,
142
+ extendDiscountReason: (_h = payload._extend) == null ? void 0 : _h.discount_reason,
143
+ originExtendDiscountReason: (_i = origin == null ? void 0 : origin._extend) == null ? void 0 : _i.discount_reason
144
+ });
145
+ const lineOriginalPrice = hasPriceOverride && Number.isFinite(originTotal) ? toPriceString(originTotal) : lineCompositeTotal;
146
+ const manualDiscountList = (0, import_manualProductDiscount.shouldBuildManualProductDiscount)({
147
+ hasPriceOverride,
148
+ originTotal,
149
+ sellingTotal
150
+ }) ? (0, import_manualProductDiscount.mergeManualProductDiscountIntoList)(
151
+ payload.discount_list,
152
+ (0, import_manualProductDiscount.buildManualProductDiscountItem)({
153
+ originTotal: Number.isFinite(originTotal) ? originTotal : Number(lineOriginalPrice),
154
+ sellingTotal: Number.isFinite(sellingTotal) ? sellingTotal : Number(lineCompositeTotal),
155
+ quantity: resolvedQuantity,
156
+ message: discountReason,
157
+ discountway: (_j = payload._extend) == null ? void 0 : _j.discountway,
158
+ discount_per: (_k = payload._extend) == null ? void 0 : _k.discount_per
159
+ })
160
+ ) : payload.discount_list || [];
111
161
  const metadata = {
112
162
  unique: payload.unique,
113
163
  session: payload.session,
@@ -119,7 +169,14 @@ function transformBaseProductToOrderProduct(params) {
119
169
  policy_id: payload.policy_id,
120
170
  source_shop_id: payload.source_shop_id,
121
171
  origin,
122
- source_product_price: sourceProductPrice
172
+ source_product_price: sourceProductPrice,
173
+ main_product_selling_price: sourceProductPrice,
174
+ main_product_original_price: sourceProductPrice,
175
+ ...hasPriceOverride ? {
176
+ price_override: String(payload.price_override),
177
+ is_manual_discount: 1
178
+ } : {},
179
+ ...payload.bundle_edit !== void 0 ? { bundle_edit: payload.bundle_edit } : {}
123
180
  };
124
181
  if (uniqueIdentificationNumber) {
125
182
  metadata.unique_identification_number = String(uniqueIdentificationNumber);
@@ -128,11 +185,13 @@ function transformBaseProductToOrderProduct(params) {
128
185
  product_id: productId,
129
186
  product_variant_id: productVariantId,
130
187
  unique_identification_number: uniqueIdentificationNumber ? String(uniqueIdentificationNumber) : void 0,
131
- num: toSafePositiveInt(payload.quantity ?? payload.num, 1),
188
+ num: resolvedQuantity,
132
189
  product_option_item: productOptionItem,
133
190
  product_bundle: productBundle,
134
- selling_price: sourceProductPrice,
135
- original_price: sourceProductPrice,
191
+ discount_list: manualDiscountList,
192
+ // 折后行价由 normalizeOrderProduct 按 main + bundle 合成;手动改价时 bundle 已为分摊后单价
193
+ selling_price: lineCompositeTotal,
194
+ original_price: lineOriginalPrice,
136
195
  tax_fee: toPriceString(
137
196
  payload.tax_fee ?? (matchedVariant == null ? void 0 : matchedVariant.tax_fee) ?? (origin == null ? void 0 : origin.tax_fee) ?? (sourceProduct == null ? void 0 : sourceProduct.tax_fee),
138
197
  "0.00"
@@ -38,6 +38,7 @@ __export(utils_exports, {
38
38
  module.exports = __toCommonJS(utils_exports);
39
39
  var import_decimal = __toESM(require("decimal.js"));
40
40
  var import_utils = require("../../modules/Order/utils");
41
+ var import_manualProductDiscount = require("../../modules/Order/utils/manualProductDiscount");
41
42
  function createEmptySummary() {
42
43
  return {
43
44
  product_quantity: 0,
@@ -102,12 +103,40 @@ function isSkuOnlyDeleteIdentity(x) {
102
103
  return !("product_option_item" in x) && !("product_bundle" in x);
103
104
  }
104
105
  function normalizeOrderProduct(product) {
105
- var _a, _b, _c;
106
+ var _a, _b, _c, _d, _e, _f;
106
107
  const metadata = { ...product.metadata || {} };
107
108
  const resolvedIdentityKey = ((_a = product.metadata) == null ? void 0 : _a.unique_identification_number) ? String(product.metadata.unique_identification_number) : product.unique_identification_number && String(product.unique_identification_number).length > 0 ? String(product.unique_identification_number) : product.identity_key && String(product.identity_key).length > 0 ? String(product.identity_key) : (0, import_utils.createUuidV4)();
108
109
  metadata.unique_identification_number = resolvedIdentityKey;
109
- const normalizedBundle = (product.product_bundle || []).map((item) => ({
110
+ const priceOverride = metadata.price_override;
111
+ const originOtherBundle = (_d = (_c = (_b = metadata.origin) == null ? void 0 : _b._extend) == null ? void 0 : _c.other) == null ? void 0 : _d.bundle;
112
+ let bundleInput = product.product_bundle || [];
113
+ if (priceOverride !== void 0 && priceOverride !== null && priceOverride !== "" && Array.isArray(originOtherBundle) && originOtherBundle.length > 0) {
114
+ const priceById = /* @__PURE__ */ new Map();
115
+ originOtherBundle.forEach((item) => {
116
+ if ((item == null ? void 0 : item.id) == null)
117
+ return;
118
+ const unit = item.price ?? item.bundle_selling_price;
119
+ if (unit === void 0 || unit === null)
120
+ return;
121
+ priceById.set(String(item.id), String(unit));
122
+ });
123
+ const base = Array.isArray(bundleInput) && bundleInput.length > 0 ? bundleInput : originOtherBundle;
124
+ bundleInput = base.map((item) => {
125
+ const unit = priceById.get(String(item == null ? void 0 : item.id));
126
+ if (unit === void 0)
127
+ return item;
128
+ return {
129
+ ...item,
130
+ price: unit,
131
+ bundle_selling_price: unit
132
+ };
133
+ });
134
+ }
135
+ const normalizedBundle = bundleInput.map((item) => ({
110
136
  ...item,
137
+ bundle_id: item.bundle_id ?? item.id,
138
+ bundle_product_id: item.bundle_product_id ?? item._bundle_product_id,
139
+ bundle_group_id: item.bundle_group_id ?? item.group_id,
111
140
  bundle_selling_price: item.bundle_selling_price ?? item.price ?? "0.00",
112
141
  price: item.price ?? item.custom_price ?? item.bundle_selling_price ?? "0.00",
113
142
  price_type: item.price_type ?? item.custom_price_type ?? "",
@@ -117,8 +146,8 @@ function normalizeOrderProduct(product) {
117
146
  const optionSum = (0, import_utils.sumOptionUnitPrice)(normalizedOptions);
118
147
  const isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === "2";
119
148
  const variantId = Number(product.product_variant_id || 0);
120
- const variantList = variantId ? (_b = metadata == null ? void 0 : metadata.origin) == null ? void 0 : _b.variant : null;
121
- const variantPrice = Array.isArray(variantList) ? (_c = variantList.find((v) => Number(v == null ? void 0 : v.id) === variantId)) == null ? void 0 : _c.price : void 0;
149
+ const variantList = variantId ? (_e = metadata == null ? void 0 : metadata.origin) == null ? void 0 : _e.variant : null;
150
+ const variantPrice = Array.isArray(variantList) ? (_f = variantList.find((v) => Number(v == null ? void 0 : v.id) === variantId)) == null ? void 0 : _f.price : void 0;
122
151
  const resolvedSource = (() => {
123
152
  var _a2, _b2;
124
153
  if (metadata.source_product_price !== void 0) {
@@ -174,6 +203,17 @@ function normalizeOrderProduct(product) {
174
203
  bundle: normalizedBundle,
175
204
  useOriginalBundle: true
176
205
  });
206
+ const finalOriginalPrice = (0, import_utils.resolveManualOverrideLineOriginalPrice)(
207
+ { num: product.num, metadata, lineOriginalPrice: product.original_price },
208
+ composedOriginalPrice
209
+ );
210
+ const discountList = (0, import_manualProductDiscount.ensureManualProductDiscountList)({
211
+ discountList: product.discount_list,
212
+ metadata,
213
+ originalPrice: finalOriginalPrice,
214
+ sellingPrice: composedSellingPrice,
215
+ quantity: getSafeProductNum(product.num)
216
+ });
177
217
  return {
178
218
  order_detail_id: product.order_detail_id || null,
179
219
  product_id: product.product_id,
@@ -181,10 +221,10 @@ function normalizeOrderProduct(product) {
181
221
  product_variant_id: product.product_variant_id,
182
222
  product_option_item: normalizedOptions,
183
223
  selling_price: composedSellingPrice,
184
- original_price: composedOriginalPrice,
224
+ original_price: finalOriginalPrice,
185
225
  tax_fee: product.tax_fee || "0.00",
186
226
  is_charge_tax: product.is_charge_tax ?? 0,
187
- discount_list: product.discount_list || [],
227
+ discount_list: discountList,
188
228
  product_bundle: normalizedBundle,
189
229
  metadata,
190
230
  note: product.note != null ? String(product.note) : ""
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 2 | 3 | 5 | 6 | 4;
314
+ weekNum: 0 | 1 | 2 | 6 | 3 | 5 | 4;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;