Good morning, I have a problem with primefacesdatatable
when performing the operation of multiplying the price field with the quantity field where the total is not the corresponding one and the total amount is:
I leave you the code or what I'm failing:
public void agregar() {
totalpedido=0;
subtotalpedido=0;
DetallePedido det=new DetallePedido();
Medicamentos medi=new Medicamentos();
det.setCantidaddetallepedido(cantidad);
det.setTotalpedido(totalpedido);
det.setMedicamentos(medicamentos);
this.lista.add(det);
for(DetallePedido det1 : lista) {
// medi.setPreciocosto(cantidad);
det1.setSubtotalpedido(subtotalpedido);
subtotalpedido = det1.getMedicamentos().getPreciocosto()*det1.getCantidaddetallepedido();
totalpedido += det1.getMedicamentos().getPreciocosto()*det1.getCantidaddetallepedido();
}
}
<p:dataTable id="detalle" value="#{pedidoBean.lista}" var="det" paginator="true" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column headerText="Proveedor">
#{det.medicamentos.proveedor.nomproveedor}
</p:column>
<p:column headerText="Nombre Producto">
#{det.medicamentos.nommedicamento}
</p:column>
<p:column headerText="Precio">
#{det.medicamentos.preciocosto}
</p:column>
<p:column headerText="Cantidad">
#{det.cantidaddetallepedido}
</p:column>
<p:column headerText="Total">
#{pedidoBean.subtotalpedido}
</p:column>
<p:columnGroup type="footer">
<p:row>
<p:column colspan="4" style="text-align:right" footerText="Monto Total:" />
<p:column footerText="$#{pedidoBean.totalpedido}" />
</p:row>
</p:columnGroup>
</p:dataTable>
The problem is that you are using the subtotal field you have defined in the bean when you should be using the subtotal field defined in each object you use as a row. The problematic code is this:
To solve it, you should change the code to this way:
You must also change the subtotal assignment order:
In the column with the header "Total" you should do the multiplication, like so:
Greetings.
The easiest way to do this is to modify your OrderDetail class and perform the multiplication inside the getSubtotalorder. thus.