Search in sources :

Example 1 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class PPSReportXlsHelper method getShiftEndDate.

private Optional<DateTime> getShiftEndDate(final DateTime day, final Entity shiftEntity) {
    Shift shift = new Shift(shiftEntity);
    com.google.common.base.Optional<DateRange> mayBeWorkTimeAt = shift.findWorkTimeAt(day.toDate());
    if (mayBeWorkTimeAt.isPresent()) {
        DateRange range = mayBeWorkTimeAt.get();
        return Optional.of(new DateTime(range.getTo()));
    }
    return Optional.empty();
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) DateRange(com.qcadoo.commons.dateTime.DateRange) DateTime(org.joda.time.DateTime)

Example 2 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class OrderHooks method checkOrderDates.

public boolean checkOrderDates(final DataDefinition orderDD, final Entity order) {
    DateRange orderDateRange = orderDatesService.getCalculatedDates(order);
    Date dateFrom = orderDateRange.getFrom();
    Date dateTo = orderDateRange.getTo();
    if (Objects.isNull(dateFrom) || Objects.isNull(dateTo) || dateTo.after(dateFrom)) {
        return true;
    }
    order.addError(orderDD.getField(OrderFields.FINISH_DATE), "orders.validate.global.error.datesOrder");
    return false;
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date)

Example 3 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class OrderDatesServiceTest method shouldReturnDateRangeWithEffectiveStartDate.

@Test
public final void shouldReturnDateRangeWithEffectiveStartDate() {
    // given
    Date plannedStartDate = new DateTime(2013, 1, 1, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.DATE_FROM, plannedStartDate);
    Date correctedStartDate = new DateTime(2013, 1, 5, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.CORRECTED_DATE_FROM, correctedStartDate);
    Date effectiveStartDate = new DateTime(2013, 2, 8, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.EFFECTIVE_DATE_FROM, effectiveStartDate);
    // when
    DateRange dateRange = orderDatesService.getCalculatedDates(order);
    // then
    assertEquals(effectiveStartDate, dateRange.getFrom());
    assertNull(dateRange.getTo());
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 4 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class OrderDatesServiceTest method shouldReturnDateRangeWithCorrectedStartAndCorrectedEndDate.

@Test
public final void shouldReturnDateRangeWithCorrectedStartAndCorrectedEndDate() {
    // given
    Date plannedStartDate = new DateTime(2012, 12, 30, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.DATE_FROM, plannedStartDate);
    Date plannedEndDate = new DateTime(2013, 1, 1, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.DATE_TO, plannedEndDate);
    Date correctedStartDate = new DateTime(2013, 1, 3, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.CORRECTED_DATE_FROM, correctedStartDate);
    Date correctedEndDate = new DateTime(2013, 1, 5, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.CORRECTED_DATE_TO, correctedEndDate);
    // when
    DateRange dateRange = orderDatesService.getCalculatedDates(order);
    // then
    assertEquals(correctedStartDate, dateRange.getFrom());
    assertEquals(correctedEndDate, dateRange.getTo());
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with DateRange

use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.

the class OrderDatesServiceTest method shouldReturnDateRangeWithEffectiveStartDate2.

@Test
public final void shouldReturnDateRangeWithEffectiveStartDate2() {
    // given
    Date correctedStartDate = new DateTime(2013, 1, 5, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.CORRECTED_DATE_FROM, correctedStartDate);
    Date effectiveStartDate = new DateTime(2013, 2, 8, 0, 0, 0, 0).toDate();
    stubDateField(order, OrderFields.EFFECTIVE_DATE_FROM, effectiveStartDate);
    // when
    DateRange dateRange = orderDatesService.getCalculatedDates(order);
    // then
    assertEquals(effectiveStartDate, dateRange.getFrom());
    assertNull(dateRange.getTo());
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateRange (com.qcadoo.commons.dateTime.DateRange)29 Test (org.junit.Test)25 Date (java.util.Date)24 DateTime (org.joda.time.DateTime)20 Entity (com.qcadoo.model.api.Entity)2 Shift (com.qcadoo.mes.basic.shift.Shift)1 EntityList (com.qcadoo.model.api.EntityList)1 LocalTime (org.joda.time.LocalTime)1