washday-sdk 0.0.163 → 0.0.165
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/utils/orders/calculateOrderTotal.js +4 -2
- package/dist/utils/orders/calculateTotalTaxesIncluded.js +3 -2
- package/dist/utils/orders/calculateTotalTaxesOverPrice.js +18 -14
- package/dist/utils/orders/helpers.js +5 -1
- package/package.json +1 -1
- package/src/interfaces/Product.ts +1 -0
- package/src/utils/orders/calculateOrderTotal.ts +9 -6
- package/src/utils/orders/calculateTotalTaxesIncluded.ts +12 -11
- package/src/utils/orders/calculateTotalTaxesOverPrice.ts +19 -14
- package/src/utils/orders/helpers.ts +51 -47
|
@@ -9,10 +9,11 @@ export const calculateOrderTotal = (order, selectedCustomer, storeSettings, hasS
|
|
|
9
9
|
const productTableCalculator = (storeSettings === null || storeSettings === void 0 ? void 0 : storeSettings.taxesType) === 'over_price' ? calculateTotalTaxesOverPrice : calculateTotalTaxesIncluded;
|
|
10
10
|
const productTableImports = productTableCalculator(order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj);
|
|
11
11
|
// PRODUCT LINE TOTALS
|
|
12
|
-
const { totalQuantity, totalImportWithDiscount, totalImportWithoutDiscount, totalImporTaxes, totalDiscountAmount } = getProductLineTotals(productTableImports);
|
|
12
|
+
const { totalQuantity, totalImportWithDiscount, totalImportWithoutDiscount, totalImporTaxes, totalDiscountAmount, totalSubtotalAmount } = getProductLineTotals(productTableImports);
|
|
13
13
|
// DISCOUNT TOTAL AND SHIPPING SERVICE COST
|
|
14
14
|
let discountCodeAmount = 0;
|
|
15
15
|
let shippingCost = getShippingCost(discountCodeObj, hasShippingCost, storeSettings);
|
|
16
|
+
// TODO: MAYBE THIS KIND OF DISCOUNT IS WRONG BECAUSE TAXES ARE CALCULATED BEFORE THIS POINT;
|
|
16
17
|
if (discountCodeObj && discountCodeObj.type === DiscountCodeTypes.NUMBER && discountCodeObj.applyOnceOnOrder) {
|
|
17
18
|
const includesProducts = discountCodeObj.applyToAllProducts || order.products.some((curr) => discountCodeObj.products.includes(curr._id));
|
|
18
19
|
discountCodeAmount = includesProducts ? discountCodeObj.value : 0;
|
|
@@ -21,7 +22,8 @@ export const calculateOrderTotal = (order, selectedCustomer, storeSettings, hasS
|
|
|
21
22
|
let orderTotalWithOutCredit = +(totalImportWithDiscount + shippingCost - discountCodeAmount).toFixed(2);
|
|
22
23
|
let creditApplied = getCreditApplied(selectedCustomer, orderTotalWithOutCredit);
|
|
23
24
|
let orderTotal = +(orderTotalWithOutCredit - creditApplied).toFixed(2);
|
|
24
|
-
return Object.assign(Object.assign({}, order), { totalQuantity, customerDiscount: order.discountCode ? 0 : (_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount, productTotal: totalImportWithDiscount, taxesTotal: totalImporTaxes, total: orderTotal,
|
|
25
|
+
return Object.assign(Object.assign({}, order), { totalQuantity, customerDiscount: order.discountCode ? 0 : (_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount, productTotal: totalImportWithDiscount, taxesTotal: totalImporTaxes, total: orderTotal, // Total final (ya sea sumando o no el IVA)
|
|
26
|
+
creditApplied, productTotalWithoutDiscount: totalImportWithoutDiscount, totalDiscountAmount: totalDiscountAmount + discountCodeAmount, shippingServiceTotal: shippingCost, appliedOrderDiscounts, subtotal: totalSubtotalAmount });
|
|
25
27
|
}
|
|
26
28
|
catch (error) {
|
|
27
29
|
throw error;
|
|
@@ -58,7 +58,7 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
|
|
|
58
58
|
const productLineImportTotal = +(totalNetWithoutDiscount * taxFactor).toFixed(2);
|
|
59
59
|
const productLineTotalWithDiscount = +(totalNetWithDiscount * taxFactor).toFixed(2);
|
|
60
60
|
// Calculate the taxes as the difference between gross and net:
|
|
61
|
-
const totalTaxesApplied = +(
|
|
61
|
+
const totalTaxesApplied = +(productLineTotalWithDiscount - totalNetWithDiscount).toFixed(2);
|
|
62
62
|
const lineDiscount = +(discountAmountPerUnit * qty).toFixed(2);
|
|
63
63
|
return {
|
|
64
64
|
product: current,
|
|
@@ -66,7 +66,8 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
|
|
|
66
66
|
productLineImportTotal, // original gross total (no discount)
|
|
67
67
|
productLineTotalWithDiscount, // gross total after discount on product (extra not discounted)
|
|
68
68
|
productLineTaxesTotal: totalTaxesApplied,
|
|
69
|
-
lineDiscountAmount: lineDiscount
|
|
69
|
+
lineDiscountAmount: lineDiscount,
|
|
70
|
+
productLineSubtotal: totalNetWithoutDiscount // All line subtotal (extra amount considered, without discounts and taxes)
|
|
70
71
|
};
|
|
71
72
|
});
|
|
72
73
|
return productTableImports;
|
|
@@ -6,10 +6,10 @@ export const calculateTotalTaxesOverPrice = (order, selectedCustomer, storeSetti
|
|
|
6
6
|
let discPercentageInteger = 0;
|
|
7
7
|
let productPercentageDiscount = 0;
|
|
8
8
|
let customerDiscount = 0;
|
|
9
|
-
|
|
10
|
-
// Precio base sin impuestos
|
|
9
|
+
const qty = current.qty; // cantidad
|
|
10
|
+
// Precio base sin impuestos (en modo over_price el precio es neto)
|
|
11
11
|
const productBasePrice = order.express ? current.expressPrice : current.price;
|
|
12
|
-
//
|
|
12
|
+
// Cálculo de descuento sobre el producto (aplicable solo sobre el precio base)
|
|
13
13
|
if (!order.discountCode) {
|
|
14
14
|
const discountsToApply = storeDiscounts.filter((discount) => discount.products.includes(current._id) && discount.isActive);
|
|
15
15
|
customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
|
|
@@ -17,6 +17,7 @@ export const calculateTotalTaxesOverPrice = (order, selectedCustomer, storeSetti
|
|
|
17
17
|
return discount.type === 'percentage' ? acc + discount.value : acc;
|
|
18
18
|
}, 0);
|
|
19
19
|
discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
|
|
20
|
+
discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount));
|
|
20
21
|
}
|
|
21
22
|
else {
|
|
22
23
|
if (discountCodeObj.type === DiscountCodeTypes.PERCENTAGE) {
|
|
@@ -34,27 +35,30 @@ export const calculateTotalTaxesOverPrice = (order, selectedCustomer, storeSetti
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
// Calcular descuento
|
|
38
|
+
// Calcular descuento por unidad y precio descontado
|
|
38
39
|
const productDiscount = productBasePrice * discPercentageInteger;
|
|
39
40
|
const discountedProductPrice = productBasePrice - productDiscount;
|
|
40
|
-
//
|
|
41
|
-
const subtotal = (discountedProductPrice * qty) + current.extraAmount;
|
|
42
|
-
// Calcular impuestos sobre el subtotal
|
|
41
|
+
// Subtotal para la línea (precio con descuento * cantidad + extraAmount) SIN impuestos
|
|
42
|
+
const subtotal = (discountedProductPrice * qty) + (current.extraAmount || 0);
|
|
43
|
+
// Calcular impuestos sobre el subtotal
|
|
43
44
|
const taxPercentage = getProductTaxesPercentage(current, storeSettings) / 100;
|
|
44
45
|
const taxes = subtotal * taxPercentage;
|
|
45
|
-
// Resultados finales
|
|
46
|
-
const totalTaxesApplied = +
|
|
46
|
+
// Resultados finales:
|
|
47
|
+
const totalTaxesApplied = +taxes.toFixed(2);
|
|
47
48
|
const lineDiscount = +(productDiscount * qty).toFixed(2);
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
const prodLinePriceWithDiscount = +((((discountedProductPrice * qty) + current.extraAmount) * (1 + taxPercentage))).toFixed(2);
|
|
49
|
+
// Precio total con descuento, reaplicando el IVA (es el total final a cobrar)
|
|
50
|
+
const prodLinePriceWithDiscount = +((subtotal * (1 + taxPercentage))).toFixed(2);
|
|
51
51
|
return {
|
|
52
52
|
product: current,
|
|
53
53
|
qty,
|
|
54
|
-
|
|
54
|
+
// Total bruto original sin descuento (precio base * cantidad + extraAmount)
|
|
55
|
+
productLineImportTotal: (productBasePrice * qty) + (current.extraAmount || 0),
|
|
56
|
+
// Total final con descuento, que se obtiene al sumar IVA al subtotal neto
|
|
55
57
|
productLineTotalWithDiscount: prodLinePriceWithDiscount,
|
|
56
58
|
productLineTaxesTotal: totalTaxesApplied,
|
|
57
|
-
lineDiscountAmount: lineDiscount
|
|
59
|
+
lineDiscountAmount: lineDiscount,
|
|
60
|
+
// Subtotal: precio base (neto, con descuento) sin aplicar IVA
|
|
61
|
+
productLineSubtotal: subtotal
|
|
58
62
|
};
|
|
59
63
|
});
|
|
60
64
|
return productTableImports;
|
|
@@ -31,12 +31,16 @@ export const getProductLineTotals = (productLinesTotals) => {
|
|
|
31
31
|
const totalDiscountAmount = +productLinesTotals
|
|
32
32
|
.reduce((acum, line) => acum + line.lineDiscountAmount, 0)
|
|
33
33
|
.toFixed(2);
|
|
34
|
+
const totalSubtotalAmount = +productLinesTotals
|
|
35
|
+
.reduce((acum, line) => acum + line.productLineSubtotal, 0)
|
|
36
|
+
.toFixed(2);
|
|
34
37
|
return {
|
|
35
38
|
totalQuantity,
|
|
36
39
|
totalImportWithDiscount,
|
|
37
40
|
totalImportWithoutDiscount,
|
|
38
41
|
totalImporTaxes,
|
|
39
|
-
totalDiscountAmount
|
|
42
|
+
totalDiscountAmount,
|
|
43
|
+
totalSubtotalAmount
|
|
40
44
|
};
|
|
41
45
|
};
|
|
42
46
|
export const getShippingCost = (discountObject, requireShippingService, store) => {
|
package/package.json
CHANGED
|
@@ -24,13 +24,15 @@ export const calculateOrderTotal = (
|
|
|
24
24
|
totalImportWithDiscount,
|
|
25
25
|
totalImportWithoutDiscount,
|
|
26
26
|
totalImporTaxes,
|
|
27
|
-
totalDiscountAmount
|
|
27
|
+
totalDiscountAmount,
|
|
28
|
+
totalSubtotalAmount
|
|
28
29
|
} = getProductLineTotals(productTableImports);
|
|
29
30
|
|
|
30
31
|
// DISCOUNT TOTAL AND SHIPPING SERVICE COST
|
|
31
32
|
let discountCodeAmount = 0;
|
|
32
33
|
let shippingCost = getShippingCost(discountCodeObj, hasShippingCost, storeSettings);
|
|
33
34
|
|
|
35
|
+
// TODO: MAYBE THIS KIND OF DISCOUNT IS WRONG BECAUSE TAXES ARE CALCULATED BEFORE THIS POINT;
|
|
34
36
|
if (discountCodeObj && discountCodeObj.type === DiscountCodeTypes.NUMBER && discountCodeObj.applyOnceOnOrder) {
|
|
35
37
|
const includesProducts = discountCodeObj.applyToAllProducts || order.products.some((curr: any) => discountCodeObj.products.includes(curr._id));
|
|
36
38
|
discountCodeAmount = includesProducts ? discountCodeObj.value : 0;
|
|
@@ -45,14 +47,15 @@ export const calculateOrderTotal = (
|
|
|
45
47
|
...order,
|
|
46
48
|
totalQuantity,
|
|
47
49
|
customerDiscount: order.discountCode ? 0 : selectedCustomer?.customer?.discount,
|
|
48
|
-
productTotal: totalImportWithDiscount,
|
|
49
|
-
taxesTotal: totalImporTaxes,
|
|
50
|
-
total: orderTotal,
|
|
50
|
+
productTotal: totalImportWithDiscount, // Total neto con descuento, que luego se convierte a bruto según el método
|
|
51
|
+
taxesTotal: totalImporTaxes, // Monto de impuestos aplicado
|
|
52
|
+
total: orderTotal, // Total final (ya sea sumando o no el IVA)
|
|
51
53
|
creditApplied,
|
|
52
|
-
productTotalWithoutDiscount: totalImportWithoutDiscount,
|
|
54
|
+
productTotalWithoutDiscount: totalImportWithoutDiscount, // Precio base (neto)
|
|
53
55
|
totalDiscountAmount: totalDiscountAmount + discountCodeAmount,
|
|
54
56
|
shippingServiceTotal: shippingCost,
|
|
55
|
-
appliedOrderDiscounts
|
|
57
|
+
appliedOrderDiscounts,
|
|
58
|
+
subtotal: totalSubtotalAmount
|
|
56
59
|
};
|
|
57
60
|
} catch (error) {
|
|
58
61
|
throw error;
|
|
@@ -13,16 +13,16 @@ export const calculateTotalTaxesIncluded = (
|
|
|
13
13
|
const qty = current.qty || 0;
|
|
14
14
|
const taxPercentage = getProductTaxesPercentage(current, storeSettings);
|
|
15
15
|
const taxFactor = 1 + taxPercentage / 100;
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
// Convert extraAmount from gross to net (assume extraAmount is not discounted)
|
|
18
18
|
const extraAmountGross = current.extraAmount || 0;
|
|
19
19
|
const extraAmountNet = extraAmountGross / taxFactor;
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
// Get the product’s gross price (excluding extraAmount)
|
|
22
22
|
const productGrossPrice = order.express ? current.expressPrice : current.price;
|
|
23
23
|
// Convert product gross price to net
|
|
24
24
|
const unitNetPrice = productGrossPrice / taxFactor;
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
// Determine discount percentage (if any) – discount is applied only on product net price.
|
|
27
27
|
let discPercentageInteger = 0;
|
|
28
28
|
let productPercentageDiscount = 0;
|
|
@@ -54,13 +54,13 @@ export const calculateTotalTaxesIncluded = (
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
// Calculate discount on product net price only.
|
|
59
59
|
const discountAmountPerUnit = discPercentageInteger ? unitNetPrice * discPercentageInteger : 0;
|
|
60
60
|
const discountedUnitNetPrice = unitNetPrice - discountAmountPerUnit;
|
|
61
61
|
// Reapply VAT to get discounted product gross price.
|
|
62
62
|
const discountedUnitGrossPrice = discountedUnitNetPrice * taxFactor;
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
// Now, calculate the final totals:
|
|
65
65
|
// For the product part:
|
|
66
66
|
const productNetTotalWithoutDiscount = unitNetPrice * qty;
|
|
@@ -68,23 +68,24 @@ export const calculateTotalTaxesIncluded = (
|
|
|
68
68
|
// Add the extraAmount net (since it is not discounted):
|
|
69
69
|
const totalNetWithoutDiscount = productNetTotalWithoutDiscount + extraAmountNet;
|
|
70
70
|
const totalNetWithDiscount = productNetTotalWithDiscount + extraAmountNet;
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
// Reapply VAT to both totals:
|
|
73
73
|
const productLineImportTotal = + (totalNetWithoutDiscount * taxFactor).toFixed(2);
|
|
74
74
|
const productLineTotalWithDiscount = + (totalNetWithDiscount * taxFactor).toFixed(2);
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
// Calculate the taxes as the difference between gross and net:
|
|
77
|
-
const totalTaxesApplied = + (
|
|
78
|
-
|
|
77
|
+
const totalTaxesApplied = + (productLineTotalWithDiscount - totalNetWithDiscount).toFixed(2);
|
|
78
|
+
|
|
79
79
|
const lineDiscount = + (discountAmountPerUnit * qty).toFixed(2);
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
return {
|
|
82
82
|
product: current,
|
|
83
83
|
qty,
|
|
84
84
|
productLineImportTotal, // original gross total (no discount)
|
|
85
85
|
productLineTotalWithDiscount, // gross total after discount on product (extra not discounted)
|
|
86
86
|
productLineTaxesTotal: totalTaxesApplied,
|
|
87
|
-
lineDiscountAmount: lineDiscount
|
|
87
|
+
lineDiscountAmount: lineDiscount,
|
|
88
|
+
productLineSubtotal: totalNetWithoutDiscount // All line subtotal (extra amount considered, without discounts and taxes)
|
|
88
89
|
};
|
|
89
90
|
});
|
|
90
91
|
return productTableImports;
|
|
@@ -13,12 +13,12 @@ export const calculateTotalTaxesOverPrice = (
|
|
|
13
13
|
let discPercentageInteger = 0;
|
|
14
14
|
let productPercentageDiscount = 0;
|
|
15
15
|
let customerDiscount = 0;
|
|
16
|
-
|
|
16
|
+
const qty = current.qty; // cantidad
|
|
17
17
|
|
|
18
|
-
// Precio base sin impuestos
|
|
18
|
+
// Precio base sin impuestos (en modo over_price el precio es neto)
|
|
19
19
|
const productBasePrice = order.express ? current.expressPrice : current.price;
|
|
20
20
|
|
|
21
|
-
//
|
|
21
|
+
// Cálculo de descuento sobre el producto (aplicable solo sobre el precio base)
|
|
22
22
|
if (!order.discountCode) {
|
|
23
23
|
const discountsToApply = storeDiscounts.filter(
|
|
24
24
|
(discount) => discount.products.includes(current._id) && discount.isActive
|
|
@@ -28,6 +28,7 @@ export const calculateTotalTaxesOverPrice = (
|
|
|
28
28
|
return discount.type === 'percentage' ? acc + discount.value : acc;
|
|
29
29
|
}, 0);
|
|
30
30
|
discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
|
|
31
|
+
discountsToApply.forEach((discount) => (appliedOrderDiscounts[discount._id] = discount));
|
|
31
32
|
} else {
|
|
32
33
|
if (discountCodeObj.type === DiscountCodeTypes.PERCENTAGE) {
|
|
33
34
|
discPercentageInteger = +(discountCodeObj.value / 100).toFixed(2);
|
|
@@ -44,31 +45,35 @@ export const calculateTotalTaxesOverPrice = (
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
// Calcular descuento
|
|
48
|
+
// Calcular descuento por unidad y precio descontado
|
|
48
49
|
const productDiscount = productBasePrice * discPercentageInteger;
|
|
49
50
|
const discountedProductPrice = productBasePrice - productDiscount;
|
|
50
51
|
|
|
51
|
-
//
|
|
52
|
-
const subtotal = (discountedProductPrice * qty) + current.extraAmount;
|
|
52
|
+
// Subtotal para la línea (precio con descuento * cantidad + extraAmount) SIN impuestos
|
|
53
|
+
const subtotal = (discountedProductPrice * qty) + (current.extraAmount || 0);
|
|
53
54
|
|
|
54
|
-
// Calcular impuestos sobre el subtotal
|
|
55
|
+
// Calcular impuestos sobre el subtotal
|
|
55
56
|
const taxPercentage = getProductTaxesPercentage(current, storeSettings) / 100;
|
|
56
57
|
const taxes = subtotal * taxPercentage;
|
|
57
58
|
|
|
58
|
-
// Resultados finales
|
|
59
|
-
const totalTaxesApplied = +
|
|
59
|
+
// Resultados finales:
|
|
60
|
+
const totalTaxesApplied = +taxes.toFixed(2);
|
|
60
61
|
const lineDiscount = +(productDiscount * qty).toFixed(2);
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
const prodLinePriceWithDiscount = +((
|
|
62
|
+
|
|
63
|
+
// Precio total con descuento, reaplicando el IVA (es el total final a cobrar)
|
|
64
|
+
const prodLinePriceWithDiscount = +((subtotal * (1 + taxPercentage))).toFixed(2);
|
|
64
65
|
|
|
65
66
|
return {
|
|
66
67
|
product: current,
|
|
67
68
|
qty,
|
|
68
|
-
|
|
69
|
+
// Total bruto original sin descuento (precio base * cantidad + extraAmount)
|
|
70
|
+
productLineImportTotal: (productBasePrice * qty) + (current.extraAmount || 0),
|
|
71
|
+
// Total final con descuento, que se obtiene al sumar IVA al subtotal neto
|
|
69
72
|
productLineTotalWithDiscount: prodLinePriceWithDiscount,
|
|
70
73
|
productLineTaxesTotal: totalTaxesApplied,
|
|
71
|
-
lineDiscountAmount: lineDiscount
|
|
74
|
+
lineDiscountAmount: lineDiscount,
|
|
75
|
+
// Subtotal: precio base (neto, con descuento) sin aplicar IVA
|
|
76
|
+
productLineSubtotal: subtotal
|
|
72
77
|
};
|
|
73
78
|
});
|
|
74
79
|
return productTableImports;
|
|
@@ -4,70 +4,74 @@ import { IOrderProduct, ProductLineTotals } from "../../interfaces/Product";
|
|
|
4
4
|
import { IStore, ITaxConfig } from "../../interfaces/Store";
|
|
5
5
|
|
|
6
6
|
export const getProductTaxesPercentage = (productObj: IOrderProduct, store: IStore): number => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const getTaxValue = (tax: ITaxConfig | null | undefined, isTaxExempt: boolean): number => {
|
|
8
|
+
if (!tax) {
|
|
9
|
+
// If no store tax configured, always return 0
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if (isTaxExempt) {
|
|
14
|
+
// If store tax is configured and taxExempt is true, return 0
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
// If store tax configured and taxExempt is false, return store tax
|
|
19
|
+
return tax.value;
|
|
20
|
+
};
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const tax1 = getTaxValue(store.taxOne, productObj.taxExemptOne);
|
|
23
|
+
const tax2 = getTaxValue(store.taxTwo, productObj.taxExemptTwo);
|
|
24
|
+
const tax3 = getTaxValue(store.taxThree, productObj.taxExemptThree);
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
return tax1 + tax2 + tax3;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export const getProductLineTotals = (productLinesTotals: ProductLineTotals[]) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
const totalQuantity = +productLinesTotals.reduce((acum, line) => acum + line.qty, 0).toFixed(2);
|
|
31
|
+
const totalImportWithDiscount = +productLinesTotals
|
|
32
|
+
.reduce((acum, line) => acum + line.productLineTotalWithDiscount, 0)
|
|
33
|
+
.toFixed(2);
|
|
34
|
+
const totalImportWithoutDiscount = +productLinesTotals
|
|
35
|
+
.reduce((acum, line) => acum + line.productLineImportTotal, 0)
|
|
36
|
+
.toFixed(2);
|
|
37
|
+
const totalImporTaxes = +productLinesTotals
|
|
38
|
+
.reduce((acum, line) => acum + line.productLineTaxesTotal, 0)
|
|
39
|
+
.toFixed(2);
|
|
40
|
+
const totalDiscountAmount = +productLinesTotals
|
|
41
|
+
.reduce((acum, line) => acum + line.lineDiscountAmount, 0)
|
|
42
|
+
.toFixed(2);
|
|
43
|
+
const totalSubtotalAmount = +productLinesTotals
|
|
44
|
+
.reduce((acum, line) => acum + line.productLineSubtotal, 0)
|
|
45
|
+
.toFixed(2);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
totalQuantity,
|
|
49
|
+
totalImportWithDiscount,
|
|
50
|
+
totalImportWithoutDiscount,
|
|
51
|
+
totalImporTaxes,
|
|
52
|
+
totalDiscountAmount,
|
|
53
|
+
totalSubtotalAmount
|
|
54
|
+
};
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
export const getShippingCost = (discountObject: any, requireShippingService: boolean, store: IStore): number => {
|
|
54
|
-
|
|
58
|
+
const shippingCost = requireShippingService ? store?.orderPageConfig?.shippingServiceCost ?? 0 : 0;
|
|
55
59
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
if (discountObject?.type === DiscountCodeTypes.FREE_DELIVERY) {
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
return shippingCost;
|
|
61
65
|
};
|
|
62
66
|
|
|
63
67
|
export const getCreditApplied = (selectedCustomer: { customer: ICustomer } | undefined, orderTotal: number): number => {
|
|
64
|
-
|
|
68
|
+
const customerCredit = selectedCustomer?.customer?.credit ?? 0;
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
if (customerCredit === 0 || !selectedCustomer) {
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
return Math.min(customerCredit, orderTotal);
|
|
71
75
|
};
|
|
72
76
|
|
|
73
77
|
export const applyDiscountToProducts = (
|