Skip to content

Commit

Permalink
FINERACT-2148: Add 'Accelerate maturity' charge-off behaviour option
Browse files Browse the repository at this point in the history
  • Loading branch information
leksinomi committed Dec 20, 2024
1 parent 8716751 commit 601b249
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum LoanChargeOffBehaviour {

REGULAR("chargeOffBehaviour.regular", "Regular"), //
ZERO_INTEREST("chargeOffBehaviour.zeroInterest", "Zero interest after charge-off"), //
ACCELERATE_MATURITY("chargeOffBehaviour.accelerateMaturity", "Accelerate maturity to charge-off date"), //
;

private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,9 @@ private void handleChargeOff(final LoanTransaction loanTransaction, final Transa
if (LoanChargeOffBehaviour.ZERO_INTEREST.equals(loanTransaction.getLoan().getLoanProductRelatedDetail().getChargeOffBehaviour())
&& !loanTransaction.isReversed()) {
handleZeroInterestChargeOff(loanTransaction, progressiveTransactionCtx);
} else if (LoanChargeOffBehaviour.ACCELERATE_MATURITY
.equals(loanTransaction.getLoan().getLoanProductRelatedDetail().getChargeOffBehaviour())) {
handleAccelerateMaturityChargeOff(loanTransaction, progressiveTransactionCtx);
}
}

Expand All @@ -1197,6 +1200,42 @@ private void handleChargeOff(final LoanTransaction loanTransaction, final Transa
loanTransaction.updateComponentsAndTotal(principalPortion, interestPortion, feeChargesPortion, penaltychargesPortion);
}

private void handleAccelerateMaturityChargeOff(LoanTransaction loanTransaction, ProgressiveTransactionCtx progressiveTransactionCtx) {
final LocalDate transactionDate = loanTransaction.getTransactionDate();
final List<LoanRepaymentScheduleInstallment> installments = progressiveTransactionCtx.getInstallments();
Loan loan = loanTransaction.getLoan();
LoanRepaymentScheduleInstallment currentInstallment = loan.getRelatedRepaymentScheduleInstallment(transactionDate);

if (!installments.isEmpty() && transactionDate.isBefore(loan.getMaturityDate())) {
if (loan.isInterestRecalculationEnabled()) {
final BigDecimal newInterest = emiCalculator
.getPeriodInterestTillDate(progressiveTransactionCtx.getModel(), currentInstallment.getDueDate(), transactionDate)
.getAmount();
currentInstallment.updateInterestCharged(newInterest);
} else {
final BigDecimal totalInterest = currentInstallment.getInterestOutstanding(progressiveTransactionCtx.getCurrency())
.getAmount();
final long totalDaysInPeriod = ChronoUnit.DAYS.between(currentInstallment.getFromDate(), currentInstallment.getDueDate());
final long daysTillChargeOff = ChronoUnit.DAYS.between(currentInstallment.getFromDate(), transactionDate);

final BigDecimal interestTillChargeOff = totalInterest
.divide(BigDecimal.valueOf(totalDaysInPeriod), MoneyHelper.getMathContext())
.multiply(BigDecimal.valueOf(daysTillChargeOff));

currentInstallment.updateInterestCharged(interestTillChargeOff);
}

currentInstallment.updateDueDate(transactionDate);
BigDecimal futurePrincipal = installments.stream().filter(installment -> transactionDate.isBefore(installment.getDueDate()))
.map(LoanRepaymentScheduleInstallment::getPrincipal).reduce(BigDecimal.ZERO, BigDecimal::add);
currentInstallment.updatePrincipal(MathUtil.nullToZero(currentInstallment.getPrincipal()).add(futurePrincipal));
List<LoanRepaymentScheduleInstallment> installmentsUpToTransactionDate = installments.stream()
.filter(installment -> transactionDate.isAfter(installment.getFromDate())).toList();
loan.updateLoanSchedule(installmentsUpToTransactionDate);
loan.updateLoanScheduleDependentDerivedFields();
}
}

private void handleZeroInterestChargeOff(final LoanTransaction loanTransaction,
final ProgressiveTransactionCtx progressiveTransactionCtx) {
final LocalDate transactionDate = loanTransaction.getTransactionDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3290,6 +3290,18 @@ public CommandProcessingResult undoChargeOff(JsonCommand command) {

loan.liftChargeOff();
loanTransactionRepository.saveAndFlush(chargedOffTransaction);
if (loan.isProgressiveSchedule()) {
final ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, null, null);
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, scheduleGeneratorDTO);
ChangedTransactionDetail changedTransactionDetail = loan.reprocessTransactions();
if (changedTransactionDetail != null) {
for (final Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
loanAccountDomainService.saveLoanTransactionWithDataIntegrityViolationChecks(mapEntry.getValue());
accountTransfersWritePlatformService.updateLoanTransaction(mapEntry.getKey(), mapEntry.getValue());
}
replayedTransactionBusinessEventService.raiseTransactionReplayedEvents(changedTransactionDetail);
}
}
saveLoanWithDataIntegrityViolationChecks(loan);
postJournalEntries(loan, existingTransactionIds, existingReversedTransactionIds);
businessEventNotifierService.notifyPostBusinessEvent(new LoanUndoChargeOffBusinessEvent(chargedOffTransaction));
Expand Down

0 comments on commit 601b249

Please sign in to comment.