Search in sources :

Example 1 with MrpAlgorithm

use of com.qcadoo.mes.technologies.constants.MrpAlgorithm in project mes by qcadoo.

the class MaterialRequirementPdfService method addDataSeries.

private void addDataSeries(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 = basicProductionCountingService.getNeededProductQuantities(orders, algorithm);
    List<String> headers = Lists.newLinkedList(headersWithAlignments.keySet());
    PdfPTable table = pdfHelper.createTableWithHeader(headersWithAlignments.size(), headers, true, defaultOrderHeaderColumnWidth, headersWithAlignments);
    List<Entity> products = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).find().add(SearchRestrictions.in("id", neededProductQuantities.keySet())).list().getEntities();
    products.sort(Comparator.comparing(p -> p.getStringField(ProductFields.NUMBER)));
    for (Entity product : products) {
        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(neededProductQuantities.get(product.getId())), FontUtils.getDejavuBold7Dark()));
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        String unit = product.getStringField(ProductFields.UNIT);
        if (Objects.isNull(unit)) {
            table.addCell(new Phrase("", FontUtils.getDejavuRegular7Dark()));
        } else {
            table.addCell(new Phrase(unit, FontUtils.getDejavuRegular7Dark()));
        }
    }
    document.add(table);
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) StringUtils(org.apache.commons.lang3.StringUtils) PdfPTable(com.lowagie.text.pdf.PdfPTable) DateUtils(com.qcadoo.localization.api.utils.DateUtils) PdfDocumentService(com.qcadoo.report.api.pdf.PdfDocumentService) BigDecimal(java.math.BigDecimal) Element(com.lowagie.text.Element) Lists(com.google.common.collect.Lists) Phrase(com.lowagie.text.Phrase) MrpAlgorithm(com.qcadoo.mes.technologies.constants.MrpAlgorithm) PdfHelper(com.qcadoo.report.api.pdf.PdfHelper) Locale(java.util.Locale) Service(org.springframework.stereotype.Service) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Map(java.util.Map) BasicProductionCountingService(com.qcadoo.mes.basicProductionCounting.BasicProductionCountingService) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) FontUtils(com.qcadoo.report.api.FontUtils) Paragraph(com.lowagie.text.Paragraph) WarehouseDateKey(com.qcadoo.mes.materialRequirements.print.WarehouseDateKey) DocumentException(com.lowagie.text.DocumentException) TranslationService(com.qcadoo.localization.api.TranslationService) Maps(com.google.common.collect.Maps) Document(com.lowagie.text.Document) Objects(java.util.Objects) List(java.util.List) Entity(com.qcadoo.model.api.Entity) MaterialRequirementFields(com.qcadoo.mes.materialRequirements.constants.MaterialRequirementFields) MaterialRequirementEntry(com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) PdfCell(com.lowagie.text.pdf.PdfCell) MaterialRequirementDataService(com.qcadoo.mes.materialRequirements.print.MaterialRequirementDataService) Comparator(java.util.Comparator) Collections(java.util.Collections) EntityOrderNumberComparator(com.qcadoo.mes.materialRequirements.util.EntityOrderNumberComparator) HeaderAlignment(com.qcadoo.report.api.pdf.HeaderAlignment) Entity(com.qcadoo.model.api.Entity) PdfPTable(com.lowagie.text.pdf.PdfPTable) Phrase(com.lowagie.text.Phrase) MrpAlgorithm(com.qcadoo.mes.technologies.constants.MrpAlgorithm) BigDecimal(java.math.BigDecimal)

Example 2 with MrpAlgorithm

use of com.qcadoo.mes.technologies.constants.MrpAlgorithm in project mes by qcadoo.

the class MaterialRequirementXlsService method addSimpleSeries.

private void addSimpleSeries(final HSSFSheet sheet, final Entity materialRequirement) {
    int rowNum = 1;
    List<Entity> orders = materialRequirement.getManyToManyField(MaterialRequirementFields.ORDERS);
    MrpAlgorithm algorithm = MrpAlgorithm.parseString(materialRequirement.getStringField(MaterialRequirementFields.MRP_ALGORITHM));
    Map<Long, BigDecimal> neededProductQuantities = basicProductionCountingService.getNeededProductQuantities(orders, algorithm);
    List<Entity> products = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).find().add(SearchRestrictions.in("id", neededProductQuantities.keySet())).list().getEntities();
    products.sort(Comparator.comparing(p -> p.getStringField(ProductFields.NUMBER)));
    for (Entity product : products) {
        HSSFRow row = sheet.createRow(rowNum++);
        row.createCell(0).setCellValue(product.getStringField(ProductFields.NUMBER));
        row.createCell(1).setCellValue(product.getStringField(ProductFields.NAME));
        row.createCell(2).setCellValue(numberService.setScaleWithDefaultMathContext(neededProductQuantities.get(product.getId())).doubleValue());
        String unit = product.getStringField(ProductFields.UNIT);
        if (Objects.isNull(unit)) {
            row.createCell(3).setCellValue("");
        } else {
            row.createCell(3).setCellValue(unit);
        }
    }
    sheet.autoSizeColumn((short) 0);
    sheet.autoSizeColumn((short) 1);
    sheet.autoSizeColumn((short) 2);
    sheet.autoSizeColumn((short) 3);
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Date(java.util.Date) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Autowired(org.springframework.beans.factory.annotation.Autowired) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) DateUtils(com.qcadoo.localization.api.utils.DateUtils) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) XlsDocumentService(com.qcadoo.report.api.xls.XlsDocumentService) MrpAlgorithm(com.qcadoo.mes.technologies.constants.MrpAlgorithm) Locale(java.util.Locale) Service(org.springframework.stereotype.Service) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Map(java.util.Map) BasicProductionCountingService(com.qcadoo.mes.basicProductionCounting.BasicProductionCountingService) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) WarehouseDateKey(com.qcadoo.mes.materialRequirements.print.WarehouseDateKey) TranslationService(com.qcadoo.localization.api.TranslationService) XlsHelper(com.qcadoo.report.api.xls.XlsHelper) Maps(com.google.common.collect.Maps) Objects(java.util.Objects) List(java.util.List) Entity(com.qcadoo.model.api.Entity) MaterialRequirementFields(com.qcadoo.mes.materialRequirements.constants.MaterialRequirementFields) MaterialRequirementEntry(com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry) NumberService(com.qcadoo.model.api.NumberService) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) MaterialRequirementDataService(com.qcadoo.mes.materialRequirements.print.MaterialRequirementDataService) Comparator(java.util.Comparator) Entity(com.qcadoo.model.api.Entity) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) MrpAlgorithm(com.qcadoo.mes.technologies.constants.MrpAlgorithm) BigDecimal(java.math.BigDecimal)

Aggregations

Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 TranslationService (com.qcadoo.localization.api.TranslationService)2 DateUtils (com.qcadoo.localization.api.utils.DateUtils)2 BasicConstants (com.qcadoo.mes.basic.constants.BasicConstants)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 BasicProductionCountingService (com.qcadoo.mes.basicProductionCounting.BasicProductionCountingService)2 MaterialFlowResourcesService (com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService)2 MaterialRequirementFields (com.qcadoo.mes.materialRequirements.constants.MaterialRequirementFields)2 MaterialRequirementDataService (com.qcadoo.mes.materialRequirements.print.MaterialRequirementDataService)2 MaterialRequirementEntry (com.qcadoo.mes.materialRequirements.print.MaterialRequirementEntry)2 WarehouseDateKey (com.qcadoo.mes.materialRequirements.print.WarehouseDateKey)2 MrpAlgorithm (com.qcadoo.mes.technologies.constants.MrpAlgorithm)2 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)2 Entity (com.qcadoo.model.api.Entity)2 NumberService (com.qcadoo.model.api.NumberService)2 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)2 BigDecimal (java.math.BigDecimal)2 Comparator (java.util.Comparator)2 Date (java.util.Date)2