@pisell/pisellos 0.0.568 → 0.0.570

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 (455) hide show
  1. package/dist/effects/index.d.ts +2 -2
  2. package/dist/model/strategy/adapter/dataVariant/type.d.ts +3 -3
  3. package/dist/model/strategy/adapter/itemRule/type.d.ts +6 -6
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
  5. package/dist/model/strategy/adapter/promotion/type.d.ts +5 -5
  6. package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
  7. package/dist/model/strategy/type.d.ts +1 -1
  8. package/dist/modules/BaseModule.d.ts +2 -2
  9. package/dist/modules/BaseModule.js +4 -4
  10. package/dist/modules/BookingContext/index.d.ts +48 -0
  11. package/dist/modules/BookingContext/index.js +566 -0
  12. package/dist/modules/BookingContext/types.d.ts +102 -0
  13. package/dist/modules/BookingContext/types.js +51 -0
  14. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  15. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
  16. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  17. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
  18. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  19. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
  20. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  21. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  22. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  23. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  24. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  25. package/dist/modules/BookingContext/utils/index.js +11 -0
  26. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  27. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  28. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  29. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  30. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  31. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  32. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  33. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  34. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  35. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  36. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  37. package/dist/modules/BookingContext/utils/resources.js +486 -0
  38. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  39. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  40. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  41. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  42. package/dist/modules/Cart/utils/cartProduct.js +26 -5
  43. package/dist/modules/Cart/utils/changePrice.js +27 -20
  44. package/dist/modules/Customer/index.d.ts +20 -0
  45. package/dist/modules/Customer/index.js +172 -83
  46. package/dist/modules/Customer/types.d.ts +3 -1
  47. package/dist/modules/Discount/index.d.ts +2 -1
  48. package/dist/modules/Discount/index.js +37 -9
  49. package/dist/modules/Discount/types.d.ts +2 -1
  50. package/dist/modules/Holder/types.d.ts +1 -1
  51. package/dist/modules/OpenData/index.d.ts +8 -0
  52. package/dist/modules/OpenData/index.js +36 -16
  53. package/dist/modules/OpenData/types.d.ts +1 -1
  54. package/dist/modules/Order/index.d.ts +448 -23
  55. package/dist/modules/Order/index.js +5417 -561
  56. package/dist/modules/Order/types.d.ts +693 -88
  57. package/dist/modules/Order/types.js +68 -1
  58. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  59. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  60. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  61. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  62. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  63. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  64. package/dist/modules/Order/utils.d.ts +167 -18
  65. package/dist/modules/Order/utils.js +960 -165
  66. package/dist/modules/Payment/index.d.ts +10 -9
  67. package/dist/modules/Payment/index.js +465 -703
  68. package/dist/modules/Payment/types.d.ts +47 -23
  69. package/dist/modules/Payment/utils.d.ts +1 -1
  70. package/dist/modules/Payment/utils.js +4 -3
  71. package/dist/modules/Payment/walletpass.js +44 -29
  72. package/dist/modules/Product/index.d.ts +1 -1
  73. package/dist/modules/Product/types.d.ts +29 -7
  74. package/dist/modules/ProductList/index.d.ts +17 -13
  75. package/dist/modules/ProductList/index.js +184 -74
  76. package/dist/modules/ProductList/types.d.ts +17 -0
  77. package/dist/modules/Quotation/index.d.ts +22 -2
  78. package/dist/modules/Quotation/index.js +108 -42
  79. package/dist/modules/Quotation/types.d.ts +19 -0
  80. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  81. package/dist/modules/ResourcePlanner/index.js +181 -0
  82. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  83. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  84. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  85. package/dist/modules/ResourcePlanner/types.js +1 -0
  86. package/dist/modules/Rules/index.d.ts +8 -10
  87. package/dist/modules/Rules/index.js +222 -109
  88. package/dist/modules/Rules/types.d.ts +15 -4
  89. package/dist/modules/SalesSummary/index.d.ts +23 -26
  90. package/dist/modules/SalesSummary/index.js +152 -46
  91. package/dist/modules/SalesSummary/types.d.ts +9 -1
  92. package/dist/modules/SalesSummary/utils.d.ts +3 -22
  93. package/dist/modules/SalesSummary/utils.js +803 -163
  94. package/dist/modules/ScanOrderLogger/types.d.ts +2 -2
  95. package/dist/modules/Schedule/getDateIsInSchedule.d.ts +1 -1
  96. package/dist/modules/Schedule/getDateIsInSchedule.js +14 -7
  97. package/dist/modules/Schedule/index.d.ts +18 -5
  98. package/dist/modules/Schedule/index.js +78 -24
  99. package/dist/modules/Schedule/type.d.ts +7 -7
  100. package/dist/modules/Schedule/types.d.ts +11 -9
  101. package/dist/modules/Summary/index.js +4 -3
  102. package/dist/modules/SurchargeList/index.d.ts +18 -0
  103. package/dist/modules/SurchargeList/index.js +185 -0
  104. package/dist/modules/SurchargeList/types.d.ts +15 -0
  105. package/dist/modules/SurchargeList/types.js +1 -0
  106. package/dist/modules/index.d.ts +3 -0
  107. package/dist/modules/index.js +4 -1
  108. package/dist/plugins/app.d.ts +2 -0
  109. package/dist/plugins/request.d.ts +3 -2
  110. package/dist/server/index.d.ts +462 -8
  111. package/dist/server/index.js +6112 -656
  112. package/dist/server/modules/floor-plan/index.d.ts +39 -0
  113. package/dist/server/modules/floor-plan/index.js +595 -0
  114. package/dist/server/modules/floor-plan/types.d.ts +43 -0
  115. package/dist/server/modules/floor-plan/types.js +13 -0
  116. package/dist/server/modules/index.d.ts +7 -2
  117. package/dist/server/modules/index.js +6 -0
  118. package/dist/server/modules/menu/types.d.ts +1 -1
  119. package/dist/server/modules/order/index.d.ts +207 -14
  120. package/dist/server/modules/order/index.js +2326 -379
  121. package/dist/server/modules/order/types.d.ts +91 -20
  122. package/dist/server/modules/order/types.js +14 -1
  123. package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
  124. package/dist/server/modules/order/utils/filterBookings.js +118 -11
  125. package/dist/server/modules/order/utils/filterOrders.js +242 -14
  126. package/dist/server/modules/payment/index.d.ts +28 -0
  127. package/dist/server/modules/payment/index.js +305 -0
  128. package/dist/server/modules/payment/types.d.ts +9 -0
  129. package/dist/server/modules/payment/types.js +1 -0
  130. package/dist/server/modules/products/index.d.ts +105 -14
  131. package/dist/server/modules/products/index.js +1393 -516
  132. package/dist/server/modules/products/types.d.ts +35 -2
  133. package/dist/server/modules/products/types.js +4 -0
  134. package/dist/server/modules/quotation/index.d.ts +39 -0
  135. package/dist/server/modules/quotation/index.js +278 -66
  136. package/dist/server/modules/resource/index.d.ts +2 -3
  137. package/dist/server/modules/resource/index.js +108 -86
  138. package/dist/server/modules/resource/types.d.ts +1 -1
  139. package/dist/server/modules/schedule/index.d.ts +6 -4
  140. package/dist/server/modules/schedule/index.js +116 -85
  141. package/dist/server/modules/schedule/utils.d.ts +1 -1
  142. package/dist/server/test.json +713 -0
  143. package/dist/server/types.d.ts +6 -4
  144. package/dist/server/utils/product.js +2 -2
  145. package/dist/server/utils/small-ticket.d.ts +71 -0
  146. package/dist/server/utils/small-ticket.js +963 -0
  147. package/dist/solution/BaseSales/index.d.ts +378 -0
  148. package/dist/solution/BaseSales/index.js +4006 -0
  149. package/dist/solution/BaseSales/types.d.ts +394 -0
  150. package/dist/solution/BaseSales/types.js +40 -0
  151. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  152. package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
  153. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  154. package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
  155. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  156. package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
  157. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  158. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
  159. package/dist/solution/BaseSales/utils.d.ts +40 -0
  160. package/dist/solution/BaseSales/utils.js +263 -0
  161. package/dist/solution/BookingByStep/index.d.ts +2 -2
  162. package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
  163. package/dist/solution/BookingTicket/index.d.ts +382 -25
  164. package/dist/solution/BookingTicket/index.js +2506 -443
  165. package/dist/solution/BookingTicket/types.d.ts +191 -6
  166. package/dist/solution/BookingTicket/types.js +83 -10
  167. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  168. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  169. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  170. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
  171. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  172. package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
  173. package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
  174. package/dist/solution/BookingTicket/utils/cartView.js +209 -0
  175. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  176. package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
  177. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  178. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  179. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  180. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
  181. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  182. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
  183. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  184. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +41 -1
  185. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  186. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  187. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  188. package/dist/solution/BookingTicket/utils/scan/handleScan.js +11 -3
  189. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  190. package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
  191. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  192. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  193. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  194. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
  195. package/dist/solution/Checkout/index.d.ts +1 -0
  196. package/dist/solution/Checkout/index.js +25 -34
  197. package/dist/solution/Checkout/utils/index.js +4 -4
  198. package/dist/solution/RegisterAndLogin/config.js +2 -10
  199. package/dist/solution/Sales/index.d.ts +50 -5
  200. package/dist/solution/Sales/index.js +484 -92
  201. package/dist/solution/Sales/types.d.ts +29 -5
  202. package/dist/solution/ScanOrder/index.d.ts +27 -21
  203. package/dist/solution/ScanOrder/index.js +499 -434
  204. package/dist/solution/ScanOrder/types.d.ts +38 -16
  205. package/dist/solution/ScanOrder/types.js +4 -5
  206. package/dist/solution/ScanOrder/utils.d.ts +4 -1
  207. package/dist/solution/ScanOrder/utils.js +109 -34
  208. package/dist/solution/ShopDiscount/index.js +4 -4
  209. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  210. package/dist/solution/ShopDiscount/utils.d.ts +2 -2
  211. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  212. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  213. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  214. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  215. package/dist/solution/VenueBooking/index.d.ts +29 -20
  216. package/dist/solution/VenueBooking/index.js +301 -213
  217. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  218. package/dist/solution/VenueBooking/types.d.ts +1 -1
  219. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  220. package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
  221. package/dist/solution/index.d.ts +2 -0
  222. package/dist/solution/index.js +3 -1
  223. package/dist/types/index.d.ts +12 -2
  224. package/dist/utils/task.d.ts +2 -2
  225. package/dist/utils/watch.d.ts +2 -2
  226. package/lib/effects/index.d.ts +2 -2
  227. package/lib/model/strategy/adapter/dataVariant/type.d.ts +3 -3
  228. package/lib/model/strategy/adapter/itemRule/type.d.ts +6 -6
  229. package/lib/model/strategy/adapter/promotion/evaluator.js +3 -2
  230. package/lib/model/strategy/adapter/promotion/type.d.ts +5 -5
  231. package/lib/model/strategy/adapter/walletPass/utils.js +6 -4
  232. package/lib/model/strategy/type.d.ts +1 -1
  233. package/lib/modules/BaseModule.d.ts +2 -2
  234. package/lib/modules/BaseModule.js +4 -4
  235. package/lib/modules/BookingContext/index.d.ts +48 -0
  236. package/lib/modules/BookingContext/index.js +390 -0
  237. package/lib/modules/BookingContext/types.d.ts +102 -0
  238. package/lib/modules/BookingContext/types.js +48 -0
  239. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  240. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +286 -0
  241. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  242. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +148 -0
  243. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  244. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +242 -0
  245. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  246. package/lib/modules/BookingContext/utils/flexible.js +63 -0
  247. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  248. package/lib/modules/BookingContext/utils/formatResourceList.js +35 -0
  249. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  250. package/lib/modules/BookingContext/utils/index.js +126 -0
  251. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  252. package/lib/modules/BookingContext/utils/noResource.js +78 -0
  253. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  254. package/lib/modules/BookingContext/utils/orderLineDisplay.js +29 -0
  255. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  256. package/lib/modules/BookingContext/utils/productExtend.js +330 -0
  257. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  258. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  259. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  260. package/lib/modules/BookingContext/utils/resourceSelection.js +24 -0
  261. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  262. package/lib/modules/BookingContext/utils/resources.js +419 -0
  263. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  264. package/lib/modules/BookingContext/utils/serviceTimes.js +161 -0
  265. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  266. package/lib/modules/BookingContext/utils/timeSlices.js +114 -0
  267. package/lib/modules/Cart/utils/cartProduct.js +27 -5
  268. package/lib/modules/Cart/utils/changePrice.js +20 -14
  269. package/lib/modules/Customer/index.d.ts +20 -0
  270. package/lib/modules/Customer/index.js +63 -10
  271. package/lib/modules/Customer/types.d.ts +3 -1
  272. package/lib/modules/Discount/index.d.ts +2 -1
  273. package/lib/modules/Discount/index.js +18 -2
  274. package/lib/modules/Discount/types.d.ts +2 -1
  275. package/lib/modules/Holder/types.d.ts +1 -1
  276. package/lib/modules/OpenData/index.d.ts +8 -0
  277. package/lib/modules/OpenData/index.js +21 -3
  278. package/lib/modules/OpenData/types.d.ts +1 -1
  279. package/lib/modules/Order/index.d.ts +448 -23
  280. package/lib/modules/Order/index.js +3641 -308
  281. package/lib/modules/Order/types.d.ts +693 -88
  282. package/lib/modules/Order/types.js +55 -1
  283. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  284. package/lib/modules/Order/utils/bundleDiscountHydration.js +106 -0
  285. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  286. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  287. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  288. package/lib/modules/Order/utils/orderCollectionIdentity.js +353 -0
  289. package/lib/modules/Order/utils.d.ts +167 -18
  290. package/lib/modules/Order/utils.js +974 -138
  291. package/lib/modules/Payment/index.d.ts +10 -9
  292. package/lib/modules/Payment/index.js +30 -124
  293. package/lib/modules/Payment/types.d.ts +47 -23
  294. package/lib/modules/Payment/utils.d.ts +1 -1
  295. package/lib/modules/Payment/utils.js +4 -3
  296. package/lib/modules/Payment/walletpass.js +16 -6
  297. package/lib/modules/Product/index.d.ts +1 -1
  298. package/lib/modules/Product/types.d.ts +29 -7
  299. package/lib/modules/ProductList/index.d.ts +17 -13
  300. package/lib/modules/ProductList/index.js +92 -51
  301. package/lib/modules/ProductList/types.d.ts +17 -0
  302. package/lib/modules/Quotation/index.d.ts +22 -2
  303. package/lib/modules/Quotation/index.js +76 -20
  304. package/lib/modules/Quotation/types.d.ts +19 -0
  305. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  306. package/lib/modules/ResourcePlanner/index.js +147 -0
  307. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  308. package/lib/modules/ResourcePlanner/planner.js +895 -0
  309. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  310. package/lib/modules/ResourcePlanner/types.js +5 -0
  311. package/lib/modules/Rules/index.d.ts +8 -10
  312. package/lib/modules/Rules/index.js +153 -61
  313. package/lib/modules/Rules/types.d.ts +15 -4
  314. package/lib/modules/SalesSummary/index.d.ts +23 -26
  315. package/lib/modules/SalesSummary/index.js +84 -16
  316. package/lib/modules/SalesSummary/types.d.ts +9 -1
  317. package/lib/modules/SalesSummary/utils.d.ts +3 -22
  318. package/lib/modules/SalesSummary/utils.js +616 -111
  319. package/lib/modules/ScanOrderLogger/types.d.ts +2 -2
  320. package/lib/modules/Schedule/getDateIsInSchedule.d.ts +1 -1
  321. package/lib/modules/Schedule/getDateIsInSchedule.js +14 -7
  322. package/lib/modules/Schedule/index.d.ts +18 -5
  323. package/lib/modules/Schedule/index.js +49 -14
  324. package/lib/modules/Schedule/type.d.ts +7 -7
  325. package/lib/modules/Schedule/types.d.ts +11 -9
  326. package/lib/modules/Summary/index.js +2 -2
  327. package/lib/modules/SurchargeList/index.d.ts +18 -0
  328. package/lib/modules/SurchargeList/index.js +95 -0
  329. package/lib/modules/SurchargeList/types.d.ts +15 -0
  330. package/lib/modules/SurchargeList/types.js +5 -0
  331. package/lib/modules/index.d.ts +3 -0
  332. package/lib/modules/index.js +33 -0
  333. package/lib/plugins/app.d.ts +2 -0
  334. package/lib/plugins/request.d.ts +3 -2
  335. package/lib/server/index.d.ts +462 -8
  336. package/lib/server/index.js +3901 -205
  337. package/lib/server/modules/floor-plan/index.d.ts +39 -0
  338. package/lib/server/modules/floor-plan/index.js +306 -0
  339. package/lib/server/modules/floor-plan/types.d.ts +43 -0
  340. package/lib/server/modules/floor-plan/types.js +19 -0
  341. package/lib/server/modules/index.d.ts +7 -2
  342. package/lib/server/modules/index.js +21 -0
  343. package/lib/server/modules/menu/types.d.ts +1 -1
  344. package/lib/server/modules/order/index.d.ts +207 -14
  345. package/lib/server/modules/order/index.js +1324 -141
  346. package/lib/server/modules/order/types.d.ts +91 -20
  347. package/lib/server/modules/order/types.js +11 -1
  348. package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
  349. package/lib/server/modules/order/utils/filterBookings.js +119 -11
  350. package/lib/server/modules/order/utils/filterOrders.js +238 -13
  351. package/lib/server/modules/payment/index.d.ts +28 -0
  352. package/lib/server/modules/payment/index.js +168 -0
  353. package/lib/server/modules/payment/types.d.ts +9 -0
  354. package/lib/server/modules/payment/types.js +5 -0
  355. package/lib/server/modules/products/index.d.ts +105 -14
  356. package/lib/server/modules/products/index.js +588 -97
  357. package/lib/server/modules/products/types.d.ts +35 -2
  358. package/lib/server/modules/products/types.js +3 -0
  359. package/lib/server/modules/quotation/index.d.ts +39 -0
  360. package/lib/server/modules/quotation/index.js +145 -1
  361. package/lib/server/modules/resource/index.d.ts +2 -3
  362. package/lib/server/modules/resource/index.js +71 -45
  363. package/lib/server/modules/resource/types.d.ts +1 -1
  364. package/lib/server/modules/schedule/index.d.ts +6 -4
  365. package/lib/server/modules/schedule/index.js +55 -44
  366. package/lib/server/modules/schedule/utils.d.ts +1 -1
  367. package/lib/server/test.json +713 -0
  368. package/lib/server/types.d.ts +6 -4
  369. package/lib/server/utils/product.js +2 -2
  370. package/lib/server/utils/small-ticket.d.ts +71 -0
  371. package/lib/server/utils/small-ticket.js +926 -0
  372. package/lib/solution/BaseSales/index.d.ts +378 -0
  373. package/lib/solution/BaseSales/index.js +2367 -0
  374. package/lib/solution/BaseSales/types.d.ts +394 -0
  375. package/lib/solution/BaseSales/types.js +47 -0
  376. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  377. package/lib/solution/BaseSales/utils/cartPromotion.js +1155 -0
  378. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  379. package/lib/solution/BaseSales/utils/parseSalesResponse.js +140 -0
  380. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  381. package/lib/solution/BaseSales/utils/quotationPrice.js +231 -0
  382. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  383. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +215 -0
  384. package/lib/solution/BaseSales/utils.d.ts +40 -0
  385. package/lib/solution/BaseSales/utils.js +259 -0
  386. package/lib/solution/BookingByStep/index.d.ts +2 -2
  387. package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
  388. package/lib/solution/BookingTicket/index.d.ts +382 -25
  389. package/lib/solution/BookingTicket/index.js +1350 -76
  390. package/lib/solution/BookingTicket/types.d.ts +191 -6
  391. package/lib/solution/BookingTicket/types.js +71 -10
  392. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  393. package/lib/solution/BookingTicket/utils/addProductDecision.js +353 -0
  394. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  395. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +94 -0
  396. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  397. package/lib/solution/BookingTicket/utils/bookingStatus.js +136 -0
  398. package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
  399. package/lib/solution/BookingTicket/utils/cartView.js +200 -0
  400. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  401. package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
  402. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  403. package/lib/solution/BookingTicket/utils/orderCustomer.js +35 -0
  404. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  405. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +387 -0
  406. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  407. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +220 -0
  408. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  409. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +24 -3
  410. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  411. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +64 -0
  412. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  413. package/lib/solution/BookingTicket/utils/scan/handleScan.js +4 -2
  414. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  415. package/lib/solution/BookingTicket/utils/scan/index.js +14 -2
  416. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  417. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +115 -0
  418. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  419. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +83 -0
  420. package/lib/solution/Checkout/index.d.ts +1 -0
  421. package/lib/solution/Checkout/index.js +18 -19
  422. package/lib/solution/Checkout/utils/index.js +4 -4
  423. package/lib/solution/RegisterAndLogin/config.js +2 -10
  424. package/lib/solution/Sales/index.d.ts +50 -5
  425. package/lib/solution/Sales/index.js +296 -39
  426. package/lib/solution/Sales/types.d.ts +29 -5
  427. package/lib/solution/ScanOrder/index.d.ts +27 -21
  428. package/lib/solution/ScanOrder/index.js +144 -103
  429. package/lib/solution/ScanOrder/types.d.ts +38 -16
  430. package/lib/solution/ScanOrder/types.js +4 -5
  431. package/lib/solution/ScanOrder/utils.d.ts +4 -1
  432. package/lib/solution/ScanOrder/utils.js +98 -26
  433. package/lib/solution/ShopDiscount/index.js +3 -3
  434. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  435. package/lib/solution/ShopDiscount/utils.d.ts +2 -2
  436. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  437. package/lib/solution/UnifiedBookingSales/index.js +1050 -0
  438. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  439. package/lib/solution/UnifiedBookingSales/types.js +14 -0
  440. package/lib/solution/VenueBooking/index.d.ts +29 -20
  441. package/lib/solution/VenueBooking/index.js +169 -94
  442. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  443. package/lib/solution/VenueBooking/types.d.ts +1 -1
  444. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  445. package/lib/solution/VenueBooking/utils/slotMerge.js +9 -3
  446. package/lib/solution/index.d.ts +2 -0
  447. package/lib/solution/index.js +22 -0
  448. package/lib/types/index.d.ts +12 -2
  449. package/lib/utils/task.d.ts +2 -2
  450. package/lib/utils/watch.d.ts +2 -2
  451. package/package.json +18 -19
  452. package/dist/model/strategy/adapter/promotion/index.d.ts +0 -4
  453. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  454. package/lib/model/strategy/adapter/promotion/index.d.ts +0 -4
  455. package/lib/solution/Checkout/appointmentDemo.json +0 -1
@@ -1,3 +1,8 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
6
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
8
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -5,15 +10,44 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
5
10
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
11
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
12
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
18
  import Decimal from 'decimal.js';
10
19
  import { getSurcharge, getSurchargeAmount } from "../Summary/utils";
20
+ import { getBundleSellingMagnitude, getBundleSignedUnit, getProductSkuOptions, isMarkdownBundle } from "../Order/utils";
11
21
  function toDecimal(value) {
12
22
  return new Decimal(value || 0);
13
23
  }
14
24
  function toFixed2(value) {
15
25
  return new Decimal(value || 0).toFixed(2);
16
26
  }
27
+ function toAmountFormat(value) {
28
+ return new Decimal(value || 0).toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
29
+ }
30
+ function toBackendTaxFee(value) {
31
+ return toBcScale(value, 2);
32
+ }
33
+ function toBcScale(value, scale) {
34
+ var factor = new Decimal(10).pow(scale);
35
+ return new Decimal(value || 0).times(factor).toDecimalPlaces(0, Decimal.ROUND_DOWN).div(factor);
36
+ }
37
+ function bcAdd(left, right, scale) {
38
+ return toBcScale(new Decimal(left || 0).plus(right || 0), scale);
39
+ }
40
+ function bcSub(left, right, scale) {
41
+ return toBcScale(new Decimal(left || 0).minus(right || 0), scale);
42
+ }
43
+ function bcMul(left, right, scale) {
44
+ return toBcScale(new Decimal(left || 0).times(right || 0), scale);
45
+ }
46
+ function bcDiv(left, right, scale) {
47
+ var divisor = new Decimal(right || 0);
48
+ if (divisor.eq(0)) return new Decimal(0);
49
+ return toBcScale(new Decimal(left || 0).div(divisor), scale);
50
+ }
17
51
  function getSafeNum(num) {
18
52
  if (!num || Number.isNaN(num)) return 1;
19
53
  if (num < 1) return 1;
@@ -23,10 +57,12 @@ function getBundleUnitPrice(product) {
23
57
  var useOriginal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
24
58
  var bundleItems = product.product_bundle || [];
25
59
  return bundleItems.reduce(function (sum, item) {
26
- var _ref, _item$original_price, _item$bundle_selling_;
27
60
  var quantity = getSafeNum(item === null || item === void 0 ? void 0 : item.num);
28
- var price = useOriginal ? toDecimal((_ref = (_item$original_price = item === null || item === void 0 ? void 0 : item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item === null || item === void 0 ? void 0 : item.product_price) !== null && _ref !== void 0 ? _ref : item === null || item === void 0 ? void 0 : item.price) : toDecimal((_item$bundle_selling_ = item === null || item === void 0 ? void 0 : item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item === null || item === void 0 ? void 0 : item.price);
29
- return sum.plus(price.times(quantity));
61
+ // markdown(减价)按带符号净额取减;markup/原价维持相加。
62
+ var signedUnit = getBundleSignedUnit(item, {
63
+ useOriginal: useOriginal
64
+ });
65
+ return sum.plus(signedUnit.times(quantity));
30
66
  }, new Decimal(0));
31
67
  }
32
68
 
@@ -48,11 +84,18 @@ function getUnitOriginalTotal(product) {
48
84
  var basePrice = mainOriginal !== undefined ? toDecimal(mainOriginal) : mainSelling !== undefined ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
49
85
  return basePrice.plus(getBundleUnitPrice(product, true));
50
86
  }
87
+ function isGeneratedVoucherProduct(product) {
88
+ var record = product;
89
+ var metadata = (record === null || record === void 0 ? void 0 : record.metadata) || {};
90
+ return (record === null || record === void 0 ? void 0 : record.extension_type) === 'product_voucher' || metadata.parent_order_detail_id !== undefined || metadata.gift_card_type !== undefined;
91
+ }
51
92
  function buildSurchargeServiceItems(products) {
52
93
  return products.map(function (product) {
53
94
  var _product$is_charge_ta, _product$metadata5, _product$metadata6;
54
95
  var quantity = getSafeNum(product.num);
55
96
  var unitTotal = getUnitPaymentTotal(product);
97
+ var options = getProductSkuOptions(product);
98
+ var persistedSurchargeFee = getPersistedMainSurchargeFee(product);
56
99
  return {
57
100
  id: product.product_id,
58
101
  num: quantity,
@@ -64,19 +107,444 @@ function buildSurchargeServiceItems(products) {
64
107
  product: {
65
108
  discount_list: product.discount_list || [],
66
109
  product_bundle: product.product_bundle || [],
67
- product_option_item: product.product_option_item || []
110
+ product_sku: product.product_sku || {
111
+ option: options
112
+ }
68
113
  }
69
114
  },
70
115
  bundle: product.product_bundle || [],
71
- option: product.product_option_item || [],
72
- options: product.product_option_item || [],
116
+ option: options,
117
+ options: options,
73
118
  relation_details: [],
74
- metadata: product.metadata || {},
119
+ metadata: _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
120
+ __persisted_surcharge_fee: persistedSurchargeFee === null || persistedSurchargeFee === void 0 ? void 0 : persistedSurchargeFee.toFixed(2)
121
+ }),
75
122
  start_date: ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.start_date) || '',
76
123
  start_time: ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.start_time) || ''
77
124
  };
78
125
  });
79
126
  }
127
+ function getRelationSurchargeIds(item) {
128
+ var _item$metadata;
129
+ var ids = [].concat(_toConsumableArray(Array.isArray(item === null || item === void 0 ? void 0 : item.relation_surcharge_ids) ? item.relation_surcharge_ids : []), _toConsumableArray(Array.isArray(item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.relation_surcharge_ids) ? item.metadata.relation_surcharge_ids : []));
130
+ return _toConsumableArray(new Set(ids.filter(function (id) {
131
+ return id !== undefined && id !== null && id !== '';
132
+ })));
133
+ }
134
+ function getSurchargeConfigId(config) {
135
+ var _config$id;
136
+ return (_config$id = config === null || config === void 0 ? void 0 : config.id) !== null && _config$id !== void 0 ? _config$id : config === null || config === void 0 ? void 0 : config.surcharge_id;
137
+ }
138
+ function getSurchargeConfigById(surchargeList) {
139
+ var map = new Map();
140
+ var _iterator = _createForOfIteratorHelper(surchargeList || []),
141
+ _step;
142
+ try {
143
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
144
+ var config = _step.value;
145
+ var id = getSurchargeConfigId(config);
146
+ if (id !== undefined) map.set(id, config);
147
+ }
148
+ } catch (err) {
149
+ _iterator.e(err);
150
+ } finally {
151
+ _iterator.f();
152
+ }
153
+ return map;
154
+ }
155
+ function getMainSurchargeUnitAmount(product) {
156
+ var _ref, _ref2, _record$metadata$main, _record$metadata, _record$metadata2;
157
+ var record = product;
158
+ return toDecimal((_ref = (_ref2 = (_record$metadata$main = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.main_product_attached_bundle_selling_price) !== null && _record$metadata$main !== void 0 ? _record$metadata$main : (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.main_product_selling_price) !== null && _ref2 !== void 0 ? _ref2 : record.selling_price) !== null && _ref !== void 0 ? _ref : 0);
159
+ }
160
+ function getBundleSurchargeUnitAmount(bundle) {
161
+ var _ref3, _ref4, _bundle$bundle_sellin;
162
+ return toDecimal((_ref3 = (_ref4 = (_bundle$bundle_sellin = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle === null || bundle === void 0 ? void 0 : bundle.bundle_sum_price) !== null && _ref4 !== void 0 ? _ref4 : bundle === null || bundle === void 0 ? void 0 : bundle.price) !== null && _ref3 !== void 0 ? _ref3 : 0);
163
+ }
164
+ function getBundleProductId(bundle) {
165
+ var _ref5, _bundle$bundle_produc;
166
+ var id = (_ref5 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref5 !== void 0 ? _ref5 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id;
167
+ if (id === undefined || id === null || id === '') return null;
168
+ var parsed = Number(id);
169
+ if (!Number.isFinite(parsed)) return null;
170
+ return parsed;
171
+ }
172
+ function getPersistedMainSurchargeFee(product) {
173
+ var _ref6, _product$surcharge_fe, _product$metadata7;
174
+ if ((product === null || product === void 0 ? void 0 : product.order_detail_id) === undefined || (product === null || product === void 0 ? void 0 : product.order_detail_id) === null) return null;
175
+ var value = (_ref6 = (_product$surcharge_fe = product === null || product === void 0 ? void 0 : product.surcharge_fee) !== null && _product$surcharge_fe !== void 0 ? _product$surcharge_fe : product === null || product === void 0 ? void 0 : product.main_product_attached_bundle_surcharge_fee) !== null && _ref6 !== void 0 ? _ref6 : product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_attached_bundle_surcharge_fee;
176
+ if (value === undefined || value === null || value === '') return null;
177
+ return toDecimal(value);
178
+ }
179
+ function getPersistedSourceSurchargeFee(sourceItem) {
180
+ var _sourceItem$metadata;
181
+ var value = sourceItem === null || sourceItem === void 0 || (_sourceItem$metadata = sourceItem.metadata) === null || _sourceItem$metadata === void 0 ? void 0 : _sourceItem$metadata.__persisted_surcharge_fee;
182
+ if (value === undefined || value === null || value === '') return null;
183
+ return toDecimal(value);
184
+ }
185
+ function getPersistedSurchargeRemainder(item, sourceItem) {
186
+ var _ref7, _sourceItem$metadata$, _sourceItem$metadata2, _item$metadata2;
187
+ var value = (_ref7 = (_sourceItem$metadata$ = sourceItem === null || sourceItem === void 0 || (_sourceItem$metadata2 = sourceItem.metadata) === null || _sourceItem$metadata2 === void 0 ? void 0 : _sourceItem$metadata2.surcharge_rounding_remainder) !== null && _sourceItem$metadata$ !== void 0 ? _sourceItem$metadata$ : item === null || item === void 0 ? void 0 : item.surcharge_rounding_remainder) !== null && _ref7 !== void 0 ? _ref7 : item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.surcharge_rounding_remainder;
188
+ if (value === undefined || value === null || value === '') return null;
189
+ return toDecimal(value);
190
+ }
191
+ function getPersistedQuantity(item, fallbackQuantity) {
192
+ var _item$product_quantit;
193
+ var isPersistedLine = (item === null || item === void 0 ? void 0 : item.order_detail_id) !== undefined && (item === null || item === void 0 ? void 0 : item.order_detail_id) !== null;
194
+ if (!isPersistedLine) return new Decimal(0);
195
+ var value = (_item$product_quantit = item === null || item === void 0 ? void 0 : item.product_quantity) !== null && _item$product_quantit !== void 0 ? _item$product_quantit : item === null || item === void 0 ? void 0 : item.quantity;
196
+ var parsed = new Decimal(value || 0);
197
+ if (parsed.lte(0)) return Decimal.min(fallbackQuantity, 1);
198
+ return Decimal.min(fallbackQuantity, parsed);
199
+ }
200
+ function getPersistedBundleSurchargeFee(bundle, product) {
201
+ var _bundle$surcharge_fee, _bundle$metadata;
202
+ if ((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) === undefined && (product === null || product === void 0 ? void 0 : product.order_detail_id) === undefined) return null;
203
+ if ((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) === null && (product === null || product === void 0 ? void 0 : product.order_detail_id) === null) return null;
204
+ var value = (_bundle$surcharge_fee = bundle === null || bundle === void 0 ? void 0 : bundle.surcharge_fee) !== null && _bundle$surcharge_fee !== void 0 ? _bundle$surcharge_fee : bundle === null || bundle === void 0 || (_bundle$metadata = bundle.metadata) === null || _bundle$metadata === void 0 ? void 0 : _bundle$metadata.surcharge_fee;
205
+ if (value === undefined || value === null || value === '') return null;
206
+ return toDecimal(value);
207
+ }
208
+ function createSurchargeAllocationNodes(products, sourceItems) {
209
+ var nodes = [];
210
+ for (var productIndex = 0; productIndex < products.length; productIndex++) {
211
+ var _product$product_id, _getPersistedSourceSu;
212
+ var product = products[productIndex];
213
+ var sourceItem = sourceItems[productIndex] || {};
214
+ var productQuantity = new Decimal(getSafeNum(product.num));
215
+ for (var bundleIndex = 0; bundleIndex < (product.product_bundle || []).length; bundleIndex++) {
216
+ var _sourceItem$bundle, _bundle$num, _bundle$num2;
217
+ var bundle = product.product_bundle[bundleIndex];
218
+ if (!isBundleOriginalPrice(bundle)) continue;
219
+ var sourceBundle = (sourceItem === null || sourceItem === void 0 || (_sourceItem$bundle = sourceItem.bundle) === null || _sourceItem$bundle === void 0 ? void 0 : _sourceItem$bundle[bundleIndex]) || {};
220
+ nodes.push({
221
+ kind: 'bundle',
222
+ target: bundle,
223
+ source: sourceBundle,
224
+ productId: getBundleProductId(bundle),
225
+ unitAmount: getBundleSurchargeUnitAmount(bundle),
226
+ quantity: new Decimal(getSafeNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity)).times(productQuantity),
227
+ persistedQuantity: getPersistedQuantity(bundle, new Decimal(getSafeNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity)).times(productQuantity)),
228
+ relationSurchargeIds: getRelationSurchargeIds(sourceBundle).length ? getRelationSurchargeIds(sourceBundle) : getRelationSurchargeIds(bundle),
229
+ persistedUnitSurchargeFee: getPersistedBundleSurchargeFee(bundle, product),
230
+ persistedSurchargeRemainder: getPersistedSurchargeRemainder(bundle, sourceBundle)
231
+ });
232
+ }
233
+ nodes.push({
234
+ kind: 'main',
235
+ target: product,
236
+ source: sourceItem,
237
+ productId: (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : null,
238
+ unitAmount: getMainSurchargeUnitAmount(product),
239
+ quantity: productQuantity,
240
+ persistedQuantity: getPersistedQuantity(product, productQuantity),
241
+ relationSurchargeIds: getRelationSurchargeIds(sourceItem).length ? getRelationSurchargeIds(sourceItem) : getRelationSurchargeIds(product),
242
+ persistedUnitSurchargeFee: (_getPersistedSourceSu = getPersistedSourceSurchargeFee(sourceItem)) !== null && _getPersistedSourceSu !== void 0 ? _getPersistedSourceSu : getPersistedMainSurchargeFee(product),
243
+ persistedSurchargeRemainder: getPersistedSurchargeRemainder(product, sourceItem)
244
+ });
245
+ }
246
+ return nodes;
247
+ }
248
+ function resetProductSurchargeFields(products) {
249
+ for (var _i = 0, _arr = products; _i < _arr.length; _i++) {
250
+ var product = _arr[_i];
251
+ product.surcharge_fee = 0;
252
+ product.main_product_attached_bundle_surcharge_fee = '0.00';
253
+ product.surcharge_rounding_remainder = 0;
254
+ product.relation_surcharge_ids = [];
255
+ var _iterator2 = _createForOfIteratorHelper(product.product_bundle || []),
256
+ _step2;
257
+ try {
258
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
259
+ var bundle = _step2.value;
260
+ bundle.surcharge_fee = 0;
261
+ bundle.relation_surcharge_ids = [];
262
+ bundle.metadata = _objectSpread(_objectSpread({}, bundle.metadata || {}), {}, {
263
+ surcharge_fee: '0.00',
264
+ surcharge_rounding_remainder: '0.00',
265
+ relation_surcharge_ids: []
266
+ });
267
+ }
268
+ } catch (err) {
269
+ _iterator2.e(err);
270
+ } finally {
271
+ _iterator2.f();
272
+ }
273
+ }
274
+ }
275
+ function getPersistedSurchargeIds(nodes) {
276
+ var ids = new Set();
277
+ var _iterator3 = _createForOfIteratorHelper(nodes),
278
+ _step3;
279
+ try {
280
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
281
+ var node = _step3.value;
282
+ if (!node.persistedUnitSurchargeFee || node.persistedUnitSurchargeFee.lte(0)) continue;
283
+ var _iterator4 = _createForOfIteratorHelper(node.relationSurchargeIds),
284
+ _step4;
285
+ try {
286
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
287
+ var surchargeId = _step4.value;
288
+ ids.add(surchargeId);
289
+ }
290
+ } catch (err) {
291
+ _iterator4.e(err);
292
+ } finally {
293
+ _iterator4.f();
294
+ }
295
+ }
296
+ } catch (err) {
297
+ _iterator3.e(err);
298
+ } finally {
299
+ _iterator3.f();
300
+ }
301
+ return ids;
302
+ }
303
+ function buildSurchargeQuantityTotals(nodes) {
304
+ var totals = new Map();
305
+ var _iterator5 = _createForOfIteratorHelper(nodes),
306
+ _step5;
307
+ try {
308
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
309
+ var node = _step5.value;
310
+ var _iterator6 = _createForOfIteratorHelper(node.relationSurchargeIds),
311
+ _step6;
312
+ try {
313
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
314
+ var surchargeId = _step6.value;
315
+ totals.set(surchargeId, (totals.get(surchargeId) || new Decimal(0)).plus(node.quantity));
316
+ }
317
+ } catch (err) {
318
+ _iterator6.e(err);
319
+ } finally {
320
+ _iterator6.f();
321
+ }
322
+ }
323
+ } catch (err) {
324
+ _iterator5.e(err);
325
+ } finally {
326
+ _iterator5.f();
327
+ }
328
+ return totals;
329
+ }
330
+ function getFallbackAllProductSurchargeIds(surchargeList) {
331
+ return (surchargeList || []).reduce(function (ids, config) {
332
+ var _config$open_product, _config$is_all, _config$open_schedule;
333
+ var id = getSurchargeConfigId(config);
334
+ if (id === undefined) return ids;
335
+ if (Number((_config$open_product = config.open_product) !== null && _config$open_product !== void 0 ? _config$open_product : 0) === 0) return ids;
336
+ if (Number((_config$is_all = config.is_all) !== null && _config$is_all !== void 0 ? _config$is_all : 0) !== 1) return ids;
337
+ if (Number((_config$open_schedule = config.open_schedule) !== null && _config$open_schedule !== void 0 ? _config$open_schedule : 0) === 1 && config.schedule_type !== 'all') return ids;
338
+ ids.push(id);
339
+ return ids;
340
+ }, []);
341
+ }
342
+ function getBackendSurchargeState(stateMap, surchargeId, config) {
343
+ var state = stateMap.get(surchargeId);
344
+ if (!state) {
345
+ state = {
346
+ config: config,
347
+ amount: new Decimal(0),
348
+ totalOffsetFee: new Decimal(0),
349
+ calculatedQuantity: new Decimal(0),
350
+ fixedIncluded: false,
351
+ fixedRemainderAssigned: false
352
+ };
353
+ stateMap.set(surchargeId, state);
354
+ }
355
+ return state;
356
+ }
357
+ function buildSurchargeResultItem(config, surchargeId, amount, index) {
358
+ var name = (config === null || config === void 0 ? void 0 : config.name) || (config === null || config === void 0 ? void 0 : config.label) || {};
359
+ return {
360
+ key: "custom_surcharge_".concat(index),
361
+ label: name,
362
+ name: name,
363
+ value: amount.toNumber(),
364
+ surcharge_id: surchargeId,
365
+ description: config === null || config === void 0 ? void 0 : config.description,
366
+ type: 'default',
367
+ fixed: config === null || config === void 0 ? void 0 : config.fixed,
368
+ amount: amount.toNumber(),
369
+ percentage: config === null || config === void 0 ? void 0 : config.percentage,
370
+ metadata: {
371
+ open_product: config === null || config === void 0 ? void 0 : config.open_product
372
+ }
373
+ };
374
+ }
375
+ function applySurchargeNodeResult(node, params) {
376
+ var unitSurchargeFee = params.unitSurchargeFee,
377
+ roundingRemainder = params.roundingRemainder,
378
+ surchargeIds = params.surchargeIds;
379
+ if (node.kind === 'main') {
380
+ node.target.surcharge_fee = unitSurchargeFee.toNumber();
381
+ node.target.main_product_attached_bundle_surcharge_fee = toFixed2(unitSurchargeFee);
382
+ node.target.surcharge_rounding_remainder = roundingRemainder.toNumber();
383
+ node.target.relation_surcharge_ids = surchargeIds;
384
+ return;
385
+ }
386
+ node.target.surcharge_fee = unitSurchargeFee.toNumber();
387
+ node.target.relation_surcharge_ids = surchargeIds;
388
+ node.target.metadata = _objectSpread(_objectSpread({}, node.target.metadata || {}), {}, {
389
+ surcharge_fee: toFixed2(unitSurchargeFee),
390
+ surcharge_rounding_remainder: toFixed2(roundingRemainder),
391
+ relation_surcharge_ids: surchargeIds
392
+ });
393
+ }
394
+ function calculateBackendProductSurcharges(params) {
395
+ var products = params.products,
396
+ sourceItems = params.sourceItems,
397
+ surchargeList = params.surchargeList;
398
+ resetProductSurchargeFields(products);
399
+ var configById = getSurchargeConfigById(surchargeList);
400
+ var nodes = createSurchargeAllocationNodes(products, sourceItems);
401
+ var fallbackAllProductSurchargeIds = getFallbackAllProductSurchargeIds(surchargeList);
402
+ var _iterator7 = _createForOfIteratorHelper(nodes),
403
+ _step7;
404
+ try {
405
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
406
+ var node = _step7.value;
407
+ if (node.relationSurchargeIds.length === 0) {
408
+ node.relationSurchargeIds = fallbackAllProductSurchargeIds;
409
+ }
410
+ }
411
+ } catch (err) {
412
+ _iterator7.e(err);
413
+ } finally {
414
+ _iterator7.f();
415
+ }
416
+ var persistedSurchargeIds = getPersistedSurchargeIds(nodes);
417
+ var quantityTotals = buildSurchargeQuantityTotals(nodes);
418
+ var stateMap = new Map();
419
+ var _iterator8 = _createForOfIteratorHelper(nodes),
420
+ _step8;
421
+ try {
422
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
423
+ var _node = _step8.value;
424
+ var unitSurchargeFee = new Decimal(0);
425
+ var roundingRemainder = new Decimal(0);
426
+ var appliedSurchargeIds = [];
427
+ var persistedRemainderApplied = false;
428
+ var _iterator10 = _createForOfIteratorHelper(_node.relationSurchargeIds),
429
+ _step10;
430
+ try {
431
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
432
+ var surchargeId = _step10.value;
433
+ var config = configById.get(surchargeId);
434
+ var totalQuantity = quantityTotals.get(surchargeId) || new Decimal(0);
435
+ if (totalQuantity.lte(0)) continue;
436
+ var persistedUnitSurchargeFee = _node.persistedUnitSurchargeFee;
437
+ if (persistedUnitSurchargeFee && persistedUnitSurchargeFee.gt(0)) {
438
+ var persistedQuantity = Decimal.min(_node.persistedQuantity, _node.quantity);
439
+ var deltaQuantity = Decimal.max(_node.quantity.minus(persistedQuantity), 0);
440
+ var _state = getBackendSurchargeState(stateMap, surchargeId, config || {
441
+ surcharge_id: surchargeId
442
+ });
443
+ var persistedSurchargeRemainder = !persistedRemainderApplied && _node.persistedSurchargeRemainder ? _node.persistedSurchargeRemainder : new Decimal(0);
444
+ _state.amount = bcAdd(bcAdd(_state.amount, bcMul(persistedUnitSurchargeFee, persistedQuantity, 2), 2), persistedSurchargeRemainder, 2);
445
+ var _fixed = new Decimal((config === null || config === void 0 ? void 0 : config.fixed) || 0);
446
+ if (_fixed.gt(0)) _state.fixedIncluded = true;
447
+ var nodeTotalSurcharge = bcAdd(bcMul(persistedUnitSurchargeFee, persistedQuantity, 2), persistedSurchargeRemainder, 2);
448
+ if (config && deltaQuantity.gt(0)) {
449
+ var _percentage = new Decimal(config.percentage || 0);
450
+ var deltaUnitPercentageFee = Decimal.max(0, bcMul(_node.unitAmount, _percentage, 2));
451
+ var deltaSurcharge = bcMul(deltaQuantity, deltaUnitPercentageFee, 2);
452
+ _state.amount = bcAdd(_state.amount, deltaSurcharge, 2);
453
+ nodeTotalSurcharge = bcAdd(nodeTotalSurcharge, deltaSurcharge, 2);
454
+ }
455
+ if (_node.quantity.gt(0)) {
456
+ unitSurchargeFee = bcAdd(unitSurchargeFee, bcDiv(nodeTotalSurcharge, _node.quantity, 2), 2);
457
+ }
458
+ if (!persistedSurchargeRemainder.eq(0)) {
459
+ roundingRemainder = bcAdd(roundingRemainder, persistedSurchargeRemainder, 2);
460
+ persistedRemainderApplied = true;
461
+ }
462
+ appliedSurchargeIds.push(surchargeId);
463
+ continue;
464
+ }
465
+ if (!config) continue;
466
+ var percentage = new Decimal(config.percentage || 0);
467
+ var fixed = new Decimal(config.fixed || 0);
468
+ var unitPercentageFee = Decimal.max(0, bcMul(_node.unitAmount, percentage, 2));
469
+ var percentageTotalFee = bcMul(_node.quantity, unitPercentageFee, 2);
470
+ var unitFixedFee = new Decimal(0);
471
+ var fixedRemainder = new Decimal(0);
472
+ if (fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
473
+ unitFixedFee = bcDiv(fixed, totalQuantity, 2);
474
+ var distributedFixed = bcMul(unitFixedFee, totalQuantity, 2);
475
+ fixedRemainder = bcSub(fixed, distributedFixed, 2);
476
+ }
477
+ var currentUnitSurcharge = Decimal.max(0, bcAdd(unitPercentageFee, unitFixedFee, 2));
478
+ if (currentUnitSurcharge.lte(0)) continue;
479
+ var state = getBackendSurchargeState(stateMap, surchargeId, config);
480
+ state.amount = bcAdd(state.amount, percentageTotalFee, 2);
481
+ var precisePercentage = Decimal.max(0, bcMul(_node.unitAmount, percentage, 6));
482
+ var offsetBaseFee = Decimal.max(0, bcSub(precisePercentage, unitPercentageFee, 6));
483
+ state.totalOffsetFee = bcAdd(state.totalOffsetFee, bcMul(offsetBaseFee, _node.quantity, 6), 6);
484
+ state.calculatedQuantity = bcAdd(state.calculatedQuantity, _node.quantity, 6);
485
+ if (!state.fixedIncluded && fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
486
+ state.amount = bcAdd(state.amount, fixed, 2);
487
+ state.fixedIncluded = true;
488
+ }
489
+ if (!state.fixedRemainderAssigned && !fixedRemainder.eq(0)) {
490
+ state.fixedRemainderAssigned = true;
491
+ roundingRemainder = bcAdd(roundingRemainder, fixedRemainder, 2);
492
+ }
493
+ if (state.calculatedQuantity.gte(totalQuantity) && state.totalOffsetFee.gt(0)) {
494
+ var totalOffsetFee = toAmountFormat(state.totalOffsetFee);
495
+ state.amount = bcAdd(state.amount, totalOffsetFee, 2);
496
+ roundingRemainder = bcAdd(roundingRemainder, totalOffsetFee, 2);
497
+ state.totalOffsetFee = new Decimal(0);
498
+ }
499
+ unitSurchargeFee = bcAdd(unitSurchargeFee, currentUnitSurcharge, 2);
500
+ appliedSurchargeIds.push(surchargeId);
501
+ }
502
+ } catch (err) {
503
+ _iterator10.e(err);
504
+ } finally {
505
+ _iterator10.f();
506
+ }
507
+ applySurchargeNodeResult(_node, {
508
+ unitSurchargeFee: unitSurchargeFee,
509
+ roundingRemainder: roundingRemainder,
510
+ surchargeIds: appliedSurchargeIds
511
+ });
512
+ }
513
+ } catch (err) {
514
+ _iterator8.e(err);
515
+ } finally {
516
+ _iterator8.f();
517
+ }
518
+ var result = (surchargeList || []).reduce(function (items, config, index) {
519
+ var surchargeId = getSurchargeConfigId(config);
520
+ if (surchargeId === undefined) return items;
521
+ var state = stateMap.get(surchargeId);
522
+ if (!state || state.amount.lte(0)) return items;
523
+ items.push(buildSurchargeResultItem(config, surchargeId, state.amount, index));
524
+ return items;
525
+ }, []);
526
+ var includedIds = new Set(result.map(function (item) {
527
+ return item === null || item === void 0 ? void 0 : item.surcharge_id;
528
+ }).filter(function (id) {
529
+ return id !== undefined;
530
+ }));
531
+ var _iterator9 = _createForOfIteratorHelper(stateMap.entries()),
532
+ _step9;
533
+ try {
534
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
535
+ var _step9$value = _slicedToArray(_step9.value, 2),
536
+ _surchargeId = _step9$value[0],
537
+ _state2 = _step9$value[1];
538
+ if (includedIds.has(_surchargeId) || _state2.amount.lte(0)) continue;
539
+ result.push(buildSurchargeResultItem(_state2.config, _surchargeId, _state2.amount, result.length));
540
+ }
541
+ } catch (err) {
542
+ _iterator9.e(err);
543
+ } finally {
544
+ _iterator9.f();
545
+ }
546
+ return result;
547
+ }
80
548
  function getProductDepositData(product) {
81
549
  var _product$_origin, _product$_origin2;
82
550
  var rootDepositData = (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.custom_deposit_data;
@@ -111,11 +579,11 @@ function calculateProductsDeposit(products) {
111
579
  var hasDeposit = false;
112
580
  var policyIds = new Set();
113
581
  var policyDataMap = new Map();
114
- var _iterator = _createForOfIteratorHelper(products),
115
- _step;
582
+ var _iterator11 = _createForOfIteratorHelper(products),
583
+ _step11;
116
584
  try {
117
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
118
- var product = _step.value;
585
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
586
+ var product = _step11.value;
119
587
  var depositData = getProductDepositData(product);
120
588
  if (!depositData || depositData.has_deposit != 1) continue;
121
589
  var num = getSafeNum(product.num);
@@ -128,45 +596,45 @@ function calculateProductsDeposit(products) {
128
596
  var itemDeposit = fixed.plus(percentage.times(productTotal));
129
597
  totalDeposit = totalDeposit.plus(itemDeposit);
130
598
  hasDeposit = true;
131
- var _iterator3 = _createForOfIteratorHelper(collectDepositPolicyIds(depositData)),
132
- _step3;
599
+ var _iterator13 = _createForOfIteratorHelper(collectDepositPolicyIds(depositData)),
600
+ _step13;
133
601
  try {
134
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
135
- var id = _step3.value;
602
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
603
+ var id = _step13.value;
136
604
  policyIds.add(id);
137
605
  }
138
606
  } catch (err) {
139
- _iterator3.e(err);
607
+ _iterator13.e(err);
140
608
  } finally {
141
- _iterator3.f();
609
+ _iterator13.f();
142
610
  }
143
- var _iterator4 = _createForOfIteratorHelper(collectDepositPolicyData(depositData)),
144
- _step4;
611
+ var _iterator14 = _createForOfIteratorHelper(collectDepositPolicyData(depositData)),
612
+ _step14;
145
613
  try {
146
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
147
- var policy = _step4.value;
614
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
615
+ var policy = _step14.value;
148
616
  if (!policyDataMap.has(policy.id)) {
149
617
  policyDataMap.set(policy.id, policy);
150
618
  }
151
619
  policyIds.add(policy.id);
152
620
  }
153
621
  } catch (err) {
154
- _iterator4.e(err);
622
+ _iterator14.e(err);
155
623
  } finally {
156
- _iterator4.f();
624
+ _iterator14.f();
157
625
  }
158
626
  }
159
627
  } catch (err) {
160
- _iterator.e(err);
628
+ _iterator11.e(err);
161
629
  } finally {
162
- _iterator.f();
630
+ _iterator11.f();
163
631
  }
164
632
  if (!hasDeposit) return undefined;
165
- var _iterator2 = _createForOfIteratorHelper(policyIds),
166
- _step2;
633
+ var _iterator12 = _createForOfIteratorHelper(policyIds),
634
+ _step12;
167
635
  try {
168
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
169
- var _id = _step2.value;
636
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
637
+ var _id = _step12.value;
170
638
  if (!policyDataMap.has(_id)) {
171
639
  policyDataMap.set(_id, {
172
640
  id: _id,
@@ -175,9 +643,9 @@ function calculateProductsDeposit(products) {
175
643
  }
176
644
  }
177
645
  } catch (err) {
178
- _iterator2.e(err);
646
+ _iterator12.e(err);
179
647
  } finally {
180
- _iterator2.f();
648
+ _iterator12.f();
181
649
  }
182
650
  return {
183
651
  total: totalDeposit.toFixed(2),
@@ -218,58 +686,202 @@ function calculateSingleItemTax(params) {
218
686
  }
219
687
 
220
688
  /**
221
- * 获取主商品折扣后总价(含 option、含主商品折扣、含加价/减价 bundle)。
689
+ * 主商品 + 非原价(加价/减价)子商品的"折扣后"售价合计(含 option、含主商品折扣,未减整单折扣)。
222
690
  *
223
- * 新语义 v2 下:
224
- * - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价,直接读即可;
225
- * - 无需再 `minus(mainDiscountAmount)` 或 `plus(getOptionUnitPrice)`;
226
- * - 仅需叠加 `markup` / `markdown` 类 bundle(原价 bundle 已由 `calculateProductsTax` 独立处理)。
691
+ * 对齐后端 metadata.main_product_attached_bundle_selling_price:
692
+ * - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价;
693
+ * - 叠加 `markup` / `markdown` 类 bundle(原价 bundle 由 `calculateProductsTax` 独立处理)。
227
694
  */
228
- function getMainProductPaymentTotal(product) {
229
- var _ref2, _product$metadata$mai, _product$metadata7, _product$metadata8;
230
- var mainSelling = (_ref2 = (_product$metadata$mai = (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_selling_price) !== null && _product$metadata$mai !== void 0 ? _product$metadata$mai : (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.main_product_original_price) !== null && _ref2 !== void 0 ? _ref2 : 0;
695
+ function getMainAttachedBundleSellingTotal(product) {
696
+ var _ref8, _product$metadata$mai, _product$metadata8, _product$metadata9;
697
+ var mainSelling = (_ref8 = (_product$metadata$mai = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.main_product_selling_price) !== null && _product$metadata$mai !== void 0 ? _product$metadata$mai : (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.main_product_original_price) !== null && _ref8 !== void 0 ? _ref8 : 0;
231
698
  var total = toDecimal(mainSelling);
232
699
  var bundleItems = product.product_bundle || [];
233
- var _iterator5 = _createForOfIteratorHelper(bundleItems),
234
- _step5;
700
+ var _iterator15 = _createForOfIteratorHelper(bundleItems),
701
+ _step15;
235
702
  try {
236
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
237
- var bundleItem = _step5.value;
703
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
704
+ var bundleItem = _step15.value;
238
705
  if (isBundleMarkupOrDiscount(bundleItem)) {
239
- var _ref3, _bundleItem$bundle_se, _bundleItem$num;
240
- var unit = toDecimal((_ref3 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref3 !== void 0 ? _ref3 : 0);
706
+ var _bundleItem$num;
707
+ // markdown(减价)按带符号净额取减;markup 维持相加。
708
+ var unit = getBundleSignedUnit(bundleItem);
241
709
  var qty = getSafeNum((_bundleItem$num = bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem.quantity);
242
710
  total = total.plus(unit.times(qty));
243
711
  }
244
712
  }
245
713
  } catch (err) {
246
- _iterator5.e(err);
714
+ _iterator15.e(err);
247
715
  } finally {
248
- _iterator5.f();
716
+ _iterator15.f();
249
717
  }
250
718
  return Decimal.max(total, 0);
251
719
  }
252
720
 
721
+ /**
722
+ * 获取主商品税费基数(含 option、含主商品折扣、含加价/减价 bundle、已减整单折扣均摊)。
723
+ *
724
+ * 对齐后端 handleMainProductTaxFee:税基使用 main_product_attached_bundle_payment_price。
725
+ * - 优先读取均摊层写入的 payment 价;
726
+ * - 兜底退化为 selling 合计(无整单折扣时两者相等)。
727
+ */
728
+ function getMainProductPaymentTotal(product) {
729
+ var _product$metadata10;
730
+ var attachedPayment = (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.main_product_attached_bundle_payment_price;
731
+ if (attachedPayment !== undefined && attachedPayment !== null && attachedPayment !== '') {
732
+ return Decimal.max(toDecimal(attachedPayment), 0);
733
+ }
734
+ return getMainAttachedBundleSellingTotal(product);
735
+ }
736
+ function getExplicitTaxRemainder(item) {
737
+ var _item$tax_fee_roundin, _item$metadata3;
738
+ var value = (_item$tax_fee_roundin = item === null || item === void 0 ? void 0 : item.tax_fee_rounding_remainder) !== null && _item$tax_fee_roundin !== void 0 ? _item$tax_fee_roundin : item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.tax_fee_rounding_remainder;
739
+ if (value === undefined || value === null || value === '') return null;
740
+ return new Decimal(value || 0);
741
+ }
742
+ function getPersistedTaxRemainder(item, parentProduct) {
743
+ var isPersistedLine = (item === null || item === void 0 ? void 0 : item.order_detail_id) !== undefined && (item === null || item === void 0 ? void 0 : item.order_detail_id) !== null || (parentProduct === null || parentProduct === void 0 ? void 0 : parentProduct.order_detail_id) !== undefined && (parentProduct === null || parentProduct === void 0 ? void 0 : parentProduct.order_detail_id) !== null;
744
+ if (!isPersistedLine) return null;
745
+ return getExplicitTaxRemainder(item);
746
+ }
747
+ function getPersistedMainTaxFee(product) {
748
+ var _ref9, _product$metadata$mai2, _product$metadata11;
749
+ if ((product === null || product === void 0 ? void 0 : product.order_detail_id) === undefined || (product === null || product === void 0 ? void 0 : product.order_detail_id) === null) return null;
750
+ var value = (_ref9 = (_product$metadata$mai2 = product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.main_product_attached_bundle_tax_fee) !== null && _product$metadata$mai2 !== void 0 ? _product$metadata$mai2 : product === null || product === void 0 ? void 0 : product.main_product_attached_bundle_tax_fee) !== null && _ref9 !== void 0 ? _ref9 : product === null || product === void 0 ? void 0 : product.tax_fee;
751
+ if (value === undefined || value === null || value === '') return null;
752
+ return toDecimal(value);
753
+ }
754
+ function writeTaxRemainder(item, roundingRemainder) {
755
+ item.tax_fee_rounding_remainder = roundingRemainder.toNumber();
756
+ if (item.metadata && _typeof(item.metadata) === 'object') {
757
+ item.metadata.tax_fee_rounding_remainder = roundingRemainder.toFixed(2);
758
+ }
759
+ }
760
+ function resetTaxRemainderFields(products) {
761
+ for (var _i2 = 0, _arr2 = products; _i2 < _arr2.length; _i2++) {
762
+ var product = _arr2[_i2];
763
+ var productRemainder = getPersistedTaxRemainder(product);
764
+ if (productRemainder !== null) {
765
+ product.tax_fee_rounding_remainder = productRemainder.toNumber();
766
+ } else {
767
+ delete product.tax_fee_rounding_remainder;
768
+ }
769
+ product.original_tax_fee_rounding_remainder = 0;
770
+ var _iterator16 = _createForOfIteratorHelper(product.product_bundle || []),
771
+ _step16;
772
+ try {
773
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
774
+ var bundle = _step16.value;
775
+ var bundleRemainder = getPersistedTaxRemainder(bundle, product);
776
+ bundle.metadata = _objectSpread({}, bundle.metadata || {});
777
+ if (bundleRemainder !== null) {
778
+ bundle.metadata.tax_fee_rounding_remainder = bundleRemainder.toFixed(2);
779
+ bundle.tax_fee_rounding_remainder = bundleRemainder.toNumber();
780
+ } else {
781
+ delete bundle.metadata.tax_fee_rounding_remainder;
782
+ delete bundle.tax_fee_rounding_remainder;
783
+ }
784
+ bundle.original_tax_fee_rounding_remainder = 0;
785
+ }
786
+ } catch (err) {
787
+ _iterator16.e(err);
788
+ } finally {
789
+ _iterator16.f();
790
+ }
791
+ }
792
+ }
793
+ function getBundlePaymentPrice(bundle, product) {
794
+ var _ref10, _ref11, _bundle$bundle_sellin2, _metadata$average_dis, _metadata;
795
+ if ((bundle === null || bundle === void 0 ? void 0 : bundle.bundle_payment_price) !== undefined) return toDecimal(bundle.bundle_payment_price);
796
+ var basePrice = toDecimal((_ref10 = (_ref11 = (_bundle$bundle_sellin2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price) !== null && _bundle$bundle_sellin2 !== void 0 ? _bundle$bundle_sellin2 : bundle === null || bundle === void 0 ? void 0 : bundle.bundle_sum_price) !== null && _ref11 !== void 0 ? _ref11 : bundle === null || bundle === void 0 ? void 0 : bundle.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
797
+ if (!isBundleOriginalPrice(bundle)) return basePrice;
798
+ var averageDiscountRate = toDecimal((_metadata$average_dis = (_metadata = product.metadata) === null || _metadata === void 0 ? void 0 : _metadata.average_discount_amount_rate) !== null && _metadata$average_dis !== void 0 ? _metadata$average_dis : 1);
799
+ return toAmountFormat(bcMul(basePrice, averageDiscountRate, 6));
800
+ }
801
+ function applyBackendTaxRemainder(params) {
802
+ var target = params.target,
803
+ rawTax = params.rawTax,
804
+ formattedTax = params.formattedTax,
805
+ quantity = params.quantity,
806
+ state = params.state;
807
+ var taxFeeDifference = bcMul(bcSub(rawTax, formattedTax, 6), quantity, 6);
808
+ state.difference = bcAdd(state.difference, taxFeeDifference, 6);
809
+ if (state.difference.lt(0.005)) return new Decimal(0);
810
+ var roundingRemainder = toAmountFormat(state.difference);
811
+ writeTaxRemainder(target, roundingRemainder);
812
+ state.difference = bcSub(state.difference, roundingRemainder, 6);
813
+ return roundingRemainder;
814
+ }
815
+
253
816
  /**
254
817
  * 遍历所有商品计算税费,回写 tax_fee 到每个商品及 bundle 原价子商品,处理舍入差值。
255
818
  * 参照 Summary/utils.ts 的 processItemsTax,适配 SalesSummaryProduct 结构。
256
819
  */
257
820
  function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
258
821
  var rate = new Decimal(taxRate);
259
- var preciseTax = new Decimal(0);
260
- var roundedTax = new Decimal(0);
261
- var preciseOriginTax = new Decimal(0);
262
- var roundedOriginTax = new Decimal(0);
263
- var lastTaxableItem = null;
264
- var _iterator6 = _createForOfIteratorHelper(products),
265
- _step6;
822
+ var taxRemainderState = {
823
+ difference: new Decimal(0)
824
+ };
825
+ var totalTax = new Decimal(0);
826
+ var totalOriginTax = new Decimal(0);
827
+ resetTaxRemainderFields(products);
828
+ var _iterator17 = _createForOfIteratorHelper(products),
829
+ _step17;
266
830
  try {
267
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
831
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
268
832
  var _product$is_charge_ta2, _product$is_charge_ta3;
269
- var product = _step6.value;
833
+ var product = _step17.value;
270
834
  var quantity = new Decimal(getSafeNum(product.num));
271
-
272
- // --- 主商品折后税费 ---
835
+ var productUnitTax = new Decimal(0);
836
+ var productUnitOriginTax = new Decimal(0);
837
+ var bundleItems = product.product_bundle || [];
838
+ var _iterator18 = _createForOfIteratorHelper(bundleItems),
839
+ _step18;
840
+ try {
841
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
842
+ var _bundleItem$num2, _ref12, _ref13, _bundleItem$original_, _ref14, _bundleItem$is_charge, _ref15, _bundleItem$is_charge2;
843
+ var bundleItem = _step18.value;
844
+ if (!isBundleOriginalPrice(bundleItem)) continue;
845
+ var bundleQuantity = new Decimal(getSafeNum((_bundleItem$num2 = bundleItem.num) !== null && _bundleItem$num2 !== void 0 ? _bundleItem$num2 : bundleItem.quantity));
846
+ var totalBundleQuantity = bundleQuantity.times(quantity);
847
+ var bundlePrice = getBundlePaymentPrice(bundleItem, product);
848
+ var bundleOriginalPrice = toDecimal((_ref12 = (_ref13 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref13 !== void 0 ? _ref13 : bundleItem.price) !== null && _ref12 !== void 0 ? _ref12 : 0);
849
+ var bundleSurchargeFee = toDecimal(bundleItem.surcharge_fee);
850
+ var bundleTaxPrecise = calculateSingleItemTax({
851
+ price: bundlePrice.plus(bundleSurchargeFee),
852
+ taxRate: rate,
853
+ isPriceIncludeTax: isPriceIncludeTax,
854
+ isChargeTax: (_ref14 = (_bundleItem$is_charge = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge !== void 0 ? _bundleItem$is_charge : product.is_charge_tax) !== null && _ref14 !== void 0 ? _ref14 : 0
855
+ });
856
+ var bundleTaxRounded = toBackendTaxFee(bundleTaxPrecise);
857
+ bundleItem.tax_fee = bundleTaxRounded.toNumber();
858
+ var persistedBundleRemainder = getPersistedTaxRemainder(bundleItem, product);
859
+ var bundleRemainder = persistedBundleRemainder !== null && persistedBundleRemainder !== void 0 ? persistedBundleRemainder : applyBackendTaxRemainder({
860
+ target: bundleItem,
861
+ rawTax: bundleTaxPrecise,
862
+ formattedTax: bundleTaxRounded,
863
+ quantity: totalBundleQuantity,
864
+ state: taxRemainderState
865
+ });
866
+ if (persistedBundleRemainder) writeTaxRemainder(bundleItem, persistedBundleRemainder);
867
+ var bundleOrigTaxPrecise = calculateSingleItemTax({
868
+ price: bundleOriginalPrice.plus(bundleSurchargeFee),
869
+ taxRate: rate,
870
+ isPriceIncludeTax: isPriceIncludeTax,
871
+ isChargeTax: (_ref15 = (_bundleItem$is_charge2 = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge2 !== void 0 ? _bundleItem$is_charge2 : product.is_charge_tax) !== null && _ref15 !== void 0 ? _ref15 : 0
872
+ });
873
+ var bundleOrigTaxRounded = toAmountFormat(bundleOrigTaxPrecise);
874
+ bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
875
+ productUnitTax = productUnitTax.plus(bundleTaxRounded.times(bundleQuantity));
876
+ productUnitOriginTax = productUnitOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
877
+ totalTax = totalTax.plus(bundleTaxRounded.times(totalBundleQuantity)).plus(bundleRemainder);
878
+ totalOriginTax = totalOriginTax.plus(bundleOrigTaxRounded.times(totalBundleQuantity));
879
+ }
880
+ } catch (err) {
881
+ _iterator18.e(err);
882
+ } finally {
883
+ _iterator18.f();
884
+ }
273
885
  var mainTotal = getMainProductPaymentTotal(product);
274
886
  var surchargeRoundingRemainder = toDecimal(product.surcharge_rounding_remainder);
275
887
  var surchargeFee = toDecimal(product.surcharge_fee).plus(quantity.gt(0) ? surchargeRoundingRemainder.div(quantity) : 0);
@@ -280,15 +892,23 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
280
892
  isPriceIncludeTax: isPriceIncludeTax,
281
893
  isChargeTax: (_product$is_charge_ta2 = product.is_charge_tax) !== null && _product$is_charge_ta2 !== void 0 ? _product$is_charge_ta2 : 0
282
894
  });
283
- var mainTaxRounded = mainTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
284
- if (mainTaxPrecise.gt(0)) {
285
- lastTaxableItem = {
286
- type: 'main',
287
- item: product
288
- };
895
+ var mainTaxRounded = toBackendTaxFee(mainTaxPrecise);
896
+ var persistedMainRemainder = getPersistedTaxRemainder(product);
897
+ var persistedMainTaxFee = getPersistedMainTaxFee(product);
898
+ var persistedQuantity = getPersistedQuantity(product, quantity);
899
+ var deltaQuantity = Decimal.max(quantity.minus(persistedQuantity), 0);
900
+ var shouldUsePersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gte(quantity);
901
+ var shouldSplitPersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gt(0) && deltaQuantity.gt(0);
902
+ var mainRemainder = shouldUsePersistedMainTax || shouldSplitPersistedMainTax ? new Decimal(0) : persistedMainRemainder !== null && persistedMainRemainder !== void 0 ? persistedMainRemainder : applyBackendTaxRemainder({
903
+ target: product,
904
+ rawTax: mainTaxPrecise,
905
+ formattedTax: mainTaxRounded,
906
+ quantity: quantity,
907
+ state: taxRemainderState
908
+ });
909
+ if (persistedMainRemainder && !shouldSplitPersistedMainTax) {
910
+ writeTaxRemainder(product, persistedMainRemainder);
289
911
  }
290
-
291
- // --- 主商品原价税费 ---
292
912
  var originalTotal = getUnitOriginalTotal(product);
293
913
  var originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
294
914
  var originalTaxPrecise = calculateSingleItemTax({
@@ -297,92 +917,91 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
297
917
  isPriceIncludeTax: isPriceIncludeTax,
298
918
  isChargeTax: (_product$is_charge_ta3 = product.is_charge_tax) !== null && _product$is_charge_ta3 !== void 0 ? _product$is_charge_ta3 : 0
299
919
  });
300
-
301
- // --- bundle 原价子商品独立计税 ---
302
- var bundlePreciseTax = new Decimal(0);
303
- var bundleRoundedTax = new Decimal(0);
304
- var bundlePreciseOriginTax = new Decimal(0);
305
- var bundleRoundedOriginTax = new Decimal(0);
306
- var bundleItems = product.product_bundle || [];
307
- var _iterator7 = _createForOfIteratorHelper(bundleItems),
308
- _step7;
309
- try {
310
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
311
- var _bundleItem$num2, _ref4, _bundleItem$bundle_se2, _ref5, _ref6, _bundleItem$original_, _ref7, _bundleItem$is_charge, _ref8, _bundleItem$is_charge2;
312
- var bundleItem = _step7.value;
313
- if (!isBundleOriginalPrice(bundleItem)) continue;
314
- var bundleQuantity = new Decimal(getSafeNum((_bundleItem$num2 = bundleItem.num) !== null && _bundleItem$num2 !== void 0 ? _bundleItem$num2 : bundleItem.quantity));
315
- var bundlePrice = toDecimal((_ref4 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref4 !== void 0 ? _ref4 : 0);
316
- var bundleOriginalPrice = toDecimal((_ref5 = (_ref6 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref6 !== void 0 ? _ref6 : bundleItem.price) !== null && _ref5 !== void 0 ? _ref5 : 0);
317
- var bundleTaxPrecise = calculateSingleItemTax({
318
- price: bundlePrice,
319
- taxRate: rate,
320
- isPriceIncludeTax: isPriceIncludeTax,
321
- isChargeTax: (_ref7 = (_bundleItem$is_charge = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge !== void 0 ? _bundleItem$is_charge : product.is_charge_tax) !== null && _ref7 !== void 0 ? _ref7 : 0
322
- });
323
- var bundleTaxRounded = bundleTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
324
- var bundleOrigTaxPrecise = calculateSingleItemTax({
325
- price: bundleOriginalPrice,
326
- taxRate: rate,
327
- isPriceIncludeTax: isPriceIncludeTax,
328
- isChargeTax: (_ref8 = (_bundleItem$is_charge2 = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge2 !== void 0 ? _bundleItem$is_charge2 : product.is_charge_tax) !== null && _ref8 !== void 0 ? _ref8 : 0
329
- });
330
- var bundleOrigTaxRounded = bundleOrigTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
331
- bundleItem.tax_fee = bundleTaxRounded.toNumber();
332
- bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
333
- bundlePreciseTax = bundlePreciseTax.plus(bundleTaxPrecise.times(bundleQuantity));
334
- bundleRoundedTax = bundleRoundedTax.plus(bundleTaxRounded.times(bundleQuantity));
335
- bundlePreciseOriginTax = bundlePreciseOriginTax.plus(bundleOrigTaxPrecise.times(bundleQuantity));
336
- bundleRoundedOriginTax = bundleRoundedOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
337
- if (bundleTaxPrecise.gt(0)) {
338
- lastTaxableItem = {
339
- type: 'bundle',
340
- item: bundleItem
341
- };
342
- }
343
- }
344
-
345
- // --- 汇总到商品级 ---
346
- } catch (err) {
347
- _iterator7.e(err);
348
- } finally {
349
- _iterator7.f();
920
+ var originalTaxRounded = toAmountFormat(originalTaxPrecise);
921
+ var effectiveMainUnitTax = shouldUsePersistedMainTax ? persistedMainTaxFee : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)).div(quantity).toDecimalPlaces(2, Decimal.ROUND_HALF_UP) : mainTaxRounded;
922
+ productUnitTax = productUnitTax.plus(effectiveMainUnitTax);
923
+ productUnitOriginTax = productUnitOriginTax.plus(originalTaxRounded);
924
+ product.main_product_attached_bundle_tax_fee = effectiveMainUnitTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
925
+ product.tax_fee = productUnitTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
926
+ product.original_tax_fee = productUnitOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
927
+ totalTax = totalTax.plus(shouldUsePersistedMainTax ? persistedMainTaxFee.times(quantity).plus(persistedMainRemainder || 0) : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)) : mainTaxRounded.times(quantity).plus(mainRemainder));
928
+ totalOriginTax = totalOriginTax.plus(originalTaxRounded.times(quantity));
929
+ if (product.tax_fee_rounding_remainder === undefined) {
930
+ product.tax_fee_rounding_remainder = 0;
350
931
  }
351
- var itemTaxPrecise = mainTaxPrecise.plus(bundlePreciseTax);
352
- var itemTaxRounded = mainTaxRounded.plus(bundleRoundedTax);
353
- var itemOriginTaxPrecise = originalTaxPrecise.plus(bundlePreciseOriginTax);
354
- var itemOriginTaxRounded = originalTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).plus(bundleRoundedOriginTax);
355
- product.tax_fee = itemTaxRounded.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
356
- product.original_tax_fee = itemOriginTaxRounded.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
357
- preciseTax = preciseTax.plus(itemTaxPrecise.times(quantity));
358
- roundedTax = roundedTax.plus(itemTaxRounded.times(quantity));
359
- preciseOriginTax = preciseOriginTax.plus(itemOriginTaxPrecise.times(quantity));
360
- roundedOriginTax = roundedOriginTax.plus(itemOriginTaxRounded.times(quantity));
361
932
  }
362
-
363
- // --- 舍入差值处理 ---
364
933
  } catch (err) {
365
- _iterator6.e(err);
934
+ _iterator17.e(err);
366
935
  } finally {
367
- _iterator6.f();
368
- }
369
- var expectedTax = preciseTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
370
- var expectedOriginTax = preciseOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
371
- var taxRemainder = expectedTax.minus(roundedTax).toNumber();
372
- var originTaxRemainder = expectedOriginTax.minus(roundedOriginTax).toNumber();
373
- if (lastTaxableItem) {
374
- if (taxRemainder !== 0) {
375
- lastTaxableItem.item.tax_fee_rounding_remainder = taxRemainder;
376
- }
377
- if (originTaxRemainder !== 0) {
378
- lastTaxableItem.item.original_tax_fee_rounding_remainder = originTaxRemainder;
379
- }
936
+ _iterator17.f();
380
937
  }
381
938
  return {
382
- tax: expectedTax,
383
- originTax: expectedOriginTax
939
+ tax: totalTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP),
940
+ originTax: totalOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP)
384
941
  };
385
942
  }
943
+
944
+ /**
945
+ * 整单折扣(shop_discount)按各行 selling 合计占比均摊到 payment 维度。
946
+ *
947
+ * 文档口径:
948
+ * - payment_price = selling_price − 整单折扣均摊;rate = payment/selling(全行同一 rate);
949
+ * - 附加费不受整单折扣影响(基数仍用 selling,本函数写 main_product_attached_bundle_selling_price);
950
+ * - 税费受整单折扣影响(基数用 payment,本函数写 main_product_attached_bundle_payment_price 与
951
+ * 原价子商品 bundle_payment_price)。
952
+ *
953
+ * 与后端一致:bundle_payment_price = bundle_selling_price × rate,
954
+ * main_product_attached_bundle_payment_price = main_product_attached_bundle_selling_price × rate。
955
+ */
956
+ function allocateShopDiscountToPayment(products, productAmount, shopDiscountAmount) {
957
+ var effectiveDiscount = productAmount.lte(0) ? new Decimal(0) : Decimal.max(Decimal.min(productAmount, shopDiscountAmount), 0);
958
+ var allocatedDiscount = new Decimal(0);
959
+ products.forEach(function (product, index) {
960
+ var quantity = new Decimal(getSafeNum(product.num));
961
+ var sellingUnit = getUnitPaymentTotal(product);
962
+ var lineSellingTotal = sellingUnit.times(quantity);
963
+ var lineDiscount = effectiveDiscount.lte(0) ? new Decimal(0) : index === products.length - 1 ? Decimal.max(effectiveDiscount.minus(allocatedDiscount), 0) : toAmountFormat(lineSellingTotal.div(productAmount).times(effectiveDiscount));
964
+ allocatedDiscount = allocatedDiscount.plus(lineDiscount);
965
+ var unitDiscount = quantity.lte(0) ? new Decimal(0) : lineDiscount.div(quantity);
966
+ var paymentUnit = Decimal.max(sellingUnit.minus(unitDiscount), 0);
967
+ var rate = sellingUnit.lte(0) ? new Decimal(1) : toBcScale(paymentUnit.div(sellingUnit), 6);
968
+ var mainSellingTotal = getMainAttachedBundleSellingTotal(product);
969
+ var mainPaymentTotal = toAmountFormat(bcMul(mainSellingTotal, rate, 6));
970
+ product.metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
971
+ average_discount_amount_rate: rate.toString(),
972
+ main_product_attached_bundle_selling_price: mainSellingTotal.toFixed(2),
973
+ main_product_attached_bundle_payment_price: mainPaymentTotal.toFixed(2)
974
+ });
975
+ var _iterator19 = _createForOfIteratorHelper(product.product_bundle || []),
976
+ _step19;
977
+ try {
978
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
979
+ var bundle = _step19.value;
980
+ // 原价子商品:bundle_payment_price = bundle_selling_price × rate
981
+ // markdown 子商品:以净额幅度 × rate(与后端一致,存正净额)
982
+ if (isBundleOriginalPrice(bundle)) {
983
+ var _ref16, _ref17, _bundle$bundle_sellin3;
984
+ var bundleSelling = toDecimal((_ref16 = (_ref17 = (_bundle$bundle_sellin3 = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin3 !== void 0 ? _bundle$bundle_sellin3 : bundle.bundle_sum_price) !== null && _ref17 !== void 0 ? _ref17 : bundle.price) !== null && _ref16 !== void 0 ? _ref16 : 0);
985
+ bundle.bundle_payment_price = toAmountFormat(bcMul(bundleSelling, rate, 6)).toFixed(2);
986
+ continue;
987
+ }
988
+ if (isMarkdownBundle(bundle)) {
989
+ var _bundle$custom_price;
990
+ var magnitude = getBundleSellingMagnitude(bundle);
991
+ bundle.custom_price = (_bundle$custom_price = bundle.custom_price) !== null && _bundle$custom_price !== void 0 ? _bundle$custom_price : bundle.price;
992
+ bundle.price = magnitude.toFixed(2);
993
+ bundle.bundle_selling_price = magnitude.toFixed(2);
994
+ bundle.bundle_payment_price = toAmountFormat(bcMul(magnitude, rate, 6)).toFixed(2);
995
+ }
996
+ }
997
+ } catch (err) {
998
+ _iterator19.e(err);
999
+ } finally {
1000
+ _iterator19.f();
1001
+ }
1002
+ product.payment_price = paymentUnit.toFixed(2);
1003
+ });
1004
+ }
386
1005
  export function createEmptySalesSummary() {
387
1006
  return {
388
1007
  product_quantity: 0,
@@ -399,6 +1018,9 @@ export function createEmptySalesSummary() {
399
1018
  deposit_amount: '0.00',
400
1019
  expect_amount: '0.00',
401
1020
  total_amount: '0.00',
1021
+ total_refund_amount: '0.00',
1022
+ customer_paid_amount: '0.00',
1023
+ order_paid_amount: '0.00',
402
1024
  amount_gap: '0.00',
403
1025
  rounding_amount: '0.00',
404
1026
  pay_service_charge_amount: '0.00'
@@ -411,19 +1033,34 @@ export function calculateSalesSummary(params) {
411
1033
  surchargeList = params.surchargeList,
412
1034
  _params$scheduleById = params.scheduleById,
413
1035
  scheduleById = _params$scheduleById === void 0 ? {} : _params$scheduleById,
414
- isInScheduleByDate = params.isInScheduleByDate;
1036
+ isInScheduleByDate = params.isInScheduleByDate,
1037
+ shopDiscount = params.shopDiscount;
415
1038
  if (!(products !== null && products !== void 0 && products.length)) return createEmptySalesSummary();
416
- var productQuantity = products.reduce(function (sum, item) {
1039
+ var summaryProducts = products.filter(function (product) {
1040
+ return !isGeneratedVoucherProduct(product);
1041
+ });
1042
+ if (!summaryProducts.length) return createEmptySalesSummary();
1043
+ var productQuantity = summaryProducts.reduce(function (sum, item) {
417
1044
  return sum + getSafeNum(item.num);
418
1045
  }, 0);
419
- var productOriginalAmount = products.reduce(function (sum, item) {
1046
+ var productOriginalAmount = summaryProducts.reduce(function (sum, item) {
420
1047
  return sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num)));
421
1048
  }, new Decimal(0));
422
- var productAmount = products.reduce(function (sum, item) {
1049
+ var productAmount = summaryProducts.reduce(function (sum, item) {
423
1050
  return sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num)));
424
1051
  }, new Decimal(0));
425
- var surchargeServiceItems = buildSurchargeServiceItems(products);
426
- var surcharge = getSurcharge({
1052
+ var shopDiscountAmount = Decimal.max(new Decimal(Number(shopDiscount) || 0), 0);
1053
+ var hasPersistedSurchargeSnapshot = summaryProducts.some(function (product) {
1054
+ var _getPersistedMainSurc;
1055
+ return (_getPersistedMainSurc = getPersistedMainSurchargeFee(product)) === null || _getPersistedMainSurc === void 0 ? void 0 : _getPersistedMainSurc.gt(0);
1056
+ });
1057
+ // 整单折扣均摊:附加费基数用 selling(不受折扣),税费基数用 payment(受折扣)。
1058
+ // persisted 快照(已下单编辑)优先采信后端回传值,不重算均摊。
1059
+ if (!hasPersistedSurchargeSnapshot) {
1060
+ allocateShopDiscountToPayment(summaryProducts, productAmount, shopDiscountAmount);
1061
+ }
1062
+ var surchargeServiceItems = buildSurchargeServiceItems(summaryProducts);
1063
+ getSurcharge({
427
1064
  service: surchargeServiceItems,
428
1065
  addons: [],
429
1066
  bookingDetail: null,
@@ -434,30 +1071,30 @@ export function calculateSalesSummary(params) {
434
1071
  surcharge_list: surchargeList,
435
1072
  scheduleById: scheduleById
436
1073
  });
1074
+ var surcharge = calculateBackendProductSurcharges({
1075
+ products: summaryProducts,
1076
+ sourceItems: surchargeServiceItems,
1077
+ surchargeList: surchargeList
1078
+ });
437
1079
  var surchargeAmount = new Decimal(getSurchargeAmount({
438
1080
  bookingDetail: null,
439
1081
  bookingId: undefined
440
1082
  }, surcharge, {
441
1083
  isEdit: false
442
1084
  }) || 0);
443
- for (var i = 0; i < products.length; i++) {
444
- var _surchargeServiceItem, _surchargeServiceItem2;
445
- products[i].surcharge_fee = ((_surchargeServiceItem = surchargeServiceItems[i]) === null || _surchargeServiceItem === void 0 ? void 0 : _surchargeServiceItem.surcharge_fee) || 0;
446
- products[i].surcharge_rounding_remainder = ((_surchargeServiceItem2 = surchargeServiceItems[i]) === null || _surchargeServiceItem2 === void 0 ? void 0 : _surchargeServiceItem2.surcharge_rounding_remainder) || 0;
447
- }
448
1085
  var hasTaxRate = taxRate !== undefined && taxRate !== null && taxRate > 0;
449
1086
  var productTaxFee;
450
1087
  if (hasTaxRate) {
451
- var taxResult = calculateProductsTax(products, taxRate, isPriceIncludeTax);
1088
+ var taxResult = calculateProductsTax(summaryProducts, taxRate, isPriceIncludeTax);
452
1089
  productTaxFee = taxResult.tax;
453
1090
  } else {
454
- productTaxFee = products.reduce(function (sum, item) {
1091
+ productTaxFee = summaryProducts.reduce(function (sum, item) {
455
1092
  return sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num)));
456
1093
  }, new Decimal(0));
457
1094
  }
458
- var expectAmount = productAmount.plus(surchargeAmount);
459
- var totalAmount = isPriceIncludeTax === 1 ? expectAmount : expectAmount.plus(productTaxFee);
460
- var deposit = calculateProductsDeposit(products);
1095
+ var orderAmountBeforeDiscount = productAmount.plus(surchargeAmount).plus(isPriceIncludeTax === 1 ? 0 : productTaxFee);
1096
+ var totalAmount = Decimal.max(0, orderAmountBeforeDiscount.minus(shopDiscountAmount));
1097
+ var deposit = calculateProductsDeposit(summaryProducts);
461
1098
  return {
462
1099
  product_quantity: productQuantity,
463
1100
  product_original_amount: toFixed2(productOriginalAmount),
@@ -469,11 +1106,14 @@ export function calculateSalesSummary(params) {
469
1106
  tax_fee: toFixed2(productTaxFee),
470
1107
  surcharge_fee: toFixed2(surchargeAmount),
471
1108
  surcharges: surcharge,
472
- discount_amount: toFixed2(Decimal.max(productOriginalAmount.minus(productAmount), 0)),
1109
+ discount_amount: toFixed2(shopDiscountAmount),
473
1110
  deposit_amount: deposit ? deposit.total : '0.00',
474
1111
  deposit: deposit,
475
- expect_amount: toFixed2(expectAmount),
1112
+ expect_amount: toFixed2(totalAmount),
476
1113
  total_amount: toFixed2(totalAmount),
1114
+ total_refund_amount: '0.00',
1115
+ customer_paid_amount: '0.00',
1116
+ order_paid_amount: '0.00',
477
1117
  amount_gap: '0.00',
478
1118
  rounding_amount: '0.00',
479
1119
  pay_service_charge_amount: '0.00',