use of org.mifos.accounts.savings.interest.SavingsInterestDetail in project head by mifos.
the class SavingsServiceFacadeWebTier method determinePostingPeriodResult.
private InterestPostingPeriodResult determinePostingPeriodResult(CalendarPeriod postingPeriod, SavingsBO savingsAccount, List<EndOfDayDetail> allEndOfDayDetailsForAccount) {
List<SavingsProductHistoricalInterestDetail> historicalInterestDetails = savingsAccount.getHistoricalInterestDetailsForPeriod(postingPeriod);
MifosCurrency currencyInUse = savingsAccount.getCurrency();
Money startingBalanceForPeriod = calculateAccountBalanceOn(postingPeriod.getStartDate(), allEndOfDayDetailsForAccount, currencyInUse);
InterestCalcType interestCalcType = savingsAccount.getInterestCalcType();
int accountingNumberOfInterestDaysInYear = AccountingRules.getNumberOfInterestDays();
SavingsInterestDetail interestDetail = new SavingsInterestDetail(interestCalcType, savingsAccount.getInterestRate(), accountingNumberOfInterestDaysInYear, savingsAccount.getMinAmntForInt());
InterestScheduledEvent interestCalculationEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(savingsAccount.getInterestCalculationMeeting());
return doCalculateInterestForPostingPeriod(postingPeriod, startingBalanceForPeriod, historicalInterestDetails, allEndOfDayDetailsForAccount, interestDetail, interestCalculationEvent);
}
use of org.mifos.accounts.savings.interest.SavingsInterestDetail in project head by mifos.
the class SavingsServiceFacadeWebTier method doCalculateInterestForPostingPeriod.
// TODO - move into InterestPostingPeriodCalculator
private InterestPostingPeriodResult doCalculateInterestForPostingPeriod(CalendarPeriod interestPostingPeriod, Money startingBalanceForPeriod, List<SavingsProductHistoricalInterestDetail> historicalInterestDetails, List<EndOfDayDetail> allEndOfDayDetailsForAccount, SavingsInterestDetail interestDetail, InterestScheduledEvent interestCalculationEvent) {
InterestPostingPeriodResult postingPeriodResult = new InterestPostingPeriodResult(interestPostingPeriod);
Money runningBalance = startingBalanceForPeriod;
if (!allEndOfDayDetailsForAccount.isEmpty()) {
List<CalendarPeriod> interestCalculationPeriods = new ArrayList<CalendarPeriod>();
// 1. determine all valid interest calculation periods that fall within this posting period and create a
// interest calculation period calculator for each one (to handle possible different interest rates)
LocalDate firstActivityDate = allEndOfDayDetailsForAccount.get(0).getDate();
if (interestPostingPeriod.contains(firstActivityDate)) {
interestCalculationPeriods = this.interestCalculationIntervalHelper.determineAllPossiblePeriods(firstActivityDate, interestCalculationEvent, interestPostingPeriod.getEndDate());
} else {
interestCalculationPeriods = this.interestCalculationIntervalHelper.determineAllPossiblePeriods(interestPostingPeriod.getStartDate(), interestCalculationEvent, interestPostingPeriod.getEndDate());
}
for (CalendarPeriod calendarPeriod : interestCalculationPeriods) {
NonCompoundingInterestCalculator interestCalculationPeriodCalculator = createInterestCalculationPeriodCalculator(interestDetail, interestCalculationEvent);
SavingsProductHistoricalInterestDetail historicalInterestDetail = findMatchingHistoricalInterestDetail(historicalInterestDetails, calendarPeriod);
if (historicalInterestDetail != null) {
int accountingNumberOfInterestDaysInYear = AccountingRules.getNumberOfInterestDays();
SavingsInterestDetail historicalSavingsInterestDetail = new SavingsInterestDetail(interestDetail.getInterestCalcType(), historicalInterestDetail.getInterestRate(), accountingNumberOfInterestDaysInYear, historicalInterestDetail.getMinAmntForInt());
interestCalculationPeriodCalculator = createInterestCalculationPeriodCalculator(historicalSavingsInterestDetail, interestCalculationEvent);
}
// 2. populate InterestCalculationPeriodDetail with valid end of day details for calculation period
InterestCalculationPeriodDetail interestCalculationPeriodDetail = InterestCalculationPeriodDetail.populatePeriodDetailBasedOnInterestCalculationInterval(calendarPeriod, allEndOfDayDetailsForAccount, runningBalance);
// 3. calculate average principal, total principal and interest details for calculation period.
InterestCalculationPeriodResult calculationPeriodResult = interestCalculationPeriodCalculator.calculateCalculationPeriodDetail(interestCalculationPeriodDetail);
// 4. only sum the total principal as 'interest calculation periods are non-compounding'
runningBalance = runningBalance.add(calculationPeriodResult.getTotalPrincipal());
postingPeriodResult.add(calculationPeriodResult);
}
}
postingPeriodResult.setPeriodBalance(runningBalance);
return postingPeriodResult;
}
Aggregations