Search in sources :

Example 1 with MaterialRequirementEntry

use of com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry in project mes by qcadoo.

the class MaterialRequirementPdfService method addGroupedDataSeries.

private void addGroupedDataSeries(final Document document, final Entity materialRequirement, final Locale locale) throws DocumentException {
    Map<WarehouseDateKey, List<MaterialRequirementEntry>> entriesMap = materialRequirementDataService.getGroupedData(materialRequirement);
    boolean includeWarehouse = materialRequirement.getBooleanField(MaterialRequirementFields.INCLUDE_WAREHOUSE);
    boolean includeStartDateOrder = materialRequirement.getBooleanField(MaterialRequirementFields.INCLUDE_START_DATE_ORDER);
    boolean showCurrentStockLevel = materialRequirement.getBooleanField(MaterialRequirementFields.SHOW_CURRENT_STOCK_LEVEL);
    List<Integer> defaultOrderHeaderColumnWidth = Lists.newArrayList();
    Map<String, HeaderAlignment> headersWithAlignments = Maps.newLinkedHashMap();
    if (includeWarehouse) {
        defaultOrderHeaderColumnWidth.add(20);
        headersWithAlignments.put(translationService.translate("materialRequirements.materialRequirement.report.warehouse", locale), HeaderAlignment.LEFT);
    }
    if (includeStartDateOrder) {
        defaultOrderHeaderColumnWidth.add(20);
        headersWithAlignments.put(translationService.translate("materialRequirements.materialRequirement.report.startDateOrder", locale), HeaderAlignment.LEFT);
    }
    defaultOrderHeaderColumnWidth.add(30);
    headersWithAlignments.put(translationService.translate("basic.product.number.label", locale), HeaderAlignment.LEFT);
    defaultOrderHeaderColumnWidth.add(30);
    headersWithAlignments.put(translationService.translate("basic.product.name.label", locale), HeaderAlignment.LEFT);
    defaultOrderHeaderColumnWidth.add(19);
    headersWithAlignments.put(translationService.translate("technologies.technologyOperationComponent.quantity.label", locale), HeaderAlignment.RIGHT);
    defaultOrderHeaderColumnWidth.add(9);
    headersWithAlignments.put(translationService.translate("materialRequirements.materialRequirement.report.product.unit", locale), HeaderAlignment.LEFT);
    if (showCurrentStockLevel) {
        defaultOrderHeaderColumnWidth.add(23);
        headersWithAlignments.put(translationService.translate("materialRequirements.materialRequirement.report.currentStock", locale), HeaderAlignment.RIGHT);
    }
    List<String> headers = Lists.newLinkedList(headersWithAlignments.keySet());
    int[] defaultOrderHeaderColumnWidthInt = new int[defaultOrderHeaderColumnWidth.size()];
    for (int i = 0; i < defaultOrderHeaderColumnWidth.size(); i++) {
        defaultOrderHeaderColumnWidthInt[i] = defaultOrderHeaderColumnWidth.get(i);
    }
    PdfPTable table = pdfHelper.createTableWithHeader(headersWithAlignments.size(), headers, true, defaultOrderHeaderColumnWidthInt, headersWithAlignments);
    List<WarehouseDateKey> keys = Lists.newArrayList(entriesMap.keySet());
    if (includeWarehouse) {
        keys.sort(Comparator.comparing(WarehouseDateKey::getWarehouseNumber).thenComparing(WarehouseDateKey::getDate));
    } else {
        keys.sort(Comparator.comparing(WarehouseDateKey::getDate));
    }
    Map<Long, Map<Long, BigDecimal>> quantitiesInStock = Maps.newHashMap();
    if (showCurrentStockLevel) {
        List<MaterialRequirementEntry> entries = Lists.newArrayList();
        for (WarehouseDateKey key : keys) {
            if (Objects.nonNull(key.getWarehouseId())) {
                entries.addAll(entriesMap.get(key));
            }
        }
        quantitiesInStock = materialRequirementDataService.getQuantitiesInStock(entries);
    }
    String actualWarehouse = "";
    Date actualDate = null;
    int keyIndex = 0;
    for (WarehouseDateKey key : keys) {
        keyIndex += 1;
        List<MaterialRequirementEntry> materials = entriesMap.get(key);
        Map<String, MaterialRequirementEntry> neededProductQuantities = getNeededProductQuantities(materials);
        List<String> materialKeys = Lists.newArrayList(neededProductQuantities.keySet());
        materialKeys.sort(Comparator.naturalOrder());
        int index = 0;
        for (String materialKey : materialKeys) {
            index += 1;
            MaterialRequirementEntry material = neededProductQuantities.get(materialKey);
            table.getDefaultCell().disableBorderSide(PdfCell.BOTTOM);
            table.getDefaultCell().disableBorderSide(PdfCell.TOP);
            if (index == materialKeys.size() && keyIndex == keys.size()) {
                table.getDefaultCell().enableBorderSide(PdfCell.BOTTOM);
            }
            boolean fillDateIfWarehouseChanged = false;
            if (includeWarehouse) {
                if (!actualWarehouse.equals(key.getWarehouseNumber())) {
                    table.getDefaultCell().enableBorderSide(PdfCell.TOP);
                    table.addCell(new Phrase(key.getWarehouseNumber(), FontUtils.getDejavuRegular7Dark()));
                    actualWarehouse = key.getWarehouseNumber();
                    fillDateIfWarehouseChanged = true;
                } else {
                    table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
                }
            }
            if (includeStartDateOrder) {
                Date date = key.getDate();
                if (Objects.isNull(actualDate) || !actualDate.equals(date) || fillDateIfWarehouseChanged) {
                    if (Objects.isNull(date)) {
                        actualDate = null;
                        table.getDefaultCell().enableBorderSide(PdfCell.TOP);
                        table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
                    } else {
                        actualDate = new Date(date.getTime());
                        table.getDefaultCell().enableBorderSide(PdfCell.TOP);
                        table.addCell(new Phrase(DateUtils.toDateString(actualDate), FontUtils.getDejavuRegular7Dark()));
                    }
                } else {
                    table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
                }
            }
            table.getDefaultCell().enableBorderSide(PdfCell.BOTTOM);
            table.getDefaultCell().enableBorderSide(PdfCell.TOP);
            table.addCell(new Phrase(material.getNumber(), FontUtils.getDejavuRegular7Dark()));
            table.addCell(new Phrase(material.getName(), FontUtils.getDejavuRegular7Dark()));
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(new Phrase(numberService.format(material.getPlannedQuantity()), FontUtils.getDejavuBold7Dark()));
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            String unit = material.getUnit();
            if (Objects.isNull(unit)) {
                table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
            } else {
                table.addCell(new Phrase(unit, FontUtils.getDejavuRegular7Dark()));
            }
            if (showCurrentStockLevel) {
                if (Objects.nonNull(key.getWarehouseId())) {
                    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
                    table.addCell(new Phrase(numberService.format(materialRequirementDataService.getQuantity(quantitiesInStock, material)), FontUtils.getDejavuBold7Dark()));
                    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                } else {
                    table.addCell(new Phrase(numberService.format(BigDecimal.ZERO), FontUtils.getDejavuRegular7Dark()));
                }
            }
        }
    }
    document.add(table);
}
Also used : MaterialRequirementEntry(com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry) WarehouseDateKey(com.qcadoo.mes.materialRequirements.print.WarehouseDateKey) Phrase(com.lowagie.text.Phrase) Date(java.util.Date) PdfPTable(com.lowagie.text.pdf.PdfPTable) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment) List(java.util.List) Map(java.util.Map)

Example 2 with MaterialRequirementEntry

use of com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry in project mes by qcadoo.

the class MaterialRequirementXlsService method addGroupedSeries.

private void addGroupedSeries(final HSSFSheet sheet, final Entity materialRequirement) {
    boolean includeWarehouse = materialRequirement.getBooleanField(MaterialRequirementFields.INCLUDE_WAREHOUSE);
    boolean includeStartDateOrder = materialRequirement.getBooleanField(MaterialRequirementFields.INCLUDE_START_DATE_ORDER);
    boolean showCurrentStockLevel = materialRequirement.getBooleanField(MaterialRequirementFields.SHOW_CURRENT_STOCK_LEVEL);
    int rowNum = 1;
    Map<WarehouseDateKey, List<MaterialRequirementEntry>> entriesMap = materialRequirementDataService.getGroupedData(materialRequirement);
    List<WarehouseDateKey> keys = Lists.newArrayList(entriesMap.keySet());
    if (includeWarehouse) {
        keys.sort(Comparator.comparing(WarehouseDateKey::getWarehouseNumber).thenComparing(WarehouseDateKey::getDate));
    } else {
        keys.sort(Comparator.comparing(WarehouseDateKey::getDate));
    }
    Map<Long, Map<Long, BigDecimal>> quantitiesInStock = Maps.newHashMap();
    if (showCurrentStockLevel) {
        List<MaterialRequirementEntry> entries = Lists.newArrayList();
        for (WarehouseDateKey key : keys) {
            if (Objects.nonNull(key.getWarehouseId())) {
                entries.addAll(entriesMap.get(key));
            }
        }
        quantitiesInStock = materialRequirementDataService.getQuantitiesInStock(entries);
    }
    String actualWarehouse = "";
    Date actualDate = null;
    int column = 0;
    for (WarehouseDateKey key : keys) {
        List<MaterialRequirementEntry> materials = entriesMap.get(key);
        Map<String, MaterialRequirementEntry> neededProductQuantities = getNeededProductQuantities(materials);
        List<String> materialKeys = Lists.newArrayList(neededProductQuantities.keySet());
        materialKeys.sort(Comparator.naturalOrder());
        for (String materialKey : materialKeys) {
            HSSFRow row = sheet.createRow(rowNum++);
            column = 0;
            MaterialRequirementEntry material = neededProductQuantities.get(materialKey);
            boolean fillDateIfWarehouseChanged = false;
            if (includeWarehouse) {
                if (!actualWarehouse.equals(key.getWarehouseNumber())) {
                    row.createCell(column).setCellValue(key.getWarehouseNumber());
                    actualWarehouse = key.getWarehouseNumber();
                    fillDateIfWarehouseChanged = true;
                } else {
                    row.createCell(column).setCellValue("");
                }
                column += 1;
            }
            if (includeStartDateOrder) {
                Date date = key.getDate();
                if (Objects.isNull(actualDate) || !actualDate.equals(date) || fillDateIfWarehouseChanged) {
                    if (Objects.isNull(date)) {
                        actualDate = null;
                        row.createCell(column).setCellValue("");
                    } else {
                        actualDate = new Date(date.getTime());
                        row.createCell(column).setCellValue(DateUtils.toDateString(actualDate));
                    }
                } else {
                    row.createCell(column).setCellValue("");
                }
                column += 1;
            }
            row.createCell(column).setCellValue(material.getNumber());
            column += 1;
            row.createCell(column).setCellValue(material.getName());
            column += 1;
            row.createCell(column).setCellValue(numberService.setScaleWithDefaultMathContext(material.getPlannedQuantity()).doubleValue());
            column += 1;
            String unit = material.getUnit();
            if (Objects.isNull(unit)) {
                row.createCell(column).setCellValue("");
            } else {
                row.createCell(column).setCellValue(unit);
            }
            column += 1;
            if (showCurrentStockLevel) {
                if (Objects.nonNull(key.getWarehouseId())) {
                    row.createCell(column).setCellValue(numberService.format(materialRequirementDataService.getQuantity(quantitiesInStock, material)));
                } else {
                    row.createCell(column).setCellValue(numberService.format(BigDecimal.ZERO));
                }
            }
        }
    }
    for (int i = 0; i < column; i++) {
        sheet.autoSizeColumn((short) i);
    }
}
Also used : MaterialRequirementEntry(com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) WarehouseDateKey(com.qcadoo.mes.materialRequirements.print.WarehouseDateKey) Date(java.util.Date) List(java.util.List) Map(java.util.Map)

Example 3 with MaterialRequirementEntry

use of com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry in project mes by qcadoo.

the class MaterialRequirementPdfService method getNeededProductQuantities.

private Map<String, MaterialRequirementEntry> getNeededProductQuantities(final List<MaterialRequirementEntry> materials) {
    Map<String, MaterialRequirementEntry> neededProductQuantities = Maps.newHashMap();
    for (MaterialRequirementEntry mre : materials) {
        String product = mre.getNumber();
        if (neededProductQuantities.containsKey(product)) {
            BigDecimal pQ = mre.getPlannedQuantity().add(neededProductQuantities.get(product).getPlannedQuantity());
            mre.setPlannedQuantity(pQ);
        }
        neededProductQuantities.put(product, mre);
    }
    return neededProductQuantities;
}
Also used : MaterialRequirementEntry(com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry) BigDecimal(java.math.BigDecimal)

Example 4 with MaterialRequirementEntry

use of com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry in project mes by qcadoo.

the class MaterialRequirementXlsService method getNeededProductQuantities.

private Map<String, MaterialRequirementEntry> getNeededProductQuantities(final List<MaterialRequirementEntry> materials) {
    Map<String, MaterialRequirementEntry> neededProductQuantities = Maps.newHashMap();
    for (MaterialRequirementEntry mre : materials) {
        String product = mre.getNumber();
        if (neededProductQuantities.containsKey(product)) {
            BigDecimal pQ = mre.getPlannedQuantity().add(neededProductQuantities.get(product).getPlannedQuantity());
            mre.setPlannedQuantity(pQ);
        }
        neededProductQuantities.put(product, mre);
    }
    return neededProductQuantities;
}
Also used : MaterialRequirementEntry(com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry) BigDecimal(java.math.BigDecimal)

Aggregations

MaterialRequirementEntry (com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry)4 WarehouseDateKey (com.qcadoo.mes.materialRequirements.print.WarehouseDateKey)2 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 Phrase (com.lowagie.text.Phrase)1 PdfPTable (com.lowagie.text.pdf.PdfPTable)1 HeaderAlignment (com.qcadoo.report.api.pdf.HeaderAlignment)1 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)1