Example usage for com.lowagie.text.pdf PdfPTable getDefaultCell

List of usage examples for com.lowagie.text.pdf PdfPTable getDefaultCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable getDefaultCell.

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

public PdfPTable addMaterialsTable(final Entity costCalculation, final Locale locale) {
    List<String> materialsTableHeader = Lists.newArrayList();
    Map<String, HeaderAlignment> alignments = Maps.newHashMap();

    for (String translate : Arrays.asList(
            L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER,
            "costCalculation.costCalculationDetails.report.columnHeader.quantity",
            "costCalculation.costCalculationDetails.report.columnHeader.unit",
            "costCalculation.costCalculationDetails.report.columnHeader.costs",
            "costCalculation.costCalculationDetails.report.columnHeader.margin",
            "costCalculation.costCalculationDetails.report.columnHeader.totalCosts")) {
        materialsTableHeader.add(translationService.translate(translate, locale));
    }/*  ww  w. ja v a2  s .c  o m*/

    alignments.put(translationService.translate(
            "costCalculation.costCalculationDetails.report.columnHeader.number", locale), HeaderAlignment.LEFT);
    alignments.put(translationService
            .translate("costCalculation.costCalculationDetails.report.columnHeader.quantity", locale),
            HeaderAlignment.RIGHT);
    alignments.put(translationService.translate(
            "costCalculation.costCalculationDetails.report.columnHeader.unit", locale), HeaderAlignment.LEFT);
    alignments.put(translationService.translate(
            "costCalculation.costCalculationDetails.report.columnHeader.costs", locale), HeaderAlignment.RIGHT);
    alignments.put(translationService
            .translate("costCalculation.costCalculationDetails.report.columnHeader.margin", locale),
            HeaderAlignment.RIGHT);
    alignments.put(
            translationService
                    .translate("costCalculation.costCalculationDetails.report.columnHeader.totalCosts", locale),
            HeaderAlignment.RIGHT);

    PdfPTable materialsTable = pdfHelper.createTableWithHeader(materialsTableHeader.size(),
            materialsTableHeader, false, alignments);

    try {
        float[] columnWidths = { 1f, 1f, 0.5f, 1f, 1f, 1.5f };
        materialsTable.setWidths(columnWidths);
    } catch (DocumentException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }

    Entity technology;
    Entity order = costCalculation.getBelongsToField(CostCalculationFields.ORDER);

    if (order == null) {
        technology = costCalculation.getBelongsToField(CostCalculationFields.TECHNOLOGY);
    } else {
        technology = costCalculation.getBelongsToField(CostCalculationFields.ORDER)
                .getBelongsToField(CostCalculationFields.TECHNOLOGY);
    }

    BigDecimal quantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY);

    Map<Long, BigDecimal> neededProductQuantities = getNeededProductQuantities(costCalculation, technology,
            quantity, MrpAlgorithm.COMPONENTS_AND_SUBCONTRACTORS_PRODUCTS);

    // TODO LUPO fix comparator
    // neededProductQuantities = SortUtil.sortMapUsingComparator(neededProductQuantities, new EntityNumberComparator());

    MathContext mathContext = numberService.getMathContext();

    for (Entry<Long, BigDecimal> neededProductQuantity : neededProductQuantities.entrySet()) {
        Entity product = productQuantitiesService.getProduct(neededProductQuantity.getKey());

        Entity productEntity = productsCostCalculationService.getAppropriateCostNormForProduct(product, order,
                costCalculation.getStringField(CostCalculationFields.SOURCE_OF_MATERIAL_COSTS));

        BigDecimal productQuantity = neededProductQuantity.getValue();

        materialsTable.addCell(
                new Phrase(product.getStringField(ProductFields.NUMBER), FontUtils.getDejavuRegular7Dark()));
        materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        materialsTable
                .addCell(new Phrase(numberService.format(productQuantity), FontUtils.getDejavuRegular7Dark()));
        materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        materialsTable.addCell(
                new Phrase(product.getStringField(ProductFields.UNIT), FontUtils.getDejavuRegular7Dark()));
        materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

        BigDecimal costForGivenQuantity = productsCostCalculationService.calculateProductCostForGivenQuantity(
                productEntity, productQuantity,
                costCalculation.getStringField(CostCalculationFields.CALCULATE_MATERIAL_COSTS_MODE));

        materialsTable.addCell(
                new Phrase(numberService.format(costForGivenQuantity), FontUtils.getDejavuRegular7Dark()));

        BigDecimal materialCostMargin = costCalculation
                .getDecimalField(CostCalculationFields.MATERIAL_COST_MARGIN);

        if (materialCostMargin == null) {
            materialsTable.addCell(new Phrase(numberService.format(0.0), FontUtils.getDejavuRegular7Dark()));
            materialsTable.addCell(
                    new Phrase(numberService.format(costForGivenQuantity), FontUtils.getDejavuRegular7Dark()));
        } else {
            BigDecimal toAdd = costForGivenQuantity
                    .multiply(materialCostMargin.divide(new BigDecimal(100), mathContext), mathContext);
            BigDecimal totalCosts = costForGivenQuantity.add(toAdd, mathContext);

            materialsTable.addCell(new Phrase(numberService.format(toAdd), FontUtils.getDejavuRegular7Dark()));
            materialsTable
                    .addCell(new Phrase(numberService.format(totalCosts), FontUtils.getDejavuRegular7Dark()));
        }

        materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    }

    BigDecimal totalMaterialCosts = costCalculation.getDecimalField(CostCalculationFields.TOTAL_MATERIAL_COSTS);
    BigDecimal materialCostsMarginValue = costCalculation
            .getDecimalField(CostCalculationFields.MATERIAL_COST_MARGIN_VALUE);

    BigDecimal totalCostOfMaterialValue = totalMaterialCosts.add(materialCostsMarginValue, mathContext);

    String totalMaterialCostsToString = numberService.format(totalMaterialCosts);
    String materialCostMarginValueToString = numberService.format(materialCostsMarginValue);
    String totalCostOfMaterialToString = numberService.format(totalCostOfMaterialValue);

    materialsTable.addCell(new Phrase(
            translationService.translate("costCalculation.costCalculation.report.totalMaterial", locale),
            FontUtils.getDejavuRegular7Dark()));
    materialsTable.addCell("");
    materialsTable.addCell("");
    materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

    materialsTable.addCell(new Phrase(totalMaterialCostsToString, FontUtils.getDejavuRegular7Dark()));
    materialsTable.addCell(new Phrase(materialCostMarginValueToString, FontUtils.getDejavuRegular7Dark()));
    materialsTable.addCell(new Phrase(totalCostOfMaterialToString, FontUtils.getDejavuRegular7Dark()));

    materialsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

    return materialsTable;
}

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

private PdfPTable addHourlyCostsTable(final Entity costCalculation, final Locale locale) {
    List<String> hourlyCostsTableHeader = Lists.newArrayList();

    for (String translate : Arrays.asList("costCalculation.costCalculationDetails.report.columnHeader.level",
            L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER,
            "costCalculation.costCalculationDetails.report.columnHeader.machDuration",
            "costCalculation.costCalculationDetails.report.columnHeader.machCosts",
            "costCalculation.costCalculationDetails.report.columnHeader.labDuration",
            "costCalculation.costCalculationDetails.report.columnHeader.labCosts",
            "costCalculation.costCalculationDetails.report.columnHeader.margin",
            "costCalculation.costCalculationDetails.report.columnHeader.totalCosts")) {
        hourlyCostsTableHeader.add(translationService.translate(translate, locale));
    }//from  w w w.j a  v  a  2s  . c om

    Map<String, HeaderAlignment> alignments = Maps.newHashMap();
    alignments.put(translationService.translate(
            "costCalculation.costCalculationDetails.report.columnHeader.level", locale), HeaderAlignment.LEFT);
    alignments.put(
            translationService
                    .translate(L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, locale),
            HeaderAlignment.LEFT);
    alignments.put(
            translationService.translate(
                    "costCalculation.costCalculationDetails.report.columnHeader.machDuration", locale),
            HeaderAlignment.RIGHT);
    alignments.put(translationService
            .translate("costCalculation.costCalculationDetails.report.columnHeader.machCosts", locale),
            HeaderAlignment.RIGHT);
    alignments.put(
            translationService.translate(
                    "costCalculation.costCalculationDetails.report.columnHeader.labDuration", locale),
            HeaderAlignment.RIGHT);
    alignments.put(translationService
            .translate("costCalculation.costCalculationDetails.report.columnHeader.labCosts", locale),
            HeaderAlignment.RIGHT);
    alignments.put(translationService
            .translate("costCalculation.costCalculationDetails.report.columnHeader.margin", locale),
            HeaderAlignment.RIGHT);
    alignments.put(
            translationService
                    .translate("costCalculation.costCalculationDetails.report.columnHeader.totalCosts", locale),
            HeaderAlignment.RIGHT);

    List<Entity> calculationOperationComponents = costCalculation
            .getHasManyField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS);

    PdfPTable hourlyCostsTable = pdfHelper.createTableWithHeader(hourlyCostsTableHeader.size(),
            hourlyCostsTableHeader, false, alignments);

    try {
        float[] columnWidths = { 1f, 0.75f, 1f, 1f, 1f, 1f, 1f, 1.25f };
        hourlyCostsTable.setWidths(columnWidths);

    } catch (DocumentException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }

    if (calculationOperationComponents != null && !calculationOperationComponents.isEmpty()) {
        Integer totalMachineWorkTimeSummary = Integer.valueOf(0);
        Integer totalLaborWorkTimeSummary = Integer.valueOf(0);

        BigDecimal totalOperationCostSummary = BigDecimal.ZERO;

        MathContext mathContext = numberService.getMathContext();

        for (Entity calculationOperationComponent : calculationOperationComponents) {
            Integer machineWorkTime = calculationOperationComponent
                    .getIntegerField(CalculationOperationComponentFields.MACHINE_WORK_TIME);
            Integer laborWorkTime = calculationOperationComponent
                    .getIntegerField(CalculationOperationComponentFields.LABOR_WORK_TIME);
            BigDecimal totalMachineOperationCost = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.TOTAL_MACHINE_OPERATION_COST);
            BigDecimal totalLaborOperationCost = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.TOTAL_LABOR_OPERATION_COST);
            BigDecimal operationCost = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.OPERATION_COST);
            BigDecimal operationMarginCost = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.OPERATION_MARGIN_COST);
            BigDecimal totalOperationCost = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.TOTAL_OPERATION_COST);

            hourlyCostsTable
                    .addCell(new Phrase(
                            calculationOperationComponent
                                    .getField(CalculationOperationComponentFields.NODE_NUMBER).toString(),
                            FontUtils.getDejavuRegular7Dark()));
            hourlyCostsTable.addCell(new Phrase(
                    calculationOperationComponent.getBelongsToField(TechnologiesConstants.MODEL_OPERATION)
                            .getStringField(OperationFields.NUMBER),
                    FontUtils.getDejavuRegular7Dark()));
            hourlyCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            hourlyCostsTable.addCell(new Phrase(timeConverterService.convertTimeToString(machineWorkTime),
                    FontUtils.getDejavuRegular7Dark()));
            hourlyCostsTable.addCell(new Phrase(numberService.format(totalMachineOperationCost),
                    FontUtils.getDejavuRegular7Dark()));
            hourlyCostsTable.addCell(new Phrase(timeConverterService.convertTimeToString(laborWorkTime),
                    FontUtils.getDejavuRegular7Dark()));
            hourlyCostsTable.addCell(new Phrase(numberService.format(totalLaborOperationCost),
                    FontUtils.getDejavuRegular7Dark()));
            hourlyCostsTable.addCell(
                    new Phrase(numberService.format(operationMarginCost), FontUtils.getDejavuRegular7Dark()));
            hourlyCostsTable.addCell(
                    new Phrase(numberService.format(totalOperationCost), FontUtils.getDejavuRegular7Dark()));

            hourlyCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

            totalMachineWorkTimeSummary += IntegerUtils.convertNullToZero(machineWorkTime);
            totalLaborWorkTimeSummary += IntegerUtils.convertNullToZero(laborWorkTime);

            // BigDecimal totalMachineOperationCostWithMargin =
            // BigDecimalUtils.convertNullToZero(calculationOperationComponent
            // .getDecimalField(CalculationOperationComponentFields.TOTAL_MACHINE_OPERATION_COST_WITH_MARGIN));
            //
            // BigDecimal totalLaborOperationCostWithMargin = BigDecimalUtils.convertNullToZero(calculationOperationComponent
            // .getDecimalField(CalculationOperationComponentFields.TOTAL_LABOR_OPERATION_COST_WITH_MARGIN));

            // BigDecimal totalOperationCostSummary =
            // totalMachineOperationCostWithMargin.add(totalLaborOperationCostWithMargin,
            // mathContext);
            //
            // totalOperationCostWithMarginSummary = totalOperationCostWithMarginSummary.add(totalOperationCostWithMargin,
            // mathContext);

            totalOperationCostSummary = totalOperationCostSummary.add(operationCost, mathContext);
        }

        BigDecimal productionCostMarginValue = costCalculation
                .getDecimalField(CostCalculationFields.PRODUCTION_COST_MARGIN_VALUE);

        BigDecimal totalOperationCost = totalOperationCostSummary.add(productionCostMarginValue, mathContext);

        String totalMachineWorkTimeToString = timeConverterService
                .convertTimeToString(totalMachineWorkTimeSummary);
        String totalMachineHourlyCosts = numberService
                .format(costCalculation.getDecimalField(CostCalculationFields.TOTAL_MACHINE_HOURLY_COSTS));
        String totalLaborWorkTimeToString = timeConverterService.convertTimeToString(totalLaborWorkTimeSummary);
        String totalLaborHourlyCosts = numberService
                .format(costCalculation.getDecimalField(CostCalculationFields.TOTAL_LABOR_HOURLY_COSTS));
        String totalProductionCostMarginValue = numberService.format(productionCostMarginValue);
        String totalOperationCostToString = numberService.format(totalOperationCost);

        hourlyCostsTable.addCell(new Phrase(
                translationService.translate("costCalculation.costCalculation.report.totalOperation", locale),
                FontUtils.getDejavuRegular7Dark()));
        hourlyCostsTable.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
        hourlyCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

        hourlyCostsTable.addCell(new Phrase(totalMachineWorkTimeToString, FontUtils.getDejavuRegular7Dark()));
        hourlyCostsTable.addCell(new Phrase(totalMachineHourlyCosts, FontUtils.getDejavuRegular7Dark()));
        hourlyCostsTable.addCell(new Phrase(totalLaborWorkTimeToString, FontUtils.getDejavuRegular7Dark()));
        hourlyCostsTable.addCell(new Phrase(totalLaborHourlyCosts, FontUtils.getDejavuRegular7Dark()));
        hourlyCostsTable.addCell(new Phrase(totalProductionCostMarginValue, FontUtils.getDejavuRegular7Dark()));
        hourlyCostsTable.addCell(new Phrase(totalOperationCostToString, FontUtils.getDejavuRegular7Dark()));

        hourlyCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    }

    return hourlyCostsTable;
}

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

private PdfPTable addTableAboutPieceworkCost(final Entity costCalculation, final Locale locale) {
    List<String> pieceworkCostsTableHeader = Lists.newArrayList();
    Map<String, HeaderAlignment> alignments = Maps.newHashMap();

    for (String translate : Arrays.asList("costCalculation.costCalculationDetails.report.columnHeader.level",
            L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER,
            "costCalculation.costCalculationDetails.report.columnHeader.pieces",
            "costCalculation.costCalculationDetails.report.columnHeader.operationCost",
            "costCalculation.costCalculationDetails.report.columnHeader.margin",
            "costCalculation.costCalculationDetails.report.columnHeader.totalCosts")) {
        pieceworkCostsTableHeader.add(translationService.translate(translate, locale));
    }/*w  ww  . j  a  v  a2s  . c  o  m*/
    alignments.put(translationService.translate(
            "costCalculation.costCalculationDetails.report.columnHeader.level", locale), HeaderAlignment.LEFT);
    alignments.put(
            translationService
                    .translate(L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, locale),
            HeaderAlignment.LEFT);
    alignments.put(translationService
            .translate("costCalculation.costCalculationDetails.report.columnHeader.pieces", locale),
            HeaderAlignment.RIGHT);
    alignments.put(
            translationService.translate(
                    "costCalculation.costCalculationDetails.report.columnHeader.operationCost", locale),
            HeaderAlignment.RIGHT);
    alignments.put(translationService
            .translate("costCalculation.costCalculationDetails.report.columnHeader.margin", locale),
            HeaderAlignment.RIGHT);
    alignments.put(
            translationService
                    .translate("costCalculation.costCalculationDetails.report.columnHeader.totalCosts", locale),
            HeaderAlignment.RIGHT);

    List<Entity> calculationOperationComponents = costCalculation
            .getTreeField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS);

    PdfPTable pieceworkCostsTable = pdfHelper.createTableWithHeader(pieceworkCostsTableHeader.size(),
            pieceworkCostsTableHeader, false, alignments);

    try {
        float[] columnWidths = { 1f, 0.75f, 1f, 1f, 1f, 1.25f };
        pieceworkCostsTable.setWidths(columnWidths);
    } catch (DocumentException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }

    if (!calculationOperationComponents.isEmpty()) {
        BigDecimal totalOperationCostSummary = BigDecimal.ZERO;
        BigDecimal totalPieces = BigDecimal.ZERO;

        MathContext mathContext = numberService.getMathContext();

        for (Entity calculationOperationComponent : calculationOperationComponents) {
            BigDecimal pieces = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.PIECES);
            BigDecimal operationCost = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.OPERATION_COST);
            BigDecimal operationMarginCost = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.OPERATION_MARGIN_COST);
            BigDecimal totalOperationCost = calculationOperationComponent
                    .getDecimalField(CalculationOperationComponentFields.TOTAL_OPERATION_COST);

            pieceworkCostsTable
                    .addCell(new Phrase(
                            calculationOperationComponent
                                    .getField(CalculationOperationComponentFields.NODE_NUMBER).toString(),
                            FontUtils.getDejavuRegular7Dark()));
            pieceworkCostsTable.addCell(new Phrase(
                    calculationOperationComponent.getBelongsToField(TechnologiesConstants.MODEL_OPERATION)
                            .getStringField(OperationFields.NUMBER),
                    FontUtils.getDejavuRegular7Dark()));
            pieceworkCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            pieceworkCostsTable
                    .addCell(new Phrase(numberService.format(pieces), FontUtils.getDejavuRegular7Dark()));
            pieceworkCostsTable.addCell(
                    new Phrase(numberService.format(operationCost), FontUtils.getDejavuRegular7Dark()));
            pieceworkCostsTable.addCell(
                    new Phrase(numberService.format(operationMarginCost), FontUtils.getDejavuRegular7Dark()));
            pieceworkCostsTable.addCell(
                    new Phrase(numberService.format(totalOperationCost), FontUtils.getDejavuRegular7Dark()));

            pieceworkCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

            totalPieces = totalPieces.add(pieces, mathContext);

            totalOperationCostSummary = totalOperationCostSummary.add(operationCost, mathContext);
        }

        BigDecimal productionCostMarginValue = costCalculation
                .getDecimalField(CostCalculationFields.PRODUCTION_COST_MARGIN_VALUE);

        BigDecimal totalOperationCost = totalOperationCostSummary.add(productionCostMarginValue, mathContext);

        String totalPiecesToString = numberService.format(totalPieces);
        String totalOperationCostSummaryToString = numberService.format(totalOperationCostSummary);
        String productionCostMarginValueToString = numberService.format(productionCostMarginValue);
        String totalOperationCostToString = numberService.format(totalOperationCost);

        pieceworkCostsTable.addCell(new Phrase(
                translationService.translate("costCalculation.costCalculation.report.totalOperation", locale),
                FontUtils.getDejavuRegular7Dark()));
        pieceworkCostsTable.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
        pieceworkCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

        pieceworkCostsTable.addCell(new Phrase(totalPiecesToString, FontUtils.getDejavuRegular7Dark()));
        pieceworkCostsTable
                .addCell(new Phrase(totalOperationCostSummaryToString, FontUtils.getDejavuRegular7Dark()));
        pieceworkCostsTable
                .addCell(new Phrase(productionCostMarginValueToString, FontUtils.getDejavuRegular7Dark()));
        pieceworkCostsTable.addCell(new Phrase(totalOperationCostToString, FontUtils.getDejavuRegular7Dark()));

        pieceworkCostsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    }

    return pieceworkCostsTable;
}

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

public void addOptionTablePrintOperationNormsHourly(final Document document, final Entity costCalculation,
        final Locale locale) throws DocumentException {
    List<String> optionTableHeader = Lists.newArrayList();

    for (String translate : Arrays.asList(
            L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER,
            L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NAME)) {
        optionTableHeader.add(translationService.translate(translate, locale));
    }//from  w w  w.  j a va 2 s.c o  m

    List<Entity> calculationOperationComponents = entityTreeUtilsService.getSortedEntities(
            costCalculation.getTreeField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS));

    for (Entity calculationOperationComponent : calculationOperationComponents) {
        PdfPTable panelTableHeader = pdfHelper.createPanelTable(2);
        PdfPTable panelTableContent = pdfHelper.createPanelTable(2);
        panelTableHeader.setSpacingBefore(10);
        panelTableContent.getDefaultCell().setBackgroundColor(null);
        panelTableContent.setTableEvent(null);

        Entity technologyOperationComponent = calculationOperationComponent
                .getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT);
        Entity operation = calculationOperationComponent
                .getBelongsToField(CalculationOperationComponentFields.OPERATION);

        panelTableHeader
                .addCell(new Phrase(
                        translationService.translate(
                                L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, locale)
                                + ": " + operation.getStringField(OperationFields.NUMBER),
                        FontUtils.getDejavuRegular7Dark()));

        panelTableHeader
                .addCell(new Phrase(
                        translationService.translate(
                                L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NAME, locale)
                                + ": " + operation.getStringField(OperationFields.NAME),
                        FontUtils.getDejavuRegular7Dark()));

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.productionSetUpTime.label",
                        locale) + ":",
                timeConverterService.convertTimeToString(technologyOperationComponent
                        .getIntegerField(TechnologyOperationComponentFieldsTNFO.TPZ)) + " (g:m:s)");

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.machineUtilization.label",
                        locale) + ":",
                numberService.format(technologyOperationComponent
                        .getDecimalField(TechnologyOperationComponentFieldsTNFO.MACHINE_UTILIZATION)));

        addTableCellAsTwoColumnsTable(panelTableContent, translationService.translate(
                "costCalculation.costCalculationDetails.report.columnHeader.productionTimeForOneCycle.label",
                locale) + ":",
                timeConverterService.convertTimeToString(
                        technologyOperationComponent.getIntegerField(TechnologyOperationComponentFieldsTNFO.TJ))
                        + " (g:m:s)");

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.laborUtilization.label",
                        locale) + ":",
                numberService.format(technologyOperationComponent
                        .getDecimalField(TechnologyOperationComponentFieldsTNFO.LABOR_UTILIZATION)));

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.additionalTime.label",
                        locale) + ":",
                timeConverterService
                        .convertTimeToString(technologyOperationComponent
                                .getIntegerField(TechnologyOperationComponentFieldsTNFO.TIME_NEXT_OPERATION))
                        + " (g:m:s)");

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.machineHourlyCost.label",
                        locale) + ":",
                numberService.format(technologyOperationComponent
                        .getDecimalField(TechnologyOperationComponentFieldsCNFO.MACHINE_HOURLY_COST)));

        addTableCellAsTwoColumnsTable(panelTableContent, "", "");

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.laborHourlyCost.label",
                        locale) + ":",
                numberService.format(technologyOperationComponent
                        .getDecimalField(TechnologyOperationComponentFieldsCNFO.LABOR_HOURLY_COST)));

        document.add(panelTableHeader);
        document.add(panelTableContent);
    }
}

From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java

License:Open Source License

private void createHeaderTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    PdfPTable dynaminHeaderTable = pdfHelper.createPanelTable(3);

    dynaminHeaderTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);

    PdfPTable firstColumnHeaderTable = new PdfPTable(1);
    PdfPTable secondColumnHeaderTable = new PdfPTable(1);
    PdfPTable thirdColumnHeaderTable = new PdfPTable(1);

    setSimpleFormat(firstColumnHeaderTable);
    setSimpleFormat(secondColumnHeaderTable);
    setSimpleFormat(thirdColumnHeaderTable);

    dynaminHeaderTable.setSpacingBefore(7);

    Map<String, Object> firstColumn = createFirstColumn(delivery);
    Map<String, Object> secondColumn = createSecondColumn(delivery);
    Map<String, Object> thirdColumn = createThirdColumn(delivery, locale);

    int maxSize = pdfHelper.getMaxSizeOfColumnsRows(Lists.newArrayList(
            Integer.valueOf(firstColumn.values().size()), Integer.valueOf(secondColumn.values().size()),
            Integer.valueOf(thirdColumn.values().size())));

    for (int i = 0; i < maxSize; i++) {
        firstColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(firstColumnHeaderTable, firstColumn,
                locale);//from   w w w  . j a v  a2 s  . c om
        secondColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(secondColumnHeaderTable, secondColumn,
                locale);
        thirdColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(thirdColumnHeaderTable, thirdColumn,
                locale);
    }

    dynaminHeaderTable.addCell(firstColumnHeaderTable);
    dynaminHeaderTable.addCell(secondColumnHeaderTable);
    dynaminHeaderTable.addCell(thirdColumnHeaderTable);

    document.add(dynaminHeaderTable);
}

From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java

License:Open Source License

private void setSimpleFormat(final PdfPTable headerTable) {
    headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    headerTable.getDefaultCell().setPadding(6.0f);
    headerTable.getDefaultCell().setVerticalAlignment(PdfPCell.ALIGN_TOP);
}

From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java

License:Open Source License

private void createProductsTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    List<Entity> columnsForDeliveries = deliveriesService.getColumnsForDeliveries();

    if (!columnsForDeliveries.isEmpty()) {
        List<DeliveryProduct> deliveryProducts = deliveryColumnFetcher.getDeliveryProducts(delivery);

        Map<DeliveryProduct, Map<String, String>> deliveryProductsColumnValues = deliveryColumnFetcher
                .getDeliveryProductsColumnValues(deliveryProducts);

        List<Entity> filteredColumnsForDeliveries = getDeliveryReportColumns(columnsForDeliveries,
                deliveryProducts, deliveryProductsColumnValues);

        if (!filteredColumnsForDeliveries.isEmpty()) {
            List<String> columnsName = Lists.newArrayList();

            for (Entity entity : filteredColumnsForDeliveries) {
                columnsName.add(entity.getStringField(ColumnForDeliveriesFields.IDENTIFIER));
            }/*from  ww w .j av a 2  s  .  c  o  m*/

            Map<String, HeaderAlignment> alignments = prepareHeaderAlignment(filteredColumnsForDeliveries,
                    locale);
            PdfPTable productsTable = pdfHelper.createTableWithHeader(filteredColumnsForDeliveries.size(),
                    prepareProductsTableHeader(document, filteredColumnsForDeliveries, locale), false,
                    pdfHelper.getReportColumnWidths(REPORT_WIDTH, parameterService.getReportColumnWidths(),
                            columnsName),
                    alignments);

            for (DeliveryProduct deliveryProduct : deliveryProducts) {
                for (Entity columnForDeliveries : filteredColumnsForDeliveries) {
                    String identifier = columnForDeliveries
                            .getStringField(ColumnForDeliveriesFields.IDENTIFIER);
                    String alignment = columnForDeliveries.getStringField(ColumnForDeliveriesFields.ALIGNMENT);

                    String value = deliveryProductsColumnValues.get(deliveryProduct).get(identifier);

                    prepareProductColumnAlignment(productsTable.getDefaultCell(),
                            ColumnAlignment.parseString(alignment));

                    productsTable.addCell(new Phrase(value, FontUtils.getDejavuRegular7Dark()));
                }
            }

            addTotalRow(productsTable, locale, columnsName, delivery);

            document.add(productsTable);
            document.add(Chunk.NEWLINE);
        }
    }
}

From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java

License:Open Source License

private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName,
        Entity delivery) {// w  w  w  .  j  av a  2 s .c o m
    DeliveryPricesAndQuantities deliveryPricesAndQuantities = new DeliveryPricesAndQuantities(delivery,
            numberService);

    PdfPCell total = new PdfPCell(
            new Phrase(translationService.translate("deliveries.delivery.report.totalCost", locale),
                    FontUtils.getDejavuRegular7Dark()));

    total.setColspan(2);
    total.setHorizontalAlignment(Element.ALIGN_LEFT);
    total.setVerticalAlignment(Element.ALIGN_MIDDLE);
    total.setBackgroundColor(null);
    total.disableBorderSide(Rectangle.RIGHT);
    total.disableBorderSide(Rectangle.LEFT);
    total.setBorderColor(ColorUtils.getLineLightColor());

    productsTable.addCell(total);

    for (int i = 2; i < columnsName.size(); i++) {
        if (columnsName.contains(OrderedProductFields.ORDERED_QUANTITY)
                && columnsName.indexOf(OrderedProductFields.ORDERED_QUANTITY) == i) {
            productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            productsTable.addCell(
                    new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedCumulatedQuantity()),
                            FontUtils.getDejavuRegular7Dark()));
        } else if (columnsName.contains(DeliveredProductFields.DELIVERED_QUANTITY)
                && columnsName.indexOf(DeliveredProductFields.DELIVERED_QUANTITY) == i) {
            productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            productsTable.addCell(new Phrase(
                    numberService.format(deliveryPricesAndQuantities.getDeliveredCumulatedQuantity()),
                    FontUtils.getDejavuRegular7Dark()));
        } else if (columnsName.contains(DeliveredProductFields.TOTAL_PRICE)
                && columnsName.indexOf(DeliveredProductFields.TOTAL_PRICE) == i) {
            productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            productsTable.addCell(
                    new Phrase(numberService.format(deliveryPricesAndQuantities.getDeliveredTotalPrice()),
                            FontUtils.getDejavuRegular7Dark()));
        } else if (columnsName.contains(L_CURRENCY) && columnsName.indexOf(L_CURRENCY) == i) {
            productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            productsTable.addCell(
                    new Phrase(deliveriesService.getCurrency(delivery), FontUtils.getDejavuRegular7Dark()));
        } else {
            productsTable.addCell("");
        }
    }
}

From source file:com.qcadoo.mes.deliveries.print.OrderReportPdf.java

License:Open Source License

private void createHeaderTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    PdfPTable dynaminHeaderTable = pdfHelper.createPanelTable(3);
    dynaminHeaderTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);

    PdfPTable firstColumnHeaderTable = new PdfPTable(1);
    PdfPTable secondColumnHeaderTable = new PdfPTable(1);
    PdfPTable thirdColumnHeaderTable = new PdfPTable(1);

    setSimpleFormat(firstColumnHeaderTable);
    setSimpleFormat(secondColumnHeaderTable);
    setSimpleFormat(thirdColumnHeaderTable);

    dynaminHeaderTable.setSpacingBefore(7);

    Map<String, Object> firstColumn = createFirstColumn(delivery);
    Map<String, Object> secondColumn = createSecondColumn(delivery);
    Map<String, Object> thirdColumn = createThirdColumn(delivery);

    int maxSize = pdfHelper.getMaxSizeOfColumnsRows(Lists.newArrayList(
            Integer.valueOf(firstColumn.values().size()), Integer.valueOf(secondColumn.values().size()),
            Integer.valueOf(thirdColumn.values().size())));

    for (int i = 0; i < maxSize; i++) {
        firstColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(firstColumnHeaderTable, firstColumn,
                locale);/*from www. j  a  v  a 2s. co  m*/
        secondColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(secondColumnHeaderTable, secondColumn,
                locale);
        thirdColumnHeaderTable = pdfHelper.addDynamicHeaderTableCell(thirdColumnHeaderTable, thirdColumn,
                locale);
    }

    dynaminHeaderTable.addCell(firstColumnHeaderTable);
    dynaminHeaderTable.addCell(secondColumnHeaderTable);
    dynaminHeaderTable.addCell(thirdColumnHeaderTable);

    document.add(dynaminHeaderTable);
    document.add(Chunk.NEWLINE);
}

From source file:com.qcadoo.mes.deliveries.print.OrderReportPdf.java

License:Open Source License

private void createProductsTable(final Document document, final Entity delivery, final Locale locale)
        throws DocumentException {
    List<Entity> columnsForOrders = deliveriesService.getColumnsForOrders();

    if (!columnsForOrders.isEmpty()) {
        List<Entity> orderedProducts = delivery.getHasManyField(DeliveryFields.ORDERED_PRODUCTS);

        Map<Entity, Map<String, String>> orderedProductsColumnValues = orderColumnFetcher
                .getOrderedProductsColumnValues(orderedProducts);

        List<Entity> filteredColumnsForOrders = getOrderReportColumns(columnsForOrders, orderedProducts,
                orderedProductsColumnValues);

        if (!filteredColumnsForOrders.isEmpty()) {
            List<String> columnsName = Lists.newArrayList();

            for (Entity entity : filteredColumnsForOrders) {
                columnsName.add(entity.getStringField(ColumnForOrdersFields.IDENTIFIER));
            }/*ww w  .  java  2s .com*/

            Map<String, HeaderAlignment> alignments = prepareHeaderAlignment(filteredColumnsForOrders, locale);
            PdfPTable productsTable = pdfHelper.createTableWithHeader(filteredColumnsForOrders.size(),
                    prepareProductsTableHeader(document, filteredColumnsForOrders, locale), false,
                    pdfHelper.getReportColumnWidths(REPORT_WIDTH, parameterService.getReportColumnWidths(),
                            columnsName),
                    alignments);

            for (Entity orderedProduct : orderedProducts) {
                for (Entity columnForOrders : filteredColumnsForOrders) {
                    String identifier = columnForOrders.getStringField(ColumnForOrdersFields.IDENTIFIER);
                    String alignment = columnForOrders.getStringField(ColumnForOrdersFields.ALIGNMENT);

                    String value = orderedProductsColumnValues.get(orderedProduct).get(identifier);

                    prepareProductColumnAlignment(productsTable.getDefaultCell(),
                            ColumnAlignment.parseString(alignment));

                    productsTable.addCell(new Phrase(value, FontUtils.getDejavuRegular7Dark()));
                }
            }

            addTotalRow(productsTable, locale, columnsName, delivery);

            document.add(productsTable);
            // document.add(Chunk.NEWLINE);
        }
    }
}