MIFOSX-1421 : corrected interest for extra repayments

This commit is contained in:
Pramod Nuthakki
2014-08-08 22:28:16 +05:30
parent 103a4a0ee1
commit 827c4c5a0d
2 changed files with 14 additions and 10 deletions
@@ -478,9 +478,9 @@ public class LoanCharge extends AbstractPersistable<Long> {
} }
} }
this.loanInstallmentCharge.removeAll(remove); this.loanInstallmentCharge.removeAll(remove);
/*while (index < loanChargePerInstallmentArray.length - 1) { while (index < loanChargePerInstallmentArray.length - 1) {
chargePerInstallments.add(loanChargePerInstallmentArray[index++]); this.loanInstallmentCharge.add(loanChargePerInstallmentArray[index++]);
}*/ }
} }
} }
@@ -315,7 +315,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
if (diffAmt != null && !diffAmt.isEmpty() && !periodStartDate.isAfter(LocalDate.now())) { if (diffAmt != null && !diffAmt.isEmpty() && !periodStartDate.isAfter(LocalDate.now())) {
Map<LocalDate, RecalculationDetail> processDetails = new TreeMap<>(); Map<LocalDate, RecalculationDetail> processDetails = new TreeMap<>();
for (RecalculationDetail detail : diffAmt) { for (RecalculationDetail detail : diffAmt) {
if (periodStartDate.isBefore(detail.getStartDate()) && detail.isLatePayment()) { if (!periodStartDate.isAfter(detail.getStartDate()) && detail.isLatePayment()) {
if (processDetails.containsKey(detail.getToDate())) { if (processDetails.containsKey(detail.getToDate())) {
RecalculationDetail recalculationDetail = processDetails.get(detail.getToDate()); RecalculationDetail recalculationDetail = processDetails.get(detail.getToDate());
RecalculationDetail updatedDetail = new RecalculationDetail(recalculationDetail.isLatePayment(), RecalculationDetail updatedDetail = new RecalculationDetail(recalculationDetail.isLatePayment(),
@@ -604,14 +604,18 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
if (installment.getDueDate().isBefore(LocalDate.now())) { if (installment.getDueDate().isBefore(LocalDate.now())) {
LocalDate startDate = installment.getDueDate(); LocalDate startDate = installment.getDueDate();
Money totalOutstanding = installment.getTotalOutstanding(currency); Money totalOutstanding = installment.getTotalOutstanding(currency);
boolean reduceStartDate = false;
while (totalOutstanding.isGreaterThanZero() && startDate.isBefore(LocalDate.now())) { while (totalOutstanding.isGreaterThanZero() && startDate.isBefore(LocalDate.now())) {
LocalDate recalculateFrom = getNextRestScheduleDate(startDate.minusDays(1), loanApplicationTerms, isHolidayEnabled, LocalDate recalculateFrom = getNextRestScheduleDate(startDate.minusDays(1), loanApplicationTerms, isHolidayEnabled,
holidays, workingDays); holidays, workingDays);
LocalDate recalcualteTill = getNextRestScheduleDate(recalculateFrom, loanApplicationTerms, isHolidayEnabled, holidays, LocalDate recalcualteTill = getNextRestScheduleDate(recalculateFrom, loanApplicationTerms, isHolidayEnabled, holidays,
workingDays); workingDays);
if (reduceStartDate) {
startDate = startDate.minusDays(1);
}
applyRest(transactions, startDate, recalculateFrom, installment, loanRepaymentScheduleTransactionProcessor, currency, applyRest(transactions, startDate, recalculateFrom, installment, loanRepaymentScheduleTransactionProcessor, currency,
loanApplicationTerms, isHolidayEnabled, holidays, workingDays); loanApplicationTerms, isHolidayEnabled, holidays, workingDays, installments);
totalOutstanding = installment.getTotalOutstanding(currency); totalOutstanding = installment.getTotalOutstanding(currency);
if (totalOutstanding.isGreaterThanZero()) { if (totalOutstanding.isGreaterThanZero()) {
Money latepaymentoutstanding = installment.getPrincipalOutstanding(currency); Money latepaymentoutstanding = installment.getPrincipalOutstanding(currency);
@@ -636,14 +640,15 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
latepaymentoutstanding); latepaymentoutstanding);
diffAmt.add(recalculationDetail); diffAmt.add(recalculationDetail);
} }
startDate = recalcualteTill; startDate = recalculateFrom.plusDays(1);
reduceStartDate = true;
} }
} }
if (!diffAmt.isEmpty()) { if (!diffAmt.isEmpty()) {
processRecalculate = true; processRecalculate = true;
break;
} }
break;
} }
if (processRecalculate) { if (processRecalculate) {
@@ -658,7 +663,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
LoanRepaymentScheduleInstallment installment, LoanRepaymentScheduleInstallment installment,
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor, MonetaryCurrency currency, final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor, MonetaryCurrency currency,
final LoanApplicationTerms loanApplicationTerms, final boolean isHolidayEnabled, final List<Holiday> holidays, final LoanApplicationTerms loanApplicationTerms, final boolean isHolidayEnabled, final List<Holiday> holidays,
final WorkingDays workingDays) { final WorkingDays workingDays, final List<LoanRepaymentScheduleInstallment> installments) {
List<LoanTransaction> transactions = new ArrayList<>(); List<LoanTransaction> transactions = new ArrayList<>();
Map<LocalDate, LocalDate> recalculationDates = new HashMap<>(); Map<LocalDate, LocalDate> recalculationDates = new HashMap<>();
for (LoanTransaction transaction : loanTransactions) { for (LoanTransaction transaction : loanTransactions) {
@@ -671,8 +676,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
workingDays)); workingDays));
} }
} }
List<LoanRepaymentScheduleInstallment> installments = new ArrayList<>(1);
installments.add(installment);
loanRepaymentScheduleTransactionProcessor.handleRepaymentSchedule(transactions, currency, installments, installment, loanRepaymentScheduleTransactionProcessor.handleRepaymentSchedule(transactions, currency, installments, installment,
recalculationDates); recalculationDates);
} }