creditu-common-library 2.0.0 → 2.1.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.
@@ -38,6 +38,10 @@ export declare class DebtParams {
38
38
  * Peridiocidad de los intereses, por defecto es Compuesta
39
39
  */
40
40
  inflationExchangeMethodMonthlyToDaily?: InterestType;
41
+ /**
42
+ * Peridiocidad de los intereses, por defecto es Compuesta
43
+ */
44
+ inflationExchangeMethodYearlyToMonthly?: InterestType;
41
45
  /**
42
46
  * Estrategia a usar para el calculo de los seguros.
43
47
  * Por defecto es PERIODS, que es el cálculo que ya veníamos haciendo.
@@ -18,6 +18,10 @@ var DebtParams = /** @class */ (function () {
18
18
  * Peridiocidad de los intereses, por defecto es Compuesta
19
19
  */
20
20
  this.inflationExchangeMethodMonthlyToDaily = models_1.InterestType.COMPOUND;
21
+ /**
22
+ * Peridiocidad de los intereses, por defecto es Compuesta
23
+ */
24
+ this.inflationExchangeMethodYearlyToMonthly = models_1.InterestType.COMPOUND;
21
25
  /**
22
26
  * Estrategia a usar para el calculo de los seguros.
23
27
  * Por defecto es PERIODS, que es el cálculo que ya veníamos haciendo.
@@ -1,3 +1,5 @@
1
+ import { InterestType } from '../../shared/models';
2
+ import { MonthNominalLength } from '../../shared/models/enum/month-nominal-length.enum';
1
3
  export declare class LatesInput {
2
4
  dueDate: string;
3
5
  today: string;
@@ -7,4 +9,6 @@ export declare class LatesInput {
7
9
  annualCreditInterestRate: number;
8
10
  inflationMap: Record<string, number>;
9
11
  considerNegativeInflation: boolean;
12
+ monthNominalLength: number | MonthNominalLength;
13
+ inflationExchangeMethodYearlyToMonthly: InterestType;
10
14
  }
@@ -33,7 +33,7 @@ export declare class AmortizationService {
33
33
  amortizationIUB: any;
34
34
  amortizationDiff: any;
35
35
  };
36
- getAmortization(amortizationIUB: number, postponedInflationaryUpdate: number, amortizationDiff: number): number;
36
+ getAmortization(amortizationIUB: number, amortizationDiff: number, postponedInflationaryUpdate: number): number;
37
37
  getAmortizationInflation(upperBound: number, amortizationDiff: number, inflationaryUpdate: number): number;
38
38
  getAmortizations(inputs: DebtInputs, balance: number, annualRate: number, inflationaryUpdate: number): {
39
39
  inflationaryUpdate: number;
@@ -79,8 +79,8 @@ var AmortizationService = /** @class */ (function () {
79
79
  }
80
80
  return { amortizationIUB: amortizationIUB, amortizationDiff: amortizationDiff };
81
81
  };
82
- AmortizationService.prototype.getAmortization = function (amortizationIUB, postponedInflationaryUpdate, amortizationDiff) {
83
- return this.math.subtract(amortizationIUB, postponedInflationaryUpdate, amortizationDiff);
82
+ AmortizationService.prototype.getAmortization = function (amortizationIUB, amortizationDiff, postponedInflationaryUpdate) {
83
+ return this.math.subtract(amortizationIUB, amortizationDiff, postponedInflationaryUpdate);
84
84
  };
85
85
  AmortizationService.prototype.getAmortizationInflation = function (upperBound, amortizationDiff, inflationaryUpdate) {
86
86
  var amortizationInflation = this.math.round(upperBound < inflationaryUpdate
@@ -93,7 +93,7 @@ var AmortizationService = /** @class */ (function () {
93
93
  var upperBound = this.math.multiply(inputs.previousBalance.value(), inputs.inflationaryUpperBound);
94
94
  var amortizationInflation = this.getAmortizationInflation(upperBound, amortizationDiff, inflationaryUpdate);
95
95
  var postponedInflationaryUpdate = this.inflationService.getPosponedInflationaryUpdate(upperBound, inflationaryUpdate, inputs.upperBoundBehaviour);
96
- var amortization = this.getAmortization(amortizationIUB, postponedInflationaryUpdate, amortizationDiff);
96
+ var amortization = this.getAmortization(amortizationIUB, amortizationDiff, postponedInflationaryUpdate);
97
97
  return {
98
98
  inflationaryUpdate: inflationaryUpdate,
99
99
  upperBound: upperBound,
@@ -37,12 +37,18 @@ var InstallmentService = /** @class */ (function () {
37
37
  var _a = this.interestService.getInterests(inputs, balanceValues, params, dueDate), interest = _a.interest, interestIUB = _a.interestIUB, interestDiff = _a.interestDiff;
38
38
  var inflationaryUpdate = this.inflationService.getInflationaryUpdate(balanceValues.balanceMonetaryUpdateValues);
39
39
  var _b = this.amortizationService.getAmortizations(inputs, balanceInflationaryUpdated, params.annualRate, inflationaryUpdate), upperBound = _b.upperBound, postponedInflationaryUpdate = _b.postponedInflationaryUpdate, amortizationInflation = _b.amortizationInflation, amortization = _b.amortization, amortizationIUB = _b.amortizationIUB, amortizationDiff = _b.amortizationDiff;
40
- var monthlyPayment = this.monthlyPaymentService.getMonthlyPayment(interest, amortization);
40
+ var monthlyPayment = this.monthlyPaymentService.getMonthlyPayment({
41
+ interestIUB: interestIUB,
42
+ amortizationIUB: amortizationIUB,
43
+ amortizationDiff: amortizationDiff,
44
+ inflationaryUpdate: inflationaryUpdate,
45
+ postponedInflationaryUpdate: postponedInflationaryUpdate
46
+ });
41
47
  // TODO: Cambiar monthlyPayment para que use valores IUB
42
48
  // Antes debemos verificar que monthlyPayment no lo estamos usando en el backend o en otro lugar.
43
49
  var balanceAfter = this.math.subtract(inputs.previousBalance.value(), amortization);
44
50
  var _c = this.insuranceService.getInsurances(inputs, params, inflationByDates, balanceValues, balanceAfter), totalLifeInsuranceFee = _c.totalLifeInsuranceFee, debtorLifeInsuranceFee = _c.debtorLifeInsuranceFee, codebtorLifeInsuranceFee = _c.codebtorLifeInsuranceFee, propertyInsuranceFee = _c.propertyInsuranceFee, monthlyCreditInsurance = _c.monthlyCreditInsurance, monthlyCreditInsuranceExpenses = _c.monthlyCreditInsuranceExpenses, monthlyCreditInsurancePrize = _c.monthlyCreditInsurancePrize;
45
- var monthlyPaymentWithInsurances = this.monthlyPaymentService.getMonthlyPaymentWithInsurances(interestIUB, amortizationIUB, amortizationInflation, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee, monthlyCreditInsurance || 0);
51
+ var monthlyPaymentWithInsurances = this.monthlyPaymentService.getMonthlyPaymentWithInsurances(monthlyPayment, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee, monthlyCreditInsurance || 0);
46
52
  var TACValue = inputs.considerTAC === true ? inputs.TACValue : 0;
47
53
  var monthlyPaymentWithTAC = this.monthlyPaymentService.getMonthlyPaymentWithTAC(monthlyPaymentWithInsurances, TACValue);
48
54
  var walletBalance = inputs.considerWallet === true ? inputs.walletBalance : 0;
@@ -57,7 +63,9 @@ var InstallmentService = /** @class */ (function () {
57
63
  lateChargesInterestRate: params.lateChargesInterestRate,
58
64
  annualCreditInterestRate: params.annualRate,
59
65
  inflationMap: inflationMapLate,
60
- considerNegativeInflation: inputs.considerNegativeInflation
66
+ considerNegativeInflation: inputs.considerNegativeInflation,
67
+ monthNominalLength: params.monthNominalLength,
68
+ inflationExchangeMethodYearlyToMonthly: params.inflationExchangeMethodYearlyToMonthly
61
69
  }), lateDays = _d.lateDays, lateChargesFine = _d.lateChargesFine, lateInflation = _d.lateInflation, lateInflationaryCorrection = _d.lateInflationaryCorrection, lateChargesInterestRate = _d.lateChargesInterestRate, lateChargesInterest = _d.lateChargesInterest, lateInterestRate = _d.lateInterestRate, lateInterest = _d.lateInterest, lastMonthLateInflation = _d.lastMonthLateInflation, lastMonthLateChargesInterestRate = _d.lastMonthLateChargesInterestRate, lastMonthLateInterestRate = _d.lastMonthLateInterestRate, lastMonthTotalLateRate = _d.lastMonthTotalLateRate, totalLateRate = _d.totalLateRate, totalLateInterest = _d.totalLateInterest, totalLate = _d.totalLate, monthlyPaymentWithLate = _d.monthlyPaymentWithLate;
62
70
  var totalMonthlyPayment = monthlyPaymentWithLate;
63
71
  var response = {
@@ -6,7 +6,6 @@ export declare class LateService {
6
6
  constructor(math: MathService);
7
7
  private readonly interestService;
8
8
  private readonly MONTHS_ON_YEAR;
9
- private readonly DAYS_ON_MONTH;
10
9
  getLate(base: number, rate: number): number;
11
10
  private getLateDailyRate;
12
11
  /**
@@ -27,5 +26,5 @@ export declare class LateService {
27
26
  monthlyPaymentWithLate: number;
28
27
  };
29
28
  getTotalMonthlyPayment(dueDate: string, today: string, monthlyPaymentWithTAC: number, lateChargesFineRate: number, lateChargesInterestRate: number, interestRate: number, inflationMapLate: Record<string, number>, dailyinflationvalues: number[]): Record<string, number>;
30
- getLates({ dueDate, today, totalMonthlyPaymentBeforeLate, lateChargesFineRate, lateChargesInterestRate, annualCreditInterestRate, inflationMap, considerNegativeInflation }: LatesInput): LatesOutput;
29
+ getLates({ dueDate, today, totalMonthlyPaymentBeforeLate, lateChargesFineRate, lateChargesInterestRate, annualCreditInterestRate, inflationMap, considerNegativeInflation, monthNominalLength, inflationExchangeMethodYearlyToMonthly }: LatesInput): LatesOutput;
31
30
  }
@@ -17,12 +17,12 @@ exports.LateService = void 0;
17
17
  var creditu_date_model_1 = require("creditu-date-model");
18
18
  var math_1 = require("../../math");
19
19
  var interest_service_1 = require("./interest.service");
20
+ var month_nominal_length_enum_1 = require("../../shared/models/enum/month-nominal-length.enum");
20
21
  var LateService = /** @class */ (function () {
21
22
  function LateService(math) {
22
23
  this.math = math;
23
24
  this.interestService = new interest_service_1.InterestService(this.math);
24
25
  this.MONTHS_ON_YEAR = 12;
25
- this.DAYS_ON_MONTH = 30;
26
26
  this.math = new math_1.MathService(true, 10);
27
27
  }
28
28
  LateService.prototype.getLate = function (base, rate) {
@@ -124,7 +124,8 @@ var LateService = /** @class */ (function () {
124
124
  return lates;
125
125
  };
126
126
  LateService.prototype.getLates = function (_a) {
127
- var dueDate = _a.dueDate, today = _a.today, totalMonthlyPaymentBeforeLate = _a.totalMonthlyPaymentBeforeLate, lateChargesFineRate = _a.lateChargesFineRate, lateChargesInterestRate = _a.lateChargesInterestRate, annualCreditInterestRate = _a.annualCreditInterestRate, inflationMap = _a.inflationMap, considerNegativeInflation = _a.considerNegativeInflation;
127
+ var _this = this;
128
+ var dueDate = _a.dueDate, today = _a.today, totalMonthlyPaymentBeforeLate = _a.totalMonthlyPaymentBeforeLate, lateChargesFineRate = _a.lateChargesFineRate, lateChargesInterestRate = _a.lateChargesInterestRate, annualCreditInterestRate = _a.annualCreditInterestRate, inflationMap = _a.inflationMap, considerNegativeInflation = _a.considerNegativeInflation, monthNominalLength = _a.monthNominalLength, inflationExchangeMethodYearlyToMonthly = _a.inflationExchangeMethodYearlyToMonthly;
128
129
  var lates = {
129
130
  lateDays: 0,
130
131
  lateChargesFine: 0,
@@ -146,6 +147,8 @@ var LateService = /** @class */ (function () {
146
147
  var todayDateModel = new creditu_date_model_1.DateModel(today);
147
148
  var dueDateDateModel = new creditu_date_model_1.DateModel(dueDate);
148
149
  var lateDays = todayDateModel.daysDiff(dueDateDateModel);
150
+ // FIXME: La fórmula para calcular lateDays debería depender de si estamos usando days360 (ver monthNominalLength)
151
+ // const lateDays = DateModel.days360(dueDate, today);
149
152
  var todayMonth = todayDateModel.monthAsNumber();
150
153
  var dueDateMonth = dueDateDateModel.monthAsNumber();
151
154
  var lateMonths = todayMonth - dueDateMonth;
@@ -156,9 +159,15 @@ var LateService = /** @class */ (function () {
156
159
  if (lateDays > 0) {
157
160
  Object.assign(lates, { lateChargesFine: this.math.multiply(lateChargesFineRate, totalMonthlyPaymentBeforeLate) });
158
161
  }
162
+ var monthlyInterestTypeFunction = {
163
+ COMPOUND: function (a, b, proportion) { return _this.math.subtract(_this.math.multiply(_this.math.add(1 + a), Math.pow(_this.math.add(1 + b), proportion)), 1); },
164
+ SIMPLE: function (a, b) { return _this.math.add(a, b); }
165
+ }[inflationExchangeMethodYearlyToMonthly];
159
166
  var monthlyCreditInterestRate = this.interestService.getCompoundPeriodicRate(annualCreditInterestRate, this.MONTHS_ON_YEAR);
167
+ // fecha de inicio de loop es la fecha más temprana entre today y dueDate
160
168
  var whileDate = todayDateModel.isSameOrAfter(dueDateDateModel) ? dueDateDateModel : todayDateModel;
161
- var _b = whileDate.toString('YYYY-MM-DD').split('-'), startingYear = _b[0], startingMonth = _b[1], startingDay = _b[2];
169
+ var _b = whileDate.toString('YYYY-MM-DD').split('-'), startingYear = _b[0], startingMonth = _b[1];
170
+ // fecha de fin de loop es la fecha más tardía entre today y dueDate
162
171
  var endDate = todayDateModel.isSameOrAfter(dueDateDateModel) ? todayDateModel : dueDateDateModel;
163
172
  var isDueDate = whileDate.daysDiff(endDate) === 0;
164
173
  var monthlyInflationMap = Object.entries(inflationMap).reduce(function (acc, _a) {
@@ -173,11 +182,14 @@ var LateService = /** @class */ (function () {
173
182
  }
174
183
  var isStartingMonth = "".concat(startingYear, "-").concat(startingMonth) === whileDate.toString('YYYY-MM-DD').substring(0, 7);
175
184
  var _c = whileDate.toString('YYYY-MM-DD').split('-'), whileYear = _c[0], whileMonth = _c[1], whileDay = _c[2];
176
- var totalDaysInMonth = (new Date(Number(whileYear), Number(whileMonth), 0)).getDate();
185
+ var totalDaysInMonth = (new Date(Number(whileYear), Number(whileMonth), 0)).getDate(); // Deberíamos usar monthNominalLength??
177
186
  var isLastMonthsDay = totalDaysInMonth === Number(whileDay);
178
187
  var isLastDay = whileDate.toString('YYYY-MM-DD') === endDate.toString('YYYY-MM-DD');
179
188
  var actualInflation = monthlyInflationMap["".concat(whileYear, "-").concat(whileMonth)];
180
189
  actualInflation = actualInflation < 0 && !considerNegativeInflation ? 0 : actualInflation;
190
+ var daysOnMonth = monthNominalLength === month_nominal_length_enum_1.MonthNominalLength.REAL
191
+ ? this.interestService.getTotalMonthDays(whileDate.toString())
192
+ : monthNominalLength;
181
193
  if (isLastMonthsDay || isLastDay || isDueDate) {
182
194
  var lastMonthLateInflation = actualInflation;
183
195
  var lastMonthLateChargesInterestRate = lateChargesInterestRate;
@@ -196,11 +208,27 @@ var LateService = /** @class */ (function () {
196
208
  });
197
209
  break;
198
210
  }
199
- var lateDaysInMonth = Number(whileDay) - (isStartingMonth ? Number(startingDay) : 0);
200
- var proportion = this.math.divide(lateDaysInMonth, this.DAYS_ON_MONTH);
211
+ // const lateDaysInMonth = Number(whileDay) - (isStartingMonth ? Number(startingDay) : 0);
212
+ // FIXME: lateDaysInMonth debe usar days360 o no dependiendo de monthNominalLength
213
+ var lateDaysInMonth = void 0;
214
+ if (isStartingMonth) {
215
+ lateDaysInMonth = creditu_date_model_1.DateModel.days360(dueDate, "".concat(startingYear, "-").concat(startingMonth, "-").concat(Number(whileDay)));
216
+ }
217
+ else if (isLastDay) {
218
+ lateDaysInMonth = Number(whileDay);
219
+ }
220
+ else {
221
+ lateDaysInMonth = daysOnMonth;
222
+ }
223
+ // lateDaysInMonth usó dueDate porque es la startingDate para este caso
224
+ var proportion = this.math.divide(lateDaysInMonth, daysOnMonth);
201
225
  var accLateInflation = lateDays > 0 ? this.math.add(lates.lateInflation, this.math.multiply(proportion, actualInflation)) : 0;
202
- var accLateChargesInterestRate = lateDays > 0 ? this.math.add(lates.lateChargesInterestRate, this.math.multiply(proportion, lateChargesInterestRate)) : 0;
203
- var accLateInterestRate = lateDays > 0 ? this.math.add(lates.lateInterestRate, this.math.multiply(proportion, monthlyCreditInterestRate)) : 0;
226
+ var accLateChargesInterestRate = lateDays > 0
227
+ ? monthlyInterestTypeFunction(lates.lateChargesInterestRate, lateChargesInterestRate, proportion)
228
+ : 0;
229
+ var accLateInterestRate = lateDays > 0
230
+ ? monthlyInterestTypeFunction(lates.lateInterestRate, monthlyCreditInterestRate, proportion)
231
+ : 0;
204
232
  var totalLateRate = this.interestService.getTotalInterestRate([
205
233
  accLateInflation,
206
234
  accLateChargesInterestRate,
@@ -9,7 +9,7 @@ export declare class MonthlyPaymentService {
9
9
  * @param amortization
10
10
  * @param amortizationIinflation
11
11
  */
12
- getMonthlyPayment(interest: number, amortization: number): number;
12
+ getMonthlyPayment({ interestIUB, amortizationIUB, amortizationDiff, inflationaryUpdate, postponedInflationaryUpdate }: Record<string, number>): number;
13
13
  /**
14
14
  * Calcula el pago de la cuota mensual considerando la tasa de administración de contrato
15
15
  * @param monthlyPaymentWithInsurances
@@ -22,7 +22,7 @@ export declare class MonthlyPaymentService {
22
22
  * @param amortization
23
23
  * @param amortizationIinflation
24
24
  */
25
- getMonthlyPaymentWithInsurances(interestIUB: number, amortizationIUB: number, amortizationIinflation: number, debtorLifeInsuranceFee: number, codebtorLifeInsuranceFee: number, propertyInsuranceFee: number, monthlyCreditInsurance: number): number;
25
+ getMonthlyPaymentWithInsurances(monthlyPayment: number, debtorLifeInsuranceFee: number, codebtorLifeInsuranceFee: number, propertyInsuranceFee: number, monthlyCreditInsurance: number): number;
26
26
  /**
27
27
  * Calcula el monto de la cuota considerando el saldo en wallet
28
28
  *
@@ -24,12 +24,17 @@ var MonthlyPaymentService = /** @class */ (function () {
24
24
  * @param amortization
25
25
  * @param amortizationIinflation
26
26
  */
27
- MonthlyPaymentService.prototype.getMonthlyPayment = function (interest, amortization) {
27
+ MonthlyPaymentService.prototype.getMonthlyPayment = function (_a) {
28
+ var interestIUB = _a.interestIUB, amortizationIUB = _a.amortizationIUB, amortizationDiff = _a.amortizationDiff, inflationaryUpdate = _a.inflationaryUpdate, postponedInflationaryUpdate = _a.postponedInflationaryUpdate;
28
29
  this.paramsValidator({
29
- interest: interest,
30
- amortization: amortization
30
+ interestIUB: interestIUB,
31
+ amortizationIUB: amortizationIUB,
32
+ amortizationDiff: amortizationDiff,
33
+ inflationaryUpdate: inflationaryUpdate,
34
+ postponedInflationaryUpdate: postponedInflationaryUpdate
31
35
  });
32
- return this.math.add(interest, amortization);
36
+ var monthlyPayment = this.math.add(interestIUB, this.math.subtract(amortizationIUB, amortizationDiff), this.math.subtract(inflationaryUpdate, postponedInflationaryUpdate));
37
+ return monthlyPayment;
33
38
  };
34
39
  /**
35
40
  * Calcula el pago de la cuota mensual considerando la tasa de administración de contrato
@@ -49,17 +54,15 @@ var MonthlyPaymentService = /** @class */ (function () {
49
54
  * @param amortization
50
55
  * @param amortizationIinflation
51
56
  */
52
- MonthlyPaymentService.prototype.getMonthlyPaymentWithInsurances = function (interestIUB, amortizationIUB, amortizationIinflation, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee, monthlyCreditInsurance) {
57
+ MonthlyPaymentService.prototype.getMonthlyPaymentWithInsurances = function (monthlyPayment, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee, monthlyCreditInsurance) {
53
58
  this.paramsValidator({
54
- interestIUB: interestIUB,
55
- amortizationIUB: amortizationIUB,
56
- amortizationIinflation: amortizationIinflation,
59
+ monthlyPayment: monthlyPayment,
57
60
  debtorLifeInsuranceFee: debtorLifeInsuranceFee,
58
61
  codebtorLifeInsuranceFee: codebtorLifeInsuranceFee,
59
62
  propertyInsuranceFee: propertyInsuranceFee,
60
63
  monthlyCreditInsurance: monthlyCreditInsurance
61
64
  });
62
- return this.math.add(interestIUB, amortizationIUB, amortizationIinflation, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee, monthlyCreditInsurance);
65
+ return this.math.add(monthlyPayment, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee, monthlyCreditInsurance);
63
66
  };
64
67
  /**
65
68
  * Calcula el monto de la cuota considerando el saldo en wallet
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creditu-common-library",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "files": [