Skip to content

Commit

Permalink
Merge pull request openMF#1494 from pramodn02/develop
Browse files Browse the repository at this point in the history
MIFOSX-2123 : added fix to change the principal amount
  • Loading branch information
vishwasbabu committed Sep 11, 2015
2 parents 30f7e70 + ac70343 commit a9a5e73
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ private LoanScheduleModel generate(final MathContext mc, final LoanApplicationTe
BigDecimal fixedEmiAmount = loanApplicationTerms.getFixedEmiAmount();
reducePrincipal = applyEarlyPaymentStrategy(loanApplicationTerms, reducePrincipal, totalCumulativePrincipal,
periodNumber + 1, mc, holidayDetailDTO);
if (fixedEmiAmount.compareTo(loanApplicationTerms.getFixedEmiAmount()) != 0) {
if (loanApplicationTerms.getAmortizationMethod().isEqualInstallment() && fixedEmiAmount.compareTo(loanApplicationTerms.getFixedEmiAmount()) != 0) {
isEmiAmountChanged = true;
}
principalForThisPeriod = principalForThisPeriod.plus(earlyPaidAmount);
Expand Down Expand Up @@ -643,7 +643,7 @@ private LoanScheduleModel generate(final MathContext mc, final LoanApplicationTe
reducePrincipal = applyEarlyPaymentStrategy(loanApplicationTerms, reducePrincipal,
totalCumulativePrincipal.plus(principalForThisPeriod.minus(principalProcessed)), periodNumber + 1, mc,
holidayDetailDTO);
if (fixedEmiAmount.compareTo(loanApplicationTerms.getFixedEmiAmount()) != 0) {
if (loanApplicationTerms.getAmortizationMethod().isEqualInstallment() && fixedEmiAmount.compareTo(loanApplicationTerms.getFixedEmiAmount()) != 0) {
isEmiAmountChanged = true;
}

Expand Down Expand Up @@ -943,6 +943,9 @@ private Money applyEarlyPaymentStrategy(final LoanApplicationTerms loanApplicati
updateFixedInstallmentAmount(mc, loanApplicationTerms, loanApplicationTerms.getExpectedDisbursementDate(),
periodNumber, loanApplicationTerms.getPrincipal().minus(totalCumulativePrincipal), holidayDetailDTO);
}
if(loanApplicationTerms.getAmortizationMethod().isEqualPrincipal()){
loanApplicationTerms.updateFixedPrincipalAmount(mc, periodNumber, loanApplicationTerms.getPrincipal().minus(totalCumulativePrincipal));
}
reducePrincipal = reducePrincipal.zero();
break;
case REDUCE_NUMBER_OF_INSTALLMENTS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -117,6 +116,8 @@ public final class LoanApplicationTerms {

private BigDecimal fixedEmiAmount;

private BigDecimal fixedPrincipalAmount;

private final BigDecimal actualFixedEmiAmount;

private final BigDecimal maxOutstandingBalance;
Expand Down Expand Up @@ -148,8 +149,8 @@ public final class LoanApplicationTerms {

private final LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy;

private Money approvedPrincipal = null ;
private Money approvedPrincipal = null;

public static LoanApplicationTerms assembleFrom(final ApplicationCurrency currency, final Integer loanTermFrequency,
final PeriodFrequencyType loanTermPeriodFrequencyType, final Integer numberOfRepayments, final Integer repaymentEvery,
final PeriodFrequencyType repaymentPeriodFrequencyType, Integer nthDay, DayOfWeekType weekDayType,
Expand All @@ -166,7 +167,8 @@ public static LoanApplicationTerms assembleFrom(final ApplicationCurrency curren
final RecalculationFrequencyType recalculationFrequencyType, final CalendarInstance restCalendarInstance,
final CalendarInstance compoundingCalendarInstance, final RecalculationFrequencyType compoundingFrequencyType,
final BigDecimal principalThresholdForLastInstalment, final Integer installmentAmountInMultiplesOf,
final LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar, BigDecimal approvedAmount) {
final LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar,
BigDecimal approvedAmount) {

final LoanRescheduleStrategyMethod rescheduleStrategyMethod = null;
final InterestRecalculationCompoundingMethod interestRecalculationCompoundingMethod = null;
Expand Down Expand Up @@ -341,7 +343,8 @@ private LoanApplicationTerms(final ApplicationCurrency currency, final Integer l
final CalendarInstance restCalendarInstance, final RecalculationFrequencyType recalculationFrequencyType,
final CalendarInstance compoundingCalendarInstance, final RecalculationFrequencyType compoundingFrequencyType,
final BigDecimal principalThresholdForLastInstalment, final Integer installmentAmountInMultiplesOf,
final LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar, BigDecimal approvedAmount) {
final LoanPreClosureInterestCalculationStrategy preClosureInterestCalculationStrategy, final Calendar loanCalendar,
BigDecimal approvedAmount) {
this.currency = currency;
this.loanTermFrequency = loanTermFrequency;
this.loanTermPeriodFrequencyType = loanTermPeriodFrequencyType;
Expand Down Expand Up @@ -390,7 +393,7 @@ private LoanApplicationTerms(final ApplicationCurrency currency, final Integer l
this.preClosureInterestCalculationStrategy = preClosureInterestCalculationStrategy;

this.loanCalendar = loanCalendar;
this.approvedPrincipal = Money.of(principal.getCurrency(), approvedAmount) ;
this.approvedPrincipal = Money.of(principal.getCurrency(), approvedAmount);
}

public Money adjustPrincipalIfLastRepaymentPeriod(final Money principalForPeriod, final Money totalCumulativePrincipalToDate,
Expand Down Expand Up @@ -490,8 +493,7 @@ public Money calculateTotalPrincipalForPeriod(final PaymentPeriodsInOneYearCalcu
case DECLINING_BALANCE:
switch (this.amortizationMethod) {
case EQUAL_INSTALLMENTS:
Money totalPmtForThisInstallment = pmtForInstallment(calculator, daysInPeriod, outstandingBalance, periodNumber,
mc);
Money totalPmtForThisInstallment = pmtForInstallment(calculator, daysInPeriod, outstandingBalance, periodNumber, mc);
principalForInstallment = calculatePrincipalDueForInstallment(periodNumber, totalPmtForThisInstallment,
interestForThisInstallment);
break;
Expand Down Expand Up @@ -556,9 +558,9 @@ public PrincipalInterest calculateTotalInterestForPeriod(final PaymentPeriodsInO
final Money interestForThisInstallmentBeforeGrace = calculateDecliningInterestDueForInstallmentBeforeApplyingGrace(
calculator, mc, daysInPeriodApplicableForInterest, outstandingBalance);

final Money interestForThisInstallmentAfterGrace = calculateDecliningInterestDueForInstallmentAfterApplyingGrace(calculator,
interestCalculationGraceOnRepaymentPeriodFraction, mc, daysInPeriodApplicableForInterest, outstandingBalance,
periodNumber);
final Money interestForThisInstallmentAfterGrace = calculateDecliningInterestDueForInstallmentAfterApplyingGrace(
calculator, interestCalculationGraceOnRepaymentPeriodFraction, mc, daysInPeriodApplicableForInterest,
outstandingBalance, periodNumber);

interestForInstallment = interestForThisInstallmentAfterGrace;
if (interestForThisInstallmentAfterGrace.isGreaterThanZero()) {
Expand Down Expand Up @@ -651,8 +653,7 @@ public void updateLoanEndDate(final LocalDate loanEndDate) {
this.loanEndDate = loanEndDate;
}

private Money calculateTotalInterestPerInstallmentWithoutGrace(final PaymentPeriodsInOneYearCalculator calculator,
final MathContext mc) {
private Money calculateTotalInterestPerInstallmentWithoutGrace(final PaymentPeriodsInOneYearCalculator calculator, final MathContext mc) {

final Money totalInterestForLoanTerm = calculateTotalFlatInterestDueWithoutGrace(calculator, mc);

Expand Down Expand Up @@ -709,8 +710,8 @@ private Money calculateTotalFlatInterestForInstallmentAveragingOutGracePeriods(f

final Integer interestPaymentDuePeriods = calculateNumberOfRepaymentPeriodsWhereInterestPaymentIsDue(this.numberOfRepayments);

interestForInstallment = realTotalInterestForLoan.dividedBy(BigDecimal.valueOf(interestPaymentDuePeriods),
mc.getRoundingMode());
interestForInstallment = realTotalInterestForLoan
.dividedBy(BigDecimal.valueOf(interestPaymentDuePeriods), mc.getRoundingMode());
}

return interestForInstallment;
Expand Down Expand Up @@ -792,8 +793,8 @@ public BigDecimal interestRateFor(final PaymentPeriodsInOneYearCalculator calcul

final BigDecimal divisor = BigDecimal.valueOf(Double.valueOf("100.0"));
final BigDecimal loanTermPeriodsInYearBigDecimal = BigDecimal.valueOf(loanTermPeriodsInOneYear);
final BigDecimal oneDayOfYearInterestRate = this.annualNominalInterestRate.divide(loanTermPeriodsInYearBigDecimal, mc)
.divide(divisor, mc);
final BigDecimal oneDayOfYearInterestRate = this.annualNominalInterestRate.divide(loanTermPeriodsInYearBigDecimal, mc).divide(
divisor, mc);
BigDecimal interestRate = oneDayOfYearInterestRate.multiply(BigDecimal.valueOf(repaymentEvery), mc);
return outstandingBalance.getAmount().multiply(interestRate, mc);
}
Expand Down Expand Up @@ -936,16 +937,27 @@ private boolean isInterestFreeGracePeriodFromDate(final double interestCalculati
private Money calculateEqualPrincipalDueForInstallment(final MathContext mc, final int periodNumber) {

final Integer numberOfPrincipalPaymentPeriods = calculateNumberOfPrincipalPaymentPeriods(this.numberOfRepayments);
Money principal = this.principal;
if (this.fixedPrincipalAmount == null) {
principal = this.principal.dividedBy(numberOfPrincipalPaymentPeriods, mc.getRoundingMode());
this.fixedPrincipalAmount = principal.getAmount();
} else {
principal = Money.of(getCurrency(), this.fixedPrincipalAmount);
}

Money principal = this.principal.dividedBy(numberOfPrincipalPaymentPeriods, mc.getRoundingMode());
if (isPrincipalGraceApplicableForThisPeriod(periodNumber)) {
principal = principal.zero();
}
return principal;
}

private Money calculatePrincipalDueForInstallment(final int periodNumber, final Money totalDuePerInstallment,
final Money periodInterest) {
public void updateFixedPrincipalAmount(final MathContext mc, final int periodNumber, final Money outstandingAmount) {
final Integer numberOfPrincipalPaymentPeriods = calculateNumberOfPrincipalPaymentPeriods(this.numberOfRepayments);
Money principal = outstandingAmount.dividedBy(numberOfPrincipalPaymentPeriods - periodNumber + 1, mc.getRoundingMode());
this.fixedPrincipalAmount = principal.getAmount();
}

private Money calculatePrincipalDueForInstallment(final int periodNumber, final Money totalDuePerInstallment, final Money periodInterest) {

Money principal = totalDuePerInstallment.minus(periodInterest);
if (isPrincipalGraceApplicableForThisPeriod(periodNumber)) {
Expand Down Expand Up @@ -1047,8 +1059,9 @@ public Money getPrincipal() {
}

public Money getApprovedPrincipal() {
return this.approvedPrincipal ;
return this.approvedPrincipal;
}

public List<DisbursementData> getDisbursementDatas() {
return this.disbursementDatas;
}
Expand Down Expand Up @@ -1256,4 +1269,5 @@ public BigDecimal getActualFixedEmiAmount() {
public Calendar getLoanCalendar() {
return loanCalendar;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public static AmortizationMethod fromInt(final Integer selectedMethod) {
public boolean isEqualInstallment() {
return this.value.equals(AmortizationMethod.EQUAL_INSTALLMENTS.getValue());
}

public boolean isEqualPrincipal() {
return this.value.equals(AmortizationMethod.EQUAL_PRINCIPAL.getValue());
}
}

0 comments on commit a9a5e73

Please sign in to comment.