Search in sources :

Example 21 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class ProductQuantitiesServiceImplBPCOverrideUtil method getProductComponentWithQuantities.

private OperationProductComponentWithQuantityContainer getProductComponentWithQuantities(final Entity order) {
    OperationProductComponentWithQuantityContainer productComponentWithQuantities = new OperationProductComponentWithQuantityContainer();
    List<Entity> productionCountingQuantities = dataDefinitionService.get(BasicProductionCountingConstants.PLUGIN_IDENTIFIER, BasicProductionCountingConstants.MODEL_PRODUCTION_COUNTING_QUANTITY).find().add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).list().getEntities();
    for (Entity productionCountingQuantity : productionCountingQuantities) {
        Entity technologyOperationComponent = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT);
        Entity product = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.PRODUCT);
        String role = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.ROLE);
        BigDecimal plannedQuantity = productionCountingQuantity.getDecimalField(ProductionCountingQuantityFields.PLANNED_QUANTITY);
        OperationProductComponentEntityType entityType = getEntityType(role);
        ProductMaterialType productMaterialType = ProductMaterialType.parseString(productionCountingQuantity.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL));
        Entity productInputType = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
        Entity attribute = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ATTRIBUTE);
        OperationProductComponentHolder operationProductComponentHolder = new OperationProductComponentHolder(product, technologyOperationComponent, productInputType, attribute, productionCountingQuantity, entityType, productMaterialType);
        productComponentWithQuantities.put(operationProductComponentHolder, plannedQuantity);
    }
    return productComponentWithQuantities;
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) ProductMaterialType(com.qcadoo.mes.technologies.dto.ProductMaterialType) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) OperationProductComponentEntityType(com.qcadoo.mes.technologies.dto.OperationProductComponentEntityType) BigDecimal(java.math.BigDecimal)

Example 22 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class ModelCardPdfService method getQuantitiesInStock.

private Map<Long, Map<Long, BigDecimal>> getQuantitiesInStock(Set<OperationProductComponentHolder> operationProductComponentHolders) {
    Map<Long, Entity> warehouses = com.google.common.collect.Maps.newHashMap();
    Map<Long, List<Entity>> warehouseProducts = com.google.common.collect.Maps.newHashMap();
    for (OperationProductComponentHolder operationProductComponentHolder : operationProductComponentHolders) {
        Entity product = operationProductComponentHolder.getProduct();
        Entity operationProductComponent = operationProductComponentHolder.getOperationProductComponent();
        Entity warehouse = operationProductComponent.getBelongsToField(OperationProductInComponentFieldsPFTD.COMPONENTS_LOCATION);
        if (!warehouses.containsKey(warehouse.getId())) {
            warehouses.put(warehouse.getId(), warehouse);
        }
        if (Objects.isNull(product)) {
            List<Entity> productBySizeGroups = getProductBySizeGroups(operationProductComponent.getId());
            for (Entity productBySizeGroup : productBySizeGroups) {
                Entity materialBySizeGroup = productBySizeGroup.getBelongsToField(ProductBySizeGroupFields.PRODUCT);
                addProductToWarehouse(warehouseProducts, warehouse, materialBySizeGroup);
            }
        } else {
            addProductToWarehouse(warehouseProducts, warehouse, product);
        }
    }
    Map<Long, Map<Long, BigDecimal>> quantitiesInStock = com.google.common.collect.Maps.newHashMap();
    for (Map.Entry<Long, List<Entity>> entry : warehouseProducts.entrySet()) {
        quantitiesInStock.put(entry.getKey(), materialFlowResourcesService.getQuantitiesForProductsAndLocation(entry.getValue(), warehouses.get(entry.getKey())));
    }
    return quantitiesInStock;
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Map(java.util.Map)

Example 23 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class ModelCardPdfService method buildPdfContent.

@Override
protected void buildPdfContent(Document document, Entity modelCard, Locale locale) throws DocumentException {
    String documentTitle = translationService.translate("productFlowThruDivision.modelCard.report.header", locale, modelCard.getStringField(ModelCardFields.NAME));
    String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale);
    pdfHelper.addDocumentHeader(document, StringUtils.EMPTY, documentTitle, documentAuthor, modelCard.getDateField(ModelCardFields.DATE));
    Entity parameter = parameterService.getParameter();
    Entity productAttribute = parameter.getBelongsToField(ParameterFieldsPFTD.PRODUCT_ATTRIBUTE);
    Entity materialAttribute = parameter.getBelongsToField(ParameterFieldsPFTD.MATERIAL_ATTRIBUTE);
    for (Entity modelCardProduct : modelCard.getHasManyField(ModelCardFields.MODEL_CARD_PRODUCTS)) {
        Entity product = modelCardProduct.getBelongsToField(ModelCardProductFields.PRODUCT);
        boolean forFamily = Objects.isNull(product.getBelongsToField(ProductFields.PARENT));
        Entity technology = modelCardProduct.getBelongsToField(ModelCardProductFields.TECHNOLOGY);
        BigDecimal quantity = modelCardProduct.getDecimalField(ModelCardProductFields.QUANTITY);
        Map<OperationProductComponentHolder, BigDecimal> neededQuantities = productQuantitiesService.getNeededProductQuantities(technology, product, quantity);
        Map<Long, Map<Long, BigDecimal>> quantitiesInStock = getQuantitiesInStock(neededQuantities.keySet());
        List<ModelCardMaterialEntry> entries = newArrayList();
        for (Map.Entry<OperationProductComponentHolder, BigDecimal> neededProductQuantity : neededQuantities.entrySet()) {
            mapToModelCardMaterialEntry(modelCard, quantitiesInStock, entries, neededProductQuantity, forFamily, quantity, locale);
        }
        List<ModelCardMaterialEntry> groupedEntries = groupMaterials(entries);
        regroupProductWithSizeGroup(groupedEntries);
        BigDecimal materialUnitCostsSum = getMaterialUnitCostsSum(groupedEntries);
        List<ModelCardMaterialEntry> sortedEntries = groupedEntries.stream().sorted(Comparator.comparing(ModelCardMaterialEntry::getNodeNumber, new NodeNumberComparator().reversed()).thenComparing(ModelCardMaterialEntry::getPriority).thenComparing(ModelCardMaterialEntry::getSizeGroupId, nullsFirst(naturalOrder()))).collect(Collectors.toList());
        addProductTable(document, modelCardProduct, productAttribute, materialUnitCostsSum, locale);
        addMaterialsTable(document, sortedEntries, materialAttribute, locale);
        document.newPage();
    }
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) BigDecimal(java.math.BigDecimal) Map(java.util.Map)

Example 24 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class ProductQuantitiesWithComponentsServiceImpl method addOPCQuantitiesToList.

public void addOPCQuantitiesToList(final Map.Entry<OperationProductComponentHolder, BigDecimal> productComponentWithQuantity, final Map<OperationProductComponentHolder, BigDecimal> productWithQuantities) {
    OperationProductComponentHolder operationProductComponentHolder = productComponentWithQuantity.getKey();
    BigDecimal quantity = productComponentWithQuantity.getValue();
    productWithQuantities.put(operationProductComponentHolder, quantity);
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) BigDecimal(java.math.BigDecimal)

Example 25 with OperationProductComponentHolder

use of com.qcadoo.mes.technologies.dto.OperationProductComponentHolder in project mes by qcadoo.

the class ProductQuantitiesServiceImpl method addProductQuantitiesToList.

@Override
public void addProductQuantitiesToList(final Entry<OperationProductComponentHolder, BigDecimal> productComponentWithQuantity, final Map<Long, BigDecimal> productWithQuantities) {
    OperationProductComponentHolder operationProductComponentHolder = productComponentWithQuantity.getKey();
    Entity product = operationProductComponentHolder.getProduct();
    if (product != null) {
        BigDecimal newQuantity = productComponentWithQuantity.getValue();
        BigDecimal oldQuantity = productWithQuantities.get(product.getId());
        if (Objects.nonNull(oldQuantity)) {
            newQuantity = newQuantity.add(oldQuantity);
        }
        productWithQuantities.put(product.getId(), newQuantity);
    }
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) BigDecimal(java.math.BigDecimal)

Aggregations

OperationProductComponentHolder (com.qcadoo.mes.technologies.dto.OperationProductComponentHolder)35 BigDecimal (java.math.BigDecimal)31 Entity (com.qcadoo.model.api.Entity)23 OperationProductComponentWithQuantityContainer (com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer)14 Map (java.util.Map)11 DataDefinition (com.qcadoo.model.api.DataDefinition)4 List (java.util.List)4 Lists (com.google.common.collect.Lists)3 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)2 OperationProductInComponentFields (com.qcadoo.mes.technologies.constants.OperationProductInComponentFields)2 ProductBySizeGroupFields (com.qcadoo.mes.technologies.constants.ProductBySizeGroupFields)2 TechnologiesConstants (com.qcadoo.mes.technologies.constants.TechnologiesConstants)2