@pisell/pisellos 2.2.243 → 2.2.244
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/evaluator.js +2 -3
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +4 -7
- package/dist/modules/Cart/utils/cartProduct.js +3 -24
- package/dist/modules/Cart/utils/changePrice.js +11 -11
- package/dist/modules/Customer/index.d.ts +0 -20
- package/dist/modules/Customer/index.js +83 -172
- package/dist/modules/Customer/types.d.ts +0 -2
- package/dist/modules/Discount/index.js +3 -4
- package/dist/modules/Discount/types.d.ts +0 -1
- package/dist/modules/OpenData/index.d.ts +0 -8
- package/dist/modules/OpenData/index.js +17 -37
- package/dist/modules/Order/index.d.ts +18 -268
- package/dist/modules/Order/index.js +757 -3306
- package/dist/modules/Order/types.d.ts +31 -279
- package/dist/modules/Order/types.js +0 -38
- package/dist/modules/Order/utils.d.ts +5 -147
- package/dist/modules/Order/utils.js +103 -746
- package/dist/modules/Payment/index.d.ts +13 -10
- package/dist/modules/Payment/index.js +837 -467
- package/dist/modules/Payment/types.d.ts +0 -2
- package/dist/modules/Payment/utils.js +1 -2
- package/dist/modules/Payment/walletpass.js +7 -14
- package/dist/modules/ProductList/index.d.ts +12 -16
- package/dist/modules/ProductList/index.js +59 -133
- package/dist/modules/ProductList/types.d.ts +0 -14
- package/dist/modules/Quotation/index.d.ts +1 -0
- package/dist/modules/Quotation/index.js +22 -25
- package/dist/modules/Rules/index.d.ts +0 -4
- package/dist/modules/Rules/index.js +69 -93
- package/dist/modules/Rules/types.d.ts +0 -1
- package/dist/modules/SalesSummary/index.d.ts +25 -8
- package/dist/modules/SalesSummary/index.js +35 -86
- package/dist/modules/SalesSummary/types.d.ts +1 -4
- package/dist/modules/SalesSummary/utils.d.ts +25 -2
- package/dist/modules/SalesSummary/utils.js +162 -794
- package/dist/modules/Schedule/index.d.ts +0 -7
- package/dist/modules/Schedule/index.js +2 -24
- package/dist/modules/Summary/index.js +3 -4
- package/dist/modules/index.d.ts +0 -2
- package/dist/modules/index.js +1 -3
- package/dist/plugins/request.d.ts +0 -1
- package/dist/server/index.d.ts +1 -204
- package/dist/server/index.js +928 -3658
- package/dist/server/modules/index.d.ts +0 -2
- package/dist/server/modules/index.js +0 -2
- package/dist/server/modules/order/index.d.ts +4 -120
- package/dist/server/modules/order/index.js +483 -1779
- package/dist/server/modules/order/types.d.ts +3 -32
- package/dist/server/modules/order/types.js +0 -8
- package/dist/server/modules/order/utils/filterBookings.js +3 -26
- package/dist/server/modules/order/utils/filterOrders.js +8 -23
- package/dist/server/modules/products/index.d.ts +7 -34
- package/dist/server/modules/products/index.js +317 -631
- package/dist/server/modules/resource/index.d.ts +0 -2
- package/dist/server/modules/resource/index.js +3 -29
- package/dist/server/modules/schedule/index.d.ts +4 -4
- package/dist/server/modules/schedule/index.js +88 -111
- package/dist/solution/BaseSales/index.d.ts +9 -131
- package/dist/solution/BaseSales/index.js +447 -1944
- package/dist/solution/BaseSales/types.d.ts +6 -76
- package/dist/solution/BaseSales/types.js +4 -5
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -105
- package/dist/solution/BaseSales/utils.d.ts +1 -1
- package/dist/solution/BaseSales/utils.js +21 -62
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +10 -270
- package/dist/solution/BookingTicket/index.js +237 -1772
- package/dist/solution/BookingTicket/types.d.ts +1 -118
- package/dist/solution/BookingTicket/types.js +2 -41
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
- package/dist/solution/BookingTicket/utils/bookingStatus.js +0 -70
- package/dist/solution/BookingTicket/utils/cartView.d.ts +1 -9
- package/dist/solution/BookingTicket/utils/cartView.js +7 -94
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +0 -5
- package/dist/solution/BookingTicket/utils/scan/index.js +8 -20
- package/dist/solution/Checkout/appointmentDemo.json +1 -0
- package/dist/solution/Checkout/index.d.ts +0 -1
- package/dist/solution/Checkout/index.js +9 -10
- package/dist/solution/RegisterAndLogin/config.js +10 -2
- package/dist/solution/ScanOrder/index.d.ts +3 -9
- package/dist/solution/ScanOrder/index.js +134 -241
- package/dist/solution/ScanOrder/types.d.ts +5 -9
- package/dist/solution/ScanOrder/types.js +3 -2
- package/dist/solution/ScanOrder/utils.d.ts +1 -1
- package/dist/solution/ScanOrder/utils.js +22 -84
- package/dist/solution/VenueBooking/index.d.ts +2 -5
- package/dist/solution/VenueBooking/index.js +59 -110
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +2 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
- package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
- package/dist/types/index.d.ts +0 -10
- package/lib/model/strategy/adapter/promotion/evaluator.js +1 -2
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/model/strategy/adapter/walletPass/utils.js +2 -3
- package/lib/modules/Cart/utils/cartProduct.js +3 -20
- package/lib/modules/Cart/utils/changePrice.js +20 -12
- package/lib/modules/Customer/index.d.ts +0 -20
- package/lib/modules/Customer/index.js +11 -64
- package/lib/modules/Customer/types.d.ts +0 -2
- package/lib/modules/Discount/index.js +1 -5
- package/lib/modules/Discount/types.d.ts +0 -1
- package/lib/modules/OpenData/index.d.ts +0 -8
- package/lib/modules/OpenData/index.js +5 -19
- package/lib/modules/Order/index.d.ts +18 -268
- package/lib/modules/Order/index.js +344 -2149
- package/lib/modules/Order/types.d.ts +31 -279
- package/lib/modules/Order/types.js +0 -1
- package/lib/modules/Order/utils.d.ts +5 -147
- package/lib/modules/Order/utils.js +46 -614
- package/lib/modules/Payment/index.d.ts +13 -10
- package/lib/modules/Payment/index.js +150 -18
- package/lib/modules/Payment/types.d.ts +0 -2
- package/lib/modules/Payment/utils.js +1 -2
- package/lib/modules/Payment/walletpass.js +3 -7
- package/lib/modules/ProductList/index.d.ts +12 -16
- package/lib/modules/ProductList/index.js +4 -41
- package/lib/modules/ProductList/types.d.ts +0 -14
- package/lib/modules/Quotation/index.d.ts +1 -0
- package/lib/modules/Quotation/index.js +16 -19
- package/lib/modules/Rules/index.d.ts +0 -4
- package/lib/modules/Rules/index.js +120 -136
- package/lib/modules/Rules/types.d.ts +0 -1
- package/lib/modules/SalesSummary/index.d.ts +25 -8
- package/lib/modules/SalesSummary/index.js +4 -30
- package/lib/modules/SalesSummary/types.d.ts +1 -4
- package/lib/modules/SalesSummary/utils.d.ts +25 -2
- package/lib/modules/SalesSummary/utils.js +91 -645
- package/lib/modules/Schedule/index.d.ts +0 -7
- package/lib/modules/Schedule/index.js +1 -17
- package/lib/modules/Summary/index.js +4 -5
- package/lib/modules/index.d.ts +0 -2
- package/lib/modules/index.js +1 -5
- package/lib/plugins/request.d.ts +0 -1
- package/lib/server/index.d.ts +1 -204
- package/lib/server/index.js +57 -1888
- package/lib/server/modules/index.d.ts +0 -2
- package/lib/server/modules/index.js +0 -3
- package/lib/server/modules/order/index.d.ts +4 -120
- package/lib/server/modules/order/index.js +142 -919
- package/lib/server/modules/order/types.d.ts +3 -32
- package/lib/server/modules/order/utils/filterBookings.js +5 -24
- package/lib/server/modules/order/utils/filterOrders.js +6 -15
- package/lib/server/modules/products/index.d.ts +7 -34
- package/lib/server/modules/products/index.js +54 -189
- package/lib/server/modules/resource/index.d.ts +0 -2
- package/lib/server/modules/resource/index.js +3 -27
- package/lib/server/modules/schedule/index.d.ts +4 -4
- package/lib/server/modules/schedule/index.js +40 -47
- package/lib/solution/BaseSales/index.d.ts +9 -131
- package/lib/solution/BaseSales/index.js +63 -1106
- package/lib/solution/BaseSales/types.d.ts +6 -76
- package/lib/solution/BaseSales/types.js +1 -3
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +18 -106
- package/lib/solution/BaseSales/utils.d.ts +1 -1
- package/lib/solution/BaseSales/utils.js +10 -54
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +10 -270
- package/lib/solution/BookingTicket/index.js +29 -922
- package/lib/solution/BookingTicket/types.d.ts +1 -118
- package/lib/solution/BookingTicket/types.js +0 -11
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
- package/lib/solution/BookingTicket/utils/bookingStatus.js +2 -44
- package/lib/solution/BookingTicket/utils/cartView.d.ts +1 -9
- package/lib/solution/BookingTicket/utils/cartView.js +6 -61
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +0 -5
- package/lib/solution/BookingTicket/utils/scan/index.js +3 -17
- package/lib/solution/Checkout/appointmentDemo.json +1 -0
- package/lib/solution/Checkout/index.d.ts +0 -1
- package/lib/solution/Checkout/index.js +2 -1
- package/lib/solution/RegisterAndLogin/config.js +10 -2
- package/lib/solution/ScanOrder/index.d.ts +3 -9
- package/lib/solution/ScanOrder/index.js +70 -153
- package/lib/solution/ScanOrder/types.d.ts +5 -9
- package/lib/solution/ScanOrder/utils.d.ts +1 -1
- package/lib/solution/ScanOrder/utils.js +17 -83
- package/lib/solution/VenueBooking/index.d.ts +2 -5
- package/lib/solution/VenueBooking/index.js +17 -54
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +2 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
- package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
- package/lib/types/index.d.ts +0 -10
- package/package.json +1 -1
- package/dist/modules/BookingContext/index.d.ts +0 -48
- package/dist/modules/BookingContext/index.js +0 -566
- package/dist/modules/BookingContext/types.d.ts +0 -102
- package/dist/modules/BookingContext/types.js +0 -51
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -284
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -145
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -218
- package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
- package/dist/modules/BookingContext/utils/flexible.js +0 -56
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
- package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
- package/dist/modules/BookingContext/utils/index.d.ts +0 -11
- package/dist/modules/BookingContext/utils/index.js +0 -11
- package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
- package/dist/modules/BookingContext/utils/noResource.js +0 -77
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +0 -36
- package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
- package/dist/modules/BookingContext/utils/productExtend.js +0 -339
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
- package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
- package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
- package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
- package/dist/modules/BookingContext/utils/resources.js +0 -486
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
- package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
- package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
- package/dist/modules/Order/utils/manualProductDiscount.js +0 -210
- package/dist/modules/SurchargeList/index.d.ts +0 -16
- package/dist/modules/SurchargeList/index.js +0 -162
- package/dist/modules/SurchargeList/types.d.ts +0 -11
- package/dist/modules/SurchargeList/types.js +0 -1
- package/dist/server/modules/payment/index.d.ts +0 -28
- package/dist/server/modules/payment/index.js +0 -305
- package/dist/server/modules/payment/types.d.ts +0 -9
- package/dist/server/modules/payment/types.js +0 -1
- package/dist/server/test.json +0 -713
- package/dist/server/utils/small-ticket.d.ts +0 -71
- package/dist/server/utils/small-ticket.js +0 -830
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
- package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1438
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
- package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
- package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
- package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
- package/dist/solution/BookingTicket/utils/addTimeAvailability.js +0 -95
- package/dist/solution/BookingTicket/utils/exampleData.d.ts +0 -123
- package/dist/solution/BookingTicket/utils/exampleData.js +0 -183
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -438
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -399
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -56
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +0 -150
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +0 -78
- package/lib/modules/BookingContext/index.d.ts +0 -48
- package/lib/modules/BookingContext/index.js +0 -368
- package/lib/modules/BookingContext/types.d.ts +0 -102
- package/lib/modules/BookingContext/types.js +0 -34
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -276
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -151
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -201
- package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
- package/lib/modules/BookingContext/utils/flexible.js +0 -80
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
- package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
- package/lib/modules/BookingContext/utils/index.d.ts +0 -11
- package/lib/modules/BookingContext/utils/index.js +0 -43
- package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
- package/lib/modules/BookingContext/utils/noResource.js +0 -90
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +0 -56
- package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
- package/lib/modules/BookingContext/utils/productExtend.js +0 -283
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
- package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
- package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
- package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
- package/lib/modules/BookingContext/utils/resources.js +0 -377
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
- package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
- package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
- package/lib/modules/Order/utils/manualProductDiscount.js +0 -206
- package/lib/modules/SurchargeList/index.d.ts +0 -16
- package/lib/modules/SurchargeList/index.js +0 -89
- package/lib/modules/SurchargeList/types.d.ts +0 -11
- package/lib/modules/SurchargeList/types.js +0 -17
- package/lib/server/modules/payment/index.d.ts +0 -28
- package/lib/server/modules/payment/index.js +0 -192
- package/lib/server/modules/payment/types.d.ts +0 -9
- package/lib/server/modules/payment/types.js +0 -17
- package/lib/server/test.json +0 -713
- package/lib/server/utils/small-ticket.d.ts +0 -71
- package/lib/server/utils/small-ticket.js +0 -781
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
- package/lib/solution/BaseSales/utils/cartPromotion.js +0 -992
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
- package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
- package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
- package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +0 -125
- package/lib/solution/BookingTicket/utils/exampleData.d.ts +0 -123
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -254
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -168
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -51
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +0 -127
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +0 -85
|
@@ -1,8 +1,3 @@
|
|
|
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; }
|
|
6
1
|
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; } } }; }
|
|
7
2
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
3
|
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."); }
|
|
@@ -10,44 +5,15 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
5
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
6
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
7
|
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; }
|
|
13
|
-
function
|
|
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); }
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
18
9
|
import Decimal from 'decimal.js';
|
|
19
10
|
import { getSurcharge, getSurchargeAmount } from "../Summary/utils";
|
|
20
|
-
import { getBundleSellingMagnitude, getBundleSignedUnit, getProductSkuOptions, isMarkdownBundle } from "../Order/utils";
|
|
21
11
|
function toDecimal(value) {
|
|
22
12
|
return new Decimal(value || 0);
|
|
23
13
|
}
|
|
24
14
|
function toFixed2(value) {
|
|
25
15
|
return new Decimal(value || 0).toFixed(2);
|
|
26
16
|
}
|
|
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
|
-
}
|
|
51
17
|
function getSafeNum(num) {
|
|
52
18
|
if (!num || Number.isNaN(num)) return 1;
|
|
53
19
|
if (num < 1) return 1;
|
|
@@ -57,12 +23,10 @@ function getBundleUnitPrice(product) {
|
|
|
57
23
|
var useOriginal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
58
24
|
var bundleItems = product.product_bundle || [];
|
|
59
25
|
return bundleItems.reduce(function (sum, item) {
|
|
26
|
+
var _ref, _item$original_price, _item$bundle_selling_;
|
|
60
27
|
var quantity = getSafeNum(item === null || item === void 0 ? void 0 : item.num);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
useOriginal: useOriginal
|
|
64
|
-
});
|
|
65
|
-
return sum.plus(signedUnit.times(quantity));
|
|
28
|
+
var price = useOriginal ? toDecimal((_ref = (_item$original_price = item === null || item === void 0 ? void 0 : item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item === null || item === void 0 ? void 0 : item.product_price) !== null && _ref !== void 0 ? _ref : item === null || item === void 0 ? void 0 : item.price) : toDecimal((_item$bundle_selling_ = item === null || item === void 0 ? void 0 : item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item === null || item === void 0 ? void 0 : item.price);
|
|
29
|
+
return sum.plus(price.times(quantity));
|
|
66
30
|
}, new Decimal(0));
|
|
67
31
|
}
|
|
68
32
|
|
|
@@ -84,18 +48,11 @@ function getUnitOriginalTotal(product) {
|
|
|
84
48
|
var basePrice = mainOriginal !== undefined ? toDecimal(mainOriginal) : mainSelling !== undefined ? toDecimal(mainSelling) : toDecimal(product.original_price || product.selling_price);
|
|
85
49
|
return basePrice.plus(getBundleUnitPrice(product, true));
|
|
86
50
|
}
|
|
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
|
-
}
|
|
92
51
|
function buildSurchargeServiceItems(products) {
|
|
93
52
|
return products.map(function (product) {
|
|
94
53
|
var _product$is_charge_ta, _product$metadata5, _product$metadata6;
|
|
95
54
|
var quantity = getSafeNum(product.num);
|
|
96
55
|
var unitTotal = getUnitPaymentTotal(product);
|
|
97
|
-
var options = getProductSkuOptions(product);
|
|
98
|
-
var persistedSurchargeFee = getPersistedMainSurchargeFee(product);
|
|
99
56
|
return {
|
|
100
57
|
id: product.product_id,
|
|
101
58
|
num: quantity,
|
|
@@ -107,443 +64,19 @@ function buildSurchargeServiceItems(products) {
|
|
|
107
64
|
product: {
|
|
108
65
|
discount_list: product.discount_list || [],
|
|
109
66
|
product_bundle: product.product_bundle || [],
|
|
110
|
-
|
|
111
|
-
option: options
|
|
112
|
-
}
|
|
67
|
+
product_option_item: product.product_option_item || []
|
|
113
68
|
}
|
|
114
69
|
},
|
|
115
70
|
bundle: product.product_bundle || [],
|
|
116
|
-
option:
|
|
117
|
-
options:
|
|
71
|
+
option: product.product_option_item || [],
|
|
72
|
+
options: product.product_option_item || [],
|
|
118
73
|
relation_details: [],
|
|
119
|
-
metadata:
|
|
120
|
-
__persisted_surcharge_fee: persistedSurchargeFee === null || persistedSurchargeFee === void 0 ? void 0 : persistedSurchargeFee.toFixed(2)
|
|
121
|
-
}),
|
|
74
|
+
metadata: product.metadata || {},
|
|
122
75
|
start_date: ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.start_date) || '',
|
|
123
76
|
start_time: ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.start_time) || ''
|
|
124
77
|
};
|
|
125
78
|
});
|
|
126
79
|
}
|
|
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
|
-
}
|
|
547
80
|
function getProductDepositData(product) {
|
|
548
81
|
var _product$_origin, _product$_origin2;
|
|
549
82
|
var rootDepositData = (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.custom_deposit_data;
|
|
@@ -578,11 +111,11 @@ function calculateProductsDeposit(products) {
|
|
|
578
111
|
var hasDeposit = false;
|
|
579
112
|
var policyIds = new Set();
|
|
580
113
|
var policyDataMap = new Map();
|
|
581
|
-
var
|
|
582
|
-
|
|
114
|
+
var _iterator = _createForOfIteratorHelper(products),
|
|
115
|
+
_step;
|
|
583
116
|
try {
|
|
584
|
-
for (
|
|
585
|
-
var product =
|
|
117
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
118
|
+
var product = _step.value;
|
|
586
119
|
var depositData = getProductDepositData(product);
|
|
587
120
|
if (!depositData || depositData.has_deposit != 1) continue;
|
|
588
121
|
var num = getSafeNum(product.num);
|
|
@@ -595,45 +128,45 @@ function calculateProductsDeposit(products) {
|
|
|
595
128
|
var itemDeposit = fixed.plus(percentage.times(productTotal));
|
|
596
129
|
totalDeposit = totalDeposit.plus(itemDeposit);
|
|
597
130
|
hasDeposit = true;
|
|
598
|
-
var
|
|
599
|
-
|
|
131
|
+
var _iterator3 = _createForOfIteratorHelper(collectDepositPolicyIds(depositData)),
|
|
132
|
+
_step3;
|
|
600
133
|
try {
|
|
601
|
-
for (
|
|
602
|
-
var id =
|
|
134
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
135
|
+
var id = _step3.value;
|
|
603
136
|
policyIds.add(id);
|
|
604
137
|
}
|
|
605
138
|
} catch (err) {
|
|
606
|
-
|
|
139
|
+
_iterator3.e(err);
|
|
607
140
|
} finally {
|
|
608
|
-
|
|
141
|
+
_iterator3.f();
|
|
609
142
|
}
|
|
610
|
-
var
|
|
611
|
-
|
|
143
|
+
var _iterator4 = _createForOfIteratorHelper(collectDepositPolicyData(depositData)),
|
|
144
|
+
_step4;
|
|
612
145
|
try {
|
|
613
|
-
for (
|
|
614
|
-
var policy =
|
|
146
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
147
|
+
var policy = _step4.value;
|
|
615
148
|
if (!policyDataMap.has(policy.id)) {
|
|
616
149
|
policyDataMap.set(policy.id, policy);
|
|
617
150
|
}
|
|
618
151
|
policyIds.add(policy.id);
|
|
619
152
|
}
|
|
620
153
|
} catch (err) {
|
|
621
|
-
|
|
154
|
+
_iterator4.e(err);
|
|
622
155
|
} finally {
|
|
623
|
-
|
|
156
|
+
_iterator4.f();
|
|
624
157
|
}
|
|
625
158
|
}
|
|
626
159
|
} catch (err) {
|
|
627
|
-
|
|
160
|
+
_iterator.e(err);
|
|
628
161
|
} finally {
|
|
629
|
-
|
|
162
|
+
_iterator.f();
|
|
630
163
|
}
|
|
631
164
|
if (!hasDeposit) return undefined;
|
|
632
|
-
var
|
|
633
|
-
|
|
165
|
+
var _iterator2 = _createForOfIteratorHelper(policyIds),
|
|
166
|
+
_step2;
|
|
634
167
|
try {
|
|
635
|
-
for (
|
|
636
|
-
var _id =
|
|
168
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
169
|
+
var _id = _step2.value;
|
|
637
170
|
if (!policyDataMap.has(_id)) {
|
|
638
171
|
policyDataMap.set(_id, {
|
|
639
172
|
id: _id,
|
|
@@ -642,9 +175,9 @@ function calculateProductsDeposit(products) {
|
|
|
642
175
|
}
|
|
643
176
|
}
|
|
644
177
|
} catch (err) {
|
|
645
|
-
|
|
178
|
+
_iterator2.e(err);
|
|
646
179
|
} finally {
|
|
647
|
-
|
|
180
|
+
_iterator2.f();
|
|
648
181
|
}
|
|
649
182
|
return {
|
|
650
183
|
total: totalDeposit.toFixed(2),
|
|
@@ -685,202 +218,58 @@ function calculateSingleItemTax(params) {
|
|
|
685
218
|
}
|
|
686
219
|
|
|
687
220
|
/**
|
|
688
|
-
*
|
|
221
|
+
* 获取主商品折扣后总价(含 option、含主商品折扣、含加价/减价 bundle)。
|
|
689
222
|
*
|
|
690
|
-
*
|
|
691
|
-
* - `metadata.main_product_selling_price` 已是"含 option、含折扣"
|
|
692
|
-
* -
|
|
223
|
+
* 新语义 v2 下:
|
|
224
|
+
* - `metadata.main_product_selling_price` 已是"含 option、含折扣"的主价,直接读即可;
|
|
225
|
+
* - 无需再 `minus(mainDiscountAmount)` 或 `plus(getOptionUnitPrice)`;
|
|
226
|
+
* - 仅需叠加 `markup` / `markdown` 类 bundle(原价 bundle 已由 `calculateProductsTax` 独立处理)。
|
|
693
227
|
*/
|
|
694
|
-
function
|
|
695
|
-
var
|
|
696
|
-
var mainSelling = (
|
|
228
|
+
function getMainProductPaymentTotal(product) {
|
|
229
|
+
var _ref2, _product$metadata$mai, _product$metadata7, _product$metadata8;
|
|
230
|
+
var mainSelling = (_ref2 = (_product$metadata$mai = (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_selling_price) !== null && _product$metadata$mai !== void 0 ? _product$metadata$mai : (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.main_product_original_price) !== null && _ref2 !== void 0 ? _ref2 : 0;
|
|
697
231
|
var total = toDecimal(mainSelling);
|
|
698
232
|
var bundleItems = product.product_bundle || [];
|
|
699
|
-
var
|
|
700
|
-
|
|
233
|
+
var _iterator5 = _createForOfIteratorHelper(bundleItems),
|
|
234
|
+
_step5;
|
|
701
235
|
try {
|
|
702
|
-
for (
|
|
703
|
-
var bundleItem =
|
|
236
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
237
|
+
var bundleItem = _step5.value;
|
|
704
238
|
if (isBundleMarkupOrDiscount(bundleItem)) {
|
|
705
|
-
var _bundleItem$num;
|
|
706
|
-
|
|
707
|
-
var unit = getBundleSignedUnit(bundleItem);
|
|
239
|
+
var _ref3, _bundleItem$bundle_se, _bundleItem$num;
|
|
240
|
+
var unit = toDecimal((_ref3 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref3 !== void 0 ? _ref3 : 0);
|
|
708
241
|
var qty = getSafeNum((_bundleItem$num = bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem.quantity);
|
|
709
242
|
total = total.plus(unit.times(qty));
|
|
710
243
|
}
|
|
711
244
|
}
|
|
712
245
|
} catch (err) {
|
|
713
|
-
|
|
246
|
+
_iterator5.e(err);
|
|
714
247
|
} finally {
|
|
715
|
-
|
|
248
|
+
_iterator5.f();
|
|
716
249
|
}
|
|
717
250
|
return Decimal.max(total, 0);
|
|
718
251
|
}
|
|
719
252
|
|
|
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
|
-
|
|
815
253
|
/**
|
|
816
254
|
* 遍历所有商品计算税费,回写 tax_fee 到每个商品及 bundle 原价子商品,处理舍入差值。
|
|
817
255
|
* 参照 Summary/utils.ts 的 processItemsTax,适配 SalesSummaryProduct 结构。
|
|
818
256
|
*/
|
|
819
257
|
function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
820
258
|
var rate = new Decimal(taxRate);
|
|
821
|
-
var
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
var
|
|
825
|
-
var
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
_step17;
|
|
259
|
+
var preciseTax = new Decimal(0);
|
|
260
|
+
var roundedTax = new Decimal(0);
|
|
261
|
+
var preciseOriginTax = new Decimal(0);
|
|
262
|
+
var roundedOriginTax = new Decimal(0);
|
|
263
|
+
var lastTaxableItem = null;
|
|
264
|
+
var _iterator6 = _createForOfIteratorHelper(products),
|
|
265
|
+
_step6;
|
|
829
266
|
try {
|
|
830
|
-
for (
|
|
267
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
831
268
|
var _product$is_charge_ta2, _product$is_charge_ta3;
|
|
832
|
-
var product =
|
|
269
|
+
var product = _step6.value;
|
|
833
270
|
var quantity = new Decimal(getSafeNum(product.num));
|
|
834
|
-
|
|
835
|
-
|
|
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
|
-
}
|
|
271
|
+
|
|
272
|
+
// --- 主商品折后税费 ---
|
|
884
273
|
var mainTotal = getMainProductPaymentTotal(product);
|
|
885
274
|
var surchargeFee = toDecimal(product.surcharge_fee);
|
|
886
275
|
var mainTaxableBase = mainTotal.lte(0) ? surchargeFee : mainTotal.plus(surchargeFee);
|
|
@@ -890,23 +279,15 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
890
279
|
isPriceIncludeTax: isPriceIncludeTax,
|
|
891
280
|
isChargeTax: (_product$is_charge_ta2 = product.is_charge_tax) !== null && _product$is_charge_ta2 !== void 0 ? _product$is_charge_ta2 : 0
|
|
892
281
|
});
|
|
893
|
-
var mainTaxRounded =
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
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);
|
|
282
|
+
var mainTaxRounded = mainTaxPrecise.toDecimalPlaces(2, Decimal.ROUND_HALF_UP);
|
|
283
|
+
if (mainTaxPrecise.gt(0)) {
|
|
284
|
+
lastTaxableItem = {
|
|
285
|
+
type: 'main',
|
|
286
|
+
item: product
|
|
287
|
+
};
|
|
909
288
|
}
|
|
289
|
+
|
|
290
|
+
// --- 主商品原价税费 ---
|
|
910
291
|
var originalTotal = getUnitOriginalTotal(product);
|
|
911
292
|
var originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
|
|
912
293
|
var originalTaxPrecise = calculateSingleItemTax({
|
|
@@ -915,91 +296,92 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
915
296
|
isPriceIncludeTax: isPriceIncludeTax,
|
|
916
297
|
isChargeTax: (_product$is_charge_ta3 = product.is_charge_tax) !== null && _product$is_charge_ta3 !== void 0 ? _product$is_charge_ta3 : 0
|
|
917
298
|
});
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
299
|
+
|
|
300
|
+
// --- bundle 原价子商品独立计税 ---
|
|
301
|
+
var bundlePreciseTax = new Decimal(0);
|
|
302
|
+
var bundleRoundedTax = new Decimal(0);
|
|
303
|
+
var bundlePreciseOriginTax = new Decimal(0);
|
|
304
|
+
var bundleRoundedOriginTax = new Decimal(0);
|
|
305
|
+
var bundleItems = product.product_bundle || [];
|
|
306
|
+
var _iterator7 = _createForOfIteratorHelper(bundleItems),
|
|
307
|
+
_step7;
|
|
308
|
+
try {
|
|
309
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
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();
|
|
929
349
|
}
|
|
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));
|
|
930
360
|
}
|
|
361
|
+
|
|
362
|
+
// --- 舍入差值处理 ---
|
|
931
363
|
} catch (err) {
|
|
932
|
-
|
|
364
|
+
_iterator6.e(err);
|
|
933
365
|
} finally {
|
|
934
|
-
|
|
366
|
+
_iterator6.f();
|
|
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
|
+
}
|
|
935
379
|
}
|
|
936
380
|
return {
|
|
937
|
-
tax:
|
|
938
|
-
originTax:
|
|
381
|
+
tax: expectedTax,
|
|
382
|
+
originTax: expectedOriginTax
|
|
939
383
|
};
|
|
940
384
|
}
|
|
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
|
-
}
|
|
1003
385
|
export function createEmptySalesSummary() {
|
|
1004
386
|
return {
|
|
1005
387
|
product_quantity: 0,
|
|
@@ -1034,31 +416,17 @@ export function calculateSalesSummary(params) {
|
|
|
1034
416
|
isInScheduleByDate = params.isInScheduleByDate,
|
|
1035
417
|
shopDiscount = params.shopDiscount;
|
|
1036
418
|
if (!(products !== null && products !== void 0 && products.length)) return createEmptySalesSummary();
|
|
1037
|
-
var
|
|
1038
|
-
return !isGeneratedVoucherProduct(product);
|
|
1039
|
-
});
|
|
1040
|
-
if (!summaryProducts.length) return createEmptySalesSummary();
|
|
1041
|
-
var productQuantity = summaryProducts.reduce(function (sum, item) {
|
|
419
|
+
var productQuantity = products.reduce(function (sum, item) {
|
|
1042
420
|
return sum + getSafeNum(item.num);
|
|
1043
421
|
}, 0);
|
|
1044
|
-
var productOriginalAmount =
|
|
422
|
+
var productOriginalAmount = products.reduce(function (sum, item) {
|
|
1045
423
|
return sum.plus(getUnitOriginalTotal(item).times(getSafeNum(item.num)));
|
|
1046
424
|
}, new Decimal(0));
|
|
1047
|
-
var productAmount =
|
|
425
|
+
var productAmount = products.reduce(function (sum, item) {
|
|
1048
426
|
return sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num)));
|
|
1049
427
|
}, new Decimal(0));
|
|
1050
|
-
var
|
|
1051
|
-
var
|
|
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({
|
|
428
|
+
var surchargeServiceItems = buildSurchargeServiceItems(products);
|
|
429
|
+
var surcharge = getSurcharge({
|
|
1062
430
|
service: surchargeServiceItems,
|
|
1063
431
|
addons: [],
|
|
1064
432
|
bookingDetail: null,
|
|
@@ -1069,30 +437,30 @@ export function calculateSalesSummary(params) {
|
|
|
1069
437
|
surcharge_list: surchargeList,
|
|
1070
438
|
scheduleById: scheduleById
|
|
1071
439
|
});
|
|
1072
|
-
var surcharge = calculateBackendProductSurcharges({
|
|
1073
|
-
products: summaryProducts,
|
|
1074
|
-
sourceItems: surchargeServiceItems,
|
|
1075
|
-
surchargeList: surchargeList
|
|
1076
|
-
});
|
|
1077
440
|
var surchargeAmount = new Decimal(getSurchargeAmount({
|
|
1078
441
|
bookingDetail: null,
|
|
1079
442
|
bookingId: undefined
|
|
1080
443
|
}, surcharge, {
|
|
1081
444
|
isEdit: false
|
|
1082
445
|
}) || 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
|
+
}
|
|
1083
450
|
var hasTaxRate = taxRate !== undefined && taxRate !== null && taxRate > 0;
|
|
1084
451
|
var productTaxFee;
|
|
1085
452
|
if (hasTaxRate) {
|
|
1086
|
-
var taxResult = calculateProductsTax(
|
|
453
|
+
var taxResult = calculateProductsTax(products, taxRate, isPriceIncludeTax);
|
|
1087
454
|
productTaxFee = taxResult.tax;
|
|
1088
455
|
} else {
|
|
1089
|
-
productTaxFee =
|
|
456
|
+
productTaxFee = products.reduce(function (sum, item) {
|
|
1090
457
|
return sum.plus(toDecimal(item.tax_fee).times(getSafeNum(item.num)));
|
|
1091
458
|
}, new Decimal(0));
|
|
1092
459
|
}
|
|
1093
|
-
var
|
|
1094
|
-
var
|
|
1095
|
-
var
|
|
460
|
+
var shopDiscountAmount = Decimal.max(new Decimal(Number(shopDiscount) || 0), 0);
|
|
461
|
+
var expectAmount = Decimal.max(0, productAmount.plus(surchargeAmount).minus(shopDiscountAmount));
|
|
462
|
+
var totalAmount = isPriceIncludeTax === 1 ? expectAmount : expectAmount.plus(productTaxFee);
|
|
463
|
+
var deposit = calculateProductsDeposit(products);
|
|
1096
464
|
return {
|
|
1097
465
|
product_quantity: productQuantity,
|
|
1098
466
|
product_original_amount: toFixed2(productOriginalAmount),
|
|
@@ -1104,10 +472,10 @@ export function calculateSalesSummary(params) {
|
|
|
1104
472
|
tax_fee: toFixed2(productTaxFee),
|
|
1105
473
|
surcharge_fee: toFixed2(surchargeAmount),
|
|
1106
474
|
surcharges: surcharge,
|
|
1107
|
-
discount_amount: toFixed2(shopDiscountAmount),
|
|
475
|
+
discount_amount: toFixed2(Decimal.max(productOriginalAmount.minus(productAmount), 0).plus(shopDiscountAmount)),
|
|
1108
476
|
deposit_amount: deposit ? deposit.total : '0.00',
|
|
1109
477
|
deposit: deposit,
|
|
1110
|
-
expect_amount: toFixed2(
|
|
478
|
+
expect_amount: toFixed2(expectAmount),
|
|
1111
479
|
total_amount: toFixed2(totalAmount),
|
|
1112
480
|
total_refund_amount: '0.00',
|
|
1113
481
|
customer_paid_amount: '0.00',
|