MIFOSX-1884 : corrected test cases

This commit is contained in:
Pramod Nuthakki
2015-03-23 11:25:56 +05:30
parent d91c6a0b64
commit cb1510463d
5 changed files with 57 additions and 63 deletions
@@ -226,9 +226,10 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
// date
PrincipalInterest principalInterestForThisPeriod = calculatePrincipalInterestComponentsForPeriod(
this.paymentPeriodsInOneYearCalculator, interestCalculationGraceOnRepaymentPeriodFraction,
totalCumulativePrincipal, totalCumulativeInterest, totalInterestChargedForFullLoanTerm,
totalOutstandingInterestPaymentDueToGrace, outstandingBalanceAsPerRest, loanApplicationTerms,
periodNumber, mc, mergeLateAndPaymentMaps(principalPortionMap, latePaymentMap, disburseDetailMap),
totalCumulativePrincipal.minus(reducePrincipal), totalCumulativeInterest,
totalInterestChargedForFullLoanTerm, totalOutstandingInterestPaymentDueToGrace,
outstandingBalanceAsPerRest, loanApplicationTerms, periodNumber, mc,
mergeLateAndPaymentMaps(principalPortionMap, latePaymentMap, disburseDetailMap),
periodStartDateApplicableForInterest, detail.getTransactionDate(),
daysInPeriodApplicableForInterest);
interestForThisinstallment = principalInterestForThisPeriod.interest();
@@ -331,9 +332,9 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
// 5 determine principal,interest of repayment period
PrincipalInterest principalInterestForThisPeriod = calculatePrincipalInterestComponentsForPeriod(
this.paymentPeriodsInOneYearCalculator, interestCalculationGraceOnRepaymentPeriodFraction, totalCumulativePrincipal,
totalCumulativeInterest, totalInterestChargedForFullLoanTerm, totalOutstandingInterestPaymentDueToGrace,
outstandingBalanceAsPerRest, loanApplicationTerms, periodNumber, mc,
this.paymentPeriodsInOneYearCalculator, interestCalculationGraceOnRepaymentPeriodFraction,
totalCumulativePrincipal.minus(reducePrincipal), totalCumulativeInterest, totalInterestChargedForFullLoanTerm,
totalOutstandingInterestPaymentDueToGrace, outstandingBalanceAsPerRest, loanApplicationTerms, periodNumber, mc,
mergeLateAndPaymentMaps(principalPortionMap, latePaymentMap, disburseDetailMap), periodStartDateApplicableForInterest,
scheduledDueDate, daysInPeriodApplicableForInterest);
@@ -349,11 +350,11 @@ public abstract class AbstractLoanScheduleGenerator implements LoanScheduleGener
totalOutstandingInterestPaymentDueToGrace = principalInterestForThisPeriod.interestPaymentDueToGrace();
Money principalForThisPeriod = principalInterestForThisPeriod.principal();
if(principalForThisPeriod.isZero()){
if (principalForThisPeriod.isZero()) {
loanApplicationTerms.resetFixedEmiAmount();
}
// applies early payments on principal portion
if (principalForThisPeriod.isGreaterThan(reducePrincipal)) {
principalForThisPeriod = principalForThisPeriod.minus(reducePrincipal);
@@ -54,27 +54,27 @@ public class DecliningBalanceInterestLoanScheduleGenerator extends AbstractLoanS
Money balanceForInterestCalculation = outstandingBalance;
Money cumulatingInterestDueToGrace = cumulatingInterestPaymentDueToGrace;
final int daysInPeriodApplicableForInterest = Days.daysBetween(periodStartDate, periodEndDate).getDays();
if(principalVariation != null){
for (Map.Entry<LocalDate, Money> principal : principalVariation.entrySet()) {
if (!principal.getKey().isAfter(periodEndDate)) {
int interestForDays = Days.daysBetween(interestStartDate, principal.getKey()).getDays();
if (interestForDays > 0) {
final PrincipalInterest result = loanApplicationTerms.calculateTotalInterestForPeriod(calculator,
interestCalculationGraceOnRepaymentPeriodFraction, periodNumber, mc, cumulatingInterestDueToGrace,
interestForDays, balanceForInterestCalculation);
if (loanApplicationTerms.getInterestCalculationPeriodMethod().isDaily()) {
interestForThisInstallment = interestForThisInstallment.plus(result.interest());
} else {
interestForThisInstallment = interestForThisInstallment.plus(calculateInterestForDays(daysForInterestInFullPeriod,
result.interest().getAmount(), interestForDays));
if (principalVariation != null) {
for (Map.Entry<LocalDate, Money> principal : principalVariation.entrySet()) {
if (!principal.getKey().isAfter(periodEndDate)) {
int interestForDays = Days.daysBetween(interestStartDate, principal.getKey()).getDays();
if (interestForDays > 0) {
final PrincipalInterest result = loanApplicationTerms.calculateTotalInterestForPeriod(calculator,
interestCalculationGraceOnRepaymentPeriodFraction, periodNumber, mc, cumulatingInterestDueToGrace,
interestForDays, balanceForInterestCalculation);
if (loanApplicationTerms.getInterestCalculationPeriodMethod().isDaily()) {
interestForThisInstallment = interestForThisInstallment.plus(result.interest());
} else {
interestForThisInstallment = interestForThisInstallment.plus(calculateInterestForDays(
daysForInterestInFullPeriod, result.interest().getAmount(), interestForDays));
}
cumulatingInterestDueToGrace = result.interestPaymentDueToGrace();
interestStartDate = principal.getKey();
}
cumulatingInterestDueToGrace = result.interestPaymentDueToGrace();
interestStartDate = principal.getKey();
balanceForInterestCalculation = balanceForInterestCalculation.plus(principal.getValue());
}
balanceForInterestCalculation = balanceForInterestCalculation.plus(principal.getValue());
}
}
}
}
int interestForDays = Days.daysBetween(interestStartDate, periodEndDate).getDays();
@@ -88,8 +88,14 @@ public class DecliningBalanceInterestLoanScheduleGenerator extends AbstractLoanS
.interest().getAmount(), interestForDays));
}
Money interestForPeriod = interestForThisInstallment;
if (interestForPeriod.isGreaterThanZero()) {
interestForPeriod = interestForPeriod.minus(cumulatingInterestPaymentDueToGrace);
}else{
interestForPeriod = result.interestPaymentDueToGrace().minus(cumulatingInterestPaymentDueToGrace);
}
Money principalForThisInstallment = loanApplicationTerms.calculateTotalPrincipalForPeriod(calculator,
daysInPeriodApplicableForInterest, outstandingBalance, periodNumber, mc);
daysInPeriodApplicableForInterest, outstandingBalance, periodNumber, mc, interestForPeriod);
// update cumulative fields for principal & interest
final Money interestBroughtFowardDueToGrace = result.interestPaymentDueToGrace();
@@ -98,7 +104,7 @@ public class DecliningBalanceInterestLoanScheduleGenerator extends AbstractLoanS
// adjust if needed
principalForThisInstallment = loanApplicationTerms.adjustPrincipalIfLastRepaymentPeriod(principalForThisInstallment,
totalCumulativePrincipalToDate, periodNumber);
return new PrincipalInterest(principalForThisInstallment, interestForThisInstallment, interestBroughtFowardDueToGrace);
}
}
@@ -23,7 +23,7 @@ public class FlatInterestLoanScheduleGenerator extends AbstractLoanScheduleGener
@SuppressWarnings("unused") int daysForInterestInFullPeriod) {
final int daysInPeriodApplicableForInterest = Days.daysBetween(periodStartDate, periodEndDate).getDays();
Money principalForThisInstallment = loanApplicationTerms.calculateTotalPrincipalForPeriod(calculator,
daysInPeriodApplicableForInterest, outstandingBalance, periodNumber, mc);
daysInPeriodApplicableForInterest, outstandingBalance, periodNumber, mc, null);
final PrincipalInterest result = loanApplicationTerms.calculateTotalInterestForPeriod(calculator,
interestCalculationGraceOnRepaymentPeriodFraction, periodNumber, mc, cumulatingInterestPaymentDueToGrace,
@@ -422,7 +422,7 @@ public final class LoanApplicationTerms {
}
public Money calculateTotalPrincipalForPeriod(final PaymentPeriodsInOneYearCalculator calculator, final int daysInPeriod,
final Money outstandingBalance, final int periodNumber, final MathContext mc) {
final Money outstandingBalance, final int periodNumber, final MathContext mc, Money interestForThisInstallment) {
Money principalForInstallment = this.principal.zero();
@@ -444,8 +444,8 @@ public final class LoanApplicationTerms {
DaysInMonthType.DAYS_30, DaysInYearType.DAYS_365);
Money totalPmtForThisInstallment = calculateTotalDueForEqualInstallmentRepaymentPeriod(
periodicInterestRateForRepaymentPeriod, outstandingBalance, periodsElapsed);
principalForInstallment = calculatePrincipalDueForInstallment(calculator, mc, periodNumber,
totalPmtForThisInstallment, daysInPeriod, outstandingBalance);
principalForInstallment = calculatePrincipalDueForInstallment(periodNumber, totalPmtForThisInstallment,
interestForThisInstallment);
break;
case EQUAL_PRINCIPAL:
principalForInstallment = calculateEqualPrincipalDueForInstallment(mc, periodNumber);
@@ -882,13 +882,9 @@ public final class LoanApplicationTerms {
return principal;
}
private Money calculatePrincipalDueForInstallment(final PaymentPeriodsInOneYearCalculator calculator, final MathContext mc,
final int periodNumber, final Money totalDuePerInstallment, final int daysInPeriod, final Money outstandingBalance) {
private Money calculatePrincipalDueForInstallment(final int periodNumber, final Money totalDuePerInstallment, final Money periodInterest) {
final Money interestForThisInstallmentBeforeGrace = calculateDecliningInterestDueForInstallmentBeforeApplyingGrace(calculator, mc,
daysInPeriod, outstandingBalance);
Money principal = totalDuePerInstallment.minus(interestForThisInstallmentBeforeGrace);
Money principal = totalDuePerInstallment.minus(periodInterest);
if (isPrincipalGraceApplicableForThisPeriod(periodNumber)) {
principal = principal.zero();
}