FINERACT-2081: Fix reversal of loan accruals when loan repayment got reversed
This commit is contained in:
committed by
Adam Saghy
parent
f76cef768e
commit
15e013b90e
+12
-5
@@ -1264,6 +1264,7 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
updateLoanChargesAndInstallmentChargesPaidBy(loan, accrualTransaction);
|
||||
// TODO check if this is required
|
||||
// saveLoanTransactionWithDataIntegrityViolationChecks(accrualTransaction);
|
||||
accrualTransaction = loanTransactionRepository.saveAndFlush(accrualTransaction);
|
||||
loan.addLoanTransaction(accrualTransaction);
|
||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanAccrualTransactionCreatedBusinessEvent(accrualTransaction));
|
||||
|
||||
@@ -1357,11 +1358,17 @@ public class LoanAccrualsProcessingServiceImpl implements LoanAccrualsProcessing
|
||||
}
|
||||
BigDecimal accruedAmount = BigDecimal.ZERO;
|
||||
BigDecimal waivedAmount = BigDecimal.ZERO;
|
||||
for (LoanChargePaidBy loanChargePaidBy : loanCharge.getLoanChargePaidBySet()) {
|
||||
if (loanChargePaidBy.getLoanTransaction().isAccrual()) {
|
||||
accruedAmount = accruedAmount.add(loanChargePaidBy.getLoanTransaction().getAmount());
|
||||
} else if (loanChargePaidBy.getLoanTransaction().isChargesWaiver()) {
|
||||
waivedAmount = waivedAmount.add(loanChargePaidBy.getLoanTransaction().getAmount());
|
||||
for (LoanTransaction loanTransaction : loan.getLoanTransactions()) {
|
||||
if (loanTransaction.isAccrual() || loanTransaction.isChargesWaiver()) {
|
||||
for (LoanChargePaidBy loanChargePaidBy : loanTransaction.getLoanChargesPaid()) {
|
||||
if (loanChargePaidBy.getLoanCharge().getId().equals(loanCharge.getId())) {
|
||||
if (loanTransaction.isAccrual()) {
|
||||
accruedAmount = accruedAmount.add(loanTransaction.getAmount());
|
||||
} else if (loanTransaction.isChargesWaiver()) {
|
||||
waivedAmount = waivedAmount.add(loanTransaction.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Money needToAccrueAmount = MathUtil.negativeToZero(loanCharge.getAmount(currency).minus(accruedAmount).minus(waivedAmount));
|
||||
|
||||
+3
-2
@@ -1031,8 +1031,9 @@ public class LoanChargeWritePlatformServiceImpl implements LoanChargeWritePlatfo
|
||||
loanCharge = this.loanChargeRepository.saveAndFlush(loanCharge);
|
||||
|
||||
// we want to apply charge transactions only for those loans charges that are applied when a loan is active and
|
||||
// the loan product uses Upfront Accruals
|
||||
if (loan.getStatus().isActive() && loan.isNoneOrCashOrUpfrontAccrualAccountingEnabledOnLoanProduct()) {
|
||||
// the loan product uses Upfront Accruals, or only when the loan are closed too,
|
||||
if ((loan.getStatus().isActive() && loan.isNoneOrCashOrUpfrontAccrualAccountingEnabledOnLoanProduct())
|
||||
|| loan.getStatus().isOverpaid() || loan.getStatus().isClosedObligationsMet()) {
|
||||
final LoanTransaction applyLoanChargeTransaction = loan.handleChargeAppliedTransaction(loanCharge, null);
|
||||
this.loanTransactionRepository.saveAndFlush(applyLoanChargeTransaction);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user