use of com.qcadoo.view.api.components.FormComponent 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);
}
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class TrackingOperationProductComponentDetailsListeners method calculateQuantityToGiven.
public void calculateQuantityToGiven(final ViewDefinitionState view, final ComponentState componentState, final String[] args) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity productComponent = form.getPersistedEntityWithIncludedFormValues();
Entity product = productComponent.getBelongsToField(TrackingOperationProductInComponentFields.PRODUCT);
if (product == null) {
return;
}
String unit = product.getStringField(ProductFields.UNIT);
FieldComponent quantityField = (FieldComponent) view.getComponentByReference(TrackingOperationProductInComponentFields.USED_QUANTITY);
if (StringUtils.isEmpty(unit) || quantityField.getFieldValue() == null) {
return;
}
Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse((String) quantityField.getFieldValue(), view.getLocale());
if (maybeQuantity.isRight()) {
if (maybeQuantity.getRight().isPresent()) {
BigDecimal quantity = maybeQuantity.getRight().get();
String givenUnit = productComponent.getStringField(TrackingOperationProductInComponentFields.GIVEN_UNIT);
if (givenUnit.equals(unit)) {
productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, quantity);
} else {
PossibleUnitConversions unitConversions = unitConversionService.getPossibleConversions(unit, searchCriteriaBuilder -> searchCriteriaBuilder.add(SearchRestrictions.belongsTo(UnitConversionItemFieldsB.PRODUCT, product)));
if (unitConversions.isDefinedFor(givenUnit)) {
BigDecimal convertedQuantity = unitConversions.convertTo(quantity, givenUnit, BigDecimal.ROUND_FLOOR);
productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, convertedQuantity);
} else {
productComponent.addError(productComponent.getDataDefinition().getField(TrackingOperationProductInComponentFields.USED_QUANTITY), "technologies.operationProductInComponent.validate.error.missingUnitConversion");
productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, null);
}
}
} else {
productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, null);
}
} else {
productComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, null);
}
form.setEntity(productComponent);
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class UseReplacementListeners method addReplacement.
public void addReplacement(final ViewDefinitionState view, final ComponentState state, final String[] args) throws JSONException {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
CheckBoxComponent generated = (CheckBoxComponent) view.getComponentByReference("generated");
generated.setChecked(false);
Entity entity = form.getPersistedEntityWithIncludedFormValues();
entity = entity.getDataDefinition().validate(entity);
if (!entity.isValid()) {
form.setEntity(entity);
return;
}
JSONObject context = view.getJsonContext();
Long productionTrackingId = context.getLong(WINDOW_MAIN_TAB_FORM_PRODUCTION_TRACKING);
Long basicProductId = context.getLong(L_WINDOW_MAIN_TAB_FORM_BASIC_PRODUCT);
Entity productionTracking = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING).get(productionTrackingId);
Entity productIn = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_TRACKING_OPERATION_PRODUCT_IN_COMPONENT).find().add(SearchRestrictions.belongsTo(TrackingOperationProductInComponentFields.PRODUCTION_TRACKING, productionTracking)).add(SearchRestrictions.belongsTo(TrackingOperationProductInComponentFields.PRODUCT, entity.getBelongsToField(PRODUCT))).setMaxResults(1).uniqueResult();
if (Objects.isNull(productIn)) {
Entity in = createInProductTracking(entity, productionTracking, basicProductId);
if (!in.isValid()) {
view.addMessage("productionCounting.useReplacement.error", ComponentState.MessageType.FAILURE);
} else {
generated.setChecked(true);
}
} else {
view.addMessage("productionCounting.useReplacement.productExists", ComponentState.MessageType.FAILURE, false);
}
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class ProductDetailsListenersPC method showProductionTrackingsForProductGrouped.
public void showProductionTrackingsForProductGrouped(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent productForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity product = productForm.getEntity();
if (product.getId() == null) {
return;
}
StringBuilder productNumberBuilder = new StringBuilder();
productNumberBuilder.append("[");
productNumberBuilder.append(product.getStringField(ProductFields.NUMBER));
productNumberBuilder.append("]");
String productNumber = productNumberBuilder.toString();
Map<String, String> filters = Maps.newHashMap();
filters.put("productNumber", productNumber);
Map<String, Object> gridOptions = Maps.newHashMap();
gridOptions.put(L_FILTERS, filters);
Map<String, Object> parameters = Maps.newHashMap();
parameters.put(L_GRID_OPTIONS, gridOptions);
parameters.put(L_WINDOW_ACTIVE_MENU, "ordersTracking.productionTrackingForProductGrouped");
String url = "../page/productionCounting/productionTrackingsForProductGroupedList.html";
view.redirectTo(url, false, true, parameters);
}
use of com.qcadoo.view.api.components.FormComponent in project mes by qcadoo.
the class ProductDetailsListenersPC method showProductionTrackingsForProduct.
public void showProductionTrackingsForProduct(final ViewDefinitionState view, final ComponentState state, final String[] args) {
FormComponent productForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity product = productForm.getEntity();
if (product.getId() == null) {
return;
}
StringBuilder productNumberBuilder = new StringBuilder();
productNumberBuilder.append("[");
productNumberBuilder.append(product.getStringField(ProductFields.NUMBER));
productNumberBuilder.append("]");
String productNumber = productNumberBuilder.toString();
Map<String, String> filters = Maps.newHashMap();
filters.put("productNumber", productNumber);
Map<String, Object> gridOptions = Maps.newHashMap();
gridOptions.put(L_FILTERS, filters);
Map<String, Object> parameters = Maps.newHashMap();
parameters.put(L_GRID_OPTIONS, gridOptions);
parameters.put(L_WINDOW_ACTIVE_MENU, "ordersTracking.productionTrackingForProduct");
String url = "../page/productionCounting/productionTrackingsForProductList.html";
view.redirectTo(url, false, true, parameters);
}
Aggregations