public static String getValue(NumberService numberService, BigDecimal value) { if (value == null) { return ""; } return numberService.formatWithMinimumFractionDigits(value, 0); }
private String getDecimalValue(BigDecimal value) { if (value == null) { return ""; } return numberService.formatWithMinimumFractionDigits(value, 0); }
private String prepareMainOrderSummary(Entity order, Entity product, Locale locale) { StringBuilder summary = new StringBuilder(translationService.translate("workPlans.workPlan.report.mainOrder", locale)); summary.append(" "); summary.append(order.getStringField(OrderFields.NUMBER)); summary.append(", "); summary.append(product.getStringField(ProductFields.NAME)); summary.append(", "); summary.append(numberService.formatWithMinimumFractionDigits(order.getDecimalField(OrderFields.PLANNED_QUANTITY), 0)); summary.append(" "); summary.append(product.getStringField(ProductFields.UNIT)); return summary.toString(); }
private String extractConversion(Resource resource) { return Objects.isNull(resource.getConversion()) ? "" : numberService.formatWithMinimumFractionDigits( resource.getConversion(), 0); }
private String prepareBaseSummary(Entity order, Entity product, Locale locale) { StringBuilder summary = new StringBuilder(translationService.translate("workPlans.workPlan.report.mainOrder", locale)); summary.append(" "); summary.append(order.getStringField("number")); summary.append(", "); summary.append(product.getStringField(ProductFields.NAME)); summary.append(", "); summary.append(numberService.formatWithMinimumFractionDigits(order.getDecimalField("plannedQuantity"), 0)); summary.append(" "); summary.append(product.getStringField(ProductFields.UNIT)); return summary.toString(); } }
private String extractConversion(Resource resource) { return Objects.isNull(resource.getConversion()) ? "" : numberService.formatWithMinimumFractionDigits( resource.getConversion(), 0); }
@Override public String getValue(Entity productionPerShift) { return numberService.formatWithMinimumFractionDigits( ppsReportXlsHelper.getOrder(productionPerShift).getDecimalField(OrderFields.PLANNED_QUANTITY), 0); }
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); } }
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); } }
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)); } }
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(); } }
private void fillWithPropertyOrZero(String componentName, String propertyName, ViewDefinitionState view) { FieldComponent component = (FieldComponent) view.getComponentByReference(componentName); if (component.getFieldValue() == null) { BigDecimal propertyValue = parameterService.getParameter().getDecimalField(propertyName); if (propertyValue != null) { String formattedProductionCostMargin = numbersService.formatWithMinimumFractionDigits(propertyValue.setScale(2), 0); component.setFieldValue(formattedProductionCostMargin); } else { component.setFieldValue(0); } } }
public void fillPrices(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { GridComponent orderedProductsGrid = (GridComponent) view.getComponentByReference(DeliveriesService.L_ORDERED_PRODUCTS); List<Entity> orderedProducts = deliveriesService.getSelectedOrderedProducts(orderedProductsGrid); orderedProducts.forEach(op -> { Entity product = op.getBelongsToField(OrderedProductFields.PRODUCT); BigDecimal lastPurchaseCost = product.getDecimalField(ProductFieldsCNFP.LAST_PURCHASE_COST); op.setField(OrderedProductFields.PRICE_PER_UNIT, lastPurchaseCost); op.getDataDefinition().save(op); }); orderedProductsGrid.reloadEntities(); BigDecimal totalPrice = orderedProducts.stream() .filter(op -> op.getDecimalField(OrderedProductFields.TOTAL_PRICE) != null) .map(op -> op.getDecimalField(OrderedProductFields.TOTAL_PRICE)).reduce(BigDecimal.ZERO, BigDecimal::add); FieldComponent totalPriceComponent = (FieldComponent) view.getComponentByReference("orderedProductsCumulatedTotalPrice"); totalPriceComponent.setFieldValue(numberService.formatWithMinimumFractionDigits(totalPrice, 0)); totalPriceComponent.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 addSmallCell(PdfPTable table, BigDecimal content) { PdfPCell cell = new PdfPCell(table.getDefaultCell()); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); String value = numberService.formatWithMinimumFractionDigits(content, 0); cell.setPhrase(new Phrase(value, FontUtils.getDejavuRegular7Dark())); table.addCell(cell); }
public void quantityChange(final ViewDefinitionState view, final ComponentState state, final String[] args) { deliveriesService.recalculatePrice(view, OrderedProductFields.ORDERED_QUANTITY); FormComponent form = (FormComponent) view.getComponentByReference("form"); Entity orderedProduct = form.getEntity(); Entity product = orderedProduct.getBelongsToField(OrderedProductFields.PRODUCT); if (decimalFieldsInvalid(form) || product == null) { return; } BigDecimal conversion = orderedProduct.getDecimalField(OrderedProductFields.CONVERSION); BigDecimal orderedQuantity = orderedProduct.getDecimalField(OrderedProductFields.ORDERED_QUANTITY); if (conversion != null && orderedQuantity != null) { String additionalQuantityUnit = Optional.ofNullable(product.getStringField(ProductFields.ADDITIONAL_UNIT)) .orElse(product.getStringField(ProductFields.UNIT)); FieldComponent additionalQuantity = (FieldComponent) view.getComponentByReference("additionalQuantity"); BigDecimal newAdditionalQuantity = calculationQuantityService.calculateAdditionalQuantity(orderedQuantity, conversion, additionalQuantityUnit); additionalQuantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newAdditionalQuantity, 0)); additionalQuantity.requestComponentUpdateState(); } }
private void fillAdditionalUnit(ViewDefinitionState view) { LookupComponent productLookup = (LookupComponent) view.getComponentByReference(OrderedProductFields.PRODUCT); Entity product = productLookup.getEntity(); if (product != null) { String unit = product.getStringField(ProductFields.UNIT); String additionalUnit = product.getStringField(ProductFields.ADDITIONAL_UNIT); FieldComponent conversionField = (FieldComponent) view.getComponentByReference("conversion"); if (!StringUtils.isEmpty(additionalUnit)) { String conversion = numberService .formatWithMinimumFractionDigits(getConversion(product, unit, additionalUnit), 0); conversionField.setFieldValue(conversion); conversionField.setEnabled(true); conversionField.requestComponentUpdateState(); } quantityChange(view, null, null); } }
public void calculateRealProductionCost(final ViewDefinitionState view, final ComponentState componentState, final String[] args) { FormComponent form = (FormComponent) view.getComponentByReference("order"); Entity order = form.getEntity(); if (order.getId() == null) { return; } Entity orderDB = order.getDataDefinition().get(order.getId()); BigDecimal realProductionCost = calculateRealProductionCost(orderDB); view.addMessage("productFlowThruDivision.realProductionCost.calculationResult", ComponentState.MessageType.SUCCESS, false, numberService.formatWithMinimumFractionDigits(numberService.setScaleWithDefaultMathContext(realProductionCost, 2), 2)); } }
public void additionalQuantityChange(final ViewDefinitionState view, final ComponentState state, final String[] args) { FormComponent form = (FormComponent) view.getComponentByReference("form"); Entity orderedProduct = form.getEntity(); Entity product = orderedProduct.getBelongsToField(OrderedProductFields.PRODUCT); if (decimalFieldsInvalid(form) || product == null) { return; } BigDecimal conversion = orderedProduct.getDecimalField(OrderedProductFields.CONVERSION); BigDecimal additionalQuantity = orderedProduct.getDecimalField(OrderedProductFields.ADDITIONAL_QUANTITY); if (conversion != null && additionalQuantity != null) { String orderedQuantityUnit = product.getStringField(ProductFields.UNIT); FieldComponent orderedQuantity = (FieldComponent) view.getComponentByReference("orderedQuantity"); BigDecimal newOrderedQuantity = calculationQuantityService.calculateQuantity(additionalQuantity, conversion, orderedQuantityUnit); orderedQuantity.setFieldValue(numberService.formatWithMinimumFractionDigits(newOrderedQuantity, 0)); orderedQuantity.requestComponentUpdateState(); deliveriesService.recalculatePrice(view, OrderedProductFields.ORDERED_QUANTITY); } }