use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.
the class ShiftExceptionService method getShiftWorkDateTimes.
public List<DateTimeRange> getShiftWorkDateTimes(final Entity productionLine, final Shift shift, DateTime dateOfDay, final boolean removeFreeTimeException) {
List<TimeRange> shiftWorkTime = Lists.newArrayList();
List<DateTimeRange> shiftWorkDateTime = Lists.newArrayList();
if (shift.worksAt(dateOfDay.dayOfWeek().get())) {
shiftWorkTime = shift.findWorkTimeAt(dateOfDay.toLocalDate());
}
for (TimeRange range : shiftWorkTime) {
shiftWorkDateTime.add(new DateTimeRange(dateOfDay, range));
}
shiftWorkDateTime = manageExceptions(shiftWorkDateTime, productionLine, shift, dateOfDay.toDate(), removeFreeTimeException);
return shiftWorkDateTime;
}
use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.
the class ShiftsServiceImpl method getNearestWorkingDateForShiftWorkTime.
private void getNearestWorkingDateForShiftWorkTime(final TimeRange shiftWorkTime, final DateTime dateFrom, final DateTime currentDate, final List<DateTimeRange> workTimes) {
LocalTime currentTime = currentDate.toLocalTime();
LocalTime timeTo = shiftWorkTime.getTo();
LocalTime timeFrom = shiftWorkTime.getFrom();
if (!currentDate.equals(dateFrom.minusDays(1)) || timeFrom.isAfter(timeTo)) {
if (timeFrom.isAfter(timeTo) && currentDate.equals(dateFrom.minusDays(1))) {
if (currentTime.compareTo(LocalTime.MIDNIGHT) >= 0 && currentTime.compareTo(timeTo) <= 0) {
Optional<Interval> interval = createInterval(currentDate.plusDays(1), currentTime, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
}
} else {
if (currentDate.equals(dateFrom)) {
if (timeFrom.compareTo(currentTime) < 0 && timeTo.compareTo(currentTime) > 0) {
Optional<Interval> interval = createInterval(currentDate, currentTime, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
} else if (timeFrom.isAfter(timeTo)) {
if (timeFrom.compareTo(currentTime) < 0) {
Optional<Interval> interval = createInterval(currentDate, currentTime, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
} else {
Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
}
} else if (timeFrom.compareTo(currentTime) >= 0) {
Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
}
} else {
Optional<Interval> interval = createInterval(currentDate, timeFrom, timeTo);
interval.ifPresent(i -> workTimes.add(new DateTimeRange(i)));
}
}
}
}
use of com.qcadoo.mes.basic.util.DateTimeRange in project mes by qcadoo.
the class ShiftsServiceImpl method getWorkedHoursOfWorker.
@Override
public BigDecimal getWorkedHoursOfWorker(final Shift shift, final DateTime dateOfDay) {
BigDecimal hours = BigDecimal.ZERO;
List<DateTimeRange> dateTimeRanges = getDateTimeRanges(Collections.singletonList(shift), dateOfDay.toDate(), dateOfDay.plusDays(1).toDate());
for (DateTimeRange dateTimeRange : dateTimeRanges) {
Period p = new Period(dateTimeRange.getFrom(), dateTimeRange.getTo());
hours = hours.add(new BigDecimal(p.getHours()));
}
return hours;
}
use of com.qcadoo.mes.basic.util.DateTimeRange 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.util.DateTimeRange 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);
}
Aggregations