Search in sources :

Example 26 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class WorkPlansColumnFiller method fillProductNames.

private void fillProductNames(final Entity technology, final Map<Entity, Map<String, String>> valuesMap) {
    EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    for (Entity operationComponent : operationComponents) {
        EntityList operationProductInComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
        EntityList operationProductOutComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
        for (Entity operationProductInComponent : operationProductInComponents) {
            initMap(valuesMap, operationProductInComponent);
            valuesMap.get(operationProductInComponent).put(L_PRODUCT_NAME, getProductNameAndNumber(operationProductInComponent));
        }
        for (Entity operationProductOutComponent : operationProductOutComponents) {
            initMap(valuesMap, operationProductOutComponent);
            valuesMap.get(operationProductOutComponent).put(L_PRODUCT_NAME, getProductNameAndNumber(operationProductOutComponent));
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) EntityTree(com.qcadoo.model.api.EntityTree)

Example 27 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class WorkPlansColumnFiller method fillPlannedQuantities.

private void fillPlannedQuantities(final Entity technology, final OperationProductComponentWithQuantityContainer productQuantities, final Map<Entity, Map<String, String>> valuesMap) {
    EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
    for (Entity operationComponent : operationComponents) {
        EntityList operationProductInComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS);
        EntityList operationProductOutComponents = operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS);
        for (Entity operationProductInComponent : operationProductInComponents) {
            initMap(valuesMap, operationProductInComponent);
            valuesMap.get(operationProductInComponent).put(L_PLANNED_QUANTITY, getProductQuantityAndUnit(operationProductInComponent, productQuantities));
        }
        for (Entity operationProductOutComponent : operationProductOutComponents) {
            initMap(valuesMap, operationProductOutComponent);
            valuesMap.get(operationProductOutComponent).put(L_PLANNED_QUANTITY, getProductQuantityAndUnit(operationProductOutComponent, productQuantities));
        }
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) EntityTree(com.qcadoo.model.api.EntityTree)

Example 28 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class CostCalculationComponentsService method getComponentCosts.

public Collection<ComponentsCalculationHolder> getComponentCosts(final Entity costCalculation, final Entity technology, List<Entity> calculationOperationComponents) {
    EntityTree operationComponents = productStructureTreeService.getOperationComponentsFromTechnology(technology);
    List<ComponentsCalculationHolder> components = operationComponents.stream().filter(pc -> ProductStructureTreeService.L_COMPONENT.equals(pc.getStringField(TechnologyOperationComponentFields.TYPE_FROM_STRUCTURE_TREE))).map(toc -> new ComponentsCalculationHolder(toc, toc.getBelongsToField(TechnologyOperationComponentFields.PRODUCT_FROM_STRUCTURE_TREE), technology)).collect(Collectors.toList());
    List<ComponentsCalculationHolder> allOperationComponents = operationComponents.stream().map(toc -> new ComponentsCalculationHolder(toc, toc.getBelongsToField(TechnologyOperationComponentFields.PRODUCT_FROM_STRUCTURE_TREE), technology)).collect(Collectors.toList());
    BigDecimal quantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY);
    addMaterialCost(costCalculation, allOperationComponents, technology, quantity);
    addLaborCost(costCalculation, allOperationComponents, calculationOperationComponents);
    fillComponentsQuantity(components, technology, quantity);
    fillComponentsCosts(operationComponents, components, allOperationComponents, quantity);
    return groupComponentCosts(components);
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) HashMap(java.util.HashMap) ProductStructureTreeService(com.qcadoo.mes.technologies.tree.ProductStructureTreeService) ProductQuantitiesWithComponentsService(com.qcadoo.mes.technologies.ProductQuantitiesWithComponentsService) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) LinkedHashMap(java.util.LinkedHashMap) CostCalculationFields(com.qcadoo.mes.costCalculation.constants.CostCalculationFields) BigDecimal(java.math.BigDecimal) MrpAlgorithm(com.qcadoo.mes.technologies.constants.MrpAlgorithm) Service(org.springframework.stereotype.Service) Map(java.util.Map) ComponentCostKey(com.qcadoo.mes.costCalculation.print.dto.ComponentCostKey) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) OperationProductInComponentFields(com.qcadoo.mes.technologies.constants.OperationProductInComponentFields) MathContext(java.math.MathContext) Collection(java.util.Collection) CalculationOperationComponentFields(com.qcadoo.mes.costNormsForOperation.constants.CalculationOperationComponentFields) SourceOfOperationCosts(com.qcadoo.mes.costCalculation.constants.SourceOfOperationCosts) OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ProductBySizeGroupFields(com.qcadoo.mes.technologies.constants.ProductBySizeGroupFields) Entity(com.qcadoo.model.api.Entity) List(java.util.List) TechnologyInputProductTypeFields(com.qcadoo.mes.technologies.constants.TechnologyInputProductTypeFields) NumberService(com.qcadoo.model.api.NumberService) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) EntityTree(com.qcadoo.model.api.EntityTree) BigDecimal(java.math.BigDecimal)

Example 29 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class ProductionCountingQuantitySetService method fillSetField.

public Entity fillSetField(final Entity productionCountingQuantity) {
    String typeOfMaterial = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL);
    String role = productionCountingQuantity.getStringField(ProductionCountingQuantityFields.ROLE);
    if (GlobalTypeOfMaterial.COMPONENT.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.USED.getStringValue().equals(role)) {
        Entity product = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.PRODUCT);
        if (product != null) {
            Entity technology = getTechnologyDD().find().add(SearchRestrictions.eq(TechnologyFields.MASTER, true)).add(SearchRestrictions.belongsTo(TechnologyFields.PRODUCT, product)).uniqueResult();
            if (technology != null) {
                EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
                Entity operationProductOutComponent = operationComponents.getRoot().getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0);
                boolean isSet = operationProductOutComponent.getBooleanField("set");
                if (isSet) {
                    productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue());
                }
            }
        }
    } else if (GlobalTypeOfMaterial.FINAL_PRODUCT.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.PRODUCED.getStringValue().equals(role)) {
        Entity order = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ORDER);
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
        EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
        Entity operationProductOutComponent = operationComponents.getRoot().getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS).get(0);
        boolean isSet = operationProductOutComponent.getBooleanField("set");
        if (isSet) {
            productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue());
            SearchCriteriaBuilder findProductionCountingQuantity = productionCountingQuantity.getDataDefinition().find();
            List<Entity> entities = findProductionCountingQuantity.add(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order)).list().getEntities();
            markIntermediateInProductionCountingQuantities(entities, true);
        }
    } else if (GlobalTypeOfMaterial.INTERMEDIATE.getStringValue().equals(typeOfMaterial) && ProductionCountingQuantityRole.USED.getStringValue().equals(role)) {
        Entity order = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.ORDER);
        SearchCriteriaBuilder findProductionCountingQuantity = productionCountingQuantity.getDataDefinition().find();
        List<Entity> entities = findProductionCountingQuantity.add(SearchRestrictions.and(SearchRestrictions.belongsTo(ProductionCountingQuantityFields.ORDER, order), SearchRestrictions.eq(ProductionCountingQuantityFields.TYPE_OF_MATERIAL, GlobalTypeOfMaterial.FINAL_PRODUCT.getStringValue()), SearchRestrictions.eq(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.SET.getStringValue()))).list().getEntities();
        Entity technologyOperationComponent = productionCountingQuantity.getBelongsToField(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT);
        if (technologyOperationComponent != null) {
            Entity operation = technologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
            long count = entities.stream().filter(entity -> {
                Entity entityTechnologyOperationComponent = entity.getBelongsToField(ProductionCountingQuantityFields.TECHNOLOGY_OPERATION_COMPONENT);
                Entity entityOperation = entityTechnologyOperationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
                return "1.".equals(entityTechnologyOperationComponent.getStringField(TechnologyOperationComponentFields.NODE_NUMBER)) && operation.getId().equals(entityOperation.getId());
            }).count();
            if (count > 0) {
                productionCountingQuantity.setField(ProductionCountingQuantityFields.SET, ProductionCountingQuantitySet.INTERMEDIATE.getStringValue());
            }
        }
    }
    return productionCountingQuantity;
}
Also used : TechnologyFields(com.qcadoo.mes.technologies.constants.TechnologyFields) ProductionCountingQuantitySet(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantitySet) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Autowired(org.springframework.beans.factory.annotation.Autowired) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) ProductionCountingQuantityFields(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityFields) Entity(com.qcadoo.model.api.Entity) List(java.util.List) GlobalTypeOfMaterial(com.qcadoo.mes.basic.constants.GlobalTypeOfMaterial) ProductionCountingQuantityRole(com.qcadoo.mes.basicProductionCounting.constants.ProductionCountingQuantityRole) Service(org.springframework.stereotype.Service) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) Entity(com.qcadoo.model.api.Entity) SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) List(java.util.List) EntityTree(com.qcadoo.model.api.EntityTree)

Example 30 with EntityTree

use of com.qcadoo.model.api.EntityTree in project mes by qcadoo.

the class AdvancedGenealogyTreeViewListeners method generateFormEntity.

Entity generateFormEntity(final ViewDefinitionState view, final ComponentState state) {
    DataDefinition dd = dataDefinitionService.get(AdvancedGenealogyConstants.PLUGIN_IDENTIFIER, AdvancedGenealogyConstants.MODEL_BATCH);
    FormComponent form = getForm(view);
    Entity formEntity = form.getEntity();
    Long batchId = (Long) view.getComponentByReference("batchLookup").getFieldValue();
    if (batchId == null) {
        throw new FormValidationException("advancedGenealogy.genealogyTree.noBatchSelected");
    }
    Entity producedBatch = dd.get(batchId);
    String includeDraftString = (String) view.getComponentByReference("includeDrafts").getFieldValue();
    boolean includeDrafts = "1".equals(includeDraftString);
    List<Entity> tree;
    String treeType = (String) view.getComponentByReference("treeType").getFieldValue();
    if ("01producedFrom".equals(treeType)) {
        tree = advancedGenealogyTreeService.getProducedFromTree(producedBatch, includeDrafts, true);
    } else if ("02usedToProduce".equals(treeType)) {
        tree = advancedGenealogyTreeService.getUsedToProduceTree(producedBatch, includeDrafts, true);
    } else {
        throw new FormValidationException("advancedGenealogy.genealogyTree.noTreeTypeSelected");
    }
    EntityTree entityTree = EntityTreeUtilsService.getDetachedEntityTree(tree);
    formEntity.setField("producedBatch", dd.get(batchId));
    formEntity.setField("genealogyTree", entityTree);
    return formEntity;
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree)

Aggregations

EntityTree (com.qcadoo.model.api.EntityTree)52 Entity (com.qcadoo.model.api.Entity)44 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)10 FormComponent (com.qcadoo.view.api.components.FormComponent)10 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)7 EntityList (com.qcadoo.model.api.EntityList)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Service (org.springframework.stereotype.Service)6 EntityTreeNode (com.qcadoo.model.api.EntityTreeNode)5 WindowComponent (com.qcadoo.view.api.components.WindowComponent)4 Set (java.util.Set)4 Sets (com.google.common.collect.Sets)3 ProductQuantitiesService (com.qcadoo.mes.technologies.ProductQuantitiesService)3 Date (java.util.Date)3 Locale (java.util.Locale)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2