private BigDecimal multiply(final BigDecimal value, final BigDecimal factor) { if (value == null || factor == null) { return BigDecimal.ZERO; } return numberService.setScaleWithDefaultMathContext(value.multiply(factor, numberService.getMathContext())); }
private void fillCoveredQuantity(final Map<Entity, Map<String, String>> values, final Entity coverageProduct) { BigDecimal coveredQuantity = null; if (coverageProduct == null) { coveredQuantity = BigDecimal.ZERO; } else { coveredQuantity = coverageProduct.getDecimalField(CoverageProductFields.COVERED_QUANTITY); } values.get(coverageProduct).put("coveredQuantity", numberService.format(coveredQuantity)); }
private void showQuantitiesDeviationNotice(final ViewDefinitionState view, final BigDecimal quantitiesDifference, final String messageKey) { for (ComponentState productionPerShiftForm : view.tryFindComponentByReference("form").asSet()) { productionPerShiftForm.addMessage(messageKey, ComponentState.MessageType.INFO, false, numberService.formatWithMinimumFractionDigits(quantitiesDifference.abs(numberService.getMathContext()), 0)); } }
@Override public String getColumnValue(Entity operationProduct) { return String.valueOf(numberService.format(numberService.setScaleWithDefaultMathContext(operationProduct .getDecimalField(OperationProductInComponentFields.QUANTITY)))); }
private BigDecimal calculatePricePerUnit(final BigDecimal quantity, final BigDecimal totalPrice) { BigDecimal pricePerUnit = BigDecimal.ZERO; if ((quantity == null) || (BigDecimal.ZERO.compareTo(quantity) == 0)) { pricePerUnit = null; } else { pricePerUnit = totalPrice.divide(quantity, numberService.getMathContext()); } return pricePerUnit; }
public BigDecimal calculateQuantity(BigDecimal additionalQuantity, BigDecimal conversion, String unit) { BigDecimal quantity = additionalQuantity.divide(conversion, NumberService.DEFAULT_MAX_FRACTION_DIGITS_IN_DECIMAL, BigDecimal.ROUND_FLOOR); if (dictionaryService.checkIfUnitIsInteger(unit)) { return numberService.setScaleWithDefaultMathContext(quantity, 0); } return numberService.setScaleWithDefaultMathContext(quantity); }
private void calculatePriceUsingTotalCost(final ViewDefinitionState view, FieldComponent quantityField, FieldComponent totalPriceField) { FieldComponent pricePerUnitField = (FieldComponent) view.getComponentByReference(L_PRICE_PER_UNIT); Locale locale = view.getLocale(); BigDecimal quantity = getBigDecimalFromField(quantityField, locale); BigDecimal totalPrice = getBigDecimalFromField(totalPriceField, locale); BigDecimal pricePerUnit = numberService.setScaleWithDefaultMathContext(totalPrice.divide(quantity, numberService.getMathContext())); pricePerUnitField.setFieldValue(numberService.format(pricePerUnit)); pricePerUnitField.requestComponentUpdateState(); }
private String extractQuantity(Resource resource) { if (Objects.isNull(resource.getQuantity())) { return ""; } else if (isIntegerValue(resource.getQuantity())) { return numberService.formatWithMinimumFractionDigits(resource.getQuantity(), 0); } else { return numberService.formatWithMinimumFractionDigits( numberService.setScaleWithDefaultMathContext(resource.getQuantity(), 1), 1); } }
public static String getValue(NumberService numberService, BigDecimal value) { if (value == null) { return ""; } return numberService.formatWithMinimumFractionDigits(value, 0); }
private BigDecimal calculateTotalPrice(final BigDecimal quantity, final BigDecimal pricePerUnit) { BigDecimal totalPrice = BigDecimal.ZERO; if ((quantity == null) || (BigDecimal.ZERO.compareTo(quantity) == 0)) { totalPrice = BigDecimal.ZERO; } else { totalPrice = pricePerUnit.multiply(quantity, numberService.getMathContext()); } return totalPrice; }
private Entity createOfferProduct(final Entity requestForQuotationProduct) { Entity offerProduct = supplyNegotiationsService.getOfferProductDD().create(); offerProduct.setField(PRODUCT, requestForQuotationProduct.getBelongsToField(PRODUCT)); offerProduct.setField(QUANTITY, numberService.setScaleWithDefaultMathContext(requestForQuotationProduct.getDecimalField(ORDERED_QUANTITY))); offerProduct.setField(TOTAL_PRICE, numberService.setScaleWithDefaultMathContext(BigDecimal.ZERO)); offerProduct.setField(PRICE_PER_UNIT, numberService.setScaleWithDefaultMathContext(BigDecimal.ZERO)); return offerProduct; }
private void calculatePriceUsingPricePerUnit(final ViewDefinitionState view, FieldComponent quantityField, FieldComponent pricePerUnitField) { FieldComponent totalPriceField = (FieldComponent) view.getComponentByReference(L_TOTAL_PRICE); Locale locale = view.getLocale(); BigDecimal pricePerUnit = getBigDecimalFromField(pricePerUnitField, locale); BigDecimal quantity = getBigDecimalFromField(quantityField, locale); BigDecimal totalPrice = numberService.setScaleWithDefaultMathContext(pricePerUnit.multiply(quantity, numberService.getMathContext())); totalPriceField.setFieldValue(numberService.format(totalPrice)); totalPriceField.requestComponentUpdateState(); }
private String extractQuantityInAdditionalUnit(Resource resource) { if (Objects.isNull(resource.getQuantityInAdditionalUnit())) { return ""; } else if (isIntegerValue(resource.getQuantityInAdditionalUnit())) { return numberService.formatWithMinimumFractionDigits(resource.getQuantityInAdditionalUnit(), 0); } else { return numberService.formatWithMinimumFractionDigits( numberService.setScaleWithDefaultMathContext(resource.getQuantityInAdditionalUnit(), 1), 1); } }
@Override public String getColumnValue(Entity operationProduct) { List<Entity> orders = operationProduct.getBelongsToField(OperationProductInComponentFields.OPERATION_COMPONENT) .getBelongsToField(TechnologyOperationComponentFields.TECHNOLOGY).getHasManyField(TechnologyFieldsO.ORDERS); BigDecimal quantity = operationProduct.getDecimalField(OperationProductInComponentFields.QUANTITY); if (orders.isEmpty() || quantity == null) { return StringUtils.EMPTY; } return String.valueOf(numberService.format(numberService.setScaleWithDefaultMathContext(quantity.divide( orders.get(0).getDecimalField(OrderFields.PLANNED_QUANTITY), RoundingMode.HALF_UP)))); }
private String getDecimalValue(BigDecimal value) { if (value == null) { return ""; } return numberService.formatWithMinimumFractionDigits(value, 0); }
public BigDecimal calculateAdditionalQuantity(BigDecimal quantity, BigDecimal conversion, String unit) { BigDecimal additionalQuantity = quantity.multiply(conversion, numberService.getMathContext()); if (dictionaryService.checkIfUnitIsInteger(unit)) { return numberService.setScaleWithDefaultMathContext(additionalQuantity, 0); } return numberService.setScaleWithDefaultMathContext(additionalQuantity); }
protected BigDecimal calculateEfficiencyForRange(BigDecimal scaledNorm, int workersOnLine, long minuets, boolean allowIncompleteUnits) { BigDecimal value = BigDecimal.ZERO; value = scaledNorm.multiply(new BigDecimal(workersOnLine), numberService.getMathContext()); value = value.multiply(new BigDecimal(minuets), numberService.getMathContext()); if(allowIncompleteUnits) { return value; } else { return value.setScale(0, RoundingMode.HALF_UP); } }
private HSSFCell createNumericCell(StylesContainer stylesContainer, HSSFRow row, int column, BigDecimal value, boolean bold) { HSSFCell cell = row.createCell(column, HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(numberService.setScaleWithDefaultMathContext(value, 2).doubleValue()); if (bold) { cell.setCellStyle(StylesContainer.aligned(stylesContainer.numberBoldStyle, HSSFCellStyle.ALIGN_RIGHT)); } else { cell.setCellStyle(StylesContainer.aligned(stylesContainer.numberStyle, HSSFCellStyle.ALIGN_RIGHT)); } return cell; }
private void fillDeliveredQuantity(final Map<Entity, Map<String, String>> values, final Entity coverageProduct) { BigDecimal deliveredQuantity = null; if (coverageProduct == null) { deliveredQuantity = BigDecimal.ZERO; } else { deliveredQuantity = coverageProduct.getDecimalField(CoverageProductFields.DELIVERED_QUANTITY); } values.get(coverageProduct).put("deliveredQuantity", numberService.format(deliveredQuantity)); }
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(); } }