use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class PlannedEventDetailsHooks method hideTabs.
private void hideTabs(final ViewDefinitionState view, final FieldsForType fieldsForType) {
List<String> hiddenTabs = fieldsForType.getHiddenTabs();
for (String tab : previouslyHiddenTabs) {
ComponentState tabComponent = view.getComponentByReference(tab);
if (tabComponent != null) {
tabComponent.setVisible(true);
}
}
for (String tab : hiddenTabs) {
ComponentState tabComponent = view.getComponentByReference(tab);
if (tabComponent != null) {
tabComponent.setVisible(false);
}
}
previouslyHiddenTabs = hiddenTabs;
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class TechnologiesListListenersCC method createCostCalculation.
public final void createCostCalculation(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
GridComponent grid = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
List<Entity> selectedEntities = grid.getSelectedEntities();
if (!selectedEntities.isEmpty()) {
DataDefinition technologyDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY);
List<Entity> technologies = selectedEntities.stream().map(e -> technologyDD.get(e.getId())).collect(Collectors.toList());
DataDefinition costCalculationDD = dataDefinitionService.get(CostCalculationConstants.PLUGIN_IDENTIFIER, CostCalculationConstants.MODEL_COST_CALCULATION);
Entity costCalculation = costCalculationDD.create();
costCalculation.setField(CostCalculationFields.TECHNOLOGIES, technologies);
costCalculation.setField(CostCalculationFields.QUANTITY, BigDecimal.ONE);
Entity parameter = parameterService.getParameter();
costCalculation.setField(CostCalculationFields.MATERIAL_COSTS_USED, parameter.getStringField(CostCalculationFields.MATERIAL_COSTS_USED) != null ? parameter.getStringField(CostCalculationFields.MATERIAL_COSTS_USED) : MaterialCostsUsed.NOMINAL.getStringValue());
costCalculation.setField(CostCalculationFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED, parameter.getBooleanField(CostCalculationFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED));
costCalculation.setField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS, parameter.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS) != null ? parameter.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS) : SourceOfOperationCosts.TECHNOLOGY_OPERATION.getStringValue());
costCalculation.setField(CostCalculationFields.STANDARD_LABOR_COST, parameter.getBelongsToField(CostCalculationFields.STANDARD_LABOR_COST));
costCalculation.setField(CostCalculationFields.AVERAGE_MACHINE_HOURLY_COST, parameter.getDecimalField(CostCalculationFields.AVERAGE_MACHINE_HOURLY_COST));
costCalculation.setField(CostCalculationFields.AVERAGE_LABOR_HOURLY_COST, parameter.getDecimalField(CostCalculationFields.AVERAGE_LABOR_HOURLY_COST));
costCalculation.setField(CostCalculationFields.INCLUDE_TPZ, parameter.getBooleanField(CostCalculationFields.INCLUDE_TPZ));
costCalculation.setField(CostCalculationFields.INCLUDE_ADDITIONAL_TIME, parameter.getBooleanField(CostCalculationFields.INCLUDE_ADDITIONAL_TIME));
costCalculation.setField(CostCalculationFields.MATERIAL_COST_MARGIN, parameter.getDecimalField(CostCalculationFields.MATERIAL_COST_MARGIN));
costCalculation.setField(CostCalculationFields.PRODUCTION_COST_MARGIN, parameter.getDecimalField(CostCalculationFields.PRODUCTION_COST_MARGIN));
costCalculation.setField(CostCalculationFields.ADDITIONAL_OVERHEAD, parameter.getDecimalField(CostCalculationFields.ADDITIONAL_OVERHEAD));
costCalculation.setField(CostCalculationFields.REGISTRATION_PRICE_OVERHEAD, parameter.getDecimalField(CostCalculationFields.REGISTRATION_PRICE_OVERHEAD));
costCalculation.setField(CostCalculationFields.TECHNICAL_PRODUCTION_COST_OVERHEAD, parameter.getDecimalField(CostCalculationFields.TECHNICAL_PRODUCTION_COST_OVERHEAD));
costCalculation.setField(CostCalculationFields.PROFIT, parameter.getDecimalField(CostCalculationFields.PROFIT));
costCalculation.setField(CostCalculationFields.NUMBER, numberGeneratorService.generateNumber(CostCalculationConstants.PLUGIN_IDENTIFIER, CostCalculationConstants.MODEL_COST_CALCULATION));
costCalculation = costCalculationDD.save(costCalculation);
String url = "../page/costCalculation/costCalculationDetails.html";
Map<String, Object> parameters = Maps.newHashMap();
parameters.put("form.id", costCalculation.getId());
view.redirectTo(url, false, true, parameters);
}
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class CostNormsForOperationService method copyCostValuesFromOperation.
/* ****** VIEW EVENT LISTENERS ******* */
public void copyCostValuesFromOperation(final ViewDefinitionState view, final ComponentState operationLookupState, final String[] args) {
ComponentState operationLookup = view.getComponentByReference(OPERATION_FIELD);
if (operationLookup.getFieldValue() == null) {
if (!OPERATION_FIELD.equals(operationLookupState.getName())) {
view.getComponentByReference(QcadooViewConstants.L_FORM).addMessage("costNormsForOperation.messages.info.missingOperationReference", INFO);
}
return;
}
Entity operation = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION).get((Long) operationLookup.getFieldValue());
applyCostNormsFromGivenSource(view, operation);
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class DeliveryDetailsListeners method changeStorageLocations.
public final void changeStorageLocations(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent deliveryForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
GridComponent deliveredProductsGrid = (GridComponent) view.getComponentByReference(DeliveryFields.DELIVERED_PRODUCTS);
List<Entity> selectedProducts = deliveredProductsGrid.getSelectedEntities();
Set<Long> selectedProductsIds = deliveredProductsGrid.getSelectedEntitiesIds();
Entity delivery = deliveryForm.getPersistedEntityWithIncludedFormValues();
List<Entity> deliveredProducts = delivery.getHasManyField(DeliveryFields.DELIVERED_PRODUCTS);
for (Entity selectedProduct : selectedProducts) {
String palletNumber = selectedProduct.getStringField(DeliveredProductFields.PALLET_NUMBER);
if (Objects.nonNull(palletNumber)) {
List<Long> notSelectedMatchingProducts = deliveredProducts.stream().filter(deliveredProduct -> Objects.nonNull(deliveredProduct.getBelongsToField(DeliveredProductFields.PALLET_NUMBER)) && deliveredProduct.getBelongsToField(DeliveredProductFields.PALLET_NUMBER).getStringField(PalletNumberFields.NUMBER).equals(palletNumber)).map(Entity::getId).filter(deliveredProduct -> !selectedProductsIds.contains(deliveredProduct)).collect(Collectors.toList());
selectedProductsIds.addAll(notSelectedMatchingProducts);
}
}
String url = "../page/deliveries/changeStorageLocationHelper.html?context={\"form.deliveredProductIds\":\"" + selectedProductsIds.stream().map(Object::toString).collect(Collectors.joining(",")) + "\"," + "\"form.delivery\":\"" + delivery.getId() + "\"}";
view.openModal(url);
}
use of com.qcadoo.view.api.ComponentState in project mes by qcadoo.
the class DeliveryDetailsListeners method downloadProductAttachment.
public void downloadProductAttachment(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent deliveryForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
GridComponent orderedProductsGrid = (GridComponent) view.getComponentByReference(DeliveryFields.ORDERED_PRODUCTS);
Set<Long> ids = orderedProductsGrid.getSelectedEntitiesIds();
SearchCriteriaBuilder searchCriteria = deliveriesService.getOrderedProductDD().find().createAlias(BasicConstants.MODEL_PRODUCT, BasicConstants.MODEL_PRODUCT, JoinType.INNER).createAlias(BasicConstants.MODEL_PRODUCT + L_DOT + ProductFields.PRODUCT_ATTACHMENTS, ProductFields.PRODUCT_ATTACHMENTS, JoinType.INNER).setProjection(SearchProjections.list().add(alias(field(ProductFields.PRODUCT_ATTACHMENTS + L_DOT + ProductAttachmentFields.ATTACHMENT), ProductAttachmentFields.ATTACHMENT)));
if (ids.isEmpty()) {
searchCriteria.createAlias(DeliveriesConstants.MODEL_DELIVERY, DeliveriesConstants.MODEL_DELIVERY, JoinType.INNER).add(SearchRestrictions.in(DeliveriesConstants.MODEL_DELIVERY + L_DOT + "id", deliveryForm.getEntityId()));
} else {
searchCriteria.add(SearchRestrictions.in("id", ids));
}
List<Entity> result = searchCriteria.list().getEntities();
if (result.isEmpty()) {
return;
}
List<File> attachments = result.stream().map(productAttachment -> new File(productAttachment.getStringField(ProductAttachmentFields.ATTACHMENT))).collect(Collectors.toList());
File zipFile;
try {
zipFile = fileService.compressToZipFile(attachments, false);
} catch (IOException e) {
LOG.error("Unable to compress documents to zip file.", e);
return;
}
view.redirectTo(fileService.getUrl(zipFile.getAbsolutePath()) + "?clean", true, false);
}
Aggregations