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));
}
}
}
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));
}
}
}
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);
}
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;
}
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;
}
Aggregations