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