Search in sources :

Example 1 with NonCompoundingInterestCalculator

use of org.mifos.accounts.savings.interest.NonCompoundingInterestCalculator 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;
}
Also used : InterestPostingPeriodResult(org.mifos.accounts.savings.interest.InterestPostingPeriodResult) Money(org.mifos.framework.util.helpers.Money) InterestCalculationPeriodResult(org.mifos.accounts.savings.interest.InterestCalculationPeriodResult) CalendarPeriod(org.mifos.accounts.savings.interest.CalendarPeriod) ArrayList(java.util.ArrayList) InterestCalculationPeriodDetail(org.mifos.accounts.savings.interest.InterestCalculationPeriodDetail) SavingsInterestDetail(org.mifos.accounts.savings.interest.SavingsInterestDetail) LocalDate(org.joda.time.LocalDate) SavingsProductHistoricalInterestDetail(org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail) NonCompoundingInterestCalculator(org.mifos.accounts.savings.interest.NonCompoundingInterestCalculator)

Example 2 with NonCompoundingInterestCalculator

use of org.mifos.accounts.savings.interest.NonCompoundingInterestCalculator in project head by mifos.

the class SavingsServiceFacadeWebTier method createInterestCalculationPeriodCalculator.

private NonCompoundingInterestCalculator createInterestCalculationPeriodCalculator(SavingsInterestDetail interestDetail, InterestScheduledEvent interestCalculationEvent) {
    InterestCalculator interestCalculator = SavingsInterestCalculatorFactory.create(interestDetail);
    NonCompoundingInterestCalculator interestCalculationPeriodCalculator = new InterestCalculationPeriodCalculator(interestCalculator, interestCalculationEvent, interestCalculationIntervalHelper);
    return interestCalculationPeriodCalculator;
}
Also used : InterestCalculator(org.mifos.accounts.savings.interest.InterestCalculator) NonCompoundingInterestCalculator(org.mifos.accounts.savings.interest.NonCompoundingInterestCalculator) InterestCalculationPeriodCalculator(org.mifos.accounts.savings.interest.InterestCalculationPeriodCalculator) NonCompoundingInterestCalculator(org.mifos.accounts.savings.interest.NonCompoundingInterestCalculator)

Aggregations

NonCompoundingInterestCalculator (org.mifos.accounts.savings.interest.NonCompoundingInterestCalculator)2 ArrayList (java.util.ArrayList)1 LocalDate (org.joda.time.LocalDate)1 CalendarPeriod (org.mifos.accounts.savings.interest.CalendarPeriod)1 InterestCalculationPeriodCalculator (org.mifos.accounts.savings.interest.InterestCalculationPeriodCalculator)1 InterestCalculationPeriodDetail (org.mifos.accounts.savings.interest.InterestCalculationPeriodDetail)1 InterestCalculationPeriodResult (org.mifos.accounts.savings.interest.InterestCalculationPeriodResult)1 InterestCalculator (org.mifos.accounts.savings.interest.InterestCalculator)1 InterestPostingPeriodResult (org.mifos.accounts.savings.interest.InterestPostingPeriodResult)1 SavingsInterestDetail (org.mifos.accounts.savings.interest.SavingsInterestDetail)1 SavingsProductHistoricalInterestDetail (org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail)1 Money (org.mifos.framework.util.helpers.Money)1