creditu-common-library 2.3.1 → 2.3.2

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.
@@ -33,7 +33,7 @@ var MonthlyPaymentService = /** @class */ (function () {
33
33
  inflationaryUpdate: inflationaryUpdate,
34
34
  postponedInflationaryUpdate: postponedInflationaryUpdate
35
35
  });
36
- var monthlyPayment = this.math.add(interestIUB, this.math.subtract(amortizationIUB, amortizationDiff), this.math.subtract(inflationaryUpdate, postponedInflationaryUpdate));
36
+ var monthlyPayment = this.math.add(interestIUB, this.math.subtract(amortizationIUB, amortizationDiff), this.math.subtract(inflationaryUpdate < 0 ? 0 : inflationaryUpdate, inflationaryUpdate < 0 ? 0 : postponedInflationaryUpdate));
37
37
  return monthlyPayment;
38
38
  };
39
39
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creditu-common-library",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -3048,9 +3048,9 @@ describe('installment-service when deflation considered', () => {
3048
3048
  interest: 1997.4448304719,
3049
3049
  interestDiff: -11.8185488878,
3050
3050
  interestIUB: 1985.6262815841,
3051
- monthlyPayment: 971.9116437017,
3052
- monthlyPaymentWithInsurances: 1038.8749949277,
3053
- monthlyPaymentWithTAC: 1038.8749949277,
3051
+ monthlyPayment: 2927.0327773106,
3052
+ monthlyPaymentWithInsurances: 2993.9961285366,
3053
+ monthlyPaymentWithTAC: 2993.9961285366,
3054
3054
  amortization: 941.4064957265,
3055
3055
  amortizationDiff: -5.5701456798,
3056
3056
  amortizationIUB: 935.8363500467,
@@ -3080,8 +3080,8 @@ describe('installment-service when deflation considered', () => {
3080
3080
  totalLateRate: 0,
3081
3081
  totalLateInterest: 0,
3082
3082
  totalLate: 0,
3083
- monthlyPaymentWithLate: 1038.8749949277,
3084
- totalMonthlyPayment: 1038.8749949277,
3083
+ monthlyPaymentWithLate: 2993.9961285366,
3084
+ totalMonthlyPayment: 2993.9961285366,
3085
3085
  walletBalance: 0
3086
3086
  };
3087
3087
 
@@ -43,11 +43,11 @@ const getResultForComparison = (resultIn: DebtResponse) => {
43
43
  // balanceAfter2: resultIn.balanceAfter
44
44
  // };
45
45
  const result = {
46
- totalMonthlyPayment: resultIn.totalMonthlyPayment,
47
- monthlyPaymentWithTAC: resultIn.monthlyPaymentWithTAC,
48
- monthlyPayment: resultIn.monthlyPayment,
46
+ totalMonthlyPayment: resultIn.totalMonthlyPayment, // Valor de la cuota
47
+ monthlyPaymentWithTAC: resultIn.monthlyPaymentWithTAC, // Principal corregido
48
+ monthlyPayment: resultIn.monthlyPayment, // Dividendo efectivo
49
49
  'amortizationIUB + interestIUB': resultIn.amortizationIUB
50
- + resultIn.interestIUB,
50
+ + resultIn.interestIUB, // Dividendo teórico
51
51
  '-': '-',
52
52
  interestIUB: resultIn.interestIUB,
53
53
  amortizationIUB: resultIn.amortizationIUB,
@@ -97,7 +97,7 @@ const getResultForComparison = (resultIn: DebtResponse) => {
97
97
  '---=': '---',
98
98
  '--=': '---',
99
99
  '-=': '---',
100
- '=': '---',
100
+ lateDays: resultIn.lateDays,
101
101
  lastMonthTotalLateRate: resultIn.lastMonthTotalLateRate
102
102
  };
103
103
  // Apply rounding to the 4 place to all fields
@@ -947,7 +947,7 @@ describe('installment-service', () => {
947
947
  });
948
948
  });
949
949
 
950
- describe('Caso 5 - Ismael Oliveira Feitosa, cuota 0', () => { // FIX PRODUCTO PENDIENTE
950
+ describe('Caso 5 - Ismael Oliveira Feitosa, cuota 0', () => {
951
951
  // Parámetros de este caso
952
952
  const isGraceMonth = true;
953
953
  const isAmortizationPostponed = false;
@@ -1108,7 +1108,7 @@ describe('installment-service', () => {
1108
1108
  expect(result).toEqual(expectedResult);
1109
1109
  });
1110
1110
  });
1111
- describe.only('Caso 5 - Ismael Oliveira Feitosa, cuota 1', () => { // FIX PRODUCTO PENDIENTE
1111
+ describe('Caso 5 - Ismael Oliveira Feitosa, cuota 1', () => {
1112
1112
  // Parámetros de este caso
1113
1113
  const isGraceMonth = false;
1114
1114
  const isAmortizationPostponed = true;
@@ -1265,7 +1265,7 @@ describe('installment-service', () => {
1265
1265
  });
1266
1266
  });
1267
1267
 
1268
- describe('Caso 6 - Keila Zibordi Moraes Carvalho', () => {
1268
+ describe('Caso 6 - Keila Zibordi Moraes Carvalho, cuota 12', () => {
1269
1269
  // Parámetros de este caso
1270
1270
  const isGraceMonth = false;
1271
1271
  const isAmortizationPostponed = false;
@@ -1411,6 +1411,152 @@ describe('installment-service', () => {
1411
1411
  });
1412
1412
  });
1413
1413
 
1414
+ describe('Caso 6 - Keila Zibordi Moraes Carvalho, cuota 13', () => {
1415
+ // Parámetros de este caso
1416
+ const isGraceMonth = false;
1417
+ const isAmortizationPostponed = false;
1418
+ const numberOfMonths = new NumberOfMonths(360);
1419
+ const paymentNumber = new PaymentNumber(13);
1420
+ const amortizationMethod = AmortizationMethod.GERMAN;
1421
+ const previousBalance = new PreviousBalance(591421.94);
1422
+ const annualRate = 0.0875;
1423
+ const inflationaryUpperBound = 0.003;
1424
+ const codebtorLifeInsuranceProportion = 0;
1425
+ const propertyAmount = 907000;
1426
+ const considerNegativeInflation = true;
1427
+ const considerTAC = true;
1428
+ const TACValue = 25;
1429
+ const monthlyCreditInsuranceExpenses = 0;
1430
+ const monthlyCreditInsurancePrize = 0;
1431
+ const monthlyCreditInsurance = monthlyCreditInsuranceExpenses + monthlyCreditInsurancePrize;
1432
+ // Inflation map debe tener fechas e inflaciones (desfasadas 2 meses)
1433
+ // desde el mes de vencimiento anterior (o fecha de firma) hasta vencimiento de cuota
1434
+ const inflationMap = {
1435
+ '2023-08-08': -0.0008,
1436
+ '2023-09-08': 0.0012
1437
+ };
1438
+ // inflationMapLate debe tener fechas e inflaciones (desfasadas 2 meses)
1439
+ // desde el vencimiento actual hasta el día de hoy (de consulta de deuda)
1440
+ const inflationMapLate = {
1441
+ '2023-09-08': 0.0012,
1442
+ '2023-10-08': 0.0023
1443
+ // '2023-11-08': 0.005
1444
+ };
1445
+ const walletBalance = 0;
1446
+ // const walletBalance = 158.64;
1447
+ // Parámetros fijos
1448
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
1449
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
1450
+ const lateChargesFineRate = 0.02;
1451
+ const lateChargesInterestRate = 0.01;
1452
+ const upperBoundBehaviour = BehaviourCAP.BOUND;
1453
+ const proportionUsesSimpleInterest = true;
1454
+ const inflationExchangeMethodMonthlyToDaily = InterestType.SIMPLE;
1455
+ const insurancesStrategy = InsurancesStrategy.BALANCES;
1456
+ const monthNominalLength = 30;
1457
+ const inflationExchangeMethodYearlyToMonthly = InterestType.COMPOUND;
1458
+ const considerWallet = true;
1459
+
1460
+ it('should yield the right results', () => {
1461
+ // const filePath = './test/br/Producto_LowCode-Desarrollo.xlsx';
1462
+ // const excelValues = new ExcelTranslator(filePath);
1463
+ const inputs: DebtInputs = {
1464
+ today: '2023-10-08',
1465
+ amortizationMethod,
1466
+ isGraceMonth,
1467
+ isAmortizationPostponed,
1468
+ paymentNumber,
1469
+ numberOfMonths,
1470
+ previousBalance,
1471
+ inflationaryUpperBound,
1472
+ propertyAmount,
1473
+ inflationMap,
1474
+ inflationMapLate,
1475
+ proportionUsesSimpleInterest,
1476
+ upperBoundBehaviour,
1477
+ codebtorLifeInsuranceProportion,
1478
+ considerNegativeInflation,
1479
+ considerTAC,
1480
+ TACValue,
1481
+ monthlyCreditInsurance,
1482
+ monthlyCreditInsuranceExpenses,
1483
+ monthlyCreditInsurancePrize,
1484
+ walletBalance,
1485
+ considerWallet
1486
+ };
1487
+ const params: DebtParams = {
1488
+ annualRate,
1489
+ debtorLifeInsuranceRate,
1490
+ propertyInsuranceRate,
1491
+ lateChargesFineRate,
1492
+ lateChargesInterestRate,
1493
+ monthNominalLength,
1494
+ inflationExchangeMethodMonthlyToDaily,
1495
+ insurancesStrategy,
1496
+ inflationExchangeMethodYearlyToMonthly
1497
+ };
1498
+
1499
+ const expectedResult = {
1500
+ inflationByDates: [
1501
+ {}
1502
+ ],
1503
+ balanceValues: {
1504
+ balances: [
1505
+ ],
1506
+ balanceMonetaryUpdateValues: [
1507
+ ]
1508
+ },
1509
+ balanceInflationaryUpdated: null,
1510
+ balanceAfter: null,
1511
+ inflationaryUpdate: null,
1512
+ interest: null, // interestIUB - interestDiff
1513
+ interestDiff: null, // Inflación dentro del interés 🟢
1514
+ interestIUB: null, // Interés corregido ✅
1515
+ monthlyPayment: null,
1516
+ monthlyPaymentWithInsurances: null,
1517
+ monthlyPaymentWithTAC: null,
1518
+ amortization: null,
1519
+ amortizationDiff: null,
1520
+ amortizationIUB: null,
1521
+ upperBound: null,
1522
+ postponedInflationaryUpdate: null,
1523
+ amortizationInflation: null,
1524
+ TACValue: null,
1525
+ totalLifeInsuranceFee: null,
1526
+ debtorLifeInsuranceFee: null,
1527
+ codebtorLifeInsuranceFee: null,
1528
+ propertyInsuranceFee: null,
1529
+ monthlyCreditInsurance: null,
1530
+ monthlyCreditInsuranceExpenses: null,
1531
+ monthlyCreditInsurancePrize: null,
1532
+ lateDays: null,
1533
+ lateChargesFine: null, // Multa en Excel
1534
+ lateChargesInterestRate: null, // Tasa de castigo diaria acumulada en Excel
1535
+ lateChargesInterest: null, // Pendiente de contrastar con el Excel
1536
+ lateInterestRate: null, // Tasa de interés diaria ac. por atraso en Excel
1537
+ lateInterest: null, // Pendiente de contrastar con el Excel
1538
+ lateInflation: null, // Tasa corrección principal en Excel
1539
+ lateInflationaryCorrection: null, // Pendiente de contrastar con el Excel
1540
+ lastMonthLateChargesInterestRate: null, // Pendiente de contrastar con el Excel
1541
+ lastMonthLateInflation: null, // Tasa de inflación mensual en Excel
1542
+ lastMonthLateInterestRate: null, // Tasa de interés mensual por atraso en Excel
1543
+ lastMonthTotalLateRate: null, // Pendiente de contrastar con el Excel
1544
+ totalLateRate: null, // Tasa de penalidad en Excel
1545
+ totalLateInterest: null, // Interés penal en Excel
1546
+ totalLate: null, // Atraso en Excel
1547
+ monthlyPaymentWithLate: null,
1548
+ totalMonthlyPayment: null,
1549
+ walletBalance: null
1550
+ };
1551
+ const result = service.getTotalMonthlyPayment(inputs, params);
1552
+ const resultForComparison = getResultForComparison(result);
1553
+ // console.log(result);
1554
+ // console.log(JSON.stringify(getResultForComparison(result), null, 2));
1555
+ // console.log(Object.values(resultForComparison).join('\n'));
1556
+ // expect(result).toEqual(expectedResult);
1557
+ });
1558
+ });
1559
+
1414
1560
  describe('Caso 6.1 - Ariel Franco de Melo', () => {
1415
1561
  // Parámetros de este caso
1416
1562
  const isGraceMonth = false;
@@ -2978,16 +3124,16 @@ describe('installment-service', () => {
2978
3124
  });
2979
3125
  });
2980
3126
 
2981
- describe('Caso 14 - Adriano Silva da Matta', () => {
3127
+ describe('Caso 14 - Adriano Silva da Matta, cuota 12', () => {
2982
3128
  // Parámetros de este caso
2983
3129
  const isGraceMonth = false;
2984
3130
  const isAmortizationPostponed = false;
2985
- const numberOfMonths = new NumberOfMonths(360);
3131
+ const numberOfMonths = new NumberOfMonths(168);
2986
3132
  const paymentNumber = new PaymentNumber(12);
2987
3133
  const amortizationMethod = AmortizationMethod.FRENCH;
2988
3134
  const previousBalance = new PreviousBalance(112136.05);
2989
3135
  const annualRate = 0.095;
2990
- const inflationaryUpperBound = 0;
3136
+ const inflationaryUpperBound = 0.01;
2991
3137
  const codebtorLifeInsuranceProportion = 0;
2992
3138
  const propertyAmount = 636000;
2993
3139
  const considerNegativeInflation = false;
@@ -8012,4 +8158,150 @@ describe('installment-service', () => {
8012
8158
  // expect(result).toEqual(expectedResult);
8013
8159
  });
8014
8160
  });
8161
+
8162
+ describe('Caso 48 - Cassia Margarete Amorim de Moura', () => {
8163
+ // Parámetros de este caso
8164
+ const isGraceMonth = false;
8165
+ const isAmortizationPostponed = true;
8166
+ const numberOfMonths = new NumberOfMonths(240);
8167
+ const paymentNumber = new PaymentNumber(8);
8168
+ const amortizationMethod = AmortizationMethod.GERMAN;
8169
+ const previousBalance = new PreviousBalance(144335.93);
8170
+ const annualRate = 0.095;
8171
+ const inflationaryUpperBound = 0.004;
8172
+ const codebtorLifeInsuranceProportion = 0;
8173
+ const propertyAmount = 239000;
8174
+ const considerNegativeInflation = true;
8175
+ const considerTAC = true;
8176
+ const TACValue = 25;
8177
+ const monthlyCreditInsurancePrize = 676.22;
8178
+ const monthlyCreditInsuranceExpenses = 364.12;
8179
+ const monthlyCreditInsurance = monthlyCreditInsuranceExpenses + monthlyCreditInsurancePrize;
8180
+ // Inflation map debe tener fechas e inflaciones (desfasadas 2 meses)
8181
+ // desde el mes de vencimiento anterior (o fecha de firma) hasta vencimiento de cuota
8182
+ const inflationMap = {
8183
+ '2023-06-08': 0.0061,
8184
+ '2023-07-08': 0.0023
8185
+ };
8186
+ // inflationMapLate debe tener fechas e inflaciones (desfasadas 2 meses)
8187
+ // desde el vencimiento actual hasta el día de hoy (de consulta de deuda)
8188
+ const inflationMapLate = {
8189
+ '2023-07-08': 0.0023,
8190
+ '2023-08-08': -0.0008,
8191
+ '2023-09-08': 0.0012,
8192
+ '2023-10-08': 0.0023
8193
+ };
8194
+ const upperBoundBehaviour = BehaviourCAP.FIXED;
8195
+ const walletBalance = 0;
8196
+ const considerWallet = false;
8197
+ // Parámetros fijos
8198
+ const propertyInsuranceRate = new CreditInsuranceRate(0.00003);
8199
+ const debtorLifeInsuranceRate = new CreditInsuranceRate(0.00017);
8200
+ const lateChargesFineRate = 0.02;
8201
+ const lateChargesInterestRate = 0.01;
8202
+ const proportionUsesSimpleInterest = true;
8203
+ const inflationExchangeMethodMonthlyToDaily = InterestType.SIMPLE;
8204
+ const insurancesStrategy = InsurancesStrategy.BALANCES;
8205
+ const monthNominalLength = 30;
8206
+ const inflationExchangeMethodYearlyToMonthly = InterestType.COMPOUND;
8207
+
8208
+ it('should yield the right results', () => {
8209
+ // const filePath = './test/br/Producto_LowCode-Desarrollo.xlsx';
8210
+ // const excelValues = new ExcelTranslator(filePath);
8211
+ const inputs: DebtInputs = {
8212
+ today: '2023-10-08',
8213
+ amortizationMethod,
8214
+ isGraceMonth,
8215
+ isAmortizationPostponed,
8216
+ paymentNumber,
8217
+ numberOfMonths,
8218
+ previousBalance,
8219
+ inflationaryUpperBound,
8220
+ propertyAmount,
8221
+ inflationMap,
8222
+ inflationMapLate,
8223
+ proportionUsesSimpleInterest,
8224
+ upperBoundBehaviour,
8225
+ codebtorLifeInsuranceProportion,
8226
+ considerNegativeInflation,
8227
+ considerTAC,
8228
+ TACValue,
8229
+ monthlyCreditInsurance,
8230
+ monthlyCreditInsuranceExpenses,
8231
+ monthlyCreditInsurancePrize,
8232
+ walletBalance,
8233
+ considerWallet
8234
+ };
8235
+ const params: DebtParams = {
8236
+ annualRate,
8237
+ debtorLifeInsuranceRate,
8238
+ propertyInsuranceRate,
8239
+ lateChargesFineRate,
8240
+ lateChargesInterestRate,
8241
+ monthNominalLength,
8242
+ inflationExchangeMethodMonthlyToDaily,
8243
+ insurancesStrategy,
8244
+ inflationExchangeMethodYearlyToMonthly
8245
+ };
8246
+
8247
+ const expectedResult = {
8248
+ inflationByDates: [
8249
+ {}
8250
+ ],
8251
+ balanceValues: {
8252
+ balances: [
8253
+ ],
8254
+ balanceMonetaryUpdateValues: [
8255
+ ]
8256
+ },
8257
+ balanceInflationaryUpdated: null,
8258
+ balanceAfter: null,
8259
+ inflationaryUpdate: null,
8260
+ interest: null, // interestIUB - interestDiff
8261
+ interestDiff: null, // Inflación dentro del interés 🟢
8262
+ interestIUB: null, // Interés corregido ✅
8263
+ monthlyPayment: null,
8264
+ monthlyPaymentWithInsurances: null,
8265
+ monthlyPaymentWithTAC: null,
8266
+ amortization: null,
8267
+ amortizationDiff: null,
8268
+ amortizationIUB: null,
8269
+ upperBound: null,
8270
+ postponedInflationaryUpdate: null,
8271
+ amortizationInflation: null,
8272
+ TACValue: null,
8273
+ totalLifeInsuranceFee: null,
8274
+ debtorLifeInsuranceFee: null,
8275
+ codebtorLifeInsuranceFee: null,
8276
+ propertyInsuranceFee: null,
8277
+ monthlyCreditInsurance: null,
8278
+ monthlyCreditInsuranceExpenses: null,
8279
+ monthlyCreditInsurancePrize: null,
8280
+ lateDays: null,
8281
+ lateChargesFine: null, // Multa en Excel
8282
+ lateChargesInterestRate: null, // Tasa de castigo diaria acumulada en Excel
8283
+ lateChargesInterest: null, // Pendiente de contrastar con el Excel
8284
+ lateInterestRate: null, // Tasa de interés diaria ac. por atraso en Excel
8285
+ lateInterest: null, // Pendiente de contrastar con el Excel
8286
+ lateInflation: null, // Tasa corrección principal en Excel
8287
+ lateInflationaryCorrection: null, // Pendiente de contrastar con el Excel
8288
+ lastMonthLateChargesInterestRate: null, // Pendiente de contrastar con el Excel
8289
+ lastMonthLateInflation: null, // Tasa de inflación mensual en Excel
8290
+ lastMonthLateInterestRate: null, // Tasa de interés mensual por atraso en Excel
8291
+ lastMonthTotalLateRate: null, // Pendiente de contrastar con el Excel
8292
+ totalLateRate: null, // Tasa de penalidad en Excel
8293
+ totalLateInterest: null, // Interés penal en Excel
8294
+ totalLate: null, // Atraso en Excel
8295
+ monthlyPaymentWithLate: null,
8296
+ totalMonthlyPayment: null,
8297
+ walletBalance: null
8298
+ };
8299
+ const result = service.getTotalMonthlyPayment(inputs, params);
8300
+ const resultForComparison = getResultForComparison(result);
8301
+ // console.log(result);
8302
+ // console.log(JSON.stringify(getResultForComparison(result), null, 2));
8303
+ // console.log(Object.values(resultForComparison).join('\n'));
8304
+ // expect(result).toEqual(expectedResult);
8305
+ });
8306
+ });
8015
8307
  });