Hi, I am trying to add the tr
of my detail table, as well as subtract when I click on the tachito icon.
I'm trying with a for and it does not work for me
THIS IS MY HTML TABLE
<div class="col-xs-7">
<table id="table_ventas"
class="table table-bordered table-condensed table-hover responsive"
cellspacing="0" width="100%">
<thead>
<tr>
<th><FONT SIZE=4>#</FONT></th>
<th><FONT SIZE=4>Código</FONT></th>
<th width="320px"><FONT SIZE=4>Producto</FONT></th>
<th><FONT SIZE=4>Precio</FONT></th>
<th><FONT SIZE=4>Cantidad</FONT></th>
<th><FONT SIZE=4>Subtotal</FONT></th>
<th width="5%"></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div class="row">
<div align="center" id="modal_footer">
<table id="table_total"
class="table table-bordered table-condensed table-hover responsive"
cellspacing="0" width="100%">
<thead>
<tr>
<td id="total_fila" style="text-align: right;"><strong><FONT SIZE=6>TOTAL : s./ </FONT></strong></th>
<td id="detalle_total"><strong><FONT color="#1b5e20" SIZE=6> 0 </FONT><th>
</tr>
</thead>
</table>
<div align="center">
<button type="button" id="btnSave" onclick="cancelar_venta()"
class="btn btn-danger btn-lg"><i class="fa fa-remove"></i> CANCELAR COMPRA</button>
</div>
</div>
</div>
</div>
THIS IS MY ADD BUTTON:
$("#confirmar_producto").click(function () {
/* Capturar los valores de los campos */
var id_producto = $('#id_producto').val();
var cod_producto = $('#cod_producto').val();
var precio = $('#precio').val();
var cantidad = $('#cantidad_comprar').val();
var producto = $("#producto").text();
var subtotal = precio * cantidad;
/* Crear una fila nueva con los datos capturados */
var cont_fila = ($('#table_ventas tbody').find('tr').length) + 1;
var fila = '<tr>';
fila = fila + '<td scope="row">' + cont_fila + '</td>';
fila = fila + '<td><input type="hidden" id="id_producto_tabla" value="' + id_producto + '"><input type="text" class="form-control text-center" id="Codigo_' + cont_fila + '" value="' + cod_producto + '" readonly="readonly" /></td>';//Codigo
fila = fila + '<td><input type="text" class="form-control text-center" id="Producto_' + cont_fila + '" value="' + producto + '" readonly="readonly" /></td>';//Producto
fila = fila + '<td><input type="text" class="form-control text-center" id="Precio_' + cont_fila + '" value="' + precio + '" readonly="readonly" /></td>';//Precio
fila = fila + '<td><input type="text" class="form-control text-center" id="Cantidad_' + cont_fila + '" value="' + cantidad + '" readonly="readonly" /></td>';//Cantidad
fila = fila + '<td><input type="text" class="form-control text-center" id="Subtotal_' + cont_fila + '" value="' + subtotal + '" readonly="readonly" /></td>';//Subtotal
fila = fila + '<td><a href="javascript:void(0);" class="eliminar_fila" onclick="eliminar_detalle(this,' + cont_fila + ');"><i class="fa fa-trash-o fa-2x"></i></a></td>';//Eliminar
fila = fila + '</tr>';
/* Agregar las futuras filas */
$("#table_ventas").append(fila);
/* Despues de agregar limpiar los inputs*/
limpiar();
suma_total();
});
THIS IS MY JQUERY CODE:
function suma_total() {
var cont_fila = ($('#table_ventas tbody').find('tr').length);
var total_general = 0;
for (var i = 1; i < cont_fila; i++) {
var subtotal = $('#Subtotal_' + cont_fila).val();
total_general = parseFloat(total_general) + parseFloat(subtotal);
}
$("#detalle_total").text((total_general * 1).toFixed(2));
}
function resta_total() {
//Aqui deberia ir el otro codigo pero como aun no avanzo con el primero :c
}