From a5bfa43dad66db8fc097ca6217a69adec5181564 Mon Sep 17 00:00:00 2001 From: John Woodlock Date: Sun, 29 May 2022 13:59:49 +0100 Subject: [PATCH] FINERACT-1557 (approval removing installment charges) --- .../portfolio/loanaccount/domain/Loan.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 9dd9a5c00..9592397e5 100644 --- 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 @@ -1737,12 +1737,41 @@ public class Loan extends AbstractPersistableCustom { chargeAmt = loanCharge.amountOrPercentage(); } if (loanCharge.isActive()) { + clearLoanInstallmentChargesBeforeRegeneration(loanCharge); loanCharge.update(chargeAmt, loanCharge.getDueLocalDate(), amount, fetchNumberOfInstallmensAfterExceptions(), totalChargeAmt); validateChargeHasValidSpecifiedDateIfApplicable(loanCharge, getDisbursementDate(), getLastRepaymentPeriodDueDate(false)); } } + private void clearLoanInstallmentChargesBeforeRegeneration(final LoanCharge loanCharge) { + /* + * JW https://issues.apache.org/jira/browse/FINERACT-1557 For loan installment charges only : Clear down + * installment charges from the loanCharge and from each of the repayment installments and allow them to be + * recalculated fully anew. This patch is to avoid the 'merging' of existing and regenerated installment charges + * which results in the installment charges being deleted on loan approval if the schedule is regenerated. Not + * pretty. updateInstallmentCharges in LoanCharge.java: the merging looks like it will work but doesn't so this + * patch simply hits the part which 'adds all' rather than merge. Possibly an ORM issue. The issue could be to + * do with the fact that, on approval, the "recalculateLoanCharge" happens twice (probably 2 schedule + * regenerations) whereas it only happens once on Submit and Disburse (and no problems with them) + * + * if (this.loanInstallmentCharge.isEmpty()) { this.loanInstallmentCharge.addAll(newChargeInstallments); + */ + Loan loan = loanCharge.getLoan(); + if (loan.isSubmittedAndPendingApproval() || loan.isApproved()) { // doing for both just in case status is not + // updated at this points + if (loanCharge.isInstalmentFee()) { + loanCharge.clearLoanInstallmentCharges(); + for (final LoanRepaymentScheduleInstallment installment : getRepaymentScheduleInstallments()) { + if (installment.isRecalculatedInterestComponent()) { + continue; // JW: does this in generateInstallmentLoanCharges - but don't understand it + } + installment.getInstallmentCharges().clear(); + } + } + } + } + private BigDecimal calculateOverdueAmountPercentageAppliedTo(final LoanCharge loanCharge, final int penaltyWaitPeriod) { LoanRepaymentScheduleInstallment installment = loanCharge.getOverdueInstallmentCharge().getInstallment(); LocalDate graceDate = DateUtils.getLocalDateOfTenant().minusDays(penaltyWaitPeriod);