Search in sources :

Example 6 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class IssueCommonDetailsHelper method setFilterValue.

public void setFilterValue(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity productToIssue = form.getPersistedEntityWithIncludedFormValues();
    Entity product = productToIssue.getBelongsToField(ProductsToIssueFields.PRODUCT);
    Entity warehouse = productToIssue.getBelongsToField(ProductsToIssueFields.LOCATION);
    LookupComponent storageLocationLookup = (LookupComponent) view.getComponentByReference(IssueCommonDetailsHelper.STORAGE_LOCATION);
    FilterValueHolder filter = storageLocationLookup.getFilterValue();
    LookupComponent additionalCodeLookup = (LookupComponent) view.getComponentByReference(ADDITIONAL_CODE);
    FilterValueHolder additionalCodeFilter = additionalCodeLookup.getFilterValue();
    if (product != null) {
        filter.put(PRODUCT, product.getId());
        additionalCodeFilter.put(PRODUCT, product.getId());
    } else if (filter.has(PRODUCT)) {
        filter.remove(PRODUCT);
        additionalCodeFilter.remove(PRODUCT);
    }
    if (warehouse != null) {
        filter.remove(LOCATION);
        filter.put(LOCATION, warehouse.getId());
    }
    storageLocationLookup.setFilterValue(filter);
    additionalCodeLookup.setFilterValue(additionalCodeFilter);
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Example 7 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder 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 8 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class UseReplacementHooks method fillFields.

private void fillFields(ViewDefinitionState view) {
    if (view.isViewAfterRedirect()) {
        JSONObject context = view.getJsonContext();
        LookupComponent basicProductComponent = (LookupComponent) view.getComponentByReference(BASIC_PRODUCT);
        LookupComponent productComponent = (LookupComponent) view.getComponentByReference(PRODUCT);
        if (context.has(L_WINDOW_MAIN_TAB_FORM_BASIC_PRODUCT)) {
            try {
                basicProductComponent.setFieldValue(context.getLong(L_WINDOW_MAIN_TAB_FORM_BASIC_PRODUCT));
                FilterValueHolder filterValueHolder = productComponent.getFilterValue();
                filterValueHolder.put("BASIC_PRODUCT_ID", context.getLong(L_WINDOW_MAIN_TAB_FORM_BASIC_PRODUCT));
                productComponent.setFilterValue(filterValueHolder);
            } catch (JSONException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) JSONObject(org.json.JSONObject) LookupComponent(com.qcadoo.view.api.components.LookupComponent) JSONException(org.json.JSONException)

Example 9 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class UsedBatchDetailsHooks method onBeforeRender.

public void onBeforeRender(final ViewDefinitionState view) {
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity usedBatch = form.getEntity();
    Entity trackingOperationProductInComponent = usedBatch.getBelongsToField(UsedBatchFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENT);
    if (view.isViewAfterRedirect() && Objects.nonNull(trackingOperationProductInComponent)) {
        Entity product = trackingOperationProductInComponent.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
        FieldComponent unitField = (FieldComponent) view.getComponentByReference(L_UNIT);
        unitField.setFieldValue(product.getStringField(ProductFields.UNIT));
        unitField.requestComponentUpdateState();
        LookupComponent batchLookup = (LookupComponent) view.getComponentByReference(UsedBatchFields.BATCH);
        FilterValueHolder batchFilterValueHolder = batchLookup.getFilterValue();
        batchFilterValueHolder.put(L_PRODUCT_ID, product.getId());
        batchLookup.setFilterValue(batchFilterValueHolder);
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) 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)

Example 10 with FilterValueHolder

use of com.qcadoo.view.api.components.lookup.FilterValueHolder in project mes by qcadoo.

the class TrackingOperationProductOutComponentDetailsHooks method fillStorageLocation.

private void fillStorageLocation(final ViewDefinitionState view) {
    FormComponent trackingOperationProductOutComponentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity trackingOperationProductOutComponent = trackingOperationProductOutComponentForm.getEntity();
    if (view.isViewAfterRedirect()) {
        LookupComponent storageLocationLookup = (LookupComponent) view.getComponentByReference(L_STORAGE_LOCATION);
        Entity productionTracking = trackingOperationProductOutComponent.getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCTION_TRACKING);
        Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
        Entity product = trackingOperationProductOutComponent.getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCT);
        FilterValueHolder storageLocationFilterValueHolder = storageLocationLookup.getFilterValue();
        Entity bpcq = basicProductionCountingService.getProductionCountingQuantityDD().find().add(SearchRestrictions.eq(ProductionCountingQuantityFields.ORDER + L_ID, order.getId())).add(SearchRestrictions.eq(ProductionCountingQuantityFields.ROLE, ProductionCountingQuantityRole.PRODUCED.getStringValue())).add(SearchRestrictions.eq(ProductionCountingQuantityFields.PRODUCT + L_ID, product.getId())).setMaxResults(1).uniqueResult();
        if (ProductionCountingQuantityTypeOfMaterial.FINAL_PRODUCT.getStringValue().equals(bpcq.getStringField(ProductionCountingQuantityFields.TYPE_OF_MATERIAL))) {
            if (Objects.nonNull(bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_INPUT_LOCATION))) {
                storageLocationFilterValueHolder.put(L_LOCATION_ID, bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_INPUT_LOCATION).getId());
                storageLocationFilterValueHolder.put(L_PRODUCT_ID, order.getBelongsToField(OrderFields.PRODUCT).getId());
                Optional<Entity> option = findStorageLocationForProduct(order.getBelongsToField(OrderFields.PRODUCT), bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_INPUT_LOCATION));
                if (option.isPresent()) {
                    if (Objects.isNull(storageLocationLookup.getEntity())) {
                        storageLocationLookup.setFieldValue(option.get().getId());
                        storageLocationLookup.requestComponentUpdateState();
                    }
                    storageLocationLookup.setEnabled(false);
                }
            } else if (storageLocationFilterValueHolder.has(L_LOCATION_ID)) {
                storageLocationFilterValueHolder.remove(L_LOCATION_ID);
            }
        } else {
            if (Objects.nonNull(bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_FLOW_LOCATION))) {
                storageLocationFilterValueHolder.put(L_LOCATION_ID, bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_FLOW_LOCATION).getId());
                storageLocationFilterValueHolder.put(L_PRODUCT_ID, bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCT).getId());
                Optional<Entity> option = findStorageLocationForProduct(bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCT), bpcq.getBelongsToField(ProductionCountingQuantityFields.PRODUCTS_FLOW_LOCATION));
                if (option.isPresent()) {
                    if (Objects.isNull(storageLocationLookup.getEntity())) {
                        storageLocationLookup.setFieldValue(option.get().getId());
                        storageLocationLookup.requestComponentUpdateState();
                    }
                    storageLocationLookup.setEnabled(false);
                }
            } else if (storageLocationFilterValueHolder.has(L_LOCATION_ID)) {
                storageLocationFilterValueHolder.remove(L_LOCATION_ID);
            }
        }
        storageLocationLookup.setFilterValue(storageLocationFilterValueHolder);
    }
}
Also used : FilterValueHolder(com.qcadoo.view.api.components.lookup.FilterValueHolder) FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) LookupComponent(com.qcadoo.view.api.components.LookupComponent)

Aggregations

FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)119 LookupComponent (com.qcadoo.view.api.components.LookupComponent)69 Entity (com.qcadoo.model.api.Entity)64 FormComponent (com.qcadoo.view.api.components.FormComponent)45 GridComponent (com.qcadoo.view.api.components.GridComponent)26 FieldComponent (com.qcadoo.view.api.components.FieldComponent)13 Collectors (java.util.stream.Collectors)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Service (org.springframework.stereotype.Service)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 Objects (java.util.Objects)10 DataDefinition (com.qcadoo.model.api.DataDefinition)9 JSONObject (org.json.JSONObject)9 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)8 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)8 EntityList (com.qcadoo.model.api.EntityList)8 SecurityService (com.qcadoo.security.api.SecurityService)8 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)8