@Override public void parse(String cellValue, BindingErrorsAccessor errorsAccessor, Consumer<Object> valueConsumer) { Locale locale = LocaleContextHolder.getLocale(); if (validateDecimalFormat(cellValue, locale, errorsAccessor)) { Either<Exception, Optional<BigDecimal>> either = BigDecimalUtils.tryParse(cellValue, locale); if (either.isLeft()) { // This is very unlikely to happen as decimal string was already checked errorsAccessor.addError(ERROR_CODE_INVALID_NUMERIC_FORMAT); } else if (either.getRight().isPresent()) { valueConsumer.accept(either.getRight().get()); } } }
public void setCommissionedPlannedQuantity(final DataDefinition orderDD, final Entity order) { if (order == null) { return; } Object quantity = order.getField(OrderFields.PLANNED_QUANTITY); if (quantity != null) { if (BigDecimalUtils.tryParse(quantity.toString(), LocaleContextHolder.getLocale()).isRight()) { order.setField(OrderFields.COMMISSIONED_PLANNED_QUANTITY, numberService.setScaleWithDefaultMathContext(order.getDecimalField(OrderFields.PLANNED_QUANTITY))); } } }
private boolean transferQuantityIsNonEmptyDecimalValue(final Entity transfer) { Either<Exception, Optional<BigDecimal>> quantity = BigDecimalUtils.tryParse( ObjectUtils.toString(transfer.getField(TransferFields.QUANTITY)), LocaleContextHolder.getLocale()); if (quantity.isLeft()) { appendErrorToModelField(transfer, QUANTITY, "qcadooView.validate.field.error.invalidNumericFormat"); return false; } if (!quantity.getRight().isPresent()) { appendErrorToModelField(transfer, QUANTITY, "materialFlow.validate.global.error.fillRequired"); return false; } return true; }
public void fillQuantitiesInAdditionalUnit(final ViewDefinitionState view) { AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("corrections"); for (FormComponent form : adl.getFormComponents()) { Entity correction = form.getPersistedEntityWithIncludedFormValues(); FieldComponent quantityField = form.findFieldComponentByName(ProductToIssueCorrectionFields.CORRECTION_QUANTITY); Either<Exception, com.google.common.base.Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse(quantityField.getFieldValue() .toString(), LocaleContextHolder.getLocale()); BigDecimal quantityAdditionalUnit = BigDecimal.ZERO; BigDecimal conversion = correction.getDecimalField(IssueFields.CONVERSION); if (conversion != null && maybeQuantity.isRight() && maybeQuantity.getRight().isPresent()) { BigDecimal correctionQuantity = maybeQuantity.getRight().get(); quantityAdditionalUnit = numberService.setScaleWithDefaultMathContext(correctionQuantity.multiply(conversion, numberService.getMathContext())); correction.setField(ProductToIssueCorrectionFields.CORRECTION_QUANTITY_IN_ADDITIONAL_UNIT, quantityAdditionalUnit); form.setEntity(correction); } } }
public void fillQuantitiesInAdditionalUnit(final ViewDefinitionState view) { AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("issues"); for (FormComponent form : adl.getFormComponents()) { Entity issue = form.getPersistedEntityWithIncludedFormValues(); FieldComponent quantityField = form.findFieldComponentByName("issueQuantity"); Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse(quantityField.getFieldValue() .toString(), LocaleContextHolder.getLocale()); BigDecimal conversion = issue.getDecimalField(IssueFields.CONVERSION); if (conversion != null && maybeQuantity.isRight() && maybeQuantity.getRight().isPresent()) { Entity product = issue.getBelongsToField(IssueFields.PRODUCT); String unit = product.getStringField(ProductFields.UNIT); String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT); BigDecimal issueQuantity = maybeQuantity.getRight().get(); BigDecimal issuedQuantityAdditionalUnit = calculationQuantityService.calculateAdditionalQuantity(issueQuantity, conversion, Optional.fromNullable(additionalUnit).or(unit)); issue.setField(IssueFields.ISSUE_QUANTITY_ADDITIONAL_UNIT, issuedQuantityAdditionalUnit); form.setEntity(issue); } } }
private void roundResults(final ViewDefinitionState view) { Set<String> referenceNames = Sets.newHashSet(CostCalculationFields.TOTAL_MATERIAL_COSTS, CostCalculationFields.TOTAL_MACHINE_HOURLY_COSTS, CostCalculationFields.TOTAL_LABOR_HOURLY_COSTS, CostCalculationFields.TOTAL_PIECEWORK_COSTS, CostCalculationFields.TOTAL_TECHNICAL_PRODUCTION_COSTS, CostCalculationFields.PRODUCTION_COST_MARGIN_VALUE, CostCalculationFields.MATERIAL_COST_MARGIN_VALUE, CostCalculationFields.ADDITIONAL_OVERHEAD_VALUE, CostCalculationFields.TOTAL_OVERHEAD, CostCalculationFields.TOTAL_COSTS, CostCalculationFields.TOTAL_COST_PER_UNIT, CostCalculationFields.REGISTRATION_PRICE_OVERHEAD_VALUE, CostCalculationFields.TECHNICAL_PRODUCTION_COSTS, CostCalculationFields.PROFIT_VALUE, CostCalculationFields.SELL_PRICE_VALUE); for (String name : referenceNames) { FieldComponent component = (FieldComponent) view.getComponentByReference(name); String value = (String) component.getFieldValue(); Either<Exception, Optional<BigDecimal>> eitherValue = BigDecimalUtils.tryParse(value, view.getLocale()); if (eitherValue.isRight()) { Optional<BigDecimal> maybeValue = eitherValue.getRight(); if (maybeValue.isPresent()) { component.setFieldValue(numbersService.format(numbersService.setScaleWithDefaultMathContext(maybeValue.get(), 2))); component.requestComponentUpdateState(); } } } }
.tryParse((String) thisQuantityField.getFieldValue(), view.getLocale());
public void quantityChanged(final ViewDefinitionState view, final ComponentState state, final String[] args) { AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("issues"); List<FormComponent> formComponenets = adl.getFormComponents(); for (FormComponent formComponent : formComponenets) { Entity formEntity = formComponent.getPersistedEntityWithIncludedFormValues(); FieldComponent quantityField = formComponent.findFieldComponentByName("issueQuantity"); BigDecimal conversion = formEntity.getDecimalField(IssueFields.CONVERSION); FieldComponent additionalQuantity = formComponent.findFieldComponentByName("issueQuantityAdditionalUnit"); 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); } } } }
public void additionalQuantityChanged(final ViewDefinitionState view, final ComponentState state, final String[] args) { AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("issues"); List<FormComponent> formComponenets = adl.getFormComponents(); for (FormComponent formComponent : formComponenets) { FieldComponent additionalQuantityField = formComponent.findFieldComponentByName("issueQuantityAdditionalUnit"); Entity formEntity = formComponent.getPersistedEntityWithIncludedFormValues(); BigDecimal conversion = formEntity.getDecimalField(IssueFields.CONVERSION); FieldComponent quantity = formComponent.findFieldComponentByName("issueQuantity"); if (additionalQuantityField.getUuid().equals(state.getUuid())) { Either<Exception, com.google.common.base.Optional<BigDecimal>> maybeAdditionalQuantity = BigDecimalUtils .tryParse(additionalQuantityField.getFieldValue().toString(), LocaleContextHolder.getLocale()); if (conversion != null && maybeAdditionalQuantity.isRight() && maybeAdditionalQuantity.getRight().isPresent()) { BigDecimal additionalQuantity = maybeAdditionalQuantity.getRight().get(); BigDecimal newQuantity = additionalQuantity.divide(conversion, numberService.getMathContext()); newQuantity = newQuantity.setScale(NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, RoundingMode.HALF_UP); quantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newQuantity, 0)); quantity.requestComponentUpdateState(); } else if (maybeAdditionalQuantity.isLeft()) { additionalQuantityField.setFieldValue(quantity.getFieldValue()); additionalQuantityField.addMessage( "productFlowThruDivision.productsToIssueHelperDetails.error.invalidQuantity", ComponentState.MessageType.FAILURE); } } } }
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); } } } }
private void calculateQuantityFromSets(ViewDefinitionState view) { FieldComponent usedQuantityField = (FieldComponent) view.getComponentByReference("usedQuantity"); Either<Exception, Optional<BigDecimal>> usedQuantity = BigDecimalUtils .tryParse((String) usedQuantityField.getFieldValue(), view.getLocale()); FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); Entity trackingOperationProductOutComponent = form.getPersistedEntityWithIncludedFormValues(); trackingOperationProductOutComponent = setTrackingOperationProductsComponents .recalculateTrackingOperationProductOutComponent( trackingOperationProductOutComponent.getBelongsToField("productionTracking"), trackingOperationProductOutComponent, usedQuantity.getRight().or(BigDecimal.ZERO)); GridComponent gridComponent = (GridComponent) view.getComponentByReference("setTrackingOperationProductsInComponents"); gridComponent.setEntities(trackingOperationProductOutComponent .getHasManyField(TrackingOperationProductOutComponentFields.SET_TRACKING_OPERATION_PRODUCTS_IN_COMPONENTS)); }
public void additionalQuantityChanged(final ViewDefinitionState view, final ComponentState state, final String[] args) { AwesomeDynamicListComponent adl = (AwesomeDynamicListComponent) view.getComponentByReference("corrections"); List<FormComponent> formComponenets = adl.getFormComponents(); for (FormComponent formComponent : formComponenets) { FieldComponent additionalQuantityField = formComponent.findFieldComponentByName("correctionQuantityInAdditionalUnit"); Entity formEntity = formComponent.getPersistedEntityWithIncludedFormValues(); BigDecimal conversion = formEntity.getDecimalField(ProductToIssueCorrectionFields.CONVERSION); FieldComponent quantity = formComponent.findFieldComponentByName("correctionQuantity"); if (additionalQuantityField.getUuid().equals(state.getUuid())) { Either<Exception, com.google.common.base.Optional<BigDecimal>> maybeAdditionalQuantity = BigDecimalUtils .tryParse(additionalQuantityField.getFieldValue().toString(), LocaleContextHolder.getLocale()); if (conversion != null && maybeAdditionalQuantity.isRight() && maybeAdditionalQuantity.getRight().isPresent()) { BigDecimal additionalQuantity = maybeAdditionalQuantity.getRight().get(); BigDecimal newQuantity = additionalQuantity.divide(conversion, numberService.getMathContext()); newQuantity = newQuantity .setScale(NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, RoundingMode.HALF_UP); quantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newQuantity, 0)); quantity.requestComponentUpdateState(); } else if (maybeAdditionalQuantity.isLeft()) { additionalQuantityField.setFieldValue(quantity.getFieldValue()); additionalQuantityField.addMessage( "productFlowThruDivision.productsToIssueHelperDetails.error.invalidQuantity", ComponentState.MessageType.FAILURE); } else { quantity.setFieldValue(null); } } } }
private void calculateQuantityFromSetsIn(ViewDefinitionState view) { FormComponent form = (FormComponent) view.getComponentByReference(L_FORM); Entity trackingOperationProductOutComponent = form.getPersistedEntityWithIncludedFormValues(); if (setTechnologyInComponentsService.isSet(trackingOperationProductOutComponent)) { FieldComponent usedQuantityField = (FieldComponent) view.getComponentByReference("usedQuantity"); Either<Exception, Optional<BigDecimal>> usedQuantity = BigDecimalUtils .tryParse((String) usedQuantityField.getFieldValue(), view.getLocale()); Entity productionTracking = trackingOperationProductOutComponent .getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCTION_TRACKING); trackingOperationProductOutComponent = setTechnologyInComponentsService.fillTrackingOperationProductOutComponent( trackingOperationProductOutComponent, productionTracking, usedQuantity.getRight().or(BigDecimal.ZERO)); GridComponent gridComponent = (GridComponent) view.getComponentByReference("setTechnologyInComponents"); gridComponent.setEntities(trackingOperationProductOutComponent .getHasManyField(TrackingOperationProductInComponentFields.SET_TECHNOLOGY_IN_COMPONENTS)); } }
.tryParse((String) givenQuantityField.getFieldValue(), view.getLocale()); if (maybeQuantity.isRight()) { if (maybeQuantity.getRight().isPresent()) {
.tryParse((String) givenQuantityField.getFieldValue(), view.getLocale()); if (maybeQuantity.isRight()) { if (maybeQuantity.getRight().isPresent()) {
Either<Exception, Optional<BigDecimal>> maybeQuantity = BigDecimalUtils.tryParse((String) quantityField.getFieldValue(), view.getLocale()); if (maybeQuantity.isRight()) {