Search in sources :

Example 31 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class PPSReportXlsService method getShiftStartDate.

private Optional<DateTime> getShiftStartDate(final DateTime day, final Entity shift) {
    Shift shiftFirst = new Shift(shift);
    List<TimeRange> ranges = shiftFirst.findWorkTimeAt(day.toLocalDate());
    if (ranges.isEmpty()) {
        return Optional.empty();
    }
    LocalTime startTime = ranges.get(0).getFrom();
    DateTime startShitTime = day;
    startShitTime = startShitTime.withHourOfDay(startTime.getHourOfDay());
    startShitTime = startShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
    return Optional.of(startShitTime);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) TimeRange(com.qcadoo.commons.dateTime.TimeRange) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime)

Example 32 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class PPSReportXlsService method getShiftEndDate.

private Optional<DateTime> getShiftEndDate(final DateTime day, final Entity shift) {
    Shift shiftFirst = new Shift(shift);
    List<TimeRange> ranges = shiftFirst.findWorkTimeAt(day.toLocalDate());
    if (ranges.isEmpty()) {
        return Optional.empty();
    }
    LocalTime startTime = ranges.get(0).getTo();
    DateTime startShitTime = day;
    startShitTime = startShitTime.withHourOfDay(startTime.getHourOfDay());
    startShitTime = startShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
    return Optional.of(startShitTime);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) TimeRange(com.qcadoo.commons.dateTime.TimeRange) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime)

Example 33 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class PpsTimeHelper method findFinishDate.

public Date findFinishDate(final Entity dailyProgress, final Date dateOfDay, final Entity order) {
    DateTime endDate = null;
    DateTime dateOfDayDT = new DateTime(dateOfDay, DateTimeZone.getDefault());
    DateTime orderStartDate = new DateTime(order.getDateField(OrderFields.START_DATE), DateTimeZone.getDefault());
    Entity shiftEntity = dailyProgress.getBelongsToField(DailyProgressFields.SHIFT);
    Shift shift = new Shift(shiftEntity);
    int time = dailyProgress.getIntegerField(DailyProgressFields.EFFICIENCY_TIME);
    List<TimeRange> shiftWorkTime = Lists.newArrayList();
    List<DateTimeRange> shiftWorkDateTime = Lists.newArrayList();
    if (shift.worksAt(dateOfDay.getDay() == 0 ? 7 : dateOfDay.getDay())) {
        shiftWorkTime = shift.findWorkTimeAt(new LocalDate(dateOfDay));
    }
    for (TimeRange range : shiftWorkTime) {
        DateTimeRange dateTimeRange = new DateTimeRange(dateOfDayDT, range);
        DateTimeRange trimmedRange = dateTimeRange.trimBefore(orderStartDate);
        if (trimmedRange != null) {
            shiftWorkDateTime.add(trimmedRange);
        }
    }
    shiftWorkDateTime = shiftExceptionService.manageExceptions(shiftWorkDateTime, order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay, true);
    for (DateTimeRange range : shiftWorkDateTime) {
        if (range.durationInMins() >= time && time > 0) {
            endDate = range.getFrom().plusMinutes(time);
            time = 0;
        } else {
            endDate = range.getTo();
            time -= range.durationInMins();
        }
    }
    return endDate != null ? endDate.toDate() : null;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) TimeRange(com.qcadoo.commons.dateTime.TimeRange) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 34 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class ShiftMockingAwareTest method mockShift.

protected Shift mockShift(final TimeRange workingTime, final Set<Integer> workingWeekDays) {
    Shift shift = mock(Shift.class);
    stubWorkingWeekDays(shift, workingWeekDays);
    stubWorkingHours(shift, workingTime, workingWeekDays);
    return shift;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift)

Example 35 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class ProductionLinesApiController method getShiftWorkingDate.

@ResponseBody
@RequestMapping(value = "/productionLine/{productionLineId}/shiftWorkingDate", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ShiftWorkingDateResponse getShiftWorkingDate(@PathVariable Long productionLineId, @RequestParam("date") Date date) {
    Entity productionLineEntity = dataDefinitionService.get(ProductionLinesConstants.PLUGIN_IDENTIFIER, ProductionLinesConstants.MODEL_PRODUCTION_LINE).get(productionLineId);
    Optional<Shift> maybeShift = shiftsService.getShiftForNearestWorkingDate(new DateTime(date), productionLineEntity);
    return maybeShift.map(shift -> new ShiftWorkingDateResponse(shift.getShiftStartDate().toDate(), shift.getShiftEndDate().toDate())).orElseGet(() -> new ShiftWorkingDateResponse(ShiftWorkingDateResponse.StatusCode.ERROR));
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) PathVariable(org.springframework.web.bind.annotation.PathVariable) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) RequestParam(org.springframework.web.bind.annotation.RequestParam) ShiftsService(com.qcadoo.mes.basic.ShiftsService) Date(java.util.Date) ProductionLineFields(com.qcadoo.mes.productionLines.constants.ProductionLineFields) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ProductionLinesConstants(com.qcadoo.mes.productionLines.constants.ProductionLinesConstants) Controller(org.springframework.stereotype.Controller) Shift(com.qcadoo.mes.basic.shift.Shift) RequestBody(org.springframework.web.bind.annotation.RequestBody) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ShiftWorkingDateResponse(com.qcadoo.mes.productionLines.controller.dataProvider.ShiftWorkingDateResponse) ProductionLineDto(com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLineDto) ProductionLinesDataProvider(com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLinesDataProvider) ProductionLineResponse(com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLineResponse) MediaType(org.springframework.http.MediaType) DateTime(org.joda.time.DateTime) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TranslationService(com.qcadoo.localization.api.TranslationService) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Objects(java.util.Objects) Entity(com.qcadoo.model.api.Entity) ProductionLinesResponse(com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLinesResponse) Optional(java.util.Optional) ProductionLineRequest(com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLineRequest) ProductionLinesGridResponse(com.qcadoo.mes.productionLines.controller.dataProvider.ProductionLinesGridResponse) Entity(com.qcadoo.model.api.Entity) ShiftWorkingDateResponse(com.qcadoo.mes.productionLines.controller.dataProvider.ShiftWorkingDateResponse) DateTime(org.joda.time.DateTime) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Shift (com.qcadoo.mes.basic.shift.Shift)37 DateTime (org.joda.time.DateTime)30 Entity (com.qcadoo.model.api.Entity)12 Test (org.junit.Test)11 TimeRange (com.qcadoo.commons.dateTime.TimeRange)9 DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)8 Date (java.util.Date)7 LocalTime (org.joda.time.LocalTime)7 LocalDate (org.joda.time.LocalDate)6 BigDecimal (java.math.BigDecimal)3 DailyProgressContainer (com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 Calendar (java.util.Calendar)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 Predicate (com.google.common.base.Predicate)1 FluentIterable (com.google.common.collect.FluentIterable)1 Lists (com.google.common.collect.Lists)1 DateRange (com.qcadoo.commons.dateTime.DateRange)1