Merge pull request #1574 from pramodn02/variableinstalmentchanges
interest calculation fix for months with partial period
This commit is contained in:
+19
-10
@@ -704,15 +704,21 @@ public final class LoanApplicationTerms {
|
|||||||
break;
|
break;
|
||||||
case MONTHS:
|
case MONTHS:
|
||||||
int numberOfMonths = Months.monthsBetween(startDate, endDate).getMonths();
|
int numberOfMonths = Months.monthsBetween(startDate, endDate).getMonths();
|
||||||
int daysLeftAfterMonths = Days.daysBetween(startDate.plusMonths(numberOfMonths), endDate).getDays();
|
LocalDate startDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths);
|
||||||
|
LocalDate endDateAfterConsideringMonths = startDate.plusMonths(numberOfMonths + 1);
|
||||||
|
int daysLeftAfterMonths = Days.daysBetween(startDateAfterConsideringMonths, endDate).getDays();
|
||||||
|
int daysInPeriodAfterMonths = Days.daysBetween(startDateAfterConsideringMonths, endDateAfterConsideringMonths).getDays();
|
||||||
numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfMonths)).add(
|
numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfMonths)).add(
|
||||||
BigDecimal.valueOf((double) daysLeftAfterMonths / 30));
|
BigDecimal.valueOf((double) daysLeftAfterMonths / daysInPeriodAfterMonths));
|
||||||
break;
|
break;
|
||||||
case YEARS:
|
case YEARS:
|
||||||
int numberOfYears = Years.yearsBetween(startDate, endDate).getYears();
|
int numberOfYears = Years.yearsBetween(startDate, endDate).getYears();
|
||||||
int daysLeftAfterYears = Days.daysBetween(startDate.plusYears(numberOfYears), endDate).getDays();
|
LocalDate startDateAfterConsideringYears = startDate.plusYears(numberOfYears);
|
||||||
|
LocalDate endDateAfterConsideringYears = startDate.plusYears(numberOfYears + 1);
|
||||||
|
int daysLeftAfterYears = Days.daysBetween(startDateAfterConsideringYears, endDate).getDays();
|
||||||
|
int daysInPeriodAfterYears = Days.daysBetween(startDateAfterConsideringYears, endDateAfterConsideringYears).getDays();
|
||||||
numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfYears)).add(
|
numberOfPeriods = numberOfPeriods.add(BigDecimal.valueOf(numberOfYears)).add(
|
||||||
BigDecimal.valueOf((double) daysLeftAfterYears / 365));
|
BigDecimal.valueOf((double) daysLeftAfterYears / daysInPeriodAfterYears));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -881,17 +887,20 @@ public final class LoanApplicationTerms {
|
|||||||
|
|
||||||
private long calculatePeriodsInOneYear(final PaymentPeriodsInOneYearCalculator calculator) {
|
private long calculatePeriodsInOneYear(final PaymentPeriodsInOneYearCalculator calculator) {
|
||||||
|
|
||||||
//check if daysInYears is set if so change periodsInOneYear to days set in db
|
// check if daysInYears is set if so change periodsInOneYear to days set
|
||||||
|
// in db
|
||||||
long periodsInOneYear;
|
long periodsInOneYear;
|
||||||
boolean daysInYearToUse = (this.repaymentPeriodFrequencyType.getCode().equalsIgnoreCase("periodFrequencyType.days") && !this.daysInYearType.getCode().equalsIgnoreCase("DaysInYearType.actual"));
|
boolean daysInYearToUse = (this.repaymentPeriodFrequencyType.getCode().equalsIgnoreCase("periodFrequencyType.days") && !this.daysInYearType
|
||||||
if(daysInYearToUse){
|
.getCode().equalsIgnoreCase("DaysInYearType.actual"));
|
||||||
|
if (daysInYearToUse) {
|
||||||
periodsInOneYear = this.daysInYearType.getValue().longValue();
|
periodsInOneYear = this.daysInYearType.getValue().longValue();
|
||||||
}else{
|
} else {
|
||||||
periodsInOneYear = calculator.calculate(this.repaymentPeriodFrequencyType).longValue();
|
periodsInOneYear = calculator.calculate(this.repaymentPeriodFrequencyType).longValue();
|
||||||
}
|
}
|
||||||
switch (this.interestCalculationPeriodMethod) {
|
switch (this.interestCalculationPeriodMethod) {
|
||||||
case DAILY:
|
case DAILY:
|
||||||
periodsInOneYear = (!this.daysInYearType.getCode().equalsIgnoreCase("DaysInYearType.actual")) ? this.daysInYearType.getValue().longValue() : calculator.calculate(PeriodFrequencyType.DAYS).longValue();
|
periodsInOneYear = (!this.daysInYearType.getCode().equalsIgnoreCase("DaysInYearType.actual")) ? this.daysInYearType
|
||||||
|
.getValue().longValue() : calculator.calculate(PeriodFrequencyType.DAYS).longValue();
|
||||||
break;
|
break;
|
||||||
case INVALID:
|
case INVALID:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user