Search in sources :

Example 21 with ComponentState

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

the class CostNormsGeneratorListeners method updateCostNorms.

public void updateCostNorms(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent costNormsGeneratorForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity costNormsGenerator = costNormsGeneratorForm.getPersistedEntityWithIncludedFormValues();
    String costsSource = costNormsGenerator.getStringField(CostNormsGeneratorFields.COSTS_SOURCE);
    if ("01mes".equals(costsSource)) {
        boolean allProducts = ProductsToUpdate.of(costNormsGenerator).compareTo(ProductsToUpdate.ALL) == 0;
        List<Entity> products = Lists.newArrayList();
        if (!allProducts) {
            products = costNormsGenerator.getHasManyField(CostNormsGeneratorFields.PRODUCTS);
            if (products.isEmpty()) {
                view.addMessage("materialFlowResources.info.costNormsNotUpdated", ComponentState.MessageType.INFO);
                return;
            }
        }
        List<Entity> warehouses = costNormsGenerator.getHasManyField(CostNormsGeneratorFields.WAREHOUSES).stream().map(warehouse -> warehouse.getBelongsToField(CostNormsLocationFields.LOCATION)).collect(Collectors.toList());
        costNormsService.updateCostNormsForProductsFromWarehouses(products, warehouses);
    }
    view.addMessage("materialFlowResources.success.costNormsUpdated", ComponentState.MessageType.SUCCESS);
}
Also used : ProductsToUpdate(com.qcadoo.mes.materialFlowResources.constants.ProductsToUpdate) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) CostNormsGeneratorFields(com.qcadoo.mes.materialFlowResources.constants.CostNormsGeneratorFields) CostNormsLocationFields(com.qcadoo.mes.materialFlowResources.constants.CostNormsLocationFields) Collectors(java.util.stream.Collectors) GridComponent(com.qcadoo.view.api.components.GridComponent) List(java.util.List) Entity(com.qcadoo.model.api.Entity) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) CostNormsService(com.qcadoo.mes.materialFlowResources.costNorms.CostNormsService) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity)

Example 22 with ComponentState

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

the class DocumentDetailsHooks method lockNumberAndTypeChange.

private void lockNumberAndTypeChange(final ViewDefinitionState view) {
    FormComponent documentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    ComponentState typeComponent = view.getComponentByReference(DocumentFields.TYPE);
    if (documentForm.getEntityId() != null) {
        typeComponent.setEnabled(false);
    } else {
        typeComponent.setEnabled(true);
    }
    FieldComponent numberField = (FieldComponent) view.getComponentByReference(DocumentFields.NUMBER);
    numberField.setEnabled(false);
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) FieldComponent(com.qcadoo.view.api.components.FieldComponent) ComponentState(com.qcadoo.view.api.ComponentState)

Example 23 with ComponentState

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

the class DocumentDetailsHooks method fetchNameAndNumberFromDatabase.

private void fetchNameAndNumberFromDatabase(final ViewDefinitionState view) {
    FormComponent documentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    if (documentForm.getEntityId() != null) {
        ComponentState numberField = view.getComponentByReference(DocumentFields.NUMBER);
        ComponentState nameField = view.getComponentByReference(DocumentFields.NAME);
        String nameFieldValue = (String) nameField.getFieldValue();
        String numberFieldValue = (String) numberField.getFieldValue();
        if (!numberFieldValue.contains("/")) {
            Entity document = getDocumentDD().get(documentForm.getEntityId());
            if (!numberFieldValue.contains("/")) {
                numberField.setFieldValue(document.getField(DocumentFields.NUMBER));
            }
            if (Strings.isNullOrEmpty(nameFieldValue)) {
                nameField.setFieldValue(document.getField(DocumentFields.NAME));
            }
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) ComponentState(com.qcadoo.view.api.ComponentState)

Example 24 with ComponentState

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

the class MaterialRequirementDetailsListeners method generateMaterialRequirement.

@Transactional
public void generateMaterialRequirement(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    if (state instanceof FormComponent) {
        ComponentState generated = view.getComponentByReference("generated");
        ComponentState date = view.getComponentByReference("date");
        ComponentState worker = view.getComponentByReference("worker");
        Entity materialRequirement = dataDefinitionService.get(MaterialRequirementsConstants.PLUGIN_IDENTIFIER, MaterialRequirementsConstants.MODEL_MATERIAL_REQUIREMENT).get((Long) state.getFieldValue());
        if (materialRequirement == null) {
            state.addMessage("qcadooView.message.entityNotFound", MessageType.FAILURE);
            return;
        } else if (StringUtils.isNotBlank(materialRequirement.getStringField("fileName"))) {
            state.addMessage("materialRequirements.materialRequirementDetails.window.materialRequirement.documentsWasGenerated", MessageType.FAILURE);
            return;
        }
        List<Entity> orders = materialRequirement.getManyToManyField("orders");
        if (orders.isEmpty()) {
            state.addMessage("materialRequirements.materialRequirementDetails.window.materialRequirement.missingAssosiatedOrders", MessageType.FAILURE);
            return;
        }
        List<String> numbersOfOrdersWithoutTechnology = orderHelperService.getOrdersWithoutTechnology(orders);
        if (!numbersOfOrdersWithoutTechnology.isEmpty()) {
            state.addMessage("materialRequirements.materialRequirementDetails.window.materialRequirement.missingTechnologyInOrders", MessageType.FAILURE, StringUtils.join(numbersOfOrdersWithoutTechnology, ",<br>"));
            return;
        }
        if ("0".equals(generated.getFieldValue())) {
            worker.setFieldValue(securityService.getCurrentUserName());
            generated.setFieldValue("1");
            date.setFieldValue(new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, LocaleContextHolder.getLocale()).format(new Date()));
        }
        state.performEvent(view, "save");
        if (state.getFieldValue() == null || !((FormComponent) state).isValid()) {
            worker.setFieldValue(null);
            generated.setFieldValue("0");
            date.setFieldValue(null);
            return;
        }
        materialRequirement = dataDefinitionService.get(MaterialRequirementsConstants.PLUGIN_IDENTIFIER, MaterialRequirementsConstants.MODEL_MATERIAL_REQUIREMENT).get((Long) state.getFieldValue());
        try {
            materialRequirementService.generateMaterialRequirementDocuments(state, materialRequirement);
            state.performEvent(view, "reset");
        } catch (IOException | DocumentException e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) IOException(java.io.IOException) Date(java.util.Date) DocumentException(com.lowagie.text.DocumentException) SimpleDateFormat(java.text.SimpleDateFormat) ComponentState(com.qcadoo.view.api.ComponentState) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with ComponentState

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

the class GenerateMaterialRequirementCoverageListeners method createDelivery.

/**
 * createOffer event handler
 *
 * @param view
 * @param state
 * @param args
 */
public void createDelivery(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    init();
    GridComponent grid = (GridComponent) view.getComponentByReference(L_GRID);
    Entity parameter = parameterService.getParameter();
    Entity systemCurrency = parameter.getBelongsToField(ParameterFields.CURRENCY);
    DataDefinition companyDataDefinition = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_COMPANY);
    Map<Optional<Integer>, List<Entity>> groupedCoverageProducts = grid.getSelectedEntities().stream().collect(Collectors.groupingBy(e -> Optional.ofNullable(e.getIntegerField("companyId"))));
    StringBuilder deliveryNumbers = new StringBuilder();
    for (Map.Entry<Optional<Integer>, List<Entity>> entry : groupedCoverageProducts.entrySet()) {
        String number = numberGeneratorService.generateNumber(DeliveriesConstants.PLUGIN_IDENTIFIER, DeliveriesConstants.MODEL_DELIVERY);
        Entity delivery = deliveriesService.getDeliveryDD().create();
        delivery.setField(NUMBER, number);
        Entity currency = null;
        if (entry.getKey().isPresent()) {
            Entity supplier = companyDataDefinition.get(entry.getKey().get().longValue());
            delivery.setField(SUPPLIER, supplier);
            currency = supplier.getBelongsToField(CompanyFieldsD.CURRENCY);
        }
        if (currency == null) {
            currency = systemCurrency;
        }
        delivery.setField(CURRENCY, currency);
        delivery.setField(EXTERNAL_SYNCHRONIZED, true);
        Entity saved = deliveriesService.getDeliveryDD().save(delivery);
        if (saved.isValid()) {
            deliveryNumbers.append("<br/>").append(number);
            entry.getValue().forEach(coverageProduct -> {
                Integer product = coverageProduct.getIntegerField("productId");
                BigDecimal reserveMissingQuantity = coverageProduct.getDecimalField(CoverageProductFields.RESERVE_MISSING_QUANTITY);
                BigDecimal orderedQuantity = reserveMissingQuantity.min(BigDecimal.ZERO).abs();
                BigDecimal conversion = getConversion(product);
                Entity orderedProduct = orderedProductDataDefinition.create();
                orderedProduct.setField("delivery", saved);
                orderedProduct.setField("product", product.longValue());
                orderedProduct.setField("orderedQuantity", reserveMissingQuantity.min(BigDecimal.ZERO).abs());
                orderedProduct.setField(OrderedProductFields.CONVERSION, conversion);
                orderedProduct.setField(OrderedProductFields.ADDITIONAL_QUANTITY, orderedQuantity.multiply(conversion, numberService.getMathContext()));
                orderedProductDataDefinition.save(orderedProduct);
            });
        }
        if (parameter.getBooleanField(L_REQUIRE_SUPPLIER_IDENTIFICATION) && Objects.isNull(delivery.getBelongsToField(SUPPLIER))) {
            state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.requireSupplierIdentification", MessageType.INFO, false);
        }
    }
    if (StringUtils.isNoneEmpty(deliveryNumbers.toString())) {
        state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.created", MessageType.SUCCESS, false, deliveryNumbers.toString());
    } else {
        state.addMessage("orderSupplies.materialRequirementCoverage.deliveries.notCreated", MessageType.INFO, false);
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) UnitConversionService(com.qcadoo.model.api.units.UnitConversionService) MaterialRequirementCoverageFields(com.qcadoo.mes.orderSupplies.constants.MaterialRequirementCoverageFields) StringUtils(org.apache.commons.lang3.StringUtils) ParameterFields(com.qcadoo.mes.basic.constants.ParameterFields) FileService(com.qcadoo.model.api.file.FileService) BigDecimal(java.math.BigDecimal) ReportService(com.qcadoo.report.api.ReportService) JSONException(org.json.JSONException) OrderSuppliesConstants(com.qcadoo.mes.orderSupplies.constants.OrderSuppliesConstants) JSONObject(org.json.JSONObject) Locale(java.util.Locale) BasicConstants(com.qcadoo.mes.basic.constants.BasicConstants) Map(java.util.Map) CoverageProductSelectedFields(com.qcadoo.mes.orderSupplies.constants.CoverageProductSelectedFields) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) DeliveriesConstants(com.qcadoo.mes.deliveries.constants.DeliveriesConstants) Collectors(java.util.stream.Collectors) DataDefinition(com.qcadoo.model.api.DataDefinition) Objects(java.util.Objects) List(java.util.List) Entity(com.qcadoo.model.api.Entity) CoverageAnalysisForOrderService(com.qcadoo.mes.orderSupplies.coverage.coverageAnalysis.CoverageAnalysisForOrderService) ParameterService(com.qcadoo.mes.basic.ParameterService) EXTERNAL_SYNCHRONIZED(com.qcadoo.mes.deliveries.constants.DeliveryFields.EXTERNAL_SYNCHRONIZED) CompanyFieldsD(com.qcadoo.mes.deliveries.constants.CompanyFieldsD) Optional(java.util.Optional) MessageType(com.qcadoo.view.api.ComponentState.MessageType) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) SimpleDateFormat(java.text.SimpleDateFormat) NUMBER(com.qcadoo.mes.deliveries.constants.DeliveryFields.NUMBER) DateUtils(com.qcadoo.localization.api.utils.DateUtils) CURRENCY(com.qcadoo.mes.deliveries.constants.DeliveryFields.CURRENCY) DeliveriesService(com.qcadoo.mes.deliveries.DeliveriesService) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) PossibleUnitConversions(com.qcadoo.model.api.units.PossibleUnitConversions) NumberGeneratorService(com.qcadoo.view.api.utils.NumberGeneratorService) OrderSuppliesService(com.qcadoo.mes.orderSupplies.OrderSuppliesService) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) SecurityService(com.qcadoo.security.api.SecurityService) CoverageProductFields(com.qcadoo.mes.orderSupplies.constants.CoverageProductFields) MaterialRequirementCoverageReportPdfService(com.qcadoo.mes.orderSupplies.print.MaterialRequirementCoverageReportPdfService) IOException(java.io.IOException) UnitConversionItemFieldsB(com.qcadoo.mes.basic.constants.UnitConversionItemFieldsB) DocumentException(com.lowagie.text.DocumentException) OrderedProductFields(com.qcadoo.mes.deliveries.constants.OrderedProductFields) GridComponent(com.qcadoo.view.api.components.GridComponent) CoverageLocationFields(com.qcadoo.mes.orderSupplies.constants.CoverageLocationFields) MaterialRequirementCoverageService(com.qcadoo.mes.orderSupplies.coverage.MaterialRequirementCoverageService) NumberService(com.qcadoo.model.api.NumberService) SUPPLIER(com.qcadoo.mes.deliveries.constants.DeliveryFields.SUPPLIER) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) PageSize(com.lowagie.text.PageSize) CoverageProductGeneratedFields(com.qcadoo.mes.orderSupplies.constants.CoverageProductGeneratedFields) Transactional(org.springframework.transaction.annotation.Transactional) Entity(com.qcadoo.model.api.Entity) Optional(java.util.Optional) GridComponent(com.qcadoo.view.api.components.GridComponent) DataDefinition(com.qcadoo.model.api.DataDefinition) BigDecimal(java.math.BigDecimal) List(java.util.List) Map(java.util.Map)

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