Example usage for com.lowagie.text Element ALIGN_RIGHT

List of usage examples for com.lowagie.text Element ALIGN_RIGHT

Introduction

In this page you can find the example usage for com.lowagie.text Element ALIGN_RIGHT.

Prototype

int ALIGN_RIGHT

To view the source code for com.lowagie.text Element ALIGN_RIGHT.

Click Source Link

Document

A possible value for paragraph alignment.

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));
    }//from  ww w  .  ja  v  a 2 s . c  om

    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));
    }//ww  w . j  a  v a  2  s  . 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));
    }/*from  ww w. j ava 2  s.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.deliveries.print.DeliveryReportPdf.java

License:Open Source License

private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName,
        Entity delivery) {/*from w  w  w.  jav  a 2  s .  com*/
    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.DeliveryReportPdf.java

License:Open Source License

private void prepareProductColumnAlignment(final PdfPCell cell, final ColumnAlignment columnAlignment) {
    if (ColumnAlignment.LEFT.equals(columnAlignment)) {
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    } else if (ColumnAlignment.RIGHT.equals(columnAlignment)) {
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    }/*from w w w . j a v  a  2  s  .c o m*/
}

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

License:Open Source License

private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName,
        Entity delivery) {//from w w  w  .  j a  va2s .com
    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(OrderedProductFields.TOTAL_PRICE)
                && columnsName.indexOf(OrderedProductFields.TOTAL_PRICE) == i) {
            productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            productsTable.addCell(
                    new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedTotalPrice()),
                            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.materialFlow.print.pdf.MaterialFlowPdfService.java

License:Open Source License

@Override
protected void buildPdfContent(final Document document, final Entity materialsInLocation, final Locale locale)
        throws DocumentException {
    Map<Entity, BigDecimal> reportData = materialFlowService
            .calculateMaterialQuantitiesInLocation(materialsInLocation);

    String documenTitle = translationService.translate("materialFlow.materialFlow.report.title", locale);
    String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale);
    pdfHelper.addDocumentHeader(document, "", documenTitle, documentAuthor,
            (Date) materialsInLocation.getField(TIME), materialsInLocation.getStringField(WORKER));

    PdfPTable panelTable = pdfHelper.createPanelTable(2);
    pdfHelper.addTableCellAsOneColumnTable(panelTable,
            translationService.translate("materialFlow.materialFlow.report.panel.materialFlowForDate", locale),
            ((Date) materialsInLocation.getField(MATERIAL_FLOW_FOR_DATE)).toString());
    pdfHelper.addTableCellAsOneColumnTable(panelTable,
            translationService.translate("materialFlow.materialFlow.report.panel.time", locale),
            ((Date) materialsInLocation.getField(TIME)).toString());

    List<Entity> materialsInLocationComponents = materialsInLocation
            .getHasManyField(MATERIALS_IN_LOCATION_COMPONENTS);
    List<String> names = new ArrayList<String>();
    for (Entity materialsInLocationComponent : materialsInLocationComponents) {
        Entity location = (Entity) materialsInLocationComponent.getField(LOCATION);
        names.add(location.getField(NUMBER).toString());
    }/* w w  w  .  j  a  va2  s  .co m*/
    pdfHelper.addTableCellAsOneColumnTable(panelTable,
            translationService.translate("materialFlow.materialFlow.report.panel.locations", locale), names);
    pdfHelper.addTableCellAsOneColumnTable(panelTable, "", "");

    panelTable.setSpacingBefore(20);
    panelTable.setSpacingAfter(20);
    document.add(panelTable);

    List<String> tableHeader = new ArrayList<String>();
    Map<String, HeaderAlignment> alignments = Maps.newHashMap();

    tableHeader
            .add(translationService.translate("materialFlow.materialFlow.report.columnHeader.number", locale));
    tableHeader.add(translationService.translate("materialFlow.materialFlow.report.columnHeader.name", locale));
    tableHeader.add(
            translationService.translate("materialFlow.materialFlow.report.columnHeader.quantity", locale));
    tableHeader.add(translationService.translate("materialFlow.materialFlow.report.columnHeader.unit", locale));

    alignments.put(translationService.translate("materialFlow.materialFlow.report.columnHeader.number", locale),
            HeaderAlignment.LEFT);
    alignments.put(translationService.translate("materialFlow.materialFlow.report.columnHeader.name", locale),
            HeaderAlignment.LEFT);
    alignments.put(
            translationService.translate("materialFlow.materialFlow.report.columnHeader.quantity", locale),
            HeaderAlignment.RIGHT);
    alignments.put(translationService.translate("materialFlow.materialFlow.report.columnHeader.unit", locale),
            HeaderAlignment.LEFT);

    PdfPTable table = pdfHelper.createTableWithHeader(4, tableHeader, false, alignments);

    for (Map.Entry<Entity, BigDecimal> data : reportData.entrySet()) {
        table.addCell(new Phrase(data.getKey().getStringField(NUMBER), FontUtils.getDejavuRegular7Dark()));
        table.addCell(new Phrase(data.getKey().getStringField(NAME), FontUtils.getDejavuRegular7Dark()));
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(new Phrase(numberService.format(data.getValue()), FontUtils.getDejavuRegular7Dark()));
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(new Phrase(data.getKey().getStringField(UNIT), FontUtils.getDejavuRegular7Dark()));
    }
    document.add(table);
}

From source file:com.qcadoo.mes.materialRequirements.print.pdf.MaterialRequirementPdfService.java

License:Open Source License

private void addTechnologySeries(final Document document, final Entity materialRequirement,
        final Map<String, HeaderAlignment> headersWithAlignments) throws DocumentException {
    List<Entity> orders = materialRequirement.getManyToManyField(MaterialRequirementFields.ORDERS);
    MrpAlgorithm algorithm = MrpAlgorithm
            .parseString(materialRequirement.getStringField(MaterialRequirementFields.MRP_ALGORITHM));

    Map<Long, BigDecimal> neededProductQuantities = productQuantitiesService.getNeededProductQuantities(orders,
            algorithm, true);//from  ww w. j  a  v  a  2 s  .  c  om

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

    List<String> headers = Lists.newLinkedList(headersWithAlignments.keySet());
    PdfPTable table = pdfHelper.createTableWithHeader(headersWithAlignments.size(), headers, true,
            defaultOrderHeaderColumnWidth, headersWithAlignments);

    for (Entry<Long, BigDecimal> neededProductQuantity : neededProductQuantities.entrySet()) {
        Entity product = productQuantitiesService.getProduct(neededProductQuantity.getKey());
        table.addCell(
                new Phrase(product.getStringField(ProductFields.NUMBER), FontUtils.getDejavuRegular7Dark()));
        table.addCell(
                new Phrase(product.getStringField(ProductFields.NAME), FontUtils.getDejavuRegular7Dark()));
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(new Phrase(numberService.format(neededProductQuantity.getValue()),
                FontUtils.getDejavuBold7Dark()));
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        String unit = product.getStringField(ProductFields.UNIT);
        if (unit == null) {
            table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
        } else {
            table.addCell(new Phrase(unit, FontUtils.getDejavuRegular7Dark()));
        }
    }
    document.add(table);
}

From source file:com.qcadoo.mes.materialRequirements.print.pdf.MaterialRequirementPdfService.java

License:Open Source License

private void addOrderSeries(final Document document, final Entity materialRequirement,
        final Map<String, HeaderAlignment> headersWithAlignments) throws DocumentException {
    List<Entity> orders = materialRequirement.getManyToManyField(MaterialRequirementFields.ORDERS);
    Collections.sort(orders, new EntityOrderNumberComparator());

    List<String> headers = Lists.newLinkedList(headersWithAlignments.keySet());
    PdfPTable table = pdfHelper.createTableWithHeader(headersWithAlignments.size(), headers, true,
            defaultMatReqHeaderColumnWidth, headersWithAlignments);

    for (Entity order : orders) {
        table.addCell(new Phrase(order.getStringField(OrderFields.NUMBER), FontUtils.getDejavuRegular7Dark()));
        table.addCell(new Phrase(order.getStringField(OrderFields.NAME), FontUtils.getDejavuRegular7Dark()));
        Entity product = (Entity) order.getField(OrderFields.PRODUCT);
        if (product == null) {
            table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
            BigDecimal plannedQuantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY);
            plannedQuantity = (plannedQuantity == null) ? BigDecimal.ZERO : plannedQuantity;
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(new Phrase(numberService.format(plannedQuantity), FontUtils.getDejavuRegular7Dark()));
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
        } else {//www . j  av  a 2  s .c o m
            table.addCell(
                    new Phrase(product.getStringField(ProductFields.NAME), FontUtils.getDejavuRegular7Dark()));
            BigDecimal plannedQuantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY);
            plannedQuantity = (plannedQuantity == null) ? BigDecimal.ZERO : plannedQuantity;
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(new Phrase(numberService.format(plannedQuantity), FontUtils.getDejavuRegular7Dark()));
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            String unit = product.getStringField(ProductFields.UNIT);
            if (unit == null) {
                table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
            } else {
                table.addCell(new Phrase(unit, FontUtils.getDejavuRegular7Dark()));
            }
        }

    }
    document.add(table);
}

From source file:com.qcadoo.mes.productionCountingWithCosts.pdf.ProductionBalanceWithCostsPdfService.java

License:Open Source License

private void addMaterialCost(final Document document, final Entity productionBalance, final Locale locale)
        throws DocumentException {
    List<String> materialCostTableHeader = Lists.newArrayList();

    materialCostTableHeader.add(translationService.translate(
            "productionCounting.productionBalanceDetails.window.materialCostsTab.technologyOperationProductInComponents.column.productNumber",
            locale));/*from   w ww  . j a va 2  s  .c o m*/
    materialCostTableHeader.add(translationService.translate(
            "productionCounting.productionBalanceDetails.window.materialCostsTab.technologyOperationProductInComponents.column.plannedCost",
            locale));
    materialCostTableHeader.add(translationService.translate(
            "productionCounting.productionBalanceDetails.window.materialCostsTab.technologyOperationProductInComponents.column.registeredCost",
            locale));
    materialCostTableHeader.add(translationService.translate(
            "productionCounting.productionBalanceDetails.window.materialCostsTab.technologyOperationProductInComponents.column.balance",
            locale));
    Map<String, HeaderAlignment> alignments = Maps.newHashMap();

    alignments.put(translationService.translate(
            "productionCounting.productionBalanceDetails.window.materialCostsTab.technologyInstOperProductInComps.column.productNumber",
            locale), HeaderAlignment.LEFT);
    alignments.put(translationService.translate(
            "productionCounting.productionBalanceDetails.window.materialCostsTab.technologyInstOperProductInComps.column.plannedCost",
            locale), HeaderAlignment.RIGHT);

    alignments.put(translationService.translate(
            "productionCounting.productionBalanceDetails.window.materialCostsTab.technologyInstOperProductInComps.column.registeredCost",
            locale), HeaderAlignment.RIGHT);

    alignments.put(translationService.translate(
            "productionCounting.productionBalanceDetails.window.materialCostsTab.technologyInstOperProductInComps.column.balance",
            locale), HeaderAlignment.RIGHT);

    List<Entity> technologyOperationProductInComponents = productionBalance
            .getHasManyField(ProductionBalanceFieldsPCWC.TECHNOLOGY_OPERATION_PRODUCT_IN_COMPONENTS);

    if (!technologyOperationProductInComponents.isEmpty()) {
        document.add(Chunk.NEWLINE);

        document.add(
                new Paragraph(
                        translationService.translate(
                                "productionCounting.productionBalance.report.table.materialCost", locale),
                        FontUtils.getDejavuBold11Dark()));

        technologyOperationProductInComponents = Lists.newLinkedList(technologyOperationProductInComponents);
        Collections.sort(technologyOperationProductInComponents, new EntityProductInOutComparator());

        PdfPTable productsTable = pdfHelper.createTableWithHeader(4, materialCostTableHeader, false,
                alignments);

        String currency = " " + currencyService.getCurrencyAlphabeticCode();

        for (Entity technologyOperationProductInComponent : technologyOperationProductInComponents) {
            productsTable.addCell(new Phrase(technologyOperationProductInComponent
                    .getBelongsToField(TechnologyOperationProductInCompFields.PRODUCT)
                    .getStringField(ProductFields.NUMBER), FontUtils.getDejavuRegular7Dark()));
            productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

            String plannedCost = numberService.format(technologyOperationProductInComponent
                    .getField(TechnologyOperationProductInCompFields.PLANNED_COST));
            productsTable.addCell(new Phrase((plannedCost == null) ? L_NULL_OBJECT : (plannedCost + currency),
                    FontUtils.getDejavuRegular7Dark()));
            String registeredCost = numberService.format(technologyOperationProductInComponent
                    .getField(TechnologyOperationProductInCompFields.REGISTERED_COST));
            productsTable
                    .addCell(new Phrase((registeredCost == null) ? L_NULL_OBJECT : (registeredCost + currency),
                            FontUtils.getDejavuRegular7Dark()));
            String balance = numberService.format(technologyOperationProductInComponent
                    .getField(TechnologyOperationProductInCompFields.BALANCE));
            productsTable.addCell(new Phrase((balance == null) ? L_NULL_OBJECT : (balance + currency),
                    FontUtils.getDejavuRegular7Dark()));
            productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

        }

        productsTable.addCell(new Phrase(
                translationService.translate("productionCounting.productionBalance.report.total", locale),
                FontUtils.getDejavuRegular7Dark()));
        String plannedComponentsCosts = numberService.format(
                productionBalance.getDecimalField(ProductionBalanceFieldsPCWC.PLANNED_COMPONENTS_COSTS));
        productsTable.addCell(new Phrase(
                (plannedComponentsCosts == null) ? L_NULL_OBJECT : (plannedComponentsCosts + currency),
                FontUtils.getDejavuRegular7Dark()));
        String componentsCosts = numberService
                .format(productionBalance.getDecimalField(ProductionBalanceFieldsPCWC.COMPONENTS_COSTS));
        productsTable
                .addCell(new Phrase((componentsCosts == null) ? L_NULL_OBJECT : (componentsCosts + currency),
                        FontUtils.getDejavuRegular7Dark()));
        String componentsCostsBalance = numberService.format(
                productionBalance.getDecimalField(ProductionBalanceFieldsPCWC.COMPONENTS_COSTS_BALANCE));
        productsTable.addCell(new Phrase(
                (componentsCostsBalance == null) ? L_NULL_OBJECT : (componentsCostsBalance + currency),
                FontUtils.getDejavuRegular7Dark()));
        productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

        document.add(productsTable);
    }
}