Search in sources :

Example 41 with DateMidnight

use of org.joda.time.DateMidnight in project uPortal by Jasig.

the class JpaEventAggregationManagementDaoTest method testAcademicTermDetails.

@Test
public void testAcademicTermDetails() throws Exception {
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
            assertEquals(0, academicTermDetail.size());
            List<AcademicTermDetail> academicTermDetails = new ArrayList<AcademicTermDetail>();
            academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 1, 1), new DateMidnight(2012, 6, 1), "Spring 2012"));
            academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 6, 1), new DateMidnight(2012, 9, 1), "Summer 2012"));
            academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 9, 1), new DateMidnight(2013, 1, 1), "Fall 2012"));
            eventAggregationManagementDao.setAcademicTermDetails(academicTermDetails);
        }
    });
    try {
        this.executeInTransaction(new CallableWithoutResult() {

            @Override
            protected void callWithoutResult() {
                final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
                assertEquals(3, academicTermDetail.size());
                academicTermDetail.add(new AcademicTermDetailImpl(new DateMidnight(2012, 1, 1), new DateMidnight(2013, 6, 1), "Spring 2013"));
                try {
                    eventAggregationManagementDao.setAcademicTermDetails(academicTermDetail);
                    fail();
                } catch (IllegalArgumentException e) {
                // expected
                }
            }
        });
        fail();
    } catch (TransactionSystemException e) {
    // Expected
    }
    this.executeInTransaction(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
            assertEquals(3, academicTermDetail.size());
            academicTermDetail.get(0).setTermName("New Term");
            academicTermDetail.remove(2);
            eventAggregationManagementDao.setAcademicTermDetails(academicTermDetail);
        }
    });
    this.execute(new CallableWithoutResult() {

        @Override
        protected void callWithoutResult() {
            final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
            assertEquals(2, academicTermDetail.size());
        }
    });
}
Also used : DateMidnight(org.joda.time.DateMidnight) AcademicTermDetail(org.apereo.portal.events.aggr.AcademicTermDetail) ArrayList(java.util.ArrayList) List(java.util.List) TransactionSystemException(org.springframework.transaction.TransactionSystemException) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Example 42 with DateMidnight

use of org.joda.time.DateMidnight in project OpenClinica by OpenClinica.

the class OpenClinicaBeanVariableNode method calculateVariable.

private Object calculateVariable() {
    if (number.equals("_CURRENT_DATE")) {
        String ssTimeZone = getExpressionBeanService().getSSTimeZone();
        if (ssTimeZone.equals("") || ssTimeZone == null)
            ssTimeZone = TimeZone.getDefault().getID();
        DateTimeZone ssZone = DateTimeZone.forID(ssTimeZone);
        DateMidnight dm = new DateMidnight(ssZone);
        DateTimeFormatter fmt = ISODateTimeFormat.date();
        return fmt.print(dm);
    }
    return null;
}
Also used : DateMidnight(org.joda.time.DateMidnight) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone)

Example 43 with DateMidnight

use of org.joda.time.DateMidnight in project OpenClinica by OpenClinica.

the class ArithmeticOpNode method calculateDaysBetween.

private String calculateDaysBetween(String value1, String value2) {
    DateMidnight dm1 = new DateMidnight(ExpressionTreeHelper.getDate(value1).getTime());
    DateMidnight dm2 = new DateMidnight(ExpressionTreeHelper.getDate(value2).getTime());
    switch(op) {
        case MINUS:
            {
                Days d = Days.daysBetween(dm1, dm2);
                int days = d.getDays();
                return String.valueOf(Math.abs(days));
            }
        default:
            // Bad operator!
            return null;
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight) Days(org.joda.time.Days)

Example 44 with DateMidnight

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

the class InterestPostingAccountingEntryTest method testBuildAccountEntryForAction.

@Test
public void testBuildAccountEntryForAction() throws FinancialException {
    // setup
    DateMidnight savingsTrxnDetailActionDate = new DateMidnight(2009, 9, 9);
    DateMidnight savingsTrxnDetailCreationDate = new DateMidnight(2009, 1, 1);
    MifosCurrency currency = TestUtils.RUPEE;
    // stubbing
    when(savingsTrxnDetail.getAccount()).thenReturn(savingsBO);
    when(savingsTrxnDetail.getInterestAmount()).thenReturn(new Money(currency, interestAmount));
    when(savingsTrxnDetail.getActionDate()).thenReturn(savingsTrxnDetailActionDate.toDate());
    when(savingsTrxnDetail.getTrxnCreatedDate()).thenReturn(new Timestamp(savingsTrxnDetailCreationDate.getMillis()));
    when(savingsTrxnDetail.getPersonnel()).thenReturn(transactionCreator);
    when(savingsBO.getSavingsOffering()).thenReturn(savingsOffering);
    when(savingsOffering.getInterestGLCode()).thenReturn(coaSavingsInterestPayable.getAssociatedGlcode());
    when(savingsOffering.getDepositGLCode()).thenReturn(coaClientsSavings.getAssociatedGlcode());
    SavingsInterestPostingFinancialActivity financialActivity = new SavingsInterestPostingFinancialActivity(savingsTrxnDetail);
    // exercise test
    interestPostingAccountingEntry.buildAccountEntryForAction(financialActivity);
    // verification
    List<FinancialTransactionBO> transactions = financialActivity.getFinanacialTransaction();
    assertThat(transactions.size(), is(2));
    /*
         * Sort by GLCode strings so "22100" (interest payable tran) should be first, followed by "22200" (client
         * savings tran)
         */
    Collections.sort(transactions, new GLCodeComparator());
    Iterator<FinancialTransactionBO> it = transactions.iterator();
    FinancialTransactionBO interestPostingTrans = it.next();
    assertThat(interestPostingTrans.getActionDate(), is(savingsTrxnDetailActionDate.toDate()));
    assertThat(interestPostingTrans.getPostedDate(), is(savingsTrxnDetailCreationDate.toDate()));
    assertThat(interestPostingTrans.getPostedAmount(), is(new Money(currency, interestAmount)));
    assertThat(interestPostingTrans.getGlcode().getGlcode(), is(coaSavingsInterestPayable.getGlCode()));
    assertThat(interestPostingTrans.getDebitCreditFlag(), is(FinancialConstants.DEBIT.getValue()));
    assertThat(interestPostingTrans.getPostedBy(), is(transactionCreator));
    FinancialTransactionBO savingsPostingTrans = it.next();
    assertThat(savingsPostingTrans.getActionDate(), is(savingsTrxnDetailActionDate.toDate()));
    assertThat(savingsPostingTrans.getPostedDate(), is(savingsTrxnDetailCreationDate.toDate()));
    assertThat(savingsPostingTrans.getPostedAmount(), is(new Money(currency, interestAmount)));
    assertThat(savingsPostingTrans.getGlcode().getGlcode(), is(coaClientsSavings.getGlCode()));
    assertThat(savingsPostingTrans.getDebitCreditFlag(), is(FinancialConstants.CREDIT.getValue()));
    assertThat(savingsPostingTrans.getPostedBy(), is(transactionCreator));
}
Also used : Money(org.mifos.framework.util.helpers.Money) FinancialTransactionBO(org.mifos.accounts.financial.business.FinancialTransactionBO) DateMidnight(org.joda.time.DateMidnight) SavingsInterestPostingFinancialActivity(org.mifos.accounts.financial.business.service.activity.SavingsInterestPostingFinancialActivity) Timestamp(java.sql.Timestamp) MifosCurrency(org.mifos.application.master.business.MifosCurrency) Test(org.junit.Test)

Example 45 with DateMidnight

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

the class AccountGetFeeDatesIntegrationTest method getScheduledDatesForFeesForGivenCustomerForWeeklySchedules.

@Test
public void getScheduledDatesForFeesForGivenCustomerForWeeklySchedules() throws Exception {
    // setup
    DateTime firstTuesdayInstallmentDate = new DateMidnight().toDateTime().withDate(2010, 4, 20);
    weeklyMeeting = new MeetingBuilder().customerMeeting().weekly().every(1).withStartDate(firstTuesdayInstallmentDate).build();
    IntegrationTestObjectMother.saveMeeting(weeklyMeeting);
    MeetingBuilder weeklyMeetingForFees = new MeetingBuilder().periodicFeeMeeting().weekly().every(1).withStartDate(firstTuesdayInstallmentDate);
    weeklyPeriodicFeeForCenterOnly = new FeeBuilder().appliesToCenterOnly().withFeeAmount("100.0").withName("Center Weekly Periodic Fee").with(weeklyMeetingForFees).with(sampleBranchOffice()).build();
    IntegrationTestObjectMother.saveFee(weeklyPeriodicFeeForCenterOnly);
    center = new CenterBuilder().with(weeklyMeeting).withName("Center").with(sampleBranchOffice()).withLoanOfficer(testUser()).build();
    IntegrationTestObjectMother.createCenter(center, weeklyMeeting, weeklyPeriodicFeeForCenterOnly);
    center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
    DateTime meetingStartDate = firstTuesdayInstallmentDate.minusDays(7);
    MeetingBO feeMeetingFrequency = new MeetingBuilder().periodicFeeMeeting().weekly().every(1).occuringOnA(WeekDay.MONDAY).startingFrom(meetingStartDate.toDate()).build();
    InstallmentDate installment1 = new InstallmentDate(Short.valueOf("1"), firstTuesdayInstallmentDate.toDate());
    InstallmentDate installment2 = new InstallmentDate(Short.valueOf("2"), firstTuesdayInstallmentDate.plusWeeks(1).toDate());
    InstallmentDate installment3 = new InstallmentDate(Short.valueOf("3"), firstTuesdayInstallmentDate.plusWeeks(2).toDate());
    InstallmentDate installment4 = new InstallmentDate(Short.valueOf("4"), firstTuesdayInstallmentDate.plusWeeks(3).toDate());
    List<InstallmentDate> installmentDates = Arrays.asList(installment1, installment2, installment3, installment4);
    // exercise test
    CustomerAccountBO customerAccount = center.getCustomerAccount();
    List<Date> feeDates = customerAccount.getFeeDates(feeMeetingFrequency, installmentDates);
    // verification
    assertThat(feeDates.get(0), is(firstTuesdayInstallmentDate.toDate()));
    assertThat(feeDates.get(1), is(firstTuesdayInstallmentDate.plusWeeks(1).toDate()));
    assertThat(feeDates.get(2), is(firstTuesdayInstallmentDate.plusWeeks(2).toDate()));
    assertThat(feeDates.get(3), is(firstTuesdayInstallmentDate.plusWeeks(3).toDate()));
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) FeeBuilder(org.mifos.domain.builders.FeeBuilder) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) MeetingBuilder(org.mifos.domain.builders.MeetingBuilder) DateTime(org.joda.time.DateTime) Date(java.util.Date) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) InstallmentDate(org.mifos.accounts.util.helpers.InstallmentDate) 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