creditu-common-library 1.2.22 → 1.2.23
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-response.dto.d.ts +4 -0
- package/debt/services/amortization-service.d.ts +1 -1
- package/debt/services/amortization-service.js +4 -8
- 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 +22 -46
- package/debt/services/insurance-service.js +6 -4
- package/debt/services/interest.service.d.ts +1 -1
- package/debt/services/interest.service.js +16 -32
- package/debt/services/ipca.service.d.ts +1 -8
- package/debt/services/ipca.service.js +2 -27
- package/debt/services/late.service.d.ts +3 -2
- package/debt/services/late.service.js +14 -3
- 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 +315 -362
- 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
|
}
|
|
@@ -5,7 +5,7 @@ export declare class AmortizationService {
|
|
|
5
5
|
private readonly math;
|
|
6
6
|
constructor(math: MathService);
|
|
7
7
|
private getPago;
|
|
8
|
-
getAmortizationIPC(
|
|
8
|
+
getAmortizationIPC(upperBound: number, amortizationDiff: number, IPCAupdate: number): number;
|
|
9
9
|
getAmortizationDiffGerman(previousBalance: number, balance: number, numberOfMonths: number): number;
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -14,14 +14,10 @@ var AmortizationService = /** @class */ (function () {
|
|
|
14
14
|
var c = this.math.subtract(a, 1);
|
|
15
15
|
return this.math.multiply(this.math.divide(b, c), balance);
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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);
|
|
17
|
+
AmortizationService.prototype.getAmortizationIPC = function (upperBound, amortizationDiff, IPCAupdate) {
|
|
18
|
+
var condition1 = upperBound < IPCAupdate;
|
|
19
|
+
if (condition1) {
|
|
20
|
+
return this.math.round(this.math.subtract(upperBound, amortizationDiff), 2);
|
|
25
21
|
}
|
|
26
22
|
return this.math.subtract(IPCAupdate, amortizationDiff);
|
|
27
23
|
};
|
|
@@ -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,7 +8,7 @@ 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
14
|
var amortization_method_enum_1 = require("../../shared/models/enum/amortization-method.enum");
|
|
@@ -19,84 +19,59 @@ var InstallmentService = /** @class */ (function () {
|
|
|
19
19
|
this.insuranceService = new insurance_service_1.InsuranceService(this.math);
|
|
20
20
|
this.ipcaService = new ipca_service_1.IPCAService(this.math);
|
|
21
21
|
this.amortizationService = new amortization_service_1.AmortizationService(this.math);
|
|
22
|
-
this.
|
|
22
|
+
this.monthlyPaymentService = new monthly_payment_service_1.MonthlyPaymentService(this.math);
|
|
23
23
|
this.interestService = new interest_service_1.InterestService(this.math);
|
|
24
24
|
this.balanceService = new balance_service_1.BalanceService(this.math);
|
|
25
25
|
this.lateService = new late_service_1.LateService(this.math);
|
|
26
26
|
this.math = new math_1.MathService(true, 10);
|
|
27
27
|
}
|
|
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
28
|
/**
|
|
40
29
|
* Calcula el total del pago mensual para una cuota
|
|
41
30
|
* @param inputs
|
|
42
31
|
* @param params
|
|
43
32
|
*/
|
|
44
33
|
InstallmentService.prototype.getTotalMonthlyPayment = function (inputs, params) {
|
|
45
|
-
if (inputs.paymentNumber.value() !== 1) {
|
|
46
|
-
inputs.IPCAmap = this.fixIPCAmap(inputs.IPCAmap);
|
|
47
|
-
}
|
|
48
34
|
var IPCAByDates = this.ipcaService.getIPCAsByDates(inputs.IPCAmap);
|
|
49
|
-
var dates = IPCAByDates.map(function (obj) { return obj.date; });
|
|
50
35
|
var dailyIPCAvalues = IPCAByDates.map(function (obj) { return obj.dailyIPCA; });
|
|
51
|
-
|
|
52
|
-
|
|
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);
|
|
36
|
+
dailyIPCAvalues = dailyIPCAvalues.slice(1);
|
|
37
|
+
var balanceValues = this.balanceService.getBalances(dailyIPCAvalues, inputs.previousBalance);
|
|
57
38
|
var balance = this.balanceService.getBalance(balanceValues.balances);
|
|
58
|
-
var startDate = Object.keys(inputs.IPCAmap)[0];
|
|
39
|
+
var startDate = new creditu_date_model_1.DateModel(Object.keys(inputs.IPCAmap)[0]).addDays(1).toString();
|
|
59
40
|
var endDate = Object.keys(inputs.IPCAmap).pop();
|
|
60
|
-
var proportionalDays =
|
|
41
|
+
var proportionalDays = this.interestService.getProportionalDays(startDate, endDate);
|
|
61
42
|
var interest = this.interestService.getInterest(inputs.previousBalance.value(), params.annualRate, proportionalDays);
|
|
62
|
-
var
|
|
63
|
-
var
|
|
43
|
+
var interestIUB = this.interestService.getInterestIUB(balanceValues.balances, params.annualRate, proportionalDays);
|
|
44
|
+
var interestDiff = this.math.subtract(interestIUB, interest);
|
|
64
45
|
var amortizationIUB;
|
|
65
46
|
var amortizationDiff;
|
|
66
47
|
if (inputs.amortizationMethod === amortization_method_enum_1.AmortizationMethod.GERMAN) {
|
|
67
48
|
amortizationIUB = this.amortizationService.getAmortizationGerman(inputs.paymentNumber, inputs.numberOfMonths, balance);
|
|
68
49
|
amortizationDiff = this.amortizationService.getAmortizationDiffGerman(inputs.previousBalance.value(), balance, inputs.numberOfMonths.value());
|
|
69
50
|
}
|
|
70
|
-
else {
|
|
51
|
+
else if (inputs.amortizationMethod === amortization_method_enum_1.AmortizationMethod.FRENCH) {
|
|
71
52
|
var monthlyRate = this.interestService.getMonthlyInterestValue(params.annualRate);
|
|
72
53
|
amortizationIUB = this.amortizationService.getAmortizationFrench(monthlyRate, inputs.numberOfMonths.value(), balance, inputs.paymentNumber.value());
|
|
73
54
|
amortizationDiff = this.amortizationService.getAmortizationDiffFrench(monthlyRate, inputs.numberOfMonths.value(), inputs.previousBalance.value(), balance, inputs.paymentNumber.value());
|
|
74
55
|
}
|
|
75
56
|
var ipcaUpdate = this.ipcaService.getIPCAUpdate(balanceValues.balanceMonetaryUpdateValues);
|
|
76
|
-
var
|
|
77
|
-
var amortizationIPCA = this.amortizationService.getAmortizationIPC(
|
|
57
|
+
var upperBound = this.math.multiply(inputs.previousBalance.value(), inputs.inflationaryUpperBound);
|
|
58
|
+
var amortizationIPCA = this.amortizationService.getAmortizationIPC(upperBound, amortizationDiff, ipcaUpdate);
|
|
59
|
+
var postponedInflationaryUpdate = this.ipcaService.getPosponedInflationaryUpdate(upperBound, ipcaUpdate, amortizationDiff, amortizationIPCA);
|
|
78
60
|
var amortization = this.math.subtract(amortizationIUB, postponedInflationaryUpdate, amortizationDiff);
|
|
79
|
-
var monthlyPayment = this.
|
|
80
|
-
// const balanceAfterOLD = this.balanceService.getBalanceAfter(inputs.previousBalance, ipcaUpdate, amortizationIUB, amortizationIPCA);
|
|
61
|
+
var monthlyPayment = this.monthlyPaymentService.getMonthlyPayment(interest, amortization);
|
|
81
62
|
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
63
|
var insurancePeriods = this.insuranceService.getInsurancePeriods(inputs.IPCAmap, inputs.paymentNumber.value(), inputs.numberOfMonths.value());
|
|
85
64
|
var lifeInsuranceBalance = this.insuranceService.getLifeInsuranceBalance(IPCAByDates, balanceValues.balances);
|
|
86
65
|
var debtorLifeInsuranceFee = this.insuranceService.getInsuranceFee(lifeInsuranceBalance, params.debtorLifeInsuranceRate, insurancePeriods);
|
|
87
66
|
var codebtorLifeInsuranceFee = params.codebtorLifeInsuranceRate ? this.insuranceService.getInsuranceFee(lifeInsuranceBalance, params.codebtorLifeInsuranceRate, insurancePeriods) : 0;
|
|
88
67
|
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);
|
|
68
|
+
var monthlyPaymentWithInsurances = this.monthlyPaymentService.getMonthlyPaymentWithInsurances(interest, interestDiff, amortizationIUB, amortizationIPCA, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee);
|
|
69
|
+
var dailyRate = this.interestService.getDailyInterestValue(params.annualRate);
|
|
95
70
|
var lateChargesFineRate = params.lateChargesFineRate, lateChargesInterestRate = params.lateChargesInterestRate;
|
|
96
71
|
var IPCAmapLate = inputs.IPCAmapLate, todayIn = inputs.today;
|
|
97
72
|
var today = todayIn || new creditu_date_model_1.DateModel().toString();
|
|
98
|
-
var
|
|
99
|
-
var
|
|
73
|
+
var _a = this.lateService.getTotalMonthlyPayment(endDate, today, monthlyPaymentWithInsurances, lateChargesFineRate, dailyRate, IPCAmapLate, lateChargesInterestRate), monthlyPaymentWithLate = _a.monthlyPaymentWithLate, lateDays = _a.lateDays, lateInterest = _a.lateInterest, lateCharges = _a.lateCharges;
|
|
74
|
+
var lateRate = this.lateService.getLateRate(lateChargesInterestRate, dailyRate, dailyIPCAvalues);
|
|
100
75
|
return {
|
|
101
76
|
IPCAByDates: IPCAByDates,
|
|
102
77
|
balanceValues: balanceValues,
|
|
@@ -109,7 +84,7 @@ var InstallmentService = /** @class */ (function () {
|
|
|
109
84
|
interestIUB: interestIUB,
|
|
110
85
|
monthlyPayment: monthlyPayment,
|
|
111
86
|
monthlyPaymentWithInsurances: monthlyPaymentWithInsurances,
|
|
112
|
-
monthlyPaymentWithLate:
|
|
87
|
+
monthlyPaymentWithLate: monthlyPaymentWithLate,
|
|
113
88
|
amortization: amortization,
|
|
114
89
|
amortizationDiff: amortizationDiff,
|
|
115
90
|
amortizationIUB: amortizationIUB,
|
|
@@ -118,9 +93,10 @@ var InstallmentService = /** @class */ (function () {
|
|
|
118
93
|
debtorLifeInsuranceFee: debtorLifeInsuranceFee,
|
|
119
94
|
codebtorLifeInsuranceFee: codebtorLifeInsuranceFee,
|
|
120
95
|
propertyInsuranceFee: propertyInsuranceFee,
|
|
121
|
-
lateDays:
|
|
122
|
-
lateInterest:
|
|
123
|
-
lateCharges:
|
|
96
|
+
lateDays: lateDays,
|
|
97
|
+
lateInterest: lateInterest,
|
|
98
|
+
lateCharges: lateCharges,
|
|
99
|
+
lateRate: lateRate
|
|
124
100
|
};
|
|
125
101
|
};
|
|
126
102
|
return InstallmentService;
|
|
@@ -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).subtractMonths(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,15 +62,14 @@ 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
|
-
|
|
84
|
-
return this.math.round(interestIPCAdiff, 2);
|
|
67
|
+
var interestIUB = this.math.multiply(lastBalance, this.getMonthlyInterestValue(annualRate), proportion);
|
|
68
|
+
return this.math.round(interestIUB, 2);
|
|
85
69
|
};
|
|
86
70
|
InterestService.prototype.getInterest = function (previusBalance, annualRate, proportion) {
|
|
87
|
-
|
|
88
|
-
var interest = this.math.multiply(previusBalance,
|
|
71
|
+
var monthlyInterest = this.getMonthlyInterestValue(annualRate);
|
|
72
|
+
var interest = this.math.multiply(previusBalance, monthlyInterest);
|
|
89
73
|
return this.math.round(this.math.multiply(interest, proportion), 2);
|
|
90
74
|
};
|
|
91
75
|
return InterestService;
|
|
@@ -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,5 @@ 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;
|
|
33
26
|
}
|
|
@@ -20,11 +20,6 @@ var IPCAService = /** @class */ (function () {
|
|
|
20
20
|
var preResult = Math.pow(op1, op2);
|
|
21
21
|
return this.math.round(this.math.subtract(preResult, 1), 10);
|
|
22
22
|
};
|
|
23
|
-
IPCAService.prototype.getInflationaryUpperBound = function (inflationaryUpperBound, days) {
|
|
24
|
-
var sum = this.math.add(1, inflationaryUpperBound);
|
|
25
|
-
var div = this.math.divide(1, days);
|
|
26
|
-
return this.math.round((Math.pow(sum, div) - 1), 10);
|
|
27
|
-
};
|
|
28
23
|
/**
|
|
29
24
|
* Permite obtener los IPCA diarios desde la fecha inicio y fecha final del IPCAmap
|
|
30
25
|
* @param IPCAmap
|
|
@@ -59,24 +54,6 @@ var IPCAService = /** @class */ (function () {
|
|
|
59
54
|
});
|
|
60
55
|
return ipcaValues;
|
|
61
56
|
};
|
|
62
|
-
/**
|
|
63
|
-
* Calcula los topes diarios de inflacion que el cliente esta dispuesto a pagar
|
|
64
|
-
* @param dates
|
|
65
|
-
* @param inflationaryUpperBound
|
|
66
|
-
*/
|
|
67
|
-
IPCAService.prototype.getDailyInflationaryUpperBound = function (dates, inflationaryUpperBound) {
|
|
68
|
-
var _this = this;
|
|
69
|
-
if (dates === undefined || dates.length === 0)
|
|
70
|
-
throw new Error('dates array is empty on DailyInflationaryUpperBound calculation');
|
|
71
|
-
if (inflationaryUpperBound === undefined || inflationaryUpperBound === null)
|
|
72
|
-
throw new Error('invalid inflationaryUpperBound on DailyInflationaryUpperBound calculation');
|
|
73
|
-
var result = dates.map(function (date) {
|
|
74
|
-
var _a = date.split('-').map(function (string) { return parseInt(string, 10); }), year = _a[0], month = _a[1];
|
|
75
|
-
var daysOfMonth = _this.calculateDaysOfMonth(year, month);
|
|
76
|
-
return _this.getInflationaryUpperBound(inflationaryUpperBound, daysOfMonth);
|
|
77
|
-
});
|
|
78
|
-
return result;
|
|
79
|
-
};
|
|
80
57
|
IPCAService.prototype.getLastInflationaryBoundDifference = function (inflationaryBoundDifferenceValues) {
|
|
81
58
|
if (inflationaryBoundDifferenceValues === undefined || inflationaryBoundDifferenceValues.length === 0) {
|
|
82
59
|
throw new Error('invalid inflationaryBoundDifferenceValues on inflationaryBoundDifference calculation');
|
|
@@ -100,10 +77,8 @@ var IPCAService = /** @class */ (function () {
|
|
|
100
77
|
* @param IPCAupdate Correción monetaria del balance por IPCA
|
|
101
78
|
* @param amortizationDiff ...
|
|
102
79
|
*/
|
|
103
|
-
IPCAService.prototype.getPosponedInflationaryUpdate = function (
|
|
104
|
-
|
|
105
|
-
var b = this.math.subtract(IPCAupdate, amortizationDiff);
|
|
106
|
-
return a > b ? 0 : b - a;
|
|
80
|
+
IPCAService.prototype.getPosponedInflationaryUpdate = function (upperBound, IPCUpdate, amortizationDiff, amortizationIPCA) {
|
|
81
|
+
return upperBound < IPCUpdate ? this.math.subtract(IPCUpdate, amortizationDiff, amortizationIPCA) : 0;
|
|
107
82
|
};
|
|
108
83
|
return IPCAService;
|
|
109
84
|
}());
|
|
@@ -21,10 +21,11 @@ export declare class LateService {
|
|
|
21
21
|
getLateDaysAndIPCA(startDate: string, endDate: string, ipcaValues: Record<string, number>): any[];
|
|
22
22
|
getTotalLateByDates(dueDate: string, date: string, totalMonthlyPayment: number, lateChargesFineRate: number, dailyRateInterest: number, ipcaValues: Record<string, number>, lateChargesInterestRate: number): any[];
|
|
23
23
|
getTotalMonthlyPayment(dueDateIn: string, date: string, totalMonthlyPayment: number, lateChargesFineRate: number, dailyInterestRate: number, ipcaValues: Record<string, number>, lateChargesInterestRate: number): {
|
|
24
|
-
|
|
24
|
+
monthlyPaymentWithLate: any;
|
|
25
25
|
lateInterest: any;
|
|
26
26
|
lateAmotizationIPCA: any;
|
|
27
|
-
|
|
27
|
+
lateCharges: any;
|
|
28
28
|
lateDays: number;
|
|
29
29
|
};
|
|
30
|
+
getLateRate(lateChargesInterestRate: number, dailyRate: number, dailyIPCAvalues: number[]): number;
|
|
30
31
|
}
|
|
@@ -96,10 +96,10 @@ var LateService = /** @class */ (function () {
|
|
|
96
96
|
var lateDays = new creditu_date_model_1.DateModel(date).daysDiff(new creditu_date_model_1.DateModel(dueDateIn));
|
|
97
97
|
if (lateDays <= 0) {
|
|
98
98
|
return {
|
|
99
|
-
|
|
99
|
+
monthlyPaymentWithLate: totalMonthlyPayment,
|
|
100
100
|
lateInterest: 0,
|
|
101
101
|
lateAmotizationIPCA: 0,
|
|
102
|
-
|
|
102
|
+
lateCharges: 0,
|
|
103
103
|
lateDays: 0
|
|
104
104
|
};
|
|
105
105
|
}
|
|
@@ -113,7 +113,18 @@ var LateService = /** @class */ (function () {
|
|
|
113
113
|
return sum;
|
|
114
114
|
}, { lateInterest: 0, lateAmotizationIPCA: 0, lateChargesInterest: 0 }), lateInterest = _a.lateInterest, lateAmotizationIPCA = _a.lateAmotizationIPCA, lateChargesInterest = _a.lateChargesInterest;
|
|
115
115
|
var finalTotalLate = totalLateByDates[totalLateByDates.length - 1][date];
|
|
116
|
-
return {
|
|
116
|
+
return {
|
|
117
|
+
monthlyPaymentWithLate: finalTotalLate.updatedLateMonthlyPayment,
|
|
118
|
+
lateInterest: lateInterest,
|
|
119
|
+
lateAmotizationIPCA: lateAmotizationIPCA,
|
|
120
|
+
lateCharges: lateChargesInterest,
|
|
121
|
+
lateDays: totalLateByDates.length
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
LateService.prototype.getLateRate = function (lateChargesInterestRate, dailyRate, dailyIPCAvalues) {
|
|
125
|
+
var lastIPCValue = dailyIPCAvalues[dailyIPCAvalues.length - 1];
|
|
126
|
+
var lateRate = this.math.add(lateChargesInterestRate, dailyRate, lastIPCValue);
|
|
127
|
+
return this.math.round(lateRate, 2);
|
|
117
128
|
};
|
|
118
129
|
return LateService;
|
|
119
130
|
}());
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MathService } from '../../math/math.service';
|
|
2
|
+
export declare class MonthlyPaymentService {
|
|
3
|
+
private readonly math;
|
|
4
|
+
constructor(math?: MathService);
|
|
5
|
+
paramsValidator: (...args: any[]) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Calcula el pago de la cuota mensual considerando la amortizacion, el interes e IPCA
|
|
8
|
+
* @param interest
|
|
9
|
+
* @param amortization
|
|
10
|
+
* @param amortizationIPCA
|
|
11
|
+
*/
|
|
12
|
+
getMonthlyPayment(interest: number, amortization: number): number;
|
|
13
|
+
/**
|
|
14
|
+
* Calcula el pago de la cuota mensual considerando todo menos los cargos de atraso
|
|
15
|
+
* @param interest
|
|
16
|
+
* @param amortization
|
|
17
|
+
* @param amortizationIPCA
|
|
18
|
+
*/
|
|
19
|
+
getMonthlyPaymentWithInsurances(interest: number, interestDiff: number, amortizationIUB: number, amortizationIPCA: number, debtorLifeInsuranceFee: number, codebtorLifeInsuranceFee: number, propertyInsuranceFee: number): number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MonthlyPaymentService = void 0;
|
|
4
|
+
var math_service_1 = require("../../math/math.service");
|
|
5
|
+
var MonthlyPaymentService = /** @class */ (function () {
|
|
6
|
+
function MonthlyPaymentService(math) {
|
|
7
|
+
if (math === void 0) { math = new math_service_1.MathService(); }
|
|
8
|
+
this.math = math;
|
|
9
|
+
this.paramsValidator = function () {
|
|
10
|
+
var args = [];
|
|
11
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
+
args[_i] = arguments[_i];
|
|
13
|
+
}
|
|
14
|
+
for (var i = 0; i < args.length; i += 1) {
|
|
15
|
+
if (args[i] === undefined || args[i] === null)
|
|
16
|
+
throw new Error("invalid ".concat(args[i], " on MonthlyPayment calculation"));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Calcula el pago de la cuota mensual considerando la amortizacion, el interes e IPCA
|
|
22
|
+
* @param interest
|
|
23
|
+
* @param amortization
|
|
24
|
+
* @param amortizationIPCA
|
|
25
|
+
*/
|
|
26
|
+
MonthlyPaymentService.prototype.getMonthlyPayment = function (interest, amortization) {
|
|
27
|
+
if (interest === undefined || interest === null)
|
|
28
|
+
throw new Error('invalid interest on MonthlyPayment calculation');
|
|
29
|
+
if (amortization === undefined || amortization === null)
|
|
30
|
+
throw new Error('invalid amortization on MonthlyPayment calculation');
|
|
31
|
+
return this.math.add(interest, amortization);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Calcula el pago de la cuota mensual considerando todo menos los cargos de atraso
|
|
35
|
+
* @param interest
|
|
36
|
+
* @param amortization
|
|
37
|
+
* @param amortizationIPCA
|
|
38
|
+
*/
|
|
39
|
+
MonthlyPaymentService.prototype.getMonthlyPaymentWithInsurances = function (interest, interestDiff, amortizationIUB, amortizationIPCA, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee) {
|
|
40
|
+
this.paramsValidator(interest, interestDiff, amortizationIUB, amortizationIPCA, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee);
|
|
41
|
+
return this.math.add(interest, interestDiff, amortizationIUB, amortizationIPCA, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee);
|
|
42
|
+
};
|
|
43
|
+
return MonthlyPaymentService;
|
|
44
|
+
}());
|
|
45
|
+
exports.MonthlyPaymentService = MonthlyPaymentService;
|
|
@@ -94,13 +94,11 @@ export declare class OfferResponse {
|
|
|
94
94
|
*/
|
|
95
95
|
operationalExpensesFee: any;
|
|
96
96
|
/**
|
|
97
|
-
* D: dividendo //
|
|
97
|
+
* D: dividendo // Payment
|
|
98
98
|
*/
|
|
99
|
-
installment: number;
|
|
100
99
|
/**
|
|
101
|
-
* D-unit: dividendo //
|
|
100
|
+
* D-unit: dividendo // UnitPayment
|
|
102
101
|
*/
|
|
103
|
-
unitInstallment: number;
|
|
104
102
|
/**
|
|
105
103
|
* Tm: tasa de interés mensual
|
|
106
104
|
*/
|
|
@@ -151,4 +149,6 @@ export declare class OfferResponse {
|
|
|
151
149
|
* Se obtiene al dividir financingAmount por amountRequestedByClient
|
|
152
150
|
*/
|
|
153
151
|
financingRatio: number;
|
|
152
|
+
installment: number;
|
|
153
|
+
unitInstallment: number;
|
|
154
154
|
}
|