Skip to content

Commit

Permalink
FINERACT-2181: Fix accrual activity reversal logic: prevent duplicate…
Browse files Browse the repository at this point in the history
… reverse-replay, copy external ID correctly
  • Loading branch information
oleksii-novikov-onix committed Mar 6, 2025
1 parent 8223c72 commit 5be1775
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ private LoanTransaction reverseReplayAccrualActivityTransaction(@NotNull Loan lo
newLoanTransaction.copyLoanTransactionRelations(loanTransaction.getLoanTransactionRelations());
newLoanTransaction.getLoanTransactionRelations().add(LoanTransactionRelation.linkToTransaction(newLoanTransaction,
loanTransaction, LoanTransactionRelationTypeEnum.REPLAYED));

newLoanTransaction.updateExternalId(loanTransaction.getExternalId());
loanTransaction.reverse();
loanTransaction.updateExternalId(null);
loanAccountService.saveLoanTransactionWithDataIntegrityViolationChecks(loanTransaction);

loanAccountService.saveLoanTransactionWithDataIntegrityViolationChecks(newLoanTransaction);
loan.addLoanTransaction(newLoanTransaction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,16 @@ private void reprocessPeriodicAccruals(Loan loan, final List<LoanTransaction> ac
if (loan.isChargedOff()) {
return;
}

// Add check for already reversed transactions
List<LoanTransaction> nonReversedAccruals = accrualTransactions.stream().filter(t -> !t.isReversed()).collect(Collectors.toList());

ensureAccrualTransactionMappings(loan);
LoanRepaymentScheduleInstallment lastInstallment = loan.getLastLoanRepaymentScheduleInstallment();
LocalDate lastDueDate = lastInstallment.getDueDate();
if (isProgressiveAccrual(loan)) {
AccrualBalances accrualBalances = new AccrualBalances();
accrualTransactions.forEach(lt -> {
nonReversedAccruals.forEach(lt -> {
switch (lt.getTypeOf()) {
case ACCRUAL -> {
accrualBalances.setFeePortion(MathUtil.add(accrualBalances.getFeePortion(), lt.getFeeChargesPortion()));
Expand Down Expand Up @@ -757,11 +761,11 @@ private void reprocessPeriodicAccruals(Loan loan, final List<LoanTransaction> ac
List<LoanRepaymentScheduleInstallment> installments = loan.getRepaymentScheduleInstallments();
boolean isBasedOnSubmittedOnDate = !isChargeOnDueDate();
for (LoanRepaymentScheduleInstallment installment : installments) {
checkAndUpdateAccrualsForInstallment(loan, accrualTransactions, installments, isBasedOnSubmittedOnDate, installment);
checkAndUpdateAccrualsForInstallment(loan, nonReversedAccruals, installments, isBasedOnSubmittedOnDate, installment);
}
}
// reverse accruals after last installment
reverseTransactionsAfter(accrualTransactions, lastDueDate, false);
reverseTransactionsAfter(nonReversedAccruals, lastDueDate, false);
}

private void reprocessNonPeriodicAccruals(Loan loan, final List<LoanTransaction> accrualTransactions) {
Expand Down

0 comments on commit 5be1775

Please sign in to comment.