creditu-common-library 1.2.7 → 1.2.10

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.
@@ -8,9 +8,13 @@ export declare class DebtParams {
8
8
  */
9
9
  annualRate: number;
10
10
  /**
11
- * Tasa de seguro de vida o desgravamen
11
+ * Tasa de seguro de vida o desgravamen deudor
12
12
  */
13
- lifeInsuranceRates: CreditInsuranceRate[];
13
+ debtorLifeInsuranceRate: CreditInsuranceRate;
14
+ /**
15
+ * Tasa de seguro de vida o desgravamen codeudor
16
+ */
17
+ codebtorLifeInsuranceRate?: CreditInsuranceRate;
14
18
  /**
15
19
  * Tasa de seguro de incendio o propiedad
16
20
  */
@@ -4,10 +4,6 @@ import { DailyIPCAOutput } from './daily-ipca-output.dto';
4
4
  * Respuesta del calculo de la deuda
5
5
  */
6
6
  export declare class DebtResponse {
7
- /**
8
- * Deuda calculada para la cuota
9
- */
10
- totalMonthlyPayment: number;
11
7
  /**
12
8
  * IPCA diarios para las fechas de calculo de deuda
13
9
  */
@@ -55,7 +51,11 @@ export declare class DebtResponse {
55
51
  /**
56
52
  * Cuota de seguro de vida o desgravamen
57
53
  */
58
- lifeInsuranceFee: number;
54
+ debtorLifeInsuranceFee: number;
55
+ /**
56
+ * Cuota de seguro de vida o desgravamen
57
+ */
58
+ codebtorLifeInsuranceFee: number;
59
59
  /**
60
60
  * Cuota de seguro de incendio o propiedad
61
61
  */
@@ -45,7 +45,7 @@ var InstallmentService = /** @class */ (function () {
45
45
  }
46
46
  var IPCAByDates = this.ipcaService.getIPCAsByDates(inputs.IPCAmap);
47
47
  var dates = IPCAByDates.map(function (obj) { return obj.date; });
48
- var dailyIPCAvalues = IPCAByDates.map(function (obj) { return obj.dailyIPCA; }); // ; // Se quita la firma para efecto de
48
+ var dailyIPCAvalues = IPCAByDates.map(function (obj) { return obj.dailyIPCA; });
49
49
  if (inputs.paymentNumber.value() === 1) {
50
50
  dailyIPCAvalues = dailyIPCAvalues.slice(1);
51
51
  }
@@ -55,7 +55,8 @@ var InstallmentService = /** @class */ (function () {
55
55
  var balance = this.balanceService.getBalance(balanceValues.balances);
56
56
  var startDate = Object.keys(inputs.IPCAmap)[0];
57
57
  var endDate = Object.keys(inputs.IPCAmap).pop();
58
- var interest = this.interestService.getInterest(balanceValues.balances, params.annualRate, startDate, endDate, inputs.paymentNumber.value());
58
+ var proportionalDays = inputs.paymentNumber.value() === 1 ? this.interestService.getProportionalDays(startDate, endDate) : 1;
59
+ var interest = this.interestService.getInterest(balanceValues.balances, params.annualRate, proportionalDays);
59
60
  var amortization;
60
61
  var amortizationDiff;
61
62
  if (inputs.amortizationMethod === amortization_method_enum_1.AmortizationMethod.GERMAN) {
@@ -71,12 +72,12 @@ var InstallmentService = /** @class */ (function () {
71
72
  var amortizationIPCA = this.amortizationService.getAmortizationIPC(inputs.previousBalance.value(), inputs.inflationaryUpperBound, amortizationDiff, ipcaUpdate);
72
73
  var monthlyPayment = this.paymentService.getMonthlyPayment(interest, amortization, amortizationIPCA);
73
74
  var balanceAfter = this.balanceService.getBalanceAfter(inputs.previousBalance, ipcaUpdate, amortization, amortizationIPCA);
74
- var lifeInsuranceFee = this.insuranceService.getLifeInsurance(params.lifeInsuranceRates, balance);
75
- var propertyInsuranceFee = this.insuranceService.getPropertyInsurance(inputs.propertyAmount, params.propertyInsuranceRate, inputs.IPCAmap);
76
- var totalMonthlyPayment = this.math.add(monthlyPayment, lifeInsuranceFee, propertyInsuranceFee);
77
- var monthlyPaymentWithInsurances = this.math.add(monthlyPayment, lifeInsuranceFee, propertyInsuranceFee); // falta incluir a cobdebtor
75
+ var insurancePeriods = this.insuranceService.getInsurancePeriods(inputs.IPCAmap, inputs.paymentNumber.value(), inputs.numberOfMonths.value());
76
+ var debtorLifeInsuranceFee = this.insuranceService.getInsuranceFee(balance, params.debtorLifeInsuranceRate, insurancePeriods);
77
+ var codebtorLifeInsuranceFee = params.codebtorLifeInsuranceRate ? this.insuranceService.getInsuranceFee(balance, params.codebtorLifeInsuranceRate, insurancePeriods) : 0;
78
+ var propertyInsuranceFee = this.insuranceService.getInsuranceFee(inputs.propertyAmount, params.propertyInsuranceRate, insurancePeriods);
79
+ var monthlyPaymentWithInsurances = this.math.add(monthlyPayment, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee);
78
80
  return {
79
- totalMonthlyPayment: totalMonthlyPayment,
80
81
  IPCAByDates: IPCAByDates,
81
82
  balanceValues: balanceValues,
82
83
  balance: balance,
@@ -88,7 +89,8 @@ var InstallmentService = /** @class */ (function () {
88
89
  monthlyPaymentWithInsurances: monthlyPaymentWithInsurances,
89
90
  amortization: amortization,
90
91
  amortizationIPCA: amortizationIPCA,
91
- lifeInsuranceFee: lifeInsuranceFee,
92
+ debtorLifeInsuranceFee: debtorLifeInsuranceFee,
93
+ codebtorLifeInsuranceFee: codebtorLifeInsuranceFee,
92
94
  propertyInsuranceFee: propertyInsuranceFee
93
95
  };
94
96
  };
@@ -3,16 +3,11 @@ import { CreditInsuranceRate } from '../../shared/models/credit-insurance-rate';
3
3
  export declare class InsuranceService {
4
4
  private readonly math;
5
5
  constructor(math: MathService);
6
+ getInsurancePeriods(IPCAmap: any, paymentNumber: number, numberOfMonths: number): number;
6
7
  /**
7
- * Calcula el seguro de propiedad
8
+ * Calcula el cobro de un seguro
8
9
  * @param propertyAmount
9
10
  * @param propertyInsuranceRate
10
11
  */
11
- getPropertyInsurance(propertyAmount: number, propertyInsuranceRate: CreditInsuranceRate, IPCAmap: Record<string, number>): number;
12
- /**
13
- * Calcula el seguro de vida
14
- * @param lifeInsuranceRateValues // Array con una sola posición ya que la tasa es fija en la operacion de un cliente
15
- * @param balance // Balance actualizado por corrección monetaria
16
- */
17
- getLifeInsurance(lifeInsuranceRateValues: CreditInsuranceRate[], balance: number): number;
12
+ getInsuranceFee(baseAmount: number, insuranceRate: CreditInsuranceRate, insurancePeriods: number): number;
18
13
  }
@@ -8,44 +8,33 @@ var InsuranceService = /** @class */ (function () {
8
8
  this.math = math;
9
9
  this.math = new math_1.MathService(true, 10);
10
10
  }
11
- /**
12
- * Calcula el seguro de propiedad
13
- * @param propertyAmount
14
- * @param propertyInsuranceRate
15
- */
16
- InsuranceService.prototype.getPropertyInsurance = function (propertyAmount, propertyInsuranceRate, IPCAmap) {
11
+ InsuranceService.prototype.getInsurancePeriods = function (IPCAmap, paymentNumber, numberOfMonths) {
17
12
  var _this = this;
18
- guarder_1.Guarder.defined(propertyInsuranceRate, 'CreditInsuranceRate');
19
- var getLifeInsurancePeriods = function (IPCAmap) {
20
- var result = Object.keys(IPCAmap)
21
- .map(function (date) {
22
- var days = date.split(',').map(function (strNum) { return parseInt(strNum, 10); }).pop();
23
- return days > 5 ? 1 : 2;
24
- })
25
- .reduce(function (a, b) { return _this.math.add(a, b); }, 0);
26
- return result - 1;
27
- };
28
- var lifeInsurancePeriods = getLifeInsurancePeriods(IPCAmap);
29
- if (propertyInsuranceRate.value() === 0)
30
- throw new Error('Invalid property insurance rate');
31
- var propertyInsurance = this.math.multiply(propertyAmount, this.math.divide(propertyInsuranceRate.value(), 100));
32
- return this.math.round(this.math.multiply(propertyInsurance, lifeInsurancePeriods), 2);
13
+ if (paymentNumber === numberOfMonths) {
14
+ return 0;
15
+ }
16
+ if (paymentNumber !== 1) {
17
+ return 1;
18
+ }
19
+ var result = Object.keys(IPCAmap)
20
+ .map(function (date) {
21
+ var days = date.split(',').map(function (strNum) { return parseInt(strNum, 10); }).pop();
22
+ return days > 5 ? 1 : 2;
23
+ })
24
+ .reduce(function (a, b) { return _this.math.add(a, b); }, 0);
25
+ return result - 1;
33
26
  };
34
27
  /**
35
- * Calcula el seguro de vida
36
- * @param lifeInsuranceRateValues // Array con una sola posición ya que la tasa es fija en la operacion de un cliente
37
- * @param balance // Balance actualizado por corrección monetaria
28
+ * Calcula el cobro de un seguro
29
+ * @param propertyAmount
30
+ * @param propertyInsuranceRate
38
31
  */
39
- InsuranceService.prototype.getLifeInsurance = function (lifeInsuranceRateValues, balance) {
40
- var _this = this;
41
- guarder_1.Guarder.defined(lifeInsuranceRateValues, 'CreditInsuranceRate');
42
- if (lifeInsuranceRateValues.filter(function (lifeInsuranceRate) { return lifeInsuranceRate.value() === 0; }).length > 0)
43
- throw new Error('Invalid life insurance rate');
44
- var lifeInsurance = lifeInsuranceRateValues
45
- .reduce(function (acc, lifeInsuranceRate) { return _this.math.multiply(balance, _this.math.divide(lifeInsuranceRate.value(), 100)); }, 0); // Multiplicar por los meses de
46
- // const lifeInsurance = this.math.multiply(this.math.subtract(balance, inflationaryBoundDifference), this.math.divide(lifeInsuranceRate.value(), 100));
47
- var result = this.math.round(lifeInsurance, 2);
48
- return result;
32
+ InsuranceService.prototype.getInsuranceFee = function (baseAmount, insuranceRate, insurancePeriods) {
33
+ guarder_1.Guarder.defined(insuranceRate, 'CreditInsuranceRate');
34
+ if (insuranceRate.value() === 0)
35
+ throw new Error('Invalid insurance rate');
36
+ var propertyInsurance = this.math.multiply(baseAmount, insuranceRate.value());
37
+ return this.math.round(this.math.multiply(propertyInsurance, insurancePeriods), 2);
49
38
  };
50
39
  return InsuranceService;
51
40
  }());
@@ -2,7 +2,6 @@ import { MathService } from '../../math';
2
2
  export declare class InterestService {
3
3
  private readonly math;
4
4
  constructor(math: MathService);
5
- private calculateDaysOfMonth;
6
5
  /**
7
6
  * Método que calcula el interés diario a partir del interés anual.
8
7
  * @param annyalRate Tasa de interés anual.
@@ -22,13 +21,17 @@ export declare class InterestService {
22
21
  * @returns
23
22
  */
24
23
  private getPeriodInterestValue;
25
- private findPeriodIndex;
24
+ /**
25
+ * Taking past month as base, returns days between start and end date over past month's total days
26
+ * @param startDate
27
+ * @param endDate
28
+ */
29
+ getProportionalDays(startDate: string, endDate: string): number;
26
30
  /**
27
31
  * Calcula el interes a partir del interes diario
28
32
  * @param balanceValues
29
33
  * @param annualRate
30
- * @param startDate
31
- * @param endDate
34
+ * @param proportion
32
35
  */
33
- getInterest(balanceValues: number[], annualRate: number, startDate: string, endDate: string, paymentNumber: number): number;
36
+ getInterest(balanceValues: number[], annualRate: number, proportion: number): number;
34
37
  }
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- // import { MathService } from '../../math';
3
- // import { PreviousBalance } from '../../shared/models/previous-balance';
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
3
  exports.InterestService = void 0;
6
4
  var creditu_date_model_1 = require("creditu-date-model");
@@ -8,24 +6,8 @@ var math_1 = require("../../math");
8
6
  var InterestService = /** @class */ (function () {
9
7
  function InterestService(math) {
10
8
  this.math = math;
11
- this.findPeriodIndex = function (periodArray, period) {
12
- var periodIndex;
13
- // eslint-disable-next-line no-loop-func
14
- periodArray.find(function (element, index) {
15
- if (element.period === period) {
16
- periodIndex = index;
17
- return true;
18
- }
19
- return false;
20
- });
21
- return periodIndex;
22
- };
23
9
  this.math = new math_1.MathService(true, 10);
24
10
  }
25
- // eslint-disable-next-line class-methods-use-this
26
- InterestService.prototype.calculateDaysOfMonth = function (year, month) {
27
- return new Date(year, month, 0).getDate();
28
- };
29
11
  /**
30
12
  * Método que calcula el interés diario a partir del interés anual.
31
13
  * @param annyalRate Tasa de interés anual.
@@ -57,44 +39,44 @@ var InterestService = /** @class */ (function () {
57
39
  return this.math.round(this.math.subtract(preResult, 1), 10);
58
40
  };
59
41
  /**
60
- * Calcula el interes a partir del interes diario
61
- * @param balanceValues
62
- * @param annualRate
42
+ * Taking past month as base, returns days between start and end date over past month's total days
63
43
  * @param startDate
64
44
  * @param endDate
65
45
  */
66
- InterestService.prototype.getInterest = function (balanceValues, annualRate, startDate, endDate, paymentNumber) {
46
+ InterestService.prototype.getProportionalDays = function (startDate, endDate) {
67
47
  var _this = this;
68
- var periodArray = [];
69
- var startDateModel = new creditu_date_model_1.DateModel(startDate);
70
- if (paymentNumber === 1) {
71
- startDateModel = startDateModel.addDays(1);
72
- }
48
+ var startDateModel = new creditu_date_model_1.DateModel(startDate).addDays(1);
73
49
  var endDateModel = new creditu_date_model_1.DateModel(endDate);
74
- while (startDateModel <= endDateModel) {
75
- var _a = startDateModel.toString().split('-'), year = _a[0], month = _a[1];
76
- var period = "".concat(year, "-").concat(month);
77
- var periodIndex = this.findPeriodIndex(periodArray, period);
78
- if (periodIndex === undefined) {
79
- periodArray.push({ period: period, days: 1 });
50
+ var periodArray = [];
51
+ var _loop_1 = function () {
52
+ var _b = startDateModel.toString().split('-'), year_1 = _b[0], month_1 = _b[1];
53
+ var currentPeriod = "".concat(year_1, "-").concat(month_1);
54
+ var periodIndex = periodArray.findIndex(function (periodObject) { return periodObject.period === currentPeriod; });
55
+ if (periodIndex === -1) {
56
+ periodArray.push({ currentPeriod: currentPeriod, days: 1 });
80
57
  }
81
58
  else {
82
59
  periodArray[periodIndex].days += 1;
83
60
  }
84
61
  startDateModel = startDateModel.addDays(1);
62
+ };
63
+ while (startDateModel <= endDateModel) {
64
+ _loop_1();
85
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
+ return periodArray.reduce(function (proportion, element) { return proportion + _this.math.multiply(_this.math.divide(1, daysOfMonth), element.days); }, 0);
71
+ };
72
+ /**
73
+ * Calcula el interes a partir del interes diario
74
+ * @param balanceValues
75
+ * @param annualRate
76
+ * @param proportion
77
+ */
78
+ InterestService.prototype.getInterest = function (balanceValues, annualRate, proportion) {
86
79
  var interest = this.math.multiply(balanceValues[balanceValues.length - 1], this.getMonthlyInterestValue(annualRate));
87
- var proportion = 1;
88
- if (paymentNumber === 1) {
89
- // 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.
90
- var yearMonth = periodArray[periodArray.length - 2].period.split('-');
91
- var daysOfMonth_1 = this.calculateDaysOfMonth(yearMonth[0], yearMonth[1]);
92
- proportion = periodArray.reduce(function (proportion, element) {
93
- // eslint-disable-next-line no-param-reassign
94
- proportion += _this.math.multiply(_this.math.divide(1, daysOfMonth_1), element.days);
95
- return proportion;
96
- }, 0);
97
- }
98
80
  return this.math.round(this.math.multiply(interest, proportion), 2);
99
81
  };
100
82
  return InterestService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creditu-common-library",
3
- "version": "1.2.7",
3
+ "version": "1.2.10",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -13,8 +13,6 @@ describe('installment-service for german method', () => {
13
13
  // revisado el 31-01-2022
14
14
  it('(WEDSON (Case 0.001 inflationaryUpperBound) should return the calculated installment', () => {
15
15
  const expectedResult = {
16
-
17
- totalMonthlyPayment: 846.62713637,
18
16
  IPCAByDates: [
19
17
  { date: '2021-12-23', ipca: 0.0125, dailyIPCA: 0.0004008068 },
20
18
  { date: '2021-12-24', ipca: 0.0125, dailyIPCA: 0.0004008068 },
@@ -84,7 +82,8 @@ describe('installment-service for german method', () => {
84
82
  monthlyPaymentWithInsurances: 846.62713637,
85
83
  amortization: 361.70713637,
86
84
  amortizationIPCA: 127.89,
87
- lifeInsuranceFee: 22.14,
85
+ debtorLifeInsuranceFee: 22.14,
86
+ codebtorLifeInsuranceFee: 0,
88
87
  propertyInsuranceFee: 4.8
89
88
  };
90
89
 
@@ -93,10 +92,10 @@ describe('installment-service for german method', () => {
93
92
  const numberOfMonths = new NumberOfMonths(360);
94
93
  const previousBalance = new PreviousBalance(129600);
95
94
  const annualRate = 0.075;
96
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
95
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
97
96
  const inflationaryUpperBound = 0.001;
98
97
  const propertyAmount = 160000;
99
- const propertyInsuranceRate = new CreditInsuranceRate(0.003);
98
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
100
99
  const IPCAmap = {
101
100
  '2021-12-23': 0.0125,
102
101
  '2022-01-05': 0.0095
@@ -112,7 +111,7 @@ describe('installment-service for german method', () => {
112
111
  };
113
112
  const params: DebtParams = {
114
113
  annualRate,
115
- lifeInsuranceRates,
114
+ debtorLifeInsuranceRate,
116
115
  propertyInsuranceRate
117
116
  };
118
117
  const result = service.getTotalMonthlyPayment(inputs, params);
@@ -120,7 +119,6 @@ describe('installment-service for german method', () => {
120
119
  });
121
120
  it('(WEDSON (Case 1 inflationaryUpperBound) should return the calculated installment', () => {
122
121
  const expectedResult = {
123
- totalMonthlyPayment: 1331.596229564,
124
122
  IPCAByDates: [
125
123
  { date: '2021-12-23', ipca: 0.0125, dailyIPCA: 0.0004008068 },
126
124
  { date: '2021-12-24', ipca: 0.0125, dailyIPCA: 0.0004008068 },
@@ -182,18 +180,19 @@ describe('installment-service for german method', () => {
182
180
  monthlyPaymentWithInsurances: 1331.596229564,
183
181
  amortization: 361.70713637,
184
182
  amortizationIPCA: 612.859093194,
185
- lifeInsuranceFee: 22.14,
186
- propertyInsuranceFee: 4.8
183
+ debtorLifeInsuranceFee: 22.14,
184
+ propertyInsuranceFee: 4.8,
185
+ codebtorLifeInsuranceFee: 0
187
186
  };
188
187
  const amortizationMethod = AmortizationMethod.GERMAN;
189
188
  const paymentNumber = new PaymentNumber(1);
190
189
  const numberOfMonths = new NumberOfMonths(360);
191
190
  const previousBalance = new PreviousBalance(129600);
192
191
  const annualRate = 0.075;
193
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
192
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
194
193
  const inflationaryUpperBound = 1;
195
194
  const propertyAmount = 160000;
196
- const propertyInsuranceRate = new CreditInsuranceRate(0.003);
195
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
197
196
  const IPCAmap = {
198
197
  '2021-12-23': 0.0125,
199
198
  '2022-01-05': 0.0095
@@ -209,7 +208,7 @@ describe('installment-service for german method', () => {
209
208
  };
210
209
  const params: DebtParams = {
211
210
  annualRate,
212
- lifeInsuranceRates,
211
+ debtorLifeInsuranceRate,
213
212
  propertyInsuranceRate
214
213
  };
215
214
  const result = service.getTotalMonthlyPayment(inputs, params);
@@ -218,7 +217,6 @@ describe('installment-service for german method', () => {
218
217
  });
219
218
  it('(WEDSON (Case 1 inflationaryUpperBound) should return the calculated installment with 1 day late', () => {
220
219
  const expectedResult = {
221
- totalMonthlyPayment: 1331.596229564,
222
220
  IPCAByDates: [
223
221
  { date: '2021-12-23', ipca: 0.0125, dailyIPCA: 0.0004008068 },
224
222
  { date: '2021-12-24', ipca: 0.0125, dailyIPCA: 0.0004008068 },
@@ -280,16 +278,17 @@ describe('installment-service for german method', () => {
280
278
  monthlyPaymentWithInsurances: 1331.596229564,
281
279
  amortization: 361.70713637,
282
280
  amortizationIPCA: 612.859093194,
283
- lifeInsuranceFee: 22.14,
284
- propertyInsuranceFee: 4.8
281
+ debtorLifeInsuranceFee: 22.14,
282
+ propertyInsuranceFee: 4.8,
283
+ codebtorLifeInsuranceFee: 0
285
284
  };
286
285
 
287
286
  const expectedLateResult = {
288
- totalMonthlyPayment: 1359.329374117,
289
287
  lateInterest: 0.2675321969,
290
288
  lateAmotizationIPCA: 0.4062055604,
291
289
  lateChargesInterest: 0.4274822044,
292
- lateDays: 1
290
+ lateDays: 1,
291
+ totalMonthlyPayment: 1359.329374117
293
292
  };
294
293
 
295
294
  const amortizationMethod = AmortizationMethod.GERMAN;
@@ -297,10 +296,10 @@ describe('installment-service for german method', () => {
297
296
  const numberOfMonths = new NumberOfMonths(360);
298
297
  const previousBalance = new PreviousBalance(129600);
299
298
  const annualRate = 0.075;
300
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
299
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
301
300
  const inflationaryUpperBound = 1;
302
301
  const propertyAmount = 160000;
303
- const propertyInsuranceRate = new CreditInsuranceRate(0.003);
302
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
304
303
  const IPCAmap = {
305
304
  '2021-12-23': 0.0125,
306
305
  '2022-01-05': 0.0095
@@ -316,7 +315,7 @@ describe('installment-service for german method', () => {
316
315
  };
317
316
  const params: DebtParams = {
318
317
  annualRate,
319
- lifeInsuranceRates,
318
+ debtorLifeInsuranceRate,
320
319
  propertyInsuranceRate
321
320
  };
322
321
  const result = service.getTotalMonthlyPayment(inputs, params);
@@ -337,7 +336,6 @@ describe('installment-service for german method', () => {
337
336
  });
338
337
  it('(Cuota > 1 (no es la primera cuota) WEDSON (Case 1 inflationaryUpperBound) should return the calculated installment', () => {
339
338
  const expectedResult = {
340
- totalMonthlyPayment: 2373.7405888545,
341
339
  IPCAByDates: [
342
340
  { date: '2021-01-06', ipca: 0.0095, dailyIPCA: 0.0003050516 },
343
341
  { date: '2021-01-07', ipca: 0.0095, dailyIPCA: 0.0003050516 },
@@ -425,18 +423,19 @@ describe('installment-service for german method', () => {
425
423
  monthlyPaymentWithInsurances: 2373.7405888545,
426
424
  amortization: 363.3378071913,
427
425
  amortizationIPCA: 1194.9427816632,
428
- lifeInsuranceFee: 22.17,
429
- propertyInsuranceFee: 4.8
426
+ debtorLifeInsuranceFee: 22.17,
427
+ propertyInsuranceFee: 4.8,
428
+ codebtorLifeInsuranceFee: 0
430
429
  };
431
430
  const amortizationMethod = AmortizationMethod.GERMAN;
432
431
  const paymentNumber = new PaymentNumber(2);
433
432
  const numberOfMonths = new NumberOfMonths(360);
434
433
  const previousBalance = new PreviousBalance(129240.00);
435
434
  const annualRate = 0.075;
436
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
435
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
437
436
  const inflationaryUpperBound = 1;
438
437
  const propertyAmount = 160000;
439
- const propertyInsuranceRate = new CreditInsuranceRate(0.003);
438
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
440
439
  const IPCAmap = {
441
440
  '2021-01-05': 0.0095,
442
441
  '2022-02-05': 0.0073
@@ -452,7 +451,7 @@ describe('installment-service for german method', () => {
452
451
  };
453
452
  const params: DebtParams = {
454
453
  annualRate,
455
- lifeInsuranceRates,
454
+ debtorLifeInsuranceRate,
456
455
  propertyInsuranceRate
457
456
  };
458
457
  const result = service.getTotalMonthlyPayment(inputs, params);
@@ -460,7 +459,6 @@ describe('installment-service for german method', () => {
460
459
  });
461
460
  it('(Cuota > 1 WEDSON (Case 0.005 inflationaryUpperBound) should return the calculated installment', () => {
462
461
  const expectedResult = {
463
- totalMonthlyPayment: 1821.6678071913,
464
462
  IPCAByDates: [
465
463
  { date: '2021-01-06', ipca: 0.0095, dailyIPCA: 0.0003050516 },
466
464
  { date: '2021-01-07', ipca: 0.0095, dailyIPCA: 0.0003050516 },
@@ -562,18 +560,19 @@ describe('installment-service for german method', () => {
562
560
  monthlyPaymentWithInsurances: 1821.6678071913,
563
561
  amortization: 363.3378071913,
564
562
  amortizationIPCA: 642.87,
565
- lifeInsuranceFee: 22.17,
566
- propertyInsuranceFee: 4.8
563
+ debtorLifeInsuranceFee: 22.17,
564
+ propertyInsuranceFee: 4.8,
565
+ codebtorLifeInsuranceFee: 0
567
566
  };
568
567
  const amortizationMethod = AmortizationMethod.GERMAN;
569
568
  const paymentNumber = new PaymentNumber(2);
570
569
  const numberOfMonths = new NumberOfMonths(360);
571
570
  const previousBalance = new PreviousBalance(129240);
572
571
  const annualRate = 0.075;
573
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
572
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
574
573
  const inflationaryUpperBound = 0.005;
575
574
  const propertyAmount = 160000;
576
- const propertyInsuranceRate = new CreditInsuranceRate(0.003);
575
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
577
576
  const IPCAmap = {
578
577
  '2021-01-05': 0.0095,
579
578
  '2022-02-05': 0.0073
@@ -589,7 +588,7 @@ describe('installment-service for german method', () => {
589
588
  };
590
589
  const params: DebtParams = {
591
590
  annualRate,
592
- lifeInsuranceRates,
591
+ debtorLifeInsuranceRate,
593
592
  propertyInsuranceRate
594
593
  };
595
594
  const result = service.getTotalMonthlyPayment(inputs, params);
@@ -602,7 +601,7 @@ describe('installment-service for german method', () => {
602
601
  const numberOfMonths = new NumberOfMonths(360);
603
602
  const previousBalance = new PreviousBalance(319480.48); /// 319,480.48
604
603
  const annualRate = 0.08;
605
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
604
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.017);
606
605
  const inflationaryUpperBound = 0.001;
607
606
  const propertyAmount = 369000;
608
607
  const propertyInsuranceRate = new CreditInsuranceRate(0.003); // esta como % en el excel
@@ -622,11 +621,10 @@ describe('installment-service for german method', () => {
622
621
  };
623
622
  const params: DebtParams = {
624
623
  annualRate,
625
- lifeInsuranceRates,
624
+ debtorLifeInsuranceRate,
626
625
  propertyInsuranceRate
627
626
  };
628
627
  const expectedResult = {
629
- totalMonthlyPayment: 4563.8038372939,
630
628
  IPCAByDates: [
631
629
  { date: '2021-11-19', ipca: 0.0116, dailyIPCA: 0.0003845151 },
632
630
  { date: '2021-11-20', ipca: 0.0116, dailyIPCA: 0.0003845151 },
@@ -760,8 +758,9 @@ describe('installment-service for german method', () => {
760
758
  monthlyPaymentWithInsurances: 4563.8038372939,
761
759
  amortization: 903.7238372939,
762
760
  amortizationIPCA: 303.2,
763
- lifeInsuranceFee: 55.31,
764
- propertyInsuranceFee: 22.14
761
+ debtorLifeInsuranceFee: 55.31,
762
+ propertyInsuranceFee: 22.14,
763
+ codebtorLifeInsuranceFee: 0
765
764
  };
766
765
 
767
766
  const result = service.getTotalMonthlyPayment(inputs, params);
@@ -769,7 +768,6 @@ describe('installment-service for german method', () => {
769
768
  });
770
769
  it('WEDSON (Case internal backend) should return the calculated installment without dueLate', () => {
771
770
  const expectedResult = {
772
- totalMonthlyPayment: 1821.6678071913,
773
771
  IPCAByDates: [
774
772
  { date: '2022-01-06', ipca: 0.0095, dailyIPCA: 0.0003050516 },
775
773
  { date: '2022-01-07', ipca: 0.0095, dailyIPCA: 0.0003050516 },
@@ -871,8 +869,9 @@ describe('installment-service for german method', () => {
871
869
  monthlyPaymentWithInsurances: 1821.6678071913,
872
870
  amortization: 363.3378071913,
873
871
  amortizationIPCA: 642.87,
874
- lifeInsuranceFee: 22.17,
875
- propertyInsuranceFee: 4.8
872
+ debtorLifeInsuranceFee: 22.17,
873
+ propertyInsuranceFee: 4.8,
874
+ codebtorLifeInsuranceFee: 0
876
875
  };
877
876
 
878
877
  const amortizationMethod = AmortizationMethod.GERMAN;
@@ -880,10 +879,10 @@ describe('installment-service for german method', () => {
880
879
  const numberOfMonths = new NumberOfMonths(360);
881
880
  const previousBalance = new PreviousBalance(129240.00);
882
881
  const annualRate = 0.075;
883
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
882
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
884
883
  const inflationaryUpperBound = 0.005;
885
884
  const propertyAmount = 160000;
886
- const propertyInsuranceRate = new CreditInsuranceRate(0.003);
885
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
887
886
  const IPCAmap = { '2022-01-05': 0.0095, '2022-02-05': 0.0073 };
888
887
  const inputs: DebtInputs = {
889
888
  amortizationMethod,
@@ -896,18 +895,120 @@ describe('installment-service for german method', () => {
896
895
  };
897
896
  const params: DebtParams = {
898
897
  annualRate,
899
- lifeInsuranceRates,
898
+ debtorLifeInsuranceRate,
900
899
  propertyInsuranceRate
901
900
  };
902
901
  const result = service.getTotalMonthlyPayment(inputs, params);
903
902
  expect(result).toEqual(expectedResult);
904
903
  });
904
+ it('WEDSON caso productivo 1ra cuota', () => {
905
+ const expectedResult = {
906
+ IPCAByDates: [
907
+ { date: '2021-12-23', ipca: 0.0125, dailyIPCA: 0.0004008068 },
908
+ { date: '2021-12-24', ipca: 0.0125, dailyIPCA: 0.0004008068 },
909
+ { date: '2021-12-25', ipca: 0.0125, dailyIPCA: 0.0004008068 },
910
+ { date: '2021-12-26', ipca: 0.0125, dailyIPCA: 0.0004008068 },
911
+ { date: '2021-12-27', ipca: 0.0125, dailyIPCA: 0.0004008068 },
912
+ { date: '2021-12-28', ipca: 0.0125, dailyIPCA: 0.0004008068 },
913
+ { date: '2021-12-29', ipca: 0.0125, dailyIPCA: 0.0004008068 },
914
+ { date: '2021-12-30', ipca: 0.0125, dailyIPCA: 0.0004008068 },
915
+ { date: '2021-12-31', ipca: 0.0125, dailyIPCA: 0.0004008068 },
916
+ { date: '2022-01-01', ipca: 0.0095, dailyIPCA: 0.0003050516 },
917
+ { date: '2022-01-02', ipca: 0.0095, dailyIPCA: 0.0003050516 },
918
+ { date: '2022-01-03', ipca: 0.0095, dailyIPCA: 0.0003050516 },
919
+ { date: '2022-01-04', ipca: 0.0095, dailyIPCA: 0.0003050516 },
920
+ { date: '2022-01-05', ipca: 0.0095, dailyIPCA: 0.0003050516 }
921
+ ],
922
+ balanceValues: {
923
+ balances: [
924
+ 129651.94456128,
925
+ 129703.9099422934,
926
+ 129755.8961513849,
927
+ 129807.9031969025,
928
+ 129859.9310871976,
929
+ 129911.9798306249,
930
+ 129964.0494355425,
931
+ 130016.1399103118,
932
+ 130055.8015418173,
933
+ 130095.4752721669,
934
+ 130135.1611050514,
935
+ 130174.8590441628,
936
+ 130214.569093194
937
+ ],
938
+ balanceMonetaryUpdateValues: [
939
+ 51.94456128, 51.9653810134,
940
+ 51.9862090915, 52.0070455176,
941
+ 52.0278902951, 52.0487434273,
942
+ 52.0696049176, 52.0904747693,
943
+ 39.6616315055, 39.6737303496,
944
+ 39.6858328845, 39.6979391114,
945
+ 39.7100490312
946
+ ],
947
+ balanceUpperBoundMonetaryUpdateValues: [
948
+ 0, 0, 0, 0, 0, 0,
949
+ 0, 0, 0, 0, 0, 0,
950
+ 0
951
+ ],
952
+ inflationaryBoundDifferenceValues: [
953
+ 0, 0, 0, 0, 0, 0,
954
+ 0, 0, 0, 0, 0, 0,
955
+ 0
956
+ ]
957
+ },
958
+ balance: 130214.569093194,
959
+ balanceAfter: 129240.00286363,
960
+ ipcaUpdate: 614.569093194,
961
+ dailyRate: 0.0002009109,
962
+ interest: 330.09,
963
+ monthlyPayment: 1304.656229564,
964
+ monthlyPaymentWithInsurances: 1331.596229564,
965
+ amortization: 361.70713637,
966
+ amortizationIPCA: 612.859093194,
967
+ debtorLifeInsuranceFee: 22.14,
968
+ codebtorLifeInsuranceFee: 0,
969
+ propertyInsuranceFee: 4.8
970
+ };
971
+ const amortizationMethod = AmortizationMethod.GERMAN;
972
+ const paymentNumber = new PaymentNumber(1);
973
+ const numberOfMonths = new NumberOfMonths(360);
974
+ const previousBalance = new PreviousBalance(129600);
975
+ const annualRate = 0.075;
976
+ // const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017); // 0.00017
977
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017); // 0.00017
978
+ const inflationaryUpperBound = 1;
979
+ const propertyAmount = 160000;
980
+ // const propertyInsuranceRate = new CreditInsuranceRate(0.00003); // 0.00003
981
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003); // 0.00003
982
+ // const IPCAmap = { '2022-01-05': 0.0095, '2022-02-05': 0.0073 };
983
+ const IPCAmap = {
984
+ // '2021-12-23': 1.25,
985
+ '2021-12-23': 0.0125,
986
+ // '2022-01-05': 0.95,
987
+ '2022-01-05': 0.0095
988
+ };
989
+ const inputs: DebtInputs = {
990
+ amortizationMethod,
991
+ paymentNumber,
992
+ numberOfMonths,
993
+ previousBalance,
994
+ inflationaryUpperBound,
995
+ propertyAmount,
996
+ IPCAmap
997
+ };
998
+ const params: DebtParams = {
999
+ annualRate,
1000
+ debtorLifeInsuranceRate,
1001
+ propertyInsuranceRate
1002
+ };
1003
+ const result = service.getTotalMonthlyPayment(inputs, params);
1004
+ expect(expectedResult).toEqual(result);
1005
+ });
905
1006
  });
1007
+
906
1008
  describe('installment-service for french method', () => {
907
1009
  const service = new InstallmentService(new MathService(true, 10));
908
1010
  it('Alitio (inflationaryUpperBound 1) should return the calculated installment', () => {
909
1011
  const expectedResult = {
910
- totalMonthlyPayment: 5928.5651403922,
911
1012
  IPCAByDates: [
912
1013
  { date: '2022-01-19', ipca: 0.0095, dailyIPCA: 0.0003050516 },
913
1014
  { date: '2022-01-20', ipca: 0.0095, dailyIPCA: 0.0003050516 },
@@ -971,8 +1072,9 @@ describe('installment-service for french method', () => {
971
1072
  monthlyPaymentWithInsurances: 5928.5651403922,
972
1073
  amortization: 1638.6085052585,
973
1074
  amortizationIPCA: 2378.0766351337,
974
- lifeInsuranceFee: 82.01,
975
- propertyInsuranceFee: 25.35
1075
+ debtorLifeInsuranceFee: 82.01,
1076
+ propertyInsuranceFee: 25.35,
1077
+ codebtorLifeInsuranceFee: 0
976
1078
  };
977
1079
 
978
1080
  const amortizationMethod = AmortizationMethod.FRENCH;
@@ -980,10 +1082,10 @@ describe('installment-service for french method', () => {
980
1082
  const numberOfMonths = new NumberOfMonths(162);
981
1083
  const previousBalance = new PreviousBalance(480000.00); //
982
1084
  const annualRate = 0.085;
983
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
1085
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
984
1086
  const inflationaryUpperBound = 1;
985
1087
  const propertyAmount = 845000;
986
- const propertyInsuranceRate = new CreditInsuranceRate(0.003);
1088
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
987
1089
  const IPCAmap = { '2022-01-19': 0.0095, '2022-02-05': 0.0073 };
988
1090
  const inputs: DebtInputs = {
989
1091
  amortizationMethod,
@@ -996,7 +1098,7 @@ describe('installment-service for french method', () => {
996
1098
  };
997
1099
  const params: DebtParams = {
998
1100
  annualRate,
999
- lifeInsuranceRates,
1101
+ debtorLifeInsuranceRate,
1000
1102
  propertyInsuranceRate
1001
1103
  };
1002
1104
  const result = service.getTotalMonthlyPayment(inputs, params);
@@ -1006,7 +1108,6 @@ describe('installment-service for french method', () => {
1006
1108
  // Falla en el cálculo de la amortizationIPC
1007
1109
  it.skip('Lucia (inflationaryUpperBound 0.0049, installment 1) should return the calculated installment', () => {
1008
1110
  const expectedResult = {
1009
- totalMonthlyPayment: 971.3444273244,
1010
1111
  IPCAByDates: [
1011
1112
  { date: '2022-01-03', ipca: 0.0095, dailyIPCA: 0.0003050516 },
1012
1113
  { date: '2022-01-04', ipca: 0.0095, dailyIPCA: 0.0003050516 },
@@ -1112,8 +1213,9 @@ describe('installment-service for french method', () => {
1112
1213
  monthlyPaymentWithInsurances: 991.60, //
1113
1214
  amortization: 61.7244273244,
1114
1215
  amortizationIPCA: 388.01, //
1115
- lifeInsuranceFee: 13.46,
1116
- propertyInsuranceFee: 3
1216
+ debtorLifeInsuranceFee: 13.46,
1217
+ propertyInsuranceFee: 3,
1218
+ codebtorLifeInsuranceFee: 0
1117
1219
  };
1118
1220
 
1119
1221
  const amortizationMethod = AmortizationMethod.FRENCH;
@@ -1121,7 +1223,7 @@ describe('installment-service for french method', () => {
1121
1223
  const numberOfMonths = new NumberOfMonths(360);
1122
1224
  const previousBalance = new PreviousBalance(78410.25); //
1123
1225
  const annualRate = 0.0750;
1124
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
1226
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.017);
1125
1227
  const inflationaryUpperBound = 0.0049;
1126
1228
  const propertyAmount = 100000;
1127
1229
  const propertyInsuranceRate = new CreditInsuranceRate(0.003);
@@ -1137,7 +1239,7 @@ describe('installment-service for french method', () => {
1137
1239
  };
1138
1240
  const params: DebtParams = {
1139
1241
  annualRate,
1140
- lifeInsuranceRates,
1242
+ debtorLifeInsuranceRate,
1141
1243
  propertyInsuranceRate
1142
1244
  };
1143
1245
  const result = service.getTotalMonthlyPayment(inputs, params);
@@ -1146,7 +1248,6 @@ describe('installment-service for french method', () => {
1146
1248
  // Falla en el cálculo de la amortizationIPC
1147
1249
  it.skip('Sylvio (inflationaryUpperBound 0.0036, installment 1) should return the calculated installment', () => {
1148
1250
  const expectedResult = {
1149
- totalMonthlyPayment: 8785.6909025334,
1150
1251
  IPCAByDates: [
1151
1252
  { date: '2022-01-19', ipca: 0.0095, dailyIPCA: 0.0003050516 },
1152
1253
  { date: '2022-01-20', ipca: 0.0095, dailyIPCA: 0.0003050516 },
@@ -1224,8 +1325,9 @@ describe('installment-service for french method', () => {
1224
1325
  amortization: 869.3209025334,
1225
1326
  // amortizationIPCA: 3990.71,
1226
1327
  amortizationIPCA: 4010.57,
1227
- lifeInsuranceFee: 189.59,
1228
- propertyInsuranceFee: 39.09
1328
+ debtorLifeInsuranceFee: 189.59,
1329
+ propertyInsuranceFee: 39.09,
1330
+ codebtorLifeInsuranceFee: 0
1229
1331
  };
1230
1332
 
1231
1333
  const amortizationMethod = AmortizationMethod.FRENCH;
@@ -1233,7 +1335,7 @@ describe('installment-service for french method', () => {
1233
1335
  const numberOfMonths = new NumberOfMonths(360);
1234
1336
  const previousBalance = new PreviousBalance(1109724.78); //
1235
1337
  const annualRate = 0.0750;
1236
- const lifeInsuranceRates = [new CreditInsuranceRate(0.017)];
1338
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.017);
1237
1339
  const inflationaryUpperBound = 0.0036;
1238
1340
  const propertyAmount = 1303000;
1239
1341
  const propertyInsuranceRate = new CreditInsuranceRate(0.003);
@@ -1249,7 +1351,7 @@ describe('installment-service for french method', () => {
1249
1351
  };
1250
1352
  const params: DebtParams = {
1251
1353
  annualRate,
1252
- lifeInsuranceRates,
1354
+ debtorLifeInsuranceRate,
1253
1355
  propertyInsuranceRate
1254
1356
  };
1255
1357
  const result = service.getTotalMonthlyPayment(inputs, params);