bdpformulas 1.0.50 → 1.0.51

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.
@@ -1,6 +1,7 @@
1
- import { ProyeccionPrestamo } from "../../../models/eeff/admFinanciera";
2
- export type Frecuencia = "ANUAL" | "BIMENSUAL" | "CUATRIMESTRAL" | "MENSUAL" | "SEMESTRAL" | "TRIMESTRAL";
3
- export type TipoCuota = "FIJA" | "VARIABLE" | "CORTOPLAZO";
1
+ import { DateTime } from 'luxon';
2
+ import { ProyeccionPrestamo } from '../../../models/eeff/admFinanciera';
3
+ export type Frecuencia = 'ANUAL' | 'BIMENSUAL' | 'CUATRIMESTRAL' | 'MENSUAL' | 'SEMESTRAL' | 'TRIMESTRAL';
4
+ export type TipoCuota = 'FIJA' | 'VARIABLE' | 'CORTOPLAZO';
4
5
  export declare const frecuenciaMeses: Record<Frecuencia, number>;
5
6
  interface SimuladorParametros {
6
7
  monto: number;
@@ -57,7 +58,7 @@ export declare function ourParseFloat(num: any, round?: boolean): number;
57
58
  * @param params.tolerancia - Precisión deseada para el resultado (por defecto: 1e-6).
58
59
  * @returns La tasa de interés periódica como decimal o undefined si no converge.
59
60
  */
60
- export declare function calcularTasaInteres({ meses, montoCuota, montoOriginal, guess, maxIteraciones, tolerancia, }: {
61
+ export declare function calcularTasaInteres({ meses, montoCuota, montoOriginal, guess, maxIteraciones, tolerancia }: {
61
62
  meses: number;
62
63
  montoCuota: number;
63
64
  montoOriginal: number;
@@ -79,18 +80,19 @@ interface GeneratePlazosParams {
79
80
  valor?: number;
80
81
  }
81
82
  export declare function generatePlazos({ inicio, cantidadProyeccion, valor }: GeneratePlazosParams): Partial<ProyeccionPrestamo>;
82
- export declare function calcularPagoPrincipalEntre({ tasaPeriodica, numeroPagos, montoPrestamo, periodoInicial, periodoFinal, }: {
83
+ export declare function calcularPagoPrincipalEntre({ tasaPeriodica, numeroPagos, montoPrestamo, periodoInicial, periodoFinal }: {
83
84
  tasaPeriodica: number;
84
85
  numeroPagos: number;
85
86
  montoPrestamo: number;
86
87
  periodoInicial?: number;
87
88
  periodoFinal: number;
88
89
  }): number;
89
- export declare function calcularPagoInteresEntre({ tasaPeriodica, numeroPagos, montoPrestamo, periodoInicial, periodoFinal, }: {
90
+ export declare function calcularPagoInteresEntre({ tasaPeriodica, numeroPagos, montoPrestamo, periodoInicial, periodoFinal }: {
90
91
  tasaPeriodica: number;
91
92
  numeroPagos: number;
92
93
  montoPrestamo: number;
93
94
  periodoInicial?: number;
94
95
  periodoFinal: number;
95
96
  }): number;
97
+ export declare function getDateTime(date: string | Date): DateTime<true> | DateTime<false>;
96
98
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calcularPagoInteresEntre = exports.calcularPagoPrincipalEntre = exports.generatePlazos = exports.sumCorrelativeKeys = exports.getColumnSum = exports.calcularTasaInteres = exports.ourParseFloat = exports.calcularPorcionCorrientePagada = exports.simuladorCuotas = exports.frecuenciaMeses = void 0;
3
+ exports.getDateTime = exports.calcularPagoInteresEntre = exports.calcularPagoPrincipalEntre = exports.generatePlazos = exports.sumCorrelativeKeys = exports.getColumnSum = exports.calcularTasaInteres = exports.ourParseFloat = exports.calcularPorcionCorrientePagada = exports.simuladorCuotas = exports.frecuenciaMeses = void 0;
4
4
  const luxon_1 = require("luxon");
5
5
  exports.frecuenciaMeses = {
6
6
  MENSUAL: 1,
@@ -8,7 +8,7 @@ exports.frecuenciaMeses = {
8
8
  TRIMESTRAL: 3,
9
9
  CUATRIMESTRAL: 4,
10
10
  SEMESTRAL: 6,
11
- ANUAL: 12,
11
+ ANUAL: 12
12
12
  };
13
13
  function simuladorCuotas({ monto, plazo, frecuencia, tipoCuota, periodoGracia = 0, tasaInteres = 0, polizaSD = 0, plazoMeses = false }) {
14
14
  const mesesPorFrecuencia = exports.frecuenciaMeses[frecuencia];
@@ -23,22 +23,26 @@ function simuladorCuotas({ monto, plazo, frecuencia, tipoCuota, periodoGracia =
23
23
  let cuotaAnual = 0;
24
24
  let anioActual = 1;
25
25
  // Calcular cuota fija si aplica
26
- const cuotaFija = tipoCuota === "FIJA"
27
- ? (monto * tasaPorPeriodo) / (1 - Math.pow(1 + tasaPorPeriodo, -cuotasTotales))
26
+ const cuotaFija = tipoCuota === 'FIJA'
27
+ ? (monto * tasaPorPeriodo) /
28
+ (1 - Math.pow(1 + tasaPorPeriodo, -cuotasTotales))
28
29
  : 0;
29
30
  for (let i = 1; i <= cuotasTotales; i++) {
30
31
  let amortizacion = 0;
31
32
  let interes = 0;
32
33
  let cuotaCredito = 0;
33
- let tiempoDias = mesesPorFrecuencia * 30; // Aproximado.
34
+ const tiempoDias = mesesPorFrecuencia * 30; // Aproximado.
34
35
  if (i > Math.ceil(periodoGracia / mesesPorFrecuencia)) {
35
36
  interes = saldoCapital * tasaPorPeriodo;
36
- if (tipoCuota === "FIJA") {
37
+ if (tipoCuota === 'FIJA') {
37
38
  cuotaCredito = cuotaFija;
38
39
  amortizacion = cuotaCredito - interes;
39
40
  }
40
41
  else {
41
- amortizacion = monto / (cuotasTotales - Math.ceil(periodoGracia / mesesPorFrecuencia));
42
+ amortizacion =
43
+ monto /
44
+ (cuotasTotales -
45
+ Math.ceil(periodoGracia / mesesPorFrecuencia));
42
46
  cuotaCredito = amortizacion + interes;
43
47
  }
44
48
  }
@@ -51,7 +55,7 @@ function simuladorCuotas({ monto, plazo, frecuencia, tipoCuota, periodoGracia =
51
55
  poliza: polizaSD,
52
56
  cuotaTotal,
53
57
  saldoCapital,
54
- tiempoDias,
58
+ tiempoDias
55
59
  });
56
60
  saldoCapital -= amortizacion;
57
61
  // Acumular valores anuales
@@ -64,7 +68,7 @@ function simuladorCuotas({ monto, plazo, frecuencia, tipoCuota, periodoGracia =
64
68
  anio: anioActual,
65
69
  capitalAnual,
66
70
  interesAnual,
67
- cuotaAnual,
71
+ cuotaAnual
68
72
  });
69
73
  anioActual++;
70
74
  capitalAnual = 0;
@@ -76,8 +80,8 @@ function simuladorCuotas({ monto, plazo, frecuencia, tipoCuota, periodoGracia =
76
80
  }
77
81
  exports.simuladorCuotas = simuladorCuotas;
78
82
  function calcularPorcionCorrientePagada({ fechaDesembolso, fechaInicial, frecuencia, simulador }) {
79
- const inicial = luxon_1.DateTime.fromISO(fechaInicial);
80
- const desembolso = luxon_1.DateTime.fromISO(fechaDesembolso);
83
+ const inicial = getDateTime(fechaInicial).endOf('month');
84
+ const desembolso = getDateTime(fechaDesembolso).endOf('month');
81
85
  const mesesPorFrecuencia = exports.frecuenciaMeses[frecuencia];
82
86
  const mesesTranscurridos = inicial.diff(desembolso, 'months').months;
83
87
  const cuotasPagadas = Math.floor(mesesTranscurridos / mesesPorFrecuencia);
@@ -85,7 +89,7 @@ function calcularPorcionCorrientePagada({ fechaDesembolso, fechaInicial, frecuen
85
89
  const porcionCorrientePagada = cuotasPagadasArray.reduce((acumulado, cuota) => acumulado + cuota.amortizacion, 0);
86
90
  return {
87
91
  cuotasPagadas: cuotasPagadasArray.length,
88
- porcionCorrientePagada,
92
+ porcionCorrientePagada
89
93
  };
90
94
  }
91
95
  exports.calcularPorcionCorrientePagada = calcularPorcionCorrientePagada;
@@ -93,8 +97,7 @@ function ourParseFloat(num, round = true) {
93
97
  let parsed = parseFloat(num);
94
98
  if (isNaN(parsed))
95
99
  parsed = 0;
96
- if (round)
97
- parsed = parseFloat(parsed.toFixed(2));
100
+ //if (round) parsed = parseFloat(parsed.toFixed(2))
98
101
  return parsed;
99
102
  }
100
103
  exports.ourParseFloat = ourParseFloat;
@@ -110,7 +113,7 @@ exports.ourParseFloat = ourParseFloat;
110
113
  * @param params.tolerancia - Precisión deseada para el resultado (por defecto: 1e-6).
111
114
  * @returns La tasa de interés periódica como decimal o undefined si no converge.
112
115
  */
113
- function calcularTasaInteres({ meses, montoCuota, montoOriginal, guess = 0.1, maxIteraciones = 100, tolerancia = 1e-10, }) {
116
+ function calcularTasaInteres({ meses, montoCuota, montoOriginal, guess = 0.1, maxIteraciones = 100, tolerancia = 1e-10 }) {
114
117
  let tasa = guess;
115
118
  for (let i = 0; i < maxIteraciones; i++) {
116
119
  let f = 0; // Función objetivo f(x)
@@ -118,7 +121,7 @@ function calcularTasaInteres({ meses, montoCuota, montoOriginal, guess = 0.1, ma
118
121
  for (let j = 1; j <= meses; j++) {
119
122
  const factor = Math.pow(1 + tasa, -j);
120
123
  f += montoCuota * factor;
121
- fDerivada += -j * montoCuota * factor / (1 + tasa);
124
+ fDerivada += (-j * montoCuota * factor) / (1 + tasa);
122
125
  }
123
126
  // Sumar flujo inicial (monto original)
124
127
  f += montoOriginal;
@@ -140,7 +143,7 @@ exports.getColumnSum = getColumnSum;
140
143
  function sumCorrelativeKeys(params) {
141
144
  const { baseKey, endIndex, startIndex = 1, data } = params;
142
145
  if (endIndex < startIndex) {
143
- throw new Error("El índice final no puede ser menor que el índice inicial.");
146
+ throw new Error('El índice final no puede ser menor que el índice inicial.');
144
147
  }
145
148
  let sum = 0;
146
149
  for (let i = startIndex; i <= endIndex; i++) {
@@ -171,7 +174,7 @@ function generatePlazos({ inicio, cantidadProyeccion, valor }) {
171
174
  return plazos;
172
175
  }
173
176
  exports.generatePlazos = generatePlazos;
174
- function calcularPagoPrincipalEntre({ tasaPeriodica, numeroPagos, montoPrestamo, periodoInicial = 1, periodoFinal, }) {
177
+ function calcularPagoPrincipalEntre({ tasaPeriodica, numeroPagos, montoPrestamo, periodoInicial = 1, periodoFinal }) {
175
178
  // Cálculo de la cuota fija periódica (PMT)
176
179
  const cuota = (tasaPeriodica * montoPrestamo) /
177
180
  (1 - Math.pow(1 + tasaPeriodica, -numeroPagos));
@@ -189,7 +192,7 @@ function calcularPagoPrincipalEntre({ tasaPeriodica, numeroPagos, montoPrestamo,
189
192
  return totalCapitalAmortizado;
190
193
  }
191
194
  exports.calcularPagoPrincipalEntre = calcularPagoPrincipalEntre;
192
- function calcularPagoInteresEntre({ tasaPeriodica, numeroPagos, montoPrestamo, periodoInicial = 1, periodoFinal, }) {
195
+ function calcularPagoInteresEntre({ tasaPeriodica, numeroPagos, montoPrestamo, periodoInicial = 1, periodoFinal }) {
193
196
  // Cálculo de la cuota fija periódica (PMT)
194
197
  const cuota = (tasaPeriodica * montoPrestamo) /
195
198
  (1 - Math.pow(1 + tasaPeriodica, -numeroPagos));
@@ -207,3 +210,9 @@ function calcularPagoInteresEntre({ tasaPeriodica, numeroPagos, montoPrestamo, p
207
210
  return totalInteresesPagados; // Devuelve el valor negativo para igualar el comportamiento de Excel
208
211
  }
209
212
  exports.calcularPagoInteresEntre = calcularPagoInteresEntre;
213
+ function getDateTime(date) {
214
+ return date instanceof Date
215
+ ? luxon_1.DateTime.fromJSDate(date, { zone: 'utc' })
216
+ : luxon_1.DateTime.fromISO(date, { zone: 'utc' });
217
+ }
218
+ exports.getDateTime = getDateTime;
@@ -1,5 +1,5 @@
1
- import { AdministracionFinancieraCalcData, AdministracionFinancieraData } from "../../models/eeff/admFinanciera";
2
- import { Strategy } from "../../strategy.interface";
1
+ import { AdministracionFinancieraCalcData, AdministracionFinancieraData } from '../../models/eeff/admFinanciera';
2
+ import { Strategy } from '../../strategy.interface';
3
3
  export default class AdmFinancieraStrategy implements Strategy {
4
4
  data: AdministracionFinancieraCalcData | null;
5
5
  constructor();
@@ -22,7 +22,7 @@ class AdmFinancieraStrategy {
22
22
  ...cloned,
23
23
  ProyeccionPrestamosDirectos: cloned.ProyeccionPrestamosDirectos ?? [],
24
24
  ProyeccionAplicaciones: [],
25
- ProyeccionPrestamosBajoLineas: [],
25
+ ProyeccionPrestamosBajoLineas: []
26
26
  };
27
27
  this.formatPrestamosDirectos();
28
28
  this.formatPrestamosBajoLinea();
@@ -35,9 +35,10 @@ class AdmFinancieraStrategy {
35
35
  return this.data;
36
36
  }
37
37
  formatPrestamosDirectos() {
38
+ const prestamos = this.data.PrestamoDirecto.filter((pr) => pr.IndicadorABM !== 'B');
38
39
  let totalMontoOriginal = 0;
39
40
  let totalPorcionPagada = 0;
40
- this.data.PrestamoDirecto.forEach(prestamo => {
41
+ prestamos.forEach((prestamo) => {
41
42
  const handled = new prestamoDirectoHandler_1.PrestamoDirectoHandler({
42
43
  prestamo,
43
44
  data: this.data
@@ -45,37 +46,43 @@ class AdmFinancieraStrategy {
45
46
  totalMontoOriginal += (0, utils_1.ourParseFloat)(handled.MontoOriginal);
46
47
  totalPorcionPagada += (0, utils_1.ourParseFloat)(handled.PorcionPagada);
47
48
  });
48
- this.data?.PrestamoDirecto.push({
49
- Descripcion: 'TOTAL PRÉSTAMOS AMORTIZABLES BS',
50
- MontoOriginal: totalMontoOriginal,
51
- PorcionPagada: totalPorcionPagada,
52
- Clasificador: 'T'
53
- });
49
+ if (prestamos.length)
50
+ this.data?.PrestamoDirecto.push({
51
+ Descripcion: 'TOTAL PRÉSTAMOS AMORTIZABLES BS',
52
+ MontoOriginal: totalMontoOriginal,
53
+ PorcionPagada: totalPorcionPagada,
54
+ Clasificador: 'T'
55
+ });
54
56
  }
55
57
  formatPrestamosBajoLinea() {
56
- let totalMonto = this.data.PrestamoBajoLinea.reduce((acc, curr) => acc + (0, utils_1.ourParseFloat)(curr.MontoOriginal), 0);
58
+ const prestamos = this.data.PrestamoBajoLinea.filter((pr) => pr.IndicadorABM !== 'B');
59
+ const totalMonto = prestamos.reduce((acc, curr) => acc + (0, utils_1.ourParseFloat)(curr.MontoOriginal), 0);
57
60
  let totalMontoUtilizado = 0;
58
61
  let totalTasaPonderada = 0;
59
62
  let totalSaldoLinea = 0;
60
- this.data.PrestamoBajoLinea.forEach(prestamo => {
63
+ prestamos.forEach((prestamo) => {
61
64
  const handled = new prestamoBajoLineaHandler_1.PrestamoBajoLineaHandler(prestamo, this.data).handle();
62
65
  totalMontoUtilizado += (0, utils_1.ourParseFloat)(handled.MontoUtilizado);
63
- totalTasaPonderada += (0, utils_1.ourParseFloat)(handled.TasaPonderada);
66
+ totalTasaPonderada += (0, utils_1.ourParseFloat)(handled.TasaPonderada, false);
64
67
  totalSaldoLinea += (0, utils_1.ourParseFloat)(handled.SaldoLineaAplicar);
65
68
  });
66
- this.data?.PrestamoBajoLinea.push({
67
- Descripcion: 'TOTAL LÍNEA DE CRÉDITO BS',
68
- MontoOriginal: totalMonto,
69
- MontoUtilizado: totalMontoUtilizado,
70
- TasaPonderada: totalTasaPonderada,
71
- SaldoLineaAplicar: totalSaldoLinea,
72
- Clasificador: 'T'
73
- });
69
+ if (prestamos.length)
70
+ this.data?.PrestamoBajoLinea.push({
71
+ Descripcion: 'TOTAL LÍNEA DE CRÉDITO BS',
72
+ MontoOriginal: totalMonto,
73
+ MontoUtilizado: totalMontoUtilizado,
74
+ TasaPonderada: totalTasaPonderada,
75
+ SaldoLineaAplicar: totalSaldoLinea,
76
+ Clasificador: 'T'
77
+ });
74
78
  }
75
79
  setProyeccionesBajoLinea() {
76
- const filaTotales = this.data.PrestamoBajoLinea.find(pr => pr.Clasificador == 'T');
77
- const totalTasaPonderada = (0, utils_1.ourParseFloat)(filaTotales?.TasaPonderada) / 100;
78
- const proyecciones = this.data.PrestamoBajoLinea.map(pr => ({
80
+ const prestamos = this.data.PrestamoBajoLinea.filter((pr) => pr.IndicadorABM !== 'B');
81
+ const filaTotales = prestamos.find((pr) => pr.Clasificador == 'T');
82
+ const totalTasaPonderada = (0, utils_1.ourParseFloat)(filaTotales?.TasaPonderada, false) / 100;
83
+ const proyecciones = prestamos
84
+ .filter((pr) => pr.Clasificador !== 'T')
85
+ .map((pr) => ({
79
86
  Descripcion: pr.Descripcion,
80
87
  ...pr.Proyecciones
81
88
  }));
@@ -87,8 +94,10 @@ class AdmFinancieraStrategy {
87
94
  for (let i = 1; i <= this.data.CantidadProyeccion; i++) {
88
95
  let value;
89
96
  if (i == 1) {
90
- const primeraFila = this.data.PrestamoBajoLinea.at(0);
91
- value = (0, utils_1.ourParseFloat)(primeraFila?.MontoUtilizado) * totalTasaPonderada;
97
+ const primeraFila = prestamos.at(0);
98
+ value =
99
+ (0, utils_1.ourParseFloat)(primeraFila?.MontoUtilizado) *
100
+ totalTasaPonderada;
92
101
  }
93
102
  else {
94
103
  const sumaColumnaAnterior = (0, utils_1.getColumnSum)(proyecciones, `Gestion${i - 1}`);
@@ -100,28 +109,33 @@ class AdmFinancieraStrategy {
100
109
  this.data.ProyeccionPrestamosBajoLineas = proyecciones;
101
110
  }
102
111
  formatPrestamosLeasing() {
112
+ const prestamos = this.data.PrestamoLeasing.filter((pr) => pr.IndicadorABM !== 'B');
103
113
  let totalMonto = 0;
104
114
  let totalCuotaPeriodo = 0;
105
115
  let totalAporteInicial = 0;
106
116
  let totalValorResidual = 0;
107
117
  let totalValorBien = 0;
108
- this.data.PrestamoLeasing.forEach(prestamo => {
109
- const handled = new prestamoLeasingHandler_1.PrestamoLeasingHandler({ data: this.data, prestamo }).handle();
118
+ prestamos.forEach((prestamo) => {
119
+ const handled = new prestamoLeasingHandler_1.PrestamoLeasingHandler({
120
+ data: this.data,
121
+ prestamo
122
+ }).handle();
110
123
  totalMonto += (0, utils_1.ourParseFloat)(handled.MontoOriginal);
111
124
  totalCuotaPeriodo += (0, utils_1.ourParseFloat)(handled.MontoCuotaPeriodo);
112
125
  totalAporteInicial += (0, utils_1.ourParseFloat)(handled.MontoAporteInicial);
113
126
  totalValorResidual += (0, utils_1.ourParseFloat)(handled.MontoValorResidual);
114
127
  totalValorBien += (0, utils_1.ourParseFloat)(handled.MontoValorBien);
115
128
  });
116
- this.data?.PrestamoLeasing.push({
117
- Descripcion: 'TOTAL LEASING BS',
118
- MontoOriginal: totalMonto,
119
- MontoCuotaPeriodo: totalCuotaPeriodo,
120
- MontoAporteInicial: totalAporteInicial,
121
- MontoValorResidual: totalValorResidual,
122
- MontoValorBien: totalValorBien,
123
- Clasificador: 'T'
124
- });
129
+ if (prestamos.length)
130
+ this.data?.PrestamoLeasing.push({
131
+ Descripcion: 'TOTAL LEASING BS',
132
+ MontoOriginal: totalMonto,
133
+ MontoCuotaPeriodo: totalCuotaPeriodo,
134
+ MontoAporteInicial: totalAporteInicial,
135
+ MontoValorResidual: totalValorResidual,
136
+ MontoValorBien: totalValorBien,
137
+ Clasificador: 'T'
138
+ });
125
139
  }
126
140
  formatLineasMixtas() {
127
141
  new lineasMixtasHandler_1.LineasMixtasHandler(this.data).handle();
@@ -0,0 +1 @@
1
+ export {};