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