@pisell/pisellos 2.1.150 → 2.1.151

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 (201) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  4. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  6. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  7. package/dist/model/strategy/engine.d.ts +18 -5
  8. package/dist/model/strategy/engine.js +145 -45
  9. package/dist/model/strategy/type.d.ts +17 -0
  10. package/dist/model/strategy/type.js +4 -0
  11. package/dist/modules/Cart/types.d.ts +2 -0
  12. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  13. package/dist/modules/Discount/index.d.ts +2 -6
  14. package/dist/modules/Discount/index.js +8 -14
  15. package/dist/modules/Discount/types.d.ts +19 -1
  16. package/dist/modules/Order/index.d.ts +1 -65
  17. package/dist/modules/Order/index.js +30 -901
  18. package/dist/modules/Order/types.d.ts +12 -174
  19. package/dist/modules/Order/types.js +0 -2
  20. package/dist/modules/Order/utils.d.ts +0 -118
  21. package/dist/modules/Order/utils.js +2 -586
  22. package/dist/modules/Payment/index.d.ts +2 -1
  23. package/dist/modules/Payment/index.js +10 -7
  24. package/dist/modules/Payment/utils.js +3 -0
  25. package/dist/modules/Payment/walletpass.d.ts +23 -0
  26. package/dist/modules/Payment/walletpass.js +191 -95
  27. package/dist/modules/Product/utils.js +2 -2
  28. package/dist/modules/ProductList/index.d.ts +1 -1
  29. package/dist/modules/ProductList/index.js +3 -4
  30. package/dist/modules/Rules/index.d.ts +9 -5
  31. package/dist/modules/Rules/index.js +677 -168
  32. package/dist/modules/Rules/types.d.ts +2 -0
  33. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -11
  34. package/dist/modules/Schedule/utils.d.ts +1 -1
  35. package/dist/modules/Summary/types.d.ts +2 -0
  36. package/dist/modules/Summary/utils.d.ts +9 -3
  37. package/dist/modules/Summary/utils.js +52 -41
  38. package/dist/modules/index.d.ts +0 -4
  39. package/dist/modules/index.js +1 -5
  40. package/dist/plugins/window.d.ts +2 -0
  41. package/dist/solution/BookingByStep/index.d.ts +3 -2
  42. package/dist/solution/BookingByStep/index.js +43 -46
  43. package/dist/solution/BookingByStep/types.d.ts +1 -3
  44. package/dist/solution/BookingByStep/types.js +1 -5
  45. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  46. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  47. package/dist/solution/Checkout/index.js +2 -0
  48. package/dist/solution/ShopDiscount/index.d.ts +2 -2
  49. package/dist/solution/ShopDiscount/index.js +41 -37
  50. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  51. package/dist/solution/ShopDiscount/types.js +2 -1
  52. package/dist/solution/ShopDiscount/utils.js +26 -12
  53. package/dist/solution/index.d.ts +0 -2
  54. package/dist/solution/index.js +1 -3
  55. package/lib/index.d.ts +1 -0
  56. package/lib/index.js +3 -1
  57. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  58. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  59. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  60. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  61. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  62. package/lib/model/strategy/engine.d.ts +18 -5
  63. package/lib/model/strategy/engine.js +85 -21
  64. package/lib/model/strategy/type.d.ts +17 -0
  65. package/lib/modules/Cart/types.d.ts +2 -0
  66. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  67. package/lib/modules/Discount/index.d.ts +2 -6
  68. package/lib/modules/Discount/index.js +1 -3
  69. package/lib/modules/Discount/types.d.ts +19 -1
  70. package/lib/modules/Order/index.d.ts +1 -65
  71. package/lib/modules/Order/index.js +1 -513
  72. package/lib/modules/Order/types.d.ts +12 -174
  73. package/lib/modules/Order/utils.d.ts +0 -118
  74. package/lib/modules/Order/utils.js +2 -483
  75. package/lib/modules/Payment/index.d.ts +2 -1
  76. package/lib/modules/Payment/index.js +1 -0
  77. package/lib/modules/Payment/utils.js +3 -0
  78. package/lib/modules/Payment/walletpass.d.ts +23 -0
  79. package/lib/modules/Payment/walletpass.js +94 -17
  80. package/lib/modules/Product/utils.js +2 -2
  81. package/lib/modules/ProductList/index.d.ts +1 -1
  82. package/lib/modules/ProductList/index.js +3 -5
  83. package/lib/modules/Rules/index.d.ts +9 -5
  84. package/lib/modules/Rules/index.js +780 -288
  85. package/lib/modules/Rules/types.d.ts +2 -0
  86. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -9
  87. package/lib/modules/Schedule/utils.d.ts +1 -1
  88. package/lib/modules/Summary/types.d.ts +2 -0
  89. package/lib/modules/Summary/utils.d.ts +9 -3
  90. package/lib/modules/Summary/utils.js +31 -22
  91. package/lib/modules/index.d.ts +0 -4
  92. package/lib/modules/index.js +1 -9
  93. package/lib/plugins/window.d.ts +2 -0
  94. package/lib/solution/BookingByStep/index.d.ts +3 -2
  95. package/lib/solution/BookingByStep/index.js +4 -6
  96. package/lib/solution/BookingByStep/types.d.ts +1 -3
  97. package/lib/solution/BookingByStep/types.js +0 -10
  98. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  99. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  100. package/lib/solution/Checkout/index.js +2 -0
  101. package/lib/solution/ShopDiscount/index.d.ts +2 -2
  102. package/lib/solution/ShopDiscount/index.js +24 -16
  103. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  104. package/lib/solution/ShopDiscount/utils.js +10 -6
  105. package/lib/solution/index.d.ts +0 -2
  106. package/lib/solution/index.js +1 -5
  107. package/package.json +1 -1
  108. package/dist/apis/picoding.d.ts +0 -0
  109. package/dist/apis/picoding.js +0 -1
  110. package/dist/modules/OpenData/index.d.ts +0 -24
  111. package/dist/modules/OpenData/index.js +0 -173
  112. package/dist/modules/OpenData/types.d.ts +0 -73
  113. package/dist/modules/OpenData/types.js +0 -1
  114. package/dist/modules/OpenData/utils.d.ts +0 -2
  115. package/dist/modules/OpenData/utils.js +0 -75
  116. package/dist/modules/Quotation/index.d.ts +0 -48
  117. package/dist/modules/Quotation/index.js +0 -248
  118. package/dist/modules/Quotation/types.d.ts +0 -42
  119. package/dist/modules/Quotation/types.js +0 -1
  120. package/dist/modules/SalesSummary/index.d.ts +0 -63
  121. package/dist/modules/SalesSummary/index.js +0 -174
  122. package/dist/modules/SalesSummary/types.d.ts +0 -60
  123. package/dist/modules/SalesSummary/types.js +0 -1
  124. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  125. package/dist/modules/SalesSummary/utils.js +0 -480
  126. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  127. package/dist/modules/ScanOrderLogger/index.js +0 -174
  128. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  129. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  130. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  131. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  132. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  133. package/dist/modules/ScanOrderLogger/types.js +0 -1
  134. package/dist/solution/ScanOrder/index.d.ts +0 -152
  135. package/dist/solution/ScanOrder/index.js +0 -3132
  136. package/dist/solution/ScanOrder/types.d.ts +0 -287
  137. package/dist/solution/ScanOrder/types.js +0 -35
  138. package/dist/solution/ScanOrder/utils.d.ts +0 -167
  139. package/dist/solution/ScanOrder/utils.js +0 -764
  140. package/dist/solution/VenueBooking/index.d.ts +0 -199
  141. package/dist/solution/VenueBooking/index.js +0 -3459
  142. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  143. package/dist/solution/VenueBooking/types.d.ts +0 -154
  144. package/dist/solution/VenueBooking/types.js +0 -21
  145. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  146. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -104
  147. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  148. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  149. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
  150. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -239
  151. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
  152. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -453
  153. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  154. package/dist/solution/VenueBooking/utils.js +0 -1
  155. package/lib/apis/picoding.d.ts +0 -0
  156. package/lib/apis/picoding.js +0 -0
  157. package/lib/modules/OpenData/index.d.ts +0 -24
  158. package/lib/modules/OpenData/index.js +0 -119
  159. package/lib/modules/OpenData/types.d.ts +0 -73
  160. package/lib/modules/OpenData/types.js +0 -17
  161. package/lib/modules/OpenData/utils.d.ts +0 -2
  162. package/lib/modules/OpenData/utils.js +0 -111
  163. package/lib/modules/Quotation/index.d.ts +0 -48
  164. package/lib/modules/Quotation/index.js +0 -152
  165. package/lib/modules/Quotation/types.d.ts +0 -42
  166. package/lib/modules/Quotation/types.js +0 -17
  167. package/lib/modules/SalesSummary/index.d.ts +0 -63
  168. package/lib/modules/SalesSummary/index.js +0 -105
  169. package/lib/modules/SalesSummary/types.d.ts +0 -60
  170. package/lib/modules/SalesSummary/types.js +0 -17
  171. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  172. package/lib/modules/SalesSummary/utils.js +0 -420
  173. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  174. package/lib/modules/ScanOrderLogger/index.js +0 -147
  175. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  176. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  177. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  178. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  179. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  180. package/lib/modules/ScanOrderLogger/types.js +0 -17
  181. package/lib/solution/ScanOrder/index.d.ts +0 -152
  182. package/lib/solution/ScanOrder/index.js +0 -1901
  183. package/lib/solution/ScanOrder/types.d.ts +0 -287
  184. package/lib/solution/ScanOrder/types.js +0 -36
  185. package/lib/solution/ScanOrder/utils.d.ts +0 -167
  186. package/lib/solution/ScanOrder/utils.js +0 -635
  187. package/lib/solution/VenueBooking/index.d.ts +0 -199
  188. package/lib/solution/VenueBooking/index.js +0 -1926
  189. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  190. package/lib/solution/VenueBooking/types.d.ts +0 -154
  191. package/lib/solution/VenueBooking/types.js +0 -44
  192. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  193. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -110
  194. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  195. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  196. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
  197. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -237
  198. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
  199. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -339
  200. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  201. package/lib/solution/VenueBooking/utils.js +0 -69
@@ -1,420 +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/SalesSummary/utils.ts
30
- var utils_exports = {};
31
- __export(utils_exports, {
32
- calculateSalesSummary: () => calculateSalesSummary,
33
- createEmptySalesSummary: () => createEmptySalesSummary
34
- });
35
- module.exports = __toCommonJS(utils_exports);
36
- var import_decimal = __toESM(require("decimal.js"));
37
- var import_utils = require("../Summary/utils");
38
- function toDecimal(value) {
39
- return new import_decimal.default(value || 0);
40
- }
41
- function toFixed2(value) {
42
- return new import_decimal.default(value || 0).toFixed(2);
43
- }
44
- function getSafeNum(num) {
45
- if (!num || Number.isNaN(num))
46
- return 1;
47
- if (num < 1)
48
- return 1;
49
- return Math.floor(num);
50
- }
51
- function getBundleUnitPrice(product, useOriginal = false) {
52
- const bundleItems = product.product_bundle || [];
53
- return bundleItems.reduce((sum, item) => {
54
- const quantity = getSafeNum(item == null ? void 0 : item.num);
55
- const price = useOriginal ? toDecimal((item == null ? void 0 : item.original_price) ?? (item == null ? void 0 : item.product_price) ?? (item == null ? void 0 : item.price)) : toDecimal((item == null ? void 0 : item.bundle_selling_price) ?? (item == null ? void 0 : item.price));
56
- return sum.plus(price.times(quantity));
57
- }, new import_decimal.default(0));
58
- }
59
- function getUnitPaymentTotal(product) {
60
- var _a, _b;
61
- const mainSelling = (_a = product.metadata) == null ? void 0 : _a.main_product_selling_price;
62
- const mainOriginal = (_b = product.metadata) == null ? void 0 : _b.main_product_original_price;
63
- const basePrice = mainSelling !== void 0 ? toDecimal(mainSelling) : mainOriginal !== void 0 ? toDecimal(mainOriginal) : toDecimal(product.selling_price);
64
- return basePrice.plus(getBundleUnitPrice(product));
65
- }
66
- function getUnitOriginalTotal(product) {
67
- var _a, _b;
68
- const mainOriginal = (_a = product.metadata) == null ? void 0 : _a.main_product_original_price;
69
- const mainSelling = (_b = product.metadata) == null ? void 0 : _b.main_product_selling_price;
70
- const basePrice = mainOriginal !== void 0 ? toDecimal(mainOriginal) : mainSelling !== void 0 ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
71
- return basePrice.plus(getBundleUnitPrice(product, true));
72
- }
73
- function buildSurchargeServiceItems(products) {
74
- return products.map((product) => {
75
- var _a, _b;
76
- const quantity = getSafeNum(product.num);
77
- const unitTotal = getUnitPaymentTotal(product);
78
- return {
79
- id: product.product_id,
80
- num: quantity,
81
- total: unitTotal.toNumber(),
82
- price: unitTotal.toNumber(),
83
- is_charge_tax: product.is_charge_tax ?? 0,
84
- isCustomItem: product.product_id === null,
85
- _origin: product._origin || {
86
- product: {
87
- discount_list: product.discount_list || [],
88
- product_bundle: product.product_bundle || [],
89
- product_option_item: product.product_option_item || []
90
- }
91
- },
92
- bundle: product.product_bundle || [],
93
- option: product.product_option_item || [],
94
- options: product.product_option_item || [],
95
- relation_details: [],
96
- metadata: product.metadata || {},
97
- start_date: ((_a = product.metadata) == null ? void 0 : _a.start_date) || "",
98
- start_time: ((_b = product.metadata) == null ? void 0 : _b.start_time) || ""
99
- };
100
- });
101
- }
102
- function getProductDepositData(product) {
103
- var _a, _b, _c;
104
- const rootDepositData = (_a = product._origin) == null ? void 0 : _a.custom_deposit_data;
105
- if (rootDepositData && typeof rootDepositData === "object")
106
- return rootDepositData;
107
- const nestedDepositData = (_c = (_b = product._origin) == null ? void 0 : _b.product) == null ? void 0 : _c.custom_deposit_data;
108
- if (nestedDepositData && typeof nestedDepositData === "object")
109
- return nestedDepositData;
110
- return void 0;
111
- }
112
- function collectDepositPolicyIds(depositData) {
113
- const rawIds = [
114
- ...Array.isArray(depositData == null ? void 0 : depositData.self_deposit_policy_ids) ? depositData.self_deposit_policy_ids : [],
115
- ...Array.isArray(depositData == null ? void 0 : depositData.deposit_policy_ids) ? depositData.deposit_policy_ids : []
116
- ];
117
- return rawIds.reduce((result, id) => {
118
- const normalizedId = Number(id);
119
- if (!Number.isFinite(normalizedId))
120
- return result;
121
- result.push(Math.floor(normalizedId));
122
- return result;
123
- }, []);
124
- }
125
- function collectDepositPolicyData(depositData) {
126
- const rawPolicyData = Array.isArray(depositData == null ? void 0 : depositData.deposit_policy_data) ? depositData.deposit_policy_data : [];
127
- return rawPolicyData.reduce((result, policy) => {
128
- const normalizedId = Number(policy == null ? void 0 : policy.id);
129
- if (!Number.isFinite(normalizedId))
130
- return result;
131
- result.push({
132
- id: Math.floor(normalizedId),
133
- title: String((policy == null ? void 0 : policy.title) || "")
134
- });
135
- return result;
136
- }, []);
137
- }
138
- function calculateProductsDeposit(products) {
139
- let totalDeposit = new import_decimal.default(0);
140
- let hasDeposit = false;
141
- const policyIds = /* @__PURE__ */ new Set();
142
- const policyDataMap = /* @__PURE__ */ new Map();
143
- for (const product of products) {
144
- const depositData = getProductDepositData(product);
145
- if (!depositData || depositData.has_deposit != 1)
146
- continue;
147
- const num = getSafeNum(product.num);
148
- const unitTotal = getUnitPaymentTotal(product);
149
- const productTotal = unitTotal.times(num);
150
- const { deposit_fixed, deposit_percentage } = depositData;
151
- const fixed = toDecimal(deposit_fixed);
152
- const percentage = toDecimal(deposit_percentage);
153
- const itemDeposit = fixed.plus(percentage.times(productTotal));
154
- totalDeposit = totalDeposit.plus(itemDeposit);
155
- hasDeposit = true;
156
- for (const id of collectDepositPolicyIds(depositData)) {
157
- policyIds.add(id);
158
- }
159
- for (const policy of collectDepositPolicyData(depositData)) {
160
- if (!policyDataMap.has(policy.id)) {
161
- policyDataMap.set(policy.id, policy);
162
- }
163
- policyIds.add(policy.id);
164
- }
165
- }
166
- if (!hasDeposit)
167
- return void 0;
168
- for (const id of policyIds) {
169
- if (!policyDataMap.has(id)) {
170
- policyDataMap.set(id, {
171
- id,
172
- title: ""
173
- });
174
- }
175
- }
176
- return {
177
- total: totalDeposit.toFixed(2),
178
- deposit_policy_ids: [...policyIds],
179
- deposit_policy_data: [...policyDataMap.values()],
180
- hasDeposit: true
181
- };
182
- }
183
- function isBundleOriginalPrice(item) {
184
- return (item == null ? void 0 : item.price_type) === "markup" && (item == null ? void 0 : item.price_type_ext) === "product_price";
185
- }
186
- function isBundleMarkupOrDiscount(item) {
187
- const isMarkup = (item == null ? void 0 : item.price_type) === "markup" && ((item == null ? void 0 : item.price_type_ext) === "" || !(item == null ? void 0 : item.price_type_ext));
188
- const isDiscount = (item == null ? void 0 : item.price_type) === "markdown" && ((item == null ? void 0 : item.price_type_ext) === "" || !(item == null ? void 0 : item.price_type_ext));
189
- return isMarkup || isDiscount;
190
- }
191
- function calculateSingleItemTax(params) {
192
- const { price, taxRate, isPriceIncludeTax, isChargeTax } = params;
193
- if (price.lte(0))
194
- return new import_decimal.default(0);
195
- if (isChargeTax === 0 || !isChargeTax)
196
- return new import_decimal.default(0);
197
- const rate = taxRate.div(100);
198
- if (isPriceIncludeTax === 0) {
199
- return price.times(rate);
200
- }
201
- const divisor = new import_decimal.default(1).plus(rate);
202
- if (divisor.lte(0))
203
- return new import_decimal.default(0);
204
- return price.dividedBy(divisor).times(rate);
205
- }
206
- function getMainProductPaymentTotal(product) {
207
- var _a, _b;
208
- const mainSelling = ((_a = product.metadata) == null ? void 0 : _a.main_product_selling_price) ?? ((_b = product.metadata) == null ? void 0 : _b.main_product_original_price) ?? 0;
209
- let total = toDecimal(mainSelling);
210
- const bundleItems = product.product_bundle || [];
211
- for (const bundleItem of bundleItems) {
212
- if (isBundleMarkupOrDiscount(bundleItem)) {
213
- const unit = toDecimal(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
214
- const qty = getSafeNum(bundleItem.num ?? bundleItem.quantity);
215
- total = total.plus(unit.times(qty));
216
- }
217
- }
218
- return import_decimal.default.max(total, 0);
219
- }
220
- function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
221
- const rate = new import_decimal.default(taxRate);
222
- let preciseTax = new import_decimal.default(0);
223
- let roundedTax = new import_decimal.default(0);
224
- let preciseOriginTax = new import_decimal.default(0);
225
- let roundedOriginTax = new import_decimal.default(0);
226
- let lastTaxableItem = null;
227
- for (const product of products) {
228
- const quantity = new import_decimal.default(getSafeNum(product.num));
229
- const mainTotal = getMainProductPaymentTotal(product);
230
- const surchargeFee = toDecimal(product.surcharge_fee);
231
- const mainTaxableBase = mainTotal.lte(0) ? surchargeFee : mainTotal.plus(surchargeFee);
232
- const mainTaxPrecise = calculateSingleItemTax({
233
- price: mainTaxableBase,
234
- taxRate: rate,
235
- isPriceIncludeTax,
236
- isChargeTax: product.is_charge_tax ?? 0
237
- });
238
- const mainTaxRounded = mainTaxPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
239
- if (mainTaxPrecise.gt(0)) {
240
- lastTaxableItem = { type: "main", item: product };
241
- }
242
- const originalTotal = getUnitOriginalTotal(product);
243
- const originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
244
- const originalTaxPrecise = calculateSingleItemTax({
245
- price: originalTaxableBase,
246
- taxRate: rate,
247
- isPriceIncludeTax,
248
- isChargeTax: product.is_charge_tax ?? 0
249
- });
250
- let bundlePreciseTax = new import_decimal.default(0);
251
- let bundleRoundedTax = new import_decimal.default(0);
252
- let bundlePreciseOriginTax = new import_decimal.default(0);
253
- let bundleRoundedOriginTax = new import_decimal.default(0);
254
- const bundleItems = product.product_bundle || [];
255
- for (const bundleItem of bundleItems) {
256
- if (!isBundleOriginalPrice(bundleItem))
257
- continue;
258
- const bundleQuantity = new import_decimal.default(getSafeNum(bundleItem.num ?? bundleItem.quantity));
259
- const bundlePrice = toDecimal(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
260
- const bundleOriginalPrice = toDecimal(bundleItem.original_price ?? bundleItem.product_price ?? bundleItem.price ?? 0);
261
- const bundleTaxPrecise = calculateSingleItemTax({
262
- price: bundlePrice,
263
- taxRate: rate,
264
- isPriceIncludeTax,
265
- isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
266
- });
267
- const bundleTaxRounded = bundleTaxPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
268
- const bundleOrigTaxPrecise = calculateSingleItemTax({
269
- price: bundleOriginalPrice,
270
- taxRate: rate,
271
- isPriceIncludeTax,
272
- isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
273
- });
274
- const bundleOrigTaxRounded = bundleOrigTaxPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
275
- bundleItem.tax_fee = bundleTaxRounded.toNumber();
276
- bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
277
- bundlePreciseTax = bundlePreciseTax.plus(bundleTaxPrecise.times(bundleQuantity));
278
- bundleRoundedTax = bundleRoundedTax.plus(bundleTaxRounded.times(bundleQuantity));
279
- bundlePreciseOriginTax = bundlePreciseOriginTax.plus(bundleOrigTaxPrecise.times(bundleQuantity));
280
- bundleRoundedOriginTax = bundleRoundedOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
281
- if (bundleTaxPrecise.gt(0)) {
282
- lastTaxableItem = { type: "bundle", item: bundleItem };
283
- }
284
- }
285
- const itemTaxPrecise = mainTaxPrecise.plus(bundlePreciseTax);
286
- const itemTaxRounded = mainTaxRounded.plus(bundleRoundedTax);
287
- const itemOriginTaxPrecise = originalTaxPrecise.plus(bundlePreciseOriginTax);
288
- const itemOriginTaxRounded = originalTaxPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).plus(bundleRoundedOriginTax);
289
- product.tax_fee = itemTaxRounded.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toFixed(2);
290
- product.original_tax_fee = itemOriginTaxRounded.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
291
- preciseTax = preciseTax.plus(itemTaxPrecise.times(quantity));
292
- roundedTax = roundedTax.plus(itemTaxRounded.times(quantity));
293
- preciseOriginTax = preciseOriginTax.plus(itemOriginTaxPrecise.times(quantity));
294
- roundedOriginTax = roundedOriginTax.plus(itemOriginTaxRounded.times(quantity));
295
- }
296
- const expectedTax = preciseTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
297
- const expectedOriginTax = preciseOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
298
- const taxRemainder = expectedTax.minus(roundedTax).toNumber();
299
- const originTaxRemainder = expectedOriginTax.minus(roundedOriginTax).toNumber();
300
- if (lastTaxableItem) {
301
- if (taxRemainder !== 0) {
302
- lastTaxableItem.item.tax_fee_rounding_remainder = taxRemainder;
303
- }
304
- if (originTaxRemainder !== 0) {
305
- lastTaxableItem.item.original_tax_fee_rounding_remainder = originTaxRemainder;
306
- }
307
- }
308
- return { tax: expectedTax, originTax: expectedOriginTax };
309
- }
310
- function createEmptySalesSummary() {
311
- return {
312
- product_quantity: 0,
313
- product_original_amount: "0.00",
314
- product_amount: "0.00",
315
- product_expect_amount: "0.00",
316
- product_tax_fee: "0.00",
317
- shipping_fee: "0.00",
318
- shipping_tax_fee: "0.00",
319
- tax_fee: "0.00",
320
- surcharge_fee: "0.00",
321
- surcharges: [],
322
- discount_amount: "0.00",
323
- deposit_amount: "0.00",
324
- expect_amount: "0.00",
325
- total_amount: "0.00",
326
- amount_gap: "0.00",
327
- rounding_amount: "0.00",
328
- pay_service_charge_amount: "0.00"
329
- };
330
- }
331
- function calculateSalesSummary(params) {
332
- var _a;
333
- const {
334
- products,
335
- isPriceIncludeTax,
336
- taxRate,
337
- surchargeList,
338
- scheduleById = {},
339
- isInScheduleByDate
340
- } = params;
341
- if (!(products == null ? void 0 : products.length))
342
- return createEmptySalesSummary();
343
- const productQuantity = products.reduce(
344
- (sum, item) => sum + getSafeNum(item.num),
345
- 0
346
- );
347
- const productOriginalAmount = products.reduce(
348
- (sum, item) => sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num))),
349
- new import_decimal.default(0)
350
- );
351
- const productAmount = products.reduce(
352
- (sum, item) => sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num))),
353
- new import_decimal.default(0)
354
- );
355
- const surchargeServiceItems = buildSurchargeServiceItems(products);
356
- const surcharge = (0, import_utils.getSurcharge)(
357
- {
358
- service: surchargeServiceItems,
359
- addons: [],
360
- bookingDetail: null,
361
- bookingId: void 0
362
- },
363
- {
364
- isEdit: false,
365
- isInScheduleByDate,
366
- surcharge_list: surchargeList,
367
- scheduleById
368
- }
369
- );
370
- const surchargeAmount = new import_decimal.default(
371
- (0, import_utils.getSurchargeAmount)(
372
- { bookingDetail: null, bookingId: void 0 },
373
- surcharge,
374
- { isEdit: false }
375
- ) || 0
376
- );
377
- for (let i = 0; i < products.length; i++) {
378
- products[i].surcharge_fee = ((_a = surchargeServiceItems[i]) == null ? void 0 : _a.surcharge_fee) || 0;
379
- }
380
- const hasTaxRate = taxRate !== void 0 && taxRate !== null && taxRate > 0;
381
- let productTaxFee;
382
- if (hasTaxRate) {
383
- const taxResult = calculateProductsTax(products, taxRate, isPriceIncludeTax);
384
- productTaxFee = taxResult.tax;
385
- } else {
386
- productTaxFee = products.reduce(
387
- (sum, item) => sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num))),
388
- new import_decimal.default(0)
389
- );
390
- }
391
- const expectAmount = productAmount.plus(surchargeAmount);
392
- const totalAmount = isPriceIncludeTax === 1 ? expectAmount : expectAmount.plus(productTaxFee);
393
- const deposit = calculateProductsDeposit(products);
394
- return {
395
- product_quantity: productQuantity,
396
- product_original_amount: toFixed2(productOriginalAmount),
397
- product_amount: toFixed2(productAmount),
398
- product_expect_amount: toFixed2(productAmount),
399
- product_tax_fee: toFixed2(productTaxFee),
400
- shipping_fee: "0.00",
401
- shipping_tax_fee: "0.00",
402
- tax_fee: toFixed2(productTaxFee),
403
- surcharge_fee: toFixed2(surchargeAmount),
404
- surcharges: surcharge,
405
- discount_amount: toFixed2(import_decimal.default.max(productOriginalAmount.minus(productAmount), 0)),
406
- deposit_amount: deposit ? deposit.total : "0.00",
407
- deposit,
408
- expect_amount: toFixed2(expectAmount),
409
- total_amount: toFixed2(totalAmount),
410
- amount_gap: "0.00",
411
- rounding_amount: "0.00",
412
- pay_service_charge_amount: "0.00",
413
- is_price_include_tax: isPriceIncludeTax
414
- };
415
- }
416
- // Annotate the CommonJS export names for ESM import in node:
417
- 0 && (module.exports = {
418
- calculateSalesSummary,
419
- createEmptySalesSummary
420
- });
@@ -1,23 +0,0 @@
1
- import { BaseModule } from '../BaseModule';
2
- import { Module, ModuleOptions, PisellCore } from '../../types';
3
- import { ScanOrderLogInput, ScanOrderLoggerContext, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType } from './types';
4
- export interface ScanOrderLoggerModuleAPI {
5
- addLog: (params: ScanOrderLogInput) => Promise<void>;
6
- setContext: (context: ScanOrderLoggerContext) => void;
7
- setProvider: (provider: ScanOrderLoggerProviderType) => void;
8
- setProviderConfig: (providerConfig: ScanOrderLoggerProviderConfig) => void;
9
- }
10
- export declare class ScanOrderLoggerModule extends BaseModule implements Module, ScanOrderLoggerModuleAPI {
11
- protected defaultName: string;
12
- protected defaultVersion: string;
13
- private store;
14
- private window?;
15
- initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
16
- setContext(context: ScanOrderLoggerContext): void;
17
- setProvider(provider: ScanOrderLoggerProviderType): void;
18
- setProviderConfig(providerConfig: ScanOrderLoggerProviderConfig): void;
19
- private getCurrentHost;
20
- private buildRecord;
21
- addLog(params: ScanOrderLogInput): Promise<void>;
22
- }
23
- export * from './types';
@@ -1,147 +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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/modules/ScanOrderLogger/index.ts
31
- var ScanOrderLogger_exports = {};
32
- __export(ScanOrderLogger_exports, {
33
- ScanOrderLoggerModule: () => ScanOrderLoggerModule
34
- });
35
- module.exports = __toCommonJS(ScanOrderLogger_exports);
36
- var import_dayjs = __toESM(require("dayjs"));
37
- var import_BaseModule = require("../BaseModule");
38
- var import_feishu = require("./providers/feishu");
39
- var import_grafana = require("./providers/grafana");
40
- __reExport(ScanOrderLogger_exports, require("./types"), module.exports);
41
- var defaultProviderConfig = {
42
- feishu: {
43
- webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/REPLACE_ME"
44
- },
45
- grafana: {
46
- endpoint: "https://grafana.example.com/collect"
47
- }
48
- };
49
- var providerMap = {
50
- feishu: import_feishu.feishuLoggerProvider,
51
- grafana: import_grafana.grafanaLoggerProvider
52
- };
53
- var ScanOrderLoggerModule = class extends import_BaseModule.BaseModule {
54
- constructor() {
55
- super(...arguments);
56
- this.defaultName = "scanOrderLogger";
57
- this.defaultVersion = "1.0.0";
58
- }
59
- async initialize(core, options = {}) {
60
- var _a, _b, _c;
61
- this.core = core;
62
- this.store = options.store;
63
- this.window = core.getPlugin("window") || void 0;
64
- const provider = ((_a = options.otherParams) == null ? void 0 : _a.provider) || "feishu";
65
- const providerConfig = ((_b = options.otherParams) == null ? void 0 : _b.providerConfig) || {};
66
- const context = ((_c = options.otherParams) == null ? void 0 : _c.context) || {};
67
- this.store.provider = provider;
68
- this.store.providerConfig = {
69
- ...defaultProviderConfig,
70
- ...providerConfig,
71
- feishu: {
72
- ...defaultProviderConfig.feishu,
73
- ...providerConfig.feishu || {}
74
- },
75
- grafana: {
76
- ...defaultProviderConfig.grafana,
77
- ...providerConfig.grafana || {}
78
- }
79
- };
80
- this.store.context = context;
81
- }
82
- setContext(context) {
83
- this.store.context = {
84
- ...this.store.context,
85
- ...context
86
- };
87
- }
88
- setProvider(provider) {
89
- this.store.provider = provider;
90
- }
91
- setProviderConfig(providerConfig) {
92
- this.store.providerConfig = {
93
- ...this.store.providerConfig,
94
- ...providerConfig,
95
- feishu: {
96
- ...this.store.providerConfig.feishu || {},
97
- ...providerConfig.feishu || {}
98
- },
99
- grafana: {
100
- ...this.store.providerConfig.grafana || {},
101
- ...providerConfig.grafana || {}
102
- }
103
- };
104
- }
105
- getCurrentHost() {
106
- var _a, _b;
107
- const host = (_b = (_a = this.window) == null ? void 0 : _a.location) == null ? void 0 : _b.host;
108
- if (typeof host === "string" && host.length > 0)
109
- return host;
110
- return void 0;
111
- }
112
- buildRecord(params) {
113
- const host = this.getCurrentHost();
114
- return {
115
- level: params.level || "info",
116
- title: params.title,
117
- timestamp: params.timestamp || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
118
- payload: params.payload || {},
119
- extra: params.extra || {},
120
- context: {
121
- ...this.store.context || {},
122
- ...host ? { host } : {}
123
- }
124
- };
125
- }
126
- async addLog(params) {
127
- if (!params.title) {
128
- console.warn("[ScanOrderLogger] 缺少日志标题,已跳过");
129
- return;
130
- }
131
- const provider = providerMap[this.store.provider] || import_feishu.feishuLoggerProvider;
132
- const record = this.buildRecord(params);
133
- try {
134
- await provider.send({
135
- record,
136
- providerConfig: this.store.providerConfig
137
- });
138
- } catch (error) {
139
- console.warn("[ScanOrderLogger] 日志上报失败", error);
140
- }
141
- }
142
- };
143
- // Annotate the CommonJS export names for ESM import in node:
144
- 0 && (module.exports = {
145
- ScanOrderLoggerModule,
146
- ...require("./types")
147
- });
@@ -1,2 +0,0 @@
1
- import { ScanOrderLoggerProvider } from '../types';
2
- export declare const feishuLoggerProvider: ScanOrderLoggerProvider;