@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
@@ -7,6 +7,7 @@ exports.calculateSalesSummary = calculateSalesSummary;
7
7
  exports.createEmptySalesSummary = createEmptySalesSummary;
8
8
  var _decimal = _interopRequireDefault(require("decimal.js"));
9
9
  var _utils = require("../Summary/utils");
10
+ var _utils2 = require("../Order/utils");
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  function toDecimal(value) {
12
13
  return new _decimal.default(value || 0);
@@ -14,6 +15,30 @@ function toDecimal(value) {
14
15
  function toFixed2(value) {
15
16
  return new _decimal.default(value || 0).toFixed(2);
16
17
  }
18
+ function toAmountFormat(value) {
19
+ return new _decimal.default(value || 0).toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
20
+ }
21
+ function toBackendTaxFee(value) {
22
+ return toBcScale(value, 2);
23
+ }
24
+ function toBcScale(value, scale) {
25
+ const factor = new _decimal.default(10).pow(scale);
26
+ return new _decimal.default(value || 0).times(factor).toDecimalPlaces(0, _decimal.default.ROUND_DOWN).div(factor);
27
+ }
28
+ function bcAdd(left, right, scale) {
29
+ return toBcScale(new _decimal.default(left || 0).plus(right || 0), scale);
30
+ }
31
+ function bcSub(left, right, scale) {
32
+ return toBcScale(new _decimal.default(left || 0).minus(right || 0), scale);
33
+ }
34
+ function bcMul(left, right, scale) {
35
+ return toBcScale(new _decimal.default(left || 0).times(right || 0), scale);
36
+ }
37
+ function bcDiv(left, right, scale) {
38
+ const divisor = new _decimal.default(right || 0);
39
+ if (divisor.eq(0)) return new _decimal.default(0);
40
+ return toBcScale(new _decimal.default(left || 0).div(divisor), scale);
41
+ }
17
42
  function getSafeNum(num) {
18
43
  if (!num || Number.isNaN(num)) return 1;
19
44
  if (num < 1) return 1;
@@ -23,8 +48,11 @@ function getBundleUnitPrice(product, useOriginal = false) {
23
48
  const bundleItems = product.product_bundle || [];
24
49
  return bundleItems.reduce((sum, item) => {
25
50
  const quantity = getSafeNum(item?.num);
26
- const price = useOriginal ? toDecimal(item?.original_price ?? item?.product_price ?? item?.price) : toDecimal(item?.bundle_selling_price ?? item?.price);
27
- return sum.plus(price.times(quantity));
51
+ // markdown(减价)按带符号净额取减;markup/原价维持相加。
52
+ const signedUnit = (0, _utils2.getBundleSignedUnit)(item, {
53
+ useOriginal
54
+ });
55
+ return sum.plus(signedUnit.times(quantity));
28
56
  }, new _decimal.default(0));
29
57
  }
30
58
 
@@ -44,10 +72,17 @@ function getUnitOriginalTotal(product) {
44
72
  const basePrice = mainOriginal !== undefined ? toDecimal(mainOriginal) : mainSelling !== undefined ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
45
73
  return basePrice.plus(getBundleUnitPrice(product, true));
46
74
  }
75
+ function isGeneratedVoucherProduct(product) {
76
+ const record = product;
77
+ const metadata = record?.metadata || {};
78
+ return record?.extension_type === 'product_voucher' || metadata.parent_order_detail_id !== undefined || metadata.gift_card_type !== undefined;
79
+ }
47
80
  function buildSurchargeServiceItems(products) {
48
81
  return products.map(product => {
49
82
  const quantity = getSafeNum(product.num);
50
83
  const unitTotal = getUnitPaymentTotal(product);
84
+ const options = (0, _utils2.getProductSkuOptions)(product);
85
+ const persistedSurchargeFee = getPersistedMainSurchargeFee(product);
51
86
  return {
52
87
  id: product.product_id,
53
88
  num: quantity,
@@ -59,19 +94,339 @@ function buildSurchargeServiceItems(products) {
59
94
  product: {
60
95
  discount_list: product.discount_list || [],
61
96
  product_bundle: product.product_bundle || [],
62
- product_option_item: product.product_option_item || []
97
+ product_sku: product.product_sku || {
98
+ option: options
99
+ }
63
100
  }
64
101
  },
65
102
  bundle: product.product_bundle || [],
66
- option: product.product_option_item || [],
67
- options: product.product_option_item || [],
103
+ option: options,
104
+ options,
68
105
  relation_details: [],
69
- metadata: product.metadata || {},
106
+ metadata: {
107
+ ...(product.metadata || {}),
108
+ __persisted_surcharge_fee: persistedSurchargeFee?.toFixed(2)
109
+ },
70
110
  start_date: product.metadata?.start_date || '',
71
111
  start_time: product.metadata?.start_time || ''
72
112
  };
73
113
  });
74
114
  }
115
+ function getRelationSurchargeIds(item) {
116
+ const ids = [...(Array.isArray(item?.relation_surcharge_ids) ? item.relation_surcharge_ids : []), ...(Array.isArray(item?.metadata?.relation_surcharge_ids) ? item.metadata.relation_surcharge_ids : [])];
117
+ return [...new Set(ids.filter(id => id !== undefined && id !== null && id !== ''))];
118
+ }
119
+ function getSurchargeConfigId(config) {
120
+ return config?.id ?? config?.surcharge_id;
121
+ }
122
+ function getSurchargeConfigById(surchargeList) {
123
+ const map = new Map();
124
+ for (const config of surchargeList || []) {
125
+ const id = getSurchargeConfigId(config);
126
+ if (id !== undefined) map.set(id, config);
127
+ }
128
+ return map;
129
+ }
130
+ function getMainSurchargeUnitAmount(product) {
131
+ const record = product;
132
+ return toDecimal(record.metadata?.main_product_attached_bundle_selling_price ?? record.metadata?.main_product_selling_price ?? record.selling_price ?? 0);
133
+ }
134
+ function getBundleSurchargeUnitAmount(bundle) {
135
+ return toDecimal(bundle?.bundle_selling_price ?? bundle?.bundle_sum_price ?? bundle?.price ?? 0);
136
+ }
137
+ function getBundleProductId(bundle) {
138
+ const id = bundle?.bundle_product_id ?? bundle?._bundle_product_id ?? bundle?.product_id;
139
+ if (id === undefined || id === null || id === '') return null;
140
+ const parsed = Number(id);
141
+ if (!Number.isFinite(parsed)) return null;
142
+ return parsed;
143
+ }
144
+ function getPersistedMainSurchargeFee(product) {
145
+ if (product?.order_detail_id === undefined || product?.order_detail_id === null) return null;
146
+ const value = product?.surcharge_fee ?? product?.main_product_attached_bundle_surcharge_fee ?? product?.metadata?.main_product_attached_bundle_surcharge_fee;
147
+ if (value === undefined || value === null || value === '') return null;
148
+ return toDecimal(value);
149
+ }
150
+ function getPersistedSourceSurchargeFee(sourceItem) {
151
+ const value = sourceItem?.metadata?.__persisted_surcharge_fee;
152
+ if (value === undefined || value === null || value === '') return null;
153
+ return toDecimal(value);
154
+ }
155
+ function getPersistedSurchargeRemainder(item, sourceItem) {
156
+ const value = sourceItem?.metadata?.surcharge_rounding_remainder ?? item?.surcharge_rounding_remainder ?? item?.metadata?.surcharge_rounding_remainder;
157
+ if (value === undefined || value === null || value === '') return null;
158
+ return toDecimal(value);
159
+ }
160
+ function getPersistedQuantity(item, fallbackQuantity) {
161
+ const isPersistedLine = item?.order_detail_id !== undefined && item?.order_detail_id !== null;
162
+ if (!isPersistedLine) return new _decimal.default(0);
163
+ const value = item?.product_quantity ?? item?.quantity;
164
+ const parsed = new _decimal.default(value || 0);
165
+ if (parsed.lte(0)) return _decimal.default.min(fallbackQuantity, 1);
166
+ return _decimal.default.min(fallbackQuantity, parsed);
167
+ }
168
+ function getPersistedBundleSurchargeFee(bundle, product) {
169
+ if (bundle?.order_detail_id === undefined && product?.order_detail_id === undefined) return null;
170
+ if (bundle?.order_detail_id === null && product?.order_detail_id === null) return null;
171
+ const value = bundle?.surcharge_fee ?? bundle?.metadata?.surcharge_fee;
172
+ if (value === undefined || value === null || value === '') return null;
173
+ return toDecimal(value);
174
+ }
175
+ function createSurchargeAllocationNodes(products, sourceItems) {
176
+ const nodes = [];
177
+ for (let productIndex = 0; productIndex < products.length; productIndex++) {
178
+ const product = products[productIndex];
179
+ const sourceItem = sourceItems[productIndex] || {};
180
+ const productQuantity = new _decimal.default(getSafeNum(product.num));
181
+ for (let bundleIndex = 0; bundleIndex < (product.product_bundle || []).length; bundleIndex++) {
182
+ const bundle = product.product_bundle[bundleIndex];
183
+ if (!isBundleOriginalPrice(bundle)) continue;
184
+ const sourceBundle = sourceItem?.bundle?.[bundleIndex] || {};
185
+ nodes.push({
186
+ kind: 'bundle',
187
+ target: bundle,
188
+ source: sourceBundle,
189
+ productId: getBundleProductId(bundle),
190
+ unitAmount: getBundleSurchargeUnitAmount(bundle),
191
+ quantity: new _decimal.default(getSafeNum(bundle?.num ?? bundle?.quantity)).times(productQuantity),
192
+ persistedQuantity: getPersistedQuantity(bundle, new _decimal.default(getSafeNum(bundle?.num ?? bundle?.quantity)).times(productQuantity)),
193
+ relationSurchargeIds: getRelationSurchargeIds(sourceBundle).length ? getRelationSurchargeIds(sourceBundle) : getRelationSurchargeIds(bundle),
194
+ persistedUnitSurchargeFee: getPersistedBundleSurchargeFee(bundle, product),
195
+ persistedSurchargeRemainder: getPersistedSurchargeRemainder(bundle, sourceBundle)
196
+ });
197
+ }
198
+ nodes.push({
199
+ kind: 'main',
200
+ target: product,
201
+ source: sourceItem,
202
+ productId: product.product_id ?? null,
203
+ unitAmount: getMainSurchargeUnitAmount(product),
204
+ quantity: productQuantity,
205
+ persistedQuantity: getPersistedQuantity(product, productQuantity),
206
+ relationSurchargeIds: getRelationSurchargeIds(sourceItem).length ? getRelationSurchargeIds(sourceItem) : getRelationSurchargeIds(product),
207
+ persistedUnitSurchargeFee: getPersistedSourceSurchargeFee(sourceItem) ?? getPersistedMainSurchargeFee(product),
208
+ persistedSurchargeRemainder: getPersistedSurchargeRemainder(product, sourceItem)
209
+ });
210
+ }
211
+ return nodes;
212
+ }
213
+ function resetProductSurchargeFields(products) {
214
+ for (const product of products) {
215
+ product.surcharge_fee = 0;
216
+ product.main_product_attached_bundle_surcharge_fee = '0.00';
217
+ product.surcharge_rounding_remainder = 0;
218
+ product.relation_surcharge_ids = [];
219
+ for (const bundle of product.product_bundle || []) {
220
+ bundle.surcharge_fee = 0;
221
+ bundle.relation_surcharge_ids = [];
222
+ bundle.metadata = {
223
+ ...(bundle.metadata || {}),
224
+ surcharge_fee: '0.00',
225
+ surcharge_rounding_remainder: '0.00',
226
+ relation_surcharge_ids: []
227
+ };
228
+ }
229
+ }
230
+ }
231
+ function getPersistedSurchargeIds(nodes) {
232
+ const ids = new Set();
233
+ for (const node of nodes) {
234
+ if (!node.persistedUnitSurchargeFee || node.persistedUnitSurchargeFee.lte(0)) continue;
235
+ for (const surchargeId of node.relationSurchargeIds) {
236
+ ids.add(surchargeId);
237
+ }
238
+ }
239
+ return ids;
240
+ }
241
+ function buildSurchargeQuantityTotals(nodes) {
242
+ const totals = new Map();
243
+ for (const node of nodes) {
244
+ for (const surchargeId of node.relationSurchargeIds) {
245
+ totals.set(surchargeId, (totals.get(surchargeId) || new _decimal.default(0)).plus(node.quantity));
246
+ }
247
+ }
248
+ return totals;
249
+ }
250
+ function getFallbackAllProductSurchargeIds(surchargeList) {
251
+ return (surchargeList || []).reduce((ids, config) => {
252
+ const id = getSurchargeConfigId(config);
253
+ if (id === undefined) return ids;
254
+ if (Number(config.open_product ?? 0) === 0) return ids;
255
+ if (Number(config.is_all ?? 0) !== 1) return ids;
256
+ if (Number(config.open_schedule ?? 0) === 1 && config.schedule_type !== 'all') return ids;
257
+ ids.push(id);
258
+ return ids;
259
+ }, []);
260
+ }
261
+ function getBackendSurchargeState(stateMap, surchargeId, config) {
262
+ let state = stateMap.get(surchargeId);
263
+ if (!state) {
264
+ state = {
265
+ config,
266
+ amount: new _decimal.default(0),
267
+ totalOffsetFee: new _decimal.default(0),
268
+ calculatedQuantity: new _decimal.default(0),
269
+ fixedIncluded: false,
270
+ fixedRemainderAssigned: false
271
+ };
272
+ stateMap.set(surchargeId, state);
273
+ }
274
+ return state;
275
+ }
276
+ function buildSurchargeResultItem(config, surchargeId, amount, index) {
277
+ const name = config?.name || config?.label || {};
278
+ return {
279
+ key: `custom_surcharge_${index}`,
280
+ label: name,
281
+ name,
282
+ value: amount.toNumber(),
283
+ surcharge_id: surchargeId,
284
+ description: config?.description,
285
+ type: 'default',
286
+ fixed: config?.fixed,
287
+ amount: amount.toNumber(),
288
+ percentage: config?.percentage,
289
+ metadata: {
290
+ open_product: config?.open_product
291
+ }
292
+ };
293
+ }
294
+ function applySurchargeNodeResult(node, params) {
295
+ const {
296
+ unitSurchargeFee,
297
+ roundingRemainder,
298
+ surchargeIds
299
+ } = params;
300
+ if (node.kind === 'main') {
301
+ node.target.surcharge_fee = unitSurchargeFee.toNumber();
302
+ node.target.main_product_attached_bundle_surcharge_fee = toFixed2(unitSurchargeFee);
303
+ node.target.surcharge_rounding_remainder = roundingRemainder.toNumber();
304
+ node.target.relation_surcharge_ids = surchargeIds;
305
+ return;
306
+ }
307
+ node.target.surcharge_fee = unitSurchargeFee.toNumber();
308
+ node.target.relation_surcharge_ids = surchargeIds;
309
+ node.target.metadata = {
310
+ ...(node.target.metadata || {}),
311
+ surcharge_fee: toFixed2(unitSurchargeFee),
312
+ surcharge_rounding_remainder: toFixed2(roundingRemainder),
313
+ relation_surcharge_ids: surchargeIds
314
+ };
315
+ }
316
+ function calculateBackendProductSurcharges(params) {
317
+ const {
318
+ products,
319
+ sourceItems,
320
+ surchargeList
321
+ } = params;
322
+ resetProductSurchargeFields(products);
323
+ const configById = getSurchargeConfigById(surchargeList);
324
+ const nodes = createSurchargeAllocationNodes(products, sourceItems);
325
+ const fallbackAllProductSurchargeIds = getFallbackAllProductSurchargeIds(surchargeList);
326
+ for (const node of nodes) {
327
+ if (node.relationSurchargeIds.length === 0) {
328
+ node.relationSurchargeIds = fallbackAllProductSurchargeIds;
329
+ }
330
+ }
331
+ const persistedSurchargeIds = getPersistedSurchargeIds(nodes);
332
+ const quantityTotals = buildSurchargeQuantityTotals(nodes);
333
+ const stateMap = new Map();
334
+ for (const node of nodes) {
335
+ let unitSurchargeFee = new _decimal.default(0);
336
+ let roundingRemainder = new _decimal.default(0);
337
+ const appliedSurchargeIds = [];
338
+ let persistedRemainderApplied = false;
339
+ for (const surchargeId of node.relationSurchargeIds) {
340
+ const config = configById.get(surchargeId);
341
+ const totalQuantity = quantityTotals.get(surchargeId) || new _decimal.default(0);
342
+ if (totalQuantity.lte(0)) continue;
343
+ const persistedUnitSurchargeFee = node.persistedUnitSurchargeFee;
344
+ if (persistedUnitSurchargeFee && persistedUnitSurchargeFee.gt(0)) {
345
+ const persistedQuantity = _decimal.default.min(node.persistedQuantity, node.quantity);
346
+ const deltaQuantity = _decimal.default.max(node.quantity.minus(persistedQuantity), 0);
347
+ const state = getBackendSurchargeState(stateMap, surchargeId, config || {
348
+ surcharge_id: surchargeId
349
+ });
350
+ const persistedSurchargeRemainder = !persistedRemainderApplied && node.persistedSurchargeRemainder ? node.persistedSurchargeRemainder : new _decimal.default(0);
351
+ state.amount = bcAdd(bcAdd(state.amount, bcMul(persistedUnitSurchargeFee, persistedQuantity, 2), 2), persistedSurchargeRemainder, 2);
352
+ const fixed = new _decimal.default(config?.fixed || 0);
353
+ if (fixed.gt(0)) state.fixedIncluded = true;
354
+ let nodeTotalSurcharge = bcAdd(bcMul(persistedUnitSurchargeFee, persistedQuantity, 2), persistedSurchargeRemainder, 2);
355
+ if (config && deltaQuantity.gt(0)) {
356
+ const percentage = new _decimal.default(config.percentage || 0);
357
+ const deltaUnitPercentageFee = _decimal.default.max(0, bcMul(node.unitAmount, percentage, 2));
358
+ const deltaSurcharge = bcMul(deltaQuantity, deltaUnitPercentageFee, 2);
359
+ state.amount = bcAdd(state.amount, deltaSurcharge, 2);
360
+ nodeTotalSurcharge = bcAdd(nodeTotalSurcharge, deltaSurcharge, 2);
361
+ }
362
+ if (node.quantity.gt(0)) {
363
+ unitSurchargeFee = bcAdd(unitSurchargeFee, bcDiv(nodeTotalSurcharge, node.quantity, 2), 2);
364
+ }
365
+ if (!persistedSurchargeRemainder.eq(0)) {
366
+ roundingRemainder = bcAdd(roundingRemainder, persistedSurchargeRemainder, 2);
367
+ persistedRemainderApplied = true;
368
+ }
369
+ appliedSurchargeIds.push(surchargeId);
370
+ continue;
371
+ }
372
+ if (!config) continue;
373
+ const percentage = new _decimal.default(config.percentage || 0);
374
+ const fixed = new _decimal.default(config.fixed || 0);
375
+ const unitPercentageFee = _decimal.default.max(0, bcMul(node.unitAmount, percentage, 2));
376
+ const percentageTotalFee = bcMul(node.quantity, unitPercentageFee, 2);
377
+ let unitFixedFee = new _decimal.default(0);
378
+ let fixedRemainder = new _decimal.default(0);
379
+ if (fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
380
+ unitFixedFee = bcDiv(fixed, totalQuantity, 2);
381
+ const distributedFixed = bcMul(unitFixedFee, totalQuantity, 2);
382
+ fixedRemainder = bcSub(fixed, distributedFixed, 2);
383
+ }
384
+ const currentUnitSurcharge = _decimal.default.max(0, bcAdd(unitPercentageFee, unitFixedFee, 2));
385
+ if (currentUnitSurcharge.lte(0)) continue;
386
+ const state = getBackendSurchargeState(stateMap, surchargeId, config);
387
+ state.amount = bcAdd(state.amount, percentageTotalFee, 2);
388
+ const precisePercentage = _decimal.default.max(0, bcMul(node.unitAmount, percentage, 6));
389
+ const offsetBaseFee = _decimal.default.max(0, bcSub(precisePercentage, unitPercentageFee, 6));
390
+ state.totalOffsetFee = bcAdd(state.totalOffsetFee, bcMul(offsetBaseFee, node.quantity, 6), 6);
391
+ state.calculatedQuantity = bcAdd(state.calculatedQuantity, node.quantity, 6);
392
+ if (!state.fixedIncluded && fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
393
+ state.amount = bcAdd(state.amount, fixed, 2);
394
+ state.fixedIncluded = true;
395
+ }
396
+ if (!state.fixedRemainderAssigned && !fixedRemainder.eq(0)) {
397
+ state.fixedRemainderAssigned = true;
398
+ roundingRemainder = bcAdd(roundingRemainder, fixedRemainder, 2);
399
+ }
400
+ if (state.calculatedQuantity.gte(totalQuantity) && state.totalOffsetFee.gt(0)) {
401
+ const totalOffsetFee = toAmountFormat(state.totalOffsetFee);
402
+ state.amount = bcAdd(state.amount, totalOffsetFee, 2);
403
+ roundingRemainder = bcAdd(roundingRemainder, totalOffsetFee, 2);
404
+ state.totalOffsetFee = new _decimal.default(0);
405
+ }
406
+ unitSurchargeFee = bcAdd(unitSurchargeFee, currentUnitSurcharge, 2);
407
+ appliedSurchargeIds.push(surchargeId);
408
+ }
409
+ applySurchargeNodeResult(node, {
410
+ unitSurchargeFee,
411
+ roundingRemainder,
412
+ surchargeIds: appliedSurchargeIds
413
+ });
414
+ }
415
+ const result = (surchargeList || []).reduce((items, config, index) => {
416
+ const surchargeId = getSurchargeConfigId(config);
417
+ if (surchargeId === undefined) return items;
418
+ const state = stateMap.get(surchargeId);
419
+ if (!state || state.amount.lte(0)) return items;
420
+ items.push(buildSurchargeResultItem(config, surchargeId, state.amount, index));
421
+ return items;
422
+ }, []);
423
+ const includedIds = new Set(result.map(item => item?.surcharge_id).filter(id => id !== undefined));
424
+ for (const [surchargeId, state] of stateMap.entries()) {
425
+ if (includedIds.has(surchargeId) || state.amount.lte(0)) continue;
426
+ result.push(buildSurchargeResultItem(state.config, surchargeId, state.amount, result.length));
427
+ }
428
+ return result;
429
+ }
75
430
  function getProductDepositData(product) {
76
431
  const rootDepositData = product._origin?.custom_deposit_data;
77
432
  if (rootDepositData && typeof rootDepositData === 'object') return rootDepositData;
@@ -180,20 +535,20 @@ function calculateSingleItemTax(params) {
180
535
  }
181
536
 
182
537
  /**
183
- * 获取主商品折扣后总价(含 option、含主商品折扣、含加价/减价 bundle)。
538
+ * 主商品 + 非原价(加价/减价)子商品的"折扣后"售价合计(含 option、含主商品折扣,未减整单折扣)。
184
539
  *
185
- * 新语义 v2 下:
186
- * - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价,直接读即可;
187
- * - 无需再 `minus(mainDiscountAmount)` 或 `plus(getOptionUnitPrice)`;
188
- * - 仅需叠加 `markup` / `markdown` 类 bundle(原价 bundle 已由 `calculateProductsTax` 独立处理)。
540
+ * 对齐后端 metadata.main_product_attached_bundle_selling_price:
541
+ * - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价;
542
+ * - 叠加 `markup` / `markdown` 类 bundle(原价 bundle 由 `calculateProductsTax` 独立处理)。
189
543
  */
190
- function getMainProductPaymentTotal(product) {
544
+ function getMainAttachedBundleSellingTotal(product) {
191
545
  const mainSelling = product.metadata?.main_product_selling_price ?? product.metadata?.main_product_original_price ?? 0;
192
546
  let total = toDecimal(mainSelling);
193
547
  const bundleItems = product.product_bundle || [];
194
548
  for (const bundleItem of bundleItems) {
195
549
  if (isBundleMarkupOrDiscount(bundleItem)) {
196
- const unit = toDecimal(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
550
+ // markdown(减价)按带符号净额取减;markup 维持相加。
551
+ const unit = (0, _utils2.getBundleSignedUnit)(bundleItem);
197
552
  const qty = getSafeNum(bundleItem.num ?? bundleItem.quantity);
198
553
  total = total.plus(unit.times(qty));
199
554
  }
@@ -201,21 +556,145 @@ function getMainProductPaymentTotal(product) {
201
556
  return _decimal.default.max(total, 0);
202
557
  }
203
558
 
559
+ /**
560
+ * 获取主商品税费基数(含 option、含主商品折扣、含加价/减价 bundle、已减整单折扣均摊)。
561
+ *
562
+ * 对齐后端 handleMainProductTaxFee:税基使用 main_product_attached_bundle_payment_price。
563
+ * - 优先读取均摊层写入的 payment 价;
564
+ * - 兜底退化为 selling 合计(无整单折扣时两者相等)。
565
+ */
566
+ function getMainProductPaymentTotal(product) {
567
+ const attachedPayment = product.metadata?.main_product_attached_bundle_payment_price;
568
+ if (attachedPayment !== undefined && attachedPayment !== null && attachedPayment !== '') {
569
+ return _decimal.default.max(toDecimal(attachedPayment), 0);
570
+ }
571
+ return getMainAttachedBundleSellingTotal(product);
572
+ }
573
+ function getExplicitTaxRemainder(item) {
574
+ const value = item?.tax_fee_rounding_remainder ?? item?.metadata?.tax_fee_rounding_remainder;
575
+ if (value === undefined || value === null || value === '') return null;
576
+ return new _decimal.default(value || 0);
577
+ }
578
+ function getPersistedTaxRemainder(item, parentProduct) {
579
+ const isPersistedLine = item?.order_detail_id !== undefined && item?.order_detail_id !== null || parentProduct?.order_detail_id !== undefined && parentProduct?.order_detail_id !== null;
580
+ if (!isPersistedLine) return null;
581
+ return getExplicitTaxRemainder(item);
582
+ }
583
+ function getPersistedMainTaxFee(product) {
584
+ if (product?.order_detail_id === undefined || product?.order_detail_id === null) return null;
585
+ const value = product?.metadata?.main_product_attached_bundle_tax_fee ?? product?.main_product_attached_bundle_tax_fee ?? product?.tax_fee;
586
+ if (value === undefined || value === null || value === '') return null;
587
+ return toDecimal(value);
588
+ }
589
+ function writeTaxRemainder(item, roundingRemainder) {
590
+ item.tax_fee_rounding_remainder = roundingRemainder.toNumber();
591
+ if (item.metadata && typeof item.metadata === 'object') {
592
+ item.metadata.tax_fee_rounding_remainder = roundingRemainder.toFixed(2);
593
+ }
594
+ }
595
+ function resetTaxRemainderFields(products) {
596
+ for (const product of products) {
597
+ const productRemainder = getPersistedTaxRemainder(product);
598
+ if (productRemainder !== null) {
599
+ product.tax_fee_rounding_remainder = productRemainder.toNumber();
600
+ } else {
601
+ delete product.tax_fee_rounding_remainder;
602
+ }
603
+ product.original_tax_fee_rounding_remainder = 0;
604
+ for (const bundle of product.product_bundle || []) {
605
+ const bundleRemainder = getPersistedTaxRemainder(bundle, product);
606
+ bundle.metadata = {
607
+ ...(bundle.metadata || {})
608
+ };
609
+ if (bundleRemainder !== null) {
610
+ bundle.metadata.tax_fee_rounding_remainder = bundleRemainder.toFixed(2);
611
+ bundle.tax_fee_rounding_remainder = bundleRemainder.toNumber();
612
+ } else {
613
+ delete bundle.metadata.tax_fee_rounding_remainder;
614
+ delete bundle.tax_fee_rounding_remainder;
615
+ }
616
+ bundle.original_tax_fee_rounding_remainder = 0;
617
+ }
618
+ }
619
+ }
620
+ function getBundlePaymentPrice(bundle, product) {
621
+ if (bundle?.bundle_payment_price !== undefined) return toDecimal(bundle.bundle_payment_price);
622
+ const basePrice = toDecimal(bundle?.bundle_selling_price ?? bundle?.bundle_sum_price ?? bundle?.price ?? 0);
623
+ if (!isBundleOriginalPrice(bundle)) return basePrice;
624
+ const averageDiscountRate = toDecimal(product.metadata?.average_discount_amount_rate ?? 1);
625
+ return toAmountFormat(bcMul(basePrice, averageDiscountRate, 6));
626
+ }
627
+ function applyBackendTaxRemainder(params) {
628
+ const {
629
+ target,
630
+ rawTax,
631
+ formattedTax,
632
+ quantity,
633
+ state
634
+ } = params;
635
+ const taxFeeDifference = bcMul(bcSub(rawTax, formattedTax, 6), quantity, 6);
636
+ state.difference = bcAdd(state.difference, taxFeeDifference, 6);
637
+ if (state.difference.lt(0.005)) return new _decimal.default(0);
638
+ const roundingRemainder = toAmountFormat(state.difference);
639
+ writeTaxRemainder(target, roundingRemainder);
640
+ state.difference = bcSub(state.difference, roundingRemainder, 6);
641
+ return roundingRemainder;
642
+ }
643
+
204
644
  /**
205
645
  * 遍历所有商品计算税费,回写 tax_fee 到每个商品及 bundle 原价子商品,处理舍入差值。
206
646
  * 参照 Summary/utils.ts 的 processItemsTax,适配 SalesSummaryProduct 结构。
207
647
  */
208
648
  function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
209
649
  const rate = new _decimal.default(taxRate);
210
- let preciseTax = new _decimal.default(0);
211
- let roundedTax = new _decimal.default(0);
212
- let preciseOriginTax = new _decimal.default(0);
213
- let roundedOriginTax = new _decimal.default(0);
214
- let lastTaxableItem = null;
650
+ const taxRemainderState = {
651
+ difference: new _decimal.default(0)
652
+ };
653
+ let totalTax = new _decimal.default(0);
654
+ let totalOriginTax = new _decimal.default(0);
655
+ resetTaxRemainderFields(products);
215
656
  for (const product of products) {
216
657
  const quantity = new _decimal.default(getSafeNum(product.num));
217
-
218
- // --- 主商品折后税费 ---
658
+ let productUnitTax = new _decimal.default(0);
659
+ let productUnitOriginTax = new _decimal.default(0);
660
+ const bundleItems = product.product_bundle || [];
661
+ for (const bundleItem of bundleItems) {
662
+ if (!isBundleOriginalPrice(bundleItem)) continue;
663
+ const bundleQuantity = new _decimal.default(getSafeNum(bundleItem.num ?? bundleItem.quantity));
664
+ const totalBundleQuantity = bundleQuantity.times(quantity);
665
+ const bundlePrice = getBundlePaymentPrice(bundleItem, product);
666
+ const bundleOriginalPrice = toDecimal(bundleItem.original_price ?? bundleItem.product_price ?? bundleItem.price ?? 0);
667
+ const bundleSurchargeFee = toDecimal(bundleItem.surcharge_fee);
668
+ const bundleTaxPrecise = calculateSingleItemTax({
669
+ price: bundlePrice.plus(bundleSurchargeFee),
670
+ taxRate: rate,
671
+ isPriceIncludeTax,
672
+ isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
673
+ });
674
+ const bundleTaxRounded = toBackendTaxFee(bundleTaxPrecise);
675
+ bundleItem.tax_fee = bundleTaxRounded.toNumber();
676
+ const persistedBundleRemainder = getPersistedTaxRemainder(bundleItem, product);
677
+ const bundleRemainder = persistedBundleRemainder ?? applyBackendTaxRemainder({
678
+ target: bundleItem,
679
+ rawTax: bundleTaxPrecise,
680
+ formattedTax: bundleTaxRounded,
681
+ quantity: totalBundleQuantity,
682
+ state: taxRemainderState
683
+ });
684
+ if (persistedBundleRemainder) writeTaxRemainder(bundleItem, persistedBundleRemainder);
685
+ const bundleOrigTaxPrecise = calculateSingleItemTax({
686
+ price: bundleOriginalPrice.plus(bundleSurchargeFee),
687
+ taxRate: rate,
688
+ isPriceIncludeTax,
689
+ isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
690
+ });
691
+ const bundleOrigTaxRounded = toAmountFormat(bundleOrigTaxPrecise);
692
+ bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
693
+ productUnitTax = productUnitTax.plus(bundleTaxRounded.times(bundleQuantity));
694
+ productUnitOriginTax = productUnitOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
695
+ totalTax = totalTax.plus(bundleTaxRounded.times(totalBundleQuantity)).plus(bundleRemainder);
696
+ totalOriginTax = totalOriginTax.plus(bundleOrigTaxRounded.times(totalBundleQuantity));
697
+ }
219
698
  const mainTotal = getMainProductPaymentTotal(product);
220
699
  const surchargeRoundingRemainder = toDecimal(product.surcharge_rounding_remainder);
221
700
  const surchargeFee = toDecimal(product.surcharge_fee).plus(quantity.gt(0) ? surchargeRoundingRemainder.div(quantity) : 0);
@@ -226,15 +705,23 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
226
705
  isPriceIncludeTax,
227
706
  isChargeTax: product.is_charge_tax ?? 0
228
707
  });
229
- const mainTaxRounded = mainTaxPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
230
- if (mainTaxPrecise.gt(0)) {
231
- lastTaxableItem = {
232
- type: 'main',
233
- item: product
234
- };
708
+ const mainTaxRounded = toBackendTaxFee(mainTaxPrecise);
709
+ const persistedMainRemainder = getPersistedTaxRemainder(product);
710
+ const persistedMainTaxFee = getPersistedMainTaxFee(product);
711
+ const persistedQuantity = getPersistedQuantity(product, quantity);
712
+ const deltaQuantity = _decimal.default.max(quantity.minus(persistedQuantity), 0);
713
+ const shouldUsePersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gte(quantity);
714
+ const shouldSplitPersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gt(0) && deltaQuantity.gt(0);
715
+ const mainRemainder = shouldUsePersistedMainTax || shouldSplitPersistedMainTax ? new _decimal.default(0) : persistedMainRemainder ?? applyBackendTaxRemainder({
716
+ target: product,
717
+ rawTax: mainTaxPrecise,
718
+ formattedTax: mainTaxRounded,
719
+ quantity,
720
+ state: taxRemainderState
721
+ });
722
+ if (persistedMainRemainder && !shouldSplitPersistedMainTax) {
723
+ writeTaxRemainder(product, persistedMainRemainder);
235
724
  }
236
-
237
- // --- 主商品原价税费 ---
238
725
  const originalTotal = getUnitOriginalTotal(product);
239
726
  const originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
240
727
  const originalTaxPrecise = calculateSingleItemTax({
@@ -243,77 +730,76 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
243
730
  isPriceIncludeTax,
244
731
  isChargeTax: product.is_charge_tax ?? 0
245
732
  });
246
-
247
- // --- bundle 原价子商品独立计税 ---
248
- let bundlePreciseTax = new _decimal.default(0);
249
- let bundleRoundedTax = new _decimal.default(0);
250
- let bundlePreciseOriginTax = new _decimal.default(0);
251
- let bundleRoundedOriginTax = new _decimal.default(0);
252
- const bundleItems = product.product_bundle || [];
253
- for (const bundleItem of bundleItems) {
254
- if (!isBundleOriginalPrice(bundleItem)) continue;
255
- const bundleQuantity = new _decimal.default(getSafeNum(bundleItem.num ?? bundleItem.quantity));
256
- const bundlePrice = toDecimal(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
257
- const bundleOriginalPrice = toDecimal(bundleItem.original_price ?? bundleItem.product_price ?? bundleItem.price ?? 0);
258
- const bundleTaxPrecise = calculateSingleItemTax({
259
- price: bundlePrice,
260
- taxRate: rate,
261
- isPriceIncludeTax,
262
- isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
263
- });
264
- const bundleTaxRounded = bundleTaxPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
265
- const bundleOrigTaxPrecise = calculateSingleItemTax({
266
- price: bundleOriginalPrice,
267
- taxRate: rate,
268
- isPriceIncludeTax,
269
- isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
270
- });
271
- const bundleOrigTaxRounded = bundleOrigTaxPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
272
- bundleItem.tax_fee = bundleTaxRounded.toNumber();
273
- bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
274
- bundlePreciseTax = bundlePreciseTax.plus(bundleTaxPrecise.times(bundleQuantity));
275
- bundleRoundedTax = bundleRoundedTax.plus(bundleTaxRounded.times(bundleQuantity));
276
- bundlePreciseOriginTax = bundlePreciseOriginTax.plus(bundleOrigTaxPrecise.times(bundleQuantity));
277
- bundleRoundedOriginTax = bundleRoundedOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
278
- if (bundleTaxPrecise.gt(0)) {
279
- lastTaxableItem = {
280
- type: 'bundle',
281
- item: bundleItem
282
- };
283
- }
284
- }
285
-
286
- // --- 汇总到商品级 ---
287
- const itemTaxPrecise = mainTaxPrecise.plus(bundlePreciseTax);
288
- const itemTaxRounded = mainTaxRounded.plus(bundleRoundedTax);
289
- const itemOriginTaxPrecise = originalTaxPrecise.plus(bundlePreciseOriginTax);
290
- const itemOriginTaxRounded = originalTaxPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).plus(bundleRoundedOriginTax);
291
- product.tax_fee = itemTaxRounded.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toFixed(2);
292
- product.original_tax_fee = itemOriginTaxRounded.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
293
- preciseTax = preciseTax.plus(itemTaxPrecise.times(quantity));
294
- roundedTax = roundedTax.plus(itemTaxRounded.times(quantity));
295
- preciseOriginTax = preciseOriginTax.plus(itemOriginTaxPrecise.times(quantity));
296
- roundedOriginTax = roundedOriginTax.plus(itemOriginTaxRounded.times(quantity));
297
- }
298
-
299
- // --- 舍入差值处理 ---
300
- const expectedTax = preciseTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
301
- const expectedOriginTax = preciseOriginTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
302
- const taxRemainder = expectedTax.minus(roundedTax).toNumber();
303
- const originTaxRemainder = expectedOriginTax.minus(roundedOriginTax).toNumber();
304
- if (lastTaxableItem) {
305
- if (taxRemainder !== 0) {
306
- lastTaxableItem.item.tax_fee_rounding_remainder = taxRemainder;
307
- }
308
- if (originTaxRemainder !== 0) {
309
- lastTaxableItem.item.original_tax_fee_rounding_remainder = originTaxRemainder;
733
+ const originalTaxRounded = toAmountFormat(originalTaxPrecise);
734
+ const effectiveMainUnitTax = shouldUsePersistedMainTax ? persistedMainTaxFee : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)).div(quantity).toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP) : mainTaxRounded;
735
+ productUnitTax = productUnitTax.plus(effectiveMainUnitTax);
736
+ productUnitOriginTax = productUnitOriginTax.plus(originalTaxRounded);
737
+ product.main_product_attached_bundle_tax_fee = effectiveMainUnitTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toFixed(2);
738
+ product.tax_fee = productUnitTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toFixed(2);
739
+ product.original_tax_fee = productUnitOriginTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
740
+ totalTax = totalTax.plus(shouldUsePersistedMainTax ? persistedMainTaxFee.times(quantity).plus(persistedMainRemainder || 0) : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)) : mainTaxRounded.times(quantity).plus(mainRemainder));
741
+ totalOriginTax = totalOriginTax.plus(originalTaxRounded.times(quantity));
742
+ if (product.tax_fee_rounding_remainder === undefined) {
743
+ product.tax_fee_rounding_remainder = 0;
310
744
  }
311
745
  }
312
746
  return {
313
- tax: expectedTax,
314
- originTax: expectedOriginTax
747
+ tax: totalTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP),
748
+ originTax: totalOriginTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP)
315
749
  };
316
750
  }
751
+
752
+ /**
753
+ * 整单折扣(shop_discount)按各行 selling 合计占比均摊到 payment 维度。
754
+ *
755
+ * 文档口径:
756
+ * - payment_price = selling_price − 整单折扣均摊;rate = payment/selling(全行同一 rate);
757
+ * - 附加费不受整单折扣影响(基数仍用 selling,本函数写 main_product_attached_bundle_selling_price);
758
+ * - 税费受整单折扣影响(基数用 payment,本函数写 main_product_attached_bundle_payment_price 与
759
+ * 原价子商品 bundle_payment_price)。
760
+ *
761
+ * 与后端一致:bundle_payment_price = bundle_selling_price × rate,
762
+ * main_product_attached_bundle_payment_price = main_product_attached_bundle_selling_price × rate。
763
+ */
764
+ function allocateShopDiscountToPayment(products, productAmount, shopDiscountAmount) {
765
+ const effectiveDiscount = productAmount.lte(0) ? new _decimal.default(0) : _decimal.default.max(_decimal.default.min(productAmount, shopDiscountAmount), 0);
766
+ let allocatedDiscount = new _decimal.default(0);
767
+ products.forEach((product, index) => {
768
+ const quantity = new _decimal.default(getSafeNum(product.num));
769
+ const sellingUnit = getUnitPaymentTotal(product);
770
+ const lineSellingTotal = sellingUnit.times(quantity);
771
+ const lineDiscount = effectiveDiscount.lte(0) ? new _decimal.default(0) : index === products.length - 1 ? _decimal.default.max(effectiveDiscount.minus(allocatedDiscount), 0) : toAmountFormat(lineSellingTotal.div(productAmount).times(effectiveDiscount));
772
+ allocatedDiscount = allocatedDiscount.plus(lineDiscount);
773
+ const unitDiscount = quantity.lte(0) ? new _decimal.default(0) : lineDiscount.div(quantity);
774
+ const paymentUnit = _decimal.default.max(sellingUnit.minus(unitDiscount), 0);
775
+ const rate = sellingUnit.lte(0) ? new _decimal.default(1) : toBcScale(paymentUnit.div(sellingUnit), 6);
776
+ const mainSellingTotal = getMainAttachedBundleSellingTotal(product);
777
+ const mainPaymentTotal = toAmountFormat(bcMul(mainSellingTotal, rate, 6));
778
+ product.metadata = {
779
+ ...(product.metadata || {}),
780
+ average_discount_amount_rate: rate.toString(),
781
+ main_product_attached_bundle_selling_price: mainSellingTotal.toFixed(2),
782
+ main_product_attached_bundle_payment_price: mainPaymentTotal.toFixed(2)
783
+ };
784
+ for (const bundle of product.product_bundle || []) {
785
+ // 原价子商品:bundle_payment_price = bundle_selling_price × rate
786
+ // markdown 子商品:以净额幅度 × rate(与后端一致,存正净额)
787
+ if (isBundleOriginalPrice(bundle)) {
788
+ const bundleSelling = toDecimal(bundle.bundle_selling_price ?? bundle.bundle_sum_price ?? bundle.price ?? 0);
789
+ bundle.bundle_payment_price = toAmountFormat(bcMul(bundleSelling, rate, 6)).toFixed(2);
790
+ continue;
791
+ }
792
+ if ((0, _utils2.isMarkdownBundle)(bundle)) {
793
+ const magnitude = (0, _utils2.getBundleSellingMagnitude)(bundle);
794
+ bundle.custom_price = bundle.custom_price ?? bundle.price;
795
+ bundle.price = magnitude.toFixed(2);
796
+ bundle.bundle_selling_price = magnitude.toFixed(2);
797
+ bundle.bundle_payment_price = toAmountFormat(bcMul(magnitude, rate, 6)).toFixed(2);
798
+ }
799
+ }
800
+ product.payment_price = paymentUnit.toFixed(2);
801
+ });
802
+ }
317
803
  function createEmptySalesSummary() {
318
804
  return {
319
805
  product_quantity: 0,
@@ -330,6 +816,9 @@ function createEmptySalesSummary() {
330
816
  deposit_amount: '0.00',
331
817
  expect_amount: '0.00',
332
818
  total_amount: '0.00',
819
+ total_refund_amount: '0.00',
820
+ customer_paid_amount: '0.00',
821
+ order_paid_amount: '0.00',
333
822
  amount_gap: '0.00',
334
823
  rounding_amount: '0.00',
335
824
  pay_service_charge_amount: '0.00'
@@ -342,14 +831,26 @@ function calculateSalesSummary(params) {
342
831
  taxRate,
343
832
  surchargeList,
344
833
  scheduleById = {},
345
- isInScheduleByDate
834
+ isInScheduleByDate,
835
+ shopDiscount
346
836
  } = params;
347
837
  if (!products?.length) return createEmptySalesSummary();
348
- const productQuantity = products.reduce((sum, item) => sum + getSafeNum(item.num), 0);
349
- const productOriginalAmount = products.reduce((sum, item) => sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num))), new _decimal.default(0));
350
- const productAmount = products.reduce((sum, item) => sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num))), new _decimal.default(0));
351
- const surchargeServiceItems = buildSurchargeServiceItems(products);
352
- const surcharge = (0, _utils.getSurcharge)({
838
+ const summaryProducts = products.filter(product => !isGeneratedVoucherProduct(product));
839
+ if (!summaryProducts.length) return createEmptySalesSummary();
840
+ const productQuantity = summaryProducts.reduce((sum, item) => sum + getSafeNum(item.num), 0);
841
+ const productOriginalAmount = summaryProducts.reduce((sum, item) => sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num))), new _decimal.default(0));
842
+ const productAmount = summaryProducts.reduce((sum, item) => sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num))), new _decimal.default(0));
843
+ const shopDiscountAmount = _decimal.default.max(new _decimal.default(Number(shopDiscount) || 0), 0);
844
+ const hasPersistedSurchargeSnapshot = summaryProducts.some(product => {
845
+ return getPersistedMainSurchargeFee(product)?.gt(0);
846
+ });
847
+ // 整单折扣均摊:附加费基数用 selling(不受折扣),税费基数用 payment(受折扣)。
848
+ // persisted 快照(已下单编辑)优先采信后端回传值,不重算均摊。
849
+ if (!hasPersistedSurchargeSnapshot) {
850
+ allocateShopDiscountToPayment(summaryProducts, productAmount, shopDiscountAmount);
851
+ }
852
+ const surchargeServiceItems = buildSurchargeServiceItems(summaryProducts);
853
+ (0, _utils.getSurcharge)({
353
854
  service: surchargeServiceItems,
354
855
  addons: [],
355
856
  bookingDetail: null,
@@ -360,27 +861,28 @@ function calculateSalesSummary(params) {
360
861
  surcharge_list: surchargeList,
361
862
  scheduleById
362
863
  });
864
+ const surcharge = calculateBackendProductSurcharges({
865
+ products: summaryProducts,
866
+ sourceItems: surchargeServiceItems,
867
+ surchargeList
868
+ });
363
869
  const surchargeAmount = new _decimal.default((0, _utils.getSurchargeAmount)({
364
870
  bookingDetail: null,
365
871
  bookingId: undefined
366
872
  }, surcharge, {
367
873
  isEdit: false
368
874
  }) || 0);
369
- for (let i = 0; i < products.length; i++) {
370
- products[i].surcharge_fee = surchargeServiceItems[i]?.surcharge_fee || 0;
371
- products[i].surcharge_rounding_remainder = surchargeServiceItems[i]?.surcharge_rounding_remainder || 0;
372
- }
373
875
  const hasTaxRate = taxRate !== undefined && taxRate !== null && taxRate > 0;
374
876
  let productTaxFee;
375
877
  if (hasTaxRate) {
376
- const taxResult = calculateProductsTax(products, taxRate, isPriceIncludeTax);
878
+ const taxResult = calculateProductsTax(summaryProducts, taxRate, isPriceIncludeTax);
377
879
  productTaxFee = taxResult.tax;
378
880
  } else {
379
- productTaxFee = products.reduce((sum, item) => sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num))), new _decimal.default(0));
881
+ productTaxFee = summaryProducts.reduce((sum, item) => sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num))), new _decimal.default(0));
380
882
  }
381
- const expectAmount = productAmount.plus(surchargeAmount);
382
- const totalAmount = isPriceIncludeTax === 1 ? expectAmount : expectAmount.plus(productTaxFee);
383
- const deposit = calculateProductsDeposit(products);
883
+ const orderAmountBeforeDiscount = productAmount.plus(surchargeAmount).plus(isPriceIncludeTax === 1 ? 0 : productTaxFee);
884
+ const totalAmount = _decimal.default.max(0, orderAmountBeforeDiscount.minus(shopDiscountAmount));
885
+ const deposit = calculateProductsDeposit(summaryProducts);
384
886
  return {
385
887
  product_quantity: productQuantity,
386
888
  product_original_amount: toFixed2(productOriginalAmount),
@@ -392,11 +894,14 @@ function calculateSalesSummary(params) {
392
894
  tax_fee: toFixed2(productTaxFee),
393
895
  surcharge_fee: toFixed2(surchargeAmount),
394
896
  surcharges: surcharge,
395
- discount_amount: toFixed2(_decimal.default.max(productOriginalAmount.minus(productAmount), 0)),
897
+ discount_amount: toFixed2(shopDiscountAmount),
396
898
  deposit_amount: deposit ? deposit.total : '0.00',
397
899
  deposit,
398
- expect_amount: toFixed2(expectAmount),
900
+ expect_amount: toFixed2(totalAmount),
399
901
  total_amount: toFixed2(totalAmount),
902
+ total_refund_amount: '0.00',
903
+ customer_paid_amount: '0.00',
904
+ order_paid_amount: '0.00',
400
905
  amount_gap: '0.00',
401
906
  rounding_amount: '0.00',
402
907
  pay_service_charge_amount: '0.00',