washday-sdk 0.0.161 → 0.0.163

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.
@@ -18,7 +18,7 @@ export const calculateOrderTotal = (order, selectedCustomer, storeSettings, hasS
18
18
  discountCodeAmount = includesProducts ? discountCodeObj.value : 0;
19
19
  }
20
20
  // ORDER TOTAL CALCULATION AND CREDIT APPLIED
21
- let orderTotalWithOutCredit = +(totalImportWithDiscount + totalImporTaxes + shippingCost - discountCodeAmount).toFixed(2);
21
+ let orderTotalWithOutCredit = +(totalImportWithDiscount + shippingCost - discountCodeAmount).toFixed(2);
22
22
  let creditApplied = getCreditApplied(selectedCustomer, orderTotalWithOutCredit);
23
23
  let orderTotal = +(orderTotalWithOutCredit - creditApplied).toFixed(2);
24
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, creditApplied, productTotalWithoutDiscount: totalImportWithoutDiscount, totalDiscountAmount: totalDiscountAmount + discountCodeAmount, shippingServiceTotal: shippingCost, appliedOrderDiscounts });
@@ -2,22 +2,20 @@ import { getProductTaxesPercentage } from "./helpers";
2
2
  export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettings, storeDiscounts, appliedOrderDiscounts, discountCodeObj) => {
3
3
  const productTableImports = [...order.products, ...order.buyAndGetProducts].map((current) => {
4
4
  var _a, _b;
5
- let discPercentageInteger = 0;
6
- let productPercentageDiscount = 0;
7
- let customerDiscount = 0;
8
5
  const qty = current.qty || 0;
9
- // ExtraAmount se trata de forma separada: se conserva su valor bruto, pero se convierte a neto
10
- const extraAmount = current.extraAmount; // valor bruto (con impuestos incluidos)
11
- // Obtener la tasa de impuesto (por ejemplo, 16%) y convertirla a decimal:
12
6
  const taxPercentage = getProductTaxesPercentage(current, storeSettings);
13
- const taxPercentageInteger = taxPercentage / 100;
14
- // Convertir extraAmount a valor neto
15
- const extraAmountNet = extraAmount / (1 + taxPercentageInteger);
16
- // Precio del producto (con impuestos incluidos) SIN incluir extraAmount
7
+ const taxFactor = 1 + taxPercentage / 100;
8
+ // Convert extraAmount from gross to net (assume extraAmount is not discounted)
9
+ const extraAmountGross = current.extraAmount || 0;
10
+ const extraAmountNet = extraAmountGross / taxFactor;
11
+ // Get the product’s gross price (excluding extraAmount)
17
12
  const productGrossPrice = order.express ? current.expressPrice : current.price;
18
- // Extraer el precio neto del producto
19
- const unitNetPrice = productGrossPrice / (1 + taxPercentageInteger);
20
- // Calcular el porcentaje de descuento (aplicable solo sobre el precio neto del producto)
13
+ // Convert product gross price to net
14
+ const unitNetPrice = productGrossPrice / taxFactor;
15
+ // Determine discount percentage (if any) discount is applied only on product net price.
16
+ let discPercentageInteger = 0;
17
+ let productPercentageDiscount = 0;
18
+ let customerDiscount = 0;
21
19
  if (!order.discountCode) {
22
20
  const discountsToApply = storeDiscounts.filter((discount) => discount.products.includes(current._id) && discount.isActive);
23
21
  customerDiscount = ((_a = selectedCustomer === null || selectedCustomer === void 0 ? void 0 : selectedCustomer.customer) === null || _a === void 0 ? void 0 : _a.discount) || 0;
@@ -44,24 +42,29 @@ export const calculateTotalTaxesIncluded = (order, selectedCustomer, storeSettin
44
42
  }
45
43
  }
46
44
  }
47
- // Aplicar el descuento sobre el precio neto del producto
48
- const discountAmountPerUnit = discPercentageInteger
49
- ? unitNetPrice * discPercentageInteger
50
- : (current.discountAmount || 0) / (1 + taxPercentageInteger);
45
+ // Calculate discount on product net price only.
46
+ const discountAmountPerUnit = discPercentageInteger ? unitNetPrice * discPercentageInteger : 0;
51
47
  const discountedUnitNetPrice = unitNetPrice - discountAmountPerUnit;
52
- // Calcular los importes netos:
53
- const productNetImportWithoutDiscount = (unitNetPrice * qty) + extraAmountNet;
54
- const productNetImportWithDiscount = (discountedUnitNetPrice * qty) + extraAmountNet;
55
- // Para obtener los valores brutos (con impuestos), se multiplica por (1 + taxPercentageInteger)
56
- const productGrossImportWithoutDiscount = productNetImportWithoutDiscount * (1 + taxPercentageInteger);
57
- // La parte de impuestos es la diferencia entre el bruto y el neto
58
- const totalTaxesApplied = +((productGrossImportWithoutDiscount - productNetImportWithoutDiscount)).toFixed(2);
48
+ // Reapply VAT to get discounted product gross price.
49
+ const discountedUnitGrossPrice = discountedUnitNetPrice * taxFactor;
50
+ // Now, calculate the final totals:
51
+ // For the product part:
52
+ const productNetTotalWithoutDiscount = unitNetPrice * qty;
53
+ const productNetTotalWithDiscount = discountedUnitNetPrice * qty;
54
+ // Add the extraAmount net (since it is not discounted):
55
+ const totalNetWithoutDiscount = productNetTotalWithoutDiscount + extraAmountNet;
56
+ const totalNetWithDiscount = productNetTotalWithDiscount + extraAmountNet;
57
+ // Reapply VAT to both totals:
58
+ const productLineImportTotal = +(totalNetWithoutDiscount * taxFactor).toFixed(2);
59
+ const productLineTotalWithDiscount = +(totalNetWithDiscount * taxFactor).toFixed(2);
60
+ // Calculate the taxes as the difference between gross and net:
61
+ const totalTaxesApplied = +(productLineImportTotal - totalNetWithoutDiscount).toFixed(2);
59
62
  const lineDiscount = +(discountAmountPerUnit * qty).toFixed(2);
60
63
  return {
61
64
  product: current,
62
65
  qty,
63
- productLineImportTotal: +productNetImportWithoutDiscount.toFixed(2), // valor neto sin descuento
64
- productLineTotalWithDiscount: +productNetImportWithDiscount.toFixed(2), // valor neto con descuento
66
+ productLineImportTotal, // original gross total (no discount)
67
+ productLineTotalWithDiscount, // gross total after discount on product (extra not discounted)
65
68
  productLineTaxesTotal: totalTaxesApplied,
66
69
  lineDiscountAmount: lineDiscount
67
70
  };
@@ -46,7 +46,8 @@ export const calculateTotalTaxesOverPrice = (order, selectedCustomer, storeSetti
46
46
  const totalTaxesApplied = +(taxes).toFixed(2);
47
47
  const lineDiscount = +(productDiscount * qty).toFixed(2);
48
48
  // Se suma el extraAmount a la parte del producto descontado para obtener el valor total a cobrar de la línea
49
- const prodLinePriceWithDiscount = +(((discountedProductPrice * qty) + current.extraAmount)).toFixed(2);
49
+ //const prodLinePriceWithDiscount = +(((discountedProductPrice * qty) + current.extraAmount)).toFixed(2);
50
+ const prodLinePriceWithDiscount = +((((discountedProductPrice * qty) + current.extraAmount) * (1 + taxPercentage))).toFixed(2);
50
51
  return {
51
52
  product: current,
52
53
  qty,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "washday-sdk",
3
- "version": "0.0.161",
3
+ "version": "0.0.163",
4
4
  "description": "Washday utilities functions and API",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -37,7 +37,7 @@ export const calculateOrderTotal = (
37
37
  }
38
38
 
39
39
  // ORDER TOTAL CALCULATION AND CREDIT APPLIED
40
- let orderTotalWithOutCredit = +(totalImportWithDiscount + totalImporTaxes + shippingCost - discountCodeAmount).toFixed(2);
40
+ let orderTotalWithOutCredit = +(totalImportWithDiscount + shippingCost - discountCodeAmount).toFixed(2);
41
41
  let creditApplied = getCreditApplied(selectedCustomer, orderTotalWithOutCredit);
42
42
  let orderTotal = +(orderTotalWithOutCredit - creditApplied).toFixed(2);
43
43
 
@@ -8,36 +8,31 @@ export const calculateTotalTaxesIncluded = (
8
8
  storeDiscounts: any[],
9
9
  appliedOrderDiscounts: any,
10
10
  discountCodeObj: any | null
11
- ) => {
11
+ ): any => {
12
12
  const productTableImports = [...order.products, ...order.buyAndGetProducts].map((current: IOrderProduct) => {
13
- let discPercentageInteger = 0;
14
- let productPercentageDiscount = 0;
15
- let customerDiscount = 0;
16
13
  const qty = current.qty || 0;
17
-
18
- // ExtraAmount se trata de forma separada: se conserva su valor bruto, pero se convierte a neto
19
- const extraAmount = current.extraAmount; // valor bruto (con impuestos incluidos)
20
-
21
- // Obtener la tasa de impuesto (por ejemplo, 16%) y convertirla a decimal:
22
14
  const taxPercentage = getProductTaxesPercentage(current, storeSettings);
23
- const taxPercentageInteger = taxPercentage / 100;
15
+ const taxFactor = 1 + taxPercentage / 100;
24
16
 
25
- // Convertir extraAmount a valor neto
26
- const extraAmountNet = extraAmount / (1 + taxPercentageInteger);
17
+ // Convert extraAmount from gross to net (assume extraAmount is not discounted)
18
+ const extraAmountGross = current.extraAmount || 0;
19
+ const extraAmountNet = extraAmountGross / taxFactor;
27
20
 
28
- // Precio del producto (con impuestos incluidos) SIN incluir extraAmount
21
+ // Get the product’s gross price (excluding extraAmount)
29
22
  const productGrossPrice = order.express ? current.expressPrice : current.price;
23
+ // Convert product gross price to net
24
+ const unitNetPrice = productGrossPrice / taxFactor;
30
25
 
31
- // Extraer el precio neto del producto
32
- const unitNetPrice = productGrossPrice / (1 + taxPercentageInteger);
33
-
34
- // Calcular el porcentaje de descuento (aplicable solo sobre el precio neto del producto)
26
+ // Determine discount percentage (if any) – discount is applied only on product net price.
27
+ let discPercentageInteger = 0;
28
+ let productPercentageDiscount = 0;
29
+ let customerDiscount = 0;
35
30
  if (!order.discountCode) {
36
31
  const discountsToApply = storeDiscounts.filter(
37
32
  (discount) => discount.products.includes(current._id) && discount.isActive
38
33
  );
39
34
  customerDiscount = selectedCustomer?.customer?.discount || 0;
40
- productPercentageDiscount = discountsToApply.reduce((prev, next) => {
35
+ productPercentageDiscount = discountsToApply.reduce((prev: number, next: any) => {
41
36
  return next.type === 'percentage' ? prev + next.value : prev;
42
37
  }, 0);
43
38
  discPercentageInteger = +((productPercentageDiscount + customerDiscount) / 100).toFixed(2);
@@ -60,28 +55,34 @@ export const calculateTotalTaxesIncluded = (
60
55
  }
61
56
  }
62
57
 
63
- // Aplicar el descuento sobre el precio neto del producto
64
- const discountAmountPerUnit = discPercentageInteger
65
- ? unitNetPrice * discPercentageInteger
66
- : (current.discountAmount || 0) / (1 + taxPercentageInteger);
58
+ // Calculate discount on product net price only.
59
+ const discountAmountPerUnit = discPercentageInteger ? unitNetPrice * discPercentageInteger : 0;
67
60
  const discountedUnitNetPrice = unitNetPrice - discountAmountPerUnit;
61
+ // Reapply VAT to get discounted product gross price.
62
+ const discountedUnitGrossPrice = discountedUnitNetPrice * taxFactor;
63
+
64
+ // Now, calculate the final totals:
65
+ // For the product part:
66
+ const productNetTotalWithoutDiscount = unitNetPrice * qty;
67
+ const productNetTotalWithDiscount = discountedUnitNetPrice * qty;
68
+ // Add the extraAmount net (since it is not discounted):
69
+ const totalNetWithoutDiscount = productNetTotalWithoutDiscount + extraAmountNet;
70
+ const totalNetWithDiscount = productNetTotalWithDiscount + extraAmountNet;
68
71
 
69
- // Calcular los importes netos:
70
- const productNetImportWithoutDiscount = (unitNetPrice * qty) + extraAmountNet;
71
- const productNetImportWithDiscount = (discountedUnitNetPrice * qty) + extraAmountNet;
72
+ // Reapply VAT to both totals:
73
+ const productLineImportTotal = + (totalNetWithoutDiscount * taxFactor).toFixed(2);
74
+ const productLineTotalWithDiscount = + (totalNetWithDiscount * taxFactor).toFixed(2);
72
75
 
73
- // Para obtener los valores brutos (con impuestos), se multiplica por (1 + taxPercentageInteger)
74
- const productGrossImportWithoutDiscount = productNetImportWithoutDiscount * (1 + taxPercentageInteger);
75
- // La parte de impuestos es la diferencia entre el bruto y el neto
76
- const totalTaxesApplied = +((productGrossImportWithoutDiscount - productNetImportWithoutDiscount)).toFixed(2);
76
+ // Calculate the taxes as the difference between gross and net:
77
+ const totalTaxesApplied = + (productLineImportTotal - totalNetWithoutDiscount).toFixed(2);
77
78
 
78
- const lineDiscount = +(discountAmountPerUnit * qty).toFixed(2);
79
+ const lineDiscount = + (discountAmountPerUnit * qty).toFixed(2);
79
80
 
80
81
  return {
81
82
  product: current,
82
83
  qty,
83
- productLineImportTotal: +productNetImportWithoutDiscount.toFixed(2), // valor neto sin descuento
84
- productLineTotalWithDiscount: +productNetImportWithDiscount.toFixed(2), // valor neto con descuento
84
+ productLineImportTotal, // original gross total (no discount)
85
+ productLineTotalWithDiscount, // gross total after discount on product (extra not discounted)
85
86
  productLineTaxesTotal: totalTaxesApplied,
86
87
  lineDiscountAmount: lineDiscount
87
88
  };
@@ -59,7 +59,8 @@ export const calculateTotalTaxesOverPrice = (
59
59
  const totalTaxesApplied = +(taxes).toFixed(2);
60
60
  const lineDiscount = +(productDiscount * qty).toFixed(2);
61
61
  // Se suma el extraAmount a la parte del producto descontado para obtener el valor total a cobrar de la línea
62
- const prodLinePriceWithDiscount = +(((discountedProductPrice * qty) + current.extraAmount)).toFixed(2);
62
+ //const prodLinePriceWithDiscount = +(((discountedProductPrice * qty) + current.extraAmount)).toFixed(2);
63
+ const prodLinePriceWithDiscount = +((((discountedProductPrice * qty) + current.extraAmount) * (1 + taxPercentage))).toFixed(2);
63
64
 
64
65
  return {
65
66
  product: current,