@pisell/pisellos 2.2.243 → 2.2.244

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 (315) hide show
  1. package/dist/model/strategy/adapter/promotion/evaluator.js +2 -3
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/model/strategy/adapter/walletPass/utils.js +4 -7
  4. package/dist/modules/Cart/utils/cartProduct.js +3 -24
  5. package/dist/modules/Cart/utils/changePrice.js +11 -11
  6. package/dist/modules/Customer/index.d.ts +0 -20
  7. package/dist/modules/Customer/index.js +83 -172
  8. package/dist/modules/Customer/types.d.ts +0 -2
  9. package/dist/modules/Discount/index.js +3 -4
  10. package/dist/modules/Discount/types.d.ts +0 -1
  11. package/dist/modules/OpenData/index.d.ts +0 -8
  12. package/dist/modules/OpenData/index.js +17 -37
  13. package/dist/modules/Order/index.d.ts +18 -268
  14. package/dist/modules/Order/index.js +757 -3306
  15. package/dist/modules/Order/types.d.ts +31 -279
  16. package/dist/modules/Order/types.js +0 -38
  17. package/dist/modules/Order/utils.d.ts +5 -147
  18. package/dist/modules/Order/utils.js +103 -746
  19. package/dist/modules/Payment/index.d.ts +13 -10
  20. package/dist/modules/Payment/index.js +837 -467
  21. package/dist/modules/Payment/types.d.ts +0 -2
  22. package/dist/modules/Payment/utils.js +1 -2
  23. package/dist/modules/Payment/walletpass.js +7 -14
  24. package/dist/modules/ProductList/index.d.ts +12 -16
  25. package/dist/modules/ProductList/index.js +59 -133
  26. package/dist/modules/ProductList/types.d.ts +0 -14
  27. package/dist/modules/Quotation/index.d.ts +1 -0
  28. package/dist/modules/Quotation/index.js +22 -25
  29. package/dist/modules/Rules/index.d.ts +0 -4
  30. package/dist/modules/Rules/index.js +69 -93
  31. package/dist/modules/Rules/types.d.ts +0 -1
  32. package/dist/modules/SalesSummary/index.d.ts +25 -8
  33. package/dist/modules/SalesSummary/index.js +35 -86
  34. package/dist/modules/SalesSummary/types.d.ts +1 -4
  35. package/dist/modules/SalesSummary/utils.d.ts +25 -2
  36. package/dist/modules/SalesSummary/utils.js +162 -794
  37. package/dist/modules/Schedule/index.d.ts +0 -7
  38. package/dist/modules/Schedule/index.js +2 -24
  39. package/dist/modules/Summary/index.js +3 -4
  40. package/dist/modules/index.d.ts +0 -2
  41. package/dist/modules/index.js +1 -3
  42. package/dist/plugins/request.d.ts +0 -1
  43. package/dist/server/index.d.ts +1 -204
  44. package/dist/server/index.js +928 -3658
  45. package/dist/server/modules/index.d.ts +0 -2
  46. package/dist/server/modules/index.js +0 -2
  47. package/dist/server/modules/order/index.d.ts +4 -120
  48. package/dist/server/modules/order/index.js +483 -1779
  49. package/dist/server/modules/order/types.d.ts +3 -32
  50. package/dist/server/modules/order/types.js +0 -8
  51. package/dist/server/modules/order/utils/filterBookings.js +3 -26
  52. package/dist/server/modules/order/utils/filterOrders.js +8 -23
  53. package/dist/server/modules/products/index.d.ts +7 -34
  54. package/dist/server/modules/products/index.js +317 -631
  55. package/dist/server/modules/resource/index.d.ts +0 -2
  56. package/dist/server/modules/resource/index.js +3 -29
  57. package/dist/server/modules/schedule/index.d.ts +4 -4
  58. package/dist/server/modules/schedule/index.js +88 -111
  59. package/dist/solution/BaseSales/index.d.ts +9 -131
  60. package/dist/solution/BaseSales/index.js +447 -1944
  61. package/dist/solution/BaseSales/types.d.ts +6 -76
  62. package/dist/solution/BaseSales/types.js +4 -5
  63. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
  64. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -105
  65. package/dist/solution/BaseSales/utils.d.ts +1 -1
  66. package/dist/solution/BaseSales/utils.js +21 -62
  67. package/dist/solution/BookingByStep/index.d.ts +1 -1
  68. package/dist/solution/BookingTicket/index.d.ts +10 -270
  69. package/dist/solution/BookingTicket/index.js +237 -1772
  70. package/dist/solution/BookingTicket/types.d.ts +1 -118
  71. package/dist/solution/BookingTicket/types.js +2 -41
  72. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
  73. package/dist/solution/BookingTicket/utils/bookingStatus.js +0 -70
  74. package/dist/solution/BookingTicket/utils/cartView.d.ts +1 -9
  75. package/dist/solution/BookingTicket/utils/cartView.js +7 -94
  76. package/dist/solution/BookingTicket/utils/scan/index.d.ts +0 -5
  77. package/dist/solution/BookingTicket/utils/scan/index.js +8 -20
  78. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  79. package/dist/solution/Checkout/index.d.ts +0 -1
  80. package/dist/solution/Checkout/index.js +9 -10
  81. package/dist/solution/RegisterAndLogin/config.js +10 -2
  82. package/dist/solution/ScanOrder/index.d.ts +3 -9
  83. package/dist/solution/ScanOrder/index.js +134 -241
  84. package/dist/solution/ScanOrder/types.d.ts +5 -9
  85. package/dist/solution/ScanOrder/types.js +3 -2
  86. package/dist/solution/ScanOrder/utils.d.ts +1 -1
  87. package/dist/solution/ScanOrder/utils.js +22 -84
  88. package/dist/solution/VenueBooking/index.d.ts +2 -5
  89. package/dist/solution/VenueBooking/index.js +59 -110
  90. package/dist/solution/VenueBooking/sales-section-4-annotated.json +2 -0
  91. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  92. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
  93. package/dist/types/index.d.ts +0 -10
  94. package/lib/model/strategy/adapter/promotion/evaluator.js +1 -2
  95. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  96. package/lib/model/strategy/adapter/walletPass/utils.js +2 -3
  97. package/lib/modules/Cart/utils/cartProduct.js +3 -20
  98. package/lib/modules/Cart/utils/changePrice.js +20 -12
  99. package/lib/modules/Customer/index.d.ts +0 -20
  100. package/lib/modules/Customer/index.js +11 -64
  101. package/lib/modules/Customer/types.d.ts +0 -2
  102. package/lib/modules/Discount/index.js +1 -5
  103. package/lib/modules/Discount/types.d.ts +0 -1
  104. package/lib/modules/OpenData/index.d.ts +0 -8
  105. package/lib/modules/OpenData/index.js +5 -19
  106. package/lib/modules/Order/index.d.ts +18 -268
  107. package/lib/modules/Order/index.js +344 -2149
  108. package/lib/modules/Order/types.d.ts +31 -279
  109. package/lib/modules/Order/types.js +0 -1
  110. package/lib/modules/Order/utils.d.ts +5 -147
  111. package/lib/modules/Order/utils.js +46 -614
  112. package/lib/modules/Payment/index.d.ts +13 -10
  113. package/lib/modules/Payment/index.js +150 -18
  114. package/lib/modules/Payment/types.d.ts +0 -2
  115. package/lib/modules/Payment/utils.js +1 -2
  116. package/lib/modules/Payment/walletpass.js +3 -7
  117. package/lib/modules/ProductList/index.d.ts +12 -16
  118. package/lib/modules/ProductList/index.js +4 -41
  119. package/lib/modules/ProductList/types.d.ts +0 -14
  120. package/lib/modules/Quotation/index.d.ts +1 -0
  121. package/lib/modules/Quotation/index.js +16 -19
  122. package/lib/modules/Rules/index.d.ts +0 -4
  123. package/lib/modules/Rules/index.js +120 -136
  124. package/lib/modules/Rules/types.d.ts +0 -1
  125. package/lib/modules/SalesSummary/index.d.ts +25 -8
  126. package/lib/modules/SalesSummary/index.js +4 -30
  127. package/lib/modules/SalesSummary/types.d.ts +1 -4
  128. package/lib/modules/SalesSummary/utils.d.ts +25 -2
  129. package/lib/modules/SalesSummary/utils.js +91 -645
  130. package/lib/modules/Schedule/index.d.ts +0 -7
  131. package/lib/modules/Schedule/index.js +1 -17
  132. package/lib/modules/Summary/index.js +4 -5
  133. package/lib/modules/index.d.ts +0 -2
  134. package/lib/modules/index.js +1 -5
  135. package/lib/plugins/request.d.ts +0 -1
  136. package/lib/server/index.d.ts +1 -204
  137. package/lib/server/index.js +57 -1888
  138. package/lib/server/modules/index.d.ts +0 -2
  139. package/lib/server/modules/index.js +0 -3
  140. package/lib/server/modules/order/index.d.ts +4 -120
  141. package/lib/server/modules/order/index.js +142 -919
  142. package/lib/server/modules/order/types.d.ts +3 -32
  143. package/lib/server/modules/order/utils/filterBookings.js +5 -24
  144. package/lib/server/modules/order/utils/filterOrders.js +6 -15
  145. package/lib/server/modules/products/index.d.ts +7 -34
  146. package/lib/server/modules/products/index.js +54 -189
  147. package/lib/server/modules/resource/index.d.ts +0 -2
  148. package/lib/server/modules/resource/index.js +3 -27
  149. package/lib/server/modules/schedule/index.d.ts +4 -4
  150. package/lib/server/modules/schedule/index.js +40 -47
  151. package/lib/solution/BaseSales/index.d.ts +9 -131
  152. package/lib/solution/BaseSales/index.js +63 -1106
  153. package/lib/solution/BaseSales/types.d.ts +6 -76
  154. package/lib/solution/BaseSales/types.js +1 -3
  155. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
  156. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +18 -106
  157. package/lib/solution/BaseSales/utils.d.ts +1 -1
  158. package/lib/solution/BaseSales/utils.js +10 -54
  159. package/lib/solution/BookingByStep/index.d.ts +1 -1
  160. package/lib/solution/BookingTicket/index.d.ts +10 -270
  161. package/lib/solution/BookingTicket/index.js +29 -922
  162. package/lib/solution/BookingTicket/types.d.ts +1 -118
  163. package/lib/solution/BookingTicket/types.js +0 -11
  164. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
  165. package/lib/solution/BookingTicket/utils/bookingStatus.js +2 -44
  166. package/lib/solution/BookingTicket/utils/cartView.d.ts +1 -9
  167. package/lib/solution/BookingTicket/utils/cartView.js +6 -61
  168. package/lib/solution/BookingTicket/utils/scan/index.d.ts +0 -5
  169. package/lib/solution/BookingTicket/utils/scan/index.js +3 -17
  170. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  171. package/lib/solution/Checkout/index.d.ts +0 -1
  172. package/lib/solution/Checkout/index.js +2 -1
  173. package/lib/solution/RegisterAndLogin/config.js +10 -2
  174. package/lib/solution/ScanOrder/index.d.ts +3 -9
  175. package/lib/solution/ScanOrder/index.js +70 -153
  176. package/lib/solution/ScanOrder/types.d.ts +5 -9
  177. package/lib/solution/ScanOrder/utils.d.ts +1 -1
  178. package/lib/solution/ScanOrder/utils.js +17 -83
  179. package/lib/solution/VenueBooking/index.d.ts +2 -5
  180. package/lib/solution/VenueBooking/index.js +17 -54
  181. package/lib/solution/VenueBooking/sales-section-4-annotated.json +2 -0
  182. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  183. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  184. package/lib/types/index.d.ts +0 -10
  185. package/package.json +1 -1
  186. package/dist/modules/BookingContext/index.d.ts +0 -48
  187. package/dist/modules/BookingContext/index.js +0 -566
  188. package/dist/modules/BookingContext/types.d.ts +0 -102
  189. package/dist/modules/BookingContext/types.js +0 -51
  190. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  191. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -284
  192. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  193. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -145
  194. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
  195. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -218
  196. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  197. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  198. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  199. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  200. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  201. package/dist/modules/BookingContext/utils/index.js +0 -11
  202. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  203. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  204. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
  205. package/dist/modules/BookingContext/utils/orderLineDisplay.js +0 -36
  206. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  207. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  208. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  209. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  210. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  211. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  212. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  213. package/dist/modules/BookingContext/utils/resources.js +0 -486
  214. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  215. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  216. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  217. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  218. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  219. package/dist/modules/Order/utils/manualProductDiscount.js +0 -210
  220. package/dist/modules/SurchargeList/index.d.ts +0 -16
  221. package/dist/modules/SurchargeList/index.js +0 -162
  222. package/dist/modules/SurchargeList/types.d.ts +0 -11
  223. package/dist/modules/SurchargeList/types.js +0 -1
  224. package/dist/server/modules/payment/index.d.ts +0 -28
  225. package/dist/server/modules/payment/index.js +0 -305
  226. package/dist/server/modules/payment/types.d.ts +0 -9
  227. package/dist/server/modules/payment/types.js +0 -1
  228. package/dist/server/test.json +0 -713
  229. package/dist/server/utils/small-ticket.d.ts +0 -71
  230. package/dist/server/utils/small-ticket.js +0 -830
  231. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
  232. package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1438
  233. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  234. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
  235. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
  236. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  237. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
  238. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +0 -95
  239. package/dist/solution/BookingTicket/utils/exampleData.d.ts +0 -123
  240. package/dist/solution/BookingTicket/utils/exampleData.js +0 -183
  241. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
  242. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -438
  243. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
  244. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -399
  245. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
  246. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -56
  247. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
  248. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +0 -150
  249. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
  250. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +0 -78
  251. package/lib/modules/BookingContext/index.d.ts +0 -48
  252. package/lib/modules/BookingContext/index.js +0 -368
  253. package/lib/modules/BookingContext/types.d.ts +0 -102
  254. package/lib/modules/BookingContext/types.js +0 -34
  255. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  256. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -276
  257. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  258. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -151
  259. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
  260. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -201
  261. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  262. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  263. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  264. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  265. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  266. package/lib/modules/BookingContext/utils/index.js +0 -43
  267. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  268. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  269. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
  270. package/lib/modules/BookingContext/utils/orderLineDisplay.js +0 -56
  271. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  272. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  273. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  274. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  275. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  276. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  277. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  278. package/lib/modules/BookingContext/utils/resources.js +0 -377
  279. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  280. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  281. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  282. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  283. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  284. package/lib/modules/Order/utils/manualProductDiscount.js +0 -206
  285. package/lib/modules/SurchargeList/index.d.ts +0 -16
  286. package/lib/modules/SurchargeList/index.js +0 -89
  287. package/lib/modules/SurchargeList/types.d.ts +0 -11
  288. package/lib/modules/SurchargeList/types.js +0 -17
  289. package/lib/server/modules/payment/index.d.ts +0 -28
  290. package/lib/server/modules/payment/index.js +0 -192
  291. package/lib/server/modules/payment/types.d.ts +0 -9
  292. package/lib/server/modules/payment/types.js +0 -17
  293. package/lib/server/test.json +0 -713
  294. package/lib/server/utils/small-ticket.d.ts +0 -71
  295. package/lib/server/utils/small-ticket.js +0 -781
  296. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
  297. package/lib/solution/BaseSales/utils/cartPromotion.js +0 -992
  298. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  299. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
  300. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
  301. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
  302. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
  303. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +0 -125
  304. package/lib/solution/BookingTicket/utils/exampleData.d.ts +0 -123
  305. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  306. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
  307. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -254
  308. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
  309. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -168
  310. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
  311. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -51
  312. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
  313. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +0 -127
  314. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
  315. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +0 -85
@@ -35,38 +35,12 @@ __export(utils_exports, {
35
35
  module.exports = __toCommonJS(utils_exports);
36
36
  var import_decimal = __toESM(require("decimal.js"));
37
37
  var import_utils = require("../Summary/utils");
38
- var import_utils2 = require("../Order/utils");
39
38
  function toDecimal(value) {
40
39
  return new import_decimal.default(value || 0);
41
40
  }
42
41
  function toFixed2(value) {
43
42
  return new import_decimal.default(value || 0).toFixed(2);
44
43
  }
45
- function toAmountFormat(value) {
46
- return new import_decimal.default(value || 0).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
47
- }
48
- function toBackendTaxFee(value) {
49
- return toBcScale(value, 2);
50
- }
51
- function toBcScale(value, scale) {
52
- const factor = new import_decimal.default(10).pow(scale);
53
- return new import_decimal.default(value || 0).times(factor).toDecimalPlaces(0, import_decimal.default.ROUND_DOWN).div(factor);
54
- }
55
- function bcAdd(left, right, scale) {
56
- return toBcScale(new import_decimal.default(left || 0).plus(right || 0), scale);
57
- }
58
- function bcSub(left, right, scale) {
59
- return toBcScale(new import_decimal.default(left || 0).minus(right || 0), scale);
60
- }
61
- function bcMul(left, right, scale) {
62
- return toBcScale(new import_decimal.default(left || 0).times(right || 0), scale);
63
- }
64
- function bcDiv(left, right, scale) {
65
- const divisor = new import_decimal.default(right || 0);
66
- if (divisor.eq(0))
67
- return new import_decimal.default(0);
68
- return toBcScale(new import_decimal.default(left || 0).div(divisor), scale);
69
- }
70
44
  function getSafeNum(num) {
71
45
  if (!num || Number.isNaN(num))
72
46
  return 1;
@@ -78,8 +52,8 @@ function getBundleUnitPrice(product, useOriginal = false) {
78
52
  const bundleItems = product.product_bundle || [];
79
53
  return bundleItems.reduce((sum, item) => {
80
54
  const quantity = getSafeNum(item == null ? void 0 : item.num);
81
- const signedUnit = (0, import_utils2.getBundleSignedUnit)(item, { useOriginal });
82
- return sum.plus(signedUnit.times(quantity));
55
+ const price = useOriginal ? toDecimal((item == null ? void 0 : item.original_price) ?? (item == null ? void 0 : item.product_price) ?? (item == null ? void 0 : item.price)) : toDecimal((item == null ? void 0 : item.bundle_selling_price) ?? (item == null ? void 0 : item.price));
56
+ return sum.plus(price.times(quantity));
83
57
  }, new import_decimal.default(0));
84
58
  }
85
59
  function getUnitPaymentTotal(product) {
@@ -96,18 +70,11 @@ function getUnitOriginalTotal(product) {
96
70
  const basePrice = mainOriginal !== void 0 ? toDecimal(mainOriginal) : mainSelling !== void 0 ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
97
71
  return basePrice.plus(getBundleUnitPrice(product, true));
98
72
  }
99
- function isGeneratedVoucherProduct(product) {
100
- const record = product;
101
- const metadata = (record == null ? void 0 : record.metadata) || {};
102
- return (record == null ? void 0 : record.extension_type) === "product_voucher" || metadata.parent_order_detail_id !== void 0 || metadata.gift_card_type !== void 0;
103
- }
104
73
  function buildSurchargeServiceItems(products) {
105
74
  return products.map((product) => {
106
75
  var _a, _b;
107
76
  const quantity = getSafeNum(product.num);
108
77
  const unitTotal = getUnitPaymentTotal(product);
109
- const options = (0, import_utils2.getProductSkuOptions)(product);
110
- const persistedSurchargeFee = getPersistedMainSurchargeFee(product);
111
78
  return {
112
79
  id: product.product_id,
113
80
  num: quantity,
@@ -119,390 +86,19 @@ function buildSurchargeServiceItems(products) {
119
86
  product: {
120
87
  discount_list: product.discount_list || [],
121
88
  product_bundle: product.product_bundle || [],
122
- product_sku: product.product_sku || { option: options }
89
+ product_option_item: product.product_option_item || []
123
90
  }
124
91
  },
125
92
  bundle: product.product_bundle || [],
126
- option: options,
127
- options,
93
+ option: product.product_option_item || [],
94
+ options: product.product_option_item || [],
128
95
  relation_details: [],
129
- metadata: {
130
- ...product.metadata || {},
131
- __persisted_surcharge_fee: persistedSurchargeFee == null ? void 0 : persistedSurchargeFee.toFixed(2)
132
- },
96
+ metadata: product.metadata || {},
133
97
  start_date: ((_a = product.metadata) == null ? void 0 : _a.start_date) || "",
134
98
  start_time: ((_b = product.metadata) == null ? void 0 : _b.start_time) || ""
135
99
  };
136
100
  });
137
101
  }
138
- function getRelationSurchargeIds(item) {
139
- var _a;
140
- const ids = [
141
- ...Array.isArray(item == null ? void 0 : item.relation_surcharge_ids) ? item.relation_surcharge_ids : [],
142
- ...Array.isArray((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.relation_surcharge_ids) ? item.metadata.relation_surcharge_ids : []
143
- ];
144
- return [...new Set(ids.filter((id) => id !== void 0 && id !== null && id !== ""))];
145
- }
146
- function getSurchargeConfigId(config) {
147
- return (config == null ? void 0 : config.id) ?? (config == null ? void 0 : config.surcharge_id);
148
- }
149
- function getSurchargeConfigById(surchargeList) {
150
- const map = /* @__PURE__ */ new Map();
151
- for (const config of surchargeList || []) {
152
- const id = getSurchargeConfigId(config);
153
- if (id !== void 0)
154
- map.set(id, config);
155
- }
156
- return map;
157
- }
158
- function getMainSurchargeUnitAmount(product) {
159
- var _a, _b;
160
- const record = product;
161
- return toDecimal(
162
- ((_a = record.metadata) == null ? void 0 : _a.main_product_attached_bundle_selling_price) ?? ((_b = record.metadata) == null ? void 0 : _b.main_product_selling_price) ?? record.selling_price ?? 0
163
- );
164
- }
165
- function getBundleSurchargeUnitAmount(bundle) {
166
- return toDecimal((bundle == null ? void 0 : bundle.bundle_selling_price) ?? (bundle == null ? void 0 : bundle.bundle_sum_price) ?? (bundle == null ? void 0 : bundle.price) ?? 0);
167
- }
168
- function getBundleProductId(bundle) {
169
- const id = (bundle == null ? void 0 : bundle.bundle_product_id) ?? (bundle == null ? void 0 : bundle._bundle_product_id) ?? (bundle == null ? void 0 : bundle.product_id);
170
- if (id === void 0 || id === null || id === "")
171
- return null;
172
- const parsed = Number(id);
173
- if (!Number.isFinite(parsed))
174
- return null;
175
- return parsed;
176
- }
177
- function getPersistedMainSurchargeFee(product) {
178
- var _a;
179
- if ((product == null ? void 0 : product.order_detail_id) === void 0 || (product == null ? void 0 : product.order_detail_id) === null)
180
- return null;
181
- const value = (product == null ? void 0 : product.surcharge_fee) ?? (product == null ? void 0 : product.main_product_attached_bundle_surcharge_fee) ?? ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.main_product_attached_bundle_surcharge_fee);
182
- if (value === void 0 || value === null || value === "")
183
- return null;
184
- return toDecimal(value);
185
- }
186
- function getPersistedSourceSurchargeFee(sourceItem) {
187
- var _a;
188
- const value = (_a = sourceItem == null ? void 0 : sourceItem.metadata) == null ? void 0 : _a.__persisted_surcharge_fee;
189
- if (value === void 0 || value === null || value === "")
190
- return null;
191
- return toDecimal(value);
192
- }
193
- function getPersistedSurchargeRemainder(item, sourceItem) {
194
- var _a, _b;
195
- const value = ((_a = sourceItem == null ? void 0 : sourceItem.metadata) == null ? void 0 : _a.surcharge_rounding_remainder) ?? (item == null ? void 0 : item.surcharge_rounding_remainder) ?? ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.surcharge_rounding_remainder);
196
- if (value === void 0 || value === null || value === "")
197
- return null;
198
- return toDecimal(value);
199
- }
200
- function getPersistedQuantity(item, fallbackQuantity) {
201
- const isPersistedLine = (item == null ? void 0 : item.order_detail_id) !== void 0 && (item == null ? void 0 : item.order_detail_id) !== null;
202
- if (!isPersistedLine)
203
- return new import_decimal.default(0);
204
- const value = (item == null ? void 0 : item.product_quantity) ?? (item == null ? void 0 : item.quantity);
205
- const parsed = new import_decimal.default(value || 0);
206
- if (parsed.lte(0))
207
- return import_decimal.default.min(fallbackQuantity, 1);
208
- return import_decimal.default.min(fallbackQuantity, parsed);
209
- }
210
- function getPersistedBundleSurchargeFee(bundle, product) {
211
- var _a;
212
- if ((bundle == null ? void 0 : bundle.order_detail_id) === void 0 && (product == null ? void 0 : product.order_detail_id) === void 0)
213
- return null;
214
- if ((bundle == null ? void 0 : bundle.order_detail_id) === null && (product == null ? void 0 : product.order_detail_id) === null)
215
- return null;
216
- const value = (bundle == null ? void 0 : bundle.surcharge_fee) ?? ((_a = bundle == null ? void 0 : bundle.metadata) == null ? void 0 : _a.surcharge_fee);
217
- if (value === void 0 || value === null || value === "")
218
- return null;
219
- return toDecimal(value);
220
- }
221
- function createSurchargeAllocationNodes(products, sourceItems) {
222
- var _a;
223
- const nodes = [];
224
- for (let productIndex = 0; productIndex < products.length; productIndex++) {
225
- const product = products[productIndex];
226
- const sourceItem = sourceItems[productIndex] || {};
227
- const productQuantity = new import_decimal.default(getSafeNum(product.num));
228
- for (let bundleIndex = 0; bundleIndex < (product.product_bundle || []).length; bundleIndex++) {
229
- const bundle = product.product_bundle[bundleIndex];
230
- if (!isBundleOriginalPrice(bundle))
231
- continue;
232
- const sourceBundle = ((_a = sourceItem == null ? void 0 : sourceItem.bundle) == null ? void 0 : _a[bundleIndex]) || {};
233
- nodes.push({
234
- kind: "bundle",
235
- target: bundle,
236
- source: sourceBundle,
237
- productId: getBundleProductId(bundle),
238
- unitAmount: getBundleSurchargeUnitAmount(bundle),
239
- quantity: new import_decimal.default(getSafeNum((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity))).times(productQuantity),
240
- persistedQuantity: getPersistedQuantity(bundle, new import_decimal.default(getSafeNum((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity))).times(productQuantity)),
241
- relationSurchargeIds: getRelationSurchargeIds(sourceBundle).length ? getRelationSurchargeIds(sourceBundle) : getRelationSurchargeIds(bundle),
242
- persistedUnitSurchargeFee: getPersistedBundleSurchargeFee(bundle, product),
243
- persistedSurchargeRemainder: getPersistedSurchargeRemainder(bundle, sourceBundle)
244
- });
245
- }
246
- nodes.push({
247
- kind: "main",
248
- target: product,
249
- source: sourceItem,
250
- productId: product.product_id ?? null,
251
- unitAmount: getMainSurchargeUnitAmount(product),
252
- quantity: productQuantity,
253
- persistedQuantity: getPersistedQuantity(product, productQuantity),
254
- relationSurchargeIds: getRelationSurchargeIds(sourceItem).length ? getRelationSurchargeIds(sourceItem) : getRelationSurchargeIds(product),
255
- persistedUnitSurchargeFee: getPersistedSourceSurchargeFee(sourceItem) ?? getPersistedMainSurchargeFee(product),
256
- persistedSurchargeRemainder: getPersistedSurchargeRemainder(product, sourceItem)
257
- });
258
- }
259
- return nodes;
260
- }
261
- function resetProductSurchargeFields(products) {
262
- for (const product of products) {
263
- product.surcharge_fee = 0;
264
- product.main_product_attached_bundle_surcharge_fee = "0.00";
265
- product.surcharge_rounding_remainder = 0;
266
- product.relation_surcharge_ids = [];
267
- for (const bundle of product.product_bundle || []) {
268
- bundle.surcharge_fee = 0;
269
- bundle.relation_surcharge_ids = [];
270
- bundle.metadata = {
271
- ...bundle.metadata || {},
272
- surcharge_fee: "0.00",
273
- surcharge_rounding_remainder: "0.00",
274
- relation_surcharge_ids: []
275
- };
276
- }
277
- }
278
- }
279
- function getPersistedSurchargeIds(nodes) {
280
- const ids = /* @__PURE__ */ new Set();
281
- for (const node of nodes) {
282
- if (!node.persistedUnitSurchargeFee || node.persistedUnitSurchargeFee.lte(0))
283
- continue;
284
- for (const surchargeId of node.relationSurchargeIds) {
285
- ids.add(surchargeId);
286
- }
287
- }
288
- return ids;
289
- }
290
- function buildSurchargeQuantityTotals(nodes) {
291
- const totals = /* @__PURE__ */ new Map();
292
- for (const node of nodes) {
293
- for (const surchargeId of node.relationSurchargeIds) {
294
- totals.set(
295
- surchargeId,
296
- (totals.get(surchargeId) || new import_decimal.default(0)).plus(node.quantity)
297
- );
298
- }
299
- }
300
- return totals;
301
- }
302
- function getFallbackAllProductSurchargeIds(surchargeList) {
303
- return (surchargeList || []).reduce((ids, config) => {
304
- const id = getSurchargeConfigId(config);
305
- if (id === void 0)
306
- return ids;
307
- if (Number(config.open_product ?? 0) === 0)
308
- return ids;
309
- if (Number(config.is_all ?? 0) !== 1)
310
- return ids;
311
- ids.push(id);
312
- return ids;
313
- }, []);
314
- }
315
- function getBackendSurchargeState(stateMap, surchargeId, config) {
316
- let state = stateMap.get(surchargeId);
317
- if (!state) {
318
- state = {
319
- config,
320
- amount: new import_decimal.default(0),
321
- totalOffsetFee: new import_decimal.default(0),
322
- calculatedQuantity: new import_decimal.default(0),
323
- fixedIncluded: false,
324
- fixedRemainderAssigned: false
325
- };
326
- stateMap.set(surchargeId, state);
327
- }
328
- return state;
329
- }
330
- function buildSurchargeResultItem(config, surchargeId, amount, index) {
331
- const name = (config == null ? void 0 : config.name) || (config == null ? void 0 : config.label) || {};
332
- return {
333
- key: `custom_surcharge_${index}`,
334
- label: name,
335
- name,
336
- value: amount.toNumber(),
337
- surcharge_id: surchargeId,
338
- description: config == null ? void 0 : config.description,
339
- type: "default",
340
- fixed: config == null ? void 0 : config.fixed,
341
- amount: amount.toNumber(),
342
- percentage: config == null ? void 0 : config.percentage,
343
- metadata: {
344
- open_product: config == null ? void 0 : config.open_product
345
- }
346
- };
347
- }
348
- function applySurchargeNodeResult(node, params) {
349
- const { unitSurchargeFee, roundingRemainder, surchargeIds } = params;
350
- if (node.kind === "main") {
351
- node.target.surcharge_fee = unitSurchargeFee.toNumber();
352
- node.target.main_product_attached_bundle_surcharge_fee = toFixed2(unitSurchargeFee);
353
- node.target.surcharge_rounding_remainder = roundingRemainder.toNumber();
354
- node.target.relation_surcharge_ids = surchargeIds;
355
- return;
356
- }
357
- node.target.surcharge_fee = unitSurchargeFee.toNumber();
358
- node.target.relation_surcharge_ids = surchargeIds;
359
- node.target.metadata = {
360
- ...node.target.metadata || {},
361
- surcharge_fee: toFixed2(unitSurchargeFee),
362
- surcharge_rounding_remainder: toFixed2(roundingRemainder),
363
- relation_surcharge_ids: surchargeIds
364
- };
365
- }
366
- function calculateBackendProductSurcharges(params) {
367
- const { products, sourceItems, surchargeList } = params;
368
- resetProductSurchargeFields(products);
369
- const configById = getSurchargeConfigById(surchargeList);
370
- const nodes = createSurchargeAllocationNodes(products, sourceItems);
371
- const fallbackAllProductSurchargeIds = getFallbackAllProductSurchargeIds(surchargeList);
372
- for (const node of nodes) {
373
- if (node.relationSurchargeIds.length === 0) {
374
- node.relationSurchargeIds = fallbackAllProductSurchargeIds;
375
- }
376
- }
377
- const persistedSurchargeIds = getPersistedSurchargeIds(nodes);
378
- const quantityTotals = buildSurchargeQuantityTotals(nodes);
379
- const stateMap = /* @__PURE__ */ new Map();
380
- for (const node of nodes) {
381
- let unitSurchargeFee = new import_decimal.default(0);
382
- let roundingRemainder = new import_decimal.default(0);
383
- const appliedSurchargeIds = [];
384
- let persistedRemainderApplied = false;
385
- for (const surchargeId of node.relationSurchargeIds) {
386
- const config = configById.get(surchargeId);
387
- const totalQuantity = quantityTotals.get(surchargeId) || new import_decimal.default(0);
388
- if (totalQuantity.lte(0))
389
- continue;
390
- const persistedUnitSurchargeFee = node.persistedUnitSurchargeFee;
391
- if (persistedUnitSurchargeFee && persistedUnitSurchargeFee.gt(0)) {
392
- const persistedQuantity = import_decimal.default.min(node.persistedQuantity, node.quantity);
393
- const deltaQuantity = import_decimal.default.max(node.quantity.minus(persistedQuantity), 0);
394
- const state2 = getBackendSurchargeState(
395
- stateMap,
396
- surchargeId,
397
- config || { surcharge_id: surchargeId }
398
- );
399
- const persistedSurchargeRemainder = !persistedRemainderApplied && node.persistedSurchargeRemainder ? node.persistedSurchargeRemainder : new import_decimal.default(0);
400
- state2.amount = bcAdd(
401
- bcAdd(
402
- state2.amount,
403
- bcMul(persistedUnitSurchargeFee, persistedQuantity, 2),
404
- 2
405
- ),
406
- persistedSurchargeRemainder,
407
- 2
408
- );
409
- const fixed2 = new import_decimal.default((config == null ? void 0 : config.fixed) || 0);
410
- if (fixed2.gt(0))
411
- state2.fixedIncluded = true;
412
- let nodeTotalSurcharge = bcAdd(
413
- bcMul(persistedUnitSurchargeFee, persistedQuantity, 2),
414
- persistedSurchargeRemainder,
415
- 2
416
- );
417
- if (config && deltaQuantity.gt(0)) {
418
- const percentage2 = new import_decimal.default(config.percentage || 0);
419
- const deltaUnitPercentageFee = import_decimal.default.max(0, bcMul(node.unitAmount, percentage2, 2));
420
- const deltaSurcharge = bcMul(deltaQuantity, deltaUnitPercentageFee, 2);
421
- state2.amount = bcAdd(state2.amount, deltaSurcharge, 2);
422
- nodeTotalSurcharge = bcAdd(nodeTotalSurcharge, deltaSurcharge, 2);
423
- }
424
- if (node.quantity.gt(0)) {
425
- unitSurchargeFee = bcAdd(unitSurchargeFee, bcDiv(nodeTotalSurcharge, node.quantity, 2), 2);
426
- }
427
- if (!persistedSurchargeRemainder.eq(0)) {
428
- roundingRemainder = bcAdd(roundingRemainder, persistedSurchargeRemainder, 2);
429
- persistedRemainderApplied = true;
430
- }
431
- appliedSurchargeIds.push(surchargeId);
432
- continue;
433
- }
434
- if (!config)
435
- continue;
436
- const percentage = new import_decimal.default(config.percentage || 0);
437
- const fixed = new import_decimal.default(config.fixed || 0);
438
- const unitPercentageFee = import_decimal.default.max(0, bcMul(node.unitAmount, percentage, 2));
439
- const percentageTotalFee = bcMul(node.quantity, unitPercentageFee, 2);
440
- let unitFixedFee = new import_decimal.default(0);
441
- let fixedRemainder = new import_decimal.default(0);
442
- if (fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
443
- unitFixedFee = bcDiv(fixed, totalQuantity, 2);
444
- const distributedFixed = bcMul(unitFixedFee, totalQuantity, 2);
445
- fixedRemainder = bcSub(fixed, distributedFixed, 2);
446
- }
447
- const currentUnitSurcharge = import_decimal.default.max(
448
- 0,
449
- bcAdd(unitPercentageFee, unitFixedFee, 2)
450
- );
451
- if (currentUnitSurcharge.lte(0))
452
- continue;
453
- const state = getBackendSurchargeState(stateMap, surchargeId, config);
454
- state.amount = bcAdd(state.amount, percentageTotalFee, 2);
455
- const precisePercentage = import_decimal.default.max(0, bcMul(node.unitAmount, percentage, 6));
456
- const offsetBaseFee = import_decimal.default.max(0, bcSub(precisePercentage, unitPercentageFee, 6));
457
- state.totalOffsetFee = bcAdd(
458
- state.totalOffsetFee,
459
- bcMul(offsetBaseFee, node.quantity, 6),
460
- 6
461
- );
462
- state.calculatedQuantity = bcAdd(state.calculatedQuantity, node.quantity, 6);
463
- if (!state.fixedIncluded && fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
464
- state.amount = bcAdd(state.amount, fixed, 2);
465
- state.fixedIncluded = true;
466
- }
467
- if (!state.fixedRemainderAssigned && !fixedRemainder.eq(0)) {
468
- state.fixedRemainderAssigned = true;
469
- roundingRemainder = bcAdd(roundingRemainder, fixedRemainder, 2);
470
- }
471
- if (state.calculatedQuantity.gte(totalQuantity) && state.totalOffsetFee.gt(0)) {
472
- const totalOffsetFee = toAmountFormat(state.totalOffsetFee);
473
- state.amount = bcAdd(state.amount, totalOffsetFee, 2);
474
- roundingRemainder = bcAdd(roundingRemainder, totalOffsetFee, 2);
475
- state.totalOffsetFee = new import_decimal.default(0);
476
- }
477
- unitSurchargeFee = bcAdd(unitSurchargeFee, currentUnitSurcharge, 2);
478
- appliedSurchargeIds.push(surchargeId);
479
- }
480
- applySurchargeNodeResult(node, {
481
- unitSurchargeFee,
482
- roundingRemainder,
483
- surchargeIds: appliedSurchargeIds
484
- });
485
- }
486
- const result = (surchargeList || []).reduce((items, config, index) => {
487
- const surchargeId = getSurchargeConfigId(config);
488
- if (surchargeId === void 0)
489
- return items;
490
- const state = stateMap.get(surchargeId);
491
- if (!state || state.amount.lte(0))
492
- return items;
493
- items.push(buildSurchargeResultItem(config, surchargeId, state.amount, index));
494
- return items;
495
- }, []);
496
- const includedIds = new Set(
497
- result.map((item) => item == null ? void 0 : item.surcharge_id).filter((id) => id !== void 0)
498
- );
499
- for (const [surchargeId, state] of stateMap.entries()) {
500
- if (includedIds.has(surchargeId) || state.amount.lte(0))
501
- continue;
502
- result.push(buildSurchargeResultItem(state.config, surchargeId, state.amount, result.length));
503
- }
504
- return result;
505
- }
506
102
  function getProductDepositData(product) {
507
103
  var _a, _b, _c;
508
104
  const rootDepositData = (_a = product._origin) == null ? void 0 : _a.custom_deposit_data;
@@ -607,158 +203,29 @@ function calculateSingleItemTax(params) {
607
203
  return new import_decimal.default(0);
608
204
  return price.dividedBy(divisor).times(rate);
609
205
  }
610
- function getMainAttachedBundleSellingTotal(product) {
206
+ function getMainProductPaymentTotal(product) {
611
207
  var _a, _b;
612
208
  const mainSelling = ((_a = product.metadata) == null ? void 0 : _a.main_product_selling_price) ?? ((_b = product.metadata) == null ? void 0 : _b.main_product_original_price) ?? 0;
613
209
  let total = toDecimal(mainSelling);
614
210
  const bundleItems = product.product_bundle || [];
615
211
  for (const bundleItem of bundleItems) {
616
212
  if (isBundleMarkupOrDiscount(bundleItem)) {
617
- const unit = (0, import_utils2.getBundleSignedUnit)(bundleItem);
213
+ const unit = toDecimal(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
618
214
  const qty = getSafeNum(bundleItem.num ?? bundleItem.quantity);
619
215
  total = total.plus(unit.times(qty));
620
216
  }
621
217
  }
622
218
  return import_decimal.default.max(total, 0);
623
219
  }
624
- function getMainProductPaymentTotal(product) {
625
- var _a;
626
- const attachedPayment = (_a = product.metadata) == null ? void 0 : _a.main_product_attached_bundle_payment_price;
627
- if (attachedPayment !== void 0 && attachedPayment !== null && attachedPayment !== "") {
628
- return import_decimal.default.max(toDecimal(attachedPayment), 0);
629
- }
630
- return getMainAttachedBundleSellingTotal(product);
631
- }
632
- function getExplicitTaxRemainder(item) {
633
- var _a;
634
- const value = (item == null ? void 0 : item.tax_fee_rounding_remainder) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.tax_fee_rounding_remainder);
635
- if (value === void 0 || value === null || value === "")
636
- return null;
637
- return new import_decimal.default(value || 0);
638
- }
639
- function getPersistedTaxRemainder(item, parentProduct) {
640
- const isPersistedLine = (item == null ? void 0 : item.order_detail_id) !== void 0 && (item == null ? void 0 : item.order_detail_id) !== null || (parentProduct == null ? void 0 : parentProduct.order_detail_id) !== void 0 && (parentProduct == null ? void 0 : parentProduct.order_detail_id) !== null;
641
- if (!isPersistedLine)
642
- return null;
643
- return getExplicitTaxRemainder(item);
644
- }
645
- function getPersistedMainTaxFee(product) {
646
- var _a;
647
- if ((product == null ? void 0 : product.order_detail_id) === void 0 || (product == null ? void 0 : product.order_detail_id) === null)
648
- return null;
649
- const value = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.main_product_attached_bundle_tax_fee) ?? (product == null ? void 0 : product.main_product_attached_bundle_tax_fee) ?? (product == null ? void 0 : product.tax_fee);
650
- if (value === void 0 || value === null || value === "")
651
- return null;
652
- return toDecimal(value);
653
- }
654
- function writeTaxRemainder(item, roundingRemainder) {
655
- item.tax_fee_rounding_remainder = roundingRemainder.toNumber();
656
- if (item.metadata && typeof item.metadata === "object") {
657
- item.metadata.tax_fee_rounding_remainder = roundingRemainder.toFixed(2);
658
- }
659
- }
660
- function resetTaxRemainderFields(products) {
661
- for (const product of products) {
662
- const productRemainder = getPersistedTaxRemainder(product);
663
- if (productRemainder !== null) {
664
- product.tax_fee_rounding_remainder = productRemainder.toNumber();
665
- } else {
666
- delete product.tax_fee_rounding_remainder;
667
- }
668
- product.original_tax_fee_rounding_remainder = 0;
669
- for (const bundle of product.product_bundle || []) {
670
- const bundleRemainder = getPersistedTaxRemainder(bundle, product);
671
- bundle.metadata = {
672
- ...bundle.metadata || {}
673
- };
674
- if (bundleRemainder !== null) {
675
- bundle.metadata.tax_fee_rounding_remainder = bundleRemainder.toFixed(2);
676
- bundle.tax_fee_rounding_remainder = bundleRemainder.toNumber();
677
- } else {
678
- delete bundle.metadata.tax_fee_rounding_remainder;
679
- delete bundle.tax_fee_rounding_remainder;
680
- }
681
- bundle.original_tax_fee_rounding_remainder = 0;
682
- }
683
- }
684
- }
685
- function getBundlePaymentPrice(bundle, product) {
686
- var _a;
687
- if ((bundle == null ? void 0 : bundle.bundle_payment_price) !== void 0)
688
- return toDecimal(bundle.bundle_payment_price);
689
- const basePrice = toDecimal((bundle == null ? void 0 : bundle.bundle_selling_price) ?? (bundle == null ? void 0 : bundle.bundle_sum_price) ?? (bundle == null ? void 0 : bundle.price) ?? 0);
690
- if (!isBundleOriginalPrice(bundle))
691
- return basePrice;
692
- const averageDiscountRate = toDecimal(
693
- ((_a = product.metadata) == null ? void 0 : _a.average_discount_amount_rate) ?? 1
694
- );
695
- return toAmountFormat(bcMul(basePrice, averageDiscountRate, 6));
696
- }
697
- function applyBackendTaxRemainder(params) {
698
- const { target, rawTax, formattedTax, quantity, state } = params;
699
- const taxFeeDifference = bcMul(
700
- bcSub(rawTax, formattedTax, 6),
701
- quantity,
702
- 6
703
- );
704
- state.difference = bcAdd(state.difference, taxFeeDifference, 6);
705
- if (state.difference.lt(5e-3))
706
- return new import_decimal.default(0);
707
- const roundingRemainder = toAmountFormat(state.difference);
708
- writeTaxRemainder(target, roundingRemainder);
709
- state.difference = bcSub(state.difference, roundingRemainder, 6);
710
- return roundingRemainder;
711
- }
712
220
  function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
713
221
  const rate = new import_decimal.default(taxRate);
714
- const taxRemainderState = { difference: new import_decimal.default(0) };
715
- let totalTax = new import_decimal.default(0);
716
- let totalOriginTax = new import_decimal.default(0);
717
- resetTaxRemainderFields(products);
222
+ let preciseTax = new import_decimal.default(0);
223
+ let roundedTax = new import_decimal.default(0);
224
+ let preciseOriginTax = new import_decimal.default(0);
225
+ let roundedOriginTax = new import_decimal.default(0);
226
+ let lastTaxableItem = null;
718
227
  for (const product of products) {
719
228
  const quantity = new import_decimal.default(getSafeNum(product.num));
720
- let productUnitTax = new import_decimal.default(0);
721
- let productUnitOriginTax = new import_decimal.default(0);
722
- const bundleItems = product.product_bundle || [];
723
- for (const bundleItem of bundleItems) {
724
- if (!isBundleOriginalPrice(bundleItem))
725
- continue;
726
- const bundleQuantity = new import_decimal.default(getSafeNum(bundleItem.num ?? bundleItem.quantity));
727
- const totalBundleQuantity = bundleQuantity.times(quantity);
728
- const bundlePrice = getBundlePaymentPrice(bundleItem, product);
729
- const bundleOriginalPrice = toDecimal(bundleItem.original_price ?? bundleItem.product_price ?? bundleItem.price ?? 0);
730
- const bundleSurchargeFee = toDecimal(bundleItem.surcharge_fee);
731
- const bundleTaxPrecise = calculateSingleItemTax({
732
- price: bundlePrice.plus(bundleSurchargeFee),
733
- taxRate: rate,
734
- isPriceIncludeTax,
735
- isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
736
- });
737
- const bundleTaxRounded = toBackendTaxFee(bundleTaxPrecise);
738
- bundleItem.tax_fee = bundleTaxRounded.toNumber();
739
- const persistedBundleRemainder = getPersistedTaxRemainder(bundleItem, product);
740
- const bundleRemainder = persistedBundleRemainder ?? applyBackendTaxRemainder({
741
- target: bundleItem,
742
- rawTax: bundleTaxPrecise,
743
- formattedTax: bundleTaxRounded,
744
- quantity: totalBundleQuantity,
745
- state: taxRemainderState
746
- });
747
- if (persistedBundleRemainder)
748
- writeTaxRemainder(bundleItem, persistedBundleRemainder);
749
- const bundleOrigTaxPrecise = calculateSingleItemTax({
750
- price: bundleOriginalPrice.plus(bundleSurchargeFee),
751
- taxRate: rate,
752
- isPriceIncludeTax,
753
- isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
754
- });
755
- const bundleOrigTaxRounded = toAmountFormat(bundleOrigTaxPrecise);
756
- bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
757
- productUnitTax = productUnitTax.plus(bundleTaxRounded.times(bundleQuantity));
758
- productUnitOriginTax = productUnitOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
759
- totalTax = totalTax.plus(bundleTaxRounded.times(totalBundleQuantity)).plus(bundleRemainder);
760
- totalOriginTax = totalOriginTax.plus(bundleOrigTaxRounded.times(totalBundleQuantity));
761
- }
762
229
  const mainTotal = getMainProductPaymentTotal(product);
763
230
  const surchargeFee = toDecimal(product.surcharge_fee);
764
231
  const mainTaxableBase = mainTotal.lte(0) ? surchargeFee : mainTotal.plus(surchargeFee);
@@ -768,22 +235,9 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
768
235
  isPriceIncludeTax,
769
236
  isChargeTax: product.is_charge_tax ?? 0
770
237
  });
771
- const mainTaxRounded = toBackendTaxFee(mainTaxPrecise);
772
- const persistedMainRemainder = getPersistedTaxRemainder(product);
773
- const persistedMainTaxFee = getPersistedMainTaxFee(product);
774
- const persistedQuantity = getPersistedQuantity(product, quantity);
775
- const deltaQuantity = import_decimal.default.max(quantity.minus(persistedQuantity), 0);
776
- const shouldUsePersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gte(quantity);
777
- const shouldSplitPersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gt(0) && deltaQuantity.gt(0);
778
- const mainRemainder = shouldUsePersistedMainTax || shouldSplitPersistedMainTax ? new import_decimal.default(0) : persistedMainRemainder ?? applyBackendTaxRemainder({
779
- target: product,
780
- rawTax: mainTaxPrecise,
781
- formattedTax: mainTaxRounded,
782
- quantity,
783
- state: taxRemainderState
784
- });
785
- if (persistedMainRemainder && !shouldSplitPersistedMainTax) {
786
- writeTaxRemainder(product, persistedMainRemainder);
238
+ const mainTaxRounded = mainTaxPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
239
+ if (mainTaxPrecise.gt(0)) {
240
+ lastTaxableItem = { type: "main", item: product };
787
241
  }
788
242
  const originalTotal = getUnitOriginalTotal(product);
789
243
  const originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
@@ -793,64 +247,65 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
793
247
  isPriceIncludeTax,
794
248
  isChargeTax: product.is_charge_tax ?? 0
795
249
  });
796
- const originalTaxRounded = toAmountFormat(originalTaxPrecise);
797
- const effectiveMainUnitTax = shouldUsePersistedMainTax ? persistedMainTaxFee : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)).div(quantity).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP) : mainTaxRounded;
798
- productUnitTax = productUnitTax.plus(effectiveMainUnitTax);
799
- productUnitOriginTax = productUnitOriginTax.plus(originalTaxRounded);
800
- product.main_product_attached_bundle_tax_fee = effectiveMainUnitTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toFixed(2);
801
- product.tax_fee = productUnitTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toFixed(2);
802
- product.original_tax_fee = productUnitOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
803
- totalTax = totalTax.plus(
804
- shouldUsePersistedMainTax ? persistedMainTaxFee.times(quantity).plus(persistedMainRemainder || 0) : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)) : mainTaxRounded.times(quantity).plus(mainRemainder)
805
- );
806
- totalOriginTax = totalOriginTax.plus(originalTaxRounded.times(quantity));
807
- if (product.tax_fee_rounding_remainder === void 0) {
808
- product.tax_fee_rounding_remainder = 0;
809
- }
810
- }
811
- return {
812
- tax: totalTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP),
813
- originTax: totalOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP)
814
- };
815
- }
816
- function allocateShopDiscountToPayment(products, productAmount, shopDiscountAmount) {
817
- const effectiveDiscount = productAmount.lte(0) ? new import_decimal.default(0) : import_decimal.default.max(import_decimal.default.min(productAmount, shopDiscountAmount), 0);
818
- let allocatedDiscount = new import_decimal.default(0);
819
- products.forEach((product, index) => {
820
- const quantity = new import_decimal.default(getSafeNum(product.num));
821
- const sellingUnit = getUnitPaymentTotal(product);
822
- const lineSellingTotal = sellingUnit.times(quantity);
823
- const lineDiscount = effectiveDiscount.lte(0) ? new import_decimal.default(0) : index === products.length - 1 ? import_decimal.default.max(effectiveDiscount.minus(allocatedDiscount), 0) : toAmountFormat(lineSellingTotal.div(productAmount).times(effectiveDiscount));
824
- allocatedDiscount = allocatedDiscount.plus(lineDiscount);
825
- const unitDiscount = quantity.lte(0) ? new import_decimal.default(0) : lineDiscount.div(quantity);
826
- const paymentUnit = import_decimal.default.max(sellingUnit.minus(unitDiscount), 0);
827
- const rate = sellingUnit.lte(0) ? new import_decimal.default(1) : toBcScale(paymentUnit.div(sellingUnit), 6);
828
- const mainSellingTotal = getMainAttachedBundleSellingTotal(product);
829
- const mainPaymentTotal = toAmountFormat(bcMul(mainSellingTotal, rate, 6));
830
- product.metadata = {
831
- ...product.metadata || {},
832
- average_discount_amount_rate: rate.toString(),
833
- main_product_attached_bundle_selling_price: mainSellingTotal.toFixed(2),
834
- main_product_attached_bundle_payment_price: mainPaymentTotal.toFixed(2)
835
- };
836
- for (const bundle of product.product_bundle || []) {
837
- if (isBundleOriginalPrice(bundle)) {
838
- const bundleSelling = toDecimal(
839
- bundle.bundle_selling_price ?? bundle.bundle_sum_price ?? bundle.price ?? 0
840
- );
841
- bundle.bundle_payment_price = toAmountFormat(bcMul(bundleSelling, rate, 6)).toFixed(2);
250
+ let bundlePreciseTax = new import_decimal.default(0);
251
+ let bundleRoundedTax = new import_decimal.default(0);
252
+ let bundlePreciseOriginTax = new import_decimal.default(0);
253
+ let bundleRoundedOriginTax = new import_decimal.default(0);
254
+ const bundleItems = product.product_bundle || [];
255
+ for (const bundleItem of bundleItems) {
256
+ if (!isBundleOriginalPrice(bundleItem))
842
257
  continue;
843
- }
844
- if ((0, import_utils2.isMarkdownBundle)(bundle)) {
845
- const magnitude = (0, import_utils2.getBundleSellingMagnitude)(bundle);
846
- bundle.custom_price = bundle.custom_price ?? bundle.price;
847
- bundle.price = magnitude.toFixed(2);
848
- bundle.bundle_selling_price = magnitude.toFixed(2);
849
- bundle.bundle_payment_price = toAmountFormat(bcMul(magnitude, rate, 6)).toFixed(2);
258
+ const bundleQuantity = new import_decimal.default(getSafeNum(bundleItem.num ?? bundleItem.quantity));
259
+ const bundlePrice = toDecimal(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
260
+ const bundleOriginalPrice = toDecimal(bundleItem.original_price ?? bundleItem.product_price ?? bundleItem.price ?? 0);
261
+ const bundleTaxPrecise = calculateSingleItemTax({
262
+ price: bundlePrice,
263
+ taxRate: rate,
264
+ isPriceIncludeTax,
265
+ isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
266
+ });
267
+ const bundleTaxRounded = bundleTaxPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
268
+ const bundleOrigTaxPrecise = calculateSingleItemTax({
269
+ price: bundleOriginalPrice,
270
+ taxRate: rate,
271
+ isPriceIncludeTax,
272
+ isChargeTax: bundleItem.is_charge_tax ?? product.is_charge_tax ?? 0
273
+ });
274
+ const bundleOrigTaxRounded = bundleOrigTaxPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
275
+ bundleItem.tax_fee = bundleTaxRounded.toNumber();
276
+ bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
277
+ bundlePreciseTax = bundlePreciseTax.plus(bundleTaxPrecise.times(bundleQuantity));
278
+ bundleRoundedTax = bundleRoundedTax.plus(bundleTaxRounded.times(bundleQuantity));
279
+ bundlePreciseOriginTax = bundlePreciseOriginTax.plus(bundleOrigTaxPrecise.times(bundleQuantity));
280
+ bundleRoundedOriginTax = bundleRoundedOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
281
+ if (bundleTaxPrecise.gt(0)) {
282
+ lastTaxableItem = { type: "bundle", item: bundleItem };
850
283
  }
851
284
  }
852
- product.payment_price = paymentUnit.toFixed(2);
853
- });
285
+ const itemTaxPrecise = mainTaxPrecise.plus(bundlePreciseTax);
286
+ const itemTaxRounded = mainTaxRounded.plus(bundleRoundedTax);
287
+ const itemOriginTaxPrecise = originalTaxPrecise.plus(bundlePreciseOriginTax);
288
+ const itemOriginTaxRounded = originalTaxPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).plus(bundleRoundedOriginTax);
289
+ product.tax_fee = itemTaxRounded.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toFixed(2);
290
+ product.original_tax_fee = itemOriginTaxRounded.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
291
+ preciseTax = preciseTax.plus(itemTaxPrecise.times(quantity));
292
+ roundedTax = roundedTax.plus(itemTaxRounded.times(quantity));
293
+ preciseOriginTax = preciseOriginTax.plus(itemOriginTaxPrecise.times(quantity));
294
+ roundedOriginTax = roundedOriginTax.plus(itemOriginTaxRounded.times(quantity));
295
+ }
296
+ const expectedTax = preciseTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
297
+ const expectedOriginTax = preciseOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
298
+ const taxRemainder = expectedTax.minus(roundedTax).toNumber();
299
+ const originTaxRemainder = expectedOriginTax.minus(roundedOriginTax).toNumber();
300
+ if (lastTaxableItem) {
301
+ if (taxRemainder !== 0) {
302
+ lastTaxableItem.item.tax_fee_rounding_remainder = taxRemainder;
303
+ }
304
+ if (originTaxRemainder !== 0) {
305
+ lastTaxableItem.item.original_tax_fee_rounding_remainder = originTaxRemainder;
306
+ }
307
+ }
308
+ return { tax: expectedTax, originTax: expectedOriginTax };
854
309
  }
855
310
  function createEmptySalesSummary() {
856
311
  return {
@@ -877,6 +332,7 @@ function createEmptySalesSummary() {
877
332
  };
878
333
  }
879
334
  function calculateSalesSummary(params) {
335
+ var _a;
880
336
  const {
881
337
  products,
882
338
  isPriceIncludeTax,
@@ -888,31 +344,20 @@ function calculateSalesSummary(params) {
888
344
  } = params;
889
345
  if (!(products == null ? void 0 : products.length))
890
346
  return createEmptySalesSummary();
891
- const summaryProducts = products.filter((product) => !isGeneratedVoucherProduct(product));
892
- if (!summaryProducts.length)
893
- return createEmptySalesSummary();
894
- const productQuantity = summaryProducts.reduce(
347
+ const productQuantity = products.reduce(
895
348
  (sum, item) => sum + getSafeNum(item.num),
896
349
  0
897
350
  );
898
- const productOriginalAmount = summaryProducts.reduce(
351
+ const productOriginalAmount = products.reduce(
899
352
  (sum, item) => sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num))),
900
353
  new import_decimal.default(0)
901
354
  );
902
- const productAmount = summaryProducts.reduce(
355
+ const productAmount = products.reduce(
903
356
  (sum, item) => sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num))),
904
357
  new import_decimal.default(0)
905
358
  );
906
- const shopDiscountAmount = import_decimal.default.max(new import_decimal.default(Number(shopDiscount) || 0), 0);
907
- const hasPersistedSurchargeSnapshot = summaryProducts.some((product) => {
908
- var _a;
909
- return (_a = getPersistedMainSurchargeFee(product)) == null ? void 0 : _a.gt(0);
910
- });
911
- if (!hasPersistedSurchargeSnapshot) {
912
- allocateShopDiscountToPayment(summaryProducts, productAmount, shopDiscountAmount);
913
- }
914
- const surchargeServiceItems = buildSurchargeServiceItems(summaryProducts);
915
- (0, import_utils.getSurcharge)(
359
+ const surchargeServiceItems = buildSurchargeServiceItems(products);
360
+ const surcharge = (0, import_utils.getSurcharge)(
916
361
  {
917
362
  service: surchargeServiceItems,
918
363
  addons: [],
@@ -926,11 +371,6 @@ function calculateSalesSummary(params) {
926
371
  scheduleById
927
372
  }
928
373
  );
929
- const surcharge = calculateBackendProductSurcharges({
930
- products: summaryProducts,
931
- sourceItems: surchargeServiceItems,
932
- surchargeList
933
- });
934
374
  const surchargeAmount = new import_decimal.default(
935
375
  (0, import_utils.getSurchargeAmount)(
936
376
  { bookingDetail: null, bookingId: void 0 },
@@ -938,20 +378,24 @@ function calculateSalesSummary(params) {
938
378
  { isEdit: false }
939
379
  ) || 0
940
380
  );
381
+ for (let i = 0; i < products.length; i++) {
382
+ products[i].surcharge_fee = ((_a = surchargeServiceItems[i]) == null ? void 0 : _a.surcharge_fee) || 0;
383
+ }
941
384
  const hasTaxRate = taxRate !== void 0 && taxRate !== null && taxRate > 0;
942
385
  let productTaxFee;
943
386
  if (hasTaxRate) {
944
- const taxResult = calculateProductsTax(summaryProducts, taxRate, isPriceIncludeTax);
387
+ const taxResult = calculateProductsTax(products, taxRate, isPriceIncludeTax);
945
388
  productTaxFee = taxResult.tax;
946
389
  } else {
947
- productTaxFee = summaryProducts.reduce(
390
+ productTaxFee = products.reduce(
948
391
  (sum, item) => sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num))),
949
392
  new import_decimal.default(0)
950
393
  );
951
394
  }
952
- const orderAmountBeforeDiscount = productAmount.plus(surchargeAmount).plus(isPriceIncludeTax === 1 ? 0 : productTaxFee);
953
- const totalAmount = import_decimal.default.max(0, orderAmountBeforeDiscount.minus(shopDiscountAmount));
954
- const deposit = calculateProductsDeposit(summaryProducts);
395
+ const shopDiscountAmount = import_decimal.default.max(new import_decimal.default(Number(shopDiscount) || 0), 0);
396
+ const expectAmount = import_decimal.default.max(0, productAmount.plus(surchargeAmount).minus(shopDiscountAmount));
397
+ const totalAmount = isPriceIncludeTax === 1 ? expectAmount : expectAmount.plus(productTaxFee);
398
+ const deposit = calculateProductsDeposit(products);
955
399
  return {
956
400
  product_quantity: productQuantity,
957
401
  product_original_amount: toFixed2(productOriginalAmount),
@@ -963,10 +407,12 @@ function calculateSalesSummary(params) {
963
407
  tax_fee: toFixed2(productTaxFee),
964
408
  surcharge_fee: toFixed2(surchargeAmount),
965
409
  surcharges: surcharge,
966
- discount_amount: toFixed2(shopDiscountAmount),
410
+ discount_amount: toFixed2(
411
+ import_decimal.default.max(productOriginalAmount.minus(productAmount), 0).plus(shopDiscountAmount)
412
+ ),
967
413
  deposit_amount: deposit ? deposit.total : "0.00",
968
414
  deposit,
969
- expect_amount: toFixed2(totalAmount),
415
+ expect_amount: toFixed2(expectAmount),
970
416
  total_amount: toFixed2(totalAmount),
971
417
  total_refund_amount: "0.00",
972
418
  customer_paid_amount: "0.00",