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