Search in sources :

Example 6 with FeeInstallment

use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeBothAccountAndFeeAreScheduledEveryWeekStartwithSecondInstallmentShouldGetOneFeeInstallmentPerAccountEvent.

/*************************************
     * These tests verify that fees are correctly merged for a single fee on an account.
     ****************************************/
@Test
public void createMergedFeeInstallmentsForOneFeeBothAccountAndFeeAreScheduledEveryWeekStartwithSecondInstallmentShouldGetOneFeeInstallmentPerAccountEvent() {
    ScheduledEvent masterEvent = new ScheduledEventBuilder().every(1).weeks().build();
    FeeBO feeBO = createWeeklyFeeBO(1);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFeeStartingWith(masterEvent, accountFeesEntity, 2, 2);
    assertThat(feeInstallments.size(), is(2));
    assertFeeInstallment(feeInstallments.get(0), 2, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 3, 10.0, feeBO);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 7 with FeeInstallment

use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeAccountScheduledEverySecondWeekFeeScheduledEveryThirdWeek.

@Test
public void createMergedFeeInstallmentsForOneFeeAccountScheduledEverySecondWeekFeeScheduledEveryThirdWeek() {
    ScheduledEvent masterEvent = new ScheduledEventBuilder().every(2).weeks().build();
    FeeBO feeBO = createWeeklyFeeBO(3);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(masterEvent, accountFeesEntity, 7);
    assertThat(feeInstallments.size(), is(5));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 3, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(2), 4, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(3), 6, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(4), 7, 10.0, feeBO);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 8 with FeeInstallment

use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.

the class FeeInstallmentTest method createMergedFeeInstallmentsForTwoFeesAccountScheduledBiWeeklyFee1ScheduledWeeklyFee2ScheduledEveryThreeWeeks.

/**
     * Expected results:
     * | week           |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 |
     * | account event  |    |  1 |    |  2 |    |  3 |    |  4 |    |  5 |    |  6 |
     * | fee1 event     |  x |  x |  x |  x |  x |  x |  x |  x |  x |  x |  x |  x |
     * | fee2 event     |    |    |  y |    |    |  y |    |    |  y |    |    |  y |
     */
@Test
public void createMergedFeeInstallmentsForTwoFeesAccountScheduledBiWeeklyFee1ScheduledWeeklyFee2ScheduledEveryThreeWeeks() {
    ScheduledEvent masterEvent = new ScheduledEventBuilder().every(2).weeks().build();
    FeeBO feeBO1 = createWeeklyFeeBO(1);
    FeeBO feeBO2 = createWeeklyFeeBO(3);
    AccountFeesEntity accountFeesEntity1 = createAccountFeesEntity(feeBO1, 10.0);
    AccountFeesEntity accountFeesEntity2 = createAccountFeesEntity(feeBO2, 13.0);
    List<AccountFeesEntity> accountFees = Arrays.asList(new AccountFeesEntity[] { accountFeesEntity1, accountFeesEntity2 });
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallments(masterEvent, accountFees, 6);
    assertThat(feeInstallments.size(), is(10));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(1), 2, 20.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(2), 3, 20.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(3), 4, 20.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(4), 5, 20.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(5), 6, 20.0, feeBO1);
    assertFeeInstallment(feeInstallments.get(6), 1, 13.0, feeBO2);
    assertFeeInstallment(feeInstallments.get(7), 3, 13.0, feeBO2);
    assertFeeInstallment(feeInstallments.get(8), 4, 13.0, feeBO2);
    assertFeeInstallment(feeInstallments.get(9), 6, 13.0, feeBO2);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 9 with FeeInstallment

use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.

the class FeeInstallmentTest method createMergedFeeInstallmentsForOneFeeAccountScheduledEveryThirdWeekFeeScheduledEverySecondWeek.

@Test
public void createMergedFeeInstallmentsForOneFeeAccountScheduledEveryThirdWeekFeeScheduledEverySecondWeek() {
    ScheduledEvent accountScheduledEvent = new ScheduledEventBuilder().every(3).weeks().build();
    FeeBO feeBO = createWeeklyFeeBO(2);
    AccountFeesEntity accountFeesEntity = createAccountFeesEntity(feeBO, 10.0);
    List<FeeInstallment> feeInstallments = FeeInstallment.createMergedFeeInstallmentsForOneFee(accountScheduledEvent, accountFeesEntity, 4);
    assertThat(feeInstallments.size(), is(4));
    assertFeeInstallment(feeInstallments.get(0), 1, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(1), 2, 10.0, feeBO);
    assertFeeInstallment(feeInstallments.get(2), 3, 20.0, feeBO);
    assertFeeInstallment(feeInstallments.get(3), 4, 10.0, feeBO);
}
Also used : ScheduledEvent(org.mifos.schedule.ScheduledEvent) ScheduledEventBuilder(org.mifos.domain.builders.ScheduledEventBuilder) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) FeeBO(org.mifos.accounts.fees.business.FeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 10 with FeeInstallment

use of org.mifos.accounts.util.helpers.FeeInstallment in project head by mifos.

the class LoanBO method handlePeriodic.

/**
     * Calculate and return the list of {@link FeeInstallment}s to be applied. A fee installment will apply to one of
     * the given loan installmentDates if the installmentIds match. Here's the criteria for matching a fee installment
     * to a loan installment: Calculate the dates in nonAdjustedInstallmentDates that the fee would be due if the fee
     * were to start today. For each unadjusted fee date, build a FeeInstallment object based on the installmentId of
     * the nearest loan installment date in the list installmentDates (this is what causes fees to pile up on a future
     * loan installment that has been pushed out of a holiday), and add it to the list to be returned.
     */
@Override
protected final List<FeeInstallment> handlePeriodic(final AccountFeesEntity accountFees, final List<InstallmentDate> installmentDates, final List<InstallmentDate> nonAdjustedInstallmentDates) throws AccountException {
    Money accountFeeAmount = accountFees.getAccountFeeAmount();
    MeetingBO feeMeetingFrequency = accountFees.getFees().getFeeFrequency().getFeeMeetingFrequency();
    // Generate the dates in nonAdjustedInstallmentDates that the fee would be due if
    // the fee were to start today
    List<Date> feeDates = getFeeDates(feeMeetingFrequency, nonAdjustedInstallmentDates, false);
    // For each unadjusted fee date, build a FeeInstallment object based on the installmentId of the
    // nearest loan installment date adjusted for holidays (this is what causes fees to pile up
    // on a future loan installment that has been pushed out of a holiday), and add it to the list to
    // be returned
    ListIterator<Date> feeDatesIterator = feeDates.listIterator();
    List<FeeInstallment> feeInstallmentList = new ArrayList<FeeInstallment>();
    while (feeDatesIterator.hasNext()) {
        Date feeDate = feeDatesIterator.next();
        logger.debug("Handling periodic fee.." + feeDate);
        Short installmentId = getMatchingInstallmentId(installmentDates, feeDate);
        feeInstallmentList.add(buildFeeInstallment(installmentId, accountFeeAmount, accountFees));
    }
    return feeInstallmentList;
}
Also used : Money(org.mifos.framework.util.helpers.Money) MeetingBO(org.mifos.application.meeting.business.MeetingBO) FeeInstallment(org.mifos.accounts.util.helpers.FeeInstallment) ArrayList(java.util.ArrayList) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) LocalDate(org.joda.time.LocalDate)

Aggregations

FeeInstallment (org.mifos.accounts.util.helpers.FeeInstallment)25 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)17 ScheduledEvent (org.mifos.schedule.ScheduledEvent)12 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)11 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 AmountFeeBO (org.mifos.accounts.fees.business.AmountFeeBO)9 FeeBO (org.mifos.accounts.fees.business.FeeBO)9 ScheduledEventBuilder (org.mifos.domain.builders.ScheduledEventBuilder)9 Money (org.mifos.framework.util.helpers.Money)9 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)7 Date (java.util.Date)4 LocalDate (org.joda.time.LocalDate)4 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 AccountFeesActionDetailEntity (org.mifos.accounts.business.AccountFeesActionDetailEntity)2 RateAmountFlag (org.mifos.accounts.fees.util.helpers.RateAmountFlag)2 InstallmentPrincipalAndInterest (org.mifos.accounts.loan.util.helpers.InstallmentPrincipalAndInterest)2 MeetingBO (org.mifos.application.meeting.business.MeetingBO)2 DateTimeService (org.mifos.framework.util.DateTimeService)2