diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java index 15e23cb30..7518b3c85 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java @@ -6285,10 +6285,14 @@ public class Loan extends AbstractPersistableCustom { final MonetaryCurrency currency = getCurrency(); Money totalPrincipal = Money.zero(currency); Money [] balances = retriveIncomeForOverlappingPeriod(transactionDate); + boolean isInterestComponent = true; for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) { if (!installment.getDueDate().isBefore(transactionDate)) { totalPrincipal = totalPrincipal.plus(installment.getPrincipal(currency)); newInstallments.remove(installment); + if (installment.getDueDate().isEqual(transactionDate)) { + isInterestComponent = false; + } } } @@ -6303,12 +6307,18 @@ public class Loan extends AbstractPersistableCustom { if (newInstallments.size() > 0) { installmentStartDate = newInstallments.get((newInstallments.size() - 1)).getDueDate(); - } + } + int installmentNumber = newInstallments.size(); + + if (!isInterestComponent) { + installmentNumber++; + } + - LoanRepaymentScheduleInstallment newInstallment = new LoanRepaymentScheduleInstallment(null, newInstallments.size() + 1, + LoanRepaymentScheduleInstallment newInstallment = new LoanRepaymentScheduleInstallment(null, newInstallments.size() + 1, installmentStartDate, transactionDate, totalPrincipal.getAmount(), - balances[0].getAmount(), balances[1].getAmount(), balances[2].getAmount(), true, null); + balances[0].getAmount(), balances[1].getAmount(), balances[2].getAmount(), isInterestComponent, null); newInstallment.updateInstallmentNumber(newInstallments.size() + 1); newInstallments.add(newInstallment); updateLoanScheduleOnForeclosure(newInstallments); @@ -6321,8 +6331,26 @@ public class Loan extends AbstractPersistableCustom { loanCharge.setActive(false); } else if (loanCharge.getDueLocalDate() == null) { recalculateLoanCharge(loanCharge, penaltyWaitPeriod); + loanCharge.updateWaivedAmount(currency); } } + + for (LoanTransaction loanTransaction : getLoanTransactions()) { + if (loanTransaction.isChargesWaiver()) { + for (LoanChargePaidBy chargePaidBy : loanTransaction + .getLoanChargesPaid()) { + if ((chargePaidBy.getLoanCharge().isDueDateCharge() && chargePaidBy + .getLoanCharge().getDueLocalDate() + .isAfter(transactionDate)) + || (chargePaidBy.getLoanCharge().isInstalmentFee() && (chargePaidBy + .getInstallmentNumber() != null && chargePaidBy + .getInstallmentNumber() > installmentNumber))) { + loanTransaction.reverse(); + } + } + + } + } } public void updateLoanScheduleOnForeclosure(final Collection installments) {