use of com.qcadoo.view.api.components.AwesomeDynamicListComponent in project mes by qcadoo.
the class ProductToIssueCorrectionDetailsListeners method quantityChanged.
public void quantityChanged(final ViewDefinitionState view, final ComponentState state, final String[] args) {
AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("corrections");
List<FormComponent> formComponenets = adl.getFormComponents();
for (FormComponent formComponent : formComponenets) {
Entity formEntity = formComponent.getPersistedEntityWithIncludedFormValues();
FieldComponent quantityField = formComponent.findFieldComponentByName("correctionQuantity");
BigDecimal conversion = formEntity.getDecimalField(ProductToIssueCorrectionFields.CONVERSION);
FieldComponent additionalQuantity = formComponent.findFieldComponentByName("correctionQuantityInAdditionalUnit");
if (quantityField.getUuid().equals(state.getUuid())) {
Either<Exception, com.google.common.base.Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse(quantityField.getFieldValue().toString(), LocaleContextHolder.getLocale());
if (conversion != null && maybeQuantity.isRight() && maybeQuantity.getRight().isPresent()) {
BigDecimal quantity = maybeQuantity.getRight().get();
BigDecimal newAdditionalQuantity = quantity.multiply(conversion, numberService.getMathContext());
newAdditionalQuantity = newAdditionalQuantity.setScale(NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, RoundingMode.HALF_UP);
additionalQuantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newAdditionalQuantity, 0));
additionalQuantity.requestComponentUpdateState();
} else if (maybeQuantity.isLeft()) {
quantityField.setFieldValue(additionalQuantity.getFieldValue());
quantityField.addMessage("productFlowThruDivision.productsToIssueHelperDetails.error.invalidQuantity", ComponentState.MessageType.FAILURE);
} else {
additionalQuantity.setFieldValue(null);
}
}
}
}
Aggregations