use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.
the class TrackingOperationProductInComponentDetailsListeners method onWasteUsedOnlyChange.
public void onWasteUsedOnlyChange(final ViewDefinitionState view, final ComponentState wasteUsedOnly, final String[] args) {
if (((CheckBoxComponent) wasteUsedOnly).isChecked()) {
Entity entity = getFormEntity(view);
Entity savedEntity = entity.getDataDefinition().get(entity.getId());
BigDecimal savedUsedQuantity = savedEntity.getDecimalField(TrackingOperationProductInComponentFields.USED_QUANTITY);
BigDecimal savedWasteUsed = convertNullToZero(savedEntity.getDecimalField(TrackingOperationProductInComponentFields.WASTE_USED_QUANTITY));
if (savedUsedQuantity != null && savedUsedQuantity.compareTo(BigDecimal.ZERO) > 0) {
FieldComponent usedQuantity = (FieldComponent) view.getComponentByReference(L_USED_QUANTITY);
FieldComponent wasteUsedQuantity = (FieldComponent) view.getComponentByReference(L_WASTE_USED_QUANTITY);
BigDecimal newValue = savedUsedQuantity.add(savedWasteUsed, numberService.getMathContext());
wasteUsedQuantity.setFieldValue(numberService.format(newValue));
usedQuantity.setFieldValue(numberService.format(BigDecimal.ZERO));
trackingOperationProductComponentDetailsListeners.calculateQuantityToGiven(view, usedQuantity, ArrayUtils.EMPTY_STRING_ARRAY);
}
}
}
use of com.qcadoo.view.api.components.CheckBoxComponent 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.CheckBoxComponent in project mes by qcadoo.
the class ProductionCountingParametersListeners method onReleaseOfMaterialsChange.
public void onReleaseOfMaterialsChange(final ViewDefinitionState view, final ComponentState state, final String[] args) {
CheckBoxComponent consumptionOfRawMaterialsBasedOnStandards = (CheckBoxComponent) view.getComponentByReference(ParameterFieldsPC.CONSUMPTION_OF_RAW_MATERIALS_BASED_ON_STANDARDS);
FieldComponent releaseOfMaterials = (FieldComponent) view.getComponentByReference(ParameterFieldsPC.RELEASE_OF_MATERIALS);
if (ReleaseOfMaterials.MANUALLY_TO_ORDER_OR_GROUP.getStringValue().equals(releaseOfMaterials.getFieldValue().toString())) {
consumptionOfRawMaterialsBasedOnStandards.setChecked(false);
consumptionOfRawMaterialsBasedOnStandards.setEnabled(false);
} else {
consumptionOfRawMaterialsBasedOnStandards.setEnabled(true);
}
}
use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.
the class AnomalyExplanationDetailsHooks method onBeforeRender.
public void onBeforeRender(final ViewDefinitionState view) {
FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity entity = form.getEntity();
if (view.isViewAfterRedirect()) {
initializeFormValues(view, entity);
}
boolean useWaste = ((CheckBoxComponent) view.getComponentByReference("useWaste")).isChecked();
LookupComponent productLookup = ((LookupComponent) view.getComponentByReference("product"));
productLookup.setEnabled(!useWaste);
view.getComponentByReference("location").setEnabled(!useWaste);
ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
String givenUnit = (String) givenUnitComponent.getFieldValue();
Entity selectedProduct = productLookup.getEntity();
boolean shouldAdditionalUnitBeEnabled = true;
if (selectedProduct != null) {
String selectedProductAdditionalUnit = selectedProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
if (isNotBlank(selectedProductAdditionalUnit) && isNotBlank(givenUnit) && selectedProductAdditionalUnit.equals(givenUnit)) {
shouldAdditionalUnitBeEnabled = false;
}
}
givenUnitComponent.setEnabled(shouldAdditionalUnitBeEnabled);
}
use of com.qcadoo.view.api.components.CheckBoxComponent in project mes by qcadoo.
the class AnomalyExplanationDetailsHooks method initializeFormValues.
private void initializeFormValues(ViewDefinitionState view, Entity entity) {
LookupComponent productLookup = ((LookupComponent) view.getComponentByReference("product"));
if (entity.getId() == null) {
Entity anomaly = entity.getBelongsToField(AnomalyExplanationFields.ANOMALY);
Entity anomalyProduct = anomaly.getBelongsToField(AnomalyFields.PRODUCT);
productLookup.setFieldValue(anomalyProduct.getId());
String selectedProductUnit = anomalyProduct.getStringField(ProductFields.UNIT);
String additionalSelectedProductUnit = anomalyProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
ComponentState givenUnitComponent = view.getComponentByReference("givenUnit");
if (isNotBlank(additionalSelectedProductUnit)) {
givenUnitComponent.setFieldValue(additionalSelectedProductUnit);
} else {
givenUnitComponent.setFieldValue(selectedProductUnit);
}
BigDecimal anomalyUsedQuantity = anomaly.getDecimalField(AnomalyFields.USED_QUANTITY);
view.getComponentByReference("usedQuantity").setFieldValue(numberService.formatWithMinimumFractionDigits(anomalyUsedQuantity, 0));
String additionalAnomalyProductUnit = anomalyProduct.getStringField(ProductFields.ADDITIONAL_UNIT);
ComponentState givenQuantityComponent = view.getComponentByReference("givenQuantity");
if (isNotBlank(additionalAnomalyProductUnit)) {
productUnitsConversionService.forProduct(anomalyProduct).fromPrimaryUnit().to(additionalAnomalyProductUnit).convertValue(anomalyUsedQuantity).ifPresent(convertedValue -> {
givenQuantityComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(convertedValue, 0));
});
} else {
givenQuantityComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(anomalyUsedQuantity, 0));
}
Entity anomalyLocation = anomaly.getBelongsToField(AnomalyFields.LOCATION);
view.getComponentByReference("location").setFieldValue(ofNullable(anomalyLocation).map(Entity::getId).orElse(null));
}
Entity selectedProduct = productLookup.getEntity();
ComponentState productUnit = view.getComponentByReference("productUnit");
ComponentState usedQuantity = view.getComponentByReference("usedQuantity");
if (selectedProduct != null) {
productUnit.setFieldValue(selectedProduct.getStringField(ProductFields.UNIT));
usedQuantity.setEnabled(true);
} else {
if (((CheckBoxComponent) view.getComponentByReference("useWaste")).isChecked()) {
productUnit.setFieldValue(entity.getStringField(AnomalyExplanationFields.GIVEN_UNIT));
} else {
productUnit.setFieldValue(null);
}
usedQuantity.setEnabled(false);
}
}
Aggregations