Search in sources :

Example 11 with Shift

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

the class ShiftsServiceImpl method getDateTimeRanges.

@Override
public List<DateTimeRange> getDateTimeRanges(final List<Shift> shifts, final Date dateFrom, final Date dateTo) {
    List<DateTimeRange> ranges = Lists.newArrayList();
    DateTime dateOfDay = new DateTime(dateFrom);
    int loopCount = 0;
    while (!dateOfDay.isAfter(new DateTime(dateTo))) {
        if (loopCount > MAX_LOOPS) {
            return ranges;
        }
        for (Shift shift : shifts) {
            ranges.addAll(shiftExceptionService.getShiftWorkDateTimes(null, shift, dateOfDay, true));
        }
        loopCount++;
        dateOfDay = dateOfDay.plusDays(1);
    }
    return ranges;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) DateTime(org.joda.time.DateTime)

Example 12 with Shift

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

the class ShiftsServiceImpl method getNearestWorkingDate.

@Override
public Optional<DateTime> getNearestWorkingDate(DateTime dateFrom, Entity productionLine) {
    List<Shift> shifts = findAll(productionLine);
    List<DateTimeRange> finalShiftWorkTimes = Lists.newArrayList();
    DateTime currentDate = dateFrom.minusDays(1);
    if (shifts.stream().noneMatch(shift -> checkShiftWorkingAfterDate(dateFrom, productionLine, shift))) {
        return Optional.empty();
    }
    while (finalShiftWorkTimes.isEmpty()) {
        for (Shift shift : shifts) {
            getNearestWorkingDateForShift(shift, productionLine, dateFrom, currentDate, finalShiftWorkTimes);
        }
        currentDate = currentDate.plusDays(1);
    }
    DateTime result = finalShiftWorkTimes.stream().min(Comparator.comparing(DateTimeRange::getFrom)).get().getFrom();
    if (result.compareTo(dateFrom) <= 0) {
        return Optional.of(dateFrom);
    }
    return Optional.of(result);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) DateTime(org.joda.time.DateTime)

Example 13 with Shift

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

the class AssignmentToShiftHooks method resolveNextStartDate.

private Optional<LocalDate> resolveNextStartDate(final Entity assignmentToShift) {
    LocalDate startDate = LocalDate.fromDateFields(assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE));
    Shift shift = shiftsFactory.buildFrom(assignmentToShift.getBelongsToField(AssignmentToShiftFields.SHIFT));
    Entity factory = assignmentToShift.getBelongsToField(AssignmentToShiftFields.FACTORY);
    Entity crew = assignmentToShift.getBelongsToField(AssignmentToShiftFields.CREW);
    Set<LocalDate> occupiedDates = findNextStartDatesMatching(assignmentToShift.getDataDefinition(), startDate, shift, factory, crew);
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    int daysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
    Iterable<Integer> daysRange = ContiguousSet.create(Range.closed(1, daysInYear), DiscreteDomain.integers());
    return FluentIterable.from(daysRange).transform(startDate::plusDays).firstMatch((final LocalDate localDate) -> !occupiedDates.contains(localDate) && shift.worksAt(localDate));
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) LocalDate(org.joda.time.LocalDate) LocalDate(org.joda.time.LocalDate)

Example 14 with Shift

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

the class AverageCostService method generateMapWorkersWithHoursWorked.

private Map<Entity, BigDecimal> generateMapWorkersWithHoursWorked(final Entity entity) {
    Map<Entity, BigDecimal> workersWithHours = new HashMap<>();
    List<Shift> shifts = shiftsService.findAll();
    List<DateTime> days = shiftsService.getDaysBetweenGivenDates(new DateTime(entity.getDateField(AvgLaborCostCalcForOrderFields.START_DATE)), new DateTime(entity.getDateField(AvgLaborCostCalcForOrderFields.FINISH_DATE)));
    for (DateTime day : days) {
        for (Shift shift : shifts) {
            Entity assignmentToShift = getAssignmentToShift(shift, day);
            if (assignmentToShift == null) {
                continue;
            }
            List<Entity> staffs = getStaffAssignmentToShiftDependOnAssignmentToShiftState(assignmentToShift, entity.getBelongsToField(AvgLaborCostCalcForOrderFields.PRODUCTION_LINE));
            for (Entity staff : staffs) {
                if (workersWithHours.containsKey(staff)) {
                    BigDecimal countHours = workersWithHours.get(staff).add(shiftsService.getWorkedHoursOfWorker(shift, day));
                    workersWithHours.put(staff, countHours);
                } else {
                    workersWithHours.put(staff, shiftsService.getWorkedHoursOfWorker(shift, day));
                }
            }
        }
    }
    return workersWithHours;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime)

Example 15 with Shift

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

the class ShiftExceptionService method manageExceptions.

public List<DateTimeRange> manageExceptions(List<DateTimeRange> shiftWorkDateTime, final Entity productionLine, final Shift shift, final Date dateOfDay, final boolean removeFreeTimeException) {
    List<Entity> exceptions;
    Entity shiftEntity = shift.getEntity();
    if (Objects.isNull(productionLine)) {
        exceptions = shiftEntity.getHasManyField(ShiftFields.TIMETABLE_EXCEPTIONS);
    } else {
        exceptions = timetableExceptionService.findFor(productionLine, shiftEntity, dateOfDay);
    }
    Shift shiftForDay = new Shift(shiftEntity, new DateTime(dateOfDay), false);
    for (Entity exception : exceptions) {
        if (removeFreeTimeException && TimetableExceptionType.FREE_TIME.getStringValue().equals(exception.getStringField(ShiftTimetableExceptionFields.TYPE))) {
            shiftWorkDateTime = removeFreeTimeException(shiftWorkDateTime, exception, shiftForDay);
        }
        if (TimetableExceptionType.WORK_TIME.getStringValue().equals(exception.getStringField(ShiftTimetableExceptionFields.TYPE))) {
            shiftWorkDateTime = addWorkTimeException(shiftWorkDateTime, exception, shiftForDay);
        }
    }
    return shiftWorkDateTime;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) DateTime(org.joda.time.DateTime)

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