MIFOSX-2390 : fixed prepay loan with installment charges

This commit is contained in:
pramod
2016-01-20 16:04:31 +05:30
parent f6f5af5c07
commit 4caeecfeb9
2 changed files with 38 additions and 10 deletions
@@ -5627,6 +5627,15 @@ public class Loan extends AbstractPersistable<Long> {
} }
public int fetchNumberOfInstallmensAfterExceptions() { public int fetchNumberOfInstallmensAfterExceptions() {
if(this.repaymentScheduleInstallments.size() > 0){
int numberOfInstallments = 0;
for (final LoanRepaymentScheduleInstallment installment : this.repaymentScheduleInstallments) {
if(!installment.isRecalculatedInterestComponent()){
numberOfInstallments++;
}
}
return numberOfInstallments;
}
return this.repaymentScheduleDetail().getNumberOfRepayments() + adjustNumberOfRepayments(); return this.repaymentScheduleDetail().getNumberOfRepayments() + adjustNumberOfRepayments();
} }
@@ -304,7 +304,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
installment = handleRecalculationForTransactions(mc, loanApplicationTerms, holidayDetailDTO, currency, scheduleParams, installment = handleRecalculationForTransactions(mc, loanApplicationTerms, holidayDetailDTO, currency, scheduleParams,
loanRepaymentScheduleTransactionProcessor, totalInterestChargedForFullLoanTerm, lastRestDate, scheduledDueDate, loanRepaymentScheduleTransactionProcessor, totalInterestChargedForFullLoanTerm, lastRestDate, scheduledDueDate,
periodStartDateApplicableForInterest, applicableTransactions, currentPeriodParams, periodStartDateApplicableForInterest, applicableTransactions, currentPeriodParams,
lastTotalOutstandingInterestPaymentDueToGrace, installment); lastTotalOutstandingInterestPaymentDueToGrace, installment, loanCharges);
periods.add(installment); periods.add(installment);
// Updates principal paid map with efective date for reducing // Updates principal paid map with efective date for reducing
@@ -424,7 +424,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
final Money totalInterestChargedForFullLoanTerm, final LocalDate lastRestDate, final LocalDate scheduledDueDate, final Money totalInterestChargedForFullLoanTerm, final LocalDate lastRestDate, final LocalDate scheduledDueDate,
final LocalDate periodStartDateApplicableForInterest, final Collection<RecalculationDetail> applicableTransactions, final LocalDate periodStartDateApplicableForInterest, final Collection<RecalculationDetail> applicableTransactions,
final ScheduleCurrentPeriodParams currentPeriodParams, final Money lastTotalOutstandingInterestPaymentDueToGrace, final ScheduleCurrentPeriodParams currentPeriodParams, final Money lastTotalOutstandingInterestPaymentDueToGrace,
final LoanScheduleModelPeriod installment) { final LoanScheduleModelPeriod installment, Set<LoanCharge> loanCharges) {
LoanScheduleModelPeriod modifiedInstallment = installment; LoanScheduleModelPeriod modifiedInstallment = installment;
if (scheduleParams.applyInterestRecalculation() && loanRepaymentScheduleTransactionProcessor != null) { if (scheduleParams.applyInterestRecalculation() && loanRepaymentScheduleTransactionProcessor != null) {
Money principalProcessed = Money.zero(currency); Money principalProcessed = Money.zero(currency);
@@ -446,7 +446,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
modifiedInstallment = handlePrepaymentOfLoan(mc, loanApplicationTerms, holidayDetailDTO, scheduleParams, modifiedInstallment = handlePrepaymentOfLoan(mc, loanApplicationTerms, holidayDetailDTO, scheduleParams,
totalInterestChargedForFullLoanTerm, scheduledDueDate, periodStartDateApplicableForInterest, totalInterestChargedForFullLoanTerm, scheduledDueDate, periodStartDateApplicableForInterest,
currentPeriodParams.getInterestCalculationGraceOnRepaymentPeriodFraction(), currentPeriodParams, currentPeriodParams.getInterestCalculationGraceOnRepaymentPeriodFraction(), currentPeriodParams,
lastTotalOutstandingInterestPaymentDueToGrace, transactionDate, modifiedInstallment); lastTotalOutstandingInterestPaymentDueToGrace, transactionDate, modifiedInstallment, loanCharges);
Money addToPrinciapal = Money.zero(currency); Money addToPrinciapal = Money.zero(currency);
if (scheduleParams.getOutstandingBalance().isLessThanZero()) { if (scheduleParams.getOutstandingBalance().isLessThanZero()) {
@@ -486,7 +486,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
final Money totalInterestChargedForFullLoanTerm, final LocalDate scheduledDueDate, final Money totalInterestChargedForFullLoanTerm, final LocalDate scheduledDueDate,
LocalDate periodStartDateApplicableForInterest, final double interestCalculationGraceOnRepaymentPeriodFraction, LocalDate periodStartDateApplicableForInterest, final double interestCalculationGraceOnRepaymentPeriodFraction,
final ScheduleCurrentPeriodParams currentPeriodParams, final Money lastTotalOutstandingInterestPaymentDueToGrace, final ScheduleCurrentPeriodParams currentPeriodParams, final Money lastTotalOutstandingInterestPaymentDueToGrace,
final LocalDate transactionDate, final LoanScheduleModelPeriod installment) { final LocalDate transactionDate, final LoanScheduleModelPeriod installment, Set<LoanCharge> loanCharges) {
LoanScheduleModelPeriod modifiedInstallment = installment; LoanScheduleModelPeriod modifiedInstallment = installment;
if (!scheduleParams.getOutstandingBalance().isGreaterThan(currentPeriodParams.getInterestForThisPeriod()) if (!scheduleParams.getOutstandingBalance().isGreaterThan(currentPeriodParams.getInterestForThisPeriod())
&& !scheduledDueDate.equals(transactionDate)) { && !scheduledDueDate.equals(transactionDate)) {
@@ -510,20 +510,31 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
lastTotalOutstandingInterestPaymentDueToGrace, scheduleParams.getOutstandingBalanceAsPerRest(), loanApplicationTerms, lastTotalOutstandingInterestPaymentDueToGrace, scheduleParams.getOutstandingBalanceAsPerRest(), loanApplicationTerms,
scheduleParams.getPeriodNumber(), mc, mergeVariationsToMap(scheduleParams), scheduleParams.getCompoundingMap(), scheduleParams.getPeriodNumber(), mc, mergeVariationsToMap(scheduleParams), scheduleParams.getCompoundingMap(),
periodStartDateApplicableForInterest, calculateTill, interestRates); periodStartDateApplicableForInterest, calculateTill, interestRates);
Money diff = currentPeriodParams.getInterestForThisPeriod().minus(interestTillDate.interest()); // applies charges for the period
final ScheduleCurrentPeriodParams tempPeriod = new ScheduleCurrentPeriodParams(
totalInterestChargedForFullLoanTerm.getCurrency(), interestCalculationGraceOnRepaymentPeriodFraction);
tempPeriod.setInterestForThisPeriod(interestTillDate.interest());
applyChargesForCurrentPeriod(loanCharges, totalInterestChargedForFullLoanTerm.getCurrency(), scheduleParams, calculateTill,
tempPeriod);
Money interestDiff = currentPeriodParams.getInterestForThisPeriod().minus(tempPeriod.getInterestForThisPeriod());
Money chargeDiff = currentPeriodParams.getFeeChargesForInstallment().minus(tempPeriod.getFeeChargesForInstallment());
Money penaltyDiff = currentPeriodParams.getPenaltyChargesForInstallment().minus(tempPeriod.getPenaltyChargesForInstallment());
Money diff = interestDiff.plus(chargeDiff).plus(penaltyDiff);
if (!scheduleParams.getOutstandingBalance().minus(diff).isGreaterThanZero()) { if (!scheduleParams.getOutstandingBalance().minus(diff).isGreaterThanZero()) {
scheduleParams.reduceOutstandingBalance(diff); scheduleParams.reduceOutstandingBalance(diff);
currentPeriodParams.minusInterestForThisPeriod(diff); currentPeriodParams.minusInterestForThisPeriod(interestDiff);
currentPeriodParams.minusFeeChargesForInstallment(chargeDiff);
currentPeriodParams.minusPenaltyChargesForInstallment(penaltyDiff);
currentPeriodParams.plusPrincipalForThisPeriod(diff); currentPeriodParams.plusPrincipalForThisPeriod(diff);
final Money totalDue = currentPeriodParams.getPrincipalForThisPeriod().plus(currentPeriodParams.getInterestForThisPeriod());
// create and replaces repayment period // create and replaces repayment period
// from parts // from parts
modifiedInstallment = LoanScheduleModelRepaymentPeriod.repayment(scheduleParams.getInstalmentNumber(), modifiedInstallment = LoanScheduleModelRepaymentPeriod.repayment(scheduleParams.getInstalmentNumber(),
scheduleParams.getPeriodStartDate(), transactionDate, currentPeriodParams.getPrincipalForThisPeriod(), scheduleParams.getPeriodStartDate(), transactionDate, currentPeriodParams.getPrincipalForThisPeriod(),
scheduleParams.getOutstandingBalance(), currentPeriodParams.getInterestForThisPeriod(), scheduleParams.getOutstandingBalance(), currentPeriodParams.getInterestForThisPeriod(),
currentPeriodParams.getFeeChargesForInstallment(), currentPeriodParams.getPenaltyChargesForInstallment(), totalDue, currentPeriodParams.getFeeChargesForInstallment(), currentPeriodParams.getPenaltyChargesForInstallment(),
false); currentPeriodParams.fetchTotalAmountForPeriod(), false);
scheduleParams.setTotalOutstandingInterestPaymentDueToGrace(interestTillDate.interestPaymentDueToGrace()); scheduleParams.setTotalOutstandingInterestPaymentDueToGrace(interestTillDate.interestPaymentDueToGrace());
} }
@@ -602,7 +613,7 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
&& scheduleParams.getLoanRepaymentScheduleTransactionProcessor() && scheduleParams.getLoanRepaymentScheduleTransactionProcessor()
.isInterestFirstRepaymentScheduleTransactionProcessor()) { .isInterestFirstRepaymentScheduleTransactionProcessor()) {
List<LoanTransaction> currentTransactions = createCurrentTransactionList(detail); List<LoanTransaction> currentTransactions = createCurrentTransactionList(detail);
if (!transactionDate.isEqual(scheduleParams.getPeriodStartDate()) || scheduleParams.getInstalmentNumber() == 1) { if (!transactionDate.isEqual(scheduleParams.getPeriodStartDate()) || scheduleParams.getInstalmentNumber() == 1) {
int periodDays = Days.daysBetween(scheduleParams.getPeriodStartDate(), transactionDate).getDays(); int periodDays = Days.daysBetween(scheduleParams.getPeriodStartDate(), transactionDate).getDays();
// calculates period start date for interest // calculates period start date for interest
@@ -2603,6 +2614,10 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
this.feeChargesForInstallment = feeChargesForInstallment; this.feeChargesForInstallment = feeChargesForInstallment;
} }
public void minusFeeChargesForInstallment(Money feeChargesForInstallment) {
this.feeChargesForInstallment = this.feeChargesForInstallment.minus(feeChargesForInstallment);
}
public Money getPenaltyChargesForInstallment() { public Money getPenaltyChargesForInstallment() {
return this.penaltyChargesForInstallment; return this.penaltyChargesForInstallment;
} }
@@ -2611,6 +2626,10 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
this.penaltyChargesForInstallment = penaltyChargesForInstallment; this.penaltyChargesForInstallment = penaltyChargesForInstallment;
} }
public void minusPenaltyChargesForInstallment(Money penaltyChargesForInstallment) {
this.penaltyChargesForInstallment = this.penaltyChargesForInstallment.minus(penaltyChargesForInstallment);
}
public Money fetchTotalAmountForPeriod() { public Money fetchTotalAmountForPeriod() {
return this.principalForThisPeriod.plus(interestForThisPeriod).plus(feeChargesForInstallment) return this.principalForThisPeriod.plus(interestForThisPeriod).plus(feeChargesForInstallment)
.plus(penaltyChargesForInstallment); .plus(penaltyChargesForInstallment);