Search in sources :

Example 1 with EntityProductionPerShiftsComparator

use of com.qcadoo.mes.productionPerShift.report.print.utils.EntityProductionPerShiftsComparator 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)

Aggregations

TimeRange (com.qcadoo.commons.dateTime.TimeRange)1 Shift (com.qcadoo.mes.basic.shift.Shift)1 ReportColumn (com.qcadoo.mes.productionPerShift.report.columns.ReportColumn)1 EntityProductionPerShiftsComparator (com.qcadoo.mes.productionPerShift.report.print.utils.EntityProductionPerShiftsComparator)1 Entity (com.qcadoo.model.api.Entity)1 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)1 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 LocalTime (org.joda.time.LocalTime)1