creditu-common-library 1.2.9 → 1.2.12

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.
@@ -35,4 +35,13 @@ export declare class DebtInputs {
35
35
  * Key: Date YYYY/MM/DD format, Value: number format
36
36
  */
37
37
  IPCAmap: Record<string, number>;
38
+ /**
39
+ * Mapa de IPCAs en el rango de fechas de la mora a calcular
40
+ * Key: Date YYYY/MM/DD format, Value: number format
41
+ */
42
+ IPCAmapLate: Record<string, number>;
43
+ /**
44
+ * Fecha a sobre la cuál se desea calcular la mora
45
+ */
46
+ today?: string;
38
47
  }
@@ -60,4 +60,20 @@ export declare class DebtResponse {
60
60
  * Cuota de seguro de incendio o propiedad
61
61
  */
62
62
  propertyInsuranceFee: number;
63
+ /**
64
+ * Valor de la cuota considerando los intereses y la mora
65
+ */
66
+ monthlyPaymentWithLate: number;
67
+ /**
68
+ * Días de mora
69
+ */
70
+ lateDays: number;
71
+ /**
72
+ * Interés en la mora
73
+ */
74
+ lateInterest: number;
75
+ /**
76
+ * Cargo por mora
77
+ */
78
+ lateCharges: number;
63
79
  }
@@ -11,6 +11,7 @@ export declare class InstallmentService {
11
11
  private readonly paymentService;
12
12
  private readonly interestService;
13
13
  private readonly balanceService;
14
+ private readonly lateService;
14
15
  private fixIPCAmap;
15
16
  /**
16
17
  * Calcula el total del pago mensual para una cuota
@@ -12,6 +12,7 @@ var payment_service_1 = require("./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");
15
+ var late_service_1 = require("./late.service");
15
16
  var InstallmentService = /** @class */ (function () {
16
17
  function InstallmentService(math) {
17
18
  this.math = math;
@@ -21,6 +22,7 @@ var InstallmentService = /** @class */ (function () {
21
22
  this.paymentService = new payment_service_1.PaymentService(this.math);
22
23
  this.interestService = new interest_service_1.InterestService(this.math);
23
24
  this.balanceService = new balance_service_1.BalanceService(this.math);
25
+ this.lateService = new late_service_1.LateService(this.math);
24
26
  this.math = new math_1.MathService(true, 10);
25
27
  }
26
28
  InstallmentService.prototype.fixIPCAmap = function (IPCAmap) {
@@ -55,7 +57,8 @@ var InstallmentService = /** @class */ (function () {
55
57
  var balance = this.balanceService.getBalance(balanceValues.balances);
56
58
  var startDate = Object.keys(inputs.IPCAmap)[0];
57
59
  var endDate = Object.keys(inputs.IPCAmap).pop();
58
- var interest = this.interestService.getInterest(balanceValues.balances, params.annualRate, startDate, endDate, inputs.paymentNumber.value());
60
+ var proportionalDays = inputs.paymentNumber.value() === 1 ? this.interestService.getProportionalDays(startDate, endDate) : 1;
61
+ var interest = this.interestService.getInterest(balanceValues.balances, params.annualRate, proportionalDays);
59
62
  var amortization;
60
63
  var amortizationDiff;
61
64
  if (inputs.amortizationMethod === amortization_method_enum_1.AmortizationMethod.GERMAN) {
@@ -71,10 +74,19 @@ var InstallmentService = /** @class */ (function () {
71
74
  var amortizationIPCA = this.amortizationService.getAmortizationIPC(inputs.previousBalance.value(), inputs.inflationaryUpperBound, amortizationDiff, ipcaUpdate);
72
75
  var monthlyPayment = this.paymentService.getMonthlyPayment(interest, amortization, amortizationIPCA);
73
76
  var balanceAfter = this.balanceService.getBalanceAfter(inputs.previousBalance, ipcaUpdate, amortization, amortizationIPCA);
74
- var debtorLifeInsuranceFee = this.insuranceService.getLifeInsurance(params.debtorLifeInsuranceRate, balance);
75
- var codebtorLifeInsuranceFee = params.codebtorLifeInsuranceRate ? this.insuranceService.getLifeInsurance(params.codebtorLifeInsuranceRate, balance) : 0;
76
- var propertyInsuranceFee = this.insuranceService.getPropertyInsurance(inputs.propertyAmount, params.propertyInsuranceRate, inputs.IPCAmap);
77
+ var insurancePeriods = this.insuranceService.getInsurancePeriods(inputs.IPCAmap, inputs.paymentNumber.value(), inputs.numberOfMonths.value());
78
+ var debtorLifeInsuranceFee = this.insuranceService.getInsuranceFee(balance, params.debtorLifeInsuranceRate, insurancePeriods);
79
+ var codebtorLifeInsuranceFee = params.codebtorLifeInsuranceRate ? this.insuranceService.getInsuranceFee(balance, params.codebtorLifeInsuranceRate, insurancePeriods) : 0;
80
+ var propertyInsuranceFee = this.insuranceService.getInsuranceFee(inputs.propertyAmount, params.propertyInsuranceRate, insurancePeriods);
77
81
  var monthlyPaymentWithInsurances = this.math.add(monthlyPayment, debtorLifeInsuranceFee, codebtorLifeInsuranceFee, propertyInsuranceFee);
82
+ // const totalLateByDates = lateService.getTotalMonthlyPayment(payment.dueDate, today,
83
+ // installment.monthlyPaymentWithInsurances, lateChargesFineRate,
84
+ // dailyInterestRate, IPCAmapLate, lateChargesInterestRate);
85
+ var lateChargesFineRate = params.lateChargesFineRate, lateChargesInterestRate = params.lateChargesInterestRate;
86
+ var IPCAmapLate = inputs.IPCAmapLate, todayIn = inputs.today;
87
+ var today = todayIn || new creditu_date_model_1.DateModel().toString();
88
+ var dailyInterestRate = this.interestService.getDailyInterestValue(params.annualRate);
89
+ var totalLateByDates = this.lateService.getTotalMonthlyPayment(endDate, today, monthlyPaymentWithInsurances, lateChargesFineRate, dailyInterestRate, IPCAmapLate, lateChargesInterestRate);
78
90
  return {
79
91
  IPCAByDates: IPCAByDates,
80
92
  balanceValues: balanceValues,
@@ -85,11 +97,15 @@ var InstallmentService = /** @class */ (function () {
85
97
  interest: interest,
86
98
  monthlyPayment: monthlyPayment,
87
99
  monthlyPaymentWithInsurances: monthlyPaymentWithInsurances,
100
+ monthlyPaymentWithLate: totalLateByDates.totalMonthlyPayment,
88
101
  amortization: amortization,
89
102
  amortizationIPCA: amortizationIPCA,
90
103
  debtorLifeInsuranceFee: debtorLifeInsuranceFee,
91
104
  codebtorLifeInsuranceFee: codebtorLifeInsuranceFee,
92
- propertyInsuranceFee: propertyInsuranceFee
105
+ propertyInsuranceFee: propertyInsuranceFee,
106
+ lateDays: totalLateByDates.lateDays,
107
+ lateInterest: totalLateByDates.lateInterest,
108
+ lateCharges: totalLateByDates.lateChargesInterest
93
109
  };
94
110
  };
95
111
  return InstallmentService;
@@ -4,15 +4,16 @@ export declare class InsuranceService {
4
4
  private readonly math;
5
5
  constructor(math: MathService);
6
6
  /**
7
- * Calcula el seguro de propiedad
8
- * @param propertyAmount
9
- * @param propertyInsuranceRate
7
+ * Gives apropiate qty of months to apply insurances
8
+ * @param IPCAmap dates keyed object to know start and end dates
9
+ * @param paymentNumber to validate if it is first or last payment
10
+ * @param numberOfMonths to validate if it is last payment
10
11
  */
11
- getPropertyInsurance(propertyAmount: number, propertyInsuranceRate: CreditInsuranceRate, IPCAmap: Record<string, number>): number;
12
+ getInsurancePeriods(IPCAmap: any, paymentNumber: number, numberOfMonths: number): number;
12
13
  /**
13
- * Calcula el seguro de vida
14
- * @param lifeInsuranceRate // tasa sobre la que se calcula el valor de un seguro
15
- * @param balance // Balance actualizado por corrección monetaria
14
+ * Calcula el cobro de un seguro
15
+ * @param propertyAmount
16
+ * @param propertyInsuranceRate
16
17
  */
17
- getLifeInsurance(lifeInsuranceRate: CreditInsuranceRate, balance: number): number;
18
+ getInsuranceFee(baseAmount: number, insuranceRate: CreditInsuranceRate, insurancePeriods: number): number;
18
19
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InsuranceService = void 0;
4
+ var creditu_date_model_1 = require("creditu-date-model");
4
5
  var math_1 = require("../../math");
5
6
  var guarder_1 = require("../../shared/models/guarder");
6
7
  var InsuranceService = /** @class */ (function () {
@@ -9,40 +10,35 @@ var InsuranceService = /** @class */ (function () {
9
10
  this.math = new math_1.MathService(true, 10);
10
11
  }
11
12
  /**
12
- * Calcula el seguro de propiedad
13
- * @param propertyAmount
14
- * @param propertyInsuranceRate
13
+ * Gives apropiate qty of months to apply insurances
14
+ * @param IPCAmap dates keyed object to know start and end dates
15
+ * @param paymentNumber to validate if it is first or last payment
16
+ * @param numberOfMonths to validate if it is last payment
15
17
  */
16
- InsuranceService.prototype.getPropertyInsurance = function (propertyAmount, propertyInsuranceRate, IPCAmap) {
17
- 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, propertyInsuranceRate.value());
32
- return this.math.round(this.math.multiply(propertyInsurance, lifeInsurancePeriods), 2);
18
+ // eslint-disable-next-line class-methods-use-this
19
+ InsuranceService.prototype.getInsurancePeriods = function (IPCAmap, paymentNumber, numberOfMonths) {
20
+ if (paymentNumber === numberOfMonths) {
21
+ return 0;
22
+ }
23
+ if (paymentNumber !== 1) {
24
+ return 1;
25
+ }
26
+ var datesMap = Object.keys(IPCAmap);
27
+ var firstDate = new creditu_date_model_1.DateModel(datesMap[0]);
28
+ var lastDate = new creditu_date_model_1.DateModel(datesMap[datesMap.length - 1]);
29
+ return lastDate.monthsDiff(firstDate) + 2;
33
30
  };
34
31
  /**
35
- * Calcula el seguro de vida
36
- * @param lifeInsuranceRate // tasa sobre la que se calcula el valor de un seguro
37
- * @param balance // Balance actualizado por corrección monetaria
32
+ * Calcula el cobro de un seguro
33
+ * @param propertyAmount
34
+ * @param propertyInsuranceRate
38
35
  */
39
- InsuranceService.prototype.getLifeInsurance = function (lifeInsuranceRate, balance) {
40
- guarder_1.Guarder.defined(lifeInsuranceRate, 'CreditInsuranceRate');
41
- if (lifeInsuranceRate.value() === 0)
42
- throw new Error('Invalid life insurance rate');
43
- var lifeInsurance = this.math.multiply(balance, lifeInsuranceRate.value());
44
- var result = this.math.round(lifeInsurance, 2);
45
- return result;
36
+ InsuranceService.prototype.getInsuranceFee = function (baseAmount, insuranceRate, insurancePeriods) {
37
+ guarder_1.Guarder.defined(insuranceRate, 'CreditInsuranceRate');
38
+ if (insuranceRate.value() === 0)
39
+ throw new Error('Invalid insurance rate');
40
+ var propertyInsurance = this.math.multiply(baseAmount, insuranceRate.value());
41
+ return this.math.round(this.math.multiply(propertyInsurance, insurancePeriods), 2);
46
42
  };
47
43
  return InsuranceService;
48
44
  }());
@@ -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,46 @@ 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
+ 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;
73
+ };
74
+ /**
75
+ * Calcula el interes a partir del interes diario
76
+ * @param balanceValues
77
+ * @param annualRate
78
+ * @param proportion
79
+ */
80
+ InterestService.prototype.getInterest = function (balanceValues, annualRate, proportion) {
86
81
  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
82
  return this.math.round(this.math.multiply(interest, proportion), 2);
99
83
  };
100
84
  return InterestService;
@@ -7,7 +7,7 @@ export declare class LateService {
7
7
  private getDailyIPCA;
8
8
  getLate(dueDate: string, date: string, totalMonthlyPayment: number, rate: number): number;
9
9
  getLateChargesInterest(dueDate: string, date: string, totalMonthlyPayment: number, rate: number): number;
10
- getTotalLate(dueDate: string, date: string, totalMonthlyPayment: number, rateInterest: number, rateIPCA: number, rateChargesInterest: number): {
10
+ getTotalLate(dueDate: string, date: string, totalMonthlyPayment: number, dailyRateInterest: number, rateIPCA: number, lateChargesInterestRate: number): {
11
11
  lateInterest: number;
12
12
  lateAmotizationIPCA: number;
13
13
  lateChargesInterest: number;
@@ -20,7 +20,7 @@ export declare class LateService {
20
20
  */
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
- getTotalMonthlyPayment(dueDateIn: string, date: string, totalMonthlyPayment: number, rateCharges: number, rateInterest: number, ipcaValues: Record<string, number>, rateChargesInterest: number): {
23
+ getTotalMonthlyPayment(dueDateIn: string, date: string, totalMonthlyPayment: number, lateChargesFineRate: number, dailyInterestRate: number, ipcaValues: Record<string, number>, lateChargesInterestRate: number): {
24
24
  totalMonthlyPayment: any;
25
25
  lateInterest: any;
26
26
  lateAmotizationIPCA: any;
@@ -35,10 +35,10 @@ var LateService = /** @class */ (function () {
35
35
  var op3 = Math.pow(op1, op2);
36
36
  return this.math.multiply(totalMonthlyPayment, this.math.subtract(op3, 1));
37
37
  };
38
- LateService.prototype.getTotalLate = function (dueDate, date, totalMonthlyPayment, rateInterest, rateIPCA, rateChargesInterest) {
39
- var lateInterest = this.getLate(dueDate, date, totalMonthlyPayment, rateInterest);
38
+ LateService.prototype.getTotalLate = function (dueDate, date, totalMonthlyPayment, dailyRateInterest, rateIPCA, lateChargesInterestRate) {
39
+ var lateInterest = this.getLate(dueDate, date, totalMonthlyPayment, dailyRateInterest);
40
40
  var lateAmotizationIPCA = this.getLate(dueDate, date, totalMonthlyPayment, rateIPCA);
41
- var lateChargesInterest = this.getLateChargesInterest(dueDate, date, totalMonthlyPayment, rateChargesInterest);
41
+ var lateChargesInterest = this.getLateChargesInterest(dueDate, date, totalMonthlyPayment, lateChargesInterestRate);
42
42
  var updatedLateMonthlyPayment = this.math.add(totalMonthlyPayment, lateInterest, lateAmotizationIPCA, lateChargesInterest);
43
43
  return { lateInterest: lateInterest, lateAmotizationIPCA: lateAmotizationIPCA, lateChargesInterest: lateChargesInterest, updatedLateMonthlyPayment: updatedLateMonthlyPayment };
44
44
  };
@@ -71,19 +71,6 @@ var LateService = /** @class */ (function () {
71
71
  // eslint-disable-next-line max-len
72
72
  LateService.prototype.getTotalLateByDates = function (dueDate, date, totalMonthlyPayment, lateChargesFineRate, dailyRateInterest, ipcaValues, lateChargesInterestRate) {
73
73
  var _this = this;
74
- // console.log('file: late.service.ts ~ line 76 ~ date', date);
75
- // console.log('file: late.service.ts ~ line 76 ~ dueDate', dueDate);
76
- // const lateDays = new DateModel(date).daysDiff(new DateModel(dueDate));
77
- // if (lateDays <= 0) {
78
- // const result = {} as any;
79
- // result[date] = {
80
- // lateInterest: 0,
81
- // lateAmotizationIPCA: 0,
82
- // lateChargesInterest: 0,
83
- // updatedLateMonthlyPayment: totalMonthlyPayment
84
- // };
85
- // return [result];
86
- // }
87
74
  var lateDaysArray = this.getLateDaysAndIPCA(dueDate, date, ipcaValues);
88
75
  var lateCharges = this.getLate(dueDate, date, totalMonthlyPayment, lateChargesFineRate);
89
76
  var totalLateBefore = totalMonthlyPayment;
@@ -104,7 +91,7 @@ var LateService = /** @class */ (function () {
104
91
  return totalLateByDates;
105
92
  };
106
93
  // eslint-disable-next-line no-param-reassign
107
- LateService.prototype.getTotalMonthlyPayment = function (dueDateIn, date, totalMonthlyPayment, rateCharges, rateInterest, ipcaValues, rateChargesInterest) {
94
+ LateService.prototype.getTotalMonthlyPayment = function (dueDateIn, date, totalMonthlyPayment, lateChargesFineRate, dailyInterestRate, ipcaValues, lateChargesInterestRate) {
108
95
  var _this = this;
109
96
  var lateDays = new creditu_date_model_1.DateModel(date).daysDiff(new creditu_date_model_1.DateModel(dueDateIn));
110
97
  if (lateDays <= 0) {
@@ -117,7 +104,7 @@ var LateService = /** @class */ (function () {
117
104
  };
118
105
  }
119
106
  var dueDate = new creditu_date_model_1.DateModel(dueDateIn).addDays(1).toString();
120
- var totalLateByDates = this.getTotalLateByDates(dueDate, date, totalMonthlyPayment, rateCharges, rateInterest, ipcaValues, rateChargesInterest);
107
+ var totalLateByDates = this.getTotalLateByDates(dueDate, date, totalMonthlyPayment, lateChargesFineRate, dailyInterestRate, ipcaValues, lateChargesInterestRate);
121
108
  var _a = totalLateByDates.reduce(function (sum, item) {
122
109
  var _a = Object.values(item).pop(), lateInterest = _a.lateInterest, lateAmotizationIPCA = _a.lateAmotizationIPCA, lateChargesInterest = _a.lateChargesInterest;
123
110
  sum.lateInterest = _this.math.add(sum.lateInterest, lateInterest);
@@ -20,9 +20,9 @@ var Operation;
20
20
  })(Operation || (Operation = {}));
21
21
  var MathService = /** @class */ (function () {
22
22
  function MathService(useRound, precision) {
23
- var _this = this;
24
23
  if (useRound === void 0) { useRound = true; }
25
24
  if (precision === void 0) { precision = 6; }
25
+ var _this = this;
26
26
  this.useRound = useRound;
27
27
  this.precision = precision;
28
28
  this.round = function (num, resolution) {
@@ -7,8 +7,8 @@ var finance_service_1 = require("./finance.service");
7
7
  var date_1 = require("../../util/date");
8
8
  var InstallmentService = /** @class */ (function () {
9
9
  function InstallmentService(math) {
10
- var _this = this;
11
10
  if (math === void 0) { math = new math_service_1.MathService(); }
11
+ var _this = this;
12
12
  this.math = math;
13
13
  this.finance = new finance_service_1.FinanceService(this.math);
14
14
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creditu-common-library",
3
- "version": "1.2.9",
3
+ "version": "1.2.12",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -21,10 +21,8 @@ var range_vo_config_1 = require("./range-vo-config");
21
21
  var InvestmentWeight = /** @class */ (function (_super) {
22
22
  __extends(InvestmentWeight, _super);
23
23
  function InvestmentWeight(value) {
24
- var _this = this;
25
24
  var config = new range_vo_config_1.RangeVoConfig(0, 1, false, true);
26
- _this = _super.call(this, 'InvestmentWeight', value, config) || this;
27
- return _this;
25
+ return _super.call(this, 'InvestmentWeight', value, config) || this;
28
26
  }
29
27
  return InvestmentWeight;
30
28
  }(range_vo_1.RangeVo));
@@ -3,7 +3,7 @@ import { NumberOfMonths } from '../src/shared/models/number-of-months';
3
3
  import { PreviousBalance } from '../src/shared/models/previous-balance';
4
4
  import { DebtInputs } from '../src/debt/models/dto/debt-inputs.dto';
5
5
  import { DebtParams } from '../src/debt/models/dto/debt-params.dto';
6
- import { InstallmentService, LateService } from '../src/debt/services';
6
+ import { InstallmentService } from '../src/debt/services';
7
7
  import { MathService } from '../src/math';
8
8
  import { CreditInsuranceRate } from '../src/shared/models/credit-insurance-rate';
9
9
  import { PaymentNumber } from '../src/shared/models/payment-number';
@@ -79,12 +79,16 @@ describe('installment-service for german method', () => {
79
79
  dailyRate: 0.0002009109,
80
80
  interest: 330.09,
81
81
  monthlyPayment: 819.68713637,
82
- monthlyPaymentWithInsurances: 846.62713637,
82
+ monthlyPaymentWithInsurances: 873.55713637,
83
83
  amortization: 361.70713637,
84
84
  amortizationIPCA: 127.89,
85
- debtorLifeInsuranceFee: 22.14,
85
+ debtorLifeInsuranceFee: 44.27,
86
86
  codebtorLifeInsuranceFee: 0,
87
- propertyInsuranceFee: 4.8
87
+ propertyInsuranceFee: 9.6,
88
+ monthlyPaymentWithLate: 873.55713637,
89
+ lateCharges: 0,
90
+ lateDays: 0,
91
+ lateInterest: 0
88
92
  };
89
93
 
90
94
  const amortizationMethod = AmortizationMethod.GERMAN;
@@ -107,7 +111,9 @@ describe('installment-service for german method', () => {
107
111
  previousBalance,
108
112
  inflationaryUpperBound,
109
113
  propertyAmount,
110
- IPCAmap
114
+ IPCAmap,
115
+ IPCAmapLate: { '2022-01-05': 0.0095 },
116
+ today: '2022-01-05'
111
117
  };
112
118
  const params: DebtParams = {
113
119
  annualRate,
@@ -177,12 +183,16 @@ describe('installment-service for german method', () => {
177
183
  dailyRate: 0.0002009109,
178
184
  interest: 330.09,
179
185
  monthlyPayment: 1304.656229564,
180
- monthlyPaymentWithInsurances: 1331.596229564,
186
+ monthlyPaymentWithInsurances: 1358.526229564,
181
187
  amortization: 361.70713637,
182
188
  amortizationIPCA: 612.859093194,
183
- debtorLifeInsuranceFee: 22.14,
184
- propertyInsuranceFee: 4.8,
185
- codebtorLifeInsuranceFee: 0
189
+ debtorLifeInsuranceFee: 44.27,
190
+ codebtorLifeInsuranceFee: 0,
191
+ propertyInsuranceFee: 9.6,
192
+ monthlyPaymentWithLate: 1358.526229564,
193
+ lateCharges: 0,
194
+ lateDays: 0,
195
+ lateInterest: 0
186
196
  };
187
197
  const amortizationMethod = AmortizationMethod.GERMAN;
188
198
  const paymentNumber = new PaymentNumber(1);
@@ -204,7 +214,9 @@ describe('installment-service for german method', () => {
204
214
  previousBalance,
205
215
  inflationaryUpperBound,
206
216
  propertyAmount,
207
- IPCAmap
217
+ IPCAmap,
218
+ IPCAmapLate: { '2022-01-05': 0.0095 },
219
+ today: '2022-01-05'
208
220
  };
209
221
  const params: DebtParams = {
210
222
  annualRate,
@@ -212,7 +224,6 @@ describe('installment-service for german method', () => {
212
224
  propertyInsuranceRate
213
225
  };
214
226
  const result = service.getTotalMonthlyPayment(inputs, params);
215
- // console.log('file: installment.service.spec.ts ~ line 216 ~ result', result);
216
227
  expect(result).toEqual(expectedResult);
217
228
  });
218
229
  it('(WEDSON (Case 1 inflationaryUpperBound) should return the calculated installment with 1 day late', () => {
@@ -275,20 +286,16 @@ describe('installment-service for german method', () => {
275
286
  dailyRate: 0.0002009109,
276
287
  interest: 330.09,
277
288
  monthlyPayment: 1304.656229564,
278
- monthlyPaymentWithInsurances: 1331.596229564,
289
+ monthlyPaymentWithInsurances: 1358.526229564,
279
290
  amortization: 361.70713637,
280
291
  amortizationIPCA: 612.859093194,
281
- debtorLifeInsuranceFee: 22.14,
282
- propertyInsuranceFee: 4.8,
283
- codebtorLifeInsuranceFee: 0
284
- };
285
-
286
- const expectedLateResult = {
287
- lateInterest: 0.2675321969,
288
- lateAmotizationIPCA: 0.4062055604,
289
- lateChargesInterest: 0.4274822044,
292
+ debtorLifeInsuranceFee: 44.27,
293
+ codebtorLifeInsuranceFee: 0,
294
+ propertyInsuranceFee: 9.6,
295
+ lateInterest: 0.2729427275,
296
+ lateCharges: 0.4361275396,
290
297
  lateDays: 1,
291
- totalMonthlyPayment: 1359.329374117
298
+ monthlyPaymentWithLate: 1386.8202450224
292
299
  };
293
300
 
294
301
  const amortizationMethod = AmortizationMethod.GERMAN;
@@ -311,28 +318,19 @@ describe('installment-service for german method', () => {
311
318
  previousBalance,
312
319
  inflationaryUpperBound,
313
320
  propertyAmount,
314
- IPCAmap
321
+ IPCAmap,
322
+ IPCAmapLate: { '2022-01-05': 0.0095 },
323
+ today: '2022-01-06'
315
324
  };
316
325
  const params: DebtParams = {
317
326
  annualRate,
318
327
  debtorLifeInsuranceRate,
319
- propertyInsuranceRate
328
+ propertyInsuranceRate,
329
+ lateChargesFineRate: 0.02,
330
+ lateChargesInterestRate: 0.01
320
331
  };
321
332
  const result = service.getTotalMonthlyPayment(inputs, params);
322
- // console.log('file: installment.service.spec.ts ~ line 216 ~ result', result);
323
333
  expect(result).toEqual(expectedResult);
324
-
325
- const totalMonthlyPayment = result.monthlyPaymentWithInsurances;
326
- const dueDate = '2022-01-05';
327
- const today = '2022-01-06';
328
- // 1331.60, 0.02, 0.0002009109
329
- const rateCharges = 0.02;
330
- const rateChargesInterest = 0.01;
331
- const dailyRateInterest = 0.0002009109;
332
- const ipcaMapLate = { '2022-01-05': 0.0095 };
333
- const lateService = new LateService(new MathService(true, 6));
334
- const resultLate = lateService.getTotalMonthlyPayment(dueDate, today, totalMonthlyPayment, rateCharges, dailyRateInterest, ipcaMapLate, rateChargesInterest);
335
- expect(resultLate).toEqual(expectedLateResult);
336
334
  });
337
335
  it('(Cuota > 1 (no es la primera cuota) WEDSON (Case 1 inflationaryUpperBound) should return the calculated installment', () => {
338
336
  const expectedResult = {
@@ -425,7 +423,11 @@ describe('installment-service for german method', () => {
425
423
  amortizationIPCA: 1194.9427816632,
426
424
  debtorLifeInsuranceFee: 22.17,
427
425
  propertyInsuranceFee: 4.8,
428
- codebtorLifeInsuranceFee: 0
426
+ codebtorLifeInsuranceFee: 0,
427
+ monthlyPaymentWithLate: 2373.7405888545,
428
+ lateCharges: 0,
429
+ lateDays: 0,
430
+ lateInterest: 0
429
431
  };
430
432
  const amortizationMethod = AmortizationMethod.GERMAN;
431
433
  const paymentNumber = new PaymentNumber(2);
@@ -447,7 +449,9 @@ describe('installment-service for german method', () => {
447
449
  previousBalance,
448
450
  inflationaryUpperBound,
449
451
  propertyAmount,
450
- IPCAmap
452
+ IPCAmap,
453
+ IPCAmapLate: { '2022-01-05': 0.0095 },
454
+ today: '2022-01-05'
451
455
  };
452
456
  const params: DebtParams = {
453
457
  annualRate,
@@ -562,7 +566,11 @@ describe('installment-service for german method', () => {
562
566
  amortizationIPCA: 642.87,
563
567
  debtorLifeInsuranceFee: 22.17,
564
568
  propertyInsuranceFee: 4.8,
565
- codebtorLifeInsuranceFee: 0
569
+ codebtorLifeInsuranceFee: 0,
570
+ monthlyPaymentWithLate: 1821.6678071913,
571
+ lateCharges: 0,
572
+ lateDays: 0,
573
+ lateInterest: 0
566
574
  };
567
575
  const amortizationMethod = AmortizationMethod.GERMAN;
568
576
  const paymentNumber = new PaymentNumber(2);
@@ -584,7 +592,9 @@ describe('installment-service for german method', () => {
584
592
  previousBalance,
585
593
  inflationaryUpperBound,
586
594
  propertyAmount,
587
- IPCAmap
595
+ IPCAmap,
596
+ IPCAmapLate: { '2022-01-05': 0.0095 },
597
+ today: '2022-01-05'
588
598
  };
589
599
  const params: DebtParams = {
590
600
  annualRate,
@@ -617,7 +627,9 @@ describe('installment-service for german method', () => {
617
627
  previousBalance,
618
628
  inflationaryUpperBound,
619
629
  propertyAmount,
620
- IPCAmap
630
+ IPCAmap,
631
+ IPCAmapLate: { '2022-01-05': 0.0095 },
632
+ today: '2022-01-05'
621
633
  };
622
634
  const params: DebtParams = {
623
635
  annualRate,
@@ -871,7 +883,11 @@ describe('installment-service for german method', () => {
871
883
  amortizationIPCA: 642.87,
872
884
  debtorLifeInsuranceFee: 22.17,
873
885
  propertyInsuranceFee: 4.8,
874
- codebtorLifeInsuranceFee: 0
886
+ codebtorLifeInsuranceFee: 0,
887
+ monthlyPaymentWithLate: 1821.6678071913,
888
+ lateCharges: 0,
889
+ lateDays: 0,
890
+ lateInterest: 0
875
891
  };
876
892
 
877
893
  const amortizationMethod = AmortizationMethod.GERMAN;
@@ -891,7 +907,9 @@ describe('installment-service for german method', () => {
891
907
  previousBalance,
892
908
  inflationaryUpperBound,
893
909
  propertyAmount,
894
- IPCAmap
910
+ IPCAmap,
911
+ IPCAmapLate: { '2022-01-05': 0.0095 },
912
+ today: '2022-01-05'
895
913
  };
896
914
  const params: DebtParams = {
897
915
  annualRate,
@@ -961,29 +979,28 @@ describe('installment-service for german method', () => {
961
979
  dailyRate: 0.0002009109,
962
980
  interest: 330.09,
963
981
  monthlyPayment: 1304.656229564,
964
- monthlyPaymentWithInsurances: 1331.596229564,
982
+ monthlyPaymentWithInsurances: 1358.526229564,
965
983
  amortization: 361.70713637,
966
984
  amortizationIPCA: 612.859093194,
967
- debtorLifeInsuranceFee: 22.14,
985
+ debtorLifeInsuranceFee: 44.27,
968
986
  codebtorLifeInsuranceFee: 0,
969
- propertyInsuranceFee: 4.8
987
+ propertyInsuranceFee: 9.6,
988
+ monthlyPaymentWithLate: 1358.526229564,
989
+ lateCharges: 0,
990
+ lateDays: 0,
991
+ lateInterest: 0
970
992
  };
971
993
  const amortizationMethod = AmortizationMethod.GERMAN;
972
994
  const paymentNumber = new PaymentNumber(1);
973
995
  const numberOfMonths = new NumberOfMonths(360);
974
996
  const previousBalance = new PreviousBalance(129600);
975
997
  const annualRate = 0.075;
976
- // const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017); // 0.00017
977
- const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017); // 0.00017
998
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
978
999
  const inflationaryUpperBound = 1;
979
1000
  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 };
1001
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
983
1002
  const IPCAmap = {
984
- // '2021-12-23': 1.25,
985
1003
  '2021-12-23': 0.0125,
986
- // '2022-01-05': 0.95,
987
1004
  '2022-01-05': 0.0095
988
1005
  };
989
1006
  const inputs: DebtInputs = {
@@ -993,7 +1010,9 @@ describe('installment-service for german method', () => {
993
1010
  previousBalance,
994
1011
  inflationaryUpperBound,
995
1012
  propertyAmount,
996
- IPCAmap
1013
+ IPCAmap,
1014
+ IPCAmapLate: { '2022-01-05': 0.0095 },
1015
+ today: '2022-01-05'
997
1016
  };
998
1017
  const params: DebtParams = {
999
1018
  annualRate,
@@ -1069,12 +1088,16 @@ describe('installment-service for french method', () => {
1069
1088
  dailyRate: 0.0002266368,
1070
1089
  interest: 1804.52,
1071
1090
  monthlyPayment: 5821.2051403922,
1072
- monthlyPaymentWithInsurances: 5928.5651403922,
1091
+ monthlyPaymentWithInsurances: 6035.9151403922,
1073
1092
  amortization: 1638.6085052585,
1074
1093
  amortizationIPCA: 2378.0766351337,
1075
- debtorLifeInsuranceFee: 82.01,
1076
- propertyInsuranceFee: 25.35,
1077
- codebtorLifeInsuranceFee: 0
1094
+ debtorLifeInsuranceFee: 164.01,
1095
+ codebtorLifeInsuranceFee: 0,
1096
+ propertyInsuranceFee: 50.7,
1097
+ monthlyPaymentWithLate: 6035.9151403922,
1098
+ lateCharges: 0,
1099
+ lateDays: 0,
1100
+ lateInterest: 0
1078
1101
  };
1079
1102
 
1080
1103
  const amortizationMethod = AmortizationMethod.FRENCH;
@@ -1094,7 +1117,9 @@ describe('installment-service for french method', () => {
1094
1117
  previousBalance,
1095
1118
  inflationaryUpperBound,
1096
1119
  propertyAmount,
1097
- IPCAmap
1120
+ IPCAmap,
1121
+ IPCAmapLate: { '2022-01-05': 0.0095 },
1122
+ today: '2022-01-05'
1098
1123
  };
1099
1124
  const params: DebtParams = {
1100
1125
  annualRate,
@@ -1102,7 +1127,6 @@ describe('installment-service for french method', () => {
1102
1127
  propertyInsuranceRate
1103
1128
  };
1104
1129
  const result = service.getTotalMonthlyPayment(inputs, params);
1105
- // console.log('file: installment.service.spec.ts ~ line 883 ~ result', result);
1106
1130
  expect(result).toEqual(expectedResult);
1107
1131
  });
1108
1132
  // Falla en el cálculo de la amortizationIPC
@@ -1235,7 +1259,9 @@ describe('installment-service for french method', () => {
1235
1259
  previousBalance,
1236
1260
  inflationaryUpperBound,
1237
1261
  propertyAmount,
1238
- IPCAmap
1262
+ IPCAmap,
1263
+ IPCAmapLate: { '2022-01-05': 0.0095 },
1264
+ today: '2022-01-05'
1239
1265
  };
1240
1266
  const params: DebtParams = {
1241
1267
  annualRate,
@@ -1347,7 +1373,9 @@ describe('installment-service for french method', () => {
1347
1373
  previousBalance,
1348
1374
  inflationaryUpperBound,
1349
1375
  propertyAmount,
1350
- IPCAmap
1376
+ IPCAmap,
1377
+ IPCAmapLate: { '2022-01-05': 0.0095 },
1378
+ today: '2022-01-05'
1351
1379
  };
1352
1380
  const params: DebtParams = {
1353
1381
  annualRate,