Search in sources :

Example 46 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class XlsClientsImporter method validateAge.

private void validateAge(final Date dateOfBirth) throws CellException, ConfigurationException {
    final DateMidnight dob = new DateMidnight(dateOfBirth);
    final DateTime now = new DateTime();
    final Years age = Years.yearsBetween(dob, now);
    final int minimumAge = ClientRules.getMinimumAge();
    final int maximumAge = ClientRules.getMaximumAge();
    if (age.getYears() < 0) {
        throw new CellException(getMessage(XlsMessageConstants.FUTURE_DATE));
    } else if (ClientRules.isAgeCheckEnabled() && !ClientRules.isAgeCheckWarningInsteadOfErrorEnabled() && (age.getYears() < minimumAge || age.getYears() > maximumAge)) {
        throw new CellException(getMessage(XlsMessageConstants.INVALID_AGE, new Object[] { minimumAge, maximumAge }));
    }
}
Also used : Years(org.joda.time.Years) DateMidnight(org.joda.time.DateMidnight) DateTime(org.joda.time.DateTime)

Example 47 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class LegacyAccountDaoIntegrationTest method testGetLoanSchedulesForAccountThatAreWithinDates.

@Test
public void testGetLoanSchedulesForAccountThatAreWithinDates() throws Exception {
    DateTime fromDate = new DateMidnight().toDateTime().plusDays(1);
    DateTime thruDate = new DateMidnight().toDateTime().plusDays(30);
    List<LoanScheduleEntity> affectedDates = legacyAccountDao.getLoanSchedulesForAccountThatAreWithinDates(groupLoan.getAccountId(), fromDate, thruDate);
    Assert.assertNotNull(affectedDates);
    Assert.assertEquals(4, affectedDates.size());
}
Also used : LoanScheduleEntity(org.mifos.accounts.loan.business.LoanScheduleEntity) DateMidnight(org.joda.time.DateMidnight) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 48 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class LegacyAccountDaoIntegrationTest method testGetSavingsSchedulesForAccountThatAreWithinDates.

@Test
public void testGetSavingsSchedulesForAccountThatAreWithinDates() throws Exception {
    savingsBO = new TestCollectionSheetRetrieveSavingsAccountsUtils().createSavingsAccount(group, "clm", "3.0", false, false);
    DateTime fromDate = new DateMidnight().toDateTime().plusDays(1);
    DateTime thruDate = new DateMidnight().toDateTime().plusDays(37);
    List<SavingsScheduleEntity> affectedDates = legacyAccountDao.getSavingsSchedulesForAccountThatAreWithinDates(savingsBO.getAccountId(), fromDate, thruDate);
    Assert.assertNotNull(affectedDates);
    Assert.assertEquals(5, affectedDates.size());
}
Also used : DateMidnight(org.joda.time.DateMidnight) TestCollectionSheetRetrieveSavingsAccountsUtils(org.mifos.application.servicefacade.TestCollectionSheetRetrieveSavingsAccountsUtils) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 49 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class TestUtils method assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek.

public static void assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(CustomerBO customer, WeekDay expectedDayOfWeek) {
    Set<AccountActionDateEntity> customerSchedules = customer.getCustomerAccount().getAccountActionDates();
    for (AccountActionDateEntity accountActionDateEntity : customerSchedules) {
        CustomerScheduleEntity customerSchedule = (CustomerScheduleEntity) accountActionDateEntity;
        LocalDate scheduledDate = new LocalDate(customerSchedule.getActionDate());
        DateTime endOfCurrentInstallmentPeriod = TestUtils.nearestDateMatchingPeriodStartingOn(new DateMidnight().toDateTime(), customer.getCustomerMeetingValue());
        if (scheduledDate.isAfter(new LocalDate(endOfCurrentInstallmentPeriod))) {
            assertThat(scheduledDate.dayOfWeek().get(), is(WeekDay.getJodaDayOfWeekThatMatchesMifosWeekDay(expectedDayOfWeek.getValue())));
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) DateMidnight(org.joda.time.DateMidnight) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 50 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class HolidayServiceFacadeWebTierTest method validateDisbursementDateIsNotInHolidayShouldThrowExceptionWhenDateIsInAHoliday.

@Test
public void validateDisbursementDateIsNotInHolidayShouldThrowExceptionWhenDateIsInAHoliday() throws Exception {
    DateTime disbursementDate = new DateMidnight().toDateTime().withDayOfWeek(DayOfWeek.monday());
    List<Holiday> holidays = new ArrayList<Holiday>();
    Holiday holiday = new HolidayBuilder().from(disbursementDate.minusDays(1)).to(disbursementDate.plusDays(6)).build();
    holidays.add(holiday);
    try {
        when(holidayDao.findAllHolidaysFromDateAndNext(officeId, new LocalDate(disbursementDate).toString())).thenReturn(holidays);
        holidayServiceFacade.validateDisbursementDateForNewLoan(officeId, disbursementDate);
        fail("Should have thrown BusinessRuleException");
    } catch (BusinessRuleException e) {
        assertThat(e.getMessageKey(), is(LoanExceptionConstants.DISBURSEMENTDATE_MUST_NOT_BE_IN_A_HOLIDAY));
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) DateMidnight(org.joda.time.DateMidnight) Holiday(org.mifos.application.holiday.business.Holiday) ArrayList(java.util.ArrayList) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateMidnight (org.joda.time.DateMidnight)70 DateTime (org.joda.time.DateTime)33 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)10 Money (org.mifos.framework.util.helpers.Money)10 Ignore (org.junit.Ignore)8 MeetingBO (org.mifos.application.meeting.business.MeetingBO)8 LocalDate (org.joda.time.LocalDate)6 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)6 Holiday (org.mifos.application.holiday.business.Holiday)6 Date (java.util.Date)5 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)5 OfficeBO (org.mifos.customers.office.business.OfficeBO)5 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)5 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)4 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)4 UserContext (org.mifos.security.util.UserContext)4 DateTimeZone (org.joda.time.DateTimeZone)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Before (org.junit.Before)3