@pisell/pisellos 2.2.170 → 2.2.171

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 (149) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/Customer/index.d.ts +0 -6
  3. package/dist/modules/Customer/index.js +83 -129
  4. package/dist/modules/Customer/types.d.ts +0 -2
  5. package/dist/modules/Discount/index.d.ts +4 -2
  6. package/dist/modules/Discount/index.js +93 -8
  7. package/dist/modules/Discount/types.d.ts +7 -1
  8. package/dist/modules/Order/index.d.ts +15 -27
  9. package/dist/modules/Order/index.js +322 -695
  10. package/dist/modules/Order/types.d.ts +14 -49
  11. package/dist/modules/Order/types.js +0 -2
  12. package/dist/modules/Order/utils.d.ts +0 -17
  13. package/dist/modules/Order/utils.js +26 -97
  14. package/dist/modules/Rules/index.d.ts +0 -4
  15. package/dist/modules/Rules/index.js +10 -26
  16. package/dist/modules/SalesSummary/index.js +2 -4
  17. package/dist/modules/index.d.ts +0 -1
  18. package/dist/modules/index.js +1 -2
  19. package/dist/server/modules/order/utils/filterOrders.js +6 -20
  20. package/dist/solution/BaseSales/index.d.ts +7 -46
  21. package/dist/solution/BaseSales/index.js +315 -1009
  22. package/dist/solution/BaseSales/types.d.ts +1 -53
  23. package/dist/solution/BaseSales/types.js +1 -3
  24. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +15 -65
  25. package/dist/solution/BaseSales/utils.js +8 -46
  26. package/dist/solution/BookingByStep/index.d.ts +1 -1
  27. package/dist/solution/BookingTicket/index.d.ts +1 -133
  28. package/dist/solution/BookingTicket/index.js +175 -768
  29. package/dist/solution/BookingTicket/types.d.ts +0 -2
  30. package/dist/solution/BookingTicket/types.js +0 -3
  31. package/dist/solution/ScanOrder/index.d.ts +3 -9
  32. package/dist/solution/ScanOrder/index.js +128 -231
  33. package/dist/solution/ScanOrder/utils.js +8 -46
  34. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  35. package/dist/solution/ShopDiscount/index.js +23 -18
  36. package/dist/solution/VenueBooking/index.d.ts +9 -5
  37. package/dist/solution/VenueBooking/index.js +55 -103
  38. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  39. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
  40. package/lib/modules/Customer/index.d.ts +0 -6
  41. package/lib/modules/Customer/index.js +11 -26
  42. package/lib/modules/Customer/types.d.ts +0 -2
  43. package/lib/modules/Discount/index.d.ts +4 -2
  44. package/lib/modules/Discount/index.js +63 -8
  45. package/lib/modules/Discount/types.d.ts +7 -1
  46. package/lib/modules/Order/index.d.ts +15 -27
  47. package/lib/modules/Order/index.js +84 -336
  48. package/lib/modules/Order/types.d.ts +14 -49
  49. package/lib/modules/Order/utils.d.ts +0 -17
  50. package/lib/modules/Order/utils.js +18 -105
  51. package/lib/modules/Rules/index.d.ts +0 -4
  52. package/lib/modules/Rules/index.js +14 -22
  53. package/lib/modules/SalesSummary/index.js +2 -4
  54. package/lib/modules/index.d.ts +0 -1
  55. package/lib/modules/index.js +1 -3
  56. package/lib/server/modules/order/utils/filterOrders.js +4 -12
  57. package/lib/solution/BaseSales/index.d.ts +7 -46
  58. package/lib/solution/BaseSales/index.js +20 -434
  59. package/lib/solution/BaseSales/types.d.ts +1 -53
  60. package/lib/solution/BaseSales/types.js +1 -3
  61. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +11 -70
  62. package/lib/solution/BaseSales/utils.js +6 -46
  63. package/lib/solution/BookingByStep/index.d.ts +1 -1
  64. package/lib/solution/BookingTicket/index.d.ts +1 -133
  65. package/lib/solution/BookingTicket/index.js +8 -341
  66. package/lib/solution/BookingTicket/types.d.ts +0 -2
  67. package/lib/solution/BookingTicket/types.js +0 -6
  68. package/lib/solution/ScanOrder/index.d.ts +3 -9
  69. package/lib/solution/ScanOrder/index.js +66 -147
  70. package/lib/solution/ScanOrder/utils.js +6 -46
  71. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  72. package/lib/solution/ShopDiscount/index.js +4 -2
  73. package/lib/solution/VenueBooking/index.d.ts +9 -5
  74. package/lib/solution/VenueBooking/index.js +14 -50
  75. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  76. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  77. package/package.json +2 -2
  78. package/dist/modules/BookingContext/index.d.ts +0 -37
  79. package/dist/modules/BookingContext/index.js +0 -436
  80. package/dist/modules/BookingContext/types.d.ts +0 -102
  81. package/dist/modules/BookingContext/types.js +0 -51
  82. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  83. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -193
  84. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  85. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -137
  86. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  87. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -215
  88. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  89. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  90. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  91. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  92. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  93. package/dist/modules/BookingContext/utils/index.js +0 -11
  94. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  95. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  96. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  97. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  98. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  99. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  100. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  101. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  102. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  103. package/dist/modules/BookingContext/utils/resources.js +0 -486
  104. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  105. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  106. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  107. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  108. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  109. package/dist/modules/Order/utils/manualProductDiscount.js +0 -212
  110. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  111. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -159
  112. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  113. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  114. package/lib/modules/BookingContext/index.d.ts +0 -37
  115. package/lib/modules/BookingContext/index.js +0 -297
  116. package/lib/modules/BookingContext/types.d.ts +0 -102
  117. package/lib/modules/BookingContext/types.js +0 -34
  118. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  119. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -207
  120. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  121. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -141
  122. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  123. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -198
  124. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  125. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  126. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  127. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  128. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  129. package/lib/modules/BookingContext/utils/index.js +0 -43
  130. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  131. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  132. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  133. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  134. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  135. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  136. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  137. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  138. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  139. package/lib/modules/BookingContext/utils/resources.js +0 -377
  140. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  141. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  142. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  143. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  144. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  145. package/lib/modules/Order/utils/manualProductDiscount.js +0 -207
  146. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  147. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -201
  148. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  149. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
@@ -1,42 +0,0 @@
1
- import dayjs from 'dayjs';
2
- import { getDurationValue } from './flexible';
3
- export interface TimeSlice {
4
- label: string;
5
- value: string;
6
- }
7
- export interface DurationSlice {
8
- label: string;
9
- value: number;
10
- }
11
- export interface TimeSlicesResult {
12
- timeSlices: TimeSlice[];
13
- durationSlicesBasedOnTime: DurationSlice[];
14
- }
15
- /**
16
- * 把一天切成等长时间槽,输出 timeSlices(开始时间标签)与 durationSlicesBasedOnTime(基于切片的时长选项)。
17
- *
18
- * 与 info2 `sliceDayIntoFiveMinutes` 行为等价;为了不依赖 `locales`,label 输出原始时间字符串('08:00 AM' / '90'),
19
- * UI 侧需要本地化展示时可基于 value 自行包装。
20
- *
21
- * @param config booking config `basic.service_time`,{ value: minutes }
22
- * @param isDay 是否跨日预约(true 时按 1~30 天切片)
23
- */
24
- export declare function sliceDayIntoFiveMinutes(config: {
25
- value?: number;
26
- } | undefined | null, isDay?: boolean): TimeSlicesResult;
27
- /**
28
- * 取「下一个 duration 选项」:优先用 defaultValue;否则在 array 中找匹配的;找不到取第一个。
29
- * 与 info2 `findNextDuration` 等价。
30
- */
31
- export declare function findNextDuration(current: {
32
- value?: number;
33
- } | undefined, array: DurationSlice[], defaultValue?: number): number | undefined;
34
- /** 取首选 time slice:若指定 date(HH:mm)则找第一个 >= date 的;否则第一个。 */
35
- export declare function findNextSlice(params: {
36
- timeSlices: TimeSlice[];
37
- index?: number;
38
- date?: string;
39
- }): string | undefined;
40
- /** 取 endDate;duration='flexible' 时取 endDate 与店铺营业时间的较小值,否则 startDate + duration 分钟。 */
41
- export declare function getEndDate(startDate: dayjs.Dayjs, duration: string | number, endDate: any, shopOpeningHours?: string): dayjs.Dayjs;
42
- export { getDurationValue };
@@ -1,124 +0,0 @@
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/modules/BookingContext/utils/timeSlices.ts
30
- var timeSlices_exports = {};
31
- __export(timeSlices_exports, {
32
- findNextDuration: () => findNextDuration,
33
- findNextSlice: () => findNextSlice,
34
- getDurationValue: () => import_flexible.getDurationValue,
35
- getEndDate: () => getEndDate,
36
- sliceDayIntoFiveMinutes: () => sliceDayIntoFiveMinutes
37
- });
38
- module.exports = __toCommonJS(timeSlices_exports);
39
- var import_dayjs = __toESM(require("dayjs"));
40
- var import_flexible = require("./flexible");
41
- function sliceDayIntoFiveMinutes(config, isDay) {
42
- const startTime = (0, import_dayjs.default)().startOf("day");
43
- const endTime = (0, import_dayjs.default)().endOf("day");
44
- const timeSlice = config && config.value || 5;
45
- const timeSlices = [];
46
- const durationSlicesBasedOnTime = [];
47
- let currentTime = startTime;
48
- if (isDay) {
49
- let currentDay = 1;
50
- while (currentDay <= 30) {
51
- timeSlices.push({
52
- label: currentTime.format("hh:mm A"),
53
- value: currentTime.format("HH:mm")
54
- });
55
- durationSlicesBasedOnTime.push({
56
- label: String(currentDay),
57
- value: currentDay
58
- });
59
- currentDay += 1;
60
- }
61
- return { timeSlices, durationSlicesBasedOnTime };
62
- }
63
- while (currentTime.isBefore(endTime)) {
64
- timeSlices.push({
65
- label: currentTime.format("hh:mm A"),
66
- value: currentTime.format("HH:mm")
67
- });
68
- const nextTime = currentTime.add(timeSlice, "minute");
69
- const durationValue = nextTime.diff(startTime, "minute");
70
- durationSlicesBasedOnTime.push({
71
- label: String(durationValue),
72
- value: durationValue
73
- });
74
- currentTime = nextTime;
75
- }
76
- return { timeSlices, durationSlicesBasedOnTime };
77
- }
78
- function findNextDuration(current, array, defaultValue) {
79
- if (defaultValue !== void 0 && defaultValue !== null)
80
- return defaultValue;
81
- if (!array || array.length === 0)
82
- return void 0;
83
- for (let i = 0; i < array.length; i += 1) {
84
- if (array[i].value === (current == null ? void 0 : current.value))
85
- return array[i].value;
86
- }
87
- return array[0].value;
88
- }
89
- function findNextSlice(params) {
90
- var _a;
91
- const { timeSlices, index = 0, date = "" } = params;
92
- const currentTimeValue = date || (0, import_dayjs.default)().format("HH:mm");
93
- for (let i = 0; i < timeSlices.length; i += 1) {
94
- if (timeSlices[i].value !== "now" && timeSlices[i].value >= currentTimeValue) {
95
- return timeSlices[i].value;
96
- }
97
- }
98
- return (_a = timeSlices[index]) == null ? void 0 : _a.value;
99
- }
100
- function getEndDate(startDate, duration, endDate, shopOpeningHours) {
101
- if (duration === "flexible") {
102
- let openingDate = (0, import_dayjs.default)(
103
- `${startDate.format("YYYY-MM-DD")} ${shopOpeningHours || "23:59"}`
104
- );
105
- if ((0, import_dayjs.default)(startDate).isAfter(openingDate)) {
106
- openingDate = openingDate.add(1, "day");
107
- }
108
- if (!endDate)
109
- return openingDate;
110
- const endDateObj = (0, import_dayjs.default)(endDate);
111
- if (endDateObj.isAfter(openingDate))
112
- return openingDate;
113
- return endDateObj;
114
- }
115
- return startDate.add(Number(duration), "minute");
116
- }
117
- // Annotate the CommonJS export names for ESM import in node:
118
- 0 && (module.exports = {
119
- findNextDuration,
120
- findNextSlice,
121
- getDurationValue,
122
- getEndDate,
123
- sliceDayIntoFiveMinutes
124
- });
@@ -1,106 +0,0 @@
1
- /** 解析商品行数量(checkout 协议 product_num 语义 = 当前行 num) */
2
- export declare function resolveSafeProductNum(num?: number | null): number;
3
- /**
4
- * 将 discount_list 中 type=product 项的 product_num 同步为当前商品数量。
5
- *
6
- * @example
7
- * syncManualProductDiscountProductNum(line.discount_list, line.num);
8
- */
9
- export declare function syncManualProductDiscountProductNum(discountList: any[] | undefined | null, productNum?: number | null): any[];
10
- /** 从多源解析改价前行总价(与 cacheItem._extend.origin_total 语义一致) */
11
- export declare function resolveManualDiscountOriginTotal(sources: {
12
- originTotal?: unknown;
13
- extendOriginTotal?: unknown;
14
- originExtendOriginTotal?: unknown;
15
- sourceExtendOriginTotal?: unknown;
16
- catalogUnitPrice?: unknown;
17
- quantity?: number;
18
- }): number;
19
- /** 从 payload / extend / origin 解析手动折扣原因 */
20
- export declare function resolveManualDiscountReasonFromSources(sources: {
21
- discountReason?: unknown;
22
- extendDiscountReason?: unknown;
23
- originExtendDiscountReason?: unknown;
24
- }): string;
25
- /** 是否带手动改价标记(price_override / is_manual_discount) */
26
- export declare function hasManualProductDiscountFlag(metadata?: Record<string, any> | null): boolean;
27
- /**
28
- * normalize 兜底:手动改价但 discount_list 缺 type=product 时,按行级原价/折后价补写。
29
- *
30
- * @example
31
- * ensureManualProductDiscountList({
32
- * discountList: [],
33
- * metadata: { price_override: '5', is_manual_discount: 1 },
34
- * originalPrice: '11.00',
35
- * sellingPrice: '5.00',
36
- * quantity: 1,
37
- * });
38
- */
39
- export declare function ensureManualProductDiscountList(params: {
40
- discountList?: any[] | null;
41
- metadata?: Record<string, any> | null;
42
- originalPrice: string | number;
43
- sellingPrice: string | number;
44
- quantity?: number;
45
- }): any[];
46
- /** 商品手动折扣 discount_list 项(checkout 协议,type = product) */
47
- export interface ManualProductDiscountItem {
48
- amount: number;
49
- type: 'product';
50
- discount: {
51
- message: string;
52
- discountway: string;
53
- product_num: number;
54
- discount_per: string;
55
- discount_type: 'discount' | 'change_price';
56
- };
57
- }
58
- /**
59
- * 从 discount_list 中取手动改价项(type = product)。
60
- *
61
- * @example
62
- * const manual = findManualProductDiscountItem(product.discount_list);
63
- * manual?.discount.message; // 折扣原因
64
- */
65
- export declare function findManualProductDiscountItem(discountList?: any[] | null): ManualProductDiscountItem | undefined;
66
- /**
67
- * 解析折扣原因:优先 discount_list[type=product].discount.message。
68
- *
69
- * @example
70
- * resolveManualDiscountMessage(line.discount_list, line.metadata?.legacy_reason);
71
- */
72
- export declare function resolveManualDiscountMessage(discountList?: any[] | null, fallback?: string): string;
73
- /** 去掉 discount_list 中已有的手动改价项,避免重复叠加 */
74
- export declare function stripManualProductDiscountItems(discountList?: any[] | null): any[];
75
- /**
76
- * 由改价前后行总价构建手动折扣项;amount = |originTotal - sellingTotal|(行级差额)。
77
- *
78
- * @example
79
- * buildManualProductDiscountItem({
80
- * originTotal: 11,
81
- * sellingTotal: 4,
82
- * quantity: 1,
83
- * message: 'VIP',
84
- * });
85
- */
86
- export declare function buildManualProductDiscountItem(params: {
87
- originTotal: number;
88
- sellingTotal: number;
89
- quantity?: number;
90
- message?: string;
91
- discountway?: string;
92
- discount_per?: string;
93
- }): ManualProductDiscountItem;
94
- /**
95
- * 将手动改价项合并进 discount_list(替换已有 type=product 项)。
96
- *
97
- * @example
98
- * mergeManualProductDiscountIntoList(coupons, manualItem);
99
- */
100
- export declare function mergeManualProductDiscountIntoList(discountList: any[] | undefined | null, manualItem: ManualProductDiscountItem | null | undefined): any[];
101
- /** 是否应写入手动改价 discount_list 项 */
102
- export declare function shouldBuildManualProductDiscount(params: {
103
- hasPriceOverride?: boolean;
104
- originTotal?: number;
105
- sellingTotal?: number;
106
- }): boolean;
@@ -1,207 +0,0 @@
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/modules/Order/utils/manualProductDiscount.ts
30
- var manualProductDiscount_exports = {};
31
- __export(manualProductDiscount_exports, {
32
- buildManualProductDiscountItem: () => buildManualProductDiscountItem,
33
- ensureManualProductDiscountList: () => ensureManualProductDiscountList,
34
- findManualProductDiscountItem: () => findManualProductDiscountItem,
35
- hasManualProductDiscountFlag: () => hasManualProductDiscountFlag,
36
- mergeManualProductDiscountIntoList: () => mergeManualProductDiscountIntoList,
37
- resolveManualDiscountMessage: () => resolveManualDiscountMessage,
38
- resolveManualDiscountOriginTotal: () => resolveManualDiscountOriginTotal,
39
- resolveManualDiscountReasonFromSources: () => resolveManualDiscountReasonFromSources,
40
- resolveSafeProductNum: () => resolveSafeProductNum,
41
- shouldBuildManualProductDiscount: () => shouldBuildManualProductDiscount,
42
- stripManualProductDiscountItems: () => stripManualProductDiscountItems,
43
- syncManualProductDiscountProductNum: () => syncManualProductDiscountProductNum
44
- });
45
- module.exports = __toCommonJS(manualProductDiscount_exports);
46
- var import_decimal = __toESM(require("decimal.js"));
47
- function resolveSafeProductNum(num) {
48
- const parsed = Number(num);
49
- if (!Number.isFinite(parsed) || parsed <= 0)
50
- return 1;
51
- return Math.floor(parsed);
52
- }
53
- function syncManualProductDiscountProductNum(discountList, productNum) {
54
- const quantity = resolveSafeProductNum(productNum);
55
- return (discountList || []).map((item) => {
56
- if ((item == null ? void 0 : item.type) !== "product")
57
- return item;
58
- return {
59
- ...item,
60
- discount: {
61
- ...item.discount || {},
62
- product_num: quantity
63
- }
64
- };
65
- });
66
- }
67
- function resolveManualDiscountOriginTotal(sources) {
68
- const candidates = [
69
- sources.originTotal,
70
- sources.extendOriginTotal,
71
- sources.originExtendOriginTotal,
72
- sources.sourceExtendOriginTotal
73
- ];
74
- for (const candidate of candidates) {
75
- if (candidate === void 0 || candidate === null || candidate === "")
76
- continue;
77
- const parsed = Number(candidate);
78
- if (Number.isFinite(parsed))
79
- return parsed;
80
- }
81
- const unit = Number(sources.catalogUnitPrice);
82
- const quantity = sources.quantity ?? 1;
83
- if (Number.isFinite(unit) && unit > 0) {
84
- return new import_decimal.default(unit).mul(quantity).toNumber();
85
- }
86
- return NaN;
87
- }
88
- function resolveManualDiscountReasonFromSources(sources) {
89
- for (const candidate of [
90
- sources.discountReason,
91
- sources.extendDiscountReason,
92
- sources.originExtendDiscountReason
93
- ]) {
94
- if (candidate != null && String(candidate).trim() !== "") {
95
- return String(candidate);
96
- }
97
- }
98
- return "";
99
- }
100
- function hasManualProductDiscountFlag(metadata) {
101
- if (!metadata)
102
- return false;
103
- const override = metadata.price_override;
104
- if (override !== void 0 && override !== null && override !== "") {
105
- return true;
106
- }
107
- return metadata.is_manual_discount === 1 || metadata.is_manual_discount === true;
108
- }
109
- function ensureManualProductDiscountList(params) {
110
- var _a, _b, _c, _d, _e, _f, _g, _h;
111
- const list = params.discountList || [];
112
- const quantity = resolveSafeProductNum(params.quantity);
113
- if (findManualProductDiscountItem(list)) {
114
- return syncManualProductDiscountProductNum(list, quantity);
115
- }
116
- const metadata = params.metadata || {};
117
- const originalNum = Number(params.originalPrice);
118
- const sellingNum = Number(params.sellingPrice);
119
- const shouldBuild = hasManualProductDiscountFlag(metadata) || shouldBuildManualProductDiscount({ originTotal: originalNum, sellingTotal: sellingNum });
120
- if (!shouldBuild) {
121
- return list;
122
- }
123
- if (!Number.isFinite(originalNum) || !Number.isFinite(sellingNum) || originalNum === sellingNum) {
124
- return list;
125
- }
126
- const message = resolveManualDiscountMessage(
127
- list,
128
- resolveManualDiscountReasonFromSources({
129
- extendDiscountReason: (_b = (_a = metadata.origin) == null ? void 0 : _a._extend) == null ? void 0 : _b.discount_reason,
130
- originExtendDiscountReason: (_d = (_c = metadata.origin) == null ? void 0 : _c._extend) == null ? void 0 : _d.discount_reason
131
- })
132
- );
133
- return mergeManualProductDiscountIntoList(
134
- list,
135
- buildManualProductDiscountItem({
136
- originTotal: originalNum,
137
- sellingTotal: sellingNum,
138
- quantity,
139
- message,
140
- discountway: (_f = (_e = metadata.origin) == null ? void 0 : _e._extend) == null ? void 0 : _f.discountway,
141
- discount_per: (_h = (_g = metadata.origin) == null ? void 0 : _g._extend) == null ? void 0 : _h.discount_per
142
- })
143
- );
144
- }
145
- function findManualProductDiscountItem(discountList) {
146
- return (discountList || []).find((item) => (item == null ? void 0 : item.type) === "product");
147
- }
148
- function resolveManualDiscountMessage(discountList, fallback) {
149
- var _a, _b;
150
- const message = (_b = (_a = findManualProductDiscountItem(discountList)) == null ? void 0 : _a.discount) == null ? void 0 : _b.message;
151
- if (message != null && String(message).trim() !== "") {
152
- return String(message);
153
- }
154
- return fallback ?? "";
155
- }
156
- function stripManualProductDiscountItems(discountList) {
157
- return (discountList || []).filter((item) => (item == null ? void 0 : item.type) !== "product");
158
- }
159
- function buildManualProductDiscountItem(params) {
160
- const origin = new import_decimal.default(Number(params.originTotal) || 0);
161
- const selling = new import_decimal.default(Number(params.sellingTotal) || 0);
162
- const diff = origin.minus(selling);
163
- const quantity = resolveSafeProductNum(params.quantity);
164
- return {
165
- amount: diff.abs().toDecimalPlaces(2).toNumber(),
166
- type: "product",
167
- discount: {
168
- message: params.message ?? "",
169
- discountway: params.discountway ?? "num",
170
- product_num: quantity,
171
- discount_per: params.discount_per ?? "",
172
- discount_type: diff.isNegative() ? "change_price" : "discount"
173
- }
174
- };
175
- }
176
- function mergeManualProductDiscountIntoList(discountList, manualItem) {
177
- const base = stripManualProductDiscountItems(discountList);
178
- if (!manualItem)
179
- return base;
180
- if (manualItem.amount === 0 && !manualItem.discount.message)
181
- return base;
182
- return [...base, manualItem];
183
- }
184
- function shouldBuildManualProductDiscount(params) {
185
- if (params.hasPriceOverride)
186
- return true;
187
- const origin = Number(params.originTotal);
188
- const selling = Number(params.sellingTotal);
189
- if (!Number.isFinite(origin) || !Number.isFinite(selling))
190
- return false;
191
- return origin !== selling;
192
- }
193
- // Annotate the CommonJS export names for ESM import in node:
194
- 0 && (module.exports = {
195
- buildManualProductDiscountItem,
196
- ensureManualProductDiscountList,
197
- findManualProductDiscountItem,
198
- hasManualProductDiscountFlag,
199
- mergeManualProductDiscountIntoList,
200
- resolveManualDiscountMessage,
201
- resolveManualDiscountOriginTotal,
202
- resolveManualDiscountReasonFromSources,
203
- resolveSafeProductNum,
204
- shouldBuildManualProductDiscount,
205
- stripManualProductDiscountItems,
206
- syncManualProductDiscountProductNum
207
- });
@@ -1,7 +0,0 @@
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 {};
@@ -1,201 +0,0 @@
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
- });