creditu-common-library 1.2.21 → 1.2.24
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 +1 -1
- package/debt/models/dto/balances-output.dto.d.ts +0 -8
- package/debt/models/dto/debt-inputs.dto.d.ts +4 -0
- package/debt/models/dto/debt-response.dto.d.ts +14 -2
- package/debt/services/amortization-service.d.ts +11 -5
- package/debt/services/amortization-service.js +43 -25
- package/debt/services/balance-service.d.ts +1 -1
- package/debt/services/balance-service.js +3 -13
- package/debt/services/index.d.ts +2 -2
- package/debt/services/index.js +3 -3
- package/debt/services/installment-service.d.ts +1 -2
- package/debt/services/installment-service.js +25 -59
- package/debt/services/insurance-service.js +7 -5
- package/debt/services/interest.service.d.ts +1 -1
- package/debt/services/interest.service.js +18 -33
- package/debt/services/ipca.service.d.ts +2 -8
- package/debt/services/ipca.service.js +6 -27
- package/debt/services/late.service.d.ts +7 -18
- package/debt/services/late.service.js +42 -50
- package/debt/services/monthly-payment-service.d.ts +20 -0
- package/debt/services/monthly-payment-service.js +45 -0
- package/offer/models/dto/offer-response.dto.d.ts +4 -4
- package/package.json +1 -1
- package/test/installment.service.spec.ts +814 -429
- package/debt/services/payment-service.d.ts +0 -12
- package/debt/services/payment-service.js +0 -25
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
|
-
- `
|
|
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
|
-
*
|
|
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
|
-
|
|
110
|
+
lateRate: number;
|
|
99
111
|
}
|
|
@@ -4,8 +4,9 @@ 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
|
|
8
|
-
|
|
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
|
*
|
|
@@ -13,16 +14,16 @@ export declare class AmortizationService {
|
|
|
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
|
|
17
|
+
* @param paymentNumber Número de cuota
|
|
17
18
|
* @returns
|
|
18
19
|
*/
|
|
19
|
-
getAmortizationDiffFrench(
|
|
20
|
+
getAmortizationDiffFrench(monthlyRate: number, numberOfMonths: number, previusBalance: number, balance: number, paymentNumber: number): number;
|
|
20
21
|
/**
|
|
21
22
|
*
|
|
22
23
|
* @param montlyRate 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
|
|
26
|
+
* @param paymentNumber Número de cuota
|
|
26
27
|
* @returns
|
|
27
28
|
*/
|
|
28
29
|
getAmortizationFrench(montlyRate: number, numberOfMonths: number, balance: number, paymentNumber: number): number;
|
|
@@ -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,30 +3,28 @@ 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.
|
|
14
|
+
AmortizationService.prototype.getMonthlyPayment = function (montlyRate, period, balance) {
|
|
12
15
|
var a = Math.pow(this.math.add(1, montlyRate), period);
|
|
13
16
|
var b = this.math.multiply(a, montlyRate);
|
|
14
17
|
var c = this.math.subtract(a, 1);
|
|
15
18
|
return this.math.multiply(this.math.divide(b, c), balance);
|
|
16
19
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!condition1) {
|
|
22
|
-
// return this.math.round(this.math.subtract(this.math.multiply(previousBalance, inflationaryUpperBound), amortizationDiff), 2);
|
|
23
|
-
return this.math.round(this.math.multiply(previousBalance, inflationaryUpperBound), 2);
|
|
24
|
-
}
|
|
25
|
-
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);
|
|
26
24
|
};
|
|
27
25
|
// (balanceAfter - balance) / numberOfMonths
|
|
28
26
|
AmortizationService.prototype.getAmortizationDiffGerman = function (previousBalance, balance, numberOfMonths) {
|
|
29
|
-
return this.math.round(this.math.divide(this.math.subtract(balance, previousBalance), numberOfMonths),
|
|
27
|
+
return this.math.round(this.math.divide(this.math.subtract(balance, previousBalance), numberOfMonths), 10);
|
|
30
28
|
};
|
|
31
29
|
/**
|
|
32
30
|
*
|
|
@@ -34,32 +32,32 @@ var AmortizationService = /** @class */ (function () {
|
|
|
34
32
|
* @param numberOfMonths Número de meses del crédito
|
|
35
33
|
* @param previusBalance Balance anterior
|
|
36
34
|
* @param balance Balance actual
|
|
37
|
-
* @param paymentNumber Número
|
|
35
|
+
* @param paymentNumber Número de cuota
|
|
38
36
|
* @returns
|
|
39
37
|
*/
|
|
40
|
-
AmortizationService.prototype.getAmortizationDiffFrench = function (
|
|
41
|
-
var period = numberOfMonths
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
return this.math.subtract(
|
|
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);
|
|
49
47
|
};
|
|
50
48
|
/**
|
|
51
49
|
*
|
|
52
50
|
* @param montlyRate Tasa mensual del crédito
|
|
53
51
|
* @param numberOfMonths Número de meses del crédito
|
|
54
52
|
* @param balance Balance actual
|
|
55
|
-
* @param paymentNumber Número
|
|
53
|
+
* @param paymentNumber Número de cuota
|
|
56
54
|
* @returns
|
|
57
55
|
*/
|
|
58
56
|
AmortizationService.prototype.getAmortizationFrench = function (montlyRate, numberOfMonths, balance, paymentNumber) {
|
|
59
|
-
var period = numberOfMonths
|
|
60
|
-
var
|
|
57
|
+
var period = this.math.subtract(this.math.add(numberOfMonths, 1), paymentNumber);
|
|
58
|
+
var monthlyPayment = this.getMonthlyPayment(montlyRate, period, balance);
|
|
61
59
|
var interest = this.math.multiply(balance, montlyRate);
|
|
62
|
-
return this.math.subtract(
|
|
60
|
+
return this.math.subtract(monthlyPayment, interest);
|
|
63
61
|
};
|
|
64
62
|
/**
|
|
65
63
|
* Calcula la amortizacion
|
|
@@ -76,6 +74,26 @@ var AmortizationService = /** @class */ (function () {
|
|
|
76
74
|
var result = this.math.divide(balance, divisor);
|
|
77
75
|
return result;
|
|
78
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
|
+
};
|
|
79
97
|
return AmortizationService;
|
|
80
98
|
}());
|
|
81
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[],
|
|
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,
|
|
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
|
-
|
|
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
|
/**
|
package/debt/services/index.d.ts
CHANGED
|
@@ -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 {
|
|
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,
|
|
8
|
+
export { AmortizationService, InsuranceService, IPCAService, MonthlyPaymentService, InterestService, InstallmentService, LateService };
|
package/debt/services/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LateService = exports.InstallmentService = exports.InterestService = exports.
|
|
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
|
|
11
|
-
Object.defineProperty(exports, "
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
50
|
-
var
|
|
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 =
|
|
39
|
+
var proportionalDays = this.interestService.getProportionalDays(startDate, endDate);
|
|
61
40
|
var interest = this.interestService.getInterest(inputs.previousBalance.value(), params.annualRate, proportionalDays);
|
|
62
|
-
var
|
|
63
|
-
var
|
|
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
|
|
77
|
-
var amortizationIPCA = this.amortizationService.getAmortizationIPC(
|
|
78
|
-
var
|
|
79
|
-
var
|
|
80
|
-
|
|
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
|
-
|
|
90
|
-
|
|
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
|
|
99
|
-
var
|
|
61
|
+
var _b = this.lateService.getTotalMonthlyPayment(endDate, today, monthlyPaymentWithInsurances, inputs.isGraceMonth, 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:
|
|
122
|
-
|
|
123
|
-
|
|
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),
|
|
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('-'),
|
|
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('-'),
|
|
67
|
-
var cond =
|
|
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
|
};
|
|
@@ -33,6 +33,6 @@ export declare class InterestService {
|
|
|
33
33
|
* @param annualRate
|
|
34
34
|
* @param proportion
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
getInterestIUB(balanceValues: number[], annualRate: number, proportion: number): number;
|
|
37
37
|
getInterest(previusBalance: number, annualRate: number, proportion: number): number;
|
|
38
38
|
}
|
|
@@ -43,33 +43,18 @@ var InterestService = /** @class */ (function () {
|
|
|
43
43
|
* @param startDate
|
|
44
44
|
* @param endDate
|
|
45
45
|
*/
|
|
46
|
+
// eslint-disable-next-line class-methods-use-this
|
|
46
47
|
InterestService.prototype.getProportionalDays = function (startDate, endDate) {
|
|
47
|
-
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
periodArray[periodIndex].days += 1;
|
|
60
|
-
}
|
|
61
|
-
startDateModel = startDateModel.addDays(1);
|
|
62
|
-
};
|
|
63
|
-
while (startDateModel <= endDateModel) {
|
|
64
|
-
_loop_1();
|
|
65
|
-
}
|
|
66
|
-
// Se utiliza el primer mes antes del vencimiento de la cuota para el total de días a considerar en la proporción para el interés.
|
|
67
|
-
var monthBeforeEndDate = endDateModel.substractMonths(1);
|
|
68
|
-
var _a = monthBeforeEndDate.toString().split('-'), year = _a[0], month = _a[1];
|
|
69
|
-
var daysOfMonth = new Date(Number(year), Number(month), 0).getDate();
|
|
70
|
-
var proportion = periodArray.reduce(function (proportion, element) { return proportion + _this.math.multiply(_this.math.divide(1, daysOfMonth), element.days); }, 0);
|
|
71
|
-
// return this.math.round(proportion, 2);
|
|
72
|
-
return proportion;
|
|
48
|
+
// primero consigo el mes anterior a la fecha de vencimiento
|
|
49
|
+
var datePreviusMonth = new creditu_date_model_1.DateModel(endDate).substractMonths(1);
|
|
50
|
+
var _a = datePreviusMonth.toString().split('-'), year = _a[0], month = _a[1];
|
|
51
|
+
// calculo sus días
|
|
52
|
+
var daysOfpreviusMonth = new Date(Number(year), Number(month), 0).getDate();
|
|
53
|
+
// calculo los días del periodo
|
|
54
|
+
var startDateModel = new creditu_date_model_1.DateModel(startDate);
|
|
55
|
+
var totalDays = new creditu_date_model_1.DateModel(endDate).daysDiff(startDateModel) + 1; // +1 porque se considera el día de pago
|
|
56
|
+
// Hago la proporción
|
|
57
|
+
return totalDays / daysOfpreviusMonth;
|
|
73
58
|
};
|
|
74
59
|
/**
|
|
75
60
|
* Calcula el interes (sin inflación) a partir del interes diario
|
|
@@ -77,16 +62,16 @@ var InterestService = /** @class */ (function () {
|
|
|
77
62
|
* @param annualRate
|
|
78
63
|
* @param proportion
|
|
79
64
|
*/
|
|
80
|
-
InterestService.prototype.
|
|
65
|
+
InterestService.prototype.getInterestIUB = function (balanceValues, annualRate, proportion) {
|
|
81
66
|
var lastBalance = balanceValues[balanceValues.length - 1];
|
|
82
|
-
var
|
|
83
|
-
var
|
|
84
|
-
return this.math.round(
|
|
67
|
+
var monthlyRate = this.getMonthlyInterestValue(annualRate);
|
|
68
|
+
var interestIUB = this.math.multiply(lastBalance, monthlyRate, proportion);
|
|
69
|
+
return this.math.round(interestIUB, 10);
|
|
85
70
|
};
|
|
86
71
|
InterestService.prototype.getInterest = function (previusBalance, annualRate, proportion) {
|
|
87
|
-
|
|
88
|
-
var interest = this.math.multiply(previusBalance,
|
|
89
|
-
return this.math.round(this.math.multiply(interest, proportion),
|
|
72
|
+
var monthlyInterest = this.getMonthlyInterestValue(annualRate);
|
|
73
|
+
var interest = this.math.multiply(previusBalance, monthlyInterest);
|
|
74
|
+
return this.math.round(this.math.multiply(interest, proportion), 10);
|
|
90
75
|
};
|
|
91
76
|
return InterestService;
|
|
92
77
|
}());
|
|
@@ -5,18 +5,11 @@ export declare class IPCAService {
|
|
|
5
5
|
constructor(math: MathService);
|
|
6
6
|
private calculateDaysOfMonth;
|
|
7
7
|
private getDailyIPCA;
|
|
8
|
-
private getInflationaryUpperBound;
|
|
9
8
|
/**
|
|
10
9
|
* Permite obtener los IPCA diarios desde la fecha inicio y fecha final del IPCAmap
|
|
11
10
|
* @param IPCAmap
|
|
12
11
|
*/
|
|
13
12
|
getIPCAsByDates(IPCAmap: Record<string, number>): DailyIPCAOutput[];
|
|
14
|
-
/**
|
|
15
|
-
* Calcula los topes diarios de inflacion que el cliente esta dispuesto a pagar
|
|
16
|
-
* @param dates
|
|
17
|
-
* @param inflationaryUpperBound
|
|
18
|
-
*/
|
|
19
|
-
getDailyInflationaryUpperBound(dates: string[], inflationaryUpperBound: any): number[];
|
|
20
13
|
getLastInflationaryBoundDifference(inflationaryBoundDifferenceValues: number[]): number;
|
|
21
14
|
/**
|
|
22
15
|
* Obtiene el valor de IPCAUpdate
|
|
@@ -29,5 +22,6 @@ export declare class IPCAService {
|
|
|
29
22
|
* @param IPCAupdate Correción monetaria del balance por IPCA
|
|
30
23
|
* @param amortizationDiff ...
|
|
31
24
|
*/
|
|
32
|
-
getPosponedInflationaryUpdate(
|
|
25
|
+
getPosponedInflationaryUpdate(upperBound: number, IPCUpdate: number, amortizationDiff: number, amortizationIPCA: number): number;
|
|
26
|
+
getDailyIPCAValues(IPCAByDates: DailyIPCAOutput[]): number[];
|
|
33
27
|
}
|