Search in sources :

Example 6 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class ProductToIssueCorrectionHelperHooks method setWarehouseCriteriaModifier.

private void setWarehouseCriteriaModifier(final ViewDefinitionState view, Entity helper) {
    LookupComponent warehouseLookup = (LookupComponent) view.getComponentByReference("locationTo");
    Entity placeOfIssue = helper.getBelongsToField("placeOfIssue");
    OptionalLong locationTo = helper.getHasManyField("corrections").stream().mapToLong(correction -> correction.getBelongsToField(ProductToIssueCorrectionFields.LOCATION).getId()).findAny();
    FilterValueHolder filter = warehouseLookup.getFilterValue();
    filter.put("locationFrom", placeOfIssue.getId());
    if (locationTo.isPresent()) {
        filter.put("locationTo", locationTo.getAsLong());
    }
    warehouseLookup.setFilterValue(filter);
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) Autowired(org.springframework.beans.factory.annotation.Autowired) com.qcadoo.model.api(com.qcadoo.model.api) BigDecimal(java.math.BigDecimal) OptionalLong(java.util.OptionalLong) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) ProductToIssueCorrectionFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductToIssueCorrectionFields) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) RibbonGroup(com.qcadoo.view.api.ribbon.RibbonGroup) TranslationService(com.qcadoo.localization.api.TranslationService) Collectors(java.util.stream.Collectors) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) com.qcadoo.view.api.components(com.qcadoo.view.api.components) List(java.util.List) Either(com.qcadoo.commons.functional.Either) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) Optional(java.util.Optional) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) StringUtils(org.springframework.util.StringUtils) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) OptionalLong(java.util.OptionalLong)

Example 7 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class ModifyTechnologyDetailsHooks method onBeforeRender.

public final void onBeforeRender(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    if (view.isViewAfterRedirect()) {
        Entity mt = form.getEntity().getDataDefinition().get(form.getEntityId());
        LookupComponent replaceProductLookup = (LookupComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT);
        replaceProductLookup.setFieldValue(mt.getBelongsToField(L_MAIN_PRODUCT).getId());
        replaceProductLookup.requestComponentUpdateState();
        String selectedEntities = mt.getStringField(ModifyTechnologyHelperFields.SELECTED_ENTITIES);
        List<Long> ids = Lists.newArrayList(selectedEntities.split(",")).stream().map(Long::valueOf).collect(Collectors.toList());
        boolean sizeProduct = mt.getBooleanField("sizeProduct");
        if (sizeProduct) {
            List<Entity> producstBySize = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_PRODUCT_BY_SIZE_GROUP).find().add(SearchRestrictions.in(L_ID, ids)).list().getEntities();
            Set<BigDecimal> quantities = producstBySize.stream().map(op -> op.getDecimalField(L_QUANTITY)).collect(Collectors.toSet());
            if (quantities.size() == 1) {
                FieldComponent qnt = (FieldComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT_QUANTITY);
                qnt.setFieldValue(quantities.stream().findFirst().get());
                qnt.requestComponentUpdateState();
            }
        } else {
            List<Entity> opicDtos = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT_DTO).find().add(SearchRestrictions.in(L_ID, ids)).list().getEntities();
            Set<BigDecimal> quantities = opicDtos.stream().map(op -> op.getDecimalField(L_QUANTITY)).collect(Collectors.toSet());
            if (quantities.size() == 1) {
                FieldComponent qnt = (FieldComponent) view.getComponentByReference(ModifyTechnologyHelperFields.REPLACE_PRODUCT_QUANTITY);
                qnt.setFieldValue(quantities.stream().findFirst().get());
                qnt.requestComponentUpdateState();
            }
        }
        FieldComponent replaceProductUnit = (FieldComponent) view.getComponentByReference(L_REPLACE_PRODUCT_UNIT);
        replaceProductUnit.setFieldValue(mt.getBelongsToField(L_MAIN_PRODUCT).getStringField(ProductFields.UNIT));
    }
    setForm(view);
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) CheckBoxComponent(com.qcadoo.view.api.components.CheckBoxComponent) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ModifyTechnologyHelperFields(com.qcadoo.mes.technologies.constants.ModifyTechnologyHelperFields) BigDecimal(java.math.BigDecimal) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) List(java.util.List) Lists(com.google.common.collect.Lists) FieldComponent(com.qcadoo.view.api.components.FieldComponent) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) LookupComponent(com.qcadoo.view.api.components.LookupComponent) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) BigDecimal(java.math.BigDecimal)

Example 8 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState in project mes by qcadoo.

the class TOCDetailsHooks method disableViewForState.

private void disableViewForState(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity toc = form.getEntity();
    if (toc.getId() == null) {
        return;
    }
    toc = getTechnologyOperationComponentDD().get(toc.getId());
    Entity technology = toc.getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY);
    if (!TechnologyState.DRAFT.getStringValue().equals(technology.getStringField(TechnologyFields.STATE))) {
        WindowComponent windowComponent = (WindowComponent) view.getComponentByReference(QcadooViewConstants.L_WINDOW);
        Ribbon ribbon = windowComponent.getRibbon();
        ribbon.getGroups().stream().filter(group -> !group.getName().equals(L_NAVIGATION)).forEach(group -> group.getItems().forEach(item -> {
            item.setEnabled(false);
            item.requestUpdate(true);
        }));
        form.setFormEnabled(false);
    }
}
Also used : RibbonActionItem(com.qcadoo.view.api.ribbon.RibbonActionItem) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Arrays(java.util.Arrays) TechnologyState(com.qcadoo.mes.technologies.states.constants.TechnologyState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Ribbon(com.qcadoo.view.api.ribbon.Ribbon) Autowired(org.springframework.beans.factory.annotation.Autowired) DataDefinition(com.qcadoo.model.api.DataDefinition) FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) com.qcadoo.mes.technologies.constants(com.qcadoo.mes.technologies.constants) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) com.qcadoo.view.api.components(com.qcadoo.view.api.components) List(java.util.List) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) Entity(com.qcadoo.model.api.Entity) Ribbon(com.qcadoo.view.api.ribbon.Ribbon)

Example 9 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState 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 10 with ViewDefinitionState

use of com.qcadoo.view.api.ViewDefinitionState 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)

Aggregations

ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)50 Autowired (org.springframework.beans.factory.annotation.Autowired)35 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)32 Service (org.springframework.stereotype.Service)31 ComponentState (com.qcadoo.view.api.ComponentState)29 Collectors (java.util.stream.Collectors)28 Entity (com.qcadoo.model.api.Entity)27 Lists (com.google.common.collect.Lists)25 GridComponent (com.qcadoo.view.api.components.GridComponent)25 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)24 FormComponent (com.qcadoo.view.api.components.FormComponent)23 BigDecimal (java.math.BigDecimal)21 List (java.util.List)21 Maps (com.google.common.collect.Maps)18 Map (java.util.Map)18 DataDefinition (com.qcadoo.model.api.DataDefinition)16 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)15 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)13 FieldComponent (com.qcadoo.view.api.components.FieldComponent)11 Objects (java.util.Objects)11