Search in sources :

Example 1 with HeaderAlignment

use of com.qcadoo.report.api.pdf.HeaderAlignment in project qcadoo by qcadoo.

the class PdfHelperImpl method setTableProperties.

private PdfPTable setTableProperties(final List<String> header, final PdfPTable table, final Map<String, HeaderAlignment> alignments) {
    table.setWidthPercentage(100f);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setSpacingBefore(7.0f);
    table.getDefaultCell().setBorderColor(ColorUtils.getLineDarkColor());
    table.getDefaultCell().setBorderWidth(1.0f);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setPadding(5.0f);
    table.getDefaultCell().disableBorderSide(Rectangle.RIGHT);
    if (alignments == null || alignments.isEmpty()) {
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        int i = 0;
        for (String element : header) {
            i++;
            if (i == header.size()) {
                table.getDefaultCell().enableBorderSide(Rectangle.RIGHT);
            }
            table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark()));
            if (i == 1) {
                table.getDefaultCell().disableBorderSide(Rectangle.LEFT);
            }
        }
    } else {
        int i = 0;
        for (String element : header) {
            i++;
            HeaderAlignment alignment = alignments.get(element);
            if (HeaderAlignment.LEFT.equals(alignment)) {
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            } else if (HeaderAlignment.RIGHT.equals(alignment)) {
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            }
            if (i == header.size()) {
                table.getDefaultCell().enableBorderSide(Rectangle.RIGHT);
            }
            table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark()));
            if (i == 1) {
                table.getDefaultCell().disableBorderSide(Rectangle.LEFT);
            }
        }
    }
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.getDefaultCell().setBackgroundColor(null);
    table.getDefaultCell().disableBorderSide(Rectangle.RIGHT);
    table.getDefaultCell().setBorderColor(ColorUtils.getLineLightColor());
    return table;
}
Also used : HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment) Phrase(com.lowagie.text.Phrase)

Example 2 with HeaderAlignment

use of com.qcadoo.report.api.pdf.HeaderAlignment in project mes by qcadoo.

the class TechnologiesTechnologyDetailsPdfView method addContent.

@Override
protected final String addContent(final Document document, final Map<String, Object> model, final Locale locale, final PdfWriter writer) throws DocumentException, IOException {
    checkState(model.get("id") != null, "Unable to generate report for unsaved technology! (missing id)");
    String documentTitle = translationService.translate("technologies.technologiesTechnologyDetails.report.title", locale);
    String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale);
    pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, new Date());
    DataDefinition technologyDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY);
    Entity technology = technologyDD.get(valueOf(model.get("id").toString()));
    Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);
    PdfPTable panelTable = pdfHelper.createPanelTable(3);
    pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate(TECHNOLOGIES_TECHNOLOGIES_TECHNOLOGY_DETAILS_REPORT_PANEL_TECHNOLOGY + TechnologyFields.NAME, locale), technology.getStringField(TechnologyFields.NAME));
    pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate(TECHNOLOGIES_TECHNOLOGIES_TECHNOLOGY_DETAILS_REPORT_PANEL_TECHNOLOGY + TechnologyFields.NUMBER, locale), technology.getStringField(TechnologyFields.NUMBER));
    panelTable.addCell(createImageCell(product));
    pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate(TECHNOLOGIES_TECHNOLOGIES_TECHNOLOGY_DETAILS_REPORT_PANEL_TECHNOLOGY + TechnologyFields.PRODUCT, locale), product.getStringField(ProductFields.NAME));
    pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate("technologies.technologiesTechnologyDetails.report.panel.technology.default", locale), technology.getBooleanField(TechnologyFields.MASTER) ? translationService.translate("qcadooView.true", locale) : translationService.translate("qcadooView.false", locale));
    if (StringUtils.isEmpty(technology.getStringField(ProductFields.DESCRIPTION))) {
        panelTable.addCell(StringUtils.EMPTY);
    } else {
        pdfHelper.addTableCellAsOneColumnTable(panelTable, translationService.translate(TECHNOLOGIES_TECHNOLOGIES_TECHNOLOGY_DETAILS_REPORT_PANEL_TECHNOLOGY + TechnologyFields.DESCRIPTION, locale), technology.getStringField(ProductFields.DESCRIPTION));
    }
    panelTable.addCell(StringUtils.EMPTY);
    panelTable.setSpacingAfter(20);
    panelTable.setSpacingBefore(20);
    document.add(panelTable);
    List<String> technologyDetailsTableHeader = new ArrayList<>();
    technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.level", locale));
    technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.name", locale));
    technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.direction", locale));
    technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.technologyInputProductTypeName", locale));
    technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.productNumber", locale));
    technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.productName", locale));
    technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.quantity", locale));
    technologyDetailsTableHeader.add(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.unit", locale));
    Map<String, HeaderAlignment> alignments = Maps.newHashMap();
    alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.level", locale), HeaderAlignment.LEFT);
    alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.name", locale), HeaderAlignment.LEFT);
    alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.direction", locale), HeaderAlignment.LEFT);
    alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.technologyInputProductTypeName", locale), HeaderAlignment.LEFT);
    alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.productNumber", locale), HeaderAlignment.LEFT);
    alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.productName", locale), HeaderAlignment.LEFT);
    alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.quantity", locale), HeaderAlignment.RIGHT);
    alignments.put(translationService.translate("technologies.technologiesTechnologyDetails.report.columnHeader.unit", locale), HeaderAlignment.LEFT);
    PdfPTable table = pdfHelper.createTableWithHeader(8, technologyDetailsTableHeader, false, alignments);
    EntityTree technologyTree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    treeNumberingService.generateTreeNumbers(technologyTree);
    List<Entity> technologyOperationComponents = entityTreeUtilsService.getSortedEntities(technologyTree);
    for (Entity technologyOperationComponent : technologyOperationComponents) {
        String nodeNumber = technologyOperationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER);
        String operationName = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION).getStringField(OperationFields.NAME);
        List<Entity> operationProductComponents = newArrayList();
        operationProductComponents.addAll(technologyOperationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS));
        operationProductComponents.addAll(technologyOperationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS));
        addProducts(locale, table, nodeNumber, operationName, operationProductComponents);
    }
    document.add(table);
    return translationService.translate("technologies.technologiesTechnologyDetails.report.fileName", locale);
}
Also used : Entity(com.qcadoo.model.api.Entity) PdfPTable(com.lowagie.text.pdf.PdfPTable) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Date(java.util.Date)

Example 3 with HeaderAlignment

use of com.qcadoo.report.api.pdf.HeaderAlignment in project mes by qcadoo.

the class DocumentPdf method createTable.

private PdfPTable createTable() {
    int[] headerWidths = Ints.toArray(getHeaderWidths());
    Map<String, HeaderAlignment> headerValues = getHeaderValues(locale);
    PdfPTable warehouseTable = pdfHelper.createTableWithHeader(headerWidths.length, Lists.newArrayList(headerValues.keySet()), false, headerWidths, headerValues);
    warehouseTable.getDefaultCell().disableBorderSide(PdfPCell.RIGHT);
    warehouseTable.getDefaultCell().disableBorderSide(PdfPCell.LEFT);
    warehouseTable.setHeaderRows(1);
    warehouseTable.setSpacingAfter(12.0f);
    return warehouseTable;
}
Also used : PdfPTable(com.lowagie.text.pdf.PdfPTable) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment)

Example 4 with HeaderAlignment

use of com.qcadoo.report.api.pdf.HeaderAlignment in project mes by qcadoo.

the class OperationProductInTable method print.

public void print(final Entity workPlan, final GroupingContainer groupingContainer, final OrderOperationComponent orderOperationComponent, final Document document, final Locale locale) throws DocumentException {
    Entity order = orderOperationComponent.getOrder();
    Entity operationComponent = orderOperationComponent.getOperationComponent();
    Map<Long, Map<OperationProductColumn, ColumnAlignment>> map = groupingContainer.getOperationComponentIdProductInColumnToAlignment();
    Map<OperationProductColumn, ColumnAlignment> operationProductColumnAlignmentMap = map.get(operationComponent.getId());
    int columnCount = operationProductColumnAlignmentMap.size();
    Map<String, HeaderAlignment> headerAlignments = new HashMap<>(columnCount);
    List<String> headers = new ArrayList<>(columnCount);
    fill(locale, operationProductColumnAlignmentMap, headers, headerAlignments);
    PdfPTable table = pdfHelper.createTableWithHeader(columnCount, headers, false, headerAlignments);
    PdfPCell defaultCell = table.getDefaultCell();
    List<OperationProductHelper> operationProductsValue = prepareOperationProductsValue(order, orderOperationComponent.getProductionCountingQuantitiesIn(), operationProductColumnAlignmentMap.entrySet());
    operationProductsValue = workPlansService.sortByColumn(workPlan, operationProductsValue, headers);
    for (OperationProductHelper operationProduct : operationProductsValue) {
        for (OperationProductColumnHelper e : operationProduct.getOperationProductColumnHelpers()) {
            alignColumn(defaultCell, e.getColumnAlignment());
            table.addCell(operationProductPhrase(e.getValue()));
        }
    }
    int additionalRows = workPlansService.getAdditionalRowsFromParameter(ParameterFieldsWP.ADDITIONAL_INPUT_ROWS);
    for (int i = 0; i < additionalRows; i++) {
        for (Map.Entry<OperationProductColumn, ColumnAlignment> e : operationProductColumnAlignmentMap.entrySet()) {
            alignColumn(defaultCell, e.getValue());
            table.addCell(" ");
        }
    }
    table.setSpacingAfter(18);
    table.setSpacingBefore(9);
    document.add(table);
}
Also used : Entity(com.qcadoo.model.api.Entity) ColumnAlignment(com.qcadoo.mes.columnExtension.constants.ColumnAlignment) PdfPCell(com.lowagie.text.pdf.PdfPCell) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PdfPTable(com.lowagie.text.pdf.PdfPTable) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment) OperationProductColumn(com.qcadoo.mes.workPlans.pdf.document.operation.product.column.OperationProductColumn) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with HeaderAlignment

use of com.qcadoo.report.api.pdf.HeaderAlignment in project mes by qcadoo.

the class OrderReportPdf method prepareHeaderAlignment.

private Map<String, HeaderAlignment> prepareHeaderAlignment(List<Entity> filteredColumnsForDeliveries, Locale locale) {
    Map<String, HeaderAlignment> alignments = Maps.newHashMap();
    for (Entity column : filteredColumnsForDeliveries) {
        String alignment = column.getStringField(ColumnForDeliveriesFields.ALIGNMENT);
        HeaderAlignment headerAlignment = HeaderAlignment.RIGHT;
        if (ColumnAlignment.LEFT.equals(ColumnAlignment.parseString(alignment))) {
            headerAlignment = HeaderAlignment.LEFT;
        } else if (ColumnAlignment.RIGHT.equals(ColumnAlignment.parseString(alignment))) {
            headerAlignment = HeaderAlignment.RIGHT;
        }
        alignments.put(prepareHeaderTranslation(column.getStringField(ColumnForDeliveriesFields.NAME), locale), headerAlignment);
    }
    return alignments;
}
Also used : Entity(com.qcadoo.model.api.Entity) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment)

Aggregations

HeaderAlignment (com.qcadoo.report.api.pdf.HeaderAlignment)23 PdfPTable (com.lowagie.text.pdf.PdfPTable)16 Entity (com.qcadoo.model.api.Entity)16 Map (java.util.Map)7 PdfPCell (com.lowagie.text.pdf.PdfPCell)5 ArrayList (java.util.ArrayList)5 Phrase (com.lowagie.text.Phrase)4 Date (java.util.Date)4 Paragraph (com.lowagie.text.Paragraph)3 ColumnAlignment (com.qcadoo.mes.columnExtension.constants.ColumnAlignment)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Document (com.lowagie.text.Document)2 DocumentException (com.lowagie.text.DocumentException)2 Element (com.lowagie.text.Element)2 TranslationService (com.qcadoo.localization.api.TranslationService)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2