Guest User

Untitled

a guest
Jan 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. $(document).on("keypress", "#DenominacionDetalle tbody tr td input#name", function () {
  2. var Cantidad = $(this).val();
  3. var ValorDenominacion = $(this).parents("tr").find("td")[2].innerHTML;
  4. var Subtotal = parseFloat(Cantidad * ValorDenominacion);
  5. var total = parseFloat(document.getElementById("Total").innerHTML);
  6. var filas = document.querySelectorAll("#DenominacionDetalle tbody tr");
  7. console.log('Cantidad')
  8. console.log(Cantidad)
  9. console.log('Valor')
  10. console.log(ValorDenominacion)
  11. console.log('SubTotal')
  12. console.log(Subtotal)
  13. console.log('----------')
  14. $(this).parents("tr").find("td")[3].innerHTML = Subtotal;
  15. $(this).val($(this).val().replace(/[^0-9.]/g, ''));
  16. if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
  17. event.preventDefault();
  18. }
  19. //Grantotal
  20. if (!isNaN(document.getElementById("Total").innerHTML)) {
  21. document.getElementById("Total").innerHTML = parseFloat(0);
  22. }
  23. else {
  24. var MontoInicial = 0;
  25. $("#DenominacionDetalle tbody tr:nth-child(-n+3) ").each(function () {
  26. MontoInicial += parseInt($(this).children("td:eq(3)").html());
  27. var totalfinal = document.getElementById("Total").innerHTML = parseFloat(MontoInicial)
  28. document.getElementById("MontoInicial").innerHTML = parseFloat(MontoInicial)
  29. ///////////
  30. console.log('Total')
  31. console.log(MontoInicial)
  32. });
  33. }
  34. });
  35.  
  36. $(document).on('keyup', '#DenominacionDetalle input[name=qty]', function () {
  37. //prevenimos teclas indeseadas segun tu config
  38. if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
  39. event.preventDefault()
  40. }
  41.  
  42. // guardamos todas las filas que requerimos
  43. // en este caso son todas las que tienen un input qty
  44. // ya que no queremos ni la primera ni la ultima
  45. let filas = $('#DenominacionDetalle tr input[name=qty]')
  46. let total = 0 //inicializamos el total en cero
  47.  
  48. $.each(filas, function (i, v) {//recorremos las filas con $.each
  49. let qty = $(v).val()//guardamos el valor de cada input si esta vacio será cero
  50. let price = $(v).parents('tr').find('td')[2].innerHTML//buscamos el valor del producto
  51. let subtotal = parseFloat(qty * price) //obtenemos el subtotal
  52. total += subtotal //sumamos el subtotal al total general
  53.  
  54. $(v).parents('tr').find('td')[3].innerHTML = subtotal //guardamos el subtotal en la celda
  55. })
  56.  
  57. $("#Total").text(total)//guardamos el total en la celda total
  58. });
Add Comment
Please, Sign In to add comment