@pisell/pisellos 2.1.171 → 2.1.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 (230) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -3
  3. package/dist/model/strategy/adapter/index.d.ts +0 -4
  4. package/dist/model/strategy/adapter/index.js +1 -5
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  7. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  8. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  9. package/dist/model/strategy/engine.d.ts +18 -5
  10. package/dist/model/strategy/engine.js +145 -45
  11. package/dist/model/strategy/type.d.ts +17 -0
  12. package/dist/model/strategy/type.js +4 -0
  13. package/dist/modules/Cart/types.d.ts +2 -0
  14. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  15. package/dist/modules/Cart/utils/changePrice.js +9 -16
  16. package/dist/modules/Discount/index.d.ts +4 -13
  17. package/dist/modules/Discount/index.js +12 -124
  18. package/dist/modules/Discount/types.d.ts +18 -13
  19. package/dist/modules/Order/index.d.ts +1 -67
  20. package/dist/modules/Order/index.js +30 -918
  21. package/dist/modules/Order/types.d.ts +12 -176
  22. package/dist/modules/Order/types.js +0 -2
  23. package/dist/modules/Order/utils.d.ts +0 -118
  24. package/dist/modules/Order/utils.js +2 -586
  25. package/dist/modules/Payment/index.d.ts +2 -1
  26. package/dist/modules/Payment/index.js +10 -7
  27. package/dist/modules/Payment/utils.js +3 -0
  28. package/dist/modules/Payment/walletpass.d.ts +23 -0
  29. package/dist/modules/Payment/walletpass.js +191 -95
  30. package/dist/modules/Product/utils.js +2 -2
  31. package/dist/modules/ProductList/index.d.ts +2 -4
  32. package/dist/modules/ProductList/index.js +12 -24
  33. package/dist/modules/Rules/index.d.ts +9 -5
  34. package/dist/modules/Rules/index.js +669 -173
  35. package/dist/modules/Rules/types.d.ts +2 -0
  36. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -16
  37. package/dist/modules/Schedule/utils.d.ts +1 -1
  38. package/dist/modules/Summary/types.d.ts +2 -0
  39. package/dist/modules/Summary/utils.d.ts +9 -3
  40. package/dist/modules/Summary/utils.js +57 -67
  41. package/dist/modules/index.d.ts +0 -4
  42. package/dist/modules/index.js +1 -5
  43. package/dist/plugins/window.d.ts +2 -0
  44. package/dist/solution/BookingByStep/index.d.ts +3 -2
  45. package/dist/solution/BookingByStep/index.js +43 -46
  46. package/dist/solution/BookingByStep/types.d.ts +1 -3
  47. package/dist/solution/BookingByStep/types.js +1 -5
  48. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  49. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  50. package/dist/solution/Checkout/index.js +2 -0
  51. package/dist/solution/ShopDiscount/index.d.ts +2 -3
  52. package/dist/solution/ShopDiscount/index.js +60 -62
  53. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  54. package/dist/solution/ShopDiscount/types.js +2 -1
  55. package/dist/solution/ShopDiscount/utils.js +26 -12
  56. package/dist/solution/index.d.ts +0 -2
  57. package/dist/solution/index.js +1 -3
  58. package/lib/index.d.ts +1 -1
  59. package/lib/index.js +3 -4
  60. package/lib/model/strategy/adapter/index.d.ts +0 -4
  61. package/lib/model/strategy/adapter/index.js +2 -13
  62. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  63. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  64. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  65. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  66. package/lib/model/strategy/engine.d.ts +18 -5
  67. package/lib/model/strategy/engine.js +85 -21
  68. package/lib/model/strategy/type.d.ts +17 -0
  69. package/lib/modules/Cart/types.d.ts +2 -0
  70. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  71. package/lib/modules/Cart/utils/changePrice.js +9 -13
  72. package/lib/modules/Discount/index.d.ts +4 -13
  73. package/lib/modules/Discount/index.js +5 -76
  74. package/lib/modules/Discount/types.d.ts +18 -13
  75. package/lib/modules/Order/index.d.ts +1 -67
  76. package/lib/modules/Order/index.js +1 -525
  77. package/lib/modules/Order/types.d.ts +12 -176
  78. package/lib/modules/Order/utils.d.ts +0 -118
  79. package/lib/modules/Order/utils.js +2 -483
  80. package/lib/modules/Payment/index.d.ts +2 -1
  81. package/lib/modules/Payment/index.js +1 -0
  82. package/lib/modules/Payment/utils.js +3 -0
  83. package/lib/modules/Payment/walletpass.d.ts +23 -0
  84. package/lib/modules/Payment/walletpass.js +94 -17
  85. package/lib/modules/Product/utils.js +2 -2
  86. package/lib/modules/ProductList/index.d.ts +2 -4
  87. package/lib/modules/ProductList/index.js +39 -46
  88. package/lib/modules/Rules/index.d.ts +9 -5
  89. package/lib/modules/Rules/index.js +776 -292
  90. package/lib/modules/Rules/types.d.ts +2 -0
  91. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -13
  92. package/lib/modules/Schedule/utils.d.ts +1 -1
  93. package/lib/modules/Summary/types.d.ts +2 -0
  94. package/lib/modules/Summary/utils.d.ts +9 -3
  95. package/lib/modules/Summary/utils.js +34 -45
  96. package/lib/modules/index.d.ts +0 -4
  97. package/lib/modules/index.js +1 -9
  98. package/lib/plugins/window.d.ts +2 -0
  99. package/lib/solution/BookingByStep/index.d.ts +3 -2
  100. package/lib/solution/BookingByStep/index.js +4 -6
  101. package/lib/solution/BookingByStep/types.d.ts +1 -3
  102. package/lib/solution/BookingByStep/types.js +0 -10
  103. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  104. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  105. package/lib/solution/Checkout/index.js +2 -0
  106. package/lib/solution/ShopDiscount/index.d.ts +2 -3
  107. package/lib/solution/ShopDiscount/index.js +27 -22
  108. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  109. package/lib/solution/ShopDiscount/utils.js +10 -6
  110. package/lib/solution/index.d.ts +0 -2
  111. package/lib/solution/index.js +1 -5
  112. package/package.json +2 -2
  113. package/dist/apis/picoding.d.ts +0 -0
  114. package/dist/apis/picoding.js +0 -1
  115. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  116. package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -167
  117. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  118. package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -780
  119. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  120. package/dist/model/strategy/adapter/dataVariant/examples.js +0 -277
  121. package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  122. package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
  123. package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -148
  124. package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
  125. package/dist/modules/OpenData/index.d.ts +0 -24
  126. package/dist/modules/OpenData/index.js +0 -173
  127. package/dist/modules/OpenData/types.d.ts +0 -73
  128. package/dist/modules/OpenData/types.js +0 -1
  129. package/dist/modules/OpenData/utils.d.ts +0 -2
  130. package/dist/modules/OpenData/utils.js +0 -75
  131. package/dist/modules/Quotation/index.d.ts +0 -48
  132. package/dist/modules/Quotation/index.js +0 -248
  133. package/dist/modules/Quotation/types.d.ts +0 -42
  134. package/dist/modules/Quotation/types.js +0 -1
  135. package/dist/modules/SalesSummary/index.d.ts +0 -63
  136. package/dist/modules/SalesSummary/index.js +0 -174
  137. package/dist/modules/SalesSummary/types.d.ts +0 -60
  138. package/dist/modules/SalesSummary/types.js +0 -1
  139. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  140. package/dist/modules/SalesSummary/utils.js +0 -480
  141. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  142. package/dist/modules/ScanOrderLogger/index.js +0 -174
  143. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  144. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  145. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  146. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  147. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  148. package/dist/modules/ScanOrderLogger/types.js +0 -1
  149. package/dist/solution/ScanOrder/index.d.ts +0 -158
  150. package/dist/solution/ScanOrder/index.js +0 -3474
  151. package/dist/solution/ScanOrder/types.d.ts +0 -306
  152. package/dist/solution/ScanOrder/types.js +0 -35
  153. package/dist/solution/ScanOrder/utils.d.ts +0 -172
  154. package/dist/solution/ScanOrder/utils.js +0 -796
  155. package/dist/solution/VenueBooking/index.d.ts +0 -262
  156. package/dist/solution/VenueBooking/index.js +0 -3991
  157. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  158. package/dist/solution/VenueBooking/types.d.ts +0 -156
  159. package/dist/solution/VenueBooking/types.js +0 -22
  160. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  161. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -91
  162. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  163. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  164. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  165. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -233
  166. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  167. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  168. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  169. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -458
  170. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  171. package/dist/solution/VenueBooking/utils.js +0 -1
  172. package/lib/apis/picoding.d.ts +0 -0
  173. package/lib/apis/picoding.js +0 -0
  174. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
  175. package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -149
  176. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
  177. package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -583
  178. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  179. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -293
  180. package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  181. package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
  182. package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -148
  183. package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
  184. package/lib/modules/OpenData/index.d.ts +0 -24
  185. package/lib/modules/OpenData/index.js +0 -119
  186. package/lib/modules/OpenData/types.d.ts +0 -73
  187. package/lib/modules/OpenData/types.js +0 -17
  188. package/lib/modules/OpenData/utils.d.ts +0 -2
  189. package/lib/modules/OpenData/utils.js +0 -111
  190. package/lib/modules/Quotation/index.d.ts +0 -48
  191. package/lib/modules/Quotation/index.js +0 -152
  192. package/lib/modules/Quotation/types.d.ts +0 -42
  193. package/lib/modules/Quotation/types.js +0 -17
  194. package/lib/modules/SalesSummary/index.d.ts +0 -63
  195. package/lib/modules/SalesSummary/index.js +0 -105
  196. package/lib/modules/SalesSummary/types.d.ts +0 -60
  197. package/lib/modules/SalesSummary/types.js +0 -17
  198. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  199. package/lib/modules/SalesSummary/utils.js +0 -420
  200. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  201. package/lib/modules/ScanOrderLogger/index.js +0 -147
  202. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  203. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  204. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  205. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  206. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  207. package/lib/modules/ScanOrderLogger/types.js +0 -17
  208. package/lib/solution/ScanOrder/index.d.ts +0 -158
  209. package/lib/solution/ScanOrder/index.js +0 -2135
  210. package/lib/solution/ScanOrder/types.d.ts +0 -306
  211. package/lib/solution/ScanOrder/types.js +0 -36
  212. package/lib/solution/ScanOrder/utils.d.ts +0 -172
  213. package/lib/solution/ScanOrder/utils.js +0 -658
  214. package/lib/solution/VenueBooking/index.d.ts +0 -262
  215. package/lib/solution/VenueBooking/index.js +0 -2394
  216. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  217. package/lib/solution/VenueBooking/types.d.ts +0 -156
  218. package/lib/solution/VenueBooking/types.js +0 -45
  219. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  220. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -105
  221. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  222. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  223. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -32
  224. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -236
  225. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  226. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -180
  227. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -34
  228. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -343
  229. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  230. package/lib/solution/VenueBooking/utils.js +0 -69
@@ -1,60 +0,0 @@
1
- export interface SalesSummaryProduct {
2
- product_id: number | null;
3
- product_variant_id: number;
4
- num: number;
5
- /** 券后单品单价(订单域成交单价),由 OrderModule 维护。 */
6
- selling_price: string;
7
- /** 券前单品单价(店铺售价)。 */
8
- original_price: string;
9
- tax_fee: string;
10
- is_charge_tax?: number;
11
- product_option_item?: any[];
12
- discount_list?: any[];
13
- product_bundle?: any[];
14
- metadata?: Record<string, any>;
15
- _origin?: Record<string, any>;
16
- }
17
- export interface DepositPolicyData {
18
- id: number;
19
- title: string;
20
- }
21
- export interface DepositInfo {
22
- total: string;
23
- deposit_policy_ids: number[];
24
- deposit_policy_data: DepositPolicyData[];
25
- hasDeposit: boolean;
26
- }
27
- export interface SalesSummaryData {
28
- product_quantity: number;
29
- product_original_amount: string;
30
- product_amount: string;
31
- product_expect_amount: string;
32
- product_tax_fee: string;
33
- shipping_fee: string;
34
- shipping_tax_fee: string;
35
- tax_fee: string;
36
- surcharge_fee: string;
37
- surcharges: any[];
38
- discount_amount: string;
39
- deposit_amount: string;
40
- deposit?: DepositInfo;
41
- expect_amount: string;
42
- total_amount: string;
43
- amount_gap: string;
44
- rounding_amount: string;
45
- pay_service_charge_amount: string;
46
- is_price_include_tax?: number;
47
- tax_title?: string;
48
- tax_rate?: number;
49
- }
50
- export interface SalesSummaryState {
51
- surchargeList: any[];
52
- summary: SalesSummaryData;
53
- }
54
- export interface SalesSummaryModuleAPI {
55
- getSummary(params: {
56
- products: SalesSummaryProduct[];
57
- isPriceIncludeTax?: number;
58
- taxRate?: number;
59
- }): Promise<SalesSummaryData>;
60
- }
@@ -1,17 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
-
15
- // src/modules/SalesSummary/types.ts
16
- var types_exports = {};
17
- module.exports = __toCommonJS(types_exports);
@@ -1,30 +0,0 @@
1
- import type { DepositInfo, SalesSummaryData, SalesSummaryProduct } from './types';
2
- export declare function createEmptySalesSummary(): SalesSummaryData;
3
- export declare function calculateSalesSummary(params: {
4
- products: SalesSummaryProduct[];
5
- isPriceIncludeTax: number;
6
- taxRate?: number;
7
- surchargeList: any[];
8
- scheduleById?: Record<string, any>;
9
- isInScheduleByDate?: any;
10
- }): SalesSummaryData | {
11
- product_quantity: number;
12
- product_original_amount: string;
13
- product_amount: string;
14
- product_expect_amount: string;
15
- product_tax_fee: string;
16
- shipping_fee: string;
17
- shipping_tax_fee: string;
18
- tax_fee: string;
19
- surcharge_fee: string;
20
- surcharges: any;
21
- discount_amount: string;
22
- deposit_amount: string;
23
- deposit: DepositInfo | undefined;
24
- expect_amount: string;
25
- total_amount: string;
26
- amount_gap: string;
27
- rounding_amount: string;
28
- pay_service_charge_amount: string;
29
- is_price_include_tax: number;
30
- };
@@ -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';