javamavenvaadinprimavera

Vaadin sum calculation


enter image description here

I am not able to add the fields, I have already tried several modifications in the code, but nothing worked.

My current code is this for the sum of the fields:

txtAmount.addValueChangeListener(event -> {

            NumberFormat formatter = NumberFormat.getCurrencyInstance(new Locale("pt", "BR"));
            double totalValue= 0;

            try {
                totalValue = formatter.parse(txtUnitaryValue.getValue()).doubleValue() * txtQuantidade.getValue();
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            txtTotalItemValue.setValue(formatter.format(totalValue));

            addValues= totalValue;
            fieldAddsValues.setValue(formatter.format(addValues));

        });

Solution

  • To calculate the sum of all positions set this snippet in the txtAmount.addValueChangeListener block:

    Double sum = listaVendas.stream().mapToDouble(product -> product.getPrice() * product.getQuantity()).sum();