tax-cl 1.4.3 → 1.4.4
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 +4 -2
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/.github/workflows/publish.yml +0 -49
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ console.log(`Tus gastos supuestos son ${resultado.gastos}`);
|
|
|
56
56
|
console.log(`Tu sueldo tributable es ${resultado.sueldoTributable}`);
|
|
57
57
|
console.log(`Lo que tendrás que pagar por impuestos es ${resultado.impuestos}`);
|
|
58
58
|
console.log(`Lo que tendrás que pagar por cotizaciones es igual a ${resultado.montoCotizacionesObligatorias}`);
|
|
59
|
-
console.log(`La retención de tus boletas anual es ${retencion}`);
|
|
59
|
+
console.log(`La retención de tus boletas anual es ${resultado.retencion}`);
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
## Advanced Usage
|
|
@@ -82,6 +82,8 @@ Retorna un objeto con las siguientes propiedades:
|
|
|
82
82
|
* `retencion`: *(number)*. Es el monto total de las retenciones pagadas al Servicio de Impuestos Internos durante un año. Este monto aumenta año a año hasta llegar al 17%.
|
|
83
83
|
* `impuestos`: *(number)*. Es el total de impuestos a pagar según el tramo impositivo.
|
|
84
84
|
* `deuda`: *(number)*. Es la deuda final, si su valor es positivo indica el valor que debes pagar al Servicio de Impuestos Internos, si es negativo es el valor que recibirás como devolución.
|
|
85
|
+
* `montoCotizacionParcial`: *(number)*. Es el monto total de las cotizaciones en modalidad parcial.
|
|
86
|
+
* `cotizaciones`: *(object)*. Es un objeto con el detalle de las cotizaciones, con las propiedades `parcial` y `total`, cada una con el desglose de cada cotización.
|
|
85
87
|
* `deudaModalidadParcial`: *(number)*. Es la deuda final, pero considerando que has optado por pagar las cotizaciones en modalidad parcial.
|
|
86
88
|
* `operacionRenta`: *(number)*. Es el año de la declaración (**2025** por defecto).
|
|
87
89
|
|
|
@@ -93,7 +95,7 @@ Configura el año de la operación renta sobre la cual aplican los cálculos. Po
|
|
|
93
95
|
|
|
94
96
|
Recibe los siguientes argumentos:
|
|
95
97
|
|
|
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
|
|
98
|
+
* `year`: *(number)*, año de la operación renta para la realización de los cálculos. Los valores válidos son desde el 2019 hasta el 2027.
|
|
97
99
|
* `options`: *(object, opcional)*, opciones de configuración adicionales:
|
|
98
100
|
* `uf`: *(number, opcional)*, valor UF personalizado. Si no se especifica, se usa el valor por defecto del año.
|
|
99
101
|
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;ACAA,4FAA4F;AAC5F,MAAM,4BAAM;IACV,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEA,iGAAiG;AACjG,MAAM,2BAAK;IACT,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEA,MAAM,kCAAY;IAChB,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEA,0FAA0F;AAC1F,MAAM,0CAAoB;IACxB,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEA,MAAM,+CAAyB;IAC7B,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEA;;;;;;;;;;;;;CAaC,GACD,SAAS,+CAAyB,GAAG;IACnC,MAAM,WAAW,OAAO,SAAS;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ACzB,MAAM,SAAS,0CAAe;IAC9B,MAAM,mBAAmB,cAAc;IACvC,MAAM,gCAAgC,0CAAiC;IACvE,MAAM,yBAAyB,0CAAiC,aAAa;IAC7E,MAAM,YAAY,0CAAkB;IACpC,MAAM,YAAY,0CAAkB;IACpC,MAAM,QAAQ,0CAAc,+BAA+B,WAAW;IACtE,MAAM,wBAAwB,0CAAc,wBAAwB,WAAW;IAC/E,OAAO;QACL,gBAAgB,6BAAO,eAAe;qBACtC;gBACA;0BACA;uCACA;gCACA;QACA,cAAc;YACZ,SAAS,0CAAoB,aAAa;YAC1C,OAAO,0CAAoB;QAC7B;mBACA;mBACA;eACA;+BACA;IACF;AACF","sources":["src/index.js","src/config.js"],"sourcesContent":["import { getConfig } from './config';\n\nconst OPERACION_RENTA_ACTUAL = 2025;\n\nconst config = getConfig(OPERACION_RENTA_ACTUAL);\n\n/**\n * Configura el año de la operación renta para los cálculos.\n * @param {Number} year - Año de la operación renta\n * @param {Object} [options] - Opciones de configuración\n * @param {Number} [options.uf] - Valor UF personalizado (por defecto usa el valor del año)\n */\nexport function configurarDeclaracion(year, options = {}) {\n const newConfig = getConfig(year, options);\n Object.keys(newConfig).forEach(key => {\n config[key] = newConfig[key];\n });\n}\n\nexport function obtenerConfiguracion() {\n return { ...config };\n}\n\nfunction min(a, b) {\n return a > b ? b : a;\n}\n\nexport function calcularGastos(rentaAnual) {\n const gastos = rentaAnual * 0.3;\n const tope = 15 * config.UTA;\n return min(gastos, tope);\n}\n\nconst COTIZACIONES_OBLIGATORIAS = [\n {\n name: \"Seguro de invalidez y sobrevivencia (SIS)\",\n percent: () => {\n // Esto cambia por año, no tengo seguridad de los años anteriores al 2022\n // Aunque el uso de esta librería es más actual que histórico (importa año comercial presente y anterior)\n // No me gusta que esto esté aquí, sin embargo, como hotfix está OK\n // https://www.spensiones.cl/portal/institucional/594/w3-propertyvalue-9917.html#recuadros_articulo_4130_0\n const SIS = {\n 2018: 1.99,\n 2019: 1.99,\n 2020: 1.99,\n 2021: 1.85,\n 2022: 1.54,\n 2023: 1.47,\n 2024: 1.49,\n 2025: 1.5,\n 2026: 1.5, // Igual que el 2025, ya que no se ha publicado el valor\n };\n return SIS[config.OPERACION_RENTA - 1] || SIS[2023];\n },\n variable: false,\n },\n {\n name:\n \"Seguro de la ley de accidentes del trabajo y enfermedades profesionales (ATEP)\",\n percent: 0.90,\n variable: false,\n },\n {\n name: \"Seguro de acompañamiento niños y niñas (Ley SANNA)\",\n percent: 0.03, // https://www.chileatiende.gob.cl/fichas/53276-seguro-para-el-acompanamiento-de-ninos-y-ninas-afectados-por-una-condicion-grave-de-salud-ley-sanna\n variable: false,\n },\n {\n name: \"Salud\",\n percent: 7,\n variable: true,\n },\n {\n name: \"AFP\",\n percent: 10.49,\n variable: true,\n },\n];\n\nfunction getContributionPercentage(contribution) {\n return typeof contribution.percent === 'function' ? contribution.percent() : contribution.percent\n}\n\nexport function calcularSueldoImponible(sueldoAnual) {\n const topeAnual = config.TOPE_IMPONIBLE_MENSUAL * config.UF * 12;\n return min(0.8 * sueldoAnual, topeAnual);\n}\n\nexport function simularCotizaciones(ingresos, cotizacionParcial = false) {\n const sueldoImponible = calcularSueldoImponible(ingresos)\n\n if (cotizacionParcial) {\n const sueldoImponibleParcial = sueldoImponible * config.COBERTURA_PARCIAL\n\n return COTIZACIONES_OBLIGATORIAS.map(cotizacion => {\n const percent = getContributionPercentage(cotizacion)\n const monto = (cotizacion.variable ? sueldoImponibleParcial : sueldoImponible) * percent / 100\n return {\n name: cotizacion.name,\n percent,\n value: monto,\n }\n })\n } else {\n let remanente = calcularRetencion(sueldoImponible / 0.8)\n return COTIZACIONES_OBLIGATORIAS.map(cotizacion => {\n if (cotizacion.name === 'AFP') {\n const monto = min(remanente, sueldoImponible * getContributionPercentage(cotizacion) / 100)\n return {\n name: cotizacion.name,\n percent: 100 * monto / sueldoImponible,\n value: monto,\n }\n } else {\n const percent = getContributionPercentage(cotizacion)\n const monto = sueldoImponible * percent / 100\n remanente -= monto\n return {\n name: cotizacion.name,\n percent,\n value: monto,\n }\n }\n })\n }\n}\n\nexport function calcularCotizacionesObligatorias(ingresos, cotizacionParcial = false) {\n return simularCotizaciones(ingresos, cotizacionParcial).reduce((total, cotizacion) => {\n return total + cotizacion.value;\n }, 0)\n}\n\nexport function calcularRetencion(sueldoAnual) {\n return sueldoAnual * config.RETENCION;\n}\n\nexport function buscarTramoImpositivo(sueldoTributable) {\n return config.TRAMOS_IMPOSITIVOS.find(({ montoMaximo }) => sueldoTributable <= montoMaximo);\n}\n\nexport function calcularImpuestos(sueldoTributable) {\n const { factor, descuento } = buscarTramoImpositivo(sueldoTributable);\n return factor * sueldoTributable - descuento;\n}\n\nexport function calcularDeuda(montoCotizacionesObligatorias, impuestos, retencion) {\n return impuestos - retencion + montoCotizacionesObligatorias;\n}\n\nexport function calcular(sueldoMensual) {\n const sueldoAnual = 12 * sueldoMensual;\n const gastos = calcularGastos(sueldoAnual);\n const sueldoTributable = sueldoAnual - gastos;\n const montoCotizacionesObligatorias = calcularCotizacionesObligatorias(sueldoAnual);\n const montoCotizacionParcial = calcularCotizacionesObligatorias(sueldoAnual, true);\n const retencion = calcularRetencion(sueldoAnual);\n const impuestos = calcularImpuestos(sueldoTributable);\n const deuda = calcularDeuda(montoCotizacionesObligatorias, impuestos, retencion);\n const deudaModalidadParcial = calcularDeuda(montoCotizacionParcial, impuestos, retencion);\n return {\n operacionRenta: config.OPERACION_RENTA,\n sueldoAnual,\n gastos,\n sueldoTributable,\n montoCotizacionesObligatorias,\n montoCotizacionParcial,\n cotizaciones: {\n parcial: simularCotizaciones(sueldoAnual, true),\n total: simularCotizaciones(sueldoAnual),\n },\n retencion,\n impuestos,\n deuda,\n deudaModalidadParcial,\n };\n}\n","// Valor UTA en diciembre en https://www.sii.cl/valores_y_fechas/index_valores_y_fechas.html\nconst UTA = {\n 2018: 580236,\n 2019: 595476,\n 2020: 612348,\n 2021: 650052,\n 2022: 733884,\n 2023: 770592,\n 2024: 807528,\n 2025: 834504,\n 2026: 837012, // 2026-01\n};\n\n// Valor UF al 31 de diciembre en https://www.sii.cl/valores_y_fechas/index_valores_y_fechas.html\nconst UF = {\n 2018: 27565.79,\n 2019: 28309.94,\n 2020: 29070.33,\n 2021: 30991.74,\n 2022: 35110.98,\n 2023: 36789.36,\n 2024: 38416.69,\n 2025: 39727.96,\n 2026: 39706.07, // 2026-01-31\n};\n\nconst RETENCION = {\n 2019: 10,\n 2020: 10.75,\n 2021: 11.5,\n 2022: 12.25,\n 2023: 13,\n 2024: 13.75,\n 2025: 14.5,\n 2026: 15.25,\n 2027: 16,\n 2028: 17,\n};\n\n// Artículo Segundo de la Ley 21.133 (https://www.bcn.cl/leychile/navegar?idNorma=1128420)\nconst COBERTURA_PARCIAL = {\n 2018: 5,\n 2019: 17,\n 2020: 27,\n 2021: 37,\n 2022: 47,\n 2023: 57,\n 2024: 70,\n 2025: 80,\n 2026: 90,\n 2027: 100,\n 2028: 100,\n};\n\nconst TOPE_IMPONIBLE_MENSUAL = {\n 2018: 78.3, // https://www.spensiones.cl/portal/institucional/594/w3-article-12946.html\n 2019: 79.2, // https://www.spensiones.cl/portal/institucional/594/w3-article-13553.html\n 2020: 80.2, // https://www.spensiones.cl/portal/institucional/594/w3-article-13843.html\n 2021: 81.6, // https://www.spensiones.cl/portal/institucional/594/w3-article-14366.html\n 2022: 81.6, // https://www.spensiones.cl/portal/institucional/594/w3-article-15178.html\n 2023: 81.6, // https://www.spensiones.cl/portal/institucional/594/w3-article-15486.html\n 2024: 84.3, // https://www.spensiones.cl/portal/institucional/594/w3-article-15855.html\n 2025: 87.8, // https://www.spensiones.cl/portal/institucional/594/w3-article-16252.html\n 2026: 89.9, // https://www.spensiones.cl/portal/institucional/594/w3-article-16885.html\n};\n\n/**\n * Calculates and returns tax brackets based on the provided UTA value.\n *\n * @param {Number} uta - The UTA value for which tax brackets are to be calculated.\n * @returns {Array.<{factor: Number, montoMaximo: Number, descuento: Number}>}\n * An array of objects, each containing:\n * - `factor`: The tax rate for the bracket.\n * - `montoMaximo`: The maximum amount for the bracket.\n * - `descuento`: The discount for the bracket.\n * \n * @example\n * const tramos = obtenerTramosImpositivos(1.5);\n * console.log(tramos); // Output will be an array of tax bracket objects.\n */\nfunction obtenerTramosImpositivos(uta) {\n const maxValue = Number.MAX_VALUE;\n return [\n [13.5 * uta, 0, 0],\n [ 30 * uta, 0.04, 0.54 * uta],\n [ 50 * uta, 0.08, 1.74 * uta],\n [ 70 * uta, 0.135, 4.49 * uta],\n [ 90 * uta, 0.23, 11.14 * uta],\n [ 120 * uta, 0.304, 17.8 * uta],\n [ 310 * uta, 0.35, 23.32 * uta],\n [ maxValue, 0.4, 38.82 * uta],\n ].map(([montoMaximo, factor, descuento]) => ({\n factor,\n montoMaximo,\n descuento,\n }));\n}\n\n/**\n * Retrieves the configuration for a given \"operacionRenta\" year.\n *\n * @param {Number} operacionRenta - The year for which the operation configuration is required.\n * @param {Object} [options] - Optional configuration overrides.\n * @param {Number} [options.uf] - Custom UF value to use instead of the default for the year.\n * @throws {Error} Throws an error if the given year is not available.\n * @returns {{\n * OPERACION_RENTA: Number,\n * UTA: Number,\n * UF: Number,\n * RETENCION: Number,\n * COBERTURA_PARCIAL: Number,\n * TOPE_IMPONIBLE_MENSUAL: Number,\n * TRAMOS_IMPOSITIVOS: Array.<{factor: number, montoMaximo: number, descuento: number}>\n * }}\n * An object containing various configuration values:\n * - `OPERACION_RENTA`: The year for which the configuration is valid.\n * - `UTA`: The UTA value for the given year (December).\n * - `UF`: The UF value for the given year (last day of December), or custom value if provided.\n * - `RETENCION`: The retention percentage for the given year.\n * - `COBERTURA_PARCIAL`: The partial coverage percentage for the given year.\n * - `TOPE_IMPONIBLE_MENSUAL`: The monthly taxable income cap for the given year.\n * - `TRAMOS_IMPOSITIVOS`: An array of objects, each containing:\n * - `factor`: The tax rate for the bracket.\n * - `montoMaximo`: The maximum amount for the bracket.\n * - `descuento`: The discount for the bracket.\n *\n * @example\n * const config = getConfig(2022);\n * console.log(config.OPERACION_RENTA); // 2022\n *\n * @example\n * // With custom UF value\n * const config = getConfig(2025, { uf: 40000 });\n * console.log(config.UF); // 40000\n*/\nexport function getConfig(operacionRenta, options = {}) {\n const commercialYear = operacionRenta - 1;\n\n if (!TOPE_IMPONIBLE_MENSUAL[commercialYear]) {\n const validos = Object.keys(TOPE_IMPONIBLE_MENSUAL).map(year => parseInt(year) + 1).join(', ');\n throw new Error(`El año ingresado es incorrecto. Los valores válidos son: ${validos}`);\n }\n\n const ufValue = options.uf !== undefined ? options.uf : UF[commercialYear];\n\n return {\n OPERACION_RENTA: operacionRenta,\n UTA: UTA[commercialYear],\n UF: ufValue,\n RETENCION: RETENCION[commercialYear] / 100,\n COBERTURA_PARCIAL: COBERTURA_PARCIAL[commercialYear] / 100,\n TOPE_IMPONIBLE_MENSUAL: TOPE_IMPONIBLE_MENSUAL[commercialYear],\n TRAMOS_IMPOSITIVOS: obtenerTramosImpositivos(UTA[commercialYear]),\n };\n}\n"],"names":[],"version":3,"file":"index.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;ACAA,4FAA4F;AAC5F,MAAM,4BAAM;IACV,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEA,iGAAiG;AACjG,MAAM,2BAAK;IACT,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEA,MAAM,kCAAY;IAChB,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEA,0FAA0F;AAC1F,MAAM,0CAAoB;IACxB,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAA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B;IAChD,MAAM,UAAE,MAAM,aAAE,SAAS,EAAE,GAAG,0CAAsB;IACpD,OAAO,SAAS,mBAAmB;AACrC;AAEO,SAAS,0CAAc,6BAA6B,EAAE,SAAS,EAAE,SAAS;IAC/E,OAAO,YAAY,YAAY;AACjC;AAEO,SAAS,0CAAS,aAAa;IACpC,MAAM,cAAc,KAAK;IACzB,MAAM,SAAS,0CAAe;IAC9B,MAAM,mBAAmB,cAAc;IACvC,MAAM,gCAAgC,0CAAiC;IACvE,MAAM,yBAAyB,0CAAiC,aAAa;IAC7E,MAAM,YAAY,0CAAkB;IACpC,MAAM,YAAY,0CAAkB;IACpC,MAAM,QAAQ,0CAAc,+BAA+B,WAAW;IACtE,MAAM,wBAAwB,0CAAc,wBAAwB,WAAW;IAC/E,OAAO;QACL,gBAAgB,6BAAO,eAAe;qBACtC;gBACA;0BACA;uCACA;gCACA;QACA,cAAc;YACZ,SAAS,0CAAoB,aAAa;YAC1C,OAAO,0CAAoB;QAC7B;mBACA;mBACA;eACA;+BACA;IACF;AACF","sources":["src/index.js","src/config.js"],"sourcesContent":["import { getConfig } from './config';\n\nconst OPERACION_RENTA_ACTUAL = 2025;\n\nconst config = getConfig(OPERACION_RENTA_ACTUAL);\n\n/**\n * Configura el año de la operación renta para los cálculos.\n * @param {Number} year - Año de la operación renta\n * @param {Object} [options] - Opciones de configuración\n * @param {Number} [options.uf] - Valor UF personalizado (por defecto usa el valor del año)\n */\nexport function configurarDeclaracion(year, options = {}) {\n const newConfig = getConfig(year, options);\n Object.keys(newConfig).forEach(key => {\n config[key] = newConfig[key];\n });\n}\n\nexport function obtenerConfiguracion() {\n return { ...config };\n}\n\nfunction min(a, b) {\n return a > b ? b : a;\n}\n\nexport function calcularGastos(rentaAnual) {\n const gastos = rentaAnual * 0.3;\n const tope = 15 * config.UTA;\n return min(gastos, tope);\n}\n\nconst COTIZACIONES_OBLIGATORIAS = [\n {\n name: \"Seguro de invalidez y sobrevivencia (SIS)\",\n percent: () => {\n // Esto cambia por año, no tengo seguridad de los años anteriores al 2022\n // Aunque el uso de esta librería es más actual que histórico (importa año comercial presente y anterior)\n // No me gusta que esto esté aquí, sin embargo, como hotfix está OK\n // https://www.spensiones.cl/portal/institucional/594/w3-propertyvalue-9917.html#recuadros_articulo_4130_0\n const SIS = {\n 2018: 1.99,\n 2019: 1.99,\n 2020: 1.99,\n 2021: 1.85,\n 2022: 1.54,\n 2023: 1.47,\n 2024: 1.49,\n 2025: 1.49,\n 2026: 1.5,\n };\n return SIS[config.OPERACION_RENTA - 1] || SIS[2023];\n },\n variable: false,\n },\n {\n name:\n \"Seguro de la ley de accidentes del trabajo y enfermedades profesionales (ATEP)\",\n percent: 0.90,\n variable: false,\n },\n {\n name: \"Seguro de acompañamiento niños y niñas (Ley SANNA)\",\n percent: 0.03, // https://www.chileatiende.gob.cl/fichas/53276-seguro-para-el-acompanamiento-de-ninos-y-ninas-afectados-por-una-condicion-grave-de-salud-ley-sanna\n variable: false,\n },\n {\n name: \"Salud\",\n percent: 7,\n variable: true,\n },\n {\n name: \"AFP\",\n percent: 10.49,\n variable: true,\n },\n];\n\nfunction getContributionPercentage(contribution) {\n return typeof contribution.percent === 'function' ? contribution.percent() : contribution.percent\n}\n\nexport function calcularSueldoImponible(sueldoAnual) {\n const topeAnual = config.TOPE_IMPONIBLE_MENSUAL * config.UF * 12;\n return min(0.8 * sueldoAnual, topeAnual);\n}\n\nexport function simularCotizaciones(ingresos, cotizacionParcial = false) {\n const sueldoImponible = calcularSueldoImponible(ingresos)\n\n if (cotizacionParcial) {\n const sueldoImponibleParcial = sueldoImponible * config.COBERTURA_PARCIAL\n\n return COTIZACIONES_OBLIGATORIAS.map(cotizacion => {\n const percent = getContributionPercentage(cotizacion)\n const monto = (cotizacion.variable ? sueldoImponibleParcial : sueldoImponible) * percent / 100\n return {\n name: cotizacion.name,\n percent,\n value: monto,\n }\n })\n } else {\n let remanente = calcularRetencion(sueldoImponible / 0.8)\n return COTIZACIONES_OBLIGATORIAS.map(cotizacion => {\n if (cotizacion.name === 'AFP') {\n const monto = min(remanente, sueldoImponible * getContributionPercentage(cotizacion) / 100)\n return {\n name: cotizacion.name,\n percent: 100 * monto / sueldoImponible,\n value: monto,\n }\n } else {\n const percent = getContributionPercentage(cotizacion)\n const monto = sueldoImponible * percent / 100\n remanente -= monto\n return {\n name: cotizacion.name,\n percent,\n value: monto,\n }\n }\n })\n }\n}\n\nexport function calcularCotizacionesObligatorias(ingresos, cotizacionParcial = false) {\n return simularCotizaciones(ingresos, cotizacionParcial).reduce((total, cotizacion) => {\n return total + cotizacion.value;\n }, 0)\n}\n\nexport function calcularRetencion(sueldoAnual) {\n return sueldoAnual * config.RETENCION;\n}\n\nexport function buscarTramoImpositivo(sueldoTributable) {\n return config.TRAMOS_IMPOSITIVOS.find(({ montoMaximo }) => sueldoTributable <= montoMaximo);\n}\n\nexport function calcularImpuestos(sueldoTributable) {\n const { factor, descuento } = buscarTramoImpositivo(sueldoTributable);\n return factor * sueldoTributable - descuento;\n}\n\nexport function calcularDeuda(montoCotizacionesObligatorias, impuestos, retencion) {\n return impuestos - retencion + montoCotizacionesObligatorias;\n}\n\nexport function calcular(sueldoMensual) {\n const sueldoAnual = 12 * sueldoMensual;\n const gastos = calcularGastos(sueldoAnual);\n const sueldoTributable = sueldoAnual - gastos;\n const montoCotizacionesObligatorias = calcularCotizacionesObligatorias(sueldoAnual);\n const montoCotizacionParcial = calcularCotizacionesObligatorias(sueldoAnual, true);\n const retencion = calcularRetencion(sueldoAnual);\n const impuestos = calcularImpuestos(sueldoTributable);\n const deuda = calcularDeuda(montoCotizacionesObligatorias, impuestos, retencion);\n const deudaModalidadParcial = calcularDeuda(montoCotizacionParcial, impuestos, retencion);\n return {\n operacionRenta: config.OPERACION_RENTA,\n sueldoAnual,\n gastos,\n sueldoTributable,\n montoCotizacionesObligatorias,\n montoCotizacionParcial,\n cotizaciones: {\n parcial: simularCotizaciones(sueldoAnual, true),\n total: simularCotizaciones(sueldoAnual),\n },\n retencion,\n impuestos,\n deuda,\n deudaModalidadParcial,\n };\n}\n","// Valor UTA en diciembre en https://www.sii.cl/valores_y_fechas/index_valores_y_fechas.html\nconst UTA = {\n 2018: 580236,\n 2019: 595476,\n 2020: 612348,\n 2021: 650052,\n 2022: 733884,\n 2023: 770592,\n 2024: 807528,\n 2025: 834504,\n 2026: 837012, // 2026-01\n};\n\n// Valor UF al 31 de diciembre en https://www.sii.cl/valores_y_fechas/index_valores_y_fechas.html\nconst UF = {\n 2018: 27565.79,\n 2019: 28309.94,\n 2020: 29070.33,\n 2021: 30991.74,\n 2022: 35110.98,\n 2023: 36789.36,\n 2024: 38416.69,\n 2025: 39727.96,\n 2026: 39706.07, // 2026-01-31\n};\n\nconst RETENCION = {\n 2019: 10,\n 2020: 10.75,\n 2021: 11.5,\n 2022: 12.25,\n 2023: 13,\n 2024: 13.75,\n 2025: 14.5,\n 2026: 15.25,\n 2027: 16,\n 2028: 17,\n};\n\n// Artículo Segundo de la Ley 21.133 (https://www.bcn.cl/leychile/navegar?idNorma=1128420)\nconst COBERTURA_PARCIAL = {\n 2018: 5,\n 2019: 17,\n 2020: 27,\n 2021: 37,\n 2022: 47,\n 2023: 57,\n 2024: 70,\n 2025: 80,\n 2026: 90,\n 2027: 100,\n 2028: 100,\n};\n\nconst TOPE_IMPONIBLE_MENSUAL = {\n 2018: 78.3, // https://www.spensiones.cl/portal/institucional/594/w3-article-12946.html\n 2019: 79.2, // https://www.spensiones.cl/portal/institucional/594/w3-article-13553.html\n 2020: 80.2, // https://www.spensiones.cl/portal/institucional/594/w3-article-13843.html\n 2021: 81.6, // https://www.spensiones.cl/portal/institucional/594/w3-article-14366.html\n 2022: 81.6, // https://www.spensiones.cl/portal/institucional/594/w3-article-15178.html\n 2023: 81.6, // https://www.spensiones.cl/portal/institucional/594/w3-article-15486.html\n 2024: 84.3, // https://www.spensiones.cl/portal/institucional/594/w3-article-15855.html\n 2025: 87.8, // https://www.spensiones.cl/portal/institucional/594/w3-article-16252.html\n 2026: 89.9, // https://www.spensiones.cl/portal/institucional/594/w3-article-16885.html\n};\n\n/**\n * Calculates and returns tax brackets based on the provided UTA value.\n *\n * @param {Number} uta - The UTA value for which tax brackets are to be calculated.\n * @returns {Array.<{factor: Number, montoMaximo: Number, descuento: Number}>}\n * An array of objects, each containing:\n * - `factor`: The tax rate for the bracket.\n * - `montoMaximo`: The maximum amount for the bracket.\n * - `descuento`: The discount for the bracket.\n * \n * @example\n * const tramos = obtenerTramosImpositivos(1.5);\n * console.log(tramos); // Output will be an array of tax bracket objects.\n */\nfunction obtenerTramosImpositivos(uta) {\n const maxValue = Number.MAX_VALUE;\n return [\n [13.5 * uta, 0, 0],\n [ 30 * uta, 0.04, 0.54 * uta],\n [ 50 * uta, 0.08, 1.74 * uta],\n [ 70 * uta, 0.135, 4.49 * uta],\n [ 90 * uta, 0.23, 11.14 * uta],\n [ 120 * uta, 0.304, 17.8 * uta],\n [ 310 * uta, 0.35, 23.32 * uta],\n [ maxValue, 0.4, 38.82 * uta],\n ].map(([montoMaximo, factor, descuento]) => ({\n factor,\n montoMaximo,\n descuento,\n }));\n}\n\n/**\n * Retrieves the configuration for a given \"operacionRenta\" year.\n *\n * @param {Number} operacionRenta - The year for which the operation configuration is required.\n * @param {Object} [options] - Optional configuration overrides.\n * @param {Number} [options.uf] - Custom UF value to use instead of the default for the year.\n * @throws {Error} Throws an error if the given year is not available.\n * @returns {{\n * OPERACION_RENTA: Number,\n * UTA: Number,\n * UF: Number,\n * RETENCION: Number,\n * COBERTURA_PARCIAL: Number,\n * TOPE_IMPONIBLE_MENSUAL: Number,\n * TRAMOS_IMPOSITIVOS: Array.<{factor: number, montoMaximo: number, descuento: number}>\n * }}\n * An object containing various configuration values:\n * - `OPERACION_RENTA`: The year for which the configuration is valid.\n * - `UTA`: The UTA value for the given year (December).\n * - `UF`: The UF value for the given year (last day of December), or custom value if provided.\n * - `RETENCION`: The retention percentage for the given year.\n * - `COBERTURA_PARCIAL`: The partial coverage percentage for the given year.\n * - `TOPE_IMPONIBLE_MENSUAL`: The monthly taxable income cap for the given year.\n * - `TRAMOS_IMPOSITIVOS`: An array of objects, each containing:\n * - `factor`: The tax rate for the bracket.\n * - `montoMaximo`: The maximum amount for the bracket.\n * - `descuento`: The discount for the bracket.\n *\n * @example\n * const config = getConfig(2022);\n * console.log(config.OPERACION_RENTA); // 2022\n *\n * @example\n * // With custom UF value\n * const config = getConfig(2025, { uf: 40000 });\n * console.log(config.UF); // 40000\n*/\nexport function getConfig(operacionRenta, options = {}) {\n const commercialYear = operacionRenta - 1;\n\n if (!TOPE_IMPONIBLE_MENSUAL[commercialYear]) {\n const validos = Object.keys(TOPE_IMPONIBLE_MENSUAL).map(year => parseInt(year) + 1).join(', ');\n throw new Error(`El año ingresado es incorrecto. Los valores válidos son: ${validos}`);\n }\n\n const ufValue = options.uf !== undefined ? options.uf : UF[commercialYear];\n\n return {\n OPERACION_RENTA: operacionRenta,\n UTA: UTA[commercialYear],\n UF: ufValue,\n RETENCION: RETENCION[commercialYear] / 100,\n COBERTURA_PARCIAL: COBERTURA_PARCIAL[commercialYear] / 100,\n TOPE_IMPONIBLE_MENSUAL: TOPE_IMPONIBLE_MENSUAL[commercialYear],\n TRAMOS_IMPOSITIVOS: obtenerTramosImpositivos(UTA[commercialYear]),\n };\n}\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/package.json
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
name: Publish to NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [main]
|
|
6
|
-
|
|
7
|
-
permissions:
|
|
8
|
-
id-token: write
|
|
9
|
-
contents: write
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
publish:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v4
|
|
16
|
-
|
|
17
|
-
- uses: actions/setup-node@v4
|
|
18
|
-
with:
|
|
19
|
-
node-version: 22
|
|
20
|
-
registry-url: https://registry.npmjs.org
|
|
21
|
-
|
|
22
|
-
- run: npm install -g npm@latest
|
|
23
|
-
- run: npm ci
|
|
24
|
-
|
|
25
|
-
- name: Check if version changed
|
|
26
|
-
id: version
|
|
27
|
-
run: |
|
|
28
|
-
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
|
29
|
-
NPM_VERSION=$(npm view tax-cl version 2>/dev/null || echo "0.0.0")
|
|
30
|
-
if [ "$PACKAGE_VERSION" = "$NPM_VERSION" ]; then
|
|
31
|
-
echo "changed=false" >> "$GITHUB_OUTPUT"
|
|
32
|
-
else
|
|
33
|
-
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
34
|
-
echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
|
|
35
|
-
fi
|
|
36
|
-
|
|
37
|
-
- name: Build
|
|
38
|
-
if: steps.version.outputs.changed == 'true'
|
|
39
|
-
run: npx parcel build
|
|
40
|
-
|
|
41
|
-
- name: Publish
|
|
42
|
-
if: steps.version.outputs.changed == 'true'
|
|
43
|
-
run: npm publish
|
|
44
|
-
|
|
45
|
-
- name: Create git tag
|
|
46
|
-
if: steps.version.outputs.changed == 'true'
|
|
47
|
-
run: |
|
|
48
|
-
git tag "v${{ steps.version.outputs.version }}"
|
|
49
|
-
git push origin "v${{ steps.version.outputs.version }}"
|