Search in sources :

Example 1 with TimeRange

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();
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) TimeRange(com.qcadoo.commons.dateTime.TimeRange) Entity(com.qcadoo.model.api.Entity) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime)

Example 2 with TimeRange

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);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) ReportColumn(com.qcadoo.mes.productionPerShift.report.columns.ReportColumn) EntityProductionPerShiftsComparator(com.qcadoo.mes.productionPerShift.report.print.utils.EntityProductionPerShiftsComparator) LocalTime(org.joda.time.LocalTime) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) TimeRange(com.qcadoo.commons.dateTime.TimeRange) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell)

Example 3 with TimeRange

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));
    }
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) TimeRange(com.qcadoo.commons.dateTime.TimeRange) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) DayShiftHolder(com.qcadoo.mes.productionPerShift.report.print.utils.DayShiftHolder)

Example 4 with TimeRange

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();
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Function(com.google.common.base.Function) Date(java.util.Date) LazyStream(com.qcadoo.commons.functional.LazyStream) DateTime(org.joda.time.DateTime) LocalTime(org.joda.time.LocalTime) FluentOptional(com.qcadoo.commons.functional.FluentOptional) Shift(com.qcadoo.mes.basic.shift.Shift) LocalDate(org.joda.time.LocalDate) List(java.util.List) Calendar(java.util.Calendar) Lists(com.google.common.collect.Lists) FluentIterable(com.google.common.collect.FluentIterable) Service(org.springframework.stereotype.Service) Optional(com.google.common.base.Optional) TimeRange(com.qcadoo.commons.dateTime.TimeRange) Collections(java.util.Collections) TimeRange(com.qcadoo.commons.dateTime.TimeRange) LocalTime(org.joda.time.LocalTime) LocalDate(org.joda.time.LocalDate)

Example 5 with TimeRange

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;
}
Also used : DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) TimeRange(com.qcadoo.commons.dateTime.TimeRange) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange)

Aggregations

TimeRange (com.qcadoo.commons.dateTime.TimeRange)19 DateTime (org.joda.time.DateTime)12 LocalTime (org.joda.time.LocalTime)12 Shift (com.qcadoo.mes.basic.shift.Shift)10 Entity (com.qcadoo.model.api.Entity)6 LocalDate (org.joda.time.LocalDate)5 DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)4 Date (java.util.Date)4 Test (org.junit.Test)4 Lists (com.google.common.collect.Lists)2 Calendar (java.util.Calendar)2 Collections (java.util.Collections)2 List (java.util.List)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 Service (org.springframework.stereotype.Service)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 FluentIterable (com.google.common.collect.FluentIterable)1 Maps (com.google.common.collect.Maps)1 FluentOptional (com.qcadoo.commons.functional.FluentOptional)1