Search in sources :

Example 36 with AwesomeDynamicListComponent

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);
            }
        }
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) FieldComponent(com.qcadoo.view.api.components.FieldComponent) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) BigDecimal(java.math.BigDecimal)

Aggregations

AwesomeDynamicListComponent (com.qcadoo.view.api.components.AwesomeDynamicListComponent)36 FormComponent (com.qcadoo.view.api.components.FormComponent)26 Entity (com.qcadoo.model.api.Entity)24 FieldComponent (com.qcadoo.view.api.components.FieldComponent)12 BigDecimal (java.math.BigDecimal)6 ProgressType (com.qcadoo.mes.productionPerShift.constants.ProgressType)4 LookupComponent (com.qcadoo.view.api.components.LookupComponent)4 Optional (com.google.common.base.Optional)2 OrderState (com.qcadoo.mes.orders.states.constants.OrderState)2 CheckBoxComponent (com.qcadoo.view.api.components.CheckBoxComponent)2 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)2 Function (com.google.common.base.Function)1 DataDefinition (com.qcadoo.model.api.DataDefinition)1 EntityRuntimeException (com.qcadoo.model.api.exception.EntityRuntimeException)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 BigInteger (java.math.BigInteger)1 Around (org.aspectj.lang.annotation.Around)1 JSONException (org.json.JSONException)1 Transactional (org.springframework.transaction.annotation.Transactional)1