Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/10/2015, 05:44
killpe
 
Fecha de Ingreso: octubre-2015
Ubicación: españa
Mensajes: 53
Antigüedad: 8 años, 6 meses
Puntos: 1
Solución definitiva por si a alguien le sirve

Esta es la solución definitiva del problema.

el código html es este:
Código HTML:
<form method="post">

		 <table id="table-data">
	   <thead>
		   <tr> 
			   <th class="primera 10porcien">Nombre</th>
			   <th class="centro_listados 10porcien">cantidad</th>
			   <th class="centro_listados 10porcien">precio</th>
			   <th class="centro_listados 10porcien">Total</th>
			   <th class="ultima 10porcien">Opciones</th>
			</tr>
		</thead>
		
		<tbody id="itemRows" class="ordenable" style="background: white;">
	<tr>
		<td><input type="text" name="nombre" placeholder="Nombre"></td>
		<td><input type="text" name="cantidad" id="cantidad" placeholder="Cantidad"></td>
		<td><input type="text" name="precio" id="precio" placeholder="precio" value="100"></td>
		<td><input type="text" name="total" disabled id="total" placeholder="Total"></td>
		<td><input onclick="AddLinea(this.form);" type="button" class="botonverde" value="agregar" /></td>
	</tr>
		</tbody>
		 </table>
	</form>
</div>
<br />
            <div id="Totales">
                Subtotal <input type="text" name="Subtotal" placeholder="Subtotal"><br />
                Impuestos <input type="text" name="Impuestos" placeholder="Impuestos"><br />
                Total <input type="text" name="Supertotal" placeholder="Total">
             </div>            
<script>   
var LineaNum = 0;
function AddLinea(frm) {
	LineaNum ++;
	var Linea = '<tr id="LineaNum'+LineaNum+'"><td><b>'+frm.nombre.value+'</b></td><td><b>'+frm.cantidad.value+'</b></td><td><b>'+frm.precio.value+'</b></td><td><input type="text" name="total[]" disabled value="'+frm.total.value+'"></td><td><input type="button" class="botonrojo" value="Borrar" onclick="EliminarLinea('+LineaNum+','+frm.total.value+');"></td></tr>';
	jQuery('#itemRows').append(Linea);
	frm.nombre.value = '';
	frm.cantidad.value = '';
	frm.precio.value = '';
	frm.total.value = '';
}


function EliminarLinea(rnum,descontar) {
	jQuery('#LineaNum'+rnum).remove();
        var subtotal = $('input[name=Subtotal]').val();
         if (!isNaN(descontar)){ subtotal -= parseFloat(descontar);
      	}else{
        return true;
        }
         
      $('input[name=Subtotal]').val(subtotal); 
    
}
</script> 
este el jQuery

Código:
$(document).ready(function() {    
//suma subtotales
        $("#cantidad, #precio").keyup(function (e) {
            var canti = $("#cantidad").val();
            var preci = $("#precio").val();
            var iva = $("#iva").val();
            //var resultado = parseFloat(mat) + parseFloat(price);
            var baseimpo = parseFloat(canti) * parseFloat(preci);
            $("#total").val(baseimpo);
            sumar_total();
        });

 //suma totales
 function sumar_total(){
       		var subtotal = 0;
        	var totales = $('input[name^=total]');
      totales.each(function(){
     		var valor = $(this).val();
        if (!isNaN(valor)){ subtotal += parseFloat(valor);
      	}else{
        return true;
        }
       }); 
      $('input[name=Subtotal]').val(subtotal);    
};
    
//ordenable  	
 	$( ".ordenable" ).sortable({
        stop: function () {
            var inputs = $('input.posicion');
            var nbElems = inputs.length;
            $('input.posicion').each(function(idx) {
                $(this).val(nbElems - idx);
            });
        }
    });
    $( ".ordenable" ).disableSelection();   
          
});
y aqui lo podeis ver funcionando https://jsfiddle.net/gf2pkks2/13/

faltaria por poner los impuestos y total mas impuestos pero con este código es simplemente meter otro calculo para los impuestos y que escriba el total definitivo...


Muchísimas gracias a todos ( sobre todo a sintle_1 ) por la ayuda