Search in sources :

Example 1 with PositionsHolder

use of com.qcadoo.mes.materialFlowResources.print.helper.PositionsHolder in project mes by qcadoo.

the class DispositionOrderPdfService method addPositionsTable.

private void addPositionsTable(Document document, Entity documentEntity, Locale locale) throws DocumentException {
    List<Integer> headerWidthsList = new ArrayList<>(Arrays.asList(25, 50, 50, 50, 65, 90, 40, 35));
    int numOfColumns = 8;
    if (acceptanceOfDocumentBeforePrinting) {
        headerWidthsList.add(45);
        numOfColumns++;
    }
    int[] headerWidths = headerWidthsList.stream().mapToInt(i -> i).toArray();
    Map<String, HeaderAlignment> headerValues = getPositionsTableHeaderLabels(locale);
    PdfPTable positionsTable = pdfHelper.createTableWithHeader(numOfColumns, Lists.newArrayList(headerValues.keySet()), false, headerWidths, headerValues);
    positionsTable.getDefaultCell().disableBorderSide(PdfPCell.RIGHT);
    positionsTable.getDefaultCell().disableBorderSide(PdfPCell.LEFT);
    positionsTable.setHeaderRows(1);
    List<Entity> positions = PositionDataProvider.getPositions(documentEntity);
    PositionsHolder positionsHolder = new PositionsHolder(numberService);
    fillPositions(positionsHolder, positions);
    List<Position> _positions = positionsHolder.getPositions();
    if (acceptanceOfDocumentBeforePrinting) {
        Collections.sort(_positions, new Comparator<Position>() {

            @Override
            public int compare(Position p1, Position p2) {
                return ComparisonChain.start().compare(p1.getTargetPallet(), p2.getTargetPallet()).compare(p1.getStorageLocation(), p2.getStorageLocation()).result();
            }
        });
    } else {
        Collections.sort(_positions, new Comparator<Position>() {

            @Override
            public int compare(Position p1, Position p2) {
                return ComparisonChain.start().compare(p1.getStorageLocation(), p2.getStorageLocation()).result();
            }
        });
    }
    Integer index = 1;
    for (Position position : _positions) {
        positionsTable.addCell(createCell(index.toString(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getStorageLocation(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getPalletNumber(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getTypeOfPallet(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getAdditionalCodeAndBatch(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getProductName(), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(PositionDataProvider.quantity(position.getQuantity()), Element.ALIGN_LEFT));
        positionsTable.addCell(createCell(position.getUnit(), Element.ALIGN_LEFT));
        if (acceptanceOfDocumentBeforePrinting) {
            positionsTable.addCell(createCell(position.getTargetPallet(), Element.ALIGN_LEFT));
        }
        index++;
    }
    positionsTable.setSpacingAfter(20);
    document.add(positionsTable);
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) Position(com.qcadoo.mes.materialFlowResources.print.helper.Position) Element(com.lowagie.text.Element) ColorUtils(com.qcadoo.report.api.ColorUtils) Locale(java.util.Locale) Map(java.util.Map) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) PdfPageEventHelper(com.lowagie.text.pdf.PdfPageEventHelper) PositionDataProvider(com.qcadoo.mes.materialFlowResources.print.helper.PositionDataProvider) FontUtils(com.qcadoo.report.api.FontUtils) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) ComparisonChain(com.google.common.collect.ComparisonChain) DataDefinition(com.qcadoo.model.api.DataDefinition) Objects(java.util.Objects) DocumentFields(com.qcadoo.mes.materialFlowResources.constants.DocumentFields) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Rectangle(com.lowagie.text.Rectangle) ParameterService(com.qcadoo.mes.basic.ParameterService) PositionsHolder(com.qcadoo.mes.materialFlowResources.print.helper.PositionsHolder) ResourceFields(com.qcadoo.mes.materialFlowResources.constants.ResourceFields) PdfWriter(com.lowagie.text.pdf.PdfWriter) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment) PositionBuilder(com.qcadoo.mes.materialFlowResources.print.helper.PositionBuilder) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) PdfDocumentWithWriterService(com.qcadoo.report.api.pdf.PdfDocumentWithWriterService) PalletNumberFields(com.qcadoo.mes.basic.constants.PalletNumberFields) PdfPTable(com.lowagie.text.pdf.PdfPTable) ArrayList(java.util.ArrayList) MaterialFlowResourcesConstants(com.qcadoo.mes.materialFlowResources.constants.MaterialFlowResourcesConstants) Lists(com.google.common.collect.Lists) Chunk(com.lowagie.text.Chunk) SearchCriterion(com.qcadoo.model.api.search.SearchCriterion) Phrase(com.lowagie.text.Phrase) DocumentDataProvider(com.qcadoo.mes.materialFlowResources.print.helper.DocumentDataProvider) PdfHelper(com.qcadoo.report.api.pdf.PdfHelper) Service(org.springframework.stereotype.Service) BatchFields(com.qcadoo.mes.advancedGenealogy.constants.BatchFields) PositionFields(com.qcadoo.mes.materialFlowResources.constants.PositionFields) Paragraph(com.lowagie.text.Paragraph) DocumentException(com.lowagie.text.DocumentException) TranslationService(com.qcadoo.localization.api.TranslationService) Maps(com.google.common.collect.Maps) Document(com.lowagie.text.Document) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) StorageLocationFields(com.qcadoo.mes.materialFlowResources.constants.StorageLocationFields) HeaderPair(com.qcadoo.mes.materialFlowResources.print.helper.DocumentPdfHelper.HeaderPair) PdfPCell(com.lowagie.text.pdf.PdfPCell) Comparator(java.util.Comparator) Collections(java.util.Collections) Entity(com.qcadoo.model.api.Entity) Position(com.qcadoo.mes.materialFlowResources.print.helper.Position) ArrayList(java.util.ArrayList) PositionsHolder(com.qcadoo.mes.materialFlowResources.print.helper.PositionsHolder) PdfPTable(com.lowagie.text.pdf.PdfPTable) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment)

Aggregations

ComparisonChain (com.google.common.collect.ComparisonChain)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Chunk (com.lowagie.text.Chunk)1 Document (com.lowagie.text.Document)1 DocumentException (com.lowagie.text.DocumentException)1 Element (com.lowagie.text.Element)1 Paragraph (com.lowagie.text.Paragraph)1 Phrase (com.lowagie.text.Phrase)1 Rectangle (com.lowagie.text.Rectangle)1 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)1 PdfPCell (com.lowagie.text.pdf.PdfPCell)1 PdfPTable (com.lowagie.text.pdf.PdfPTable)1 PdfPageEventHelper (com.lowagie.text.pdf.PdfPageEventHelper)1 PdfWriter (com.lowagie.text.pdf.PdfWriter)1 TranslationService (com.qcadoo.localization.api.TranslationService)1 BatchFields (com.qcadoo.mes.advancedGenealogy.constants.BatchFields)1 ParameterService (com.qcadoo.mes.basic.ParameterService)1 PalletNumberFields (com.qcadoo.mes.basic.constants.PalletNumberFields)1 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)1