From cb1510463d247d029c4929bc134ef3e28e1b5c6a Mon Sep 17 00:00:00 2001 From: Pramod Nuthakki Date: Mon, 23 Mar 2015 11:25:56 +0530 Subject: [PATCH] MIFOSX-1884 : corrected test cases --- .../ClientLoanIntegrationTest.java | 39 ++++++---------- .../domain/AbstractLoanScheduleGenerator.java | 19 ++++---- ...gBalanceInterestLoanScheduleGenerator.java | 46 +++++++++++-------- .../FlatInterestLoanScheduleGenerator.java | 2 +- .../domain/LoanApplicationTerms.java | 14 ++---- 5 files changed, 57 insertions(+), 63 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java index c5817dd9b..bade7d93c 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java @@ -3206,7 +3206,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.76", "46.15", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2505.67", "23.24", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.24", "11.67", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2528.81", "11.67", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); @@ -3300,7 +3300,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "4.62", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.76", "46.15", "4.62", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2505.67", "23.24", "2.32", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.24", "11.67", "1.17", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2528.81", "11.67", "1.17", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); @@ -3391,8 +3391,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.54", "46.37", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2505.67", "23.24", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.24", "11.67", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "11.79", "0.05", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2529.03", "11.67", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); @@ -3401,8 +3400,7 @@ public class ClientLoanIntegrationTest { todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant()); addRepaymentValues(expectedvalues, todaysDate, 0, "4965.3", "92.52", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2505.67", "23.24", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.24", "11.67", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "11.79", "0.05", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2529.03", "11.67", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues, 0); @@ -3499,8 +3497,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "100.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2486.04", "42.87", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2497.5", "31.41", "200", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2508.98", "19.93", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "24.72", "8.38", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2533.7", "19.93", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); @@ -3518,8 +3515,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "100.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.57", "46.34", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2497.49", "31.42", "200", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2508.96", "19.95", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "28.22", "8.4", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2537.18", "19.95", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); @@ -3535,8 +3531,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "100.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2486.04", "42.87", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2497.5", "31.41", "200", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2508.98", "19.93", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "24.72", "8.38", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2533.7", "19.93", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); Float earlyPayment = new Float("5100"); @@ -3551,8 +3546,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "100.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "5057.13", "42.87", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "0", "19.55", "200", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2349.13", "11.35", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "110.98", "8.26", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2460.11", "11.35", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); HashMap prepayDetail = this.loanTransactionHelper.getPrepayAmount(this.requestSpec, this.responseSpec, loanID); @@ -3625,8 +3619,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -2, "2482.76", "46.15", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.54", "46.37", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.33", "46.58", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.13", "11.78", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "35.24", "0.16", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2552.37", "11.78", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); @@ -3639,7 +3632,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -2, "2482.76", "46.15", "0.0", "252.89"); addRepaymentValues(expectedvalues, todaysDate, 1, "2481.38", "47.53", "0.0", "252.89"); addRepaymentValues(expectedvalues, todaysDate, 1, "2479.99", "48.92", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.11", "11.8", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2555.87", "11.8", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); Calendar repaymentDate = Calendar.getInstance(Utils.getTimeZoneOfTenant()); @@ -3655,7 +3648,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -2, "2482.76", "46.15", "0.0", "252.89"); addRepaymentValues(expectedvalues, todaysDate, 1, "2493.05", "35.86", "0.0", "252.89"); addRepaymentValues(expectedvalues, todaysDate, 1, "2491.72", "37.19", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.22", "11.69", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2532.47", "11.69", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); repaymentDate = Calendar.getInstance(Utils.getTimeZoneOfTenant()); @@ -3670,7 +3663,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -2, "2482.76", "46.15", "0.0", "252.89"); addRepaymentValues(expectedvalues, todaysDate, 1, "2493.05", "35.86", "0.0", "252.89"); addRepaymentValues(expectedvalues, todaysDate, 1, "2491.72", "37.19", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.22", "11.69", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2532.47", "11.69", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); } @@ -3731,7 +3724,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.76", "46.15", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2505.67", "23.24", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.24", "11.67", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2528.81", "11.67", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); @@ -3824,8 +3817,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.54", "46.37", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2505.67", "23.24", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.24", "11.67", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "11.79", "0.05", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2529.03", "11.67", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant()); @@ -3902,8 +3894,7 @@ public class ClientLoanIntegrationTest { addRepaymentValues(expectedvalues, todaysDate, -1, "2482.76", "46.15", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2482.54", "46.37", "0.0", "0.0"); addRepaymentValues(expectedvalues, todaysDate, 1, "2505.67", "23.24", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "2517.24", "11.67", "0.0", "0.0"); - addRepaymentValues(expectedvalues, todaysDate, 1, "11.79", "0.05", "0.0", "0.0"); + addRepaymentValues(expectedvalues, todaysDate, 1, "2529.03", "11.67", "0.0", "0.0"); verifyLoanRepaymentSchedule(loanSchedule, expectedvalues); todaysDate = Calendar.getInstance(Utils.getTimeZoneOfTenant()); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/AbstractLoanScheduleGenerator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/AbstractLoanScheduleGenerator.java index 1e3fc0d78..a5544a169 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/AbstractLoanScheduleGenerator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/AbstractLoanScheduleGenerator.java @@ -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); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/DecliningBalanceInterestLoanScheduleGenerator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/DecliningBalanceInterestLoanScheduleGenerator.java index f7d8f53ff..05f7cb466 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/DecliningBalanceInterestLoanScheduleGenerator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/DecliningBalanceInterestLoanScheduleGenerator.java @@ -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 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 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); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/FlatInterestLoanScheduleGenerator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/FlatInterestLoanScheduleGenerator.java index 18240cd27..e9a8bec6f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/FlatInterestLoanScheduleGenerator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/FlatInterestLoanScheduleGenerator.java @@ -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, diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java index 36090b3f7..d83dfbf48 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/loanschedule/domain/LoanApplicationTerms.java @@ -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(); }