Search in sources :

Example 6 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class OrderRealizationDaysResolverTest method shouldResolveRealizationDay6.

@Test
public final void shouldResolveRealizationDay6() {
    // given
    DateTime startDate = new DateTime(2014, 8, 14, 3, 0, 0);
    List<Shift> shifts = ImmutableList.of(shift1, shift2, shift3);
    // when
    // - 3rd order realization day is Saturday,
    // - it's a first day of order realization,
    // - shift starting order starts day before,
    // - 'day before' mentioned above is spare day
    OrderRealizationDay realizationDay = orderRealizationDaysResolver.find(startDate, 3, true, shifts);
    // then
    assertRealizationDayState(realizationDay, 5, startDate.toLocalDate().plusDays(4), shifts);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 7 with Shift

use of com.qcadoo.mes.basic.shift.Shift 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 8 with Shift

use of com.qcadoo.mes.basic.shift.Shift 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 9 with Shift

use of com.qcadoo.mes.basic.shift.Shift 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 10 with Shift

use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.

the class OrderRealizationDaysResolver method findFirstWorkingDayFrom.

private OrderRealizationDay findFirstWorkingDayFrom(final LocalDate orderStartDate, final int startFrom, final List<Shift> shifts) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    int daysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
    for (int offset = startFrom; offset < startFrom + daysInYear; offset++) {
        List<Shift> workingShifts = getShiftsWorkingAt(orderStartDate.plusDays(offset - 1).getDayOfWeek(), shifts);
        if (!workingShifts.isEmpty()) {
            return new OrderRealizationDay(orderStartDate, offset, workingShifts);
        }
    }
    // be any offsets caused by work free time boundaries.
    return new OrderRealizationDay(orderStartDate, startFrom, Collections.<Shift>emptyList());
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Calendar(java.util.Calendar) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Aggregations

Shift (com.qcadoo.mes.basic.shift.Shift)37 DateTime (org.joda.time.DateTime)30 Entity (com.qcadoo.model.api.Entity)12 Test (org.junit.Test)11 TimeRange (com.qcadoo.commons.dateTime.TimeRange)9 DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)8 Date (java.util.Date)7 LocalTime (org.joda.time.LocalTime)7 LocalDate (org.joda.time.LocalDate)6 BigDecimal (java.math.BigDecimal)3 DailyProgressContainer (com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 Calendar (java.util.Calendar)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 Predicate (com.google.common.base.Predicate)1 FluentIterable (com.google.common.collect.FluentIterable)1 Lists (com.google.common.collect.Lists)1 DateRange (com.qcadoo.commons.dateTime.DateRange)1