@pisell/pisellos 0.0.569 → 0.10.2

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 (328) hide show
  1. package/dist/core/index.js +10 -6
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -3
  4. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
  6. package/dist/model/strategy/adapter/walletPass/example.js +26 -3
  7. package/dist/model/strategy/adapter/walletPass/index.js +5 -5
  8. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
  9. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  10. package/dist/model/strategy/adapter/walletPass/utils.js +17 -92
  11. package/dist/model/strategy/strategy-example.js +19 -5
  12. package/dist/modules/BaseModule.d.ts +1 -1
  13. package/dist/modules/BaseModule.js +8 -10
  14. package/dist/modules/Cart/index.js +3 -0
  15. package/dist/modules/Cart/utils/cartProduct.js +1 -0
  16. package/dist/modules/Cart/utils/cartResource.js +0 -2
  17. package/dist/modules/Cart/utils/changePrice.js +9 -16
  18. package/dist/modules/Date/index.js +5 -1
  19. package/dist/modules/Discount/index.d.ts +0 -1
  20. package/dist/modules/Discount/index.js +7 -22
  21. package/dist/modules/Discount/types.d.ts +0 -1
  22. package/dist/modules/OpenData/index.js +2 -0
  23. package/dist/modules/Order/index.js +70 -40
  24. package/dist/modules/Payment/index.js +162 -97
  25. package/dist/modules/Payment/types.d.ts +4 -8
  26. package/dist/modules/Payment/walletpass.d.ts +0 -2
  27. package/dist/modules/Payment/walletpass.js +5 -4
  28. package/dist/modules/ProductList/index.d.ts +1 -1
  29. package/dist/modules/ProductList/index.js +3 -12
  30. package/dist/modules/ProductList/types.d.ts +0 -1
  31. package/dist/modules/Rules/index.js +126 -427
  32. package/dist/modules/SalesSummary/utils.js +1 -2
  33. package/dist/modules/Schedule/getDateIsInSchedule.js +0 -5
  34. package/dist/modules/Schedule/index.js +1 -0
  35. package/dist/modules/Schedule/utils.js +1 -0
  36. package/dist/modules/Step/index.js +1 -0
  37. package/dist/modules/Summary/utils.js +22 -43
  38. package/dist/plugins/request.js +4 -1
  39. package/dist/plugins/window.js +6 -2
  40. package/dist/server/index.js +129 -97
  41. package/dist/server/modules/menu/index.js +41 -32
  42. package/dist/server/modules/order/index.js +4 -2
  43. package/dist/server/modules/products/index.js +42 -24
  44. package/dist/server/modules/quotation/index.js +38 -29
  45. package/dist/server/modules/resource/index.js +4 -3
  46. package/dist/server/modules/schedule/index.js +35 -27
  47. package/dist/server/utils/product.js +1 -0
  48. package/dist/solution/BaseSales/index.js +41 -38
  49. package/dist/solution/BookingByStep/index.d.ts +1 -1
  50. package/dist/solution/BookingByStep/index.js +60 -11
  51. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  52. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  53. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  54. package/dist/solution/BookingTicket/index.d.ts +1 -1
  55. package/dist/solution/BookingTicket/index.js +2 -0
  56. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +7 -6
  57. package/dist/solution/BookingTicket/utils/scan/handleScan.js +31 -25
  58. package/dist/solution/BookingTicket/utils/scan/index.js +10 -6
  59. package/dist/solution/BuyTickets/index.js +12 -9
  60. package/dist/solution/Checkout/index.js +252 -177
  61. package/dist/solution/Checkout/utils/index.js +16 -4
  62. package/dist/solution/RegisterAndLogin/index.js +76 -30
  63. package/dist/solution/ScanOrder/index.js +60 -50
  64. package/dist/solution/ShopDiscount/index.js +14 -15
  65. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  66. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  67. package/dist/solution/ShopDiscount/utils.js +0 -9
  68. package/dist/solution/VenueBooking/index.d.ts +3 -31
  69. package/dist/solution/VenueBooking/index.js +496 -651
  70. package/dist/solution/VenueBooking/types.d.ts +1 -3
  71. package/dist/solution/VenueBooking/types.js +0 -1
  72. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  73. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  74. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  75. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  76. package/dist/types/index.d.ts +1 -1
  77. package/dist/utils/task.js +18 -15
  78. package/dist/utils/watch.js +1 -0
  79. package/lib/apis/picoding.js +0 -2
  80. package/lib/core/index.js +132 -130
  81. package/lib/effects/index.js +57 -46
  82. package/lib/index.d.ts +0 -1
  83. package/lib/index.js +50 -92
  84. package/lib/model/index.js +21 -14
  85. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  86. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  87. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  88. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  89. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  90. package/lib/model/strategy/adapter/index.js +64 -100
  91. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  92. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  93. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  94. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  95. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  96. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  97. package/lib/model/strategy/adapter/promotion/evaluator.js +231 -381
  98. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  99. package/lib/model/strategy/adapter/promotion/index.js +49 -1
  100. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  101. package/lib/model/strategy/adapter/type.js +16 -4
  102. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  103. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  104. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  105. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  106. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  107. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  108. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  109. package/lib/model/strategy/adapter/walletPass/utils.js +383 -678
  110. package/lib/model/strategy/engine.js +168 -270
  111. package/lib/model/strategy/index.js +34 -49
  112. package/lib/model/strategy/strategy-example.js +239 -243
  113. package/lib/model/strategy/type.js +40 -100
  114. package/lib/modules/Account/index.js +53 -39
  115. package/lib/modules/Account/types.js +33 -20
  116. package/lib/modules/AccountList/index.js +154 -116
  117. package/lib/modules/AccountList/types.js +31 -30
  118. package/lib/modules/AccountList/utils.js +30 -18
  119. package/lib/modules/BaseModule.d.ts +1 -1
  120. package/lib/modules/BaseModule.js +46 -25
  121. package/lib/modules/BookingContext/index.js +136 -158
  122. package/lib/modules/BookingContext/types.js +32 -46
  123. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +143 -131
  124. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +82 -75
  125. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +150 -170
  126. package/lib/modules/BookingContext/utils/flexible.js +55 -38
  127. package/lib/modules/BookingContext/utils/formatResourceList.js +34 -19
  128. package/lib/modules/BookingContext/utils/index.js +41 -124
  129. package/lib/modules/BookingContext/utils/noResource.js +70 -58
  130. package/lib/modules/BookingContext/utils/orderLineDisplay.js +41 -14
  131. package/lib/modules/BookingContext/utils/productExtend.js +155 -202
  132. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  133. package/lib/modules/BookingContext/utils/resourceSelection.js +41 -19
  134. package/lib/modules/BookingContext/utils/resources.js +167 -209
  135. package/lib/modules/BookingContext/utils/serviceTimes.js +116 -115
  136. package/lib/modules/BookingContext/utils/timeSlices.js +80 -70
  137. package/lib/modules/Cart/index.js +124 -170
  138. package/lib/modules/Cart/types.js +51 -46
  139. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  140. package/lib/modules/Cart/utils/cartDate.js +61 -56
  141. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  142. package/lib/modules/Cart/utils/cartNote.js +32 -27
  143. package/lib/modules/Cart/utils/cartProduct.js +251 -321
  144. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  145. package/lib/modules/Cart/utils/cartResource.js +78 -72
  146. package/lib/modules/Cart/utils/changePrice.js +50 -28
  147. package/lib/modules/Cart/utils/index.js +48 -106
  148. package/lib/modules/Customer/constants.js +34 -13
  149. package/lib/modules/Customer/index.js +169 -232
  150. package/lib/modules/Customer/types.js +35 -38
  151. package/lib/modules/Date/index.js +115 -116
  152. package/lib/modules/Date/types.js +28 -16
  153. package/lib/modules/Date/utils.js +123 -174
  154. package/lib/modules/Discount/index.d.ts +0 -1
  155. package/lib/modules/Discount/index.js +128 -130
  156. package/lib/modules/Discount/types.d.ts +0 -1
  157. package/lib/modules/Discount/types.js +31 -9
  158. package/lib/modules/Guests/index.js +56 -30
  159. package/lib/modules/Guests/types.js +33 -23
  160. package/lib/modules/Holder/index.js +189 -209
  161. package/lib/modules/Holder/types.js +16 -4
  162. package/lib/modules/Holder/utils.js +49 -20
  163. package/lib/modules/OpenData/index.js +76 -69
  164. package/lib/modules/OpenData/types.js +16 -4
  165. package/lib/modules/OpenData/utils.js +78 -44
  166. package/lib/modules/Order/index.js +1909 -1572
  167. package/lib/modules/Order/types.js +35 -78
  168. package/lib/modules/Order/utils/bundleDiscountHydration.js +74 -41
  169. package/lib/modules/Order/utils/manualProductDiscount.js +123 -124
  170. package/lib/modules/Order/utils/orderCollectionIdentity.js +210 -148
  171. package/lib/modules/Order/utils.js +634 -799
  172. package/lib/modules/Payment/cash.js +33 -20
  173. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  174. package/lib/modules/Payment/eftpos.js +30 -16
  175. package/lib/modules/Payment/index.js +378 -518
  176. package/lib/modules/Payment/mx51.js +0 -1
  177. package/lib/modules/Payment/types.d.ts +4 -8
  178. package/lib/modules/Payment/types.js +107 -216
  179. package/lib/modules/Payment/utils.js +48 -51
  180. package/lib/modules/Payment/walletpass.d.ts +0 -2
  181. package/lib/modules/Payment/walletpass.js +211 -226
  182. package/lib/modules/Product/index.js +46 -51
  183. package/lib/modules/Product/types.js +16 -4
  184. package/lib/modules/Product/utils.js +33 -32
  185. package/lib/modules/ProductList/index.d.ts +1 -1
  186. package/lib/modules/ProductList/index.js +117 -117
  187. package/lib/modules/ProductList/types.d.ts +0 -1
  188. package/lib/modules/ProductList/types.js +31 -9
  189. package/lib/modules/Quotation/index.js +100 -66
  190. package/lib/modules/Quotation/types.js +16 -4
  191. package/lib/modules/Resource/index.js +59 -27
  192. package/lib/modules/Resource/types.js +32 -22
  193. package/lib/modules/Resource/utils.js +38 -30
  194. package/lib/modules/ResourcePlanner/index.js +61 -60
  195. package/lib/modules/ResourcePlanner/planner.js +384 -346
  196. package/lib/modules/ResourcePlanner/types.js +16 -4
  197. package/lib/modules/Rules/index.js +903 -1475
  198. package/lib/modules/Rules/types.js +40 -17
  199. package/lib/modules/SalesSummary/index.js +90 -85
  200. package/lib/modules/SalesSummary/types.js +16 -4
  201. package/lib/modules/SalesSummary/utils.js +427 -351
  202. package/lib/modules/ScanOrderLogger/index.js +79 -59
  203. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  204. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  205. package/lib/modules/ScanOrderLogger/types.js +16 -4
  206. package/lib/modules/Schedule/getDateIsInSchedule.js +163 -339
  207. package/lib/modules/Schedule/index.js +114 -100
  208. package/lib/modules/Schedule/type.js +16 -4
  209. package/lib/modules/Schedule/types.js +16 -4
  210. package/lib/modules/Schedule/utils.js +291 -433
  211. package/lib/modules/Step/index.js +52 -40
  212. package/lib/modules/Step/tyeps.js +16 -4
  213. package/lib/modules/Summary/index.js +71 -66
  214. package/lib/modules/Summary/types.js +16 -4
  215. package/lib/modules/Summary/utils.js +418 -791
  216. package/lib/modules/SurchargeList/index.js +60 -46
  217. package/lib/modules/SurchargeList/types.js +16 -4
  218. package/lib/modules/index.js +63 -245
  219. package/lib/plugins/app.js +16 -4
  220. package/lib/plugins/index.js +25 -36
  221. package/lib/plugins/request.js +126 -137
  222. package/lib/plugins/shopStore.js +16 -4
  223. package/lib/plugins/user.js +16 -4
  224. package/lib/plugins/window.js +179 -171
  225. package/lib/server/index.js +2337 -2675
  226. package/lib/server/modules/floor-plan/index.js +123 -102
  227. package/lib/server/modules/floor-plan/types.js +30 -15
  228. package/lib/server/modules/index.js +68 -106
  229. package/lib/server/modules/menu/index.js +122 -146
  230. package/lib/server/modules/menu/types.js +31 -18
  231. package/lib/server/modules/order/index.js +642 -567
  232. package/lib/server/modules/order/types.js +32 -117
  233. package/lib/server/modules/order/utils/filterBookings.js +194 -219
  234. package/lib/server/modules/order/utils/filterOrders.js +92 -118
  235. package/lib/server/modules/payment/index.js +83 -59
  236. package/lib/server/modules/payment/types.js +16 -4
  237. package/lib/server/modules/products/index.js +459 -575
  238. package/lib/server/modules/products/types.js +34 -44
  239. package/lib/server/modules/quotation/index.js +172 -137
  240. package/lib/server/modules/quotation/types.js +31 -21
  241. package/lib/server/modules/resource/index.js +184 -213
  242. package/lib/server/modules/resource/types.js +33 -42
  243. package/lib/server/modules/schedule/index.js +123 -135
  244. package/lib/server/modules/schedule/types.js +21 -14
  245. package/lib/server/modules/schedule/utils.js +163 -334
  246. package/lib/server/types.js +16 -4
  247. package/lib/server/utils/index.js +23 -25
  248. package/lib/server/utils/product.js +139 -196
  249. package/lib/server/utils/schedule.js +41 -34
  250. package/lib/server/utils/small-ticket.js +456 -478
  251. package/lib/server/utils/time.js +49 -40
  252. package/lib/solution/BaseSales/index.js +1016 -850
  253. package/lib/solution/BaseSales/types.js +37 -41
  254. package/lib/solution/BaseSales/utils/cartPromotion.js +460 -611
  255. package/lib/solution/BaseSales/utils/parseSalesResponse.js +105 -85
  256. package/lib/solution/BaseSales/utils/quotationPrice.js +114 -56
  257. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +143 -102
  258. package/lib/solution/BaseSales/utils.js +140 -155
  259. package/lib/solution/BookingByStep/index.d.ts +1 -1
  260. package/lib/solution/BookingByStep/index.js +1340 -1530
  261. package/lib/solution/BookingByStep/types.js +99 -40
  262. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  263. package/lib/solution/BookingByStep/utils/products.js +52 -42
  264. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  265. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  266. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  267. package/lib/solution/BookingTicket/index.d.ts +1 -1
  268. package/lib/solution/BookingTicket/index.js +459 -543
  269. package/lib/solution/BookingTicket/types.js +77 -99
  270. package/lib/solution/BookingTicket/utils/addProductDecision.js +184 -219
  271. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +89 -58
  272. package/lib/solution/BookingTicket/utils/bookingStatus.js +78 -107
  273. package/lib/solution/BookingTicket/utils/cartView.js +94 -110
  274. package/lib/solution/BookingTicket/utils/exampleData.js +0 -185
  275. package/lib/solution/BookingTicket/utils/orderCustomer.js +41 -18
  276. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +86 -219
  277. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +93 -144
  278. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +91 -79
  279. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +41 -54
  280. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -84
  281. package/lib/solution/BookingTicket/utils/scan/index.js +104 -98
  282. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  283. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +64 -52
  284. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +58 -56
  285. package/lib/solution/BuyTickets/index.js +70 -67
  286. package/lib/solution/BuyTickets/types.js +38 -22
  287. package/lib/solution/Checkout/index.js +1158 -1451
  288. package/lib/solution/Checkout/types.js +61 -91
  289. package/lib/solution/Checkout/utils/index.js +156 -228
  290. package/lib/solution/PlaceOrder/index.js +0 -55
  291. package/lib/solution/RegisterAndLogin/config.js +460 -493
  292. package/lib/solution/RegisterAndLogin/index.js +630 -633
  293. package/lib/solution/RegisterAndLogin/types.js +76 -189
  294. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  295. package/lib/solution/Sales/index.js +320 -317
  296. package/lib/solution/Sales/types.js +33 -27
  297. package/lib/solution/ScanOrder/index.js +862 -831
  298. package/lib/solution/ScanOrder/types.js +34 -33
  299. package/lib/solution/ScanOrder/utils.js +371 -406
  300. package/lib/solution/ShopDiscount/index.js +233 -235
  301. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  302. package/lib/solution/ShopDiscount/types.js +37 -15
  303. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  304. package/lib/solution/ShopDiscount/utils.js +172 -309
  305. package/lib/solution/UnifiedBookingSales/index.js +405 -379
  306. package/lib/solution/UnifiedBookingSales/types.js +31 -12
  307. package/lib/solution/VenueBooking/index.d.ts +3 -31
  308. package/lib/solution/VenueBooking/index.js +916 -967
  309. package/lib/solution/VenueBooking/types.d.ts +1 -3
  310. package/lib/solution/VenueBooking/types.js +39 -20
  311. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  312. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  313. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  314. package/lib/solution/VenueBooking/utils/slotMerge.js +107 -94
  315. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  316. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  317. package/lib/solution/VenueBooking/utils.js +67 -130
  318. package/lib/solution/index.js +41 -124
  319. package/lib/store/createStore.js +29 -32
  320. package/lib/types/index.d.ts +1 -1
  321. package/lib/types/index.js +16 -4
  322. package/lib/utils/task.js +36 -36
  323. package/lib/utils/watch.js +47 -81
  324. package/package.json +2 -4
  325. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  326. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  327. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  328. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -1,87 +1,112 @@
1
- "use strict";
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);
2
28
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
29
+ // src/modules/SalesSummary/utils.ts
30
+ var utils_exports = {};
31
+ __export(utils_exports, {
32
+ calculateSalesSummary: () => calculateSalesSummary,
33
+ createEmptySalesSummary: () => createEmptySalesSummary
5
34
  });
6
- exports.calculateSalesSummary = calculateSalesSummary;
7
- exports.createEmptySalesSummary = createEmptySalesSummary;
8
- var _decimal = _interopRequireDefault(require("decimal.js"));
9
- var _utils = require("../Summary/utils");
10
- var _utils2 = require("../Order/utils");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ module.exports = __toCommonJS(utils_exports);
36
+ var import_decimal = __toESM(require("decimal.js"));
37
+ var import_utils = require("../Summary/utils");
38
+ var import_utils2 = require("../Order/utils");
12
39
  function toDecimal(value) {
13
- return new _decimal.default(value || 0);
40
+ return new import_decimal.default(value || 0);
14
41
  }
15
42
  function toFixed2(value) {
16
- return new _decimal.default(value || 0).toFixed(2);
43
+ return new import_decimal.default(value || 0).toFixed(2);
17
44
  }
18
45
  function toAmountFormat(value) {
19
- return new _decimal.default(value || 0).toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
46
+ return new import_decimal.default(value || 0).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
20
47
  }
21
48
  function toBackendTaxFee(value) {
22
49
  return toBcScale(value, 2);
23
50
  }
24
51
  function toBcScale(value, scale) {
25
- const factor = new _decimal.default(10).pow(scale);
26
- return new _decimal.default(value || 0).times(factor).toDecimalPlaces(0, _decimal.default.ROUND_DOWN).div(factor);
52
+ const factor = new import_decimal.default(10).pow(scale);
53
+ return new import_decimal.default(value || 0).times(factor).toDecimalPlaces(0, import_decimal.default.ROUND_DOWN).div(factor);
27
54
  }
28
55
  function bcAdd(left, right, scale) {
29
- return toBcScale(new _decimal.default(left || 0).plus(right || 0), scale);
56
+ return toBcScale(new import_decimal.default(left || 0).plus(right || 0), scale);
30
57
  }
31
58
  function bcSub(left, right, scale) {
32
- return toBcScale(new _decimal.default(left || 0).minus(right || 0), scale);
59
+ return toBcScale(new import_decimal.default(left || 0).minus(right || 0), scale);
33
60
  }
34
61
  function bcMul(left, right, scale) {
35
- return toBcScale(new _decimal.default(left || 0).times(right || 0), scale);
62
+ return toBcScale(new import_decimal.default(left || 0).times(right || 0), scale);
36
63
  }
37
64
  function bcDiv(left, right, scale) {
38
- const divisor = new _decimal.default(right || 0);
39
- if (divisor.eq(0)) return new _decimal.default(0);
40
- return toBcScale(new _decimal.default(left || 0).div(divisor), scale);
65
+ const divisor = new import_decimal.default(right || 0);
66
+ if (divisor.eq(0))
67
+ return new import_decimal.default(0);
68
+ return toBcScale(new import_decimal.default(left || 0).div(divisor), scale);
41
69
  }
42
70
  function getSafeNum(num) {
43
- if (!num || Number.isNaN(num)) return 1;
44
- if (num < 1) return 1;
71
+ if (!num || Number.isNaN(num))
72
+ return 1;
73
+ if (num < 1)
74
+ return 1;
45
75
  return Math.floor(num);
46
76
  }
47
77
  function getBundleUnitPrice(product, useOriginal = false) {
48
78
  const bundleItems = product.product_bundle || [];
49
79
  return bundleItems.reduce((sum, item) => {
50
- const quantity = getSafeNum(item?.num);
51
- // markdown(减价)按带符号净额取减;markup/原价维持相加。
52
- const signedUnit = (0, _utils2.getBundleSignedUnit)(item, {
53
- useOriginal
54
- });
80
+ const quantity = getSafeNum(item == null ? void 0 : item.num);
81
+ const signedUnit = (0, import_utils2.getBundleSignedUnit)(item, { useOriginal });
55
82
  return sum.plus(signedUnit.times(quantity));
56
- }, new _decimal.default(0));
83
+ }, new import_decimal.default(0));
57
84
  }
58
-
59
- // 单商品 composite 单价(随后再乘商品数量):
60
- // 新语义 v2 下 `metadata.main_product_selling_price` 已经是"含 option、含主商品折扣"的主价,
61
- // composite 单价 = main_product_selling_price + Σ(bundle_selling_price × num)。
62
- // 不再叠加 options(会重复计算),也不再用 variant/selling_price 兜底(选项已固化进 metadata)。
63
85
  function getUnitPaymentTotal(product) {
64
- const mainSelling = product.metadata?.main_product_selling_price;
65
- const mainOriginal = product.metadata?.main_product_original_price;
66
- const basePrice = mainSelling !== undefined ? toDecimal(mainSelling) : mainOriginal !== undefined ? toDecimal(mainOriginal) : toDecimal(product.selling_price);
86
+ var _a, _b;
87
+ const mainSelling = (_a = product.metadata) == null ? void 0 : _a.main_product_selling_price;
88
+ const mainOriginal = (_b = product.metadata) == null ? void 0 : _b.main_product_original_price;
89
+ const basePrice = mainSelling !== void 0 ? toDecimal(mainSelling) : mainOriginal !== void 0 ? toDecimal(mainOriginal) : toDecimal(product.selling_price);
67
90
  return basePrice.plus(getBundleUnitPrice(product));
68
91
  }
69
92
  function getUnitOriginalTotal(product) {
70
- const mainOriginal = product.metadata?.main_product_original_price;
71
- const mainSelling = product.metadata?.main_product_selling_price;
72
- const basePrice = mainOriginal !== undefined ? toDecimal(mainOriginal) : mainSelling !== undefined ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
93
+ var _a, _b;
94
+ const mainOriginal = (_a = product.metadata) == null ? void 0 : _a.main_product_original_price;
95
+ const mainSelling = (_b = product.metadata) == null ? void 0 : _b.main_product_selling_price;
96
+ const basePrice = mainOriginal !== void 0 ? toDecimal(mainOriginal) : mainSelling !== void 0 ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
73
97
  return basePrice.plus(getBundleUnitPrice(product, true));
74
98
  }
75
99
  function isGeneratedVoucherProduct(product) {
76
100
  const record = product;
77
- const metadata = record?.metadata || {};
78
- return record?.extension_type === 'product_voucher' || metadata.parent_order_detail_id !== undefined || metadata.gift_card_type !== undefined;
101
+ const metadata = (record == null ? void 0 : record.metadata) || {};
102
+ return (record == null ? void 0 : record.extension_type) === "product_voucher" || metadata.parent_order_detail_id !== void 0 || metadata.gift_card_type !== void 0;
79
103
  }
80
104
  function buildSurchargeServiceItems(products) {
81
- return products.map(product => {
105
+ return products.map((product) => {
106
+ var _a, _b;
82
107
  const quantity = getSafeNum(product.num);
83
108
  const unitTotal = getUnitPaymentTotal(product);
84
- const options = (0, _utils2.getProductSkuOptions)(product);
109
+ const options = (0, import_utils2.getProductSkuOptions)(product);
85
110
  const persistedSurchargeFee = getPersistedMainSurchargeFee(product);
86
111
  return {
87
112
  id: product.product_id,
@@ -94,9 +119,7 @@ function buildSurchargeServiceItems(products) {
94
119
  product: {
95
120
  discount_list: product.discount_list || [],
96
121
  product_bundle: product.product_bundle || [],
97
- product_sku: product.product_sku || {
98
- option: options
99
- }
122
+ product_sku: product.product_sku || { option: options }
100
123
  }
101
124
  },
102
125
  bundle: product.product_bundle || [],
@@ -104,99 +127,124 @@ function buildSurchargeServiceItems(products) {
104
127
  options,
105
128
  relation_details: [],
106
129
  metadata: {
107
- ...(product.metadata || {}),
108
- __persisted_surcharge_fee: persistedSurchargeFee?.toFixed(2)
130
+ ...product.metadata || {},
131
+ __persisted_surcharge_fee: persistedSurchargeFee == null ? void 0 : persistedSurchargeFee.toFixed(2)
109
132
  },
110
- start_date: product.metadata?.start_date || '',
111
- start_time: product.metadata?.start_time || ''
133
+ start_date: ((_a = product.metadata) == null ? void 0 : _a.start_date) || "",
134
+ start_time: ((_b = product.metadata) == null ? void 0 : _b.start_time) || ""
112
135
  };
113
136
  });
114
137
  }
115
138
  function getRelationSurchargeIds(item) {
116
- const ids = [...(Array.isArray(item?.relation_surcharge_ids) ? item.relation_surcharge_ids : []), ...(Array.isArray(item?.metadata?.relation_surcharge_ids) ? item.metadata.relation_surcharge_ids : [])];
117
- return [...new Set(ids.filter(id => id !== undefined && id !== null && id !== ''))];
139
+ var _a;
140
+ const ids = [
141
+ ...Array.isArray(item == null ? void 0 : item.relation_surcharge_ids) ? item.relation_surcharge_ids : [],
142
+ ...Array.isArray((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.relation_surcharge_ids) ? item.metadata.relation_surcharge_ids : []
143
+ ];
144
+ return [...new Set(ids.filter((id) => id !== void 0 && id !== null && id !== ""))];
118
145
  }
119
146
  function getSurchargeConfigId(config) {
120
- return config?.id ?? config?.surcharge_id;
147
+ return (config == null ? void 0 : config.id) ?? (config == null ? void 0 : config.surcharge_id);
121
148
  }
122
149
  function getSurchargeConfigById(surchargeList) {
123
- const map = new Map();
150
+ const map = /* @__PURE__ */ new Map();
124
151
  for (const config of surchargeList || []) {
125
152
  const id = getSurchargeConfigId(config);
126
- if (id !== undefined) map.set(id, config);
153
+ if (id !== void 0)
154
+ map.set(id, config);
127
155
  }
128
156
  return map;
129
157
  }
130
158
  function getMainSurchargeUnitAmount(product) {
159
+ var _a, _b;
131
160
  const record = product;
132
- return toDecimal(record.metadata?.main_product_attached_bundle_selling_price ?? record.metadata?.main_product_selling_price ?? record.selling_price ?? 0);
161
+ return toDecimal(
162
+ ((_a = record.metadata) == null ? void 0 : _a.main_product_attached_bundle_selling_price) ?? ((_b = record.metadata) == null ? void 0 : _b.main_product_selling_price) ?? record.selling_price ?? 0
163
+ );
133
164
  }
134
165
  function getBundleSurchargeUnitAmount(bundle) {
135
- return toDecimal(bundle?.bundle_selling_price ?? bundle?.bundle_sum_price ?? bundle?.price ?? 0);
166
+ return toDecimal((bundle == null ? void 0 : bundle.bundle_selling_price) ?? (bundle == null ? void 0 : bundle.bundle_sum_price) ?? (bundle == null ? void 0 : bundle.price) ?? 0);
136
167
  }
137
168
  function getBundleProductId(bundle) {
138
- const id = bundle?.bundle_product_id ?? bundle?._bundle_product_id ?? bundle?.product_id;
139
- if (id === undefined || id === null || id === '') return null;
169
+ const id = (bundle == null ? void 0 : bundle.bundle_product_id) ?? (bundle == null ? void 0 : bundle._bundle_product_id) ?? (bundle == null ? void 0 : bundle.product_id);
170
+ if (id === void 0 || id === null || id === "")
171
+ return null;
140
172
  const parsed = Number(id);
141
- if (!Number.isFinite(parsed)) return null;
173
+ if (!Number.isFinite(parsed))
174
+ return null;
142
175
  return parsed;
143
176
  }
144
177
  function getPersistedMainSurchargeFee(product) {
145
- if (product?.order_detail_id === undefined || product?.order_detail_id === null) return null;
146
- const value = product?.surcharge_fee ?? product?.main_product_attached_bundle_surcharge_fee ?? product?.metadata?.main_product_attached_bundle_surcharge_fee;
147
- if (value === undefined || value === null || value === '') return null;
178
+ var _a;
179
+ if ((product == null ? void 0 : product.order_detail_id) === void 0 || (product == null ? void 0 : product.order_detail_id) === null)
180
+ return null;
181
+ const value = (product == null ? void 0 : product.surcharge_fee) ?? (product == null ? void 0 : product.main_product_attached_bundle_surcharge_fee) ?? ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.main_product_attached_bundle_surcharge_fee);
182
+ if (value === void 0 || value === null || value === "")
183
+ return null;
148
184
  return toDecimal(value);
149
185
  }
150
186
  function getPersistedSourceSurchargeFee(sourceItem) {
151
- const value = sourceItem?.metadata?.__persisted_surcharge_fee;
152
- if (value === undefined || value === null || value === '') return null;
187
+ var _a;
188
+ const value = (_a = sourceItem == null ? void 0 : sourceItem.metadata) == null ? void 0 : _a.__persisted_surcharge_fee;
189
+ if (value === void 0 || value === null || value === "")
190
+ return null;
153
191
  return toDecimal(value);
154
192
  }
155
193
  function getPersistedSurchargeRemainder(item, sourceItem) {
156
- const value = sourceItem?.metadata?.surcharge_rounding_remainder ?? item?.surcharge_rounding_remainder ?? item?.metadata?.surcharge_rounding_remainder;
157
- if (value === undefined || value === null || value === '') return null;
194
+ var _a, _b;
195
+ const value = ((_a = sourceItem == null ? void 0 : sourceItem.metadata) == null ? void 0 : _a.surcharge_rounding_remainder) ?? (item == null ? void 0 : item.surcharge_rounding_remainder) ?? ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.surcharge_rounding_remainder);
196
+ if (value === void 0 || value === null || value === "")
197
+ return null;
158
198
  return toDecimal(value);
159
199
  }
160
200
  function getPersistedQuantity(item, fallbackQuantity) {
161
- const isPersistedLine = item?.order_detail_id !== undefined && item?.order_detail_id !== null;
162
- if (!isPersistedLine) return new _decimal.default(0);
163
- const value = item?.product_quantity ?? item?.quantity;
164
- const parsed = new _decimal.default(value || 0);
165
- if (parsed.lte(0)) return _decimal.default.min(fallbackQuantity, 1);
166
- return _decimal.default.min(fallbackQuantity, parsed);
201
+ const isPersistedLine = (item == null ? void 0 : item.order_detail_id) !== void 0 && (item == null ? void 0 : item.order_detail_id) !== null;
202
+ if (!isPersistedLine)
203
+ return new import_decimal.default(0);
204
+ const value = (item == null ? void 0 : item.product_quantity) ?? (item == null ? void 0 : item.quantity);
205
+ const parsed = new import_decimal.default(value || 0);
206
+ if (parsed.lte(0))
207
+ return import_decimal.default.min(fallbackQuantity, 1);
208
+ return import_decimal.default.min(fallbackQuantity, parsed);
167
209
  }
168
210
  function getPersistedBundleSurchargeFee(bundle, product) {
169
- if (bundle?.order_detail_id === undefined && product?.order_detail_id === undefined) return null;
170
- if (bundle?.order_detail_id === null && product?.order_detail_id === null) return null;
171
- const value = bundle?.surcharge_fee ?? bundle?.metadata?.surcharge_fee;
172
- if (value === undefined || value === null || value === '') return null;
211
+ var _a;
212
+ if ((bundle == null ? void 0 : bundle.order_detail_id) === void 0 && (product == null ? void 0 : product.order_detail_id) === void 0)
213
+ return null;
214
+ if ((bundle == null ? void 0 : bundle.order_detail_id) === null && (product == null ? void 0 : product.order_detail_id) === null)
215
+ return null;
216
+ const value = (bundle == null ? void 0 : bundle.surcharge_fee) ?? ((_a = bundle == null ? void 0 : bundle.metadata) == null ? void 0 : _a.surcharge_fee);
217
+ if (value === void 0 || value === null || value === "")
218
+ return null;
173
219
  return toDecimal(value);
174
220
  }
175
221
  function createSurchargeAllocationNodes(products, sourceItems) {
222
+ var _a;
176
223
  const nodes = [];
177
224
  for (let productIndex = 0; productIndex < products.length; productIndex++) {
178
225
  const product = products[productIndex];
179
226
  const sourceItem = sourceItems[productIndex] || {};
180
- const productQuantity = new _decimal.default(getSafeNum(product.num));
227
+ const productQuantity = new import_decimal.default(getSafeNum(product.num));
181
228
  for (let bundleIndex = 0; bundleIndex < (product.product_bundle || []).length; bundleIndex++) {
182
229
  const bundle = product.product_bundle[bundleIndex];
183
- if (!isBundleOriginalPrice(bundle)) continue;
184
- const sourceBundle = sourceItem?.bundle?.[bundleIndex] || {};
230
+ if (!isBundleOriginalPrice(bundle))
231
+ continue;
232
+ const sourceBundle = ((_a = sourceItem == null ? void 0 : sourceItem.bundle) == null ? void 0 : _a[bundleIndex]) || {};
185
233
  nodes.push({
186
- kind: 'bundle',
234
+ kind: "bundle",
187
235
  target: bundle,
188
236
  source: sourceBundle,
189
237
  productId: getBundleProductId(bundle),
190
238
  unitAmount: getBundleSurchargeUnitAmount(bundle),
191
- quantity: new _decimal.default(getSafeNum(bundle?.num ?? bundle?.quantity)).times(productQuantity),
192
- persistedQuantity: getPersistedQuantity(bundle, new _decimal.default(getSafeNum(bundle?.num ?? bundle?.quantity)).times(productQuantity)),
239
+ quantity: new import_decimal.default(getSafeNum((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity))).times(productQuantity),
240
+ persistedQuantity: getPersistedQuantity(bundle, new import_decimal.default(getSafeNum((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity))).times(productQuantity)),
193
241
  relationSurchargeIds: getRelationSurchargeIds(sourceBundle).length ? getRelationSurchargeIds(sourceBundle) : getRelationSurchargeIds(bundle),
194
242
  persistedUnitSurchargeFee: getPersistedBundleSurchargeFee(bundle, product),
195
243
  persistedSurchargeRemainder: getPersistedSurchargeRemainder(bundle, sourceBundle)
196
244
  });
197
245
  }
198
246
  nodes.push({
199
- kind: 'main',
247
+ kind: "main",
200
248
  target: product,
201
249
  source: sourceItem,
202
250
  productId: product.product_id ?? null,
@@ -213,25 +261,26 @@ function createSurchargeAllocationNodes(products, sourceItems) {
213
261
  function resetProductSurchargeFields(products) {
214
262
  for (const product of products) {
215
263
  product.surcharge_fee = 0;
216
- product.main_product_attached_bundle_surcharge_fee = '0.00';
264
+ product.main_product_attached_bundle_surcharge_fee = "0.00";
217
265
  product.surcharge_rounding_remainder = 0;
218
266
  product.relation_surcharge_ids = [];
219
267
  for (const bundle of product.product_bundle || []) {
220
268
  bundle.surcharge_fee = 0;
221
269
  bundle.relation_surcharge_ids = [];
222
270
  bundle.metadata = {
223
- ...(bundle.metadata || {}),
224
- surcharge_fee: '0.00',
225
- surcharge_rounding_remainder: '0.00',
271
+ ...bundle.metadata || {},
272
+ surcharge_fee: "0.00",
273
+ surcharge_rounding_remainder: "0.00",
226
274
  relation_surcharge_ids: []
227
275
  };
228
276
  }
229
277
  }
230
278
  }
231
279
  function getPersistedSurchargeIds(nodes) {
232
- const ids = new Set();
280
+ const ids = /* @__PURE__ */ new Set();
233
281
  for (const node of nodes) {
234
- if (!node.persistedUnitSurchargeFee || node.persistedUnitSurchargeFee.lte(0)) continue;
282
+ if (!node.persistedUnitSurchargeFee || node.persistedUnitSurchargeFee.lte(0))
283
+ continue;
235
284
  for (const surchargeId of node.relationSurchargeIds) {
236
285
  ids.add(surchargeId);
237
286
  }
@@ -239,10 +288,13 @@ function getPersistedSurchargeIds(nodes) {
239
288
  return ids;
240
289
  }
241
290
  function buildSurchargeQuantityTotals(nodes) {
242
- const totals = new Map();
291
+ const totals = /* @__PURE__ */ new Map();
243
292
  for (const node of nodes) {
244
293
  for (const surchargeId of node.relationSurchargeIds) {
245
- totals.set(surchargeId, (totals.get(surchargeId) || new _decimal.default(0)).plus(node.quantity));
294
+ totals.set(
295
+ surchargeId,
296
+ (totals.get(surchargeId) || new import_decimal.default(0)).plus(node.quantity)
297
+ );
246
298
  }
247
299
  }
248
300
  return totals;
@@ -250,10 +302,14 @@ function buildSurchargeQuantityTotals(nodes) {
250
302
  function getFallbackAllProductSurchargeIds(surchargeList) {
251
303
  return (surchargeList || []).reduce((ids, config) => {
252
304
  const id = getSurchargeConfigId(config);
253
- if (id === undefined) return ids;
254
- if (Number(config.open_product ?? 0) === 0) return ids;
255
- if (Number(config.is_all ?? 0) !== 1) return ids;
256
- if (Number(config.open_schedule ?? 0) === 1 && config.schedule_type !== 'all') return ids;
305
+ if (id === void 0)
306
+ return ids;
307
+ if (Number(config.open_product ?? 0) === 0)
308
+ return ids;
309
+ if (Number(config.is_all ?? 0) !== 1)
310
+ return ids;
311
+ if (Number(config.open_schedule ?? 0) === 1 && config.schedule_type !== "all")
312
+ return ids;
257
313
  ids.push(id);
258
314
  return ids;
259
315
  }, []);
@@ -263,9 +319,9 @@ function getBackendSurchargeState(stateMap, surchargeId, config) {
263
319
  if (!state) {
264
320
  state = {
265
321
  config,
266
- amount: new _decimal.default(0),
267
- totalOffsetFee: new _decimal.default(0),
268
- calculatedQuantity: new _decimal.default(0),
322
+ amount: new import_decimal.default(0),
323
+ totalOffsetFee: new import_decimal.default(0),
324
+ calculatedQuantity: new import_decimal.default(0),
269
325
  fixedIncluded: false,
270
326
  fixedRemainderAssigned: false
271
327
  };
@@ -274,30 +330,26 @@ function getBackendSurchargeState(stateMap, surchargeId, config) {
274
330
  return state;
275
331
  }
276
332
  function buildSurchargeResultItem(config, surchargeId, amount, index) {
277
- const name = config?.name || config?.label || {};
333
+ const name = (config == null ? void 0 : config.name) || (config == null ? void 0 : config.label) || {};
278
334
  return {
279
335
  key: `custom_surcharge_${index}`,
280
336
  label: name,
281
337
  name,
282
338
  value: amount.toNumber(),
283
339
  surcharge_id: surchargeId,
284
- description: config?.description,
285
- type: 'default',
286
- fixed: config?.fixed,
340
+ description: config == null ? void 0 : config.description,
341
+ type: "default",
342
+ fixed: config == null ? void 0 : config.fixed,
287
343
  amount: amount.toNumber(),
288
- percentage: config?.percentage,
344
+ percentage: config == null ? void 0 : config.percentage,
289
345
  metadata: {
290
- open_product: config?.open_product
346
+ open_product: config == null ? void 0 : config.open_product
291
347
  }
292
348
  };
293
349
  }
294
350
  function applySurchargeNodeResult(node, params) {
295
- const {
296
- unitSurchargeFee,
297
- roundingRemainder,
298
- surchargeIds
299
- } = params;
300
- if (node.kind === 'main') {
351
+ const { unitSurchargeFee, roundingRemainder, surchargeIds } = params;
352
+ if (node.kind === "main") {
301
353
  node.target.surcharge_fee = unitSurchargeFee.toNumber();
302
354
  node.target.main_product_attached_bundle_surcharge_fee = toFixed2(unitSurchargeFee);
303
355
  node.target.surcharge_rounding_remainder = roundingRemainder.toNumber();
@@ -307,18 +359,14 @@ function applySurchargeNodeResult(node, params) {
307
359
  node.target.surcharge_fee = unitSurchargeFee.toNumber();
308
360
  node.target.relation_surcharge_ids = surchargeIds;
309
361
  node.target.metadata = {
310
- ...(node.target.metadata || {}),
362
+ ...node.target.metadata || {},
311
363
  surcharge_fee: toFixed2(unitSurchargeFee),
312
364
  surcharge_rounding_remainder: toFixed2(roundingRemainder),
313
365
  relation_surcharge_ids: surchargeIds
314
366
  };
315
367
  }
316
368
  function calculateBackendProductSurcharges(params) {
317
- const {
318
- products,
319
- sourceItems,
320
- surchargeList
321
- } = params;
369
+ const { products, sourceItems, surchargeList } = params;
322
370
  resetProductSurchargeFields(products);
323
371
  const configById = getSurchargeConfigById(surchargeList);
324
372
  const nodes = createSurchargeAllocationNodes(products, sourceItems);
@@ -330,33 +378,49 @@ function calculateBackendProductSurcharges(params) {
330
378
  }
331
379
  const persistedSurchargeIds = getPersistedSurchargeIds(nodes);
332
380
  const quantityTotals = buildSurchargeQuantityTotals(nodes);
333
- const stateMap = new Map();
381
+ const stateMap = /* @__PURE__ */ new Map();
334
382
  for (const node of nodes) {
335
- let unitSurchargeFee = new _decimal.default(0);
336
- let roundingRemainder = new _decimal.default(0);
383
+ let unitSurchargeFee = new import_decimal.default(0);
384
+ let roundingRemainder = new import_decimal.default(0);
337
385
  const appliedSurchargeIds = [];
338
386
  let persistedRemainderApplied = false;
339
387
  for (const surchargeId of node.relationSurchargeIds) {
340
388
  const config = configById.get(surchargeId);
341
- const totalQuantity = quantityTotals.get(surchargeId) || new _decimal.default(0);
342
- if (totalQuantity.lte(0)) continue;
389
+ const totalQuantity = quantityTotals.get(surchargeId) || new import_decimal.default(0);
390
+ if (totalQuantity.lte(0))
391
+ continue;
343
392
  const persistedUnitSurchargeFee = node.persistedUnitSurchargeFee;
344
393
  if (persistedUnitSurchargeFee && persistedUnitSurchargeFee.gt(0)) {
345
- const persistedQuantity = _decimal.default.min(node.persistedQuantity, node.quantity);
346
- const deltaQuantity = _decimal.default.max(node.quantity.minus(persistedQuantity), 0);
347
- const state = getBackendSurchargeState(stateMap, surchargeId, config || {
348
- surcharge_id: surchargeId
349
- });
350
- const persistedSurchargeRemainder = !persistedRemainderApplied && node.persistedSurchargeRemainder ? node.persistedSurchargeRemainder : new _decimal.default(0);
351
- state.amount = bcAdd(bcAdd(state.amount, bcMul(persistedUnitSurchargeFee, persistedQuantity, 2), 2), persistedSurchargeRemainder, 2);
352
- const fixed = new _decimal.default(config?.fixed || 0);
353
- if (fixed.gt(0)) state.fixedIncluded = true;
354
- let nodeTotalSurcharge = bcAdd(bcMul(persistedUnitSurchargeFee, persistedQuantity, 2), persistedSurchargeRemainder, 2);
394
+ const persistedQuantity = import_decimal.default.min(node.persistedQuantity, node.quantity);
395
+ const deltaQuantity = import_decimal.default.max(node.quantity.minus(persistedQuantity), 0);
396
+ const state2 = getBackendSurchargeState(
397
+ stateMap,
398
+ surchargeId,
399
+ config || { surcharge_id: surchargeId }
400
+ );
401
+ const persistedSurchargeRemainder = !persistedRemainderApplied && node.persistedSurchargeRemainder ? node.persistedSurchargeRemainder : new import_decimal.default(0);
402
+ state2.amount = bcAdd(
403
+ bcAdd(
404
+ state2.amount,
405
+ bcMul(persistedUnitSurchargeFee, persistedQuantity, 2),
406
+ 2
407
+ ),
408
+ persistedSurchargeRemainder,
409
+ 2
410
+ );
411
+ const fixed2 = new import_decimal.default((config == null ? void 0 : config.fixed) || 0);
412
+ if (fixed2.gt(0))
413
+ state2.fixedIncluded = true;
414
+ let nodeTotalSurcharge = bcAdd(
415
+ bcMul(persistedUnitSurchargeFee, persistedQuantity, 2),
416
+ persistedSurchargeRemainder,
417
+ 2
418
+ );
355
419
  if (config && deltaQuantity.gt(0)) {
356
- const percentage = new _decimal.default(config.percentage || 0);
357
- const deltaUnitPercentageFee = _decimal.default.max(0, bcMul(node.unitAmount, percentage, 2));
420
+ const percentage2 = new import_decimal.default(config.percentage || 0);
421
+ const deltaUnitPercentageFee = import_decimal.default.max(0, bcMul(node.unitAmount, percentage2, 2));
358
422
  const deltaSurcharge = bcMul(deltaQuantity, deltaUnitPercentageFee, 2);
359
- state.amount = bcAdd(state.amount, deltaSurcharge, 2);
423
+ state2.amount = bcAdd(state2.amount, deltaSurcharge, 2);
360
424
  nodeTotalSurcharge = bcAdd(nodeTotalSurcharge, deltaSurcharge, 2);
361
425
  }
362
426
  if (node.quantity.gt(0)) {
@@ -369,25 +433,34 @@ function calculateBackendProductSurcharges(params) {
369
433
  appliedSurchargeIds.push(surchargeId);
370
434
  continue;
371
435
  }
372
- if (!config) continue;
373
- const percentage = new _decimal.default(config.percentage || 0);
374
- const fixed = new _decimal.default(config.fixed || 0);
375
- const unitPercentageFee = _decimal.default.max(0, bcMul(node.unitAmount, percentage, 2));
436
+ if (!config)
437
+ continue;
438
+ const percentage = new import_decimal.default(config.percentage || 0);
439
+ const fixed = new import_decimal.default(config.fixed || 0);
440
+ const unitPercentageFee = import_decimal.default.max(0, bcMul(node.unitAmount, percentage, 2));
376
441
  const percentageTotalFee = bcMul(node.quantity, unitPercentageFee, 2);
377
- let unitFixedFee = new _decimal.default(0);
378
- let fixedRemainder = new _decimal.default(0);
442
+ let unitFixedFee = new import_decimal.default(0);
443
+ let fixedRemainder = new import_decimal.default(0);
379
444
  if (fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
380
445
  unitFixedFee = bcDiv(fixed, totalQuantity, 2);
381
446
  const distributedFixed = bcMul(unitFixedFee, totalQuantity, 2);
382
447
  fixedRemainder = bcSub(fixed, distributedFixed, 2);
383
448
  }
384
- const currentUnitSurcharge = _decimal.default.max(0, bcAdd(unitPercentageFee, unitFixedFee, 2));
385
- if (currentUnitSurcharge.lte(0)) continue;
449
+ const currentUnitSurcharge = import_decimal.default.max(
450
+ 0,
451
+ bcAdd(unitPercentageFee, unitFixedFee, 2)
452
+ );
453
+ if (currentUnitSurcharge.lte(0))
454
+ continue;
386
455
  const state = getBackendSurchargeState(stateMap, surchargeId, config);
387
456
  state.amount = bcAdd(state.amount, percentageTotalFee, 2);
388
- const precisePercentage = _decimal.default.max(0, bcMul(node.unitAmount, percentage, 6));
389
- const offsetBaseFee = _decimal.default.max(0, bcSub(precisePercentage, unitPercentageFee, 6));
390
- state.totalOffsetFee = bcAdd(state.totalOffsetFee, bcMul(offsetBaseFee, node.quantity, 6), 6);
457
+ const precisePercentage = import_decimal.default.max(0, bcMul(node.unitAmount, percentage, 6));
458
+ const offsetBaseFee = import_decimal.default.max(0, bcSub(precisePercentage, unitPercentageFee, 6));
459
+ state.totalOffsetFee = bcAdd(
460
+ state.totalOffsetFee,
461
+ bcMul(offsetBaseFee, node.quantity, 6),
462
+ 6
463
+ );
391
464
  state.calculatedQuantity = bcAdd(state.calculatedQuantity, node.quantity, 6);
392
465
  if (!state.fixedIncluded && fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
393
466
  state.amount = bcAdd(state.amount, fixed, 2);
@@ -401,7 +474,7 @@ function calculateBackendProductSurcharges(params) {
401
474
  const totalOffsetFee = toAmountFormat(state.totalOffsetFee);
402
475
  state.amount = bcAdd(state.amount, totalOffsetFee, 2);
403
476
  roundingRemainder = bcAdd(roundingRemainder, totalOffsetFee, 2);
404
- state.totalOffsetFee = new _decimal.default(0);
477
+ state.totalOffsetFee = new import_decimal.default(0);
405
478
  }
406
479
  unitSurchargeFee = bcAdd(unitSurchargeFee, currentUnitSurcharge, 2);
407
480
  appliedSurchargeIds.push(surchargeId);
@@ -414,62 +487,73 @@ function calculateBackendProductSurcharges(params) {
414
487
  }
415
488
  const result = (surchargeList || []).reduce((items, config, index) => {
416
489
  const surchargeId = getSurchargeConfigId(config);
417
- if (surchargeId === undefined) return items;
490
+ if (surchargeId === void 0)
491
+ return items;
418
492
  const state = stateMap.get(surchargeId);
419
- if (!state || state.amount.lte(0)) return items;
493
+ if (!state || state.amount.lte(0))
494
+ return items;
420
495
  items.push(buildSurchargeResultItem(config, surchargeId, state.amount, index));
421
496
  return items;
422
497
  }, []);
423
- const includedIds = new Set(result.map(item => item?.surcharge_id).filter(id => id !== undefined));
498
+ const includedIds = new Set(
499
+ result.map((item) => item == null ? void 0 : item.surcharge_id).filter((id) => id !== void 0)
500
+ );
424
501
  for (const [surchargeId, state] of stateMap.entries()) {
425
- if (includedIds.has(surchargeId) || state.amount.lte(0)) continue;
502
+ if (includedIds.has(surchargeId) || state.amount.lte(0))
503
+ continue;
426
504
  result.push(buildSurchargeResultItem(state.config, surchargeId, state.amount, result.length));
427
505
  }
428
506
  return result;
429
507
  }
430
508
  function getProductDepositData(product) {
431
- const rootDepositData = product._origin?.custom_deposit_data;
432
- if (rootDepositData && typeof rootDepositData === 'object') return rootDepositData;
433
- const nestedDepositData = product._origin?.product?.custom_deposit_data;
434
- if (nestedDepositData && typeof nestedDepositData === 'object') return nestedDepositData;
435
- return undefined;
509
+ var _a, _b, _c;
510
+ const rootDepositData = (_a = product._origin) == null ? void 0 : _a.custom_deposit_data;
511
+ if (rootDepositData && typeof rootDepositData === "object")
512
+ return rootDepositData;
513
+ const nestedDepositData = (_c = (_b = product._origin) == null ? void 0 : _b.product) == null ? void 0 : _c.custom_deposit_data;
514
+ if (nestedDepositData && typeof nestedDepositData === "object")
515
+ return nestedDepositData;
516
+ return void 0;
436
517
  }
437
518
  function collectDepositPolicyIds(depositData) {
438
- const rawIds = [...(Array.isArray(depositData?.self_deposit_policy_ids) ? depositData.self_deposit_policy_ids : []), ...(Array.isArray(depositData?.deposit_policy_ids) ? depositData.deposit_policy_ids : [])];
519
+ const rawIds = [
520
+ ...Array.isArray(depositData == null ? void 0 : depositData.self_deposit_policy_ids) ? depositData.self_deposit_policy_ids : [],
521
+ ...Array.isArray(depositData == null ? void 0 : depositData.deposit_policy_ids) ? depositData.deposit_policy_ids : []
522
+ ];
439
523
  return rawIds.reduce((result, id) => {
440
524
  const normalizedId = Number(id);
441
- if (!Number.isFinite(normalizedId)) return result;
525
+ if (!Number.isFinite(normalizedId))
526
+ return result;
442
527
  result.push(Math.floor(normalizedId));
443
528
  return result;
444
529
  }, []);
445
530
  }
446
531
  function collectDepositPolicyData(depositData) {
447
- const rawPolicyData = Array.isArray(depositData?.deposit_policy_data) ? depositData.deposit_policy_data : [];
532
+ const rawPolicyData = Array.isArray(depositData == null ? void 0 : depositData.deposit_policy_data) ? depositData.deposit_policy_data : [];
448
533
  return rawPolicyData.reduce((result, policy) => {
449
- const normalizedId = Number(policy?.id);
450
- if (!Number.isFinite(normalizedId)) return result;
534
+ const normalizedId = Number(policy == null ? void 0 : policy.id);
535
+ if (!Number.isFinite(normalizedId))
536
+ return result;
451
537
  result.push({
452
538
  id: Math.floor(normalizedId),
453
- title: String(policy?.title || '')
539
+ title: String((policy == null ? void 0 : policy.title) || "")
454
540
  });
455
541
  return result;
456
542
  }, []);
457
543
  }
458
544
  function calculateProductsDeposit(products) {
459
- let totalDeposit = new _decimal.default(0);
545
+ let totalDeposit = new import_decimal.default(0);
460
546
  let hasDeposit = false;
461
- const policyIds = new Set();
462
- const policyDataMap = new Map();
547
+ const policyIds = /* @__PURE__ */ new Set();
548
+ const policyDataMap = /* @__PURE__ */ new Map();
463
549
  for (const product of products) {
464
550
  const depositData = getProductDepositData(product);
465
- if (!depositData || depositData.has_deposit != 1) continue;
551
+ if (!depositData || depositData.has_deposit != 1)
552
+ continue;
466
553
  const num = getSafeNum(product.num);
467
554
  const unitTotal = getUnitPaymentTotal(product);
468
555
  const productTotal = unitTotal.times(num);
469
- const {
470
- deposit_fixed,
471
- deposit_percentage
472
- } = depositData;
556
+ const { deposit_fixed, deposit_percentage } = depositData;
473
557
  const fixed = toDecimal(deposit_fixed);
474
558
  const percentage = toDecimal(deposit_percentage);
475
559
  const itemDeposit = fixed.plus(percentage.times(productTotal));
@@ -485,12 +569,13 @@ function calculateProductsDeposit(products) {
485
569
  policyIds.add(policy.id);
486
570
  }
487
571
  }
488
- if (!hasDeposit) return undefined;
572
+ if (!hasDeposit)
573
+ return void 0;
489
574
  for (const id of policyIds) {
490
575
  if (!policyDataMap.has(id)) {
491
576
  policyDataMap.set(id, {
492
577
  id,
493
- title: ''
578
+ title: ""
494
579
  });
495
580
  }
496
581
  }
@@ -502,93 +587,75 @@ function calculateProductsDeposit(products) {
502
587
  };
503
588
  }
504
589
  function isBundleOriginalPrice(item) {
505
- return item?.price_type === 'markup' && item?.price_type_ext === 'product_price';
590
+ return (item == null ? void 0 : item.price_type) === "markup" && (item == null ? void 0 : item.price_type_ext) === "product_price";
506
591
  }
507
592
  function isBundleMarkupOrDiscount(item) {
508
- const isMarkup = item?.price_type === 'markup' && (item?.price_type_ext === '' || !item?.price_type_ext);
509
- const isDiscount = item?.price_type === 'markdown' && (item?.price_type_ext === '' || !item?.price_type_ext);
593
+ 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));
594
+ 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));
510
595
  return isMarkup || isDiscount;
511
596
  }
512
-
513
- /**
514
- * 计算单个商品税费(返回精确值,不四舍五入)。
515
- * 与 Summary/utils.ts 的 getProductItemTax 公式一致,但不依赖 bookingDetail。
516
- *
517
- * @param taxRate 百分比税率(如 5 表示 5%),函数内部会 /100
518
- */
519
597
  function calculateSingleItemTax(params) {
520
- const {
521
- price,
522
- taxRate,
523
- isPriceIncludeTax,
524
- isChargeTax
525
- } = params;
526
- if (price.lte(0)) return new _decimal.default(0);
527
- if (isChargeTax === 0 || !isChargeTax) return new _decimal.default(0);
598
+ const { price, taxRate, isPriceIncludeTax, isChargeTax } = params;
599
+ if (price.lte(0))
600
+ return new import_decimal.default(0);
601
+ if (isChargeTax === 0 || !isChargeTax)
602
+ return new import_decimal.default(0);
528
603
  const rate = taxRate.div(100);
529
604
  if (isPriceIncludeTax === 0) {
530
605
  return price.times(rate);
531
606
  }
532
- const divisor = new _decimal.default(1).plus(rate);
533
- if (divisor.lte(0)) return new _decimal.default(0);
607
+ const divisor = new import_decimal.default(1).plus(rate);
608
+ if (divisor.lte(0))
609
+ return new import_decimal.default(0);
534
610
  return price.dividedBy(divisor).times(rate);
535
611
  }
536
-
537
- /**
538
- * 主商品 + 非原价(加价/减价)子商品的"折扣后"售价合计(含 option、含主商品折扣,未减整单折扣)。
539
- *
540
- * 对齐后端 metadata.main_product_attached_bundle_selling_price:
541
- * - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价;
542
- * - 叠加 `markup` / `markdown` 类 bundle(原价 bundle 由 `calculateProductsTax` 独立处理)。
543
- */
544
612
  function getMainAttachedBundleSellingTotal(product) {
545
- const mainSelling = product.metadata?.main_product_selling_price ?? product.metadata?.main_product_original_price ?? 0;
613
+ var _a, _b;
614
+ 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;
546
615
  let total = toDecimal(mainSelling);
547
616
  const bundleItems = product.product_bundle || [];
548
617
  for (const bundleItem of bundleItems) {
549
618
  if (isBundleMarkupOrDiscount(bundleItem)) {
550
- // markdown(减价)按带符号净额取减;markup 维持相加。
551
- const unit = (0, _utils2.getBundleSignedUnit)(bundleItem);
619
+ const unit = (0, import_utils2.getBundleSignedUnit)(bundleItem);
552
620
  const qty = getSafeNum(bundleItem.num ?? bundleItem.quantity);
553
621
  total = total.plus(unit.times(qty));
554
622
  }
555
623
  }
556
- return _decimal.default.max(total, 0);
624
+ return import_decimal.default.max(total, 0);
557
625
  }
558
-
559
- /**
560
- * 获取主商品税费基数(含 option、含主商品折扣、含加价/减价 bundle、已减整单折扣均摊)。
561
- *
562
- * 对齐后端 handleMainProductTaxFee:税基使用 main_product_attached_bundle_payment_price。
563
- * - 优先读取均摊层写入的 payment 价;
564
- * - 兜底退化为 selling 合计(无整单折扣时两者相等)。
565
- */
566
626
  function getMainProductPaymentTotal(product) {
567
- const attachedPayment = product.metadata?.main_product_attached_bundle_payment_price;
568
- if (attachedPayment !== undefined && attachedPayment !== null && attachedPayment !== '') {
569
- return _decimal.default.max(toDecimal(attachedPayment), 0);
627
+ var _a;
628
+ const attachedPayment = (_a = product.metadata) == null ? void 0 : _a.main_product_attached_bundle_payment_price;
629
+ if (attachedPayment !== void 0 && attachedPayment !== null && attachedPayment !== "") {
630
+ return import_decimal.default.max(toDecimal(attachedPayment), 0);
570
631
  }
571
632
  return getMainAttachedBundleSellingTotal(product);
572
633
  }
573
634
  function getExplicitTaxRemainder(item) {
574
- const value = item?.tax_fee_rounding_remainder ?? item?.metadata?.tax_fee_rounding_remainder;
575
- if (value === undefined || value === null || value === '') return null;
576
- return new _decimal.default(value || 0);
635
+ var _a;
636
+ const value = (item == null ? void 0 : item.tax_fee_rounding_remainder) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.tax_fee_rounding_remainder);
637
+ if (value === void 0 || value === null || value === "")
638
+ return null;
639
+ return new import_decimal.default(value || 0);
577
640
  }
578
641
  function getPersistedTaxRemainder(item, parentProduct) {
579
- const isPersistedLine = item?.order_detail_id !== undefined && item?.order_detail_id !== null || parentProduct?.order_detail_id !== undefined && parentProduct?.order_detail_id !== null;
580
- if (!isPersistedLine) return null;
642
+ const isPersistedLine = (item == null ? void 0 : item.order_detail_id) !== void 0 && (item == null ? void 0 : item.order_detail_id) !== null || (parentProduct == null ? void 0 : parentProduct.order_detail_id) !== void 0 && (parentProduct == null ? void 0 : parentProduct.order_detail_id) !== null;
643
+ if (!isPersistedLine)
644
+ return null;
581
645
  return getExplicitTaxRemainder(item);
582
646
  }
583
647
  function getPersistedMainTaxFee(product) {
584
- if (product?.order_detail_id === undefined || product?.order_detail_id === null) return null;
585
- const value = product?.metadata?.main_product_attached_bundle_tax_fee ?? product?.main_product_attached_bundle_tax_fee ?? product?.tax_fee;
586
- if (value === undefined || value === null || value === '') return null;
648
+ var _a;
649
+ if ((product == null ? void 0 : product.order_detail_id) === void 0 || (product == null ? void 0 : product.order_detail_id) === null)
650
+ return null;
651
+ const value = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.main_product_attached_bundle_tax_fee) ?? (product == null ? void 0 : product.main_product_attached_bundle_tax_fee) ?? (product == null ? void 0 : product.tax_fee);
652
+ if (value === void 0 || value === null || value === "")
653
+ return null;
587
654
  return toDecimal(value);
588
655
  }
589
656
  function writeTaxRemainder(item, roundingRemainder) {
590
657
  item.tax_fee_rounding_remainder = roundingRemainder.toNumber();
591
- if (item.metadata && typeof item.metadata === 'object') {
658
+ if (item.metadata && typeof item.metadata === "object") {
592
659
  item.metadata.tax_fee_rounding_remainder = roundingRemainder.toFixed(2);
593
660
  }
594
661
  }
@@ -604,7 +671,7 @@ function resetTaxRemainderFields(products) {
604
671
  for (const bundle of product.product_bundle || []) {
605
672
  const bundleRemainder = getPersistedTaxRemainder(bundle, product);
606
673
  bundle.metadata = {
607
- ...(bundle.metadata || {})
674
+ ...bundle.metadata || {}
608
675
  };
609
676
  if (bundleRemainder !== null) {
610
677
  bundle.metadata.tax_fee_rounding_remainder = bundleRemainder.toFixed(2);
@@ -618,49 +685,47 @@ function resetTaxRemainderFields(products) {
618
685
  }
619
686
  }
620
687
  function getBundlePaymentPrice(bundle, product) {
621
- if (bundle?.bundle_payment_price !== undefined) return toDecimal(bundle.bundle_payment_price);
622
- const basePrice = toDecimal(bundle?.bundle_selling_price ?? bundle?.bundle_sum_price ?? bundle?.price ?? 0);
623
- if (!isBundleOriginalPrice(bundle)) return basePrice;
624
- const averageDiscountRate = toDecimal(product.metadata?.average_discount_amount_rate ?? 1);
688
+ var _a;
689
+ if ((bundle == null ? void 0 : bundle.bundle_payment_price) !== void 0)
690
+ return toDecimal(bundle.bundle_payment_price);
691
+ const basePrice = toDecimal((bundle == null ? void 0 : bundle.bundle_selling_price) ?? (bundle == null ? void 0 : bundle.bundle_sum_price) ?? (bundle == null ? void 0 : bundle.price) ?? 0);
692
+ if (!isBundleOriginalPrice(bundle))
693
+ return basePrice;
694
+ const averageDiscountRate = toDecimal(
695
+ ((_a = product.metadata) == null ? void 0 : _a.average_discount_amount_rate) ?? 1
696
+ );
625
697
  return toAmountFormat(bcMul(basePrice, averageDiscountRate, 6));
626
698
  }
627
699
  function applyBackendTaxRemainder(params) {
628
- const {
629
- target,
630
- rawTax,
631
- formattedTax,
700
+ const { target, rawTax, formattedTax, quantity, state } = params;
701
+ const taxFeeDifference = bcMul(
702
+ bcSub(rawTax, formattedTax, 6),
632
703
  quantity,
633
- state
634
- } = params;
635
- const taxFeeDifference = bcMul(bcSub(rawTax, formattedTax, 6), quantity, 6);
704
+ 6
705
+ );
636
706
  state.difference = bcAdd(state.difference, taxFeeDifference, 6);
637
- if (state.difference.lt(0.005)) return new _decimal.default(0);
707
+ if (state.difference.lt(5e-3))
708
+ return new import_decimal.default(0);
638
709
  const roundingRemainder = toAmountFormat(state.difference);
639
710
  writeTaxRemainder(target, roundingRemainder);
640
711
  state.difference = bcSub(state.difference, roundingRemainder, 6);
641
712
  return roundingRemainder;
642
713
  }
643
-
644
- /**
645
- * 遍历所有商品计算税费,回写 tax_fee 到每个商品及 bundle 原价子商品,处理舍入差值。
646
- * 参照 Summary/utils.ts 的 processItemsTax,适配 SalesSummaryProduct 结构。
647
- */
648
714
  function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
649
- const rate = new _decimal.default(taxRate);
650
- const taxRemainderState = {
651
- difference: new _decimal.default(0)
652
- };
653
- let totalTax = new _decimal.default(0);
654
- let totalOriginTax = new _decimal.default(0);
715
+ const rate = new import_decimal.default(taxRate);
716
+ const taxRemainderState = { difference: new import_decimal.default(0) };
717
+ let totalTax = new import_decimal.default(0);
718
+ let totalOriginTax = new import_decimal.default(0);
655
719
  resetTaxRemainderFields(products);
656
720
  for (const product of products) {
657
- const quantity = new _decimal.default(getSafeNum(product.num));
658
- let productUnitTax = new _decimal.default(0);
659
- let productUnitOriginTax = new _decimal.default(0);
721
+ const quantity = new import_decimal.default(getSafeNum(product.num));
722
+ let productUnitTax = new import_decimal.default(0);
723
+ let productUnitOriginTax = new import_decimal.default(0);
660
724
  const bundleItems = product.product_bundle || [];
661
725
  for (const bundleItem of bundleItems) {
662
- if (!isBundleOriginalPrice(bundleItem)) continue;
663
- const bundleQuantity = new _decimal.default(getSafeNum(bundleItem.num ?? bundleItem.quantity));
726
+ if (!isBundleOriginalPrice(bundleItem))
727
+ continue;
728
+ const bundleQuantity = new import_decimal.default(getSafeNum(bundleItem.num ?? bundleItem.quantity));
664
729
  const totalBundleQuantity = bundleQuantity.times(quantity);
665
730
  const bundlePrice = getBundlePaymentPrice(bundleItem, product);
666
731
  const bundleOriginalPrice = toDecimal(bundleItem.original_price ?? bundleItem.product_price ?? bundleItem.price ?? 0);
@@ -681,7 +746,8 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
681
746
  quantity: totalBundleQuantity,
682
747
  state: taxRemainderState
683
748
  });
684
- if (persistedBundleRemainder) writeTaxRemainder(bundleItem, persistedBundleRemainder);
749
+ if (persistedBundleRemainder)
750
+ writeTaxRemainder(bundleItem, persistedBundleRemainder);
685
751
  const bundleOrigTaxPrecise = calculateSingleItemTax({
686
752
  price: bundleOriginalPrice.plus(bundleSurchargeFee),
687
753
  taxRate: rate,
@@ -696,8 +762,7 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
696
762
  totalOriginTax = totalOriginTax.plus(bundleOrigTaxRounded.times(totalBundleQuantity));
697
763
  }
698
764
  const mainTotal = getMainProductPaymentTotal(product);
699
- const surchargeRoundingRemainder = toDecimal(product.surcharge_rounding_remainder);
700
- const surchargeFee = toDecimal(product.surcharge_fee).plus(quantity.gt(0) ? surchargeRoundingRemainder.div(quantity) : 0);
765
+ const surchargeFee = toDecimal(product.surcharge_fee);
701
766
  const mainTaxableBase = mainTotal.lte(0) ? surchargeFee : mainTotal.plus(surchargeFee);
702
767
  const mainTaxPrecise = calculateSingleItemTax({
703
768
  price: mainTaxableBase,
@@ -709,10 +774,10 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
709
774
  const persistedMainRemainder = getPersistedTaxRemainder(product);
710
775
  const persistedMainTaxFee = getPersistedMainTaxFee(product);
711
776
  const persistedQuantity = getPersistedQuantity(product, quantity);
712
- const deltaQuantity = _decimal.default.max(quantity.minus(persistedQuantity), 0);
777
+ const deltaQuantity = import_decimal.default.max(quantity.minus(persistedQuantity), 0);
713
778
  const shouldUsePersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gte(quantity);
714
779
  const shouldSplitPersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gt(0) && deltaQuantity.gt(0);
715
- const mainRemainder = shouldUsePersistedMainTax || shouldSplitPersistedMainTax ? new _decimal.default(0) : persistedMainRemainder ?? applyBackendTaxRemainder({
780
+ const mainRemainder = shouldUsePersistedMainTax || shouldSplitPersistedMainTax ? new import_decimal.default(0) : persistedMainRemainder ?? applyBackendTaxRemainder({
716
781
  target: product,
717
782
  rawTax: mainTaxPrecise,
718
783
  formattedTax: mainTaxRounded,
@@ -731,66 +796,55 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
731
796
  isChargeTax: product.is_charge_tax ?? 0
732
797
  });
733
798
  const originalTaxRounded = toAmountFormat(originalTaxPrecise);
734
- const effectiveMainUnitTax = shouldUsePersistedMainTax ? persistedMainTaxFee : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)).div(quantity).toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP) : mainTaxRounded;
799
+ const effectiveMainUnitTax = shouldUsePersistedMainTax ? persistedMainTaxFee : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)).div(quantity).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP) : mainTaxRounded;
735
800
  productUnitTax = productUnitTax.plus(effectiveMainUnitTax);
736
801
  productUnitOriginTax = productUnitOriginTax.plus(originalTaxRounded);
737
- product.main_product_attached_bundle_tax_fee = effectiveMainUnitTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toFixed(2);
738
- product.tax_fee = productUnitTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toFixed(2);
739
- product.original_tax_fee = productUnitOriginTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
740
- totalTax = totalTax.plus(shouldUsePersistedMainTax ? persistedMainTaxFee.times(quantity).plus(persistedMainRemainder || 0) : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)) : mainTaxRounded.times(quantity).plus(mainRemainder));
802
+ product.main_product_attached_bundle_tax_fee = effectiveMainUnitTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toFixed(2);
803
+ product.tax_fee = productUnitTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toFixed(2);
804
+ product.original_tax_fee = productUnitOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
805
+ totalTax = totalTax.plus(
806
+ shouldUsePersistedMainTax ? persistedMainTaxFee.times(quantity).plus(persistedMainRemainder || 0) : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)) : mainTaxRounded.times(quantity).plus(mainRemainder)
807
+ );
741
808
  totalOriginTax = totalOriginTax.plus(originalTaxRounded.times(quantity));
742
- if (product.tax_fee_rounding_remainder === undefined) {
809
+ if (product.tax_fee_rounding_remainder === void 0) {
743
810
  product.tax_fee_rounding_remainder = 0;
744
811
  }
745
812
  }
746
813
  return {
747
- tax: totalTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP),
748
- originTax: totalOriginTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP)
814
+ tax: totalTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP),
815
+ originTax: totalOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP)
749
816
  };
750
817
  }
751
-
752
- /**
753
- * 整单折扣(shop_discount)按各行 selling 合计占比均摊到 payment 维度。
754
- *
755
- * 文档口径:
756
- * - payment_price = selling_price − 整单折扣均摊;rate = payment/selling(全行同一 rate);
757
- * - 附加费不受整单折扣影响(基数仍用 selling,本函数写 main_product_attached_bundle_selling_price);
758
- * - 税费受整单折扣影响(基数用 payment,本函数写 main_product_attached_bundle_payment_price 与
759
- * 原价子商品 bundle_payment_price)。
760
- *
761
- * 与后端一致:bundle_payment_price = bundle_selling_price × rate,
762
- * main_product_attached_bundle_payment_price = main_product_attached_bundle_selling_price × rate。
763
- */
764
818
  function allocateShopDiscountToPayment(products, productAmount, shopDiscountAmount) {
765
- const effectiveDiscount = productAmount.lte(0) ? new _decimal.default(0) : _decimal.default.max(_decimal.default.min(productAmount, shopDiscountAmount), 0);
766
- let allocatedDiscount = new _decimal.default(0);
819
+ const effectiveDiscount = productAmount.lte(0) ? new import_decimal.default(0) : import_decimal.default.max(import_decimal.default.min(productAmount, shopDiscountAmount), 0);
820
+ let allocatedDiscount = new import_decimal.default(0);
767
821
  products.forEach((product, index) => {
768
- const quantity = new _decimal.default(getSafeNum(product.num));
822
+ const quantity = new import_decimal.default(getSafeNum(product.num));
769
823
  const sellingUnit = getUnitPaymentTotal(product);
770
824
  const lineSellingTotal = sellingUnit.times(quantity);
771
- const lineDiscount = effectiveDiscount.lte(0) ? new _decimal.default(0) : index === products.length - 1 ? _decimal.default.max(effectiveDiscount.minus(allocatedDiscount), 0) : toAmountFormat(lineSellingTotal.div(productAmount).times(effectiveDiscount));
825
+ const lineDiscount = effectiveDiscount.lte(0) ? new import_decimal.default(0) : index === products.length - 1 ? import_decimal.default.max(effectiveDiscount.minus(allocatedDiscount), 0) : toAmountFormat(lineSellingTotal.div(productAmount).times(effectiveDiscount));
772
826
  allocatedDiscount = allocatedDiscount.plus(lineDiscount);
773
- const unitDiscount = quantity.lte(0) ? new _decimal.default(0) : lineDiscount.div(quantity);
774
- const paymentUnit = _decimal.default.max(sellingUnit.minus(unitDiscount), 0);
775
- const rate = sellingUnit.lte(0) ? new _decimal.default(1) : toBcScale(paymentUnit.div(sellingUnit), 6);
827
+ const unitDiscount = quantity.lte(0) ? new import_decimal.default(0) : lineDiscount.div(quantity);
828
+ const paymentUnit = import_decimal.default.max(sellingUnit.minus(unitDiscount), 0);
829
+ const rate = sellingUnit.lte(0) ? new import_decimal.default(1) : toBcScale(paymentUnit.div(sellingUnit), 6);
776
830
  const mainSellingTotal = getMainAttachedBundleSellingTotal(product);
777
831
  const mainPaymentTotal = toAmountFormat(bcMul(mainSellingTotal, rate, 6));
778
832
  product.metadata = {
779
- ...(product.metadata || {}),
833
+ ...product.metadata || {},
780
834
  average_discount_amount_rate: rate.toString(),
781
835
  main_product_attached_bundle_selling_price: mainSellingTotal.toFixed(2),
782
836
  main_product_attached_bundle_payment_price: mainPaymentTotal.toFixed(2)
783
837
  };
784
838
  for (const bundle of product.product_bundle || []) {
785
- // 原价子商品:bundle_payment_price = bundle_selling_price × rate
786
- // markdown 子商品:以净额幅度 × rate(与后端一致,存正净额)
787
839
  if (isBundleOriginalPrice(bundle)) {
788
- const bundleSelling = toDecimal(bundle.bundle_selling_price ?? bundle.bundle_sum_price ?? bundle.price ?? 0);
840
+ const bundleSelling = toDecimal(
841
+ bundle.bundle_selling_price ?? bundle.bundle_sum_price ?? bundle.price ?? 0
842
+ );
789
843
  bundle.bundle_payment_price = toAmountFormat(bcMul(bundleSelling, rate, 6)).toFixed(2);
790
844
  continue;
791
845
  }
792
- if ((0, _utils2.isMarkdownBundle)(bundle)) {
793
- const magnitude = (0, _utils2.getBundleSellingMagnitude)(bundle);
846
+ if ((0, import_utils2.isMarkdownBundle)(bundle)) {
847
+ const magnitude = (0, import_utils2.getBundleSellingMagnitude)(bundle);
794
848
  bundle.custom_price = bundle.custom_price ?? bundle.price;
795
849
  bundle.price = magnitude.toFixed(2);
796
850
  bundle.bundle_selling_price = magnitude.toFixed(2);
@@ -803,25 +857,25 @@ function allocateShopDiscountToPayment(products, productAmount, shopDiscountAmou
803
857
  function createEmptySalesSummary() {
804
858
  return {
805
859
  product_quantity: 0,
806
- product_original_amount: '0.00',
807
- product_amount: '0.00',
808
- product_expect_amount: '0.00',
809
- product_tax_fee: '0.00',
810
- shipping_fee: '0.00',
811
- shipping_tax_fee: '0.00',
812
- tax_fee: '0.00',
813
- surcharge_fee: '0.00',
860
+ product_original_amount: "0.00",
861
+ product_amount: "0.00",
862
+ product_expect_amount: "0.00",
863
+ product_tax_fee: "0.00",
864
+ shipping_fee: "0.00",
865
+ shipping_tax_fee: "0.00",
866
+ tax_fee: "0.00",
867
+ surcharge_fee: "0.00",
814
868
  surcharges: [],
815
- discount_amount: '0.00',
816
- deposit_amount: '0.00',
817
- expect_amount: '0.00',
818
- total_amount: '0.00',
819
- total_refund_amount: '0.00',
820
- customer_paid_amount: '0.00',
821
- order_paid_amount: '0.00',
822
- amount_gap: '0.00',
823
- rounding_amount: '0.00',
824
- pay_service_charge_amount: '0.00'
869
+ discount_amount: "0.00",
870
+ deposit_amount: "0.00",
871
+ expect_amount: "0.00",
872
+ total_amount: "0.00",
873
+ total_refund_amount: "0.00",
874
+ customer_paid_amount: "0.00",
875
+ order_paid_amount: "0.00",
876
+ amount_gap: "0.00",
877
+ rounding_amount: "0.00",
878
+ pay_service_charge_amount: "0.00"
825
879
  };
826
880
  }
827
881
  function calculateSalesSummary(params) {
@@ -834,54 +888,71 @@ function calculateSalesSummary(params) {
834
888
  isInScheduleByDate,
835
889
  shopDiscount
836
890
  } = params;
837
- if (!products?.length) return createEmptySalesSummary();
838
- const summaryProducts = products.filter(product => !isGeneratedVoucherProduct(product));
839
- if (!summaryProducts.length) return createEmptySalesSummary();
840
- const productQuantity = summaryProducts.reduce((sum, item) => sum + getSafeNum(item.num), 0);
841
- const productOriginalAmount = summaryProducts.reduce((sum, item) => sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num))), new _decimal.default(0));
842
- const productAmount = summaryProducts.reduce((sum, item) => sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num))), new _decimal.default(0));
843
- const shopDiscountAmount = _decimal.default.max(new _decimal.default(Number(shopDiscount) || 0), 0);
844
- const hasPersistedSurchargeSnapshot = summaryProducts.some(product => {
845
- return getPersistedMainSurchargeFee(product)?.gt(0);
891
+ if (!(products == null ? void 0 : products.length))
892
+ return createEmptySalesSummary();
893
+ const summaryProducts = products.filter((product) => !isGeneratedVoucherProduct(product));
894
+ if (!summaryProducts.length)
895
+ return createEmptySalesSummary();
896
+ const productQuantity = summaryProducts.reduce(
897
+ (sum, item) => sum + getSafeNum(item.num),
898
+ 0
899
+ );
900
+ const productOriginalAmount = summaryProducts.reduce(
901
+ (sum, item) => sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num))),
902
+ new import_decimal.default(0)
903
+ );
904
+ const productAmount = summaryProducts.reduce(
905
+ (sum, item) => sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num))),
906
+ new import_decimal.default(0)
907
+ );
908
+ const shopDiscountAmount = import_decimal.default.max(new import_decimal.default(Number(shopDiscount) || 0), 0);
909
+ const hasPersistedSurchargeSnapshot = summaryProducts.some((product) => {
910
+ var _a;
911
+ return (_a = getPersistedMainSurchargeFee(product)) == null ? void 0 : _a.gt(0);
846
912
  });
847
- // 整单折扣均摊:附加费基数用 selling(不受折扣),税费基数用 payment(受折扣)。
848
- // persisted 快照(已下单编辑)优先采信后端回传值,不重算均摊。
849
913
  if (!hasPersistedSurchargeSnapshot) {
850
914
  allocateShopDiscountToPayment(summaryProducts, productAmount, shopDiscountAmount);
851
915
  }
852
916
  const surchargeServiceItems = buildSurchargeServiceItems(summaryProducts);
853
- (0, _utils.getSurcharge)({
854
- service: surchargeServiceItems,
855
- addons: [],
856
- bookingDetail: null,
857
- bookingId: undefined
858
- }, {
859
- isEdit: false,
860
- isInScheduleByDate,
861
- surcharge_list: surchargeList,
862
- scheduleById
863
- });
917
+ (0, import_utils.getSurcharge)(
918
+ {
919
+ service: surchargeServiceItems,
920
+ addons: [],
921
+ bookingDetail: null,
922
+ bookingId: void 0
923
+ },
924
+ {
925
+ isEdit: false,
926
+ isInScheduleByDate,
927
+ surcharge_list: surchargeList,
928
+ scheduleById
929
+ }
930
+ );
864
931
  const surcharge = calculateBackendProductSurcharges({
865
932
  products: summaryProducts,
866
933
  sourceItems: surchargeServiceItems,
867
934
  surchargeList
868
935
  });
869
- const surchargeAmount = new _decimal.default((0, _utils.getSurchargeAmount)({
870
- bookingDetail: null,
871
- bookingId: undefined
872
- }, surcharge, {
873
- isEdit: false
874
- }) || 0);
875
- const hasTaxRate = taxRate !== undefined && taxRate !== null && taxRate > 0;
936
+ const surchargeAmount = new import_decimal.default(
937
+ (0, import_utils.getSurchargeAmount)(
938
+ { bookingDetail: null, bookingId: void 0 },
939
+ surcharge,
940
+ { isEdit: false }
941
+ ) || 0
942
+ );
943
+ const hasTaxRate = taxRate !== void 0 && taxRate !== null && taxRate > 0;
876
944
  let productTaxFee;
877
945
  if (hasTaxRate) {
878
946
  const taxResult = calculateProductsTax(summaryProducts, taxRate, isPriceIncludeTax);
879
947
  productTaxFee = taxResult.tax;
880
948
  } else {
881
- productTaxFee = summaryProducts.reduce((sum, item) => sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num))), new _decimal.default(0));
949
+ productTaxFee = summaryProducts.reduce(
950
+ (sum, item) => sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num))),
951
+ new import_decimal.default(0)
952
+ );
882
953
  }
883
954
  const orderAmountBeforeDiscount = productAmount.plus(surchargeAmount).plus(isPriceIncludeTax === 1 ? 0 : productTaxFee);
884
- const totalAmount = _decimal.default.max(0, orderAmountBeforeDiscount.minus(shopDiscountAmount));
955
+ const totalAmount = import_decimal.default.max(0, orderAmountBeforeDiscount.minus(shopDiscountAmount));
885
956
  const deposit = calculateProductsDeposit(summaryProducts);
886
957
  return {
887
958
  product_quantity: productQuantity,
@@ -889,22 +960,27 @@ function calculateSalesSummary(params) {
889
960
  product_amount: toFixed2(productAmount),
890
961
  product_expect_amount: toFixed2(productAmount),
891
962
  product_tax_fee: toFixed2(productTaxFee),
892
- shipping_fee: '0.00',
893
- shipping_tax_fee: '0.00',
963
+ shipping_fee: "0.00",
964
+ shipping_tax_fee: "0.00",
894
965
  tax_fee: toFixed2(productTaxFee),
895
966
  surcharge_fee: toFixed2(surchargeAmount),
896
967
  surcharges: surcharge,
897
968
  discount_amount: toFixed2(shopDiscountAmount),
898
- deposit_amount: deposit ? deposit.total : '0.00',
969
+ deposit_amount: deposit ? deposit.total : "0.00",
899
970
  deposit,
900
971
  expect_amount: toFixed2(totalAmount),
901
972
  total_amount: toFixed2(totalAmount),
902
- total_refund_amount: '0.00',
903
- customer_paid_amount: '0.00',
904
- order_paid_amount: '0.00',
905
- amount_gap: '0.00',
906
- rounding_amount: '0.00',
907
- pay_service_charge_amount: '0.00',
973
+ total_refund_amount: "0.00",
974
+ customer_paid_amount: "0.00",
975
+ order_paid_amount: "0.00",
976
+ amount_gap: "0.00",
977
+ rounding_amount: "0.00",
978
+ pay_service_charge_amount: "0.00",
908
979
  is_price_include_tax: isPriceIncludeTax
909
980
  };
910
- }
981
+ }
982
+ // Annotate the CommonJS export names for ESM import in node:
983
+ 0 && (module.exports = {
984
+ calculateSalesSummary,
985
+ createEmptySalesSummary
986
+ });