Github user nazeer1100126 commented on a diff in the pull request: https://github.com/apache/incubator-fineract/pull/130#discussion_r66404831 --- Diff: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java --- @@ -5972,4 +5986,204 @@ public BigDecimal getDerivedAmountForCharge(LoanCharge loanCharge) { return amount; } + public LoanRepaymentScheduleInstallment fetchLoanForeclosureDetail(final LocalDate closureDate) { + Money totalPrincipal = Money.of(getCurrency(), this.getSummary().getTotalPrincipalOutstanding()); + Money[] receivables = retriveIncomeOutstandingTillDate(closureDate); + final List<LoanInterestRecalcualtionAdditionalDetails> compoundingDetails = null; + return new LoanRepaymentScheduleInstallment(null, 0, LocalDate.now(), LocalDate.now(), totalPrincipal.getAmount(), + receivables[0].getAmount(), receivables[1].getAmount(), receivables[2].getAmount(), false, compoundingDetails); + } + + public Money[] retriveIncomeOutstandingTillDate(final LocalDate paymentDate) { + Money[] balances = new Money[3]; + final MonetaryCurrency currency = getCurrency(); + Money interest = Money.zero(currency); + Money fee = Money.zero(currency); + Money penalty = Money.zero(currency); + boolean isArrearsPresent = false; + for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) { + if (installment.isNotFullyPaidOff()) { + if (!isArrearsPresent || !installment.getDueDate().isAfter(paymentDate)) { + interest = interest.plus(installment.getInterestOutstanding(currency)); + fee = fee.plus(installment.getFeeChargesOutstanding(currency)); + penalty = penalty.plus(installment.getPenaltyChargesOutstanding(currency)); + isArrearsPresent = true; + } else if (installment.getFromDate().isBefore(paymentDate)) { + int totalPeriodDays = Days.daysBetween(installment.getFromDate(), installment.getDueDate()).getDays(); + int tillDays = Days.daysBetween(installment.getFromDate(), paymentDate).getDays(); + interest = interest.plus(calculateInterestForDays(totalPeriodDays, installment.getInterestOutstanding(currency) + .getAmount(), tillDays)); + for (LoanCharge loanCharge : this.charges) { + if (loanCharge.isActive() + && loanCharge.isDueForCollectionFromAndUpToAndIncluding(installment.getFromDate(), paymentDate)) { + if (loanCharge.isPenaltyCharge()) { + penalty = penalty.plus(loanCharge.getAmountOutstanding(currency)); + } else { + fee = fee.plus(loanCharge.getAmountOutstanding(currency)); + } + } + } + } + } + } + balances[0] = interest; + balances[1] = fee; + balances[2] = penalty; + return balances; + } + + private double calculateInterestForDays(int daysInPeriod, BigDecimal interest, int days) { + if (interest.doubleValue() == 0) { return 0; } + return ((interest.doubleValue()) / daysInPeriod) * days; + } + + public boolean canForecloseLoan() { --- End diff -- This method is not required as already validation is done
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---