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