//Create a runner that represents the begin of the actual month
//For the first month this may be another day of month than 1
LocalDate actualMonthBegin = begin;
//Now iterate over all months
MutableMoney rentSummer = new MutableMoney();
while ( actualMonthBegin.isBefore( end ) ) {
LocalDate actualMonthEnd = actualMonthBegin.plusMonths( 1 );
//Check if this month is complete --> else only add the rest
if ( actualMonthEnd.isAfter( end ) ) {
actualMonthEnd = end;
}
double monthYears = getTimeSystem().calculateYears( actualMonthBegin, actualMonthEnd );
double monthDays = getTimeSystem().calculateDays( actualMonthBegin, actualMonthEnd );
double monthRate = getInterestRateProvider().getRate( actualMonthBegin );
//add the rent for the rent
Money baseForMonth = rentSummer.immutable();
Money compoundInterest;
if ( getBackingCalculationSystem().isCompoundSystem() && baseForMonth.getValue() != 0 ) {
compoundInterest = getBackingCalculationSystem().calculateInterest( baseForMonth, monthYears, monthDays, monthRate );
rentSummer.plus( compoundInterest );
} else {
compoundInterest = Money.ZERO;
}
//add the rent for the amount
Money interest = getBackingCalculationSystem().calculateInterest( amount, monthYears, monthDays, monthRate );
rentSummer.plus( interest );
//Build the information object (if expected)
interestDetails.add( new InterestDetails( actualMonthBegin, actualMonthEnd, monthRate, baseForMonth, interest.plus( compoundInterest ), monthDays ) );
//Next month --> now we really need the first day of the month