Search in sources :

Example 16 with ComponentState

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;
}
Also used : ComponentState(com.qcadoo.view.api.ComponentState) SelectComponentState(com.qcadoo.view.internal.components.select.SelectComponentState)

Example 17 with ComponentState

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);
    }
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) MaterialCostsUsed(com.qcadoo.mes.costCalculation.constants.MaterialCostsUsed) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) SourceOfOperationCosts(com.qcadoo.mes.costCalculation.constants.SourceOfOperationCosts) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponent(com.qcadoo.view.api.components.GridComponent) BigDecimal(java.math.BigDecimal) CostCalculationFields(com.qcadoo.mes.costCalculation.constants.CostCalculationFields) List(java.util.List) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) ParameterService(com.qcadoo.mes.basic.ParameterService) NumberGeneratorService(com.qcadoo.view.api.utils.NumberGeneratorService) Service(org.springframework.stereotype.Service) Map(java.util.Map) CostCalculationConstants(com.qcadoo.mes.costCalculation.constants.CostCalculationConstants) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) Entity(com.qcadoo.model.api.Entity) GridComponent(com.qcadoo.view.api.components.GridComponent) DataDefinition(com.qcadoo.model.api.DataDefinition)

Example 18 with ComponentState

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);
}
Also used : Entity(com.qcadoo.model.api.Entity) ComponentState(com.qcadoo.view.api.ComponentState)

Example 19 with ComponentState

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);
}
Also used : MessageType(com.qcadoo.view.api.ComponentState.MessageType) java.util(java.util) CurrencyService(com.qcadoo.mes.basic.util.CurrencyService) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) LoggerFactory(org.slf4j.LoggerFactory) com.qcadoo.mes.deliveries.constants(com.qcadoo.mes.deliveries.constants) Autowired(org.springframework.beans.factory.annotation.Autowired) UnitConversionService(com.qcadoo.model.api.units.UnitConversionService) ReservationService(com.qcadoo.mes.deliveries.ReservationService) StringUtils(org.apache.commons.lang3.StringUtils) com.qcadoo.model.api(com.qcadoo.model.api) FileService(com.qcadoo.model.api.file.FileService) DeliveriesService(com.qcadoo.mes.deliveries.DeliveriesService) DeliveryStateStringValues(com.qcadoo.mes.deliveries.states.constants.DeliveryStateStringValues) BigDecimal(java.math.BigDecimal) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) ProductFieldsCNFP(com.qcadoo.mes.costNormsForProduct.constants.ProductFieldsCNFP) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) NumberGeneratorService(com.qcadoo.view.api.utils.NumberGeneratorService) PdfHelper(com.qcadoo.report.api.pdf.PdfHelper) FormComponent(com.qcadoo.view.api.components.FormComponent) PluginUtils(com.qcadoo.plugin.api.PluginUtils) DeliveredProductMultiPositionService(com.qcadoo.mes.deliveries.DeliveredProductMultiPositionService) OrderReportPdf(com.qcadoo.mes.deliveries.print.OrderReportPdf) com.qcadoo.model.api.search(com.qcadoo.model.api.search) SearchProjections.field(com.qcadoo.model.api.search.SearchProjections.field) Logger(org.slf4j.Logger) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) File(java.io.File) Component(org.springframework.stereotype.Component) ParameterService(com.qcadoo.mes.basic.ParameterService) FieldComponent(com.qcadoo.view.api.components.FieldComponent) com.qcadoo.mes.basic.constants(com.qcadoo.mes.basic.constants) LookupComponent(com.qcadoo.view.api.components.LookupComponent) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) SearchProjections.alias(com.qcadoo.model.api.search.SearchProjections.alias) DeliveryReportPdf(com.qcadoo.mes.deliveries.print.DeliveryReportPdf) FormComponent(com.qcadoo.view.api.components.FormComponent) GridComponent(com.qcadoo.view.api.components.GridComponent)

Example 20 with ComponentState

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);
}
Also used : MessageType(com.qcadoo.view.api.ComponentState.MessageType) java.util(java.util) CurrencyService(com.qcadoo.mes.basic.util.CurrencyService) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) LoggerFactory(org.slf4j.LoggerFactory) com.qcadoo.mes.deliveries.constants(com.qcadoo.mes.deliveries.constants) Autowired(org.springframework.beans.factory.annotation.Autowired) UnitConversionService(com.qcadoo.model.api.units.UnitConversionService) ReservationService(com.qcadoo.mes.deliveries.ReservationService) StringUtils(org.apache.commons.lang3.StringUtils) com.qcadoo.model.api(com.qcadoo.model.api) FileService(com.qcadoo.model.api.file.FileService) DeliveriesService(com.qcadoo.mes.deliveries.DeliveriesService) DeliveryStateStringValues(com.qcadoo.mes.deliveries.states.constants.DeliveryStateStringValues) BigDecimal(java.math.BigDecimal) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) ProductFieldsCNFP(com.qcadoo.mes.costNormsForProduct.constants.ProductFieldsCNFP) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) NumberGeneratorService(com.qcadoo.view.api.utils.NumberGeneratorService) PdfHelper(com.qcadoo.report.api.pdf.PdfHelper) FormComponent(com.qcadoo.view.api.components.FormComponent) PluginUtils(com.qcadoo.plugin.api.PluginUtils) DeliveredProductMultiPositionService(com.qcadoo.mes.deliveries.DeliveredProductMultiPositionService) OrderReportPdf(com.qcadoo.mes.deliveries.print.OrderReportPdf) com.qcadoo.model.api.search(com.qcadoo.model.api.search) SearchProjections.field(com.qcadoo.model.api.search.SearchProjections.field) Logger(org.slf4j.Logger) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) File(java.io.File) Component(org.springframework.stereotype.Component) ParameterService(com.qcadoo.mes.basic.ParameterService) FieldComponent(com.qcadoo.view.api.components.FieldComponent) com.qcadoo.mes.basic.constants(com.qcadoo.mes.basic.constants) LookupComponent(com.qcadoo.view.api.components.LookupComponent) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) SearchProjections.alias(com.qcadoo.model.api.search.SearchProjections.alias) DeliveryReportPdf(com.qcadoo.mes.deliveries.print.DeliveryReportPdf) FormComponent(com.qcadoo.view.api.components.FormComponent) GridComponent(com.qcadoo.view.api.components.GridComponent) IOException(java.io.IOException) File(java.io.File)

Aggregations

ComponentState (com.qcadoo.view.api.ComponentState)68 Entity (com.qcadoo.model.api.Entity)33 FormComponent (com.qcadoo.view.api.components.FormComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)23 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)21 Autowired (org.springframework.beans.factory.annotation.Autowired)17 FieldComponent (com.qcadoo.view.api.components.FieldComponent)16 Test (org.junit.Test)16 Service (org.springframework.stereotype.Service)16 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)15 Collectors (java.util.stream.Collectors)14 List (java.util.List)13 DataDefinition (com.qcadoo.model.api.DataDefinition)12 Lists (com.google.common.collect.Lists)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)11 Map (java.util.Map)11 BigDecimal (java.math.BigDecimal)10 Maps (com.google.common.collect.Maps)8 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 Transactional (org.springframework.transaction.annotation.Transactional)8