tax-cl 1.0.5 → 1.2.0

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/README.md CHANGED
@@ -93,4 +93,4 @@ Configura el año de la operación renta sobre la cual aplican los cálculos. Po
93
93
 
94
94
  Recibe el siguiente argumento:
95
95
 
96
- * `year`: *(number)*, año de la operación renta para la realización de los cálculos. Los valores válidos son: `2018`, `2019`, `2020`, `2021`, `2022` y `2023`.
96
+ * `year`: *(number)*, año de la operación renta para la realización de los cálculos. Los valores válidos son desde el 2018 hasta el 2024.
package/lib/config.js CHANGED
@@ -4,6 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getConfig = getConfig;
7
+
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+
12
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
+
14
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
15
+
16
+ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
17
+
18
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+
7
20
  // Valor UTA en diciembre en https://www.sii.cl/valores_y_fechas/index_valores_y_fechas.html
8
21
  var UTA = {
9
22
  2018: 580236,
@@ -11,7 +24,8 @@ var UTA = {
11
24
  2020: 612348,
12
25
  2021: 650052,
13
26
  2022: 733884,
14
- 2023: 741228 // 2023-01
27
+ 2023: 770592,
28
+ 2024: 772116 // 2024-02
15
29
 
16
30
  }; // Valor UF al 31 de diciembre en https://www.sii.cl/valores_y_fechas/index_valores_y_fechas.html
17
31
 
@@ -21,7 +35,8 @@ var UF = {
21
35
  2020: 29070.33,
22
36
  2021: 30991.74,
23
37
  2022: 35110.98,
24
- 2023: 35287.50 // 2023-01-31
38
+ 2023: 36789.36,
39
+ 2024: 36679.62 // 2024-02-09
25
40
 
26
41
  };
27
42
  var RETENCION = {
@@ -61,21 +76,72 @@ var TOPE_IMPONIBLE_MENSUAL = {
61
76
  // https://www.spensiones.cl/portal/institucional/594/w3-article-14366.html
62
77
  2022: 81.6,
63
78
  // https://www.spensiones.cl/portal/institucional/594/w3-article-15178.html
64
- 2023: 81.6 // https://www.spensiones.cl/portal/institucional/594/w3-article-15486.html
79
+ 2023: 81.6,
80
+ // https://www.spensiones.cl/portal/institucional/594/w3-article-15486.html
81
+ 2024: 81.6 // Not yet available
65
82
 
66
83
  };
84
+ /**
85
+ * Calculates and returns tax brackets based on the provided UTA value.
86
+ *
87
+ * @param {Number} uta - The UTA value for which tax brackets are to be calculated.
88
+ * @returns {Array.<{factor: Number, montoMaximo: Number, descuento: Number}>}
89
+ * An array of objects, each containing:
90
+ * - `factor`: The tax rate for the bracket.
91
+ * - `montoMaximo`: The maximum amount for the bracket.
92
+ * - `descuento`: The discount for the bracket.
93
+ *
94
+ * @example
95
+ * const tramos = obtenerTramosImpositivos(1.5);
96
+ * console.log(tramos); // Output will be an array of tax bracket objects.
97
+ */
67
98
 
68
99
  function obtenerTramosImpositivos(uta) {
69
- var construirTramoImpositivo = function construirTramoImpositivo(factor, montoMaximo, descuento) {
100
+ var maxValue = Number.MAX_VALUE;
101
+ return [[13.5 * uta, 0, 0], [30 * uta, 0.04, 0.54 * uta], [50 * uta, 0.08, 1.74 * uta], [70 * uta, 0.135, 4.49 * uta], [90 * uta, 0.23, 11.14 * uta], [120 * uta, 0.304, 17.8 * uta], [310 * uta, 0.35, 23.32 * uta], [maxValue, 0.4, 38.82 * uta]].map(function (_ref) {
102
+ var _ref2 = _slicedToArray(_ref, 3),
103
+ montoMaximo = _ref2[0],
104
+ factor = _ref2[1],
105
+ descuento = _ref2[2];
106
+
70
107
  return {
71
108
  factor: factor,
72
109
  montoMaximo: montoMaximo,
73
110
  descuento: descuento
74
111
  };
75
- };
76
-
77
- return [construirTramoImpositivo(0, 13.5 * uta, 0), construirTramoImpositivo(0.04, 30 * uta, 0.54 * uta), construirTramoImpositivo(0.08, 50 * uta, 1.74 * uta), construirTramoImpositivo(0.135, 70 * uta, 4.49 * uta), construirTramoImpositivo(0.23, 90 * uta, 11.14 * uta), construirTramoImpositivo(0.304, 120 * uta, 17.8 * uta), construirTramoImpositivo(0.35, 150 * uta, 23.92 * uta), construirTramoImpositivo(0.4, Number.MAX_VALUE, 30.67 * uta)];
112
+ });
78
113
  }
114
+ /**
115
+ * Retrieves the configuration for a given "operacionRenta" year.
116
+ *
117
+ * @param {Number} operacionRenta - The year for which the operation configuration is required.
118
+ * @throws {Error} Throws an error if the given year is not available.
119
+ * @returns {{
120
+ * OPERACION_RENTA: Number,
121
+ * UTA: Number,
122
+ * UF: Number,
123
+ * RETENCION: Number,
124
+ * COBERTURA_PARCIAL: Number,
125
+ * TOPE_IMPONIBLE_MENSUAL: Number,
126
+ * TRAMOS_IMPOSITIVOS: Array.<{factor: number, montoMaximo: number, descuento: number}>
127
+ * }}
128
+ * An object containing various configuration values:
129
+ * - `OPERACION_RENTA`: The year for which the configuration is valid.
130
+ * - `UTA`: The UTA value for the given year (December).
131
+ * - `UF`: The UF value for the given year (last day of December).
132
+ * - `RETENCION`: The retention percentage for the given year.
133
+ * - `COBERTURA_PARCIAL`: The partial coverage percentage for the given year.
134
+ * - `TOPE_IMPONIBLE_MENSUAL`: The monthly taxable income cap for the given year.
135
+ * - `TRAMOS_IMPOSITIVOS`: An array of objects, each containing:
136
+ * - `factor`: The tax rate for the bracket.
137
+ * - `montoMaximo`: The maximum amount for the bracket.
138
+ * - `descuento`: The discount for the bracket.
139
+ *
140
+ * @example
141
+ * const config = getConfig(2022);
142
+ * console.log(config.OPERACION_RENTA); // 2022
143
+ */
144
+
79
145
 
80
146
  function getConfig(operacionRenta) {
81
147
  var commercialYear = operacionRenta - 1;
package/lib/index.js CHANGED
@@ -7,6 +7,7 @@ exports.configurarDeclaracion = configurarDeclaracion;
7
7
  exports.obtenerConfiguracion = obtenerConfiguracion;
8
8
  exports.calcularGastos = calcularGastos;
9
9
  exports.calcularSueldoImponible = calcularSueldoImponible;
10
+ exports.simularCotizaciones = simularCotizaciones;
10
11
  exports.calcularCotizacionesObligatorias = calcularCotizacionesObligatorias;
11
12
  exports.calcularRetencion = calcularRetencion;
12
13
  exports.buscarTramoImpositivo = buscarTramoImpositivo;
@@ -27,7 +28,7 @@ var OPERACION_RENTA_ACTUAL = 2023;
27
28
  var config = (0, _config.getConfig)(OPERACION_RENTA_ACTUAL);
28
29
  /**
29
30
  * Configura el año de la operación renta para los cálculos.
30
- * @param {Number} year, año de la operación renta
31
+ * @param year {Number}, año de la operación renta
31
32
  */
32
33
 
33
34
  function configurarDeclaracion(year) {
@@ -45,8 +46,8 @@ function min(a, b) {
45
46
  return a > b ? b : a;
46
47
  }
47
48
 
48
- function calcularGastos(sueldoAnual) {
49
- var gastos = sueldoAnual * 0.3;
49
+ function calcularGastos(rentaAnual) {
50
+ var gastos = rentaAnual * 0.3;
50
51
  var tope = 15 * config.UTA;
51
52
  return min(gastos, tope);
52
53
  }
@@ -71,13 +72,8 @@ var COTIZACIONES_OBLIGATORIAS = [{
71
72
  variable: true
72
73
  }, {
73
74
  name: "AFP",
74
- percent: 10,
75
+ percent: 10.58,
75
76
  variable: true
76
- }, {
77
- name: "Comisión AFP",
78
- percent: 0.58,
79
- // AFP Modelo https://www.spensiones.cl/apps/estcom/estcom.php
80
- variable: false
81
77
  }];
82
78
  exports.COTIZACIONES_OBLIGATORIAS = COTIZACIONES_OBLIGATORIAS;
83
79
 
@@ -86,19 +82,51 @@ function calcularSueldoImponible(sueldoAnual) {
86
82
  return min(0.8 * sueldoAnual, topeAnual);
87
83
  }
88
84
 
89
- function calcularCotizacionesObligatorias(ingresos) {
85
+ function simularCotizaciones(ingresos) {
90
86
  var cotizacionParcial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
91
- var totalCotizacionesObligatorias = 0;
92
- COTIZACIONES_OBLIGATORIAS.forEach(function (cotizacion) {
93
- var montoCotizacion = calcularSueldoImponible(ingresos) * cotizacion.percent / 100;
94
-
95
- if (cotizacion.variable && cotizacionParcial) {
96
- montoCotizacion = montoCotizacion * config.COBERTURA_PARCIAL;
97
- }
87
+ var sueldoImponible = calcularSueldoImponible(ingresos);
88
+
89
+ if (cotizacionParcial) {
90
+ var sueldoImponibleParcial = sueldoImponible * config.COBERTURA_PARCIAL;
91
+ return COTIZACIONES_OBLIGATORIAS.map(function (cotizacion) {
92
+ var monto = (cotizacion.variable ? sueldoImponibleParcial : sueldoImponible) * cotizacion.percent / 100;
93
+ return {
94
+ name: cotizacion.name,
95
+ percent: 100 * monto / sueldoImponible,
96
+ value: monto
97
+ };
98
+ });
99
+ } else {
100
+ var remanente = calcularRetencion(sueldoImponible / 0.8);
101
+ return COTIZACIONES_OBLIGATORIAS.map(function (cotizacion) {
102
+ if (cotizacion.name === 'AFP') {
103
+ var monto = min(remanente, sueldoImponible * cotizacion.percent / 100);
104
+ return {
105
+ name: cotizacion.name,
106
+ percent: 100 * monto / sueldoImponible,
107
+ value: monto
108
+ };
109
+ } else {
110
+ var percent = cotizacion.percent;
111
+
112
+ var _monto = sueldoImponible * cotizacion.percent / 100;
113
+
114
+ remanente -= _monto;
115
+ return {
116
+ name: cotizacion.name,
117
+ percent: percent,
118
+ value: _monto
119
+ };
120
+ }
121
+ });
122
+ }
123
+ }
98
124
 
99
- totalCotizacionesObligatorias += montoCotizacion;
100
- });
101
- return totalCotizacionesObligatorias;
125
+ function calcularCotizacionesObligatorias(ingresos) {
126
+ var cotizacionParcial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
127
+ return simularCotizaciones(ingresos, cotizacionParcial).reduce(function (total, cotizacion) {
128
+ return total + cotizacion.value;
129
+ }, 0);
102
130
  }
103
131
 
104
132
  function calcularRetencion(sueldoAnual) {
@@ -129,17 +157,22 @@ function calcular(sueldoMensual) {
129
157
  var gastos = calcularGastos(sueldoAnual);
130
158
  var sueldoTributable = sueldoAnual - gastos;
131
159
  var montoCotizacionesObligatorias = calcularCotizacionesObligatorias(sueldoAnual);
132
- var cotizacionesParciales = calcularCotizacionesObligatorias(sueldoAnual, true);
160
+ var montoCotizacionParcial = calcularCotizacionesObligatorias(sueldoAnual, true);
133
161
  var retencion = calcularRetencion(sueldoAnual);
134
162
  var impuestos = calcularImpuestos(sueldoTributable);
135
163
  var deuda = calcularDeuda(montoCotizacionesObligatorias, impuestos, retencion);
136
- var deudaModalidadParcial = calcularDeuda(cotizacionesParciales, impuestos, retencion);
164
+ var deudaModalidadParcial = calcularDeuda(montoCotizacionParcial, impuestos, retencion);
137
165
  return {
138
166
  operacionRenta: config.OPERACION_RENTA,
139
167
  sueldoAnual: sueldoAnual,
140
168
  gastos: gastos,
141
169
  sueldoTributable: sueldoTributable,
142
170
  montoCotizacionesObligatorias: montoCotizacionesObligatorias,
171
+ montoCotizacionParcial: montoCotizacionParcial,
172
+ cotizaciones: {
173
+ parcial: simularCotizaciones(sueldoAnual, true),
174
+ total: simularCotizaciones(sueldoAnual)
175
+ },
143
176
  retencion: retencion,
144
177
  impuestos: impuestos,
145
178
  deuda: deuda,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tax-cl",
3
- "version": "1.0.5",
3
+ "version": "1.2.0",
4
4
  "description": "Librería cálculo de impuestos y cotizaciones en Chile 🇨🇱",
5
5
  "main": "lib/index.js",
6
6
  "repository": "git@github.com:muZk/tax-cl.git",
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/tax-cl.iml" filepath="$PROJECT_DIR$/.idea/tax-cl.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/tax-cl.iml DELETED
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/temp" />
6
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
6
- </project>