creditu-common-library 1.2.22 → 1.3.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
@@ -24,7 +24,7 @@ Los services expuestos son:
24
24
  - `ConstantsService`: es un servicio auxiliar, que contiene funciones que calculan constantes que, a su vez, agrupan parametros conocidos para diversos propósitos en cálculos financieros.
25
25
  - `CreditInsuranceService`: este servicio tiene funciones de cálculo para el dominio `Seguros`.
26
26
  - `FinanceService`: este servicio auxiliar tiene funciones genéricas de funciones financieras, como interés anual, mensual, etc.
27
- - `InstallmentService`: este servicio tiene funciones de cálculo para el dominio `Dividendo`.
27
+ - `PaymentService`: este servicio tiene funciones de cálculo para el dominio `Dividendo`.
28
28
  - `LoanToValueService`: este servicio tiene funciones de cálculo para el dominio `LTV`.
29
29
  - `MaximumLocalService`: este servicio tiene funciones de cálculo para el dominio `Máximos Locales`.
30
30
  - `OfferService`: este servicio tiene funciones de cálculo para el dominio `Oferta`.
@@ -7,12 +7,4 @@ export declare class BalancesOutput {
7
7
  * Arreglo de montos darios de IPCA
8
8
  */
9
9
  balanceMonetaryUpdateValues: number[];
10
- /**
11
- * Arreglo de montos darios aplicando IPCA considerando el tope maximo de pago de IPCA pactado con el cliente
12
- */
13
- balanceUpperBoundMonetaryUpdateValues: number[];
14
- /**
15
- * Arreglo de montos diarios de IPCA que exceden el tope maximo de pago de IPCA pactado con el cliente
16
- */
17
- inflationaryBoundDifferenceValues: number[];
18
10
  }
@@ -14,6 +14,10 @@ export declare class DebtInputs {
14
14
  * Numero de cuota al que se le calcula la deuda
15
15
  */
16
16
  paymentNumber: PaymentNumber;
17
+ /**
18
+ * Numero de cuota al que se le calcula la deuda
19
+ */
20
+ isGraceMonth: boolean;
17
21
  /**
18
22
  * Numero de meses (cuotas) totales del credito
19
23
  */
@@ -89,11 +89,23 @@ export declare class DebtResponse {
89
89
  */
90
90
  lateDays: number;
91
91
  /**
92
- * Interés en la mora
92
+ * Multa por entrar en mora
93
+ */
94
+ lateCharges: number;
95
+ /**
96
+ * Cargo de mora por interés de la deuda
93
97
  */
94
98
  lateInterest: number;
99
+ /**
100
+ * Cargo de mora por inflación
101
+ */
102
+ lateAmortizationIPCA: number;
103
+ /**
104
+ * Cargo de mora por día de atraso
105
+ */
106
+ lateChargesInterest: number;
95
107
  /**
96
108
  * Cargo por mora
97
109
  */
98
- lateCharges: number;
110
+ lateRate: number;
99
111
  }
@@ -4,28 +4,29 @@ import { PaymentNumber } from '../../shared/models/payment-number';
4
4
  export declare class AmortizationService {
5
5
  private readonly math;
6
6
  constructor(math: MathService);
7
- private getPago;
8
- getAmortizationIPC(previousBalance: number, inflationaryUpperBound: number, amortizationDiff: number, IPCAupdate: number): number;
7
+ private readonly interestService;
8
+ private getMonthlyPayment;
9
+ getAmortizationIPC(upperBound: number, amortizationDiff: number, IPCAupdate: number): number;
9
10
  getAmortizationDiffGerman(previousBalance: number, balance: number, numberOfMonths: number): number;
10
11
  /**
11
12
  *
12
- * @param montlyRate Tasa mensual del crédito
13
+ * @param monthlyRate Tasa mensual del crédito
13
14
  * @param numberOfMonths Número de meses del crédito
14
15
  * @param previusBalance Balance anterior
15
16
  * @param balance Balance actual
16
- * @param paymentNumber Número del pago
17
+ * @param paymentNumber Número de cuota
17
18
  * @returns
18
19
  */
19
- getAmortizationDiffFrench(montlyRate: number, numberOfMonths: number, previusBalance: number, balance: number, paymentNumber: number): number;
20
+ getAmortizationDiffFrench(monthlyRate: number, numberOfMonths: number, previusBalance: number, balance: number, paymentNumber: number): number;
20
21
  /**
21
22
  *
22
- * @param montlyRate Tasa mensual del crédito
23
+ * @param monthlyRate Tasa mensual del crédito
23
24
  * @param numberOfMonths Número de meses del crédito
24
25
  * @param balance Balance actual
25
- * @param paymentNumber Número del pago
26
+ * @param paymentNumber Número de cuota
26
27
  * @returns
27
28
  */
28
- getAmortizationFrench(montlyRate: number, numberOfMonths: number, balance: number, paymentNumber: number): number;
29
+ getAmortizationFrench(monthlyRate: number, numberOfMonths: number, balance: number, paymentNumber: number): number;
29
30
  /**
30
31
  * Calcula la amortizacion
31
32
  * @param paymentNumber
@@ -33,4 +34,9 @@ export declare class AmortizationService {
33
34
  * @param balance
34
35
  */
35
36
  getAmortizationGerman(paymentNumber: PaymentNumber, numberOfMonths: NumberOfMonths, balance: number): number;
37
+ getAmortizationIUB(inputs: any, balance: any, annualRate: any): {
38
+ amortizationIUB: any;
39
+ amortizationDiff: any;
40
+ };
41
+ getAmortization(amortizationIUB: number, postponedInflationaryUpdate: number, amortizationDiff: number): number;
36
42
  }
@@ -3,64 +3,61 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AmortizationService = void 0;
4
4
  var math_1 = require("../../math");
5
5
  var guarder_1 = require("../../shared/models/guarder");
6
+ var models_1 = require("../../shared/models");
7
+ var interest_service_1 = require("./interest.service");
6
8
  var AmortizationService = /** @class */ (function () {
7
9
  function AmortizationService(math) {
8
10
  this.math = math;
11
+ this.interestService = new interest_service_1.InterestService(this.math);
9
12
  this.math = new math_1.MathService(true, 10);
10
13
  }
11
- AmortizationService.prototype.getPago = function (montlyRate, period, balance) {
12
- var a = Math.pow(this.math.add(1, montlyRate), period);
13
- var b = this.math.multiply(a, montlyRate);
14
- var c = this.math.subtract(a, 1);
15
- return this.math.multiply(this.math.divide(b, c), balance);
14
+ AmortizationService.prototype.getMonthlyPayment = function (monthlyRate, period, balance) {
15
+ var periodInterest = Math.pow(this.math.add(1, monthlyRate), period);
16
+ var interest = this.math.multiply(periodInterest, monthlyRate);
17
+ var periodRate = this.math.subtract(periodInterest, 1);
18
+ return this.math.multiply(this.math.divide(interest, periodRate), balance);
16
19
  };
17
- // previousBalance*inflationaryUpperBound - amortizationDiff
18
- AmortizationService.prototype.getAmortizationIPC = function (previousBalance, inflationaryUpperBound, amortizationDiff, IPCAupdate) {
19
- // const condition1 = previousBalance * inflationaryUpperBound > IPCAupdate;
20
- var condition1 = this.math.multiply(previousBalance, inflationaryUpperBound) > this.math.subtract(IPCAupdate, amortizationDiff); // IPCAupdate - amortizationDiff
21
- if (!condition1) {
22
- // se reestablece el dia 25-03-2022 tras reunion con thais y el equipo, volviendo a resta la diferencia de amortizacion para este caso.
23
- return this.math.round(this.math.subtract(this.math.multiply(previousBalance, inflationaryUpperBound), amortizationDiff), 2);
24
- // return this.math.round(this.math.multiply(previousBalance, inflationaryUpperBound), 2);
25
- }
26
- return this.math.subtract(IPCAupdate, amortizationDiff);
20
+ AmortizationService.prototype.getAmortizationIPC = function (upperBound, amortizationDiff, IPCAupdate) {
21
+ return this.math.round(upperBound < IPCAupdate
22
+ ? this.math.subtract(upperBound, amortizationDiff)
23
+ : this.math.subtract(IPCAupdate, amortizationDiff), 10);
27
24
  };
28
25
  // (balanceAfter - balance) / numberOfMonths
29
26
  AmortizationService.prototype.getAmortizationDiffGerman = function (previousBalance, balance, numberOfMonths) {
30
- return this.math.round(this.math.divide(this.math.subtract(balance, previousBalance), numberOfMonths), 2);
27
+ return this.math.round(this.math.divide(this.math.subtract(balance, previousBalance), numberOfMonths), 10);
31
28
  };
32
29
  /**
33
30
  *
34
- * @param montlyRate Tasa mensual del crédito
31
+ * @param monthlyRate Tasa mensual del crédito
35
32
  * @param numberOfMonths Número de meses del crédito
36
33
  * @param previusBalance Balance anterior
37
34
  * @param balance Balance actual
38
- * @param paymentNumber Número del pago
35
+ * @param paymentNumber Número de cuota
39
36
  * @returns
40
37
  */
41
- AmortizationService.prototype.getAmortizationDiffFrench = function (montlyRate, numberOfMonths, previusBalance, balance, paymentNumber) {
42
- var period = numberOfMonths + 1 - paymentNumber;
43
- var pago = this.getPago(montlyRate, period, balance);
44
- var interest = this.math.multiply(balance, montlyRate);
45
- var a = this.math.subtract(pago, interest);
46
- var previusPago = this.getPago(montlyRate, period, previusBalance);
47
- var previusInterest = this.math.multiply(previusBalance, montlyRate);
48
- var b = this.math.subtract(previusPago, previusInterest);
49
- return this.math.subtract(a, b);
38
+ AmortizationService.prototype.getAmortizationDiffFrench = function (monthlyRate, numberOfMonths, previusBalance, balance, paymentNumber) {
39
+ var period = this.math.subtract(this.math.add(numberOfMonths, 1), paymentNumber);
40
+ var initialMonthlyPayment = this.getMonthlyPayment(monthlyRate, period, previusBalance);
41
+ var initialInterest = this.math.multiply(previusBalance, monthlyRate);
42
+ var initialMonthlyAmortization = this.math.subtract(initialMonthlyPayment, initialInterest);
43
+ var finalMonthlyPayment = this.getMonthlyPayment(monthlyRate, period, balance);
44
+ var interest = this.math.multiply(balance, monthlyRate);
45
+ var finalMonthlyAmortization = this.math.subtract(finalMonthlyPayment, interest);
46
+ return this.math.subtract(finalMonthlyAmortization, initialMonthlyAmortization);
50
47
  };
51
48
  /**
52
49
  *
53
- * @param montlyRate Tasa mensual del crédito
50
+ * @param monthlyRate Tasa mensual del crédito
54
51
  * @param numberOfMonths Número de meses del crédito
55
52
  * @param balance Balance actual
56
- * @param paymentNumber Número del pago
53
+ * @param paymentNumber Número de cuota
57
54
  * @returns
58
55
  */
59
- AmortizationService.prototype.getAmortizationFrench = function (montlyRate, numberOfMonths, balance, paymentNumber) {
60
- var period = numberOfMonths + 1 - paymentNumber;
61
- var pago = this.getPago(montlyRate, period, balance);
62
- var interest = this.math.multiply(balance, montlyRate);
63
- return this.math.subtract(pago, interest);
56
+ AmortizationService.prototype.getAmortizationFrench = function (monthlyRate, numberOfMonths, balance, paymentNumber) {
57
+ var period = this.math.subtract(this.math.add(numberOfMonths, 1), paymentNumber);
58
+ var monthlyPayment = this.getMonthlyPayment(monthlyRate, period, balance);
59
+ var interest = this.math.multiply(balance, monthlyRate);
60
+ return this.math.subtract(monthlyPayment, interest);
64
61
  };
65
62
  /**
66
63
  * Calcula la amortizacion
@@ -77,6 +74,26 @@ var AmortizationService = /** @class */ (function () {
77
74
  var result = this.math.divide(balance, divisor);
78
75
  return result;
79
76
  };
77
+ AmortizationService.prototype.getAmortizationIUB = function (inputs, balance, annualRate) {
78
+ if (inputs.isGraceMonth) {
79
+ return { amortizationIUB: 0, amortizationDiff: 0 };
80
+ }
81
+ var amortizationIUB;
82
+ var amortizationDiff;
83
+ if (inputs.amortizationMethod === models_1.AmortizationMethod.GERMAN) {
84
+ amortizationIUB = this.getAmortizationGerman(inputs.paymentNumber, inputs.numberOfMonths, balance);
85
+ amortizationDiff = this.getAmortizationDiffGerman(inputs.previousBalance.value(), balance, inputs.numberOfMonths.value());
86
+ }
87
+ else if (inputs.amortizationMethod === models_1.AmortizationMethod.FRENCH) {
88
+ var monthlyRate = this.interestService.getMonthlyInterestValue(annualRate);
89
+ amortizationIUB = this.getAmortizationFrench(monthlyRate, inputs.numberOfMonths.value(), balance, inputs.paymentNumber.value());
90
+ amortizationDiff = this.getAmortizationDiffFrench(monthlyRate, inputs.numberOfMonths.value(), inputs.previousBalance.value(), balance, inputs.paymentNumber.value());
91
+ }
92
+ return { amortizationIUB: amortizationIUB, amortizationDiff: amortizationDiff };
93
+ };
94
+ AmortizationService.prototype.getAmortization = function (amortizationIUB, postponedInflationaryUpdate, amortizationDiff) {
95
+ return this.math.subtract(amortizationIUB, postponedInflationaryUpdate, amortizationDiff);
96
+ };
80
97
  return AmortizationService;
81
98
  }());
82
99
  exports.AmortizationService = AmortizationService;
@@ -10,7 +10,7 @@ export declare class BalanceService {
10
10
  * @param dailyInflationaryUpperBound
11
11
  * @param previousBalance
12
12
  */
13
- getBalances(dailyIPCAvalues: number[], dailyInflationaryUpperBound: number[], previousBalance: PreviousBalance): BalancesOutput;
13
+ getBalances(dailyIPCAvalues: number[], previousBalance: PreviousBalance): BalancesOutput;
14
14
  /**
15
15
  * Calcula el balance despues del pago
16
16
  * previousBalance + IPCAupdate - amortizationIPC -amortization
@@ -14,35 +14,25 @@ var BalanceService = /** @class */ (function () {
14
14
  * @param dailyInflationaryUpperBound
15
15
  * @param previousBalance
16
16
  */
17
- BalanceService.prototype.getBalances = function (dailyIPCAvalues, dailyInflationaryUpperBound, previousBalance) {
17
+ BalanceService.prototype.getBalances = function (dailyIPCAvalues, previousBalance) {
18
18
  var _this = this;
19
19
  if (dailyIPCAvalues === undefined || dailyIPCAvalues.length === 0)
20
20
  throw new Error('invalid dailyIPCAvalues on Balances calculation');
21
- if (dailyInflationaryUpperBound === undefined || dailyInflationaryUpperBound.length === 0)
22
- throw new Error('invalid dailyInflationaryUpperBound on Balances calculation');
23
21
  guarder_1.Guarder.defined(previousBalance, 'PreviousBalance');
24
22
  if (previousBalance.value() < 0)
25
23
  throw new Error('invalid previousBalance on Balances calculation');
26
24
  var balances = [previousBalance.value()];
27
25
  var balanceMonetaryUpdateValues = [];
28
- var balanceUpperBoundMonetaryUpdateValues = [];
29
- var inflationaryBoundDifferenceValues = [];
30
- dailyIPCAvalues.forEach(function (dailyIPCA, index) {
26
+ dailyIPCAvalues.forEach(function (dailyIPCA) {
31
27
  var previusBalanceUsed = balances[balances.length - 1];
32
28
  var balanceMonetaryUpdate = _this.math.multiply(dailyIPCA, previusBalanceUsed);
33
29
  balanceMonetaryUpdateValues.push(balanceMonetaryUpdate);
34
30
  balances.push(_this.math.add(balanceMonetaryUpdate, previusBalanceUsed));
35
- var balanceUpperBoundMonetaryUpdate = dailyInflationaryUpperBound[index] < dailyIPCA ? _this.math.multiply(previusBalanceUsed, dailyInflationaryUpperBound[index]) : 0;
36
- balanceUpperBoundMonetaryUpdateValues.push(balanceUpperBoundMonetaryUpdate);
37
- var inflationaryBoundDifference = balanceUpperBoundMonetaryUpdate ? _this.math.subtract(balanceMonetaryUpdate, balanceUpperBoundMonetaryUpdate) : 0;
38
- inflationaryBoundDifferenceValues.push(inflationaryBoundDifference);
39
31
  });
40
32
  balances.splice(0, 1);
41
33
  return {
42
34
  balances: balances,
43
- balanceMonetaryUpdateValues: balanceMonetaryUpdateValues,
44
- balanceUpperBoundMonetaryUpdateValues: balanceUpperBoundMonetaryUpdateValues,
45
- inflationaryBoundDifferenceValues: inflationaryBoundDifferenceValues
35
+ balanceMonetaryUpdateValues: balanceMonetaryUpdateValues
46
36
  };
47
37
  };
48
38
  /**
@@ -1,8 +1,8 @@
1
1
  import { AmortizationService } from './amortization-service';
2
2
  import { InsuranceService } from './insurance-service';
3
3
  import { IPCAService } from './ipca.service';
4
- import { PaymentService } from './payment-service';
4
+ import { MonthlyPaymentService } from './monthly-payment-service';
5
5
  import { InterestService } from './interest.service';
6
6
  import { InstallmentService } from './installment-service';
7
7
  import { LateService } from './late.service';
8
- export { AmortizationService, InsuranceService, IPCAService, PaymentService, InterestService, InstallmentService, LateService };
8
+ export { AmortizationService, InsuranceService, IPCAService, MonthlyPaymentService, InterestService, InstallmentService, LateService };
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LateService = exports.InstallmentService = exports.InterestService = exports.PaymentService = exports.IPCAService = exports.InsuranceService = exports.AmortizationService = void 0;
3
+ exports.LateService = exports.InstallmentService = exports.InterestService = exports.MonthlyPaymentService = exports.IPCAService = exports.InsuranceService = exports.AmortizationService = void 0;
4
4
  var amortization_service_1 = require("./amortization-service");
5
5
  Object.defineProperty(exports, "AmortizationService", { enumerable: true, get: function () { return amortization_service_1.AmortizationService; } });
6
6
  var insurance_service_1 = require("./insurance-service");
7
7
  Object.defineProperty(exports, "InsuranceService", { enumerable: true, get: function () { return insurance_service_1.InsuranceService; } });
8
8
  var ipca_service_1 = require("./ipca.service");
9
9
  Object.defineProperty(exports, "IPCAService", { enumerable: true, get: function () { return ipca_service_1.IPCAService; } });
10
- var payment_service_1 = require("./payment-service");
11
- Object.defineProperty(exports, "PaymentService", { enumerable: true, get: function () { return payment_service_1.PaymentService; } });
10
+ var monthly_payment_service_1 = require("./monthly-payment-service");
11
+ Object.defineProperty(exports, "MonthlyPaymentService", { enumerable: true, get: function () { return monthly_payment_service_1.MonthlyPaymentService; } });
12
12
  var interest_service_1 = require("./interest.service");
13
13
  Object.defineProperty(exports, "InterestService", { enumerable: true, get: function () { return interest_service_1.InterestService; } });
14
14
  var installment_service_1 = require("./installment-service");
@@ -8,11 +8,10 @@ export declare class InstallmentService {
8
8
  private readonly insuranceService;
9
9
  private readonly ipcaService;
10
10
  private readonly amortizationService;
11
- private readonly paymentService;
11
+ private readonly monthlyPaymentService;
12
12
  private readonly interestService;
13
13
  private readonly balanceService;
14
14
  private readonly lateService;
15
- private fixIPCAmap;
16
15
  /**
17
16
  * Calcula el total del pago mensual para una cuota
18
17
  * @param inputs
@@ -8,10 +8,9 @@ var math_1 = require("../../math");
8
8
  var insurance_service_1 = require("./insurance-service");
9
9
  var ipca_service_1 = require("./ipca.service");
10
10
  var amortization_service_1 = require("./amortization-service");
11
- var payment_service_1 = require("./payment-service");
11
+ var monthly_payment_service_1 = require("./monthly-payment-service");
12
12
  var interest_service_1 = require("./interest.service");
13
13
  var balance_service_1 = require("./balance-service");
14
- var amortization_method_enum_1 = require("../../shared/models/enum/amortization-method.enum");
15
14
  var late_service_1 = require("./late.service");
16
15
  var InstallmentService = /** @class */ (function () {
17
16
  function InstallmentService(math) {
@@ -19,84 +18,48 @@ var InstallmentService = /** @class */ (function () {
19
18
  this.insuranceService = new insurance_service_1.InsuranceService(this.math);
20
19
  this.ipcaService = new ipca_service_1.IPCAService(this.math);
21
20
  this.amortizationService = new amortization_service_1.AmortizationService(this.math);
22
- this.paymentService = new payment_service_1.PaymentService(this.math);
21
+ this.monthlyPaymentService = new monthly_payment_service_1.MonthlyPaymentService(this.math);
23
22
  this.interestService = new interest_service_1.InterestService(this.math);
24
23
  this.balanceService = new balance_service_1.BalanceService(this.math);
25
24
  this.lateService = new late_service_1.LateService(this.math);
26
25
  this.math = new math_1.MathService(true, 10);
27
26
  }
28
- InstallmentService.prototype.fixIPCAmap = function (IPCAmap) {
29
- var fechaInicio = Object.keys(IPCAmap)[0];
30
- var nuevaFechainidico = new creditu_date_model_1.DateModel(fechaInicio).addDays(1).toString();
31
- IPCAmap[nuevaFechainidico] = IPCAmap[fechaInicio];
32
- delete IPCAmap[fechaInicio];
33
- var keysOrdenadas = Object.keys(IPCAmap).sort();
34
- var IPCAmapfixed = {};
35
- // eslint-disable-next-line no-return-assign
36
- keysOrdenadas.forEach(function (key) { return IPCAmapfixed[key] = IPCAmap[key]; });
37
- return IPCAmapfixed;
38
- };
39
27
  /**
40
28
  * Calcula el total del pago mensual para una cuota
41
29
  * @param inputs
42
30
  * @param params
43
31
  */
44
32
  InstallmentService.prototype.getTotalMonthlyPayment = function (inputs, params) {
45
- if (inputs.paymentNumber.value() !== 1) {
46
- inputs.IPCAmap = this.fixIPCAmap(inputs.IPCAmap);
47
- }
48
33
  var IPCAByDates = this.ipcaService.getIPCAsByDates(inputs.IPCAmap);
49
- var dates = IPCAByDates.map(function (obj) { return obj.date; });
50
- var dailyIPCAvalues = IPCAByDates.map(function (obj) { return obj.dailyIPCA; });
51
- if (inputs.paymentNumber.value() === 1) {
52
- dailyIPCAvalues = dailyIPCAvalues.slice(1);
53
- }
54
- var dailyInflationaryUpperBound = this.ipcaService.getDailyInflationaryUpperBound(dates, inputs.inflationaryUpperBound);
55
- var balanceValues = this.balanceService.getBalances(dailyIPCAvalues, dailyInflationaryUpperBound, inputs.previousBalance);
56
- var dailyRate = this.interestService.getDailyInterestValue(params.annualRate);
34
+ var dailyIPCAvalues = this.ipcaService.getDailyIPCAValues(IPCAByDates);
35
+ var balanceValues = this.balanceService.getBalances(dailyIPCAvalues, inputs.previousBalance);
57
36
  var balance = this.balanceService.getBalance(balanceValues.balances);
58
- var startDate = Object.keys(inputs.IPCAmap)[0];
37
+ var startDate = new creditu_date_model_1.DateModel(Object.keys(inputs.IPCAmap)[0]).addDays(1).toString();
59
38
  var endDate = Object.keys(inputs.IPCAmap).pop();
60
- var proportionalDays = inputs.paymentNumber.value() === 1 ? this.interestService.getProportionalDays(startDate, endDate) : 1;
39
+ var proportionalDays = this.interestService.getProportionalDays(startDate, endDate);
61
40
  var interest = this.interestService.getInterest(inputs.previousBalance.value(), params.annualRate, proportionalDays);
62
- var interestDiff = this.interestService.getInterestDiff(balanceValues.balances, params.annualRate, proportionalDays, interest);
63
- var interestIUB = this.math.add(interest, interestDiff);
64
- var amortizationIUB;
65
- var amortizationDiff;
66
- if (inputs.amortizationMethod === amortization_method_enum_1.AmortizationMethod.GERMAN) {
67
- amortizationIUB = this.amortizationService.getAmortizationGerman(inputs.paymentNumber, inputs.numberOfMonths, balance);
68
- amortizationDiff = this.amortizationService.getAmortizationDiffGerman(inputs.previousBalance.value(), balance, inputs.numberOfMonths.value());
69
- }
70
- else {
71
- var monthlyRate = this.interestService.getMonthlyInterestValue(params.annualRate);
72
- amortizationIUB = this.amortizationService.getAmortizationFrench(monthlyRate, inputs.numberOfMonths.value(), balance, inputs.paymentNumber.value());
73
- amortizationDiff = this.amortizationService.getAmortizationDiffFrench(monthlyRate, inputs.numberOfMonths.value(), inputs.previousBalance.value(), balance, inputs.paymentNumber.value());
74
- }
41
+ var interestIUB = this.interestService.getInterestIUB(balanceValues.balances, params.annualRate, proportionalDays);
42
+ var interestDiff = this.math.subtract(interestIUB, interest);
43
+ var _a = this.amortizationService.getAmortizationIUB(inputs, balance, params.annualRate), amortizationIUB = _a.amortizationIUB, amortizationDiff = _a.amortizationDiff;
75
44
  var ipcaUpdate = this.ipcaService.getIPCAUpdate(balanceValues.balanceMonetaryUpdateValues);
76
- var postponedInflationaryUpdate = this.ipcaService.getPosponedInflationaryUpdate(inputs.previousBalance.value(), inputs.inflationaryUpperBound, ipcaUpdate, amortizationDiff);
77
- var amortizationIPCA = this.amortizationService.getAmortizationIPC(inputs.previousBalance.value(), inputs.inflationaryUpperBound, amortizationDiff, ipcaUpdate);
78
- var amortization = this.math.subtract(amortizationIUB, postponedInflationaryUpdate, amortizationDiff);
79
- var monthlyPayment = this.paymentService.getMonthlyPayment(interest, amortization);
80
- // const balanceAfterOLD = this.balanceService.getBalanceAfter(inputs.previousBalance, ipcaUpdate, amortizationIUB, amortizationIPCA);
45
+ var upperBound = this.math.multiply(inputs.previousBalance.value(), inputs.inflationaryUpperBound);
46
+ var amortizationIPCA = this.amortizationService.getAmortizationIPC(upperBound, amortizationDiff, ipcaUpdate);
47
+ var postponedInflationaryUpdate = this.ipcaService.getPosponedInflationaryUpdate(upperBound, ipcaUpdate, amortizationDiff, amortizationIPCA);
48
+ var amortization = this.amortizationService.getAmortization(amortizationIUB, postponedInflationaryUpdate, amortizationDiff);
49
+ var monthlyPayment = this.monthlyPaymentService.getMonthlyPayment(interest, amortization);
81
50
  var balanceAfter = this.math.subtract(inputs.previousBalance.value(), amortization);
82
- // const diferencia = this.math.subtract(amortization, balanceAfter);
83
- // console.log('file: installment-service.ts ~ line 100 ~ diferencia', diferencia);
84
51
  var insurancePeriods = this.insuranceService.getInsurancePeriods(inputs.IPCAmap, inputs.paymentNumber.value(), inputs.numberOfMonths.value());
85
52
  var lifeInsuranceBalance = this.insuranceService.getLifeInsuranceBalance(IPCAByDates, balanceValues.balances);
86
53
  var debtorLifeInsuranceFee = this.insuranceService.getInsuranceFee(lifeInsuranceBalance, params.debtorLifeInsuranceRate, insurancePeriods);
87
54
  var codebtorLifeInsuranceFee = params.codebtorLifeInsuranceRate ? this.insuranceService.getInsuranceFee(lifeInsuranceBalance, params.codebtorLifeInsuranceRate, insurancePeriods) : 0;
88
55
  var propertyInsuranceFee = this.insuranceService.getInsuranceFee(inputs.propertyAmount, params.propertyInsuranceRate, insurancePeriods);
89
- // TODO: Cambiar.
90
- // const monthlyPaymentWithInsurances = this.math.add(monthlyPayment, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee);
91
- var monthlyPaymentWithInsurances = this.math.add(interest, interestDiff, amortizationIUB, amortizationIPCA, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee);
92
- // const totalLateByDates = lateService.getTotalMonthlyPayment(payment.dueDate, today,
93
- // installment.monthlyPaymentWithInsurances, lateChargesFineRate,
94
- // dailyInterestRate, IPCAmapLate, lateChargesInterestRate);
56
+ var monthlyPaymentWithInsurances = this.monthlyPaymentService.getMonthlyPaymentWithInsurances(interest, interestDiff, amortizationIUB, amortizationIPCA, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee);
57
+ var dailyRate = this.interestService.getDailyInterestValue(params.annualRate);
95
58
  var lateChargesFineRate = params.lateChargesFineRate, lateChargesInterestRate = params.lateChargesInterestRate;
96
59
  var IPCAmapLate = inputs.IPCAmapLate, todayIn = inputs.today;
97
60
  var today = todayIn || new creditu_date_model_1.DateModel().toString();
98
- var dailyInterestRate = this.interestService.getDailyInterestValue(params.annualRate);
99
- var totalLateByDates = this.lateService.getTotalMonthlyPayment(endDate, today, monthlyPaymentWithInsurances, lateChargesFineRate, dailyInterestRate, IPCAmapLate, lateChargesInterestRate);
61
+ var _b = this.lateService.getTotalMonthlyPayment(endDate, today, monthlyPaymentWithInsurances, lateChargesFineRate, dailyRate, IPCAmapLate, lateChargesInterestRate), lateCharges = _b.lateCharges, lateInterest = _b.lateInterest, lateAmortizationIPCA = _b.lateAmortizationIPCA, lateChargesInterest = _b.lateChargesInterest, monthlyPaymentWithLate = _b.monthlyPaymentWithLate, lateDays = _b.lateDays;
62
+ var lateRate = this.lateService.getLateRate(lateChargesInterestRate, dailyRate, dailyIPCAvalues);
100
63
  return {
101
64
  IPCAByDates: IPCAByDates,
102
65
  balanceValues: balanceValues,
@@ -109,7 +72,6 @@ var InstallmentService = /** @class */ (function () {
109
72
  interestIUB: interestIUB,
110
73
  monthlyPayment: monthlyPayment,
111
74
  monthlyPaymentWithInsurances: monthlyPaymentWithInsurances,
112
- monthlyPaymentWithLate: totalLateByDates.totalMonthlyPayment,
113
75
  amortization: amortization,
114
76
  amortizationDiff: amortizationDiff,
115
77
  amortizationIUB: amortizationIUB,
@@ -118,9 +80,13 @@ var InstallmentService = /** @class */ (function () {
118
80
  debtorLifeInsuranceFee: debtorLifeInsuranceFee,
119
81
  codebtorLifeInsuranceFee: codebtorLifeInsuranceFee,
120
82
  propertyInsuranceFee: propertyInsuranceFee,
121
- lateDays: totalLateByDates.lateDays,
122
- lateInterest: totalLateByDates.lateInterest,
123
- lateCharges: totalLateByDates.lateChargesInterest
83
+ lateDays: lateDays,
84
+ lateCharges: lateCharges,
85
+ lateInterest: lateInterest,
86
+ lateAmortizationIPCA: lateAmortizationIPCA,
87
+ lateChargesInterest: lateChargesInterest,
88
+ lateRate: lateRate,
89
+ monthlyPaymentWithLate: monthlyPaymentWithLate
124
90
  };
125
91
  };
126
92
  return InstallmentService;
@@ -47,7 +47,7 @@ var InsuranceService = /** @class */ (function () {
47
47
  if (insuranceRate.value() === 0)
48
48
  throw new Error('Invalid insurance rate');
49
49
  var insuranceFee = this.math.multiply(baseAmount, insuranceRate.value());
50
- return this.math.round(this.math.multiply(insuranceFee, insurancePeriods), 2);
50
+ return this.math.round(this.math.multiply(insuranceFee, insurancePeriods), 10);
51
51
  };
52
52
  /**
53
53
  * Metodo para recuperar el balance del último día del mes anterior a la fecha de pago del seguro de vida
@@ -59,14 +59,16 @@ var InsuranceService = /** @class */ (function () {
59
59
  InsuranceService.prototype.getLifeInsuranceBalance = function (IPCAByDatesIn, balances) {
60
60
  var IPCAByDates = JSON.parse(JSON.stringify(IPCAByDatesIn));
61
61
  // se quita el día de la firma
62
+ // if (IPCAByDatesIn.length !== balances.length)
62
63
  IPCAByDates.shift();
63
- var _a = IPCAByDates[IPCAByDates.length - 1].date.split('-'), lastYear = _a[0], lastMonth = _a[1];
64
+ var _a = IPCAByDates[IPCAByDates.length - 1].date.split('-'), lastMonth = _a[1];
64
65
  var lastIndex;
65
66
  IPCAByDates.forEach(function (obj, index) {
66
- var _a = obj.date.split('-'), year = _a[0], month = _a[1];
67
- var cond = year !== lastYear || month !== lastMonth;
68
- if (cond)
67
+ var _a = obj.date.split('-'), month = _a[1];
68
+ var cond = month !== lastMonth;
69
+ if (cond) {
69
70
  lastIndex = index;
71
+ }
70
72
  });
71
73
  return lastIndex ? balances[lastIndex] : balances.shift();
72
74
  };
@@ -4,10 +4,10 @@ export declare class InterestService {
4
4
  constructor(math: MathService);
5
5
  /**
6
6
  * Método que calcula el interés diario a partir del interés anual.
7
- * @param annyalRate Tasa de interés anual.
7
+ * @param annualRate Tasa de interés anual.
8
8
  * @returns
9
9
  */
10
- getDailyInterestValue(annyalRate: number): number;
10
+ getDailyInterestValue(annualRate: number): number;
11
11
  /**
12
12
  * Método que calcula el interés mensual a partir del interés anual.
13
13
  * @param annualRate Tasa de interés anual.
@@ -16,7 +16,7 @@ export declare class InterestService {
16
16
  getMonthlyInterestValue(annualRate: number): number;
17
17
  /**
18
18
  * Método que calcula el interés de un periodo de tiempo a partir del interés anual.
19
- * @param annyalRate Tasa de interés anual.
19
+ * @param annualRate Tasa de interés anual.
20
20
  * @param period Periodo de tiempo para calcular la tasa, normalmente 360 para la tasa diaria o 12 para la tasa mensual.
21
21
  * @returns
22
22
  */
@@ -33,6 +33,6 @@ export declare class InterestService {
33
33
  * @param annualRate
34
34
  * @param proportion
35
35
  */
36
- getInterestDiff(balanceValues: number[], annualRate: number, proportion: number, interest: any): number;
36
+ getInterestIUB(balanceValues: number[], annualRate: number, proportion: number): number;
37
37
  getInterest(previusBalance: number, annualRate: number, proportion: number): number;
38
38
  }