@pisell/pisellos 2.2.171 → 2.2.172

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 (156) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +193 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.d.ts +2 -4
  35. package/dist/modules/Discount/index.js +8 -93
  36. package/dist/modules/Discount/types.d.ts +1 -7
  37. package/dist/modules/Order/index.d.ts +47 -16
  38. package/dist/modules/Order/index.js +743 -334
  39. package/dist/modules/Order/types.d.ts +57 -17
  40. package/dist/modules/Order/types.js +2 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
  43. package/dist/modules/Order/utils.d.ts +23 -1
  44. package/dist/modules/Order/utils.js +139 -30
  45. package/dist/modules/Quotation/index.js +16 -5
  46. package/dist/modules/Rules/index.d.ts +4 -0
  47. package/dist/modules/Rules/index.js +26 -10
  48. package/dist/modules/SalesSummary/index.js +4 -2
  49. package/dist/modules/Schedule/index.js +6 -2
  50. package/dist/modules/index.d.ts +1 -0
  51. package/dist/modules/index.js +2 -1
  52. package/dist/server/index.js +10 -6
  53. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  54. package/dist/server/modules/products/index.js +9 -8
  55. package/dist/server/modules/schedule/index.js +13 -6
  56. package/dist/solution/BaseSales/index.d.ts +65 -7
  57. package/dist/solution/BaseSales/index.js +1066 -315
  58. package/dist/solution/BaseSales/types.d.ts +53 -1
  59. package/dist/solution/BaseSales/types.js +3 -1
  60. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  61. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  62. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +65 -15
  63. package/dist/solution/BaseSales/utils.js +46 -8
  64. package/dist/solution/BookingTicket/index.d.ts +134 -2
  65. package/dist/solution/BookingTicket/index.js +768 -175
  66. package/dist/solution/BookingTicket/types.d.ts +2 -0
  67. package/dist/solution/BookingTicket/types.js +3 -0
  68. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  69. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  70. package/dist/solution/ScanOrder/index.d.ts +9 -3
  71. package/dist/solution/ScanOrder/index.js +231 -128
  72. package/dist/solution/ScanOrder/utils.js +46 -8
  73. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  74. package/dist/solution/ShopDiscount/index.js +18 -23
  75. package/dist/solution/VenueBooking/index.d.ts +5 -9
  76. package/dist/solution/VenueBooking/index.js +103 -55
  77. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  78. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  79. package/lib/modules/BookingContext/index.d.ts +37 -0
  80. package/lib/modules/BookingContext/index.js +297 -0
  81. package/lib/modules/BookingContext/types.d.ts +102 -0
  82. package/lib/modules/BookingContext/types.js +34 -0
  83. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  86. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  87. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  88. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  89. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  90. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  91. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  92. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  93. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  94. package/lib/modules/BookingContext/utils/index.js +43 -0
  95. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  96. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  97. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  98. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  99. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  100. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  101. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  102. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  103. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  104. package/lib/modules/BookingContext/utils/resources.js +377 -0
  105. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  106. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  107. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  108. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  109. package/lib/modules/Customer/index.d.ts +6 -0
  110. package/lib/modules/Customer/index.js +26 -11
  111. package/lib/modules/Customer/types.d.ts +2 -0
  112. package/lib/modules/Discount/index.d.ts +2 -4
  113. package/lib/modules/Discount/index.js +8 -63
  114. package/lib/modules/Discount/types.d.ts +1 -7
  115. package/lib/modules/Order/index.d.ts +47 -16
  116. package/lib/modules/Order/index.js +389 -90
  117. package/lib/modules/Order/types.d.ts +57 -17
  118. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  119. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  120. package/lib/modules/Order/utils.d.ts +23 -1
  121. package/lib/modules/Order/utils.js +145 -21
  122. package/lib/modules/Quotation/index.js +17 -6
  123. package/lib/modules/Rules/index.d.ts +4 -0
  124. package/lib/modules/Rules/index.js +22 -14
  125. package/lib/modules/SalesSummary/index.js +4 -2
  126. package/lib/modules/Schedule/index.js +3 -1
  127. package/lib/modules/index.d.ts +1 -0
  128. package/lib/modules/index.js +3 -1
  129. package/lib/server/index.js +2 -0
  130. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  131. package/lib/server/modules/products/index.js +8 -9
  132. package/lib/server/modules/schedule/index.js +2 -1
  133. package/lib/solution/BaseSales/index.d.ts +65 -7
  134. package/lib/solution/BaseSales/index.js +492 -20
  135. package/lib/solution/BaseSales/types.d.ts +53 -1
  136. package/lib/solution/BaseSales/types.js +3 -1
  137. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  138. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  139. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +70 -11
  140. package/lib/solution/BaseSales/utils.js +46 -6
  141. package/lib/solution/BookingTicket/index.d.ts +134 -2
  142. package/lib/solution/BookingTicket/index.js +341 -8
  143. package/lib/solution/BookingTicket/types.d.ts +2 -0
  144. package/lib/solution/BookingTicket/types.js +6 -0
  145. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  146. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  147. package/lib/solution/ScanOrder/index.d.ts +9 -3
  148. package/lib/solution/ScanOrder/index.js +147 -66
  149. package/lib/solution/ScanOrder/utils.js +46 -6
  150. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  151. package/lib/solution/ShopDiscount/index.js +2 -4
  152. package/lib/solution/VenueBooking/index.d.ts +5 -9
  153. package/lib/solution/VenueBooking/index.js +50 -14
  154. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  155. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  156. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLoggerModule as BaseSalesLoggerModule, ScheduleModule } from '../../modules';
1
+ import { OrderModule, ProductList, QuotationModule, SalesSummaryModule, ScanOrderLoggerModule as BaseSalesLoggerModule, ScheduleModule } from '../../modules';
2
2
  import type { ScanOrderLogInput as BaseSalesLogInput, ScanOrderLoggerProviderConfig as BaseSalesLoggerProviderConfig, ScanOrderLoggerProviderType as BaseSalesLoggerProviderType } from '../../modules/ScanOrderLogger/types';
3
3
  import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
4
4
  /**
@@ -11,6 +11,8 @@ export declare const BaseSalesHookNames: {
11
11
  readonly onRetryInit: "onRetryInit";
12
12
  readonly onRefresh: "onRefresh";
13
13
  readonly onCartValidationChanged: "onCartValidationChanged";
14
+ readonly onPaymentSyncStart: "onPaymentSyncStart";
15
+ readonly onPaymentSyncEnd: "onPaymentSyncEnd";
14
16
  };
15
17
  export type BaseSalesHookName = typeof BaseSalesHookNames[keyof typeof BaseSalesHookNames];
16
18
  export declare function createBaseSalesHook(moduleName: string, hookName: BaseSalesHookName): string;
@@ -42,6 +44,9 @@ export interface BaseSalesOrderProductIdentity {
42
44
  product_option_item?: any[];
43
45
  product_bundle?: any[];
44
46
  }
47
+ export interface BaseSalesUpdateOrderProductQuantityParams extends BaseSalesOrderProductIdentity {
48
+ num: number;
49
+ }
45
50
  export interface BaseSalesOrderProduct extends BaseSalesOrderProductIdentity {
46
51
  order_detail_id: number | null;
47
52
  num: number;
@@ -203,6 +208,52 @@ export interface BaseSalesSubmitPayload extends Omit<BaseSalesTempOrder, 'platfo
203
208
  }>;
204
209
  products: BaseSalesSubmitProduct[];
205
210
  }
211
+ export interface BaseSalesQuotationDurationConfig {
212
+ type: string;
213
+ value: number;
214
+ flexible_config?: {
215
+ is_enable_minimum_duration?: 0 | 1;
216
+ warning_threshold?: number;
217
+ block_threshold?: number;
218
+ };
219
+ }
220
+ export interface BaseSalesCalculateProductBookingPriceParams {
221
+ product: Record<string, any>;
222
+ booking?: {
223
+ start_date?: string;
224
+ start_time?: string;
225
+ end_date?: string;
226
+ end_time?: string;
227
+ [key: string]: any;
228
+ };
229
+ duration?: BaseSalesQuotationDurationConfig;
230
+ customer_id?: number | string;
231
+ fallback_price?: number | string;
232
+ datetime?: string;
233
+ channel?: string;
234
+ }
235
+ export type BaseSalesProductBookingPriceSegmentSource = 'quotation' | 'fallback';
236
+ export interface BaseSalesProductBookingPriceSegment {
237
+ start_datetime: string;
238
+ end_datetime?: string;
239
+ time_point: string;
240
+ unit_price: string;
241
+ quantity: number;
242
+ total_price: string;
243
+ quotation_shelf_id: number;
244
+ source: BaseSalesProductBookingPriceSegmentSource;
245
+ }
246
+ export interface BaseSalesProductBookingPriceResult {
247
+ product_id: number | null;
248
+ product_variant_id: number;
249
+ customer_id?: number | string;
250
+ unit_price: string;
251
+ total_price: string;
252
+ quantity: number;
253
+ duration?: BaseSalesQuotationDurationConfig;
254
+ quotation_shelf_id: number;
255
+ segments: BaseSalesProductBookingPriceSegment[];
256
+ }
206
257
  export type BaseSalesAvailabilityMode = 'idle' | 'shop_closed' | 'submit_disabled' | 'resource_busy' | 'additional_order_with_code' | 'additional_order';
207
258
  export interface BaseSalesTableFormRecord {
208
259
  policy?: string | null;
@@ -281,6 +332,7 @@ export interface BaseSalesState {
281
332
  error: string | null;
282
333
  products?: ProductList;
283
334
  order?: OrderModule;
335
+ quotation?: QuotationModule;
284
336
  salesSummary?: SalesSummaryModule;
285
337
  baseSalesLogger?: BaseSalesLoggerModule;
286
338
  schedule?: ScheduleModule;
@@ -28,7 +28,9 @@ var BaseSalesHookNames = {
28
28
  onDestroy: "onDestroy",
29
29
  onRetryInit: "onRetryInit",
30
30
  onRefresh: "onRefresh",
31
- onCartValidationChanged: "onCartValidationChanged"
31
+ onCartValidationChanged: "onCartValidationChanged",
32
+ onPaymentSyncStart: "onPaymentSyncStart",
33
+ onPaymentSyncEnd: "onPaymentSyncEnd"
32
34
  };
33
35
  function createBaseSalesHook(moduleName, hookName) {
34
36
  return `${moduleName}:${hookName}`;
@@ -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,201 @@
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 shouldSplitByDuration(duration, start, end) {
103
+ if (!duration)
104
+ return false;
105
+ if (!start || !end || !end.isAfter(start))
106
+ return false;
107
+ const unit = getDurationUnit(duration.type);
108
+ const value = toFiniteNumber(duration.value);
109
+ return !!unit && value > 0;
110
+ }
111
+ function buildTimeSegments(params) {
112
+ const booking = params.booking || {};
113
+ const explicitDatetime = normalizeDateTime(params.datetime);
114
+ const bookingStart = buildBookingDateTime(booking.start_date, booking.start_time);
115
+ const start = bookingStart || explicitDatetime || (0, import_dayjs.default)();
116
+ const bookingEnd = buildBookingDateTime(booking.end_date, booking.end_time);
117
+ if (!shouldSplitByDuration(params.duration, start, bookingEnd)) {
118
+ return [{ start }];
119
+ }
120
+ const unit = getDurationUnit(params.duration.type);
121
+ const value = toFiniteNumber(params.duration.value);
122
+ const segments = [];
123
+ let cursor = start;
124
+ let guard = 0;
125
+ while (cursor.isBefore(bookingEnd) && guard < 1e4) {
126
+ const next = cursor.add(value, unit);
127
+ segments.push({
128
+ start: cursor,
129
+ end: next.isBefore(bookingEnd) ? next : bookingEnd ?? void 0
130
+ });
131
+ cursor = next;
132
+ guard += 1;
133
+ }
134
+ return segments.length ? segments : [{ start }];
135
+ }
136
+ function formatTimePoint(datetime) {
137
+ return datetime.format("YYYY-MM-DD HH:mm:ss");
138
+ }
139
+ function buildPriceSegment(params) {
140
+ const timePoint = formatTimePoint(params.segment.start);
141
+ const quotedPrice = params.quotation && params.productId !== null ? params.quotation.getPriceForProduct({
142
+ productId: params.productId,
143
+ variantId: params.variantId,
144
+ datetime: timePoint,
145
+ customer_id: params.customerId
146
+ }) : null;
147
+ const unitPrice = toPriceString(quotedPrice ?? params.fallbackPrice);
148
+ const quotationShelfId = quotedPrice !== null && params.quotation && params.productId !== null ? params.quotation.getQuotationShelfId({
149
+ productId: params.productId,
150
+ variantId: params.variantId,
151
+ datetime: timePoint,
152
+ customer_id: params.customerId
153
+ }) : 0;
154
+ return {
155
+ start_datetime: timePoint,
156
+ end_datetime: params.segment.end ? formatTimePoint(params.segment.end) : void 0,
157
+ time_point: timePoint,
158
+ unit_price: unitPrice,
159
+ quantity: 1,
160
+ total_price: unitPrice,
161
+ quotation_shelf_id: quotationShelfId,
162
+ source: quotedPrice !== null ? "quotation" : "fallback"
163
+ };
164
+ }
165
+ function calculateBaseSalesProductBookingPrice(params) {
166
+ var _a;
167
+ const product = params.product || {};
168
+ const productId = getProductId(product);
169
+ const variantId = getProductVariantId(product);
170
+ const productQuantity = getProductQuantity(product);
171
+ const fallbackPrice = getFallbackPrice(params);
172
+ const segments = buildTimeSegments(params).map((segment) => buildPriceSegment({
173
+ quotation: params.quotation,
174
+ productId,
175
+ variantId,
176
+ customerId: params.customer_id,
177
+ fallbackPrice,
178
+ segment
179
+ }));
180
+ const unitPrice = segments.reduce(
181
+ (total, segment) => total.plus(segment.total_price),
182
+ new import_decimal.default(0)
183
+ );
184
+ const totalPrice = unitPrice.times(productQuantity);
185
+ const quotationShelfId = ((_a = segments.find((segment) => segment.quotation_shelf_id)) == null ? void 0 : _a.quotation_shelf_id) || 0;
186
+ return {
187
+ product_id: productId,
188
+ product_variant_id: variantId ?? 0,
189
+ customer_id: params.customer_id,
190
+ unit_price: unitPrice.toDecimalPlaces(2).toFixed(2),
191
+ total_price: totalPrice.toDecimalPlaces(2).toFixed(2),
192
+ quantity: productQuantity,
193
+ duration: params.duration,
194
+ quotation_shelf_id: quotationShelfId,
195
+ segments
196
+ };
197
+ }
198
+ // Annotate the CommonJS export names for ESM import in node:
199
+ 0 && (module.exports = {
200
+ calculateBaseSalesProductBookingPrice
201
+ });
@@ -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
127
  const uniqueIdentificationNumber = payload.unique_identification_number ?? payload.unique;
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) : ""