@pisell/pisellos 0.0.568 → 0.10.1

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 (588) hide show
  1. package/dist/core/index.js +10 -6
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -3
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
  6. package/dist/model/strategy/adapter/walletPass/example.js +26 -3
  7. package/dist/model/strategy/adapter/walletPass/index.js +5 -5
  8. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
  9. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  10. package/dist/model/strategy/adapter/walletPass/utils.js +24 -96
  11. package/dist/model/strategy/strategy-example.js +19 -5
  12. package/dist/modules/BaseModule.d.ts +2 -2
  13. package/dist/modules/BaseModule.js +12 -14
  14. package/dist/modules/BookingContext/index.d.ts +48 -0
  15. package/dist/modules/BookingContext/index.js +566 -0
  16. package/dist/modules/BookingContext/types.d.ts +102 -0
  17. package/dist/modules/BookingContext/types.js +51 -0
  18. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  19. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
  20. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  21. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
  22. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  23. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
  24. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  25. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  26. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  27. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  28. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  29. package/dist/modules/BookingContext/utils/index.js +11 -0
  30. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  31. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  32. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  33. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  34. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  35. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  36. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  37. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  38. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  39. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  40. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  41. package/dist/modules/BookingContext/utils/resources.js +486 -0
  42. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  43. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  44. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  45. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  46. package/dist/modules/Cart/index.js +3 -0
  47. package/dist/modules/Cart/utils/cartProduct.js +27 -5
  48. package/dist/modules/Cart/utils/cartResource.js +0 -2
  49. package/dist/modules/Cart/utils/changePrice.js +11 -11
  50. package/dist/modules/Customer/index.d.ts +20 -0
  51. package/dist/modules/Customer/index.js +172 -83
  52. package/dist/modules/Customer/types.d.ts +2 -0
  53. package/dist/modules/Date/index.js +5 -1
  54. package/dist/modules/Discount/index.d.ts +2 -2
  55. package/dist/modules/Discount/index.js +43 -30
  56. package/dist/modules/Discount/types.d.ts +1 -1
  57. package/dist/modules/OpenData/index.d.ts +8 -0
  58. package/dist/modules/OpenData/index.js +38 -16
  59. package/dist/modules/Order/index.d.ts +449 -24
  60. package/dist/modules/Order/index.js +5460 -574
  61. package/dist/modules/Order/types.d.ts +693 -88
  62. package/dist/modules/Order/types.js +68 -1
  63. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  64. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  65. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  66. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  67. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  68. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  69. package/dist/modules/Order/utils.d.ts +167 -18
  70. package/dist/modules/Order/utils.js +960 -165
  71. package/dist/modules/Payment/index.d.ts +10 -9
  72. package/dist/modules/Payment/index.js +573 -746
  73. package/dist/modules/Payment/types.d.ts +44 -24
  74. package/dist/modules/Payment/utils.d.ts +1 -1
  75. package/dist/modules/Payment/utils.js +4 -3
  76. package/dist/modules/Payment/walletpass.d.ts +0 -2
  77. package/dist/modules/Payment/walletpass.js +49 -33
  78. package/dist/modules/Product/types.d.ts +29 -7
  79. package/dist/modules/ProductList/index.d.ts +17 -13
  80. package/dist/modules/ProductList/index.js +182 -81
  81. package/dist/modules/ProductList/types.d.ts +16 -0
  82. package/dist/modules/Quotation/index.d.ts +22 -2
  83. package/dist/modules/Quotation/index.js +108 -42
  84. package/dist/modules/Quotation/types.d.ts +19 -0
  85. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  86. package/dist/modules/ResourcePlanner/index.js +181 -0
  87. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  88. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  89. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  90. package/dist/modules/ResourcePlanner/types.js +1 -0
  91. package/dist/modules/Rules/index.d.ts +8 -10
  92. package/dist/modules/Rules/index.js +324 -513
  93. package/dist/modules/Rules/types.d.ts +14 -3
  94. package/dist/modules/SalesSummary/index.d.ts +23 -26
  95. package/dist/modules/SalesSummary/index.js +152 -46
  96. package/dist/modules/SalesSummary/types.d.ts +9 -1
  97. package/dist/modules/SalesSummary/utils.d.ts +3 -22
  98. package/dist/modules/SalesSummary/utils.js +804 -165
  99. package/dist/modules/Schedule/getDateIsInSchedule.js +14 -12
  100. package/dist/modules/Schedule/index.d.ts +18 -5
  101. package/dist/modules/Schedule/index.js +79 -24
  102. package/dist/modules/Schedule/types.d.ts +2 -0
  103. package/dist/modules/Schedule/utils.js +1 -0
  104. package/dist/modules/Step/index.js +1 -0
  105. package/dist/modules/Summary/index.js +4 -3
  106. package/dist/modules/Summary/utils.js +22 -43
  107. package/dist/modules/SurchargeList/index.d.ts +18 -0
  108. package/dist/modules/SurchargeList/index.js +185 -0
  109. package/dist/modules/SurchargeList/types.d.ts +15 -0
  110. package/dist/modules/SurchargeList/types.js +1 -0
  111. package/dist/modules/index.d.ts +3 -0
  112. package/dist/modules/index.js +4 -1
  113. package/dist/plugins/app.d.ts +2 -0
  114. package/dist/plugins/request.d.ts +1 -0
  115. package/dist/plugins/request.js +4 -1
  116. package/dist/plugins/window.js +6 -2
  117. package/dist/server/index.d.ts +462 -8
  118. package/dist/server/index.js +6168 -680
  119. package/dist/server/modules/floor-plan/index.d.ts +39 -0
  120. package/dist/server/modules/floor-plan/index.js +595 -0
  121. package/dist/server/modules/floor-plan/types.d.ts +43 -0
  122. package/dist/server/modules/floor-plan/types.js +13 -0
  123. package/dist/server/modules/index.d.ts +7 -2
  124. package/dist/server/modules/index.js +6 -0
  125. package/dist/server/modules/menu/index.js +41 -32
  126. package/dist/server/modules/order/index.d.ts +207 -14
  127. package/dist/server/modules/order/index.js +2328 -379
  128. package/dist/server/modules/order/types.d.ts +76 -5
  129. package/dist/server/modules/order/types.js +14 -1
  130. package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
  131. package/dist/server/modules/order/utils/filterBookings.js +118 -11
  132. package/dist/server/modules/order/utils/filterOrders.js +242 -14
  133. package/dist/server/modules/payment/index.d.ts +28 -0
  134. package/dist/server/modules/payment/index.js +305 -0
  135. package/dist/server/modules/payment/types.d.ts +9 -0
  136. package/dist/server/modules/payment/types.js +1 -0
  137. package/dist/server/modules/products/index.d.ts +105 -14
  138. package/dist/server/modules/products/index.js +1416 -521
  139. package/dist/server/modules/products/types.d.ts +34 -1
  140. package/dist/server/modules/products/types.js +4 -0
  141. package/dist/server/modules/quotation/index.d.ts +39 -0
  142. package/dist/server/modules/quotation/index.js +298 -77
  143. package/dist/server/modules/resource/index.d.ts +2 -3
  144. package/dist/server/modules/resource/index.js +109 -86
  145. package/dist/server/modules/schedule/index.d.ts +6 -4
  146. package/dist/server/modules/schedule/index.js +145 -106
  147. package/dist/server/test.json +713 -0
  148. package/dist/server/types.d.ts +2 -0
  149. package/dist/server/utils/product.js +3 -2
  150. package/dist/server/utils/small-ticket.d.ts +71 -0
  151. package/dist/server/utils/small-ticket.js +963 -0
  152. package/dist/solution/BaseSales/index.d.ts +378 -0
  153. package/dist/solution/BaseSales/index.js +4009 -0
  154. package/dist/solution/BaseSales/types.d.ts +394 -0
  155. package/dist/solution/BaseSales/types.js +40 -0
  156. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  157. package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
  158. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  159. package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
  160. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  161. package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
  162. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  163. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
  164. package/dist/solution/BaseSales/utils.d.ts +40 -0
  165. package/dist/solution/BaseSales/utils.js +263 -0
  166. package/dist/solution/BookingByStep/index.d.ts +1 -1
  167. package/dist/solution/BookingByStep/index.js +60 -11
  168. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  169. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  170. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  171. package/dist/solution/BookingTicket/index.d.ts +393 -24
  172. package/dist/solution/BookingTicket/index.js +2508 -443
  173. package/dist/solution/BookingTicket/types.d.ts +191 -6
  174. package/dist/solution/BookingTicket/types.js +83 -10
  175. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  176. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  177. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  178. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
  179. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  180. package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
  181. package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
  182. package/dist/solution/BookingTicket/utils/cartView.js +209 -0
  183. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  184. package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
  185. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  186. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  187. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  188. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
  189. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  190. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
  191. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  192. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +42 -1
  193. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  194. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  195. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  196. package/dist/solution/BookingTicket/utils/scan/handleScan.js +42 -28
  197. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  198. package/dist/solution/BookingTicket/utils/scan/index.js +30 -14
  199. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  200. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  201. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  202. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
  203. package/dist/solution/BuyTickets/index.js +12 -9
  204. package/dist/solution/Checkout/index.d.ts +1 -0
  205. package/dist/solution/Checkout/index.js +275 -209
  206. package/dist/solution/Checkout/utils/index.js +20 -8
  207. package/dist/solution/RegisterAndLogin/config.js +2 -10
  208. package/dist/solution/RegisterAndLogin/index.js +76 -30
  209. package/dist/solution/Sales/index.d.ts +50 -5
  210. package/dist/solution/Sales/index.js +484 -92
  211. package/dist/solution/Sales/types.d.ts +26 -2
  212. package/dist/solution/ScanOrder/index.d.ts +27 -21
  213. package/dist/solution/ScanOrder/index.js +519 -444
  214. package/dist/solution/ScanOrder/types.d.ts +33 -11
  215. package/dist/solution/ScanOrder/types.js +4 -5
  216. package/dist/solution/ScanOrder/utils.d.ts +4 -1
  217. package/dist/solution/ScanOrder/utils.js +109 -34
  218. package/dist/solution/ShopDiscount/index.js +18 -19
  219. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  220. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  221. package/dist/solution/ShopDiscount/utils.js +0 -9
  222. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  223. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  224. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  225. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  226. package/dist/solution/VenueBooking/index.d.ts +32 -51
  227. package/dist/solution/VenueBooking/index.js +741 -808
  228. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  229. package/dist/solution/VenueBooking/types.d.ts +1 -3
  230. package/dist/solution/VenueBooking/types.js +0 -1
  231. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  232. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  233. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  234. package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
  235. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  236. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  237. package/dist/solution/index.d.ts +2 -0
  238. package/dist/solution/index.js +3 -1
  239. package/dist/types/index.d.ts +12 -2
  240. package/dist/utils/task.js +18 -15
  241. package/dist/utils/watch.js +1 -0
  242. package/lib/apis/picoding.js +0 -2
  243. package/lib/core/index.js +132 -130
  244. package/lib/effects/index.js +57 -46
  245. package/lib/index.d.ts +0 -1
  246. package/lib/index.js +50 -92
  247. package/lib/model/index.js +21 -14
  248. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  249. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  250. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  251. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  252. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  253. package/lib/model/strategy/adapter/index.js +64 -100
  254. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  255. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  256. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  257. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  258. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  259. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  260. package/lib/model/strategy/adapter/promotion/evaluator.js +233 -382
  261. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  262. package/lib/model/strategy/adapter/promotion/index.js +0 -1
  263. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  264. package/lib/model/strategy/adapter/type.js +16 -4
  265. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  266. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  267. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  268. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  269. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  270. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  271. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  272. package/lib/model/strategy/adapter/walletPass/utils.js +383 -676
  273. package/lib/model/strategy/engine.js +168 -270
  274. package/lib/model/strategy/index.js +34 -49
  275. package/lib/model/strategy/strategy-example.js +239 -243
  276. package/lib/model/strategy/type.js +40 -100
  277. package/lib/modules/Account/index.js +53 -39
  278. package/lib/modules/Account/types.js +33 -20
  279. package/lib/modules/AccountList/index.js +154 -116
  280. package/lib/modules/AccountList/types.js +31 -30
  281. package/lib/modules/AccountList/utils.js +30 -18
  282. package/lib/modules/BaseModule.d.ts +2 -2
  283. package/lib/modules/BaseModule.js +50 -29
  284. package/lib/modules/BookingContext/index.d.ts +48 -0
  285. package/lib/modules/BookingContext/index.js +368 -0
  286. package/lib/modules/BookingContext/types.d.ts +102 -0
  287. package/lib/modules/BookingContext/types.js +34 -0
  288. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  289. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +298 -0
  290. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  291. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +155 -0
  292. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  293. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +222 -0
  294. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  295. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  296. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  297. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  298. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  299. package/lib/modules/BookingContext/utils/index.js +43 -0
  300. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  301. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  302. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  303. package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
  304. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  305. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  306. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  307. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  308. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  309. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  310. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  311. package/lib/modules/BookingContext/utils/resources.js +377 -0
  312. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  313. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  314. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  315. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  316. package/lib/modules/Cart/index.js +124 -170
  317. package/lib/modules/Cart/types.js +51 -46
  318. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  319. package/lib/modules/Cart/utils/cartDate.js +61 -56
  320. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  321. package/lib/modules/Cart/utils/cartNote.js +32 -27
  322. package/lib/modules/Cart/utils/cartProduct.js +261 -309
  323. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  324. package/lib/modules/Cart/utils/cartResource.js +78 -72
  325. package/lib/modules/Cart/utils/changePrice.js +59 -31
  326. package/lib/modules/Cart/utils/index.js +48 -106
  327. package/lib/modules/Customer/constants.js +34 -13
  328. package/lib/modules/Customer/index.d.ts +20 -0
  329. package/lib/modules/Customer/index.js +207 -217
  330. package/lib/modules/Customer/types.d.ts +2 -0
  331. package/lib/modules/Customer/types.js +35 -38
  332. package/lib/modules/Date/index.js +115 -116
  333. package/lib/modules/Date/types.js +28 -16
  334. package/lib/modules/Date/utils.js +123 -174
  335. package/lib/modules/Discount/index.d.ts +2 -2
  336. package/lib/modules/Discount/index.js +133 -119
  337. package/lib/modules/Discount/types.d.ts +1 -1
  338. package/lib/modules/Discount/types.js +31 -9
  339. package/lib/modules/Guests/index.js +56 -30
  340. package/lib/modules/Guests/types.js +33 -23
  341. package/lib/modules/Holder/index.js +189 -209
  342. package/lib/modules/Holder/types.js +16 -4
  343. package/lib/modules/Holder/utils.js +49 -20
  344. package/lib/modules/OpenData/index.d.ts +8 -0
  345. package/lib/modules/OpenData/index.js +88 -63
  346. package/lib/modules/OpenData/types.js +16 -4
  347. package/lib/modules/OpenData/utils.js +78 -44
  348. package/lib/modules/Order/index.d.ts +449 -24
  349. package/lib/modules/Order/index.js +4184 -514
  350. package/lib/modules/Order/types.d.ts +693 -88
  351. package/lib/modules/Order/types.js +35 -24
  352. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  353. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  354. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  355. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  356. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  357. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  358. package/lib/modules/Order/utils.d.ts +167 -18
  359. package/lib/modules/Order/utils.js +1085 -414
  360. package/lib/modules/Payment/cash.js +33 -20
  361. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  362. package/lib/modules/Payment/eftpos.js +30 -16
  363. package/lib/modules/Payment/index.d.ts +10 -9
  364. package/lib/modules/Payment/index.js +402 -636
  365. package/lib/modules/Payment/mx51.js +0 -1
  366. package/lib/modules/Payment/types.d.ts +44 -24
  367. package/lib/modules/Payment/types.js +107 -216
  368. package/lib/modules/Payment/utils.d.ts +1 -1
  369. package/lib/modules/Payment/utils.js +50 -52
  370. package/lib/modules/Payment/walletpass.d.ts +0 -2
  371. package/lib/modules/Payment/walletpass.js +216 -221
  372. package/lib/modules/Product/index.js +46 -51
  373. package/lib/modules/Product/types.d.ts +29 -7
  374. package/lib/modules/Product/types.js +16 -4
  375. package/lib/modules/Product/utils.js +33 -32
  376. package/lib/modules/ProductList/index.d.ts +17 -13
  377. package/lib/modules/ProductList/index.js +161 -120
  378. package/lib/modules/ProductList/types.d.ts +16 -0
  379. package/lib/modules/ProductList/types.js +31 -9
  380. package/lib/modules/Quotation/index.d.ts +22 -2
  381. package/lib/modules/Quotation/index.js +154 -64
  382. package/lib/modules/Quotation/types.d.ts +19 -0
  383. package/lib/modules/Quotation/types.js +16 -4
  384. package/lib/modules/Resource/index.js +59 -27
  385. package/lib/modules/Resource/types.js +32 -22
  386. package/lib/modules/Resource/utils.js +38 -30
  387. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  388. package/lib/modules/ResourcePlanner/index.js +148 -0
  389. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  390. package/lib/modules/ResourcePlanner/planner.js +933 -0
  391. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  392. package/lib/modules/ResourcePlanner/types.js +17 -0
  393. package/lib/modules/Rules/index.d.ts +8 -10
  394. package/lib/modules/Rules/index.js +960 -1440
  395. package/lib/modules/Rules/types.d.ts +14 -3
  396. package/lib/modules/Rules/types.js +40 -17
  397. package/lib/modules/SalesSummary/index.d.ts +23 -26
  398. package/lib/modules/SalesSummary/index.js +134 -61
  399. package/lib/modules/SalesSummary/types.d.ts +9 -1
  400. package/lib/modules/SalesSummary/types.js +16 -4
  401. package/lib/modules/SalesSummary/utils.d.ts +3 -22
  402. package/lib/modules/SalesSummary/utils.js +814 -233
  403. package/lib/modules/ScanOrderLogger/index.js +79 -59
  404. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  405. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  406. package/lib/modules/ScanOrderLogger/types.js +16 -4
  407. package/lib/modules/Schedule/getDateIsInSchedule.js +169 -338
  408. package/lib/modules/Schedule/index.d.ts +18 -5
  409. package/lib/modules/Schedule/index.js +153 -104
  410. package/lib/modules/Schedule/type.js +16 -4
  411. package/lib/modules/Schedule/types.d.ts +2 -0
  412. package/lib/modules/Schedule/types.js +16 -4
  413. package/lib/modules/Schedule/utils.js +291 -433
  414. package/lib/modules/Step/index.js +52 -40
  415. package/lib/modules/Step/tyeps.js +16 -4
  416. package/lib/modules/Summary/index.js +71 -66
  417. package/lib/modules/Summary/types.js +16 -4
  418. package/lib/modules/Summary/utils.js +418 -791
  419. package/lib/modules/SurchargeList/index.d.ts +18 -0
  420. package/lib/modules/SurchargeList/index.js +109 -0
  421. package/lib/modules/SurchargeList/types.d.ts +15 -0
  422. package/lib/modules/SurchargeList/types.js +17 -0
  423. package/lib/modules/index.d.ts +3 -0
  424. package/lib/modules/index.js +63 -212
  425. package/lib/plugins/app.d.ts +2 -0
  426. package/lib/plugins/app.js +16 -4
  427. package/lib/plugins/index.js +25 -36
  428. package/lib/plugins/request.d.ts +1 -0
  429. package/lib/plugins/request.js +126 -137
  430. package/lib/plugins/shopStore.js +16 -4
  431. package/lib/plugins/user.js +16 -4
  432. package/lib/plugins/window.js +179 -171
  433. package/lib/server/index.d.ts +462 -8
  434. package/lib/server/index.js +4520 -1162
  435. package/lib/server/modules/floor-plan/index.d.ts +39 -0
  436. package/lib/server/modules/floor-plan/index.js +327 -0
  437. package/lib/server/modules/floor-plan/types.d.ts +43 -0
  438. package/lib/server/modules/floor-plan/types.js +34 -0
  439. package/lib/server/modules/index.d.ts +7 -2
  440. package/lib/server/modules/index.js +67 -84
  441. package/lib/server/modules/menu/index.js +122 -146
  442. package/lib/server/modules/menu/types.js +31 -18
  443. package/lib/server/modules/order/index.d.ts +207 -14
  444. package/lib/server/modules/order/index.js +1543 -285
  445. package/lib/server/modules/order/types.d.ts +76 -5
  446. package/lib/server/modules/order/types.js +32 -107
  447. package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
  448. package/lib/server/modules/order/utils/filterBookings.js +259 -176
  449. package/lib/server/modules/order/utils/filterOrders.js +293 -94
  450. package/lib/server/modules/payment/index.d.ts +28 -0
  451. package/lib/server/modules/payment/index.js +192 -0
  452. package/lib/server/modules/payment/types.d.ts +9 -0
  453. package/lib/server/modules/payment/types.js +17 -0
  454. package/lib/server/modules/products/index.d.ts +105 -14
  455. package/lib/server/modules/products/index.js +850 -475
  456. package/lib/server/modules/products/types.d.ts +34 -1
  457. package/lib/server/modules/products/types.js +34 -41
  458. package/lib/server/modules/quotation/index.d.ts +39 -0
  459. package/lib/server/modules/quotation/index.js +254 -75
  460. package/lib/server/modules/quotation/types.js +31 -21
  461. package/lib/server/modules/resource/index.d.ts +2 -3
  462. package/lib/server/modules/resource/index.js +240 -243
  463. package/lib/server/modules/resource/types.js +33 -42
  464. package/lib/server/modules/schedule/index.d.ts +6 -4
  465. package/lib/server/modules/schedule/index.js +146 -147
  466. package/lib/server/modules/schedule/types.js +21 -14
  467. package/lib/server/modules/schedule/utils.js +163 -334
  468. package/lib/server/test.json +713 -0
  469. package/lib/server/types.d.ts +2 -0
  470. package/lib/server/types.js +16 -4
  471. package/lib/server/utils/index.js +23 -25
  472. package/lib/server/utils/product.js +140 -197
  473. package/lib/server/utils/schedule.js +41 -34
  474. package/lib/server/utils/small-ticket.d.ts +71 -0
  475. package/lib/server/utils/small-ticket.js +904 -0
  476. package/lib/server/utils/time.js +49 -40
  477. package/lib/solution/BaseSales/index.d.ts +378 -0
  478. package/lib/solution/BaseSales/index.js +2533 -0
  479. package/lib/solution/BaseSales/types.d.ts +394 -0
  480. package/lib/solution/BaseSales/types.js +43 -0
  481. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  482. package/lib/solution/BaseSales/utils/cartPromotion.js +1004 -0
  483. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  484. package/lib/solution/BaseSales/utils/parseSalesResponse.js +160 -0
  485. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  486. package/lib/solution/BaseSales/utils/quotationPrice.js +289 -0
  487. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  488. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +256 -0
  489. package/lib/solution/BaseSales/utils.d.ts +40 -0
  490. package/lib/solution/BaseSales/utils.js +244 -0
  491. package/lib/solution/BookingByStep/index.d.ts +1 -1
  492. package/lib/solution/BookingByStep/index.js +1340 -1530
  493. package/lib/solution/BookingByStep/types.js +99 -40
  494. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  495. package/lib/solution/BookingByStep/utils/products.js +52 -42
  496. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  497. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  498. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  499. package/lib/solution/BookingTicket/index.d.ts +393 -24
  500. package/lib/solution/BookingTicket/index.js +1374 -184
  501. package/lib/solution/BookingTicket/types.d.ts +191 -6
  502. package/lib/solution/BookingTicket/types.js +79 -40
  503. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  504. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  505. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  506. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
  507. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  508. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -0
  509. package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
  510. package/lib/solution/BookingTicket/utils/cartView.js +184 -0
  511. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  512. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  513. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  514. package/lib/solution/BookingTicket/utils/orderCustomer.js +58 -0
  515. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  516. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
  517. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  518. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
  519. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  520. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +97 -64
  521. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  522. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
  523. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  524. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -82
  525. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  526. package/lib/solution/BookingTicket/utils/scan/index.js +109 -91
  527. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  528. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  529. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
  530. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  531. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
  532. package/lib/solution/BuyTickets/index.js +70 -67
  533. package/lib/solution/BuyTickets/types.js +38 -22
  534. package/lib/solution/Checkout/index.d.ts +1 -0
  535. package/lib/solution/Checkout/index.js +1169 -1463
  536. package/lib/solution/Checkout/types.js +61 -91
  537. package/lib/solution/Checkout/utils/index.js +156 -228
  538. package/lib/solution/PlaceOrder/index.js +0 -55
  539. package/lib/solution/RegisterAndLogin/config.js +462 -503
  540. package/lib/solution/RegisterAndLogin/index.js +630 -633
  541. package/lib/solution/RegisterAndLogin/types.js +76 -189
  542. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  543. package/lib/solution/Sales/index.d.ts +50 -5
  544. package/lib/solution/Sales/index.js +498 -238
  545. package/lib/solution/Sales/types.d.ts +26 -2
  546. package/lib/solution/Sales/types.js +33 -27
  547. package/lib/solution/ScanOrder/index.d.ts +27 -21
  548. package/lib/solution/ScanOrder/index.js +936 -864
  549. package/lib/solution/ScanOrder/types.d.ts +33 -11
  550. package/lib/solution/ScanOrder/types.js +34 -34
  551. package/lib/solution/ScanOrder/utils.d.ts +4 -1
  552. package/lib/solution/ScanOrder/utils.js +422 -385
  553. package/lib/solution/ShopDiscount/index.js +233 -235
  554. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  555. package/lib/solution/ShopDiscount/types.js +37 -15
  556. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  557. package/lib/solution/ShopDiscount/utils.js +172 -309
  558. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  559. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  560. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  561. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  562. package/lib/solution/VenueBooking/index.d.ts +32 -51
  563. package/lib/solution/VenueBooking/index.js +1008 -984
  564. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  565. package/lib/solution/VenueBooking/types.d.ts +1 -3
  566. package/lib/solution/VenueBooking/types.js +39 -20
  567. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  568. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  569. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  570. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  571. package/lib/solution/VenueBooking/utils/slotMerge.js +109 -90
  572. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  573. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  574. package/lib/solution/VenueBooking/utils.js +67 -130
  575. package/lib/solution/index.d.ts +2 -0
  576. package/lib/solution/index.js +41 -102
  577. package/lib/store/createStore.js +29 -32
  578. package/lib/types/index.d.ts +12 -2
  579. package/lib/types/index.js +16 -4
  580. package/lib/utils/task.js +36 -36
  581. package/lib/utils/watch.js +47 -81
  582. package/package.json +2 -4
  583. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  584. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  585. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  586. package/lib/solution/Checkout/appointmentDemo.json +0 -1
  587. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  588. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -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,61 +686,204 @@ 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
- var surchargeRoundingRemainder = toDecimal(product.surcharge_rounding_remainder);
275
- var surchargeFee = toDecimal(product.surcharge_fee).plus(quantity.gt(0) ? surchargeRoundingRemainder.div(quantity) : 0);
886
+ var surchargeFee = toDecimal(product.surcharge_fee);
276
887
  var mainTaxableBase = mainTotal.lte(0) ? surchargeFee : mainTotal.plus(surchargeFee);
277
888
  var mainTaxPrecise = calculateSingleItemTax({
278
889
  price: mainTaxableBase,
@@ -280,15 +891,23 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
280
891
  isPriceIncludeTax: isPriceIncludeTax,
281
892
  isChargeTax: (_product$is_charge_ta2 = product.is_charge_tax) !== null && _product$is_charge_ta2 !== void 0 ? _product$is_charge_ta2 : 0
282
893
  });
283
- var mainTaxRounded = mainTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
284
- if (mainTaxPrecise.gt(0)) {
285
- lastTaxableItem = {
286
- type: 'main',
287
- item: product
288
- };
894
+ var mainTaxRounded = toBackendTaxFee(mainTaxPrecise);
895
+ var persistedMainRemainder = getPersistedTaxRemainder(product);
896
+ var persistedMainTaxFee = getPersistedMainTaxFee(product);
897
+ var persistedQuantity = getPersistedQuantity(product, quantity);
898
+ var deltaQuantity = Decimal.max(quantity.minus(persistedQuantity), 0);
899
+ var shouldUsePersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gte(quantity);
900
+ var shouldSplitPersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gt(0) && deltaQuantity.gt(0);
901
+ var mainRemainder = shouldUsePersistedMainTax || shouldSplitPersistedMainTax ? new Decimal(0) : persistedMainRemainder !== null && persistedMainRemainder !== void 0 ? persistedMainRemainder : applyBackendTaxRemainder({
902
+ target: product,
903
+ rawTax: mainTaxPrecise,
904
+ formattedTax: mainTaxRounded,
905
+ quantity: quantity,
906
+ state: taxRemainderState
907
+ });
908
+ if (persistedMainRemainder && !shouldSplitPersistedMainTax) {
909
+ writeTaxRemainder(product, persistedMainRemainder);
289
910
  }
290
-
291
- // --- 主商品原价税费 ---
292
911
  var originalTotal = getUnitOriginalTotal(product);
293
912
  var originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
294
913
  var originalTaxPrecise = calculateSingleItemTax({
@@ -297,92 +916,91 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
297
916
  isPriceIncludeTax: isPriceIncludeTax,
298
917
  isChargeTax: (_product$is_charge_ta3 = product.is_charge_tax) !== null && _product$is_charge_ta3 !== void 0 ? _product$is_charge_ta3 : 0
299
918
  });
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();
919
+ var originalTaxRounded = toAmountFormat(originalTaxPrecise);
920
+ var effectiveMainUnitTax = shouldUsePersistedMainTax ? persistedMainTaxFee : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)).div(quantity).toDecimalPlaces(2, Decimal.ROUND_HALF_UP) : mainTaxRounded;
921
+ productUnitTax = productUnitTax.plus(effectiveMainUnitTax);
922
+ productUnitOriginTax = productUnitOriginTax.plus(originalTaxRounded);
923
+ product.main_product_attached_bundle_tax_fee = effectiveMainUnitTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
924
+ product.tax_fee = productUnitTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
925
+ product.original_tax_fee = productUnitOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
926
+ totalTax = totalTax.plus(shouldUsePersistedMainTax ? persistedMainTaxFee.times(quantity).plus(persistedMainRemainder || 0) : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)) : mainTaxRounded.times(quantity).plus(mainRemainder));
927
+ totalOriginTax = totalOriginTax.plus(originalTaxRounded.times(quantity));
928
+ if (product.tax_fee_rounding_remainder === undefined) {
929
+ product.tax_fee_rounding_remainder = 0;
350
930
  }
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
931
  }
362
-
363
- // --- 舍入差值处理 ---
364
932
  } catch (err) {
365
- _iterator6.e(err);
933
+ _iterator17.e(err);
366
934
  } 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
- }
935
+ _iterator17.f();
380
936
  }
381
937
  return {
382
- tax: expectedTax,
383
- originTax: expectedOriginTax
938
+ tax: totalTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP),
939
+ originTax: totalOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP)
384
940
  };
385
941
  }
942
+
943
+ /**
944
+ * 整单折扣(shop_discount)按各行 selling 合计占比均摊到 payment 维度。
945
+ *
946
+ * 文档口径:
947
+ * - payment_price = selling_price − 整单折扣均摊;rate = payment/selling(全行同一 rate);
948
+ * - 附加费不受整单折扣影响(基数仍用 selling,本函数写 main_product_attached_bundle_selling_price);
949
+ * - 税费受整单折扣影响(基数用 payment,本函数写 main_product_attached_bundle_payment_price 与
950
+ * 原价子商品 bundle_payment_price)。
951
+ *
952
+ * 与后端一致:bundle_payment_price = bundle_selling_price × rate,
953
+ * main_product_attached_bundle_payment_price = main_product_attached_bundle_selling_price × rate。
954
+ */
955
+ function allocateShopDiscountToPayment(products, productAmount, shopDiscountAmount) {
956
+ var effectiveDiscount = productAmount.lte(0) ? new Decimal(0) : Decimal.max(Decimal.min(productAmount, shopDiscountAmount), 0);
957
+ var allocatedDiscount = new Decimal(0);
958
+ products.forEach(function (product, index) {
959
+ var quantity = new Decimal(getSafeNum(product.num));
960
+ var sellingUnit = getUnitPaymentTotal(product);
961
+ var lineSellingTotal = sellingUnit.times(quantity);
962
+ var lineDiscount = effectiveDiscount.lte(0) ? new Decimal(0) : index === products.length - 1 ? Decimal.max(effectiveDiscount.minus(allocatedDiscount), 0) : toAmountFormat(lineSellingTotal.div(productAmount).times(effectiveDiscount));
963
+ allocatedDiscount = allocatedDiscount.plus(lineDiscount);
964
+ var unitDiscount = quantity.lte(0) ? new Decimal(0) : lineDiscount.div(quantity);
965
+ var paymentUnit = Decimal.max(sellingUnit.minus(unitDiscount), 0);
966
+ var rate = sellingUnit.lte(0) ? new Decimal(1) : toBcScale(paymentUnit.div(sellingUnit), 6);
967
+ var mainSellingTotal = getMainAttachedBundleSellingTotal(product);
968
+ var mainPaymentTotal = toAmountFormat(bcMul(mainSellingTotal, rate, 6));
969
+ product.metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
970
+ average_discount_amount_rate: rate.toString(),
971
+ main_product_attached_bundle_selling_price: mainSellingTotal.toFixed(2),
972
+ main_product_attached_bundle_payment_price: mainPaymentTotal.toFixed(2)
973
+ });
974
+ var _iterator19 = _createForOfIteratorHelper(product.product_bundle || []),
975
+ _step19;
976
+ try {
977
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
978
+ var bundle = _step19.value;
979
+ // 原价子商品:bundle_payment_price = bundle_selling_price × rate
980
+ // markdown 子商品:以净额幅度 × rate(与后端一致,存正净额)
981
+ if (isBundleOriginalPrice(bundle)) {
982
+ var _ref16, _ref17, _bundle$bundle_sellin3;
983
+ 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);
984
+ bundle.bundle_payment_price = toAmountFormat(bcMul(bundleSelling, rate, 6)).toFixed(2);
985
+ continue;
986
+ }
987
+ if (isMarkdownBundle(bundle)) {
988
+ var _bundle$custom_price;
989
+ var magnitude = getBundleSellingMagnitude(bundle);
990
+ bundle.custom_price = (_bundle$custom_price = bundle.custom_price) !== null && _bundle$custom_price !== void 0 ? _bundle$custom_price : bundle.price;
991
+ bundle.price = magnitude.toFixed(2);
992
+ bundle.bundle_selling_price = magnitude.toFixed(2);
993
+ bundle.bundle_payment_price = toAmountFormat(bcMul(magnitude, rate, 6)).toFixed(2);
994
+ }
995
+ }
996
+ } catch (err) {
997
+ _iterator19.e(err);
998
+ } finally {
999
+ _iterator19.f();
1000
+ }
1001
+ product.payment_price = paymentUnit.toFixed(2);
1002
+ });
1003
+ }
386
1004
  export function createEmptySalesSummary() {
387
1005
  return {
388
1006
  product_quantity: 0,
@@ -399,6 +1017,9 @@ export function createEmptySalesSummary() {
399
1017
  deposit_amount: '0.00',
400
1018
  expect_amount: '0.00',
401
1019
  total_amount: '0.00',
1020
+ total_refund_amount: '0.00',
1021
+ customer_paid_amount: '0.00',
1022
+ order_paid_amount: '0.00',
402
1023
  amount_gap: '0.00',
403
1024
  rounding_amount: '0.00',
404
1025
  pay_service_charge_amount: '0.00'
@@ -411,19 +1032,34 @@ export function calculateSalesSummary(params) {
411
1032
  surchargeList = params.surchargeList,
412
1033
  _params$scheduleById = params.scheduleById,
413
1034
  scheduleById = _params$scheduleById === void 0 ? {} : _params$scheduleById,
414
- isInScheduleByDate = params.isInScheduleByDate;
1035
+ isInScheduleByDate = params.isInScheduleByDate,
1036
+ shopDiscount = params.shopDiscount;
415
1037
  if (!(products !== null && products !== void 0 && products.length)) return createEmptySalesSummary();
416
- var productQuantity = products.reduce(function (sum, item) {
1038
+ var summaryProducts = products.filter(function (product) {
1039
+ return !isGeneratedVoucherProduct(product);
1040
+ });
1041
+ if (!summaryProducts.length) return createEmptySalesSummary();
1042
+ var productQuantity = summaryProducts.reduce(function (sum, item) {
417
1043
  return sum + getSafeNum(item.num);
418
1044
  }, 0);
419
- var productOriginalAmount = products.reduce(function (sum, item) {
1045
+ var productOriginalAmount = summaryProducts.reduce(function (sum, item) {
420
1046
  return sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num)));
421
1047
  }, new Decimal(0));
422
- var productAmount = products.reduce(function (sum, item) {
1048
+ var productAmount = summaryProducts.reduce(function (sum, item) {
423
1049
  return sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num)));
424
1050
  }, new Decimal(0));
425
- var surchargeServiceItems = buildSurchargeServiceItems(products);
426
- var surcharge = getSurcharge({
1051
+ var shopDiscountAmount = Decimal.max(new Decimal(Number(shopDiscount) || 0), 0);
1052
+ var hasPersistedSurchargeSnapshot = summaryProducts.some(function (product) {
1053
+ var _getPersistedMainSurc;
1054
+ return (_getPersistedMainSurc = getPersistedMainSurchargeFee(product)) === null || _getPersistedMainSurc === void 0 ? void 0 : _getPersistedMainSurc.gt(0);
1055
+ });
1056
+ // 整单折扣均摊:附加费基数用 selling(不受折扣),税费基数用 payment(受折扣)。
1057
+ // persisted 快照(已下单编辑)优先采信后端回传值,不重算均摊。
1058
+ if (!hasPersistedSurchargeSnapshot) {
1059
+ allocateShopDiscountToPayment(summaryProducts, productAmount, shopDiscountAmount);
1060
+ }
1061
+ var surchargeServiceItems = buildSurchargeServiceItems(summaryProducts);
1062
+ getSurcharge({
427
1063
  service: surchargeServiceItems,
428
1064
  addons: [],
429
1065
  bookingDetail: null,
@@ -434,30 +1070,30 @@ export function calculateSalesSummary(params) {
434
1070
  surcharge_list: surchargeList,
435
1071
  scheduleById: scheduleById
436
1072
  });
1073
+ var surcharge = calculateBackendProductSurcharges({
1074
+ products: summaryProducts,
1075
+ sourceItems: surchargeServiceItems,
1076
+ surchargeList: surchargeList
1077
+ });
437
1078
  var surchargeAmount = new Decimal(getSurchargeAmount({
438
1079
  bookingDetail: null,
439
1080
  bookingId: undefined
440
1081
  }, surcharge, {
441
1082
  isEdit: false
442
1083
  }) || 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
1084
  var hasTaxRate = taxRate !== undefined && taxRate !== null && taxRate > 0;
449
1085
  var productTaxFee;
450
1086
  if (hasTaxRate) {
451
- var taxResult = calculateProductsTax(products, taxRate, isPriceIncludeTax);
1087
+ var taxResult = calculateProductsTax(summaryProducts, taxRate, isPriceIncludeTax);
452
1088
  productTaxFee = taxResult.tax;
453
1089
  } else {
454
- productTaxFee = products.reduce(function (sum, item) {
1090
+ productTaxFee = summaryProducts.reduce(function (sum, item) {
455
1091
  return sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num)));
456
1092
  }, new Decimal(0));
457
1093
  }
458
- var expectAmount = productAmount.plus(surchargeAmount);
459
- var totalAmount = isPriceIncludeTax === 1 ? expectAmount : expectAmount.plus(productTaxFee);
460
- var deposit = calculateProductsDeposit(products);
1094
+ var orderAmountBeforeDiscount = productAmount.plus(surchargeAmount).plus(isPriceIncludeTax === 1 ? 0 : productTaxFee);
1095
+ var totalAmount = Decimal.max(0, orderAmountBeforeDiscount.minus(shopDiscountAmount));
1096
+ var deposit = calculateProductsDeposit(summaryProducts);
461
1097
  return {
462
1098
  product_quantity: productQuantity,
463
1099
  product_original_amount: toFixed2(productOriginalAmount),
@@ -469,11 +1105,14 @@ export function calculateSalesSummary(params) {
469
1105
  tax_fee: toFixed2(productTaxFee),
470
1106
  surcharge_fee: toFixed2(surchargeAmount),
471
1107
  surcharges: surcharge,
472
- discount_amount: toFixed2(Decimal.max(productOriginalAmount.minus(productAmount), 0)),
1108
+ discount_amount: toFixed2(shopDiscountAmount),
473
1109
  deposit_amount: deposit ? deposit.total : '0.00',
474
1110
  deposit: deposit,
475
- expect_amount: toFixed2(expectAmount),
1111
+ expect_amount: toFixed2(totalAmount),
476
1112
  total_amount: toFixed2(totalAmount),
1113
+ total_refund_amount: '0.00',
1114
+ customer_paid_amount: '0.00',
1115
+ order_paid_amount: '0.00',
477
1116
  amount_gap: '0.00',
478
1117
  rounding_amount: '0.00',
479
1118
  pay_service_charge_amount: '0.00',