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;
}
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);
}
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));
}
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;
}
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;
}
Aggregations