Search in sources :

Example 51 with ComponentState

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

the class DeviationReportGeneratorViewHooks method setDefaultDateRange.

private void setDefaultDateRange(final ViewDefinitionState view) {
    for (ComponentState dateFromComponent : view.tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_FROM).asSet()) {
        Date firstDayOfCurrentMonth = LocalDate.now().withDayOfMonth(1).toDate();
        dateFromComponent.setFieldValue(DateUtils.toDateString(firstDayOfCurrentMonth));
    }
    Optional<ComponentState> maybeDateFromComponent = view.tryFindComponentByReference(DeviationReportGeneratorViewReferences.DATE_TO);
    for (ComponentState dateFromComponent : maybeDateFromComponent.asSet()) {
        Date today = LocalDate.now().toDate();
        dateFromComponent.setFieldValue(DateUtils.toDateString(today));
    }
}
Also used : LocalDate(org.joda.time.LocalDate) Date(java.util.Date) ComponentState(com.qcadoo.view.api.ComponentState)

Example 52 with ComponentState

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

the class QuantityService method checkMinimalQuantityValue.

private void checkMinimalQuantityValue(final ViewDefinitionState view, final Entity technologyEntity) {
    FieldComponent plannedQuantityComponent = (FieldComponent) view.getComponentByReference("plannedQuantity");
    BigDecimal plannedQuantity = getBigDecimalFromField(plannedQuantityComponent.getFieldValue(), view.getLocale());
    BigDecimal minimalQuantity = getBigDecimalFromField(technologyEntity.getField("minimalQuantity"), view.getLocale());
    Entity product = dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT).get(technologyEntity.getBelongsToField("product").getId());
    if (plannedQuantity == null || minimalQuantity == null) {
        return;
    }
    String unit = product.getStringField("unit");
    if (plannedQuantity.compareTo(minimalQuantity) < 0) {
        ComponentState form = (ComponentState) view.getComponentByReference(QcadooViewConstants.L_FORM);
        form.addMessage("orders.order.report.minimalQuantity", MessageType.INFO, false, minimalQuantity.toString(), unit);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) BigDecimal(java.math.BigDecimal) ComponentState(com.qcadoo.view.api.ComponentState)

Example 53 with ComponentState

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

the class OrderDetailsHooks method changePredefinedTechnologyFieldsVisibility.

private void changePredefinedTechnologyFieldsVisibility(final ViewDefinitionState view) {
    for (String reference : OrderDetailsHooks.L_PREDEFINED_TECHNOLOGY_FIELDS) {
        ComponentState componentState = view.getComponentByReference(reference);
        componentState.setVisible(true);
    }
}
Also used : ComponentState(com.qcadoo.view.api.ComponentState)

Example 54 with ComponentState

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

the class ProductsToIssueHelperDetailsListeners method updateQuantities.

public void updateQuantities(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference(L_ISSUES);
    Long changedId = (Long) state.getFieldValue();
    for (FormComponent form : adl.getFormComponents()) {
        Entity issue = form.getPersistedEntityWithIncludedFormValues();
        Entity product = issue.getBelongsToField(IssueFields.PRODUCT);
        if (product != null && product.getId().equals(changedId)) {
            Entity locationTo = issue.getBelongsToField(IssueFields.LOCATION);
            Entity warehouseIssue = issue.getBelongsToField(IssueFields.WAREHOUSE_ISSUE);
            Entity locationFrom = warehouseIssue.getBelongsToField(WarehouseIssueFields.PLACE_OF_ISSUE);
            Optional<Entity> maybeProductToIssue = warehouseIssue.getHasManyField(WarehouseIssueFields.PRODUCTS_TO_ISSUES).stream().filter(p -> p.getBelongsToField(ProductsToIssueFields.PRODUCT).getId().equals(product.getId()) && p.getBelongsToField(ProductsToIssueFields.LOCATION).getId().equals(locationTo.getId())).findFirst();
            BigDecimal quantityFrom = materialFlowResourcesService.getResourcesQuantityForLocationAndProduct(locationFrom, product);
            BigDecimal quantityTo = materialFlowResourcesService.getResourcesQuantityForLocationAndProduct(locationTo, product);
            if (maybeProductToIssue.isPresent()) {
                Entity productToIssue = maybeProductToIssue.get();
                BigDecimal demandQuantity = productToIssue.getDecimalField(ProductsToIssueFields.DEMAND_QUANTITY);
                BigDecimal issuedQuantity = productToIssue.getDecimalField(ProductsToIssueFields.ISSUE_QUANTITY);
                issue.setField(IssueFields.ADDITIONAL_CODE, productToIssue.getBelongsToField(ProductsToIssueFields.ADDITIONAL_CODE));
                issue.setField(IssueFields.STORAGE_LOCATION, productToIssue.getBelongsToField(ProductsToIssueFields.STORAGE_LOCATION));
                BigDecimal quantityPerUnit = null;
                BigDecimal issueQuantity = BigDecimal.ZERO;
                if (warehouseIssueParameterService.issueForOrder()) {
                    Entity order = warehouseIssue.getBelongsToField(WarehouseIssueFields.ORDER);
                    BigDecimal plannedQuantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY);
                    if (plannedQuantity != null && demandQuantity != null) {
                        quantityPerUnit = demandQuantity.divide(plannedQuantity, numberService.getMathContext());
                    }
                }
                if (demandQuantity != null && issuedQuantity != null) {
                    issueQuantity = demandQuantity.subtract(issuedQuantity);
                }
                if (issueQuantity.compareTo(BigDecimal.ZERO) == -1) {
                    issueQuantity = BigDecimal.ZERO;
                }
                issue.setField(IssueFields.DEMAND_QUANTITY, demandQuantity);
                issue.setField(IssueFields.QUANTITY_PER_UNIT, quantityPerUnit);
                issue.setField(IssueFields.ISSUE_QUANTITY, issueQuantity);
                BigDecimal conversion = productToIssue.getDecimalField(ProductsToIssueFields.CONVERSION);
                if (conversion != null) {
                    issue.setField(IssueFields.CONVERSION, conversion);
                    String unit = product.getStringField(ProductFields.UNIT);
                    String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT);
                    BigDecimal newAdditionalQuantity = calculationQuantityService.calculateAdditionalQuantity(demandQuantity, conversion, Optional.ofNullable(additionalUnit).orElse(unit));
                    issue.setField(IssueFields.ADDITIONAL_DEMAND_QUANTITY, newAdditionalQuantity);
                }
            } else {
                issue.setField(IssueFields.DEMAND_QUANTITY, BigDecimal.ZERO);
                issue.setField(IssueFields.QUANTITY_PER_UNIT, BigDecimal.ZERO);
            }
            issue.setField(IssueFields.LOCATIONS_QUANTITY, quantityFrom);
            issue.setField(IssueFields.LOCATION_TO_QUANTITY, quantityTo);
            form.setEntity(issue);
        }
    }
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) java.util(java.util) RuntimeExceptionWithArguments(com.qcadoo.model.api.exception.RuntimeExceptionWithArguments) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) com.qcadoo.model.api(com.qcadoo.model.api) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) Lists(com.google.common.collect.Lists) WarehouseIssueService(com.qcadoo.mes.productFlowThruDivision.service.WarehouseIssueService) Service(org.springframework.stereotype.Service) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) GlobalMessage(com.qcadoo.model.api.validators.GlobalMessage) EntityRuntimeException(com.qcadoo.model.api.exception.EntityRuntimeException) LocationFields(com.qcadoo.mes.materialFlow.constants.LocationFields) MaterialFlowResourcesService(com.qcadoo.mes.materialFlowResources.MaterialFlowResourcesService) RoundingMode(java.math.RoundingMode) ProductsToIssueDetailsHooks(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.hooks.ProductsToIssueDetailsHooks) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) IssueValidators(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.validators.IssueValidators) PositionFields(com.qcadoo.mes.materialFlowResources.constants.PositionFields) DocumentBuildException(com.qcadoo.mes.materialFlowResources.exceptions.DocumentBuildException) TranslationService(com.qcadoo.localization.api.TranslationService) com.qcadoo.view.api.components(com.qcadoo.view.api.components) Either(com.qcadoo.commons.functional.Either) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) CalculationQuantityService(com.qcadoo.mes.basic.CalculationQuantityService) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) UpdateIssuesLocationsQuantityStatusHolder(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.UpdateIssuesLocationsQuantityStatusHolder) Transactional(org.springframework.transaction.annotation.Transactional) BigDecimal(java.math.BigDecimal)

Example 55 with ComponentState

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

the class WarehouseIssueDetailsListeners method fillProductsToIssue.

public void fillProductsToIssue(final ViewDefinitionState view, final ComponentState state, final String[] args) {
    FormComponent issueForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    FieldComponent collectionProductsField = (FieldComponent) view.getComponentByReference(WarehouseIssueFields.COLLECTION_PRODUCTS);
    LookupComponent operation = (LookupComponent) view.getComponentByReference(WarehouseIssueFields.TECHNOLOGY_OPERATION_COMPONENT);
    LookupComponent division = (LookupComponent) view.getComponentByReference(WarehouseIssueFields.DIVISION);
    Long warehouseIssueId = issueForm.getEntityId();
    Entity toc = operation.getEntity();
    Entity divisionEntity = division.getEntity();
    List<Entity> createdProducts = warehouseIssueService.fillProductsToIssue(warehouseIssueId, CollectionProducts.fromStringValue(collectionProductsField.getFieldValue().toString()), toc, divisionEntity);
    if (createdProducts != null) {
        List<Entity> invalidProducts = createdProducts.stream().filter(productToIssue -> !productToIssue.isValid()).collect(Collectors.toList());
        if (invalidProducts.isEmpty()) {
            view.addMessage("productFlowThruDivision.issue.downloadedProducts", ComponentState.MessageType.SUCCESS);
        } else {
            Multimap<String, String> errors = ArrayListMultimap.create();
            for (Entity productToIssue : invalidProducts) {
                String number = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT).getStringField(ProductFields.NUMBER);
                Map<String, ErrorMessage> errorMessages = productToIssue.getErrors();
                errorMessages.entrySet().stream().forEach(entry -> errors.put(entry.getValue().getMessage(), number));
                productToIssue.getGlobalErrors().stream().forEach(error -> errors.put(error.getMessage(), number));
            }
            view.addMessage("productFlowThruDivision.issue.downloadedProductsError", ComponentState.MessageType.INFO, false);
            for (String message : errors.keySet()) {
                String translatedMessage = translationService.translate(message, LocaleContextHolder.getLocale());
                String products = errors.get(message).stream().collect(Collectors.joining(", "));
                if ((translatedMessage + products).length() < 255) {
                    view.addMessage("productFlowThruDivision.issue.downloadedProductsErrorMessages", ComponentState.MessageType.FAILURE, false, translatedMessage, products);
                }
            }
        }
    } else {
        view.addMessage("productFlowThruDivision.issue.noProductsToDownload", ComponentState.MessageType.INFO);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) java.util(java.util) DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) ProductsToIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields) IssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.IssueFields) ComponentState(com.qcadoo.view.api.ComponentState) QcadooViewConstants(com.qcadoo.view.constants.QcadooViewConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) OrderFields(com.qcadoo.mes.orders.constants.OrderFields) ProductionLineFields(com.qcadoo.mes.productionLines.constants.ProductionLineFields) Multimap(com.google.common.collect.Multimap) OrdersConstants(com.qcadoo.mes.orders.constants.OrdersConstants) DateUtils(com.qcadoo.localization.api.utils.DateUtils) BigDecimal(java.math.BigDecimal) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) WarehouseIssueService(com.qcadoo.mes.productFlowThruDivision.service.WarehouseIssueService) Service(org.springframework.stereotype.Service) FormComponent(com.qcadoo.view.api.components.FormComponent) WarehouseIssueFields(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields) WarehouseIssueHooks(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.hooks.WarehouseIssueHooks) WarehouseIssueParameterService(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService) TranslationService(com.qcadoo.localization.api.TranslationService) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponent(com.qcadoo.view.api.components.GridComponent) Entity(com.qcadoo.model.api.Entity) CollectionProducts(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.CollectionProducts) FieldComponent(com.qcadoo.view.api.components.FieldComponent) WarehouseIssueDetailHooks(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.hooks.WarehouseIssueDetailHooks) NumberService(com.qcadoo.model.api.NumberService) LookupComponent(com.qcadoo.view.api.components.LookupComponent) ProductFields(com.qcadoo.mes.basic.constants.ProductFields) ProductFlowThruDivisionConstants(com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants) IssueDetailsHooks(com.qcadoo.mes.productFlowThruDivision.warehouseIssue.hooks.IssueDetailsHooks) 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) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

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