Skip to content

Commit

Permalink
FINERACT-2162: Chargeback implementation for progressive interest rec…
Browse files Browse the repository at this point in the history
…alculation enabled loan when no payment allocation set.

Fix tests & fix rebase issues
  • Loading branch information
somasorosdpc committed Feb 5, 2025
1 parent 7fab52a commit b224db7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -869,14 +869,6 @@ public void addToCreditedPrincipal(final BigDecimal amount) {
}
}

public void addToCreditedInterest(final BigDecimal amount) {
if (this.creditedInterest == null) {
this.creditedInterest = amount;
} else {
this.creditedInterest = this.creditedInterest.add(amount);
}
}

public void addToCreditedFee(final BigDecimal amount) {
if (this.creditedFee == null) {
this.creditedFee = amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTra
.filter(LoanRepaymentScheduleInstallment::isAdditional).findAny()
.or(() -> createAdditionalInstalment(loanTransaction, ctx)).orElseThrow();
// generic
recognizeAmountsAfterChargebackWithInterest(ctx, loanTransaction.getTransactionDate(), instalment, chargebackAllocation);
recognizeAmountsAfterChargeback(ctx, loanTransaction.getTransactionDate(), instalment, chargebackAllocation);
if (instalment.getDueDate().isBefore(loanTransaction.getTransactionDate())) {
instalment.updateDueDate(loanTransaction.getTransactionDate());
}
Expand All @@ -489,7 +489,7 @@ protected void processCreditTransactionWithEmiCalculator(LoanTransaction loanTra
LoanRepaymentScheduleInstallment instalment = ctx.getInstallments().stream()
.filter(i -> i.getDueDate().isEqual(loanTransaction.getLoan().getMaturityDate())).findAny().orElseThrow();
// generic
recognizeAmountsAfterChargebackWithInterest(ctx, loanTransaction.getTransactionDate(), instalment, chargebackAllocation);
recognizeAmountsAfterChargeback(ctx, loanTransaction.getTransactionDate(), instalment, chargebackAllocation);
}

allocateOverpayment(loanTransaction, ctx);
Expand Down Expand Up @@ -651,7 +651,6 @@ private Map<AllocationType, Money> adjustOriginalAllocationWithFormerChargebacks
return allocation;
}

/*
private void recognizeFeePenaltiesAmountsAfterChargeback(TransactionCtx ctx, LoanRepaymentScheduleInstallment installment,
Map<AllocationType, Money> chargebackAllocation) {
MonetaryCurrency currency = ctx.getCurrency();
Expand All @@ -669,37 +668,6 @@ private void recognizeFeePenaltiesAmountsAfterChargeback(TransactionCtx ctx, Loa
Money.zero(currency));
}
}
*/

private void recognizeAmountsAfterChargeback(final TransactionCtx ctx, final LocalDate transactionDate,
final LoanRepaymentScheduleInstallment installment, final Map<AllocationType, Money> chargebackAllocation) {
final Money principal = chargebackAllocation.get(PRINCIPAL);
if (principal != null && principal.isGreaterThanZero()) {
installment.addToCreditedPrincipal(principal.getAmount());
installment.addToPrincipal(transactionDate, principal);
}

final Money interest = chargebackAllocation.get(INTEREST);
if (interest != null && interest.isGreaterThanZero()) {
installment.addToCreditedInterest(interest.getAmount());
installment.addToInterest(transactionDate, interest);
}

final MonetaryCurrency currency = ctx.getCurrency();
final Money fee = chargebackAllocation.get(FEE);
if (fee != null && fee.isGreaterThanZero()) {
installment.addToCreditedFee(fee.getAmount());
installment.addToChargePortion(fee, Money.zero(currency), Money.zero(currency), Money.zero(currency), Money.zero(currency),
Money.zero(currency));
}

final Money penalty = chargebackAllocation.get(PENALTY);
if (penalty != null && penalty.isGreaterThanZero()) {
installment.addToCreditedPenalty(penalty.getAmount());
installment.addToChargePortion(Money.zero(currency), Money.zero(currency), Money.zero(currency), penalty, Money.zero(currency),
Money.zero(currency));
}
}

private void recognizeAmountsAfterChargebackWithInterestRecalculation(TransactionCtx ctx, LoanRepaymentScheduleInstallment installment,
Map<AllocationType, Money> chargebackAllocation) {
Expand All @@ -714,23 +682,19 @@ private void recognizeAmountsAfterChargebackWithInterestRecalculation(Transactio
recognizeFeePenaltiesAmountsAfterChargeback(ctx, installment, chargebackAllocation);
}

private void recognizeAmountsAfterChargebackWithInterest(TransactionCtx ctx, LocalDate transactionDate,
LoanRepaymentScheduleInstallment installment, Map<AllocationType, Money> chargebackAllocation) {
Money interest = chargebackAllocation.get(INTEREST);
if (interest.isGreaterThanZero()) {
installment.addToCreditedInterest(interest.getAmount());
installment.addToInterest(transactionDate, interest);
}
recognizeAmountsAfterChargeback(ctx, transactionDate, installment, chargebackAllocation);
}

private void recognizeAmountsAfterChargeback(TransactionCtx ctx, LocalDate transactionDate,
LoanRepaymentScheduleInstallment installment, Map<AllocationType, Money> chargebackAllocation) {
Money principal = chargebackAllocation.get(PRINCIPAL);
if (principal.isGreaterThanZero()) {
final Money principal = chargebackAllocation.get(PRINCIPAL);
if (principal != null && principal.isGreaterThanZero()) {
installment.addToCreditedPrincipal(principal.getAmount());
installment.addToPrincipal(transactionDate, principal);
}

final Money interest = chargebackAllocation.get(INTEREST);
if (interest != null && interest.isGreaterThanZero()) {
installment.addToCreditedInterest(interest.getAmount());
installment.addToInterest(transactionDate, interest);
}
recognizeFeePenaltiesAmountsAfterChargeback(ctx, installment, chargebackAllocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public void testS1() {
unpaidInstallment(33.53, 0.49, "01 April 2024"), //
unpaidInstallment(16.72, 0.29, "01 May 2024"), //
unpaidInstallment(16.81, 0.20, "01 June 2024"), //
unpaidInstallment(16.9, 0.10, "01 July 2024") //
unpaidInstallment(17.0, 0.10, "01 July 2024") //
); //
});
}
Expand Down Expand Up @@ -734,17 +734,17 @@ public void testS2AndS3() {
unpaidInstallment(31.53, 0.48, "01 April 2024"), //
unpaidInstallment(16.72, 0.29, "01 May 2024"), //
unpaidInstallment(16.81, 0.20, "01 June 2024"), //
unpaidInstallment(16.9, 0.10, "01 July 2024") //
unpaidInstallment(16.99, 0.10, "01 July 2024") //
); //
addChargebackForLoan(loanId, repaymentId, 17.01);
verifyRepaymentSchedule(loanId, //
installment(100.0, null, "01 January 2024"), //
fullyRepaidInstallment(16.43, 0.58, "01 February 2024"), //
fullyRepaidInstallment(16.52, 0.49, "01 March 2024"), //
unpaidInstallment(48.44, 0.58, "01 April 2024"), //
unpaidInstallment(16.72, 0.29, "01 May 2024"), //
unpaidInstallment(16.71, 0.30, "01 May 2024"), //
unpaidInstallment(16.81, 0.20, "01 June 2024"), //
unpaidInstallment(16.9, 0.10, "01 July 2024") //
unpaidInstallment(17.10, 0.10, "01 July 2024") //
); //
});
}
Expand Down Expand Up @@ -810,7 +810,7 @@ public void testS4() {
unpaidInstallment(33.57, 0.45, "01 April 2024"), //
unpaidInstallment(16.72, 0.29, "01 May 2024"), //
unpaidInstallment(16.81, 0.20, "01 June 2024"), //
unpaidInstallment(16.9, 0.10, "01 July 2024") //
unpaidInstallment(16.96, 0.10, "01 July 2024") //
); //
});
}
Expand Down

0 comments on commit b224db7

Please sign in to comment.