public void quantityChange(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent form = (FormComponent) view.getComponentByReference("form"); Entity deliveredProductReservation = form.getEntity(); Entity deliveredProduct = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.DELIVERED_PRODUCT); BigDecimal conversion = deliveredProduct.getDecimalField(DeliveredProductFields.CONVERSION); Object deliveredQuantityRawValue = deliveredProductReservation.getField(DeliveredProductFields.DELIVERED_QUANTITY); Either<Exception, Optional<BigDecimal>> tryParseDeliveredQuantity = BigDecimalUtils.tryParseAndIgnoreSeparator(deliveredQuantityRawValue == null ? "" : deliveredQuantityRawValue.toString(), LocaleContextHolder.getLocale()); if (conversion != null && tryParseDeliveredQuantity.isRight() && tryParseDeliveredQuantity.getRight().isPresent()) { BigDecimal deliveredQuantity = tryParseDeliveredQuantity.getRight().get(); FieldComponent additionalQuantity = (FieldComponent) view.getComponentByReference(DeliveredProductReservationFields.ADDITIONAL_QUANTITY); BigDecimal newAdditionalQuantity = deliveredQuantity.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(); } }
public void additionalQuantityChange(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent form = (FormComponent) view.getComponentByReference("form"); Entity deliveredProductReservation = form.getEntity(); Entity deliveredProduct = deliveredProductReservation.getBelongsToField(DeliveredProductReservationFields.DELIVERED_PRODUCT); BigDecimal conversion = deliveredProduct.getDecimalField(DeliveredProductFields.CONVERSION); Object additionalQuantityRawValue = deliveredProductReservation.getField(DeliveredProductReservationFields.ADDITIONAL_QUANTITY); Either<Exception, Optional<BigDecimal>> tryParseAdditionalQuantity = BigDecimalUtils.tryParseAndIgnoreSeparator(additionalQuantityRawValue == null ? "" : additionalQuantityRawValue.toString(), LocaleContextHolder.getLocale()); if (conversion != null && tryParseAdditionalQuantity.isRight() && tryParseAdditionalQuantity.getRight().isPresent()) { BigDecimal additionalQuantity = tryParseAdditionalQuantity.getRight().get(); FieldComponent deliveredQuantity = (FieldComponent) view.getComponentByReference(DeliveredProductReservationFields.DELIVERED_QUANTITY); BigDecimal newDeliveredQuantity = additionalQuantity.divide(conversion, numberService.getMathContext()); newDeliveredQuantity = newDeliveredQuantity.setScale(NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, RoundingMode.HALF_UP); deliveredQuantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newDeliveredQuantity, 0)); deliveredQuantity.requestComponentUpdateState(); } }
public void additionalQuantityChange(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent form = (FormComponent) view.getComponentByReference("form"); Entity orderedProductReservation = form.getEntity(); Entity orderedProduct = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.ORDERED_PRODUCT); BigDecimal conversion = orderedProduct.getDecimalField(OrderedProductFields.CONVERSION); Object additionalQuantityRawValue = orderedProductReservation .getField(OrderedProductReservationFields.ADDITIONAL_QUANTITY); Either<Exception, Optional<BigDecimal>> tryParseAdditionalQuantity = BigDecimalUtils.tryParseAndIgnoreSeparator( additionalQuantityRawValue == null ? "" : additionalQuantityRawValue.toString(), LocaleContextHolder.getLocale()); if (conversion != null && tryParseAdditionalQuantity.isRight() && tryParseAdditionalQuantity.getRight().isPresent()) { BigDecimal additionalQuantity = tryParseAdditionalQuantity.getRight().get(); FieldComponent orderedQuantity = (FieldComponent) view .getComponentByReference(OrderedProductReservationFields.ORDERED_QUANTITY); BigDecimal newOrderedQuantity = calculationQuantityService.calculateQuantity(additionalQuantity, conversion, orderedProduct.getBelongsToField(OrderedProductFields.PRODUCT).getStringField(ProductFields.UNIT)); orderedQuantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newOrderedQuantity, 0)); orderedQuantity.requestComponentUpdateState(); } }
public void quantityChange(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent form = (FormComponent) view.getComponentByReference("form"); Entity orderedProductReservation = form.getEntity(); Entity orderedProduct = orderedProductReservation.getBelongsToField(OrderedProductReservationFields.ORDERED_PRODUCT); BigDecimal conversion = orderedProduct.getDecimalField(OrderedProductFields.CONVERSION); Object orderedQuantityRawValue = orderedProductReservation.getField(OrderedProductReservationFields.ORDERED_QUANTITY); Either<Exception, Optional<BigDecimal>> tryParseOrderedQuantity = BigDecimalUtils.tryParseAndIgnoreSeparator( orderedQuantityRawValue == null ? "" : orderedQuantityRawValue.toString(), LocaleContextHolder.getLocale()); if (conversion != null && tryParseOrderedQuantity.isRight() && tryParseOrderedQuantity.getRight().isPresent()) { BigDecimal orderedQuantity = tryParseOrderedQuantity.getRight().get(); FieldComponent additionalQuantity = (FieldComponent) view .getComponentByReference(OrderedProductReservationFields.ADDITIONAL_QUANTITY); BigDecimal newAdditionalQuantity = calculationQuantityService.calculateAdditionalQuantity(orderedQuantity, conversion, orderedProduct.getBelongsToField(OrderedProductFields.PRODUCT).getStringField(ProductFields.ADDITIONAL_UNIT)); additionalQuantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newAdditionalQuantity, 0)); additionalQuantity.requestComponentUpdateState(); } }
String newConversion = (String) conversionInput.getFieldValue(); Either<Exception, Optional<BigDecimal>> quantity = BigDecimalUtils.tryParseAndIgnoreSeparator(newQuantity, view.getLocale()); Either<Exception, Optional<BigDecimal>> price = BigDecimalUtils.tryParseAndIgnoreSeparator(newPrice, view.getLocale()); Either<Exception, Optional<BigDecimal>> conversion = BigDecimalUtils.tryParseAndIgnoreSeparator(newConversion, view.getLocale());
public void onQuantityChange(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { FieldComponent quantityField = (FieldComponent) viewDefinitionState.getComponentByReference(ResourceFields.QUANTITY); FieldComponent quantityInAdditionalUnitField = (FieldComponent) viewDefinitionState .getComponentByReference(ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT); FieldComponent additionalUnitField = (FieldComponent) viewDefinitionState .getComponentByReference(ResourceFields.GIVEN_UNIT); Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParseAndIgnoreSeparator( (String) quantityField.getFieldValue(), viewDefinitionState.getLocale()); if (maybeQuantity.isRight() && maybeQuantity.getRight().isPresent()) { FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference(L_FORM); Entity resource = form.getEntity(); BigDecimal newAdditionalQuantity = calculationQuantityService.calculateAdditionalQuantity(maybeQuantity.getRight() .get(), resource.getDecimalField(ResourceFields.CONVERSION), (String) additionalUnitField.getFieldValue()); String quantityInAdditionalUnitFormatted = numberService.format(newAdditionalQuantity); quantityInAdditionalUnitField.setFieldValue(quantityInAdditionalUnitFormatted); } else { quantityInAdditionalUnitField.setFieldValue(null); } }
public void onConversionChange(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { FieldComponent conversionField = (FieldComponent) viewDefinitionState.getComponentByReference(ResourceFields.CONVERSION); FieldComponent quantityInAdditionalUnitField = (FieldComponent) viewDefinitionState .getComponentByReference(ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT); FieldComponent additionalUnitField = (FieldComponent) viewDefinitionState .getComponentByReference(ResourceFields.GIVEN_UNIT); Either<Exception, Optional<BigDecimal>> maybeConversion = BigDecimalUtils.tryParseAndIgnoreSeparator( (String) conversionField.getFieldValue(), viewDefinitionState.getLocale()); if (maybeConversion.isRight() && maybeConversion.getRight().isPresent()) { FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference(L_FORM); Entity resource = form.getPersistedEntityWithIncludedFormValues(); BigDecimal newAdditionalQuantity = calculationQuantityService.calculateAdditionalQuantity( resource.getDecimalField(ResourceFields.QUANTITY), maybeConversion.getRight().get(), (String) additionalUnitField.getFieldValue()); String quantityInAdditionalUnitFormatted = numberService.format(newAdditionalQuantity); quantityInAdditionalUnitField.setFieldValue(quantityInAdditionalUnitFormatted); } else { quantityInAdditionalUnitField.setFieldValue(null); } }
public void onQuantityInAdditionalUnitChange(final ViewDefinitionState viewDefinitionState, final ComponentState state, final String[] args) { FieldComponent quantityField = (FieldComponent) viewDefinitionState.getComponentByReference(ResourceFields.QUANTITY); FieldComponent quantityInAdditionalUnitField = (FieldComponent) viewDefinitionState .getComponentByReference(ResourceFields.QUANTITY_IN_ADDITIONAL_UNIT); Either<Exception, Optional<BigDecimal>> maybeQuantityInAdditionalUnit = BigDecimalUtils.tryParseAndIgnoreSeparator( (String) quantityInAdditionalUnitField.getFieldValue(), viewDefinitionState.getLocale()); if (maybeQuantityInAdditionalUnit.isRight() && maybeQuantityInAdditionalUnit.getRight().isPresent()) { FormComponent form = (FormComponent) viewDefinitionState.getComponentByReference(L_FORM); Entity resource = form.getEntity(); BigDecimal conversion = resource.getDecimalField(ResourceFields.CONVERSION); Entity product = resource.getBelongsToField(ResourceFields.PRODUCT); BigDecimal quantity = calculationQuantityService.calculateQuantity(maybeQuantityInAdditionalUnit.getRight().get(), conversion, product.getStringField(ProductFields.UNIT)); String quantityFormatted = numberService.format(numberService.setScaleWithDefaultMathContext(quantity)); quantityField.setFieldValue(quantityFormatted); } else { quantityField.setFieldValue(null); } }