Search in sources :

Example 1 with RepaymentRuleTypes

use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes in project head by mifos.

the class MoratoriumStrategy method shiftDatePastNonMoratoriumHoliday.

/**
     * Given that the date is in a non-moratorium holiday, shift it past the holiday until either it is no longer
     * in a holiday or moratorium, or until it no longer moves (e.g., lands in a same-day holiday).
     *
     * <p> If the date shifts into a moratorium period, then shift it out using the RepaymentRuleType of
     * the most recent non-moratorium holiday that the date was shifted out of. For example, if shifting
     * the date out of a next-working-day holiday lands it in a moratorium period, then use the
     * next-working-day repayment rule to shift it past the moratorium period.</p>
     *
     * @param date the DateTime to be shifted
     * @return the shifted date
     */
private DateTime shiftDatePastNonMoratoriumHoliday(DateTime date) {
    assert date != null;
    assert isEnclosedByAHoliday(date);
    assert !isEnclosedByAHolidayWithRepaymentRule(date, RepaymentRuleTypes.REPAYMENT_MORATORIUM);
    Holiday currentlyEnclosingHoliday = getHolidayEnclosing(date);
    RepaymentRuleTypes mostRecentNonMoratoriumRepaymentRule = //never REPAYMENT_MORATORIUM
    currentlyEnclosingHoliday.getRepaymentRuleType();
    DateTime previousDate = null;
    DateTime adjustedDate = date;
    do {
        previousDate = adjustedDate;
        if (currentlyEnclosingHoliday.getRepaymentRuleType() == RepaymentRuleTypes.REPAYMENT_MORATORIUM) {
            adjustedDate = buildHolidayFromCurrentHolidayWithRepaymentRule(currentlyEnclosingHoliday, mostRecentNonMoratoriumRepaymentRule).adjust(previousDate, workingDays, scheduledEvent);
        } else {
            adjustedDate = (new BasicWorkingDayStrategy(workingDays)).adjust(currentlyEnclosingHoliday.adjust(previousDate, workingDays, scheduledEvent));
            mostRecentNonMoratoriumRepaymentRule = currentlyEnclosingHoliday.getRepaymentRuleType();
        }
        if (isEnclosedByAHoliday(adjustedDate)) {
            currentlyEnclosingHoliday = getHolidayEnclosing(adjustedDate);
        }
    } while (isEnclosedByAHoliday(adjustedDate) && (!adjustedDate.equals(previousDate)));
    return adjustedDate;
}
Also used : RepaymentRuleTypes(org.mifos.application.holiday.util.helpers.RepaymentRuleTypes) Holiday(org.mifos.application.holiday.business.Holiday) DateTime(org.joda.time.DateTime)

Example 2 with RepaymentRuleTypes

use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes in project head by mifos.

the class HolidayAdjustmentRuleFactoryTest method givenRepaymentMoratoriumRuleFactoryShouldReturnNearestNearestScheduledEventBeginningOnStrategy.

@Test
public void givenRepaymentMoratoriumRuleFactoryShouldReturnNearestNearestScheduledEventBeginningOnStrategy() {
    RepaymentRuleTypes holidayAdjustmentRule = RepaymentRuleTypes.REPAYMENT_MORATORIUM;
    // exercise test
    DateAdjustmentStrategy adjustmentStrategy = holidayAdjustmentRuleFactory.createStrategy(originalScheduledDate, workingDays, scheduledEvent, holidayAdjustmentRule);
    assertThat(adjustmentStrategy, is(instanceOf(NextScheduledEventStrategy.class)));
}
Also used : RepaymentRuleTypes(org.mifos.application.holiday.util.helpers.RepaymentRuleTypes) Test(org.junit.Test)

Example 3 with RepaymentRuleTypes

use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes in project head by mifos.

the class HolidayAdjustmentRuleFactoryTest method factoryShouldReturnNearestScheduledEventBeginningOnStrategy.

@Test
public void factoryShouldReturnNearestScheduledEventBeginningOnStrategy() {
    RepaymentRuleTypes holidayAdjustmentRule = RepaymentRuleTypes.NEXT_MEETING_OR_REPAYMENT;
    // exercise test
    DateAdjustmentStrategy adjustmentStrategy = holidayAdjustmentRuleFactory.createStrategy(originalScheduledDate, workingDays, scheduledEvent, holidayAdjustmentRule);
    assertThat(adjustmentStrategy, is(instanceOf(NextScheduledEventStrategy.class)));
}
Also used : RepaymentRuleTypes(org.mifos.application.holiday.util.helpers.RepaymentRuleTypes) Test(org.junit.Test)

Example 4 with RepaymentRuleTypes

use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes in project head by mifos.

the class HolidayAdjustmentRuleFactoryTest method factoryShouldReturnNextWorkingDayStrategyForSameDayRule.

@Test
public void factoryShouldReturnNextWorkingDayStrategyForSameDayRule() {
    RepaymentRuleTypes holidayAdjustmentRule = RepaymentRuleTypes.SAME_DAY;
    // exercise test
    DateAdjustmentStrategy adjustmentStrategy = holidayAdjustmentRuleFactory.createStrategy(originalScheduledDate, workingDays, scheduledEvent, holidayAdjustmentRule);
    assertThat(adjustmentStrategy, is(instanceOf(SameDayStrategy.class)));
}
Also used : RepaymentRuleTypes(org.mifos.application.holiday.util.helpers.RepaymentRuleTypes) Test(org.junit.Test)

Example 5 with RepaymentRuleTypes

use of org.mifos.application.holiday.util.helpers.RepaymentRuleTypes in project head by mifos.

the class HolidayAdjustmentRuleFactoryTest method factoryShouldReturnNextWorkingDayStrategy.

@Test
public void factoryShouldReturnNextWorkingDayStrategy() {
    RepaymentRuleTypes holidayAdjustmentRule = RepaymentRuleTypes.NEXT_WORKING_DAY;
    // exercise test
    DateAdjustmentStrategy adjustmentStrategy = holidayAdjustmentRuleFactory.createStrategy(originalScheduledDate, workingDays, scheduledEvent, holidayAdjustmentRule);
    assertThat(adjustmentStrategy, is(instanceOf(NextWorkingDayStrategy.class)));
}
Also used : RepaymentRuleTypes(org.mifos.application.holiday.util.helpers.RepaymentRuleTypes) Test(org.junit.Test)

Aggregations

RepaymentRuleTypes (org.mifos.application.holiday.util.helpers.RepaymentRuleTypes)6 Test (org.junit.Test)4 DateTime (org.joda.time.DateTime)2 Date (java.util.Date)1 Locale (java.util.Locale)1 LocalDate (org.joda.time.LocalDate)1 Before (org.junit.Before)1 Holiday (org.mifos.application.holiday.business.Holiday)1 HolidayDetails (org.mifos.dto.domain.HolidayDetails)1