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