Search in sources :

Example 1 with SavingsProductHistoricalInterestDetail

use of org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail 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);
}
Also used : SavingsInterestScheduledEventFactory(org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory) Money(org.mifos.framework.util.helpers.Money) InterestCalcType(org.mifos.accounts.productdefinition.util.helpers.InterestCalcType) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) SavingsInterestDetail(org.mifos.accounts.savings.interest.SavingsInterestDetail) SavingsProductHistoricalInterestDetail(org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail) MifosCurrency(org.mifos.application.master.business.MifosCurrency)

Example 2 with SavingsProductHistoricalInterestDetail

use of org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail 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 3 with SavingsProductHistoricalInterestDetail

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

the class SavingsBO method getHistoricalInterestDetailsForPeriod.

public List<SavingsProductHistoricalInterestDetail> getHistoricalInterestDetailsForPeriod(CalendarPeriod period) {
    List<SavingsProductHistoricalInterestDetail> validHistoricalDetails = new ArrayList<SavingsProductHistoricalInterestDetail>();
    List<SavingsProductHistoricalInterestDetail> allHistoricalDetails = this.savingsOffering.getHistoricalInterestDetails();
    for (SavingsProductHistoricalInterestDetail interestDetail : allHistoricalDetails) {
        if (period.contains(interestDetail.getStartDate())) {
            validHistoricalDetails.add(interestDetail);
        }
    }
    return validHistoricalDetails;
}
Also used : ArrayList(java.util.ArrayList) SavingsProductHistoricalInterestDetail(org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail)

Example 4 with SavingsProductHistoricalInterestDetail

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

the class SavingsOfferingBO method updateSavingsDetails.

public void updateSavingsDetails(Money recommendedAmount, RecommendedAmntUnitEntity recommendedAmntUnit, Money maxAmntWithdrawl, Double interestRate, Money minAmountRequiredForInterestToBeCalculated, LocalDate updateDate) {
    this.maxAmntWithdrawl = maxAmntWithdrawl;
    this.recommendedAmount = recommendedAmount;
    this.recommendedAmntUnit = recommendedAmntUnit;
    if (interestDetailsHaveChanged(interestRate, minAmountRequiredForInterestToBeCalculated)) {
        InterestScheduledEvent interestCalculationEvent = new SavingsInterestScheduledEventFactory().createScheduledEventFrom(this.getTimePerForInstcalc().getMeeting());
        LocalDate nextInterestCalculationDate = interestCalculationEvent.nextMatchingDateAfter(startOfFiscalYear(updateDate), updateDate);
        LocalDate startOfPeriodDate = interestCalculationEvent.findFirstDateOfPeriodForMatchingDate(nextInterestCalculationDate);
        LocalDate previousInterestCalculationDate = startOfPeriodDate.minusDays(1);
        LocalDate startOfPreviousPeriodDate = interestCalculationEvent.findFirstDateOfPeriodForMatchingDate(previousInterestCalculationDate);
        CalendarPeriod previousInterestCalculationPeriod = new CalendarPeriod(startOfPreviousPeriodDate, previousInterestCalculationDate);
        if (noHistoricalRecordExistsFor(previousInterestCalculationPeriod)) {
            SavingsProductHistoricalInterestDetail historicalInterestDetail = new SavingsProductHistoricalInterestDetail(previousInterestCalculationPeriod, this.interestRate, this.minAmntForInt, this);
            this.historicalInterestDetails.add(historicalInterestDetail);
        }
        this.interestRate = interestRate;
        this.minAmntForInt = minAmountRequiredForInterestToBeCalculated;
    }
}
Also used : SavingsInterestScheduledEventFactory(org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) CalendarPeriod(org.mifos.accounts.savings.interest.CalendarPeriod) LocalDate(org.joda.time.LocalDate) SavingsProductHistoricalInterestDetail(org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail)

Example 5 with SavingsProductHistoricalInterestDetail

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

the class SavingsServiceFacadeWebTier method findMatchingHistoricalInterestDetail.

private SavingsProductHistoricalInterestDetail findMatchingHistoricalInterestDetail(List<SavingsProductHistoricalInterestDetail> historicalInterestDetails, CalendarPeriod calendarPeriod) {
    SavingsProductHistoricalInterestDetail match = null;
    SavingsProductHistoricalInterestDetail closestMatch = null;
    for (SavingsProductHistoricalInterestDetail historicalInterestDetail : historicalInterestDetails) {
        if (calendarPeriod.contains(historicalInterestDetail.getStartDate())) {
            match = historicalInterestDetail;
        }
        if (calendarPeriod.getEndDate().isBefore(historicalInterestDetail.getStartDate())) {
            closestMatch = historicalInterestDetail;
        }
    }
    if (match == null) {
        match = closestMatch;
    }
    return match;
}
Also used : SavingsProductHistoricalInterestDetail(org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail)

Aggregations

SavingsProductHistoricalInterestDetail (org.mifos.accounts.savings.interest.SavingsProductHistoricalInterestDetail)5 ArrayList (java.util.ArrayList)2 LocalDate (org.joda.time.LocalDate)2 CalendarPeriod (org.mifos.accounts.savings.interest.CalendarPeriod)2 SavingsInterestDetail (org.mifos.accounts.savings.interest.SavingsInterestDetail)2 InterestScheduledEvent (org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent)2 SavingsInterestScheduledEventFactory (org.mifos.accounts.savings.interest.schedule.SavingsInterestScheduledEventFactory)2 Money (org.mifos.framework.util.helpers.Money)2 InterestCalcType (org.mifos.accounts.productdefinition.util.helpers.InterestCalcType)1 InterestCalculationPeriodDetail (org.mifos.accounts.savings.interest.InterestCalculationPeriodDetail)1 InterestCalculationPeriodResult (org.mifos.accounts.savings.interest.InterestCalculationPeriodResult)1 InterestPostingPeriodResult (org.mifos.accounts.savings.interest.InterestPostingPeriodResult)1 NonCompoundingInterestCalculator (org.mifos.accounts.savings.interest.NonCompoundingInterestCalculator)1 MifosCurrency (org.mifos.application.master.business.MifosCurrency)1