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);
}
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);
}
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);
}
}
}
}
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);
}
}
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);
}
}
Aggregations