FINERACT-2433: Fix interest and accrual calculation in case of last installment payment

This commit is contained in:
Adam Saghy
2026-01-08 12:22:48 +01:00
parent d42b4f7b6c
commit 8b3c8280de
9 changed files with 420 additions and 37 deletions
@@ -131,7 +131,8 @@ public class LoanTransactionProcessingServiceImpl implements LoanTransactionProc
@Override
public LoanScheduleDTO getRecalculatedSchedule(final ScheduleGeneratorDTO generatorDTO, Loan loan) {
if (!loan.isInterestBearingAndInterestRecalculationEnabled() || loan.isNpa() || loan.isChargedOff()) {
if (!loan.isInterestBearingAndInterestRecalculationEnabled() || loan.isNpa()
|| (loan.isChargedOff() && loan.isCumulativeSchedule())) {
return null;
}
final InterestMethod interestMethod = loan.getLoanRepaymentScheduleDetail().getInterestMethod();
@@ -2742,24 +2742,22 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf
businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data));
});
final LoanTransaction chargeOffTransaction = LoanTransaction.chargeOff(loan, transactionDate, txnExternalId);
final LoanTransaction chargeOffTransaction;
if (loan.isInterestBearingAndInterestRecalculationEnabled()) {
if (loan.isCumulativeSchedule()) {
final ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, null, null);
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, scheduleGeneratorDTO);
}
final ScheduleGeneratorDTO scheduleGeneratorDTO = this.loanUtilService.buildScheduleGeneratorDTO(loan, null, null);
loanScheduleService.regenerateRepaymentScheduleWithInterestRecalculation(loan, scheduleGeneratorDTO);
chargeOffTransaction = LoanTransaction.chargeOff(loan, transactionDate, txnExternalId);
reprocessLoanTransactionsService.reprocessTransactions(loan, List.of(chargeOffTransaction));
loan.addLoanTransaction(chargeOffTransaction);
} else {
chargeOffTransaction = LoanTransaction.chargeOff(loan, transactionDate, txnExternalId);
reprocessLoanTransactionsService.processLatestTransaction(chargeOffTransaction, loan);
loan.addLoanTransaction(chargeOffTransaction);
}
loanTransactionRepository.saveAndFlush(chargeOffTransaction);
journalEntryPoster.postJournalEntriesForLoanTransaction(chargeOffTransaction, false, false);
saveAndFlushLoanWithDataIntegrityViolationChecks(loan);
String noteText = command.stringValueOfParameterNamed(LoanApiConstants.noteParameterName);
if (StringUtils.isNotBlank(noteText)) {
changes.put(LoanApiConstants.noteParameterName, noteText);