FINERACT-2234: add interest recalc filter
This commit is contained in:
+21
-13
@@ -21,6 +21,7 @@ package org.apache.fineract.cob.loan;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.infrastructure.core.domain.ActionContext;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
|
||||
@@ -35,22 +36,29 @@ public class LoanInterestRecalculationCOBBusinessStep implements LoanCOBBusiness
|
||||
|
||||
@Override
|
||||
public Loan execute(Loan loan) {
|
||||
if (!loan.getStatus().isActive() || loan.isNpa() || loan.isChargedOff() || !loan.isInterestBearingAndInterestRecalculationEnabled()
|
||||
|| loan.getLoanInterestRecalculationDetails().disallowInterestCalculationOnPastDue()) {
|
||||
log.debug(
|
||||
"Skip processing loan interest recalculation [{}] - Possible reasons: Loan is not an interest bearing loan, Loan is not active, Interest recalculation on past due is disabled on this loan",
|
||||
loan.getId());
|
||||
try {
|
||||
ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT);
|
||||
if (!loan.getStatus().isActive() || loan.isNpa() || loan.isChargedOff()
|
||||
|| !loan.isInterestBearingAndInterestRecalculationEnabled()
|
||||
|| loan.getLoanInterestRecalculationDetails().disallowInterestCalculationOnPastDue() || !hasOverdueInstallment(loan)) {
|
||||
log.debug(
|
||||
"Skip processing loan interest recalculation [{}] - Possible reasons: Loan is not an interest bearing loan, Loan is not active, Interest recalculation on past due is disabled on this loan",
|
||||
loan.getId());
|
||||
return loan;
|
||||
}
|
||||
|
||||
log.debug("Start processing loan interest recalculation [{}]", loan.getId());
|
||||
loan = loanWritePlatformService.recalculateInterest(loan);
|
||||
log.debug("End processing loan interest recalculation [{}]", loan.getId());
|
||||
return loan;
|
||||
} finally {
|
||||
ThreadLocalContextUtil.setActionContext(ActionContext.COB);
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("Start processing loan interest recalculation [{}]", loan.getId());
|
||||
|
||||
ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT);
|
||||
|
||||
loan = loanWritePlatformService.recalculateInterest(loan);
|
||||
|
||||
log.debug("End processing loan interest recalculation [{}]", loan.getId());
|
||||
return loan;
|
||||
private boolean hasOverdueInstallment(Loan loan) {
|
||||
return loan.getRepaymentScheduleInstallments().stream()
|
||||
.anyMatch(installment -> DateUtils.isBeforeBusinessDate(installment.getDueDate()) && !installment.isObligationsMet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user