Search in sources :

Example 1 with InterestCalculationPeriodResult

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

the class SavingsPostInterestTest method whenPostingInterestASingleAccountPaymentIsMade.

@Test
public void whenPostingInterestASingleAccountPaymentIsMade() {
    // setup
    InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
    Money interestToBePosted = TestUtils.createMoney("100");
    DateTime activationDate = new DateTime().withDate(2010, 7, 20);
    DateTime nextInterestPostingDate = new DateTime().withDate(2010, 7, 31);
    savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withNextInterestPostingDateOf(nextInterestPostingDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
    // pre verification
    assertTrue(savingsAccount.getAccountPayments().isEmpty());
    InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
    InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().from(nextInterestPostingDate.toLocalDate()).to(nextInterestPostingDate.toLocalDate()).with(calculationPeriod).build();
    PersonnelBO createdBy = new PersonnelBuilder().build();
    // exercise
    savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
    // verification
    assertFalse(savingsAccount.getAccountPayments().isEmpty());
    AccountPaymentEntity interestPostingPayment = savingsAccount.getAccountPayments().get(0);
    assertThat(interestPostingPayment.getAccount(), is((AccountBO) savingsAccount));
    assertThat(interestPostingPayment.getAmount(), is(interestToBePosted));
    assertThat(interestPostingPayment.getPaymentType().getId(), is(SavingsConstants.DEFAULT_PAYMENT_TYPE));
    assertThat(new LocalDate(interestPostingPayment.getPaymentDate()), is(nextInterestPostingDate.toLocalDate()));
}
Also used : InterestPostingPeriodResult(org.mifos.accounts.savings.interest.InterestPostingPeriodResult) PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) InterestCalculationPeriodResult(org.mifos.accounts.savings.interest.InterestCalculationPeriodResult) InterestPostingPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestPostingPeriodResultBuilder) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Money(org.mifos.framework.util.helpers.Money) AccountBO(org.mifos.accounts.business.AccountBO) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) InterestCalculationPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestCalculationPeriodResultBuilder) Test(org.junit.Test)

Example 2 with InterestCalculationPeriodResult

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

the class SavingsPostInterestTest method whenPostingInterestNextInterestPostingDateIsPopulatedWithNextPostingDate.

@Test
public void whenPostingInterestNextInterestPostingDateIsPopulatedWithNextPostingDate() {
    // setup
    InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
    DateTime activationDate = new DateTime().withDate(2010, 7, 20);
    DateTime nextInterestPostingDate = new DateTime().withDate(2010, 7, 31);
    savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withNextInterestPostingDateOf(nextInterestPostingDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
    // pre verification
    assertThat(new LocalDate(savingsAccount.getNextIntPostDate()), is(nextInterestPostingDate.toLocalDate()));
    InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
    InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().from(nextInterestPostingDate.toLocalDate()).to(nextInterestPostingDate.toLocalDate()).with(calculationPeriod).build();
    PersonnelBO createdBy = new PersonnelBuilder().build();
    // exercise
    savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
    // verification
    assertThat(new LocalDate(savingsAccount.getNextIntPostDate()), is(endOfMonthAfter(nextInterestPostingDate)));
}
Also used : InterestPostingPeriodResult(org.mifos.accounts.savings.interest.InterestPostingPeriodResult) PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) InterestCalculationPeriodResult(org.mifos.accounts.savings.interest.InterestCalculationPeriodResult) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) InterestPostingPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestPostingPeriodResultBuilder) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) InterestCalculationPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestCalculationPeriodResultBuilder) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with InterestCalculationPeriodResult

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

the class SavingsPostInterestTest method whenPostingInterestASavingsAcitvityIsAddedForInterestPostingEvent.

@Test
public void whenPostingInterestASavingsAcitvityIsAddedForInterestPostingEvent() {
    // setup
    InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
    DateTime activationDate = new DateTime().withDate(2010, 7, 20);
    savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
    // pre verification
    List<SavingsActivityEntity> preSavingsActivityityDetails = new ArrayList<SavingsActivityEntity>(savingsAccount.getSavingsActivityDetails());
    assertThat(preSavingsActivityityDetails.size(), is(0));
    InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
    InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().with(calculationPeriod).build();
    PersonnelBO createdBy = new PersonnelBuilder().build();
    // exercise
    savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
    // verification
    List<SavingsActivityEntity> savingsActivityityDetails = new ArrayList<SavingsActivityEntity>(savingsAccount.getSavingsActivityDetails());
    assertThat(savingsActivityityDetails.size(), is(1));
}
Also used : InterestPostingPeriodResult(org.mifos.accounts.savings.interest.InterestPostingPeriodResult) PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) InterestCalculationPeriodResult(org.mifos.accounts.savings.interest.InterestCalculationPeriodResult) InterestPostingPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestPostingPeriodResultBuilder) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) SavingsActivityEntity(org.mifos.accounts.savings.business.SavingsActivityEntity) InterestCalculationPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestCalculationPeriodResultBuilder) Test(org.junit.Test)

Example 4 with InterestCalculationPeriodResult

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

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

the class SavingsPostInterestTest method whenPostingInterestASavingsAcitvityIsAddedWithCorrectDetails.

@Test
public void whenPostingInterestASavingsAcitvityIsAddedWithCorrectDetails() {
    // setup
    InterestScheduledEvent postingSchedule = new MonthlyOnLastDayOfMonthInterestScheduledEvent(1);
    DateTime activationDate = new DateTime().withDate(2010, 7, 20);
    DateTime nextInterestPostingDate = new DateTime().withDate(2010, 7, 31);
    savingsAccount = new SavingsAccountBuilder().active().withActivationDate(activationDate).withNextInterestPostingDateOf(nextInterestPostingDate).withSavingsProduct(savingsProduct).withCustomer(client).build();
    // pre verification
    assertThat(new LocalDate(savingsAccount.getNextIntPostDate()), is(nextInterestPostingDate.toLocalDate()));
    InterestCalculationPeriodResult calculationPeriod = new InterestCalculationPeriodResultBuilder().withCalculatedInterest("100").build();
    InterestPostingPeriodResult interestPostingPeriodResult = new InterestPostingPeriodResultBuilder().from(nextInterestPostingDate.toLocalDate()).to(nextInterestPostingDate.toLocalDate()).with(calculationPeriod).build();
    PersonnelBO createdBy = new PersonnelBuilder().build();
    // exercise
    savingsAccount.postInterest(postingSchedule, interestPostingPeriodResult, createdBy);
    // verification
    List<SavingsActivityEntity> savingsActivityityDetails = new ArrayList<SavingsActivityEntity>(savingsAccount.getSavingsActivityDetails());
    SavingsActivityEntity interestPostingActivity = savingsActivityityDetails.get(0);
    assertThat(interestPostingActivity.getAccount(), is((AccountBO) savingsAccount));
    assertThat(interestPostingActivity.getActivity().getId(), is(AccountActionTypes.SAVINGS_INTEREST_POSTING.getValue()));
    assertThat(interestPostingActivity.getAmount(), is(TestUtils.createMoney("100")));
    assertThat(datePartOf(interestPostingActivity.getTrxnCreatedDate()), is(nextInterestPostingDate.toLocalDate()));
}
Also used : InterestPostingPeriodResult(org.mifos.accounts.savings.interest.InterestPostingPeriodResult) PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) InterestCalculationPeriodResult(org.mifos.accounts.savings.interest.InterestCalculationPeriodResult) InterestPostingPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestPostingPeriodResultBuilder) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) AccountBO(org.mifos.accounts.business.AccountBO) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) MonthlyOnLastDayOfMonthInterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) SavingsAccountBuilder(org.mifos.domain.builders.SavingsAccountBuilder) InterestCalculationPeriodResultBuilder(org.mifos.accounts.savings.interest.InterestCalculationPeriodResultBuilder) SavingsActivityEntity(org.mifos.accounts.savings.business.SavingsActivityEntity) Test(org.junit.Test)

Aggregations

InterestCalculationPeriodResult (org.mifos.accounts.savings.interest.InterestCalculationPeriodResult)9 InterestPostingPeriodResult (org.mifos.accounts.savings.interest.InterestPostingPeriodResult)9 DateTime (org.joda.time.DateTime)8 Test (org.junit.Test)8 InterestCalculationPeriodResultBuilder (org.mifos.accounts.savings.interest.InterestCalculationPeriodResultBuilder)8 InterestPostingPeriodResultBuilder (org.mifos.accounts.savings.interest.InterestPostingPeriodResultBuilder)8 InterestScheduledEvent (org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent)8 MonthlyOnLastDayOfMonthInterestScheduledEvent (org.mifos.accounts.savings.interest.schedule.internal.MonthlyOnLastDayOfMonthInterestScheduledEvent)8 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)8 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)8 SavingsAccountBuilder (org.mifos.domain.builders.SavingsAccountBuilder)8 LocalDate (org.joda.time.LocalDate)6 ArrayList (java.util.ArrayList)4 AccountBO (org.mifos.accounts.business.AccountBO)3 Money (org.mifos.framework.util.helpers.Money)3 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)2 SavingsActivityEntity (org.mifos.accounts.savings.business.SavingsActivityEntity)2 AccountTrxnEntity (org.mifos.accounts.business.AccountTrxnEntity)1 SavingsTrxnDetailEntity (org.mifos.accounts.savings.business.SavingsTrxnDetailEntity)1 CalendarPeriod (org.mifos.accounts.savings.interest.CalendarPeriod)1