use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class PPSReportXlsHelper method getDateToInMills.
private long getDateToInMills(final Entity goodFoodReport, final List<Entity> shifts) {
DateTime dateTo = new DateTime(goodFoodReport.getDateField(PPSReportFields.DATE_TO));
Shift shiftEnd = new Shift(shifts.get(shifts.size() - 1), dateTo, false);
List<TimeRange> rangesEnd = shiftEnd.findWorkTimeAt(dateTo.toLocalDate());
LocalTime endTime = rangesEnd.get(0).getTo();
dateTo = dateTo.plusDays(ONE);
dateTo = dateTo.withHourOfDay(endTime.getHourOfDay());
dateTo = dateTo.withMinuteOfHour(endTime.getMinuteOfHour());
Entity shiftEntity = shiftsService.getShiftFromDateWithTime(dateTo.toDate());
if (Objects.nonNull(shiftEntity)) {
Optional<DateTime> mayBeShiftEndDate = getShiftEndDate(new DateTime(dateTo), shiftEntity);
if (mayBeShiftEndDate.isPresent()) {
dateTo = mayBeShiftEndDate.get();
}
}
return dateTo.getMillis();
}
use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class PPSReportXlsService method addSeriesOfProductionLine.
private void addSeriesOfProductionLine(final HSSFSheet sheet, final Entity report, final PPSReportXlsStyleContainer styleContainer, final List<ReportColumn> columns) {
List<Entity> productionPerShifts = ppsReportXlsHelper.getProductionPerShiftForReport(report);
List<Entity> shifts = shiftsService.getShifts();
DateTime dateFrom = new DateTime(report.getDateField(PPSReportFields.DATE_FROM));
Shift shiftFirst = new Shift(shifts.get(0), dateFrom, false);
List<TimeRange> ranges = shiftFirst.findWorkTimeAt(new LocalDate(report.getDateField(PPSReportFields.DATE_FROM)));
if (ranges.isEmpty()) {
return;
}
LocalTime startTime = ranges.get(0).getFrom();
if (productionPerShifts.isEmpty()) {
return;
}
productionPerShifts.sort(new EntityProductionPerShiftsComparator());
String oldProductionLineNumber = "";
String newProductionLineNumber;
int rowNum = 6;
boolean isFirstRow;
boolean greyBg = false;
for (Entity productionPerShift : productionPerShifts) {
Entity order = ppsReportXlsHelper.getOrder(productionPerShift);
Entity changeover = ppsReportXlsHelper.getChangeover(order);
Entity productionLine = ppsReportXlsHelper.getProductionLine(productionPerShift);
newProductionLineNumber = productionLine.getStringField(ProductionLineFields.NUMBER);
isFirstRow = !oldProductionLineNumber.equals(newProductionLineNumber);
if (isFirstRow) {
greyBg = !greyBg;
}
if (changeover != null && isChangeOverOnThisPrint(order, report, startTime)) {
HSSFRow row = sheet.createRow(rowNum++);
int colIndex = 0;
for (ReportColumn column : columns) {
HSSFCell cell = row.createCell(colIndex);
if (isFirstRow) {
cell.setCellValue(column.getFirstRowChangeoverValue(productionPerShift));
} else {
cell.setCellValue(column.getChangeoverValue(productionPerShift));
}
colIndex++;
}
isFirstRow = false;
addSeriesForChangeOver(sheet, report, row, changeover, order, styleContainer, columns);
}
HSSFRow row = sheet.createRow(rowNum++);
int colIndex = 0;
for (ReportColumn column : columns) {
HSSFCell cell = row.createCell(colIndex);
if (isFirstRow) {
Object firstRowValue = column.getFirstRowValue(productionPerShift);
if (firstRowValue instanceof Double) {
cell.setCellValue((Double) firstRowValue);
cell.setCellType(CellType.NUMERIC);
} else {
cell.setCellValue((String) firstRowValue);
}
} else {
Object value = column.getValue(productionPerShift);
if (value instanceof Double) {
cell.setCellValue((Double) value);
cell.setCellType(CellType.NUMERIC);
} else {
cell.setCellValue((String) value);
}
}
if (greyBg) {
if (columns.size() == colIndex - 1) {
column.setGreyDataStyleEnd(cell, styleContainer);
} else {
column.setGreyDataStyle(cell, styleContainer);
}
} else {
if (columns.size() == colIndex - 1) {
column.setWhiteDataStyleEnd(cell, styleContainer);
} else {
column.setWhiteDataStyle(cell, styleContainer);
}
}
colIndex++;
}
addSeriesOfDailyProgress(sheet, report, row, productionPerShift, greyBg, styleContainer, columns);
oldProductionLineNumber = newProductionLineNumber;
}
setColumnWidths(sheet, columns);
}
use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class PPSReportXlsService method addSeriesForChangeOver.
private void addSeriesForChangeOver(final HSSFSheet sheet, final Entity entity, final HSSFRow row, final Entity changeover, final Entity order, final PPSReportXlsStyleContainer styleContainer, final List<ReportColumn> columns) {
Map<Integer, DayShiftHolder> mapCells = Maps.newHashMap();
List<Entity> shifts = shiftsService.getShifts();
DateTime dateFrom = new DateTime(entity.getDateField(PPSReportFields.DATE_FROM));
DateTime dateTo = new DateTime(entity.getDateField(PPSReportFields.DATE_TO));
List<DateTime> days = shiftsService.getDaysBetweenGivenDates(dateFrom, dateTo);
Date startDateOrder = order.getDateField(OrderFields.START_DATE);
Shift shiftFirst = new Shift(shifts.get(0));
List<TimeRange> ranges = shiftFirst.findWorkTimeAt(days.get(0).toLocalDate());
if (ranges.isEmpty()) {
return;
}
LocalTime startTime = ranges.get(0).getFrom();
DateTime firstStartShitTime = days.get(0);
firstStartShitTime = firstStartShitTime.withHourOfDay(startTime.getHourOfDay());
firstStartShitTime = firstStartShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
int columnNumber = columns.size();
if (new DateTime(startDateOrder).minusSeconds(1).toDate().before(firstStartShitTime.toDate())) {
for (DateTime day : days) {
for (Entity shift : shifts) {
HSSFCell cellDailyProgress = row.createCell(columnNumber);
cellDailyProgress.setCellValue("");
cellDailyProgress.setCellStyle(styleContainer.getStyles().get(PPSReportXlsStyleContainer.I_ChangeoverDataStyle));
columnNumber++;
sheet.autoSizeColumn((short) columnNumber);
}
}
} else {
for (DateTime day : days) {
for (Entity shift : shifts) {
HSSFCell cell = row.createCell(columnNumber);
cell.setCellValue("");
DayShiftHolder holder = new DayShiftHolder(shift, day, cell);
cell.setCellStyle(styleContainer.getStyles().get(PPSReportXlsStyleContainer.I_ChangeoverDataStyle));
mapCells.put(columnNumber, holder);
columnNumber++;
sheet.autoSizeColumn((short) columnNumber);
}
}
columnNumber = columns.size();
for (DateTime day : days) {
for (Entity shift : shifts) {
Optional<DateTime> maybeShiftStart = getShiftStartDate(day, shift);
Optional<DateTime> maybeShiftEnd = getShiftEndDate(day, shift);
HSSFCell cell = mapCells.get(columnNumber).getCell();
if (!maybeShiftStart.isPresent() || !maybeShiftEnd.isPresent()) {
cell.setCellValue("");
columnNumber++;
continue;
}
DateTime shiftEnd = maybeShiftEnd.get();
DateTime shiftStart = maybeShiftStart.get();
if (shiftStart.toDate().after(shiftEnd.toDate())) {
shiftEnd = shiftEnd.plusDays(1);
}
boolean isChangeover = betweenDates(shiftStart.toDate(), shiftEnd.toDate(), new DateTime(startDateOrder).plusSeconds(1).toDate());
if (isChangeover) {
int duration = changeover.getIntegerField(LineChangeoverNormsFields.DURATION);
int changeoverOnShift = Seconds.secondsBetween(shiftStart, new DateTime(startDateOrder)).getSeconds();
if (duration - changeoverOnShift > 0) {
if (changeoverOnShift > 0) {
cell.setCellValue(DurationFormatUtils.formatDuration(changeoverOnShift * 1000, "HH:mm"));
}
int durationToMark = duration - changeoverOnShift;
int currentIndex = columnNumber - 1;
if (currentIndex >= columns.size()) {
while (durationToMark > 0) {
HSSFCell cellBefore = mapCells.get(currentIndex).getCell();
Optional<DateTime> maybeStart = getShiftStartDate(day, shift);
Optional<DateTime> maybeEnd = getShiftEndDate(day, shift);
if (!maybeStart.isPresent() || !maybeEnd.isPresent()) {
cell.setCellValue("");
continue;
}
DateTime start = maybeStart.get();
DateTime end = maybeEnd.get();
if (start.toDate().after(end.toDate())) {
end = end.plusDays(1);
}
int seconds = Seconds.secondsBetween(start, end).getSeconds();
if (durationToMark > seconds) {
cellBefore.setCellValue(DurationFormatUtils.formatDuration(seconds * 1000, "HH:mm"));
durationToMark = durationToMark - seconds;
currentIndex = currentIndex - 1;
if (currentIndex < columns.size()) {
break;
}
} else {
cellBefore.setCellValue(DurationFormatUtils.formatDuration(durationToMark * 1000, "HH:mm"));
durationToMark = durationToMark - seconds;
}
}
}
} else {
cell.setCellValue(DurationFormatUtils.formatDuration(duration * 1000, "HH:mm"));
}
}
columnNumber++;
}
}
}
for (int i = 0; i < columnNumber; i++) {
row.getCell(i).setCellStyle(styleContainer.getStyles().get(PPSReportXlsStyleContainer.I_ChangeoverDataStyle));
}
}
use of com.qcadoo.commons.dateTime.TimeRange in project mes by qcadoo.
the class OrderRealizationDaysResolver method tryResolveFirstDay.
private Optional<OrderRealizationDay> tryResolveFirstDay(final OrderRealizationDay firstWorkingDay, final DateTime orderStartDateTime) {
LocalDate orderStartDate = orderStartDateTime.toLocalDate();
LocalTime orderStartTime = orderStartDateTime.toLocalTime();
Optional<Shift> shiftStartingOrder = firstWorkingDay.findShiftWorkingAt(orderStartTime);
Optional<TimeRange> workTimeRange = FluentOptional.wrap(shiftStartingOrder).flatMap(shift -> {
int prevDayOfWeek = firstWorkingDay.getDate().minusDays(1).getDayOfWeek();
return shift.findWorkTimeAt(prevDayOfWeek, orderStartTime);
}).toOpt();
if (shiftWorkTimeMatchPredicate(shiftStartingOrder, workTimeRange, startsDayBefore(orderStartTime))) {
return Optional.of(new OrderRealizationDay(orderStartDate, firstWorkingDay.getRealizationDayNumber() - 1, Lists.newArrayList(shiftStartingOrder.asSet())));
}
if (shiftWorkTimeMatchPredicate(shiftStartingOrder, workTimeRange, endsNextDay(orderStartTime))) {
return Optional.of(new OrderRealizationDay(firstWorkingDay.getDate(), firstWorkingDay.getRealizationDayNumber(), Lists.newArrayList(shiftStartingOrder.asSet())));
}
return Optional.absent();
}
use of com.qcadoo.commons.dateTime.TimeRange 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;
}
Aggregations