@pisell/pisellos 2.2.244 → 2.2.245
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/model/strategy/adapter/promotion/evaluator.js +3 -2
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
- package/dist/modules/BookingContext/index.d.ts +48 -0
- package/dist/modules/BookingContext/index.js +566 -0
- package/dist/modules/BookingContext/types.d.ts +102 -0
- package/dist/modules/BookingContext/types.js +51 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +284 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +145 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +218 -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/utils/cartProduct.js +24 -3
- 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/Discount/index.d.ts +1 -1
- package/dist/modules/Discount/index.js +13 -6
- package/dist/modules/Discount/types.d.ts +1 -0
- package/dist/modules/OpenData/index.d.ts +8 -0
- package/dist/modules/OpenData/index.js +37 -17
- package/dist/modules/Order/index.d.ts +275 -19
- package/dist/modules/Order/index.js +3493 -809
- package/dist/modules/Order/types.d.ts +286 -31
- package/dist/modules/Order/types.js +38 -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.d.ts +147 -5
- package/dist/modules/Order/utils.js +750 -104
- package/dist/modules/Payment/index.d.ts +10 -13
- package/dist/modules/Payment/index.js +467 -837
- package/dist/modules/Payment/types.d.ts +2 -0
- package/dist/modules/Payment/utils.js +2 -1
- package/dist/modules/Payment/walletpass.js +41 -25
- package/dist/modules/ProductList/index.d.ts +16 -12
- package/dist/modules/ProductList/index.js +133 -59
- package/dist/modules/ProductList/types.d.ts +14 -0
- package/dist/modules/Quotation/index.d.ts +0 -1
- package/dist/modules/Quotation/index.js +25 -22
- package/dist/modules/Rules/index.d.ts +4 -0
- package/dist/modules/Rules/index.js +97 -70
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/SalesSummary/index.d.ts +8 -25
- package/dist/modules/SalesSummary/index.js +86 -35
- package/dist/modules/SalesSummary/types.d.ts +4 -1
- package/dist/modules/SalesSummary/utils.d.ts +2 -25
- package/dist/modules/SalesSummary/utils.js +794 -162
- package/dist/modules/Schedule/index.d.ts +7 -0
- package/dist/modules/Schedule/index.js +24 -2
- package/dist/modules/Summary/index.js +4 -3
- package/dist/modules/SurchargeList/index.d.ts +16 -0
- package/dist/modules/SurchargeList/index.js +162 -0
- package/dist/modules/SurchargeList/types.d.ts +11 -0
- package/dist/modules/SurchargeList/types.js +1 -0
- package/dist/modules/index.d.ts +2 -0
- package/dist/modules/index.js +3 -1
- package/dist/plugins/request.d.ts +1 -0
- package/dist/server/index.d.ts +204 -1
- package/dist/server/index.js +3654 -922
- package/dist/server/modules/index.d.ts +2 -0
- package/dist/server/modules/index.js +2 -0
- package/dist/server/modules/order/index.d.ts +120 -3
- package/dist/server/modules/order/index.js +1758 -448
- package/dist/server/modules/order/types.d.ts +32 -3
- package/dist/server/modules/order/types.js +8 -0
- package/dist/server/modules/order/utils/filterBookings.js +26 -3
- package/dist/server/modules/order/utils/filterOrders.js +23 -8
- 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 +34 -7
- package/dist/server/modules/products/index.js +631 -317
- package/dist/server/modules/resource/index.d.ts +2 -0
- package/dist/server/modules/resource/index.js +29 -3
- package/dist/server/modules/schedule/index.d.ts +4 -4
- package/dist/server/modules/schedule/index.js +111 -88
- package/dist/server/test.json +713 -0
- package/dist/server/utils/small-ticket.d.ts +71 -0
- package/dist/server/utils/small-ticket.js +840 -0
- package/dist/solution/BaseSales/index.d.ts +133 -10
- package/dist/solution/BaseSales/index.js +1950 -447
- package/dist/solution/BaseSales/types.d.ts +82 -6
- package/dist/solution/BaseSales/types.js +5 -4
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/dist/solution/BaseSales/utils/cartPromotion.js +1438 -0
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +105 -24
- package/dist/solution/BaseSales/utils.d.ts +1 -1
- package/dist/solution/BaseSales/utils.js +62 -21
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +271 -11
- package/dist/solution/BookingTicket/index.js +1777 -242
- package/dist/solution/BookingTicket/types.d.ts +118 -1
- package/dist/solution/BookingTicket/types.js +41 -2
- 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 +40 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.js +70 -0
- package/dist/solution/BookingTicket/utils/cartView.d.ts +9 -1
- package/dist/solution/BookingTicket/utils/cartView.js +94 -7
- package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/dist/solution/BookingTicket/utils/exampleData.js +183 -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/formatGlobalScan.d.ts +32 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
- 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/Checkout/index.d.ts +1 -0
- package/dist/solution/Checkout/index.js +10 -9
- package/dist/solution/RegisterAndLogin/config.js +2 -10
- package/dist/solution/ScanOrder/index.d.ts +9 -3
- package/dist/solution/ScanOrder/index.js +241 -134
- package/dist/solution/ScanOrder/types.d.ts +9 -5
- package/dist/solution/ScanOrder/types.js +2 -3
- package/dist/solution/ScanOrder/utils.d.ts +1 -1
- package/dist/solution/ScanOrder/utils.js +84 -22
- package/dist/solution/VenueBooking/index.d.ts +5 -2
- package/dist/solution/VenueBooking/index.js +110 -59
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/dist/types/index.d.ts +10 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +2 -1
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
- 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 +276 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +151 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +201 -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/utils/cartProduct.js +20 -3
- package/lib/modules/Cart/utils/changePrice.js +12 -20
- package/lib/modules/Customer/index.d.ts +20 -0
- package/lib/modules/Customer/index.js +64 -11
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +1 -1
- package/lib/modules/Discount/index.js +9 -1
- package/lib/modules/Discount/types.d.ts +1 -0
- package/lib/modules/OpenData/index.d.ts +8 -0
- package/lib/modules/OpenData/index.js +19 -5
- package/lib/modules/Order/index.d.ts +275 -19
- package/lib/modules/Order/index.js +2245 -336
- package/lib/modules/Order/types.d.ts +286 -31
- package/lib/modules/Order/types.js +1 -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.d.ts +147 -5
- package/lib/modules/Order/utils.js +615 -46
- package/lib/modules/Payment/index.d.ts +10 -13
- package/lib/modules/Payment/index.js +18 -150
- package/lib/modules/Payment/types.d.ts +2 -0
- package/lib/modules/Payment/utils.js +2 -1
- package/lib/modules/Payment/walletpass.js +16 -3
- package/lib/modules/ProductList/index.d.ts +16 -12
- package/lib/modules/ProductList/index.js +41 -4
- package/lib/modules/ProductList/types.d.ts +14 -0
- package/lib/modules/Quotation/index.d.ts +0 -1
- package/lib/modules/Quotation/index.js +19 -16
- package/lib/modules/Rules/index.d.ts +4 -0
- package/lib/modules/Rules/index.js +137 -120
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/SalesSummary/index.d.ts +8 -25
- package/lib/modules/SalesSummary/index.js +30 -4
- package/lib/modules/SalesSummary/types.d.ts +4 -1
- package/lib/modules/SalesSummary/utils.d.ts +2 -25
- package/lib/modules/SalesSummary/utils.js +645 -91
- package/lib/modules/Schedule/index.d.ts +7 -0
- package/lib/modules/Schedule/index.js +17 -1
- package/lib/modules/Summary/index.js +5 -4
- package/lib/modules/SurchargeList/index.d.ts +16 -0
- package/lib/modules/SurchargeList/index.js +89 -0
- package/lib/modules/SurchargeList/types.d.ts +11 -0
- package/lib/modules/SurchargeList/types.js +17 -0
- package/lib/modules/index.d.ts +2 -0
- package/lib/modules/index.js +5 -1
- package/lib/plugins/request.d.ts +1 -0
- package/lib/server/index.d.ts +204 -1
- package/lib/server/index.js +1891 -59
- package/lib/server/modules/index.d.ts +2 -0
- package/lib/server/modules/index.js +3 -0
- package/lib/server/modules/order/index.d.ts +120 -3
- package/lib/server/modules/order/index.js +883 -94
- package/lib/server/modules/order/types.d.ts +32 -3
- package/lib/server/modules/order/utils/filterBookings.js +24 -5
- package/lib/server/modules/order/utils/filterOrders.js +15 -6
- 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 +34 -7
- package/lib/server/modules/products/index.js +189 -54
- package/lib/server/modules/resource/index.d.ts +2 -0
- package/lib/server/modules/resource/index.js +27 -3
- package/lib/server/modules/schedule/index.d.ts +4 -4
- package/lib/server/modules/schedule/index.js +47 -40
- package/lib/server/test.json +713 -0
- package/lib/server/utils/small-ticket.d.ts +71 -0
- package/lib/server/utils/small-ticket.js +800 -0
- package/lib/solution/BaseSales/index.d.ts +133 -10
- package/lib/solution/BaseSales/index.js +1111 -63
- package/lib/solution/BaseSales/types.d.ts +82 -6
- package/lib/solution/BaseSales/types.js +3 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +992 -0
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +106 -18
- package/lib/solution/BaseSales/utils.d.ts +1 -1
- package/lib/solution/BaseSales/utils.js +54 -10
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +271 -11
- package/lib/solution/BookingTicket/index.js +922 -29
- package/lib/solution/BookingTicket/types.d.ts +118 -1
- package/lib/solution/BookingTicket/types.js +11 -0
- 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 +40 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.js +44 -2
- package/lib/solution/BookingTicket/utils/cartView.d.ts +9 -1
- package/lib/solution/BookingTicket/utils/cartView.js +61 -6
- package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -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/formatGlobalScan.d.ts +32 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +17 -3
- 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/Checkout/index.d.ts +1 -0
- package/lib/solution/Checkout/index.js +1 -2
- package/lib/solution/RegisterAndLogin/config.js +2 -10
- package/lib/solution/ScanOrder/index.d.ts +9 -3
- package/lib/solution/ScanOrder/index.js +153 -70
- package/lib/solution/ScanOrder/types.d.ts +9 -5
- package/lib/solution/ScanOrder/utils.d.ts +1 -1
- package/lib/solution/ScanOrder/utils.js +83 -17
- package/lib/solution/VenueBooking/index.d.ts +5 -2
- package/lib/solution/VenueBooking/index.js +54 -17
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/lib/types/index.d.ts +10 -0
- package/package.json +1 -1
- package/dist/solution/Checkout/appointmentDemo.json +0 -1
- package/lib/solution/Checkout/appointmentDemo.json +0 -1
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
1
6
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
7
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
8
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -5,15 +10,44 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
5
10
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
11
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
12
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
-
function
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
18
|
import Decimal from 'decimal.js';
|
|
10
19
|
import { getSurcharge, getSurchargeAmount } from "../Summary/utils";
|
|
20
|
+
import { getBundleSellingMagnitude, getBundleSignedUnit, getProductSkuOptions, isMarkdownBundle } from "../Order/utils";
|
|
11
21
|
function toDecimal(value) {
|
|
12
22
|
return new Decimal(value || 0);
|
|
13
23
|
}
|
|
14
24
|
function toFixed2(value) {
|
|
15
25
|
return new Decimal(value || 0).toFixed(2);
|
|
16
26
|
}
|
|
27
|
+
function toAmountFormat(value) {
|
|
28
|
+
return new Decimal(value || 0).toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
29
|
+
}
|
|
30
|
+
function toBackendTaxFee(value) {
|
|
31
|
+
return toBcScale(value, 2);
|
|
32
|
+
}
|
|
33
|
+
function toBcScale(value, scale) {
|
|
34
|
+
var factor = new Decimal(10).pow(scale);
|
|
35
|
+
return new Decimal(value || 0).times(factor).toDecimalPlaces(0, Decimal.ROUND_DOWN).div(factor);
|
|
36
|
+
}
|
|
37
|
+
function bcAdd(left, right, scale) {
|
|
38
|
+
return toBcScale(new Decimal(left || 0).plus(right || 0), scale);
|
|
39
|
+
}
|
|
40
|
+
function bcSub(left, right, scale) {
|
|
41
|
+
return toBcScale(new Decimal(left || 0).minus(right || 0), scale);
|
|
42
|
+
}
|
|
43
|
+
function bcMul(left, right, scale) {
|
|
44
|
+
return toBcScale(new Decimal(left || 0).times(right || 0), scale);
|
|
45
|
+
}
|
|
46
|
+
function bcDiv(left, right, scale) {
|
|
47
|
+
var divisor = new Decimal(right || 0);
|
|
48
|
+
if (divisor.eq(0)) return new Decimal(0);
|
|
49
|
+
return toBcScale(new Decimal(left || 0).div(divisor), scale);
|
|
50
|
+
}
|
|
17
51
|
function getSafeNum(num) {
|
|
18
52
|
if (!num || Number.isNaN(num)) return 1;
|
|
19
53
|
if (num < 1) return 1;
|
|
@@ -23,10 +57,12 @@ function getBundleUnitPrice(product) {
|
|
|
23
57
|
var useOriginal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
24
58
|
var bundleItems = product.product_bundle || [];
|
|
25
59
|
return bundleItems.reduce(function (sum, item) {
|
|
26
|
-
var _ref, _item$original_price, _item$bundle_selling_;
|
|
27
60
|
var quantity = getSafeNum(item === null || item === void 0 ? void 0 : item.num);
|
|
28
|
-
|
|
29
|
-
|
|
61
|
+
// markdown(减价)按带符号净额取减;markup/原价维持相加。
|
|
62
|
+
var signedUnit = getBundleSignedUnit(item, {
|
|
63
|
+
useOriginal: useOriginal
|
|
64
|
+
});
|
|
65
|
+
return sum.plus(signedUnit.times(quantity));
|
|
30
66
|
}, new Decimal(0));
|
|
31
67
|
}
|
|
32
68
|
|
|
@@ -48,11 +84,18 @@ function getUnitOriginalTotal(product) {
|
|
|
48
84
|
var basePrice = mainOriginal !== undefined ? toDecimal(mainOriginal) : mainSelling !== undefined ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
|
|
49
85
|
return basePrice.plus(getBundleUnitPrice(product, true));
|
|
50
86
|
}
|
|
87
|
+
function isGeneratedVoucherProduct(product) {
|
|
88
|
+
var record = product;
|
|
89
|
+
var metadata = (record === null || record === void 0 ? void 0 : record.metadata) || {};
|
|
90
|
+
return (record === null || record === void 0 ? void 0 : record.extension_type) === 'product_voucher' || metadata.parent_order_detail_id !== undefined || metadata.gift_card_type !== undefined;
|
|
91
|
+
}
|
|
51
92
|
function buildSurchargeServiceItems(products) {
|
|
52
93
|
return products.map(function (product) {
|
|
53
94
|
var _product$is_charge_ta, _product$metadata5, _product$metadata6;
|
|
54
95
|
var quantity = getSafeNum(product.num);
|
|
55
96
|
var unitTotal = getUnitPaymentTotal(product);
|
|
97
|
+
var options = getProductSkuOptions(product);
|
|
98
|
+
var persistedSurchargeFee = getPersistedMainSurchargeFee(product);
|
|
56
99
|
return {
|
|
57
100
|
id: product.product_id,
|
|
58
101
|
num: quantity,
|
|
@@ -64,19 +107,443 @@ function buildSurchargeServiceItems(products) {
|
|
|
64
107
|
product: {
|
|
65
108
|
discount_list: product.discount_list || [],
|
|
66
109
|
product_bundle: product.product_bundle || [],
|
|
67
|
-
|
|
110
|
+
product_sku: product.product_sku || {
|
|
111
|
+
option: options
|
|
112
|
+
}
|
|
68
113
|
}
|
|
69
114
|
},
|
|
70
115
|
bundle: product.product_bundle || [],
|
|
71
|
-
option:
|
|
72
|
-
options:
|
|
116
|
+
option: options,
|
|
117
|
+
options: options,
|
|
73
118
|
relation_details: [],
|
|
74
|
-
metadata: product.metadata || {},
|
|
119
|
+
metadata: _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
|
|
120
|
+
__persisted_surcharge_fee: persistedSurchargeFee === null || persistedSurchargeFee === void 0 ? void 0 : persistedSurchargeFee.toFixed(2)
|
|
121
|
+
}),
|
|
75
122
|
start_date: ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.start_date) || '',
|
|
76
123
|
start_time: ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.start_time) || ''
|
|
77
124
|
};
|
|
78
125
|
});
|
|
79
126
|
}
|
|
127
|
+
function getRelationSurchargeIds(item) {
|
|
128
|
+
var _item$metadata;
|
|
129
|
+
var ids = [].concat(_toConsumableArray(Array.isArray(item === null || item === void 0 ? void 0 : item.relation_surcharge_ids) ? item.relation_surcharge_ids : []), _toConsumableArray(Array.isArray(item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.relation_surcharge_ids) ? item.metadata.relation_surcharge_ids : []));
|
|
130
|
+
return _toConsumableArray(new Set(ids.filter(function (id) {
|
|
131
|
+
return id !== undefined && id !== null && id !== '';
|
|
132
|
+
})));
|
|
133
|
+
}
|
|
134
|
+
function getSurchargeConfigId(config) {
|
|
135
|
+
var _config$id;
|
|
136
|
+
return (_config$id = config === null || config === void 0 ? void 0 : config.id) !== null && _config$id !== void 0 ? _config$id : config === null || config === void 0 ? void 0 : config.surcharge_id;
|
|
137
|
+
}
|
|
138
|
+
function getSurchargeConfigById(surchargeList) {
|
|
139
|
+
var map = new Map();
|
|
140
|
+
var _iterator = _createForOfIteratorHelper(surchargeList || []),
|
|
141
|
+
_step;
|
|
142
|
+
try {
|
|
143
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
144
|
+
var config = _step.value;
|
|
145
|
+
var id = getSurchargeConfigId(config);
|
|
146
|
+
if (id !== undefined) map.set(id, config);
|
|
147
|
+
}
|
|
148
|
+
} catch (err) {
|
|
149
|
+
_iterator.e(err);
|
|
150
|
+
} finally {
|
|
151
|
+
_iterator.f();
|
|
152
|
+
}
|
|
153
|
+
return map;
|
|
154
|
+
}
|
|
155
|
+
function getMainSurchargeUnitAmount(product) {
|
|
156
|
+
var _ref, _ref2, _record$metadata$main, _record$metadata, _record$metadata2;
|
|
157
|
+
var record = product;
|
|
158
|
+
return toDecimal((_ref = (_ref2 = (_record$metadata$main = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.main_product_attached_bundle_selling_price) !== null && _record$metadata$main !== void 0 ? _record$metadata$main : (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.main_product_selling_price) !== null && _ref2 !== void 0 ? _ref2 : record.selling_price) !== null && _ref !== void 0 ? _ref : 0);
|
|
159
|
+
}
|
|
160
|
+
function getBundleSurchargeUnitAmount(bundle) {
|
|
161
|
+
var _ref3, _ref4, _bundle$bundle_sellin;
|
|
162
|
+
return toDecimal((_ref3 = (_ref4 = (_bundle$bundle_sellin = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle === null || bundle === void 0 ? void 0 : bundle.bundle_sum_price) !== null && _ref4 !== void 0 ? _ref4 : bundle === null || bundle === void 0 ? void 0 : bundle.price) !== null && _ref3 !== void 0 ? _ref3 : 0);
|
|
163
|
+
}
|
|
164
|
+
function getBundleProductId(bundle) {
|
|
165
|
+
var _ref5, _bundle$bundle_produc;
|
|
166
|
+
var id = (_ref5 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref5 !== void 0 ? _ref5 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id;
|
|
167
|
+
if (id === undefined || id === null || id === '') return null;
|
|
168
|
+
var parsed = Number(id);
|
|
169
|
+
if (!Number.isFinite(parsed)) return null;
|
|
170
|
+
return parsed;
|
|
171
|
+
}
|
|
172
|
+
function getPersistedMainSurchargeFee(product) {
|
|
173
|
+
var _ref6, _product$surcharge_fe, _product$metadata7;
|
|
174
|
+
if ((product === null || product === void 0 ? void 0 : product.order_detail_id) === undefined || (product === null || product === void 0 ? void 0 : product.order_detail_id) === null) return null;
|
|
175
|
+
var value = (_ref6 = (_product$surcharge_fe = product === null || product === void 0 ? void 0 : product.surcharge_fee) !== null && _product$surcharge_fe !== void 0 ? _product$surcharge_fe : product === null || product === void 0 ? void 0 : product.main_product_attached_bundle_surcharge_fee) !== null && _ref6 !== void 0 ? _ref6 : product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_attached_bundle_surcharge_fee;
|
|
176
|
+
if (value === undefined || value === null || value === '') return null;
|
|
177
|
+
return toDecimal(value);
|
|
178
|
+
}
|
|
179
|
+
function getPersistedSourceSurchargeFee(sourceItem) {
|
|
180
|
+
var _sourceItem$metadata;
|
|
181
|
+
var value = sourceItem === null || sourceItem === void 0 || (_sourceItem$metadata = sourceItem.metadata) === null || _sourceItem$metadata === void 0 ? void 0 : _sourceItem$metadata.__persisted_surcharge_fee;
|
|
182
|
+
if (value === undefined || value === null || value === '') return null;
|
|
183
|
+
return toDecimal(value);
|
|
184
|
+
}
|
|
185
|
+
function getPersistedSurchargeRemainder(item, sourceItem) {
|
|
186
|
+
var _ref7, _sourceItem$metadata$, _sourceItem$metadata2, _item$metadata2;
|
|
187
|
+
var value = (_ref7 = (_sourceItem$metadata$ = sourceItem === null || sourceItem === void 0 || (_sourceItem$metadata2 = sourceItem.metadata) === null || _sourceItem$metadata2 === void 0 ? void 0 : _sourceItem$metadata2.surcharge_rounding_remainder) !== null && _sourceItem$metadata$ !== void 0 ? _sourceItem$metadata$ : item === null || item === void 0 ? void 0 : item.surcharge_rounding_remainder) !== null && _ref7 !== void 0 ? _ref7 : item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.surcharge_rounding_remainder;
|
|
188
|
+
if (value === undefined || value === null || value === '') return null;
|
|
189
|
+
return toDecimal(value);
|
|
190
|
+
}
|
|
191
|
+
function getPersistedQuantity(item, fallbackQuantity) {
|
|
192
|
+
var _item$product_quantit;
|
|
193
|
+
var isPersistedLine = (item === null || item === void 0 ? void 0 : item.order_detail_id) !== undefined && (item === null || item === void 0 ? void 0 : item.order_detail_id) !== null;
|
|
194
|
+
if (!isPersistedLine) return new Decimal(0);
|
|
195
|
+
var value = (_item$product_quantit = item === null || item === void 0 ? void 0 : item.product_quantity) !== null && _item$product_quantit !== void 0 ? _item$product_quantit : item === null || item === void 0 ? void 0 : item.quantity;
|
|
196
|
+
var parsed = new Decimal(value || 0);
|
|
197
|
+
if (parsed.lte(0)) return Decimal.min(fallbackQuantity, 1);
|
|
198
|
+
return Decimal.min(fallbackQuantity, parsed);
|
|
199
|
+
}
|
|
200
|
+
function getPersistedBundleSurchargeFee(bundle, product) {
|
|
201
|
+
var _bundle$surcharge_fee, _bundle$metadata;
|
|
202
|
+
if ((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) === undefined && (product === null || product === void 0 ? void 0 : product.order_detail_id) === undefined) return null;
|
|
203
|
+
if ((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) === null && (product === null || product === void 0 ? void 0 : product.order_detail_id) === null) return null;
|
|
204
|
+
var value = (_bundle$surcharge_fee = bundle === null || bundle === void 0 ? void 0 : bundle.surcharge_fee) !== null && _bundle$surcharge_fee !== void 0 ? _bundle$surcharge_fee : bundle === null || bundle === void 0 || (_bundle$metadata = bundle.metadata) === null || _bundle$metadata === void 0 ? void 0 : _bundle$metadata.surcharge_fee;
|
|
205
|
+
if (value === undefined || value === null || value === '') return null;
|
|
206
|
+
return toDecimal(value);
|
|
207
|
+
}
|
|
208
|
+
function createSurchargeAllocationNodes(products, sourceItems) {
|
|
209
|
+
var nodes = [];
|
|
210
|
+
for (var productIndex = 0; productIndex < products.length; productIndex++) {
|
|
211
|
+
var _product$product_id, _getPersistedSourceSu;
|
|
212
|
+
var product = products[productIndex];
|
|
213
|
+
var sourceItem = sourceItems[productIndex] || {};
|
|
214
|
+
var productQuantity = new Decimal(getSafeNum(product.num));
|
|
215
|
+
for (var bundleIndex = 0; bundleIndex < (product.product_bundle || []).length; bundleIndex++) {
|
|
216
|
+
var _sourceItem$bundle, _bundle$num, _bundle$num2;
|
|
217
|
+
var bundle = product.product_bundle[bundleIndex];
|
|
218
|
+
if (!isBundleOriginalPrice(bundle)) continue;
|
|
219
|
+
var sourceBundle = (sourceItem === null || sourceItem === void 0 || (_sourceItem$bundle = sourceItem.bundle) === null || _sourceItem$bundle === void 0 ? void 0 : _sourceItem$bundle[bundleIndex]) || {};
|
|
220
|
+
nodes.push({
|
|
221
|
+
kind: 'bundle',
|
|
222
|
+
target: bundle,
|
|
223
|
+
source: sourceBundle,
|
|
224
|
+
productId: getBundleProductId(bundle),
|
|
225
|
+
unitAmount: getBundleSurchargeUnitAmount(bundle),
|
|
226
|
+
quantity: new Decimal(getSafeNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity)).times(productQuantity),
|
|
227
|
+
persistedQuantity: getPersistedQuantity(bundle, new Decimal(getSafeNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity)).times(productQuantity)),
|
|
228
|
+
relationSurchargeIds: getRelationSurchargeIds(sourceBundle).length ? getRelationSurchargeIds(sourceBundle) : getRelationSurchargeIds(bundle),
|
|
229
|
+
persistedUnitSurchargeFee: getPersistedBundleSurchargeFee(bundle, product),
|
|
230
|
+
persistedSurchargeRemainder: getPersistedSurchargeRemainder(bundle, sourceBundle)
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
nodes.push({
|
|
234
|
+
kind: 'main',
|
|
235
|
+
target: product,
|
|
236
|
+
source: sourceItem,
|
|
237
|
+
productId: (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : null,
|
|
238
|
+
unitAmount: getMainSurchargeUnitAmount(product),
|
|
239
|
+
quantity: productQuantity,
|
|
240
|
+
persistedQuantity: getPersistedQuantity(product, productQuantity),
|
|
241
|
+
relationSurchargeIds: getRelationSurchargeIds(sourceItem).length ? getRelationSurchargeIds(sourceItem) : getRelationSurchargeIds(product),
|
|
242
|
+
persistedUnitSurchargeFee: (_getPersistedSourceSu = getPersistedSourceSurchargeFee(sourceItem)) !== null && _getPersistedSourceSu !== void 0 ? _getPersistedSourceSu : getPersistedMainSurchargeFee(product),
|
|
243
|
+
persistedSurchargeRemainder: getPersistedSurchargeRemainder(product, sourceItem)
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return nodes;
|
|
247
|
+
}
|
|
248
|
+
function resetProductSurchargeFields(products) {
|
|
249
|
+
for (var _i = 0, _arr = products; _i < _arr.length; _i++) {
|
|
250
|
+
var product = _arr[_i];
|
|
251
|
+
product.surcharge_fee = 0;
|
|
252
|
+
product.main_product_attached_bundle_surcharge_fee = '0.00';
|
|
253
|
+
product.surcharge_rounding_remainder = 0;
|
|
254
|
+
product.relation_surcharge_ids = [];
|
|
255
|
+
var _iterator2 = _createForOfIteratorHelper(product.product_bundle || []),
|
|
256
|
+
_step2;
|
|
257
|
+
try {
|
|
258
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
259
|
+
var bundle = _step2.value;
|
|
260
|
+
bundle.surcharge_fee = 0;
|
|
261
|
+
bundle.relation_surcharge_ids = [];
|
|
262
|
+
bundle.metadata = _objectSpread(_objectSpread({}, bundle.metadata || {}), {}, {
|
|
263
|
+
surcharge_fee: '0.00',
|
|
264
|
+
surcharge_rounding_remainder: '0.00',
|
|
265
|
+
relation_surcharge_ids: []
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
} catch (err) {
|
|
269
|
+
_iterator2.e(err);
|
|
270
|
+
} finally {
|
|
271
|
+
_iterator2.f();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function getPersistedSurchargeIds(nodes) {
|
|
276
|
+
var ids = new Set();
|
|
277
|
+
var _iterator3 = _createForOfIteratorHelper(nodes),
|
|
278
|
+
_step3;
|
|
279
|
+
try {
|
|
280
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
281
|
+
var node = _step3.value;
|
|
282
|
+
if (!node.persistedUnitSurchargeFee || node.persistedUnitSurchargeFee.lte(0)) continue;
|
|
283
|
+
var _iterator4 = _createForOfIteratorHelper(node.relationSurchargeIds),
|
|
284
|
+
_step4;
|
|
285
|
+
try {
|
|
286
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
287
|
+
var surchargeId = _step4.value;
|
|
288
|
+
ids.add(surchargeId);
|
|
289
|
+
}
|
|
290
|
+
} catch (err) {
|
|
291
|
+
_iterator4.e(err);
|
|
292
|
+
} finally {
|
|
293
|
+
_iterator4.f();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
} catch (err) {
|
|
297
|
+
_iterator3.e(err);
|
|
298
|
+
} finally {
|
|
299
|
+
_iterator3.f();
|
|
300
|
+
}
|
|
301
|
+
return ids;
|
|
302
|
+
}
|
|
303
|
+
function buildSurchargeQuantityTotals(nodes) {
|
|
304
|
+
var totals = new Map();
|
|
305
|
+
var _iterator5 = _createForOfIteratorHelper(nodes),
|
|
306
|
+
_step5;
|
|
307
|
+
try {
|
|
308
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
309
|
+
var node = _step5.value;
|
|
310
|
+
var _iterator6 = _createForOfIteratorHelper(node.relationSurchargeIds),
|
|
311
|
+
_step6;
|
|
312
|
+
try {
|
|
313
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
314
|
+
var surchargeId = _step6.value;
|
|
315
|
+
totals.set(surchargeId, (totals.get(surchargeId) || new Decimal(0)).plus(node.quantity));
|
|
316
|
+
}
|
|
317
|
+
} catch (err) {
|
|
318
|
+
_iterator6.e(err);
|
|
319
|
+
} finally {
|
|
320
|
+
_iterator6.f();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
} catch (err) {
|
|
324
|
+
_iterator5.e(err);
|
|
325
|
+
} finally {
|
|
326
|
+
_iterator5.f();
|
|
327
|
+
}
|
|
328
|
+
return totals;
|
|
329
|
+
}
|
|
330
|
+
function getFallbackAllProductSurchargeIds(surchargeList) {
|
|
331
|
+
return (surchargeList || []).reduce(function (ids, config) {
|
|
332
|
+
var _config$open_product, _config$is_all;
|
|
333
|
+
var id = getSurchargeConfigId(config);
|
|
334
|
+
if (id === undefined) return ids;
|
|
335
|
+
if (Number((_config$open_product = config.open_product) !== null && _config$open_product !== void 0 ? _config$open_product : 0) === 0) return ids;
|
|
336
|
+
if (Number((_config$is_all = config.is_all) !== null && _config$is_all !== void 0 ? _config$is_all : 0) !== 1) return ids;
|
|
337
|
+
ids.push(id);
|
|
338
|
+
return ids;
|
|
339
|
+
}, []);
|
|
340
|
+
}
|
|
341
|
+
function getBackendSurchargeState(stateMap, surchargeId, config) {
|
|
342
|
+
var state = stateMap.get(surchargeId);
|
|
343
|
+
if (!state) {
|
|
344
|
+
state = {
|
|
345
|
+
config: config,
|
|
346
|
+
amount: new Decimal(0),
|
|
347
|
+
totalOffsetFee: new Decimal(0),
|
|
348
|
+
calculatedQuantity: new Decimal(0),
|
|
349
|
+
fixedIncluded: false,
|
|
350
|
+
fixedRemainderAssigned: false
|
|
351
|
+
};
|
|
352
|
+
stateMap.set(surchargeId, state);
|
|
353
|
+
}
|
|
354
|
+
return state;
|
|
355
|
+
}
|
|
356
|
+
function buildSurchargeResultItem(config, surchargeId, amount, index) {
|
|
357
|
+
var name = (config === null || config === void 0 ? void 0 : config.name) || (config === null || config === void 0 ? void 0 : config.label) || {};
|
|
358
|
+
return {
|
|
359
|
+
key: "custom_surcharge_".concat(index),
|
|
360
|
+
label: name,
|
|
361
|
+
name: name,
|
|
362
|
+
value: amount.toNumber(),
|
|
363
|
+
surcharge_id: surchargeId,
|
|
364
|
+
description: config === null || config === void 0 ? void 0 : config.description,
|
|
365
|
+
type: 'default',
|
|
366
|
+
fixed: config === null || config === void 0 ? void 0 : config.fixed,
|
|
367
|
+
amount: amount.toNumber(),
|
|
368
|
+
percentage: config === null || config === void 0 ? void 0 : config.percentage,
|
|
369
|
+
metadata: {
|
|
370
|
+
open_product: config === null || config === void 0 ? void 0 : config.open_product
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function applySurchargeNodeResult(node, params) {
|
|
375
|
+
var unitSurchargeFee = params.unitSurchargeFee,
|
|
376
|
+
roundingRemainder = params.roundingRemainder,
|
|
377
|
+
surchargeIds = params.surchargeIds;
|
|
378
|
+
if (node.kind === 'main') {
|
|
379
|
+
node.target.surcharge_fee = unitSurchargeFee.toNumber();
|
|
380
|
+
node.target.main_product_attached_bundle_surcharge_fee = toFixed2(unitSurchargeFee);
|
|
381
|
+
node.target.surcharge_rounding_remainder = roundingRemainder.toNumber();
|
|
382
|
+
node.target.relation_surcharge_ids = surchargeIds;
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
node.target.surcharge_fee = unitSurchargeFee.toNumber();
|
|
386
|
+
node.target.relation_surcharge_ids = surchargeIds;
|
|
387
|
+
node.target.metadata = _objectSpread(_objectSpread({}, node.target.metadata || {}), {}, {
|
|
388
|
+
surcharge_fee: toFixed2(unitSurchargeFee),
|
|
389
|
+
surcharge_rounding_remainder: toFixed2(roundingRemainder),
|
|
390
|
+
relation_surcharge_ids: surchargeIds
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function calculateBackendProductSurcharges(params) {
|
|
394
|
+
var products = params.products,
|
|
395
|
+
sourceItems = params.sourceItems,
|
|
396
|
+
surchargeList = params.surchargeList;
|
|
397
|
+
resetProductSurchargeFields(products);
|
|
398
|
+
var configById = getSurchargeConfigById(surchargeList);
|
|
399
|
+
var nodes = createSurchargeAllocationNodes(products, sourceItems);
|
|
400
|
+
var fallbackAllProductSurchargeIds = getFallbackAllProductSurchargeIds(surchargeList);
|
|
401
|
+
var _iterator7 = _createForOfIteratorHelper(nodes),
|
|
402
|
+
_step7;
|
|
403
|
+
try {
|
|
404
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
405
|
+
var node = _step7.value;
|
|
406
|
+
if (node.relationSurchargeIds.length === 0) {
|
|
407
|
+
node.relationSurchargeIds = fallbackAllProductSurchargeIds;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
} catch (err) {
|
|
411
|
+
_iterator7.e(err);
|
|
412
|
+
} finally {
|
|
413
|
+
_iterator7.f();
|
|
414
|
+
}
|
|
415
|
+
var persistedSurchargeIds = getPersistedSurchargeIds(nodes);
|
|
416
|
+
var quantityTotals = buildSurchargeQuantityTotals(nodes);
|
|
417
|
+
var stateMap = new Map();
|
|
418
|
+
var _iterator8 = _createForOfIteratorHelper(nodes),
|
|
419
|
+
_step8;
|
|
420
|
+
try {
|
|
421
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
422
|
+
var _node = _step8.value;
|
|
423
|
+
var unitSurchargeFee = new Decimal(0);
|
|
424
|
+
var roundingRemainder = new Decimal(0);
|
|
425
|
+
var appliedSurchargeIds = [];
|
|
426
|
+
var persistedRemainderApplied = false;
|
|
427
|
+
var _iterator10 = _createForOfIteratorHelper(_node.relationSurchargeIds),
|
|
428
|
+
_step10;
|
|
429
|
+
try {
|
|
430
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
431
|
+
var surchargeId = _step10.value;
|
|
432
|
+
var config = configById.get(surchargeId);
|
|
433
|
+
var totalQuantity = quantityTotals.get(surchargeId) || new Decimal(0);
|
|
434
|
+
if (totalQuantity.lte(0)) continue;
|
|
435
|
+
var persistedUnitSurchargeFee = _node.persistedUnitSurchargeFee;
|
|
436
|
+
if (persistedUnitSurchargeFee && persistedUnitSurchargeFee.gt(0)) {
|
|
437
|
+
var persistedQuantity = Decimal.min(_node.persistedQuantity, _node.quantity);
|
|
438
|
+
var deltaQuantity = Decimal.max(_node.quantity.minus(persistedQuantity), 0);
|
|
439
|
+
var _state = getBackendSurchargeState(stateMap, surchargeId, config || {
|
|
440
|
+
surcharge_id: surchargeId
|
|
441
|
+
});
|
|
442
|
+
var persistedSurchargeRemainder = !persistedRemainderApplied && _node.persistedSurchargeRemainder ? _node.persistedSurchargeRemainder : new Decimal(0);
|
|
443
|
+
_state.amount = bcAdd(bcAdd(_state.amount, bcMul(persistedUnitSurchargeFee, persistedQuantity, 2), 2), persistedSurchargeRemainder, 2);
|
|
444
|
+
var _fixed = new Decimal((config === null || config === void 0 ? void 0 : config.fixed) || 0);
|
|
445
|
+
if (_fixed.gt(0)) _state.fixedIncluded = true;
|
|
446
|
+
var nodeTotalSurcharge = bcAdd(bcMul(persistedUnitSurchargeFee, persistedQuantity, 2), persistedSurchargeRemainder, 2);
|
|
447
|
+
if (config && deltaQuantity.gt(0)) {
|
|
448
|
+
var _percentage = new Decimal(config.percentage || 0);
|
|
449
|
+
var deltaUnitPercentageFee = Decimal.max(0, bcMul(_node.unitAmount, _percentage, 2));
|
|
450
|
+
var deltaSurcharge = bcMul(deltaQuantity, deltaUnitPercentageFee, 2);
|
|
451
|
+
_state.amount = bcAdd(_state.amount, deltaSurcharge, 2);
|
|
452
|
+
nodeTotalSurcharge = bcAdd(nodeTotalSurcharge, deltaSurcharge, 2);
|
|
453
|
+
}
|
|
454
|
+
if (_node.quantity.gt(0)) {
|
|
455
|
+
unitSurchargeFee = bcAdd(unitSurchargeFee, bcDiv(nodeTotalSurcharge, _node.quantity, 2), 2);
|
|
456
|
+
}
|
|
457
|
+
if (!persistedSurchargeRemainder.eq(0)) {
|
|
458
|
+
roundingRemainder = bcAdd(roundingRemainder, persistedSurchargeRemainder, 2);
|
|
459
|
+
persistedRemainderApplied = true;
|
|
460
|
+
}
|
|
461
|
+
appliedSurchargeIds.push(surchargeId);
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
if (!config) continue;
|
|
465
|
+
var percentage = new Decimal(config.percentage || 0);
|
|
466
|
+
var fixed = new Decimal(config.fixed || 0);
|
|
467
|
+
var unitPercentageFee = Decimal.max(0, bcMul(_node.unitAmount, percentage, 2));
|
|
468
|
+
var percentageTotalFee = bcMul(_node.quantity, unitPercentageFee, 2);
|
|
469
|
+
var unitFixedFee = new Decimal(0);
|
|
470
|
+
var fixedRemainder = new Decimal(0);
|
|
471
|
+
if (fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
|
|
472
|
+
unitFixedFee = bcDiv(fixed, totalQuantity, 2);
|
|
473
|
+
var distributedFixed = bcMul(unitFixedFee, totalQuantity, 2);
|
|
474
|
+
fixedRemainder = bcSub(fixed, distributedFixed, 2);
|
|
475
|
+
}
|
|
476
|
+
var currentUnitSurcharge = Decimal.max(0, bcAdd(unitPercentageFee, unitFixedFee, 2));
|
|
477
|
+
if (currentUnitSurcharge.lte(0)) continue;
|
|
478
|
+
var state = getBackendSurchargeState(stateMap, surchargeId, config);
|
|
479
|
+
state.amount = bcAdd(state.amount, percentageTotalFee, 2);
|
|
480
|
+
var precisePercentage = Decimal.max(0, bcMul(_node.unitAmount, percentage, 6));
|
|
481
|
+
var offsetBaseFee = Decimal.max(0, bcSub(precisePercentage, unitPercentageFee, 6));
|
|
482
|
+
state.totalOffsetFee = bcAdd(state.totalOffsetFee, bcMul(offsetBaseFee, _node.quantity, 6), 6);
|
|
483
|
+
state.calculatedQuantity = bcAdd(state.calculatedQuantity, _node.quantity, 6);
|
|
484
|
+
if (!state.fixedIncluded && fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
|
|
485
|
+
state.amount = bcAdd(state.amount, fixed, 2);
|
|
486
|
+
state.fixedIncluded = true;
|
|
487
|
+
}
|
|
488
|
+
if (!state.fixedRemainderAssigned && !fixedRemainder.eq(0)) {
|
|
489
|
+
state.fixedRemainderAssigned = true;
|
|
490
|
+
roundingRemainder = bcAdd(roundingRemainder, fixedRemainder, 2);
|
|
491
|
+
}
|
|
492
|
+
if (state.calculatedQuantity.gte(totalQuantity) && state.totalOffsetFee.gt(0)) {
|
|
493
|
+
var totalOffsetFee = toAmountFormat(state.totalOffsetFee);
|
|
494
|
+
state.amount = bcAdd(state.amount, totalOffsetFee, 2);
|
|
495
|
+
roundingRemainder = bcAdd(roundingRemainder, totalOffsetFee, 2);
|
|
496
|
+
state.totalOffsetFee = new Decimal(0);
|
|
497
|
+
}
|
|
498
|
+
unitSurchargeFee = bcAdd(unitSurchargeFee, currentUnitSurcharge, 2);
|
|
499
|
+
appliedSurchargeIds.push(surchargeId);
|
|
500
|
+
}
|
|
501
|
+
} catch (err) {
|
|
502
|
+
_iterator10.e(err);
|
|
503
|
+
} finally {
|
|
504
|
+
_iterator10.f();
|
|
505
|
+
}
|
|
506
|
+
applySurchargeNodeResult(_node, {
|
|
507
|
+
unitSurchargeFee: unitSurchargeFee,
|
|
508
|
+
roundingRemainder: roundingRemainder,
|
|
509
|
+
surchargeIds: appliedSurchargeIds
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
} catch (err) {
|
|
513
|
+
_iterator8.e(err);
|
|
514
|
+
} finally {
|
|
515
|
+
_iterator8.f();
|
|
516
|
+
}
|
|
517
|
+
var result = (surchargeList || []).reduce(function (items, config, index) {
|
|
518
|
+
var surchargeId = getSurchargeConfigId(config);
|
|
519
|
+
if (surchargeId === undefined) return items;
|
|
520
|
+
var state = stateMap.get(surchargeId);
|
|
521
|
+
if (!state || state.amount.lte(0)) return items;
|
|
522
|
+
items.push(buildSurchargeResultItem(config, surchargeId, state.amount, index));
|
|
523
|
+
return items;
|
|
524
|
+
}, []);
|
|
525
|
+
var includedIds = new Set(result.map(function (item) {
|
|
526
|
+
return item === null || item === void 0 ? void 0 : item.surcharge_id;
|
|
527
|
+
}).filter(function (id) {
|
|
528
|
+
return id !== undefined;
|
|
529
|
+
}));
|
|
530
|
+
var _iterator9 = _createForOfIteratorHelper(stateMap.entries()),
|
|
531
|
+
_step9;
|
|
532
|
+
try {
|
|
533
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
534
|
+
var _step9$value = _slicedToArray(_step9.value, 2),
|
|
535
|
+
_surchargeId = _step9$value[0],
|
|
536
|
+
_state2 = _step9$value[1];
|
|
537
|
+
if (includedIds.has(_surchargeId) || _state2.amount.lte(0)) continue;
|
|
538
|
+
result.push(buildSurchargeResultItem(_state2.config, _surchargeId, _state2.amount, result.length));
|
|
539
|
+
}
|
|
540
|
+
} catch (err) {
|
|
541
|
+
_iterator9.e(err);
|
|
542
|
+
} finally {
|
|
543
|
+
_iterator9.f();
|
|
544
|
+
}
|
|
545
|
+
return result;
|
|
546
|
+
}
|
|
80
547
|
function getProductDepositData(product) {
|
|
81
548
|
var _product$_origin, _product$_origin2;
|
|
82
549
|
var rootDepositData = (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.custom_deposit_data;
|
|
@@ -111,11 +578,11 @@ function calculateProductsDeposit(products) {
|
|
|
111
578
|
var hasDeposit = false;
|
|
112
579
|
var policyIds = new Set();
|
|
113
580
|
var policyDataMap = new Map();
|
|
114
|
-
var
|
|
115
|
-
|
|
581
|
+
var _iterator11 = _createForOfIteratorHelper(products),
|
|
582
|
+
_step11;
|
|
116
583
|
try {
|
|
117
|
-
for (
|
|
118
|
-
var product =
|
|
584
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
585
|
+
var product = _step11.value;
|
|
119
586
|
var depositData = getProductDepositData(product);
|
|
120
587
|
if (!depositData || depositData.has_deposit != 1) continue;
|
|
121
588
|
var num = getSafeNum(product.num);
|
|
@@ -128,45 +595,45 @@ function calculateProductsDeposit(products) {
|
|
|
128
595
|
var itemDeposit = fixed.plus(percentage.times(productTotal));
|
|
129
596
|
totalDeposit = totalDeposit.plus(itemDeposit);
|
|
130
597
|
hasDeposit = true;
|
|
131
|
-
var
|
|
132
|
-
|
|
598
|
+
var _iterator13 = _createForOfIteratorHelper(collectDepositPolicyIds(depositData)),
|
|
599
|
+
_step13;
|
|
133
600
|
try {
|
|
134
|
-
for (
|
|
135
|
-
var id =
|
|
601
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
602
|
+
var id = _step13.value;
|
|
136
603
|
policyIds.add(id);
|
|
137
604
|
}
|
|
138
605
|
} catch (err) {
|
|
139
|
-
|
|
606
|
+
_iterator13.e(err);
|
|
140
607
|
} finally {
|
|
141
|
-
|
|
608
|
+
_iterator13.f();
|
|
142
609
|
}
|
|
143
|
-
var
|
|
144
|
-
|
|
610
|
+
var _iterator14 = _createForOfIteratorHelper(collectDepositPolicyData(depositData)),
|
|
611
|
+
_step14;
|
|
145
612
|
try {
|
|
146
|
-
for (
|
|
147
|
-
var policy =
|
|
613
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
614
|
+
var policy = _step14.value;
|
|
148
615
|
if (!policyDataMap.has(policy.id)) {
|
|
149
616
|
policyDataMap.set(policy.id, policy);
|
|
150
617
|
}
|
|
151
618
|
policyIds.add(policy.id);
|
|
152
619
|
}
|
|
153
620
|
} catch (err) {
|
|
154
|
-
|
|
621
|
+
_iterator14.e(err);
|
|
155
622
|
} finally {
|
|
156
|
-
|
|
623
|
+
_iterator14.f();
|
|
157
624
|
}
|
|
158
625
|
}
|
|
159
626
|
} catch (err) {
|
|
160
|
-
|
|
627
|
+
_iterator11.e(err);
|
|
161
628
|
} finally {
|
|
162
|
-
|
|
629
|
+
_iterator11.f();
|
|
163
630
|
}
|
|
164
631
|
if (!hasDeposit) return undefined;
|
|
165
|
-
var
|
|
166
|
-
|
|
632
|
+
var _iterator12 = _createForOfIteratorHelper(policyIds),
|
|
633
|
+
_step12;
|
|
167
634
|
try {
|
|
168
|
-
for (
|
|
169
|
-
var _id =
|
|
635
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
636
|
+
var _id = _step12.value;
|
|
170
637
|
if (!policyDataMap.has(_id)) {
|
|
171
638
|
policyDataMap.set(_id, {
|
|
172
639
|
id: _id,
|
|
@@ -175,9 +642,9 @@ function calculateProductsDeposit(products) {
|
|
|
175
642
|
}
|
|
176
643
|
}
|
|
177
644
|
} catch (err) {
|
|
178
|
-
|
|
645
|
+
_iterator12.e(err);
|
|
179
646
|
} finally {
|
|
180
|
-
|
|
647
|
+
_iterator12.f();
|
|
181
648
|
}
|
|
182
649
|
return {
|
|
183
650
|
total: totalDeposit.toFixed(2),
|
|
@@ -218,58 +685,202 @@ function calculateSingleItemTax(params) {
|
|
|
218
685
|
}
|
|
219
686
|
|
|
220
687
|
/**
|
|
221
|
-
*
|
|
688
|
+
* 主商品 + 非原价(加价/减价)子商品的"折扣后"售价合计(含 option、含主商品折扣,未减整单折扣)。
|
|
222
689
|
*
|
|
223
|
-
*
|
|
224
|
-
* - `metadata.main_product_selling_price` 已是"含 option、含折扣"
|
|
225
|
-
* -
|
|
226
|
-
* - 仅需叠加 `markup` / `markdown` 类 bundle(原价 bundle 已由 `calculateProductsTax` 独立处理)。
|
|
690
|
+
* 对齐后端 metadata.main_product_attached_bundle_selling_price:
|
|
691
|
+
* - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价;
|
|
692
|
+
* - 叠加 `markup` / `markdown` 类 bundle(原价 bundle 由 `calculateProductsTax` 独立处理)。
|
|
227
693
|
*/
|
|
228
|
-
function
|
|
229
|
-
var
|
|
230
|
-
var mainSelling = (
|
|
694
|
+
function getMainAttachedBundleSellingTotal(product) {
|
|
695
|
+
var _ref8, _product$metadata$mai, _product$metadata8, _product$metadata9;
|
|
696
|
+
var mainSelling = (_ref8 = (_product$metadata$mai = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.main_product_selling_price) !== null && _product$metadata$mai !== void 0 ? _product$metadata$mai : (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.main_product_original_price) !== null && _ref8 !== void 0 ? _ref8 : 0;
|
|
231
697
|
var total = toDecimal(mainSelling);
|
|
232
698
|
var bundleItems = product.product_bundle || [];
|
|
233
|
-
var
|
|
234
|
-
|
|
699
|
+
var _iterator15 = _createForOfIteratorHelper(bundleItems),
|
|
700
|
+
_step15;
|
|
235
701
|
try {
|
|
236
|
-
for (
|
|
237
|
-
var bundleItem =
|
|
702
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
703
|
+
var bundleItem = _step15.value;
|
|
238
704
|
if (isBundleMarkupOrDiscount(bundleItem)) {
|
|
239
|
-
var
|
|
240
|
-
|
|
705
|
+
var _bundleItem$num;
|
|
706
|
+
// markdown(减价)按带符号净额取减;markup 维持相加。
|
|
707
|
+
var unit = getBundleSignedUnit(bundleItem);
|
|
241
708
|
var qty = getSafeNum((_bundleItem$num = bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem.quantity);
|
|
242
709
|
total = total.plus(unit.times(qty));
|
|
243
710
|
}
|
|
244
711
|
}
|
|
245
712
|
} catch (err) {
|
|
246
|
-
|
|
713
|
+
_iterator15.e(err);
|
|
247
714
|
} finally {
|
|
248
|
-
|
|
715
|
+
_iterator15.f();
|
|
249
716
|
}
|
|
250
717
|
return Decimal.max(total, 0);
|
|
251
718
|
}
|
|
252
719
|
|
|
720
|
+
/**
|
|
721
|
+
* 获取主商品税费基数(含 option、含主商品折扣、含加价/减价 bundle、已减整单折扣均摊)。
|
|
722
|
+
*
|
|
723
|
+
* 对齐后端 handleMainProductTaxFee:税基使用 main_product_attached_bundle_payment_price。
|
|
724
|
+
* - 优先读取均摊层写入的 payment 价;
|
|
725
|
+
* - 兜底退化为 selling 合计(无整单折扣时两者相等)。
|
|
726
|
+
*/
|
|
727
|
+
function getMainProductPaymentTotal(product) {
|
|
728
|
+
var _product$metadata10;
|
|
729
|
+
var attachedPayment = (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.main_product_attached_bundle_payment_price;
|
|
730
|
+
if (attachedPayment !== undefined && attachedPayment !== null && attachedPayment !== '') {
|
|
731
|
+
return Decimal.max(toDecimal(attachedPayment), 0);
|
|
732
|
+
}
|
|
733
|
+
return getMainAttachedBundleSellingTotal(product);
|
|
734
|
+
}
|
|
735
|
+
function getExplicitTaxRemainder(item) {
|
|
736
|
+
var _item$tax_fee_roundin, _item$metadata3;
|
|
737
|
+
var value = (_item$tax_fee_roundin = item === null || item === void 0 ? void 0 : item.tax_fee_rounding_remainder) !== null && _item$tax_fee_roundin !== void 0 ? _item$tax_fee_roundin : item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.tax_fee_rounding_remainder;
|
|
738
|
+
if (value === undefined || value === null || value === '') return null;
|
|
739
|
+
return new Decimal(value || 0);
|
|
740
|
+
}
|
|
741
|
+
function getPersistedTaxRemainder(item, parentProduct) {
|
|
742
|
+
var isPersistedLine = (item === null || item === void 0 ? void 0 : item.order_detail_id) !== undefined && (item === null || item === void 0 ? void 0 : item.order_detail_id) !== null || (parentProduct === null || parentProduct === void 0 ? void 0 : parentProduct.order_detail_id) !== undefined && (parentProduct === null || parentProduct === void 0 ? void 0 : parentProduct.order_detail_id) !== null;
|
|
743
|
+
if (!isPersistedLine) return null;
|
|
744
|
+
return getExplicitTaxRemainder(item);
|
|
745
|
+
}
|
|
746
|
+
function getPersistedMainTaxFee(product) {
|
|
747
|
+
var _ref9, _product$metadata$mai2, _product$metadata11;
|
|
748
|
+
if ((product === null || product === void 0 ? void 0 : product.order_detail_id) === undefined || (product === null || product === void 0 ? void 0 : product.order_detail_id) === null) return null;
|
|
749
|
+
var value = (_ref9 = (_product$metadata$mai2 = product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.main_product_attached_bundle_tax_fee) !== null && _product$metadata$mai2 !== void 0 ? _product$metadata$mai2 : product === null || product === void 0 ? void 0 : product.main_product_attached_bundle_tax_fee) !== null && _ref9 !== void 0 ? _ref9 : product === null || product === void 0 ? void 0 : product.tax_fee;
|
|
750
|
+
if (value === undefined || value === null || value === '') return null;
|
|
751
|
+
return toDecimal(value);
|
|
752
|
+
}
|
|
753
|
+
function writeTaxRemainder(item, roundingRemainder) {
|
|
754
|
+
item.tax_fee_rounding_remainder = roundingRemainder.toNumber();
|
|
755
|
+
if (item.metadata && _typeof(item.metadata) === 'object') {
|
|
756
|
+
item.metadata.tax_fee_rounding_remainder = roundingRemainder.toFixed(2);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
function resetTaxRemainderFields(products) {
|
|
760
|
+
for (var _i2 = 0, _arr2 = products; _i2 < _arr2.length; _i2++) {
|
|
761
|
+
var product = _arr2[_i2];
|
|
762
|
+
var productRemainder = getPersistedTaxRemainder(product);
|
|
763
|
+
if (productRemainder !== null) {
|
|
764
|
+
product.tax_fee_rounding_remainder = productRemainder.toNumber();
|
|
765
|
+
} else {
|
|
766
|
+
delete product.tax_fee_rounding_remainder;
|
|
767
|
+
}
|
|
768
|
+
product.original_tax_fee_rounding_remainder = 0;
|
|
769
|
+
var _iterator16 = _createForOfIteratorHelper(product.product_bundle || []),
|
|
770
|
+
_step16;
|
|
771
|
+
try {
|
|
772
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
773
|
+
var bundle = _step16.value;
|
|
774
|
+
var bundleRemainder = getPersistedTaxRemainder(bundle, product);
|
|
775
|
+
bundle.metadata = _objectSpread({}, bundle.metadata || {});
|
|
776
|
+
if (bundleRemainder !== null) {
|
|
777
|
+
bundle.metadata.tax_fee_rounding_remainder = bundleRemainder.toFixed(2);
|
|
778
|
+
bundle.tax_fee_rounding_remainder = bundleRemainder.toNumber();
|
|
779
|
+
} else {
|
|
780
|
+
delete bundle.metadata.tax_fee_rounding_remainder;
|
|
781
|
+
delete bundle.tax_fee_rounding_remainder;
|
|
782
|
+
}
|
|
783
|
+
bundle.original_tax_fee_rounding_remainder = 0;
|
|
784
|
+
}
|
|
785
|
+
} catch (err) {
|
|
786
|
+
_iterator16.e(err);
|
|
787
|
+
} finally {
|
|
788
|
+
_iterator16.f();
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
function getBundlePaymentPrice(bundle, product) {
|
|
793
|
+
var _ref10, _ref11, _bundle$bundle_sellin2, _metadata$average_dis, _metadata;
|
|
794
|
+
if ((bundle === null || bundle === void 0 ? void 0 : bundle.bundle_payment_price) !== undefined) return toDecimal(bundle.bundle_payment_price);
|
|
795
|
+
var basePrice = toDecimal((_ref10 = (_ref11 = (_bundle$bundle_sellin2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price) !== null && _bundle$bundle_sellin2 !== void 0 ? _bundle$bundle_sellin2 : bundle === null || bundle === void 0 ? void 0 : bundle.bundle_sum_price) !== null && _ref11 !== void 0 ? _ref11 : bundle === null || bundle === void 0 ? void 0 : bundle.price) !== null && _ref10 !== void 0 ? _ref10 : 0);
|
|
796
|
+
if (!isBundleOriginalPrice(bundle)) return basePrice;
|
|
797
|
+
var averageDiscountRate = toDecimal((_metadata$average_dis = (_metadata = product.metadata) === null || _metadata === void 0 ? void 0 : _metadata.average_discount_amount_rate) !== null && _metadata$average_dis !== void 0 ? _metadata$average_dis : 1);
|
|
798
|
+
return toAmountFormat(bcMul(basePrice, averageDiscountRate, 6));
|
|
799
|
+
}
|
|
800
|
+
function applyBackendTaxRemainder(params) {
|
|
801
|
+
var target = params.target,
|
|
802
|
+
rawTax = params.rawTax,
|
|
803
|
+
formattedTax = params.formattedTax,
|
|
804
|
+
quantity = params.quantity,
|
|
805
|
+
state = params.state;
|
|
806
|
+
var taxFeeDifference = bcMul(bcSub(rawTax, formattedTax, 6), quantity, 6);
|
|
807
|
+
state.difference = bcAdd(state.difference, taxFeeDifference, 6);
|
|
808
|
+
if (state.difference.lt(0.005)) return new Decimal(0);
|
|
809
|
+
var roundingRemainder = toAmountFormat(state.difference);
|
|
810
|
+
writeTaxRemainder(target, roundingRemainder);
|
|
811
|
+
state.difference = bcSub(state.difference, roundingRemainder, 6);
|
|
812
|
+
return roundingRemainder;
|
|
813
|
+
}
|
|
814
|
+
|
|
253
815
|
/**
|
|
254
816
|
* 遍历所有商品计算税费,回写 tax_fee 到每个商品及 bundle 原价子商品,处理舍入差值。
|
|
255
817
|
* 参照 Summary/utils.ts 的 processItemsTax,适配 SalesSummaryProduct 结构。
|
|
256
818
|
*/
|
|
257
819
|
function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
258
820
|
var rate = new Decimal(taxRate);
|
|
259
|
-
var
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
var
|
|
263
|
-
var
|
|
264
|
-
|
|
265
|
-
|
|
821
|
+
var taxRemainderState = {
|
|
822
|
+
difference: new Decimal(0)
|
|
823
|
+
};
|
|
824
|
+
var totalTax = new Decimal(0);
|
|
825
|
+
var totalOriginTax = new Decimal(0);
|
|
826
|
+
resetTaxRemainderFields(products);
|
|
827
|
+
var _iterator17 = _createForOfIteratorHelper(products),
|
|
828
|
+
_step17;
|
|
266
829
|
try {
|
|
267
|
-
for (
|
|
830
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
268
831
|
var _product$is_charge_ta2, _product$is_charge_ta3;
|
|
269
|
-
var product =
|
|
832
|
+
var product = _step17.value;
|
|
270
833
|
var quantity = new Decimal(getSafeNum(product.num));
|
|
271
|
-
|
|
272
|
-
|
|
834
|
+
var productUnitTax = new Decimal(0);
|
|
835
|
+
var productUnitOriginTax = new Decimal(0);
|
|
836
|
+
var bundleItems = product.product_bundle || [];
|
|
837
|
+
var _iterator18 = _createForOfIteratorHelper(bundleItems),
|
|
838
|
+
_step18;
|
|
839
|
+
try {
|
|
840
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
841
|
+
var _bundleItem$num2, _ref12, _ref13, _bundleItem$original_, _ref14, _bundleItem$is_charge, _ref15, _bundleItem$is_charge2;
|
|
842
|
+
var bundleItem = _step18.value;
|
|
843
|
+
if (!isBundleOriginalPrice(bundleItem)) continue;
|
|
844
|
+
var bundleQuantity = new Decimal(getSafeNum((_bundleItem$num2 = bundleItem.num) !== null && _bundleItem$num2 !== void 0 ? _bundleItem$num2 : bundleItem.quantity));
|
|
845
|
+
var totalBundleQuantity = bundleQuantity.times(quantity);
|
|
846
|
+
var bundlePrice = getBundlePaymentPrice(bundleItem, product);
|
|
847
|
+
var bundleOriginalPrice = toDecimal((_ref12 = (_ref13 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref13 !== void 0 ? _ref13 : bundleItem.price) !== null && _ref12 !== void 0 ? _ref12 : 0);
|
|
848
|
+
var bundleSurchargeFee = toDecimal(bundleItem.surcharge_fee);
|
|
849
|
+
var bundleTaxPrecise = calculateSingleItemTax({
|
|
850
|
+
price: bundlePrice.plus(bundleSurchargeFee),
|
|
851
|
+
taxRate: rate,
|
|
852
|
+
isPriceIncludeTax: isPriceIncludeTax,
|
|
853
|
+
isChargeTax: (_ref14 = (_bundleItem$is_charge = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge !== void 0 ? _bundleItem$is_charge : product.is_charge_tax) !== null && _ref14 !== void 0 ? _ref14 : 0
|
|
854
|
+
});
|
|
855
|
+
var bundleTaxRounded = toBackendTaxFee(bundleTaxPrecise);
|
|
856
|
+
bundleItem.tax_fee = bundleTaxRounded.toNumber();
|
|
857
|
+
var persistedBundleRemainder = getPersistedTaxRemainder(bundleItem, product);
|
|
858
|
+
var bundleRemainder = persistedBundleRemainder !== null && persistedBundleRemainder !== void 0 ? persistedBundleRemainder : applyBackendTaxRemainder({
|
|
859
|
+
target: bundleItem,
|
|
860
|
+
rawTax: bundleTaxPrecise,
|
|
861
|
+
formattedTax: bundleTaxRounded,
|
|
862
|
+
quantity: totalBundleQuantity,
|
|
863
|
+
state: taxRemainderState
|
|
864
|
+
});
|
|
865
|
+
if (persistedBundleRemainder) writeTaxRemainder(bundleItem, persistedBundleRemainder);
|
|
866
|
+
var bundleOrigTaxPrecise = calculateSingleItemTax({
|
|
867
|
+
price: bundleOriginalPrice.plus(bundleSurchargeFee),
|
|
868
|
+
taxRate: rate,
|
|
869
|
+
isPriceIncludeTax: isPriceIncludeTax,
|
|
870
|
+
isChargeTax: (_ref15 = (_bundleItem$is_charge2 = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge2 !== void 0 ? _bundleItem$is_charge2 : product.is_charge_tax) !== null && _ref15 !== void 0 ? _ref15 : 0
|
|
871
|
+
});
|
|
872
|
+
var bundleOrigTaxRounded = toAmountFormat(bundleOrigTaxPrecise);
|
|
873
|
+
bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
|
|
874
|
+
productUnitTax = productUnitTax.plus(bundleTaxRounded.times(bundleQuantity));
|
|
875
|
+
productUnitOriginTax = productUnitOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
|
|
876
|
+
totalTax = totalTax.plus(bundleTaxRounded.times(totalBundleQuantity)).plus(bundleRemainder);
|
|
877
|
+
totalOriginTax = totalOriginTax.plus(bundleOrigTaxRounded.times(totalBundleQuantity));
|
|
878
|
+
}
|
|
879
|
+
} catch (err) {
|
|
880
|
+
_iterator18.e(err);
|
|
881
|
+
} finally {
|
|
882
|
+
_iterator18.f();
|
|
883
|
+
}
|
|
273
884
|
var mainTotal = getMainProductPaymentTotal(product);
|
|
274
885
|
var surchargeFee = toDecimal(product.surcharge_fee);
|
|
275
886
|
var mainTaxableBase = mainTotal.lte(0) ? surchargeFee : mainTotal.plus(surchargeFee);
|
|
@@ -279,15 +890,23 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
279
890
|
isPriceIncludeTax: isPriceIncludeTax,
|
|
280
891
|
isChargeTax: (_product$is_charge_ta2 = product.is_charge_tax) !== null && _product$is_charge_ta2 !== void 0 ? _product$is_charge_ta2 : 0
|
|
281
892
|
});
|
|
282
|
-
var mainTaxRounded = mainTaxPrecise
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
893
|
+
var mainTaxRounded = toBackendTaxFee(mainTaxPrecise);
|
|
894
|
+
var persistedMainRemainder = getPersistedTaxRemainder(product);
|
|
895
|
+
var persistedMainTaxFee = getPersistedMainTaxFee(product);
|
|
896
|
+
var persistedQuantity = getPersistedQuantity(product, quantity);
|
|
897
|
+
var deltaQuantity = Decimal.max(quantity.minus(persistedQuantity), 0);
|
|
898
|
+
var shouldUsePersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gte(quantity);
|
|
899
|
+
var shouldSplitPersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gt(0) && deltaQuantity.gt(0);
|
|
900
|
+
var mainRemainder = shouldUsePersistedMainTax || shouldSplitPersistedMainTax ? new Decimal(0) : persistedMainRemainder !== null && persistedMainRemainder !== void 0 ? persistedMainRemainder : applyBackendTaxRemainder({
|
|
901
|
+
target: product,
|
|
902
|
+
rawTax: mainTaxPrecise,
|
|
903
|
+
formattedTax: mainTaxRounded,
|
|
904
|
+
quantity: quantity,
|
|
905
|
+
state: taxRemainderState
|
|
906
|
+
});
|
|
907
|
+
if (persistedMainRemainder && !shouldSplitPersistedMainTax) {
|
|
908
|
+
writeTaxRemainder(product, persistedMainRemainder);
|
|
288
909
|
}
|
|
289
|
-
|
|
290
|
-
// --- 主商品原价税费 ---
|
|
291
910
|
var originalTotal = getUnitOriginalTotal(product);
|
|
292
911
|
var originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
|
|
293
912
|
var originalTaxPrecise = calculateSingleItemTax({
|
|
@@ -296,92 +915,91 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
296
915
|
isPriceIncludeTax: isPriceIncludeTax,
|
|
297
916
|
isChargeTax: (_product$is_charge_ta3 = product.is_charge_tax) !== null && _product$is_charge_ta3 !== void 0 ? _product$is_charge_ta3 : 0
|
|
298
917
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
var _bundleItem$num2, _ref4, _bundleItem$bundle_se2, _ref5, _ref6, _bundleItem$original_, _ref7, _bundleItem$is_charge, _ref8, _bundleItem$is_charge2;
|
|
311
|
-
var bundleItem = _step7.value;
|
|
312
|
-
if (!isBundleOriginalPrice(bundleItem)) continue;
|
|
313
|
-
var bundleQuantity = new Decimal(getSafeNum((_bundleItem$num2 = bundleItem.num) !== null && _bundleItem$num2 !== void 0 ? _bundleItem$num2 : bundleItem.quantity));
|
|
314
|
-
var bundlePrice = toDecimal((_ref4 = (_bundleItem$bundle_se2 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se2 !== void 0 ? _bundleItem$bundle_se2 : bundleItem.price) !== null && _ref4 !== void 0 ? _ref4 : 0);
|
|
315
|
-
var bundleOriginalPrice = toDecimal((_ref5 = (_ref6 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref6 !== void 0 ? _ref6 : bundleItem.price) !== null && _ref5 !== void 0 ? _ref5 : 0);
|
|
316
|
-
var bundleTaxPrecise = calculateSingleItemTax({
|
|
317
|
-
price: bundlePrice,
|
|
318
|
-
taxRate: rate,
|
|
319
|
-
isPriceIncludeTax: isPriceIncludeTax,
|
|
320
|
-
isChargeTax: (_ref7 = (_bundleItem$is_charge = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge !== void 0 ? _bundleItem$is_charge : product.is_charge_tax) !== null && _ref7 !== void 0 ? _ref7 : 0
|
|
321
|
-
});
|
|
322
|
-
var bundleTaxRounded = bundleTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
323
|
-
var bundleOrigTaxPrecise = calculateSingleItemTax({
|
|
324
|
-
price: bundleOriginalPrice,
|
|
325
|
-
taxRate: rate,
|
|
326
|
-
isPriceIncludeTax: isPriceIncludeTax,
|
|
327
|
-
isChargeTax: (_ref8 = (_bundleItem$is_charge2 = bundleItem.is_charge_tax) !== null && _bundleItem$is_charge2 !== void 0 ? _bundleItem$is_charge2 : product.is_charge_tax) !== null && _ref8 !== void 0 ? _ref8 : 0
|
|
328
|
-
});
|
|
329
|
-
var bundleOrigTaxRounded = bundleOrigTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
330
|
-
bundleItem.tax_fee = bundleTaxRounded.toNumber();
|
|
331
|
-
bundleItem.original_tax_fee = bundleOrigTaxRounded.toNumber();
|
|
332
|
-
bundlePreciseTax = bundlePreciseTax.plus(bundleTaxPrecise.times(bundleQuantity));
|
|
333
|
-
bundleRoundedTax = bundleRoundedTax.plus(bundleTaxRounded.times(bundleQuantity));
|
|
334
|
-
bundlePreciseOriginTax = bundlePreciseOriginTax.plus(bundleOrigTaxPrecise.times(bundleQuantity));
|
|
335
|
-
bundleRoundedOriginTax = bundleRoundedOriginTax.plus(bundleOrigTaxRounded.times(bundleQuantity));
|
|
336
|
-
if (bundleTaxPrecise.gt(0)) {
|
|
337
|
-
lastTaxableItem = {
|
|
338
|
-
type: 'bundle',
|
|
339
|
-
item: bundleItem
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
// --- 汇总到商品级 ---
|
|
345
|
-
} catch (err) {
|
|
346
|
-
_iterator7.e(err);
|
|
347
|
-
} finally {
|
|
348
|
-
_iterator7.f();
|
|
918
|
+
var originalTaxRounded = toAmountFormat(originalTaxPrecise);
|
|
919
|
+
var effectiveMainUnitTax = shouldUsePersistedMainTax ? persistedMainTaxFee : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)).div(quantity).toDecimalPlaces(2, Decimal.ROUND_HALF_UP) : mainTaxRounded;
|
|
920
|
+
productUnitTax = productUnitTax.plus(effectiveMainUnitTax);
|
|
921
|
+
productUnitOriginTax = productUnitOriginTax.plus(originalTaxRounded);
|
|
922
|
+
product.main_product_attached_bundle_tax_fee = effectiveMainUnitTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
|
|
923
|
+
product.tax_fee = productUnitTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
|
|
924
|
+
product.original_tax_fee = productUnitOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
925
|
+
totalTax = totalTax.plus(shouldUsePersistedMainTax ? persistedMainTaxFee.times(quantity).plus(persistedMainRemainder || 0) : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)) : mainTaxRounded.times(quantity).plus(mainRemainder));
|
|
926
|
+
totalOriginTax = totalOriginTax.plus(originalTaxRounded.times(quantity));
|
|
927
|
+
if (product.tax_fee_rounding_remainder === undefined) {
|
|
928
|
+
product.tax_fee_rounding_remainder = 0;
|
|
349
929
|
}
|
|
350
|
-
var itemTaxPrecise = mainTaxPrecise.plus(bundlePreciseTax);
|
|
351
|
-
var itemTaxRounded = mainTaxRounded.plus(bundleRoundedTax);
|
|
352
|
-
var itemOriginTaxPrecise = originalTaxPrecise.plus(bundlePreciseOriginTax);
|
|
353
|
-
var itemOriginTaxRounded = originalTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).plus(bundleRoundedOriginTax);
|
|
354
|
-
product.tax_fee = itemTaxRounded.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toFixed(2);
|
|
355
|
-
product.original_tax_fee = itemOriginTaxRounded.toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
356
|
-
preciseTax = preciseTax.plus(itemTaxPrecise.times(quantity));
|
|
357
|
-
roundedTax = roundedTax.plus(itemTaxRounded.times(quantity));
|
|
358
|
-
preciseOriginTax = preciseOriginTax.plus(itemOriginTaxPrecise.times(quantity));
|
|
359
|
-
roundedOriginTax = roundedOriginTax.plus(itemOriginTaxRounded.times(quantity));
|
|
360
930
|
}
|
|
361
|
-
|
|
362
|
-
// --- 舍入差值处理 ---
|
|
363
931
|
} catch (err) {
|
|
364
|
-
|
|
932
|
+
_iterator17.e(err);
|
|
365
933
|
} finally {
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
var expectedTax = preciseTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
369
|
-
var expectedOriginTax = preciseOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
370
|
-
var taxRemainder = expectedTax.minus(roundedTax).toNumber();
|
|
371
|
-
var originTaxRemainder = expectedOriginTax.minus(roundedOriginTax).toNumber();
|
|
372
|
-
if (lastTaxableItem) {
|
|
373
|
-
if (taxRemainder !== 0) {
|
|
374
|
-
lastTaxableItem.item.tax_fee_rounding_remainder = taxRemainder;
|
|
375
|
-
}
|
|
376
|
-
if (originTaxRemainder !== 0) {
|
|
377
|
-
lastTaxableItem.item.original_tax_fee_rounding_remainder = originTaxRemainder;
|
|
378
|
-
}
|
|
934
|
+
_iterator17.f();
|
|
379
935
|
}
|
|
380
936
|
return {
|
|
381
|
-
tax:
|
|
382
|
-
originTax:
|
|
937
|
+
tax: totalTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP),
|
|
938
|
+
originTax: totalOriginTax.toDecimalPlaces(2, Decimal.ROUND_HALF_UP)
|
|
383
939
|
};
|
|
384
940
|
}
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* 整单折扣(shop_discount)按各行 selling 合计占比均摊到 payment 维度。
|
|
944
|
+
*
|
|
945
|
+
* 文档口径:
|
|
946
|
+
* - payment_price = selling_price − 整单折扣均摊;rate = payment/selling(全行同一 rate);
|
|
947
|
+
* - 附加费不受整单折扣影响(基数仍用 selling,本函数写 main_product_attached_bundle_selling_price);
|
|
948
|
+
* - 税费受整单折扣影响(基数用 payment,本函数写 main_product_attached_bundle_payment_price 与
|
|
949
|
+
* 原价子商品 bundle_payment_price)。
|
|
950
|
+
*
|
|
951
|
+
* 与后端一致:bundle_payment_price = bundle_selling_price × rate,
|
|
952
|
+
* main_product_attached_bundle_payment_price = main_product_attached_bundle_selling_price × rate。
|
|
953
|
+
*/
|
|
954
|
+
function allocateShopDiscountToPayment(products, productAmount, shopDiscountAmount) {
|
|
955
|
+
var effectiveDiscount = productAmount.lte(0) ? new Decimal(0) : Decimal.max(Decimal.min(productAmount, shopDiscountAmount), 0);
|
|
956
|
+
var allocatedDiscount = new Decimal(0);
|
|
957
|
+
products.forEach(function (product, index) {
|
|
958
|
+
var quantity = new Decimal(getSafeNum(product.num));
|
|
959
|
+
var sellingUnit = getUnitPaymentTotal(product);
|
|
960
|
+
var lineSellingTotal = sellingUnit.times(quantity);
|
|
961
|
+
var lineDiscount = effectiveDiscount.lte(0) ? new Decimal(0) : index === products.length - 1 ? Decimal.max(effectiveDiscount.minus(allocatedDiscount), 0) : toAmountFormat(lineSellingTotal.div(productAmount).times(effectiveDiscount));
|
|
962
|
+
allocatedDiscount = allocatedDiscount.plus(lineDiscount);
|
|
963
|
+
var unitDiscount = quantity.lte(0) ? new Decimal(0) : lineDiscount.div(quantity);
|
|
964
|
+
var paymentUnit = Decimal.max(sellingUnit.minus(unitDiscount), 0);
|
|
965
|
+
var rate = sellingUnit.lte(0) ? new Decimal(1) : toBcScale(paymentUnit.div(sellingUnit), 6);
|
|
966
|
+
var mainSellingTotal = getMainAttachedBundleSellingTotal(product);
|
|
967
|
+
var mainPaymentTotal = toAmountFormat(bcMul(mainSellingTotal, rate, 6));
|
|
968
|
+
product.metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
|
|
969
|
+
average_discount_amount_rate: rate.toString(),
|
|
970
|
+
main_product_attached_bundle_selling_price: mainSellingTotal.toFixed(2),
|
|
971
|
+
main_product_attached_bundle_payment_price: mainPaymentTotal.toFixed(2)
|
|
972
|
+
});
|
|
973
|
+
var _iterator19 = _createForOfIteratorHelper(product.product_bundle || []),
|
|
974
|
+
_step19;
|
|
975
|
+
try {
|
|
976
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
977
|
+
var bundle = _step19.value;
|
|
978
|
+
// 原价子商品:bundle_payment_price = bundle_selling_price × rate
|
|
979
|
+
// markdown 子商品:以净额幅度 × rate(与后端一致,存正净额)
|
|
980
|
+
if (isBundleOriginalPrice(bundle)) {
|
|
981
|
+
var _ref16, _ref17, _bundle$bundle_sellin3;
|
|
982
|
+
var bundleSelling = toDecimal((_ref16 = (_ref17 = (_bundle$bundle_sellin3 = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin3 !== void 0 ? _bundle$bundle_sellin3 : bundle.bundle_sum_price) !== null && _ref17 !== void 0 ? _ref17 : bundle.price) !== null && _ref16 !== void 0 ? _ref16 : 0);
|
|
983
|
+
bundle.bundle_payment_price = toAmountFormat(bcMul(bundleSelling, rate, 6)).toFixed(2);
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
if (isMarkdownBundle(bundle)) {
|
|
987
|
+
var _bundle$custom_price;
|
|
988
|
+
var magnitude = getBundleSellingMagnitude(bundle);
|
|
989
|
+
bundle.custom_price = (_bundle$custom_price = bundle.custom_price) !== null && _bundle$custom_price !== void 0 ? _bundle$custom_price : bundle.price;
|
|
990
|
+
bundle.price = magnitude.toFixed(2);
|
|
991
|
+
bundle.bundle_selling_price = magnitude.toFixed(2);
|
|
992
|
+
bundle.bundle_payment_price = toAmountFormat(bcMul(magnitude, rate, 6)).toFixed(2);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
} catch (err) {
|
|
996
|
+
_iterator19.e(err);
|
|
997
|
+
} finally {
|
|
998
|
+
_iterator19.f();
|
|
999
|
+
}
|
|
1000
|
+
product.payment_price = paymentUnit.toFixed(2);
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
385
1003
|
export function createEmptySalesSummary() {
|
|
386
1004
|
return {
|
|
387
1005
|
product_quantity: 0,
|
|
@@ -416,17 +1034,31 @@ export function calculateSalesSummary(params) {
|
|
|
416
1034
|
isInScheduleByDate = params.isInScheduleByDate,
|
|
417
1035
|
shopDiscount = params.shopDiscount;
|
|
418
1036
|
if (!(products !== null && products !== void 0 && products.length)) return createEmptySalesSummary();
|
|
419
|
-
var
|
|
1037
|
+
var summaryProducts = products.filter(function (product) {
|
|
1038
|
+
return !isGeneratedVoucherProduct(product);
|
|
1039
|
+
});
|
|
1040
|
+
if (!summaryProducts.length) return createEmptySalesSummary();
|
|
1041
|
+
var productQuantity = summaryProducts.reduce(function (sum, item) {
|
|
420
1042
|
return sum + getSafeNum(item.num);
|
|
421
1043
|
}, 0);
|
|
422
|
-
var productOriginalAmount =
|
|
1044
|
+
var productOriginalAmount = summaryProducts.reduce(function (sum, item) {
|
|
423
1045
|
return sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num)));
|
|
424
1046
|
}, new Decimal(0));
|
|
425
|
-
var productAmount =
|
|
1047
|
+
var productAmount = summaryProducts.reduce(function (sum, item) {
|
|
426
1048
|
return sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num)));
|
|
427
1049
|
}, new Decimal(0));
|
|
428
|
-
var
|
|
429
|
-
var
|
|
1050
|
+
var shopDiscountAmount = Decimal.max(new Decimal(Number(shopDiscount) || 0), 0);
|
|
1051
|
+
var hasPersistedSurchargeSnapshot = summaryProducts.some(function (product) {
|
|
1052
|
+
var _getPersistedMainSurc;
|
|
1053
|
+
return (_getPersistedMainSurc = getPersistedMainSurchargeFee(product)) === null || _getPersistedMainSurc === void 0 ? void 0 : _getPersistedMainSurc.gt(0);
|
|
1054
|
+
});
|
|
1055
|
+
// 整单折扣均摊:附加费基数用 selling(不受折扣),税费基数用 payment(受折扣)。
|
|
1056
|
+
// persisted 快照(已下单编辑)优先采信后端回传值,不重算均摊。
|
|
1057
|
+
if (!hasPersistedSurchargeSnapshot) {
|
|
1058
|
+
allocateShopDiscountToPayment(summaryProducts, productAmount, shopDiscountAmount);
|
|
1059
|
+
}
|
|
1060
|
+
var surchargeServiceItems = buildSurchargeServiceItems(summaryProducts);
|
|
1061
|
+
getSurcharge({
|
|
430
1062
|
service: surchargeServiceItems,
|
|
431
1063
|
addons: [],
|
|
432
1064
|
bookingDetail: null,
|
|
@@ -437,30 +1069,30 @@ export function calculateSalesSummary(params) {
|
|
|
437
1069
|
surcharge_list: surchargeList,
|
|
438
1070
|
scheduleById: scheduleById
|
|
439
1071
|
});
|
|
1072
|
+
var surcharge = calculateBackendProductSurcharges({
|
|
1073
|
+
products: summaryProducts,
|
|
1074
|
+
sourceItems: surchargeServiceItems,
|
|
1075
|
+
surchargeList: surchargeList
|
|
1076
|
+
});
|
|
440
1077
|
var surchargeAmount = new Decimal(getSurchargeAmount({
|
|
441
1078
|
bookingDetail: null,
|
|
442
1079
|
bookingId: undefined
|
|
443
1080
|
}, surcharge, {
|
|
444
1081
|
isEdit: false
|
|
445
1082
|
}) || 0);
|
|
446
|
-
for (var i = 0; i < products.length; i++) {
|
|
447
|
-
var _surchargeServiceItem;
|
|
448
|
-
products[i].surcharge_fee = ((_surchargeServiceItem = surchargeServiceItems[i]) === null || _surchargeServiceItem === void 0 ? void 0 : _surchargeServiceItem.surcharge_fee) || 0;
|
|
449
|
-
}
|
|
450
1083
|
var hasTaxRate = taxRate !== undefined && taxRate !== null && taxRate > 0;
|
|
451
1084
|
var productTaxFee;
|
|
452
1085
|
if (hasTaxRate) {
|
|
453
|
-
var taxResult = calculateProductsTax(
|
|
1086
|
+
var taxResult = calculateProductsTax(summaryProducts, taxRate, isPriceIncludeTax);
|
|
454
1087
|
productTaxFee = taxResult.tax;
|
|
455
1088
|
} else {
|
|
456
|
-
productTaxFee =
|
|
1089
|
+
productTaxFee = summaryProducts.reduce(function (sum, item) {
|
|
457
1090
|
return sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num)));
|
|
458
1091
|
}, new Decimal(0));
|
|
459
1092
|
}
|
|
460
|
-
var
|
|
461
|
-
var
|
|
462
|
-
var
|
|
463
|
-
var deposit = calculateProductsDeposit(products);
|
|
1093
|
+
var orderAmountBeforeDiscount = productAmount.plus(surchargeAmount).plus(isPriceIncludeTax === 1 ? 0 : productTaxFee);
|
|
1094
|
+
var totalAmount = Decimal.max(0, orderAmountBeforeDiscount.minus(shopDiscountAmount));
|
|
1095
|
+
var deposit = calculateProductsDeposit(summaryProducts);
|
|
464
1096
|
return {
|
|
465
1097
|
product_quantity: productQuantity,
|
|
466
1098
|
product_original_amount: toFixed2(productOriginalAmount),
|
|
@@ -472,10 +1104,10 @@ export function calculateSalesSummary(params) {
|
|
|
472
1104
|
tax_fee: toFixed2(productTaxFee),
|
|
473
1105
|
surcharge_fee: toFixed2(surchargeAmount),
|
|
474
1106
|
surcharges: surcharge,
|
|
475
|
-
discount_amount: toFixed2(
|
|
1107
|
+
discount_amount: toFixed2(shopDiscountAmount),
|
|
476
1108
|
deposit_amount: deposit ? deposit.total : '0.00',
|
|
477
1109
|
deposit: deposit,
|
|
478
|
-
expect_amount: toFixed2(
|
|
1110
|
+
expect_amount: toFixed2(totalAmount),
|
|
479
1111
|
total_amount: toFixed2(totalAmount),
|
|
480
1112
|
total_refund_amount: '0.00',
|
|
481
1113
|
customer_paid_amount: '0.00',
|