Calculate a sales invoice

0

I have this problem and I'm already stuck, I'll appreciate your help.

What I'm doing is a sales ticket with all those dynamic data that should be updated with jquery and change its value (to then send them by post with php to a database).

The <div class="row items"> add them dynamically with another jquery that interacts with another database.

The + and - Amount buttons do not work either, I was testing and they do not work.

I am not closed to learning other methods any help is welcome.

$.each($('.items'),function(i,v){
        var cantidad = $(v).find('.cantidad').val();
        var punitario = $(v).find('.punitario').val();
        var total = cantidad * punitario;
        var impuesto = total*(18/100);
        var subtotal = total-subtotal;
        $(v).find('.total_prod').text(total);
        $('#subtotal').text(subtotal);
        $('#impuesto').text(impuesto);
        $('#total').text(total);
      });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="productos w-100">
  <div class="row" id="prods_0">
    <div class="col-sm-2 text-center"><b>CODIGO</b></div>
    <div class="col-sm-4"><b>NOMBRE</b></div>
    <div class="col-sm-2"><b>CANTIDAD</b></div>
    <div class="col-sm-2"><b>PRECIO UNIT.</b></div>
    <div class="col-sm-2" id="prods_0"><b>PRECIO TOTAL</b></div>
  </div>
  <div class="row items">
    <div class="col-sm-2 text-center">4000600000</div>
    <div class="col-sm-4">Item 1</div>
    <div class="col-sm-2">
      <div class="input-group mb-3">
        <div class="input-group-prepend"><span class="input-group-text">+</span></div><input class="form-control cantidad" value="1" type="text">
        <div class="input-group-append"><span class="input-group-text">-</span></div>
      </div>
    </div>
    <div class="col-sm-2 punitario">30</div>
    <div class="col-sm-2 total_prod" id="1">0</div>
  </div>
  <div class="row items">
    <div class="col-sm-2 text-center">4000600001</div>
    <div class="col-sm-4">Item 2</div>
    <div class="col-sm-2">
      <div class="input-group mb-3">
        <div class="input-group-prepend"><span class="input-group-text">+</span></div><input class="form-control cantidad" value="1" type="text">
        <div class="input-group-append"><span class="input-group-text">-</span></div>
      </div>
    </div>
    <div class="col-sm-2 punitario">30</div>
    <div class="col-sm-2 total_prod" id="2">0</div>
  </div>
</div>
<div class="row justify-content-end">
    <div class="col-sm-2 col-6">
      <b>Subtotal</b><br>
      <b>IGV 18%</b><br>
      <b>Total</b>
    </div>
    <div class="col-sm-2 col-6">
      <div id="subtotal" class="text-center"></div>
      <div id="impuesto" class="text-center"></div>
      <div id="total" class="text-center"></div>
    </div>
  </div>
    
asked by Marco Torres 10.09.2018 в 02:53
source

1 answer

0

Verify that in your code you consult the text and not the value of a div. Also, the subtotal I think you were calculating wrong. Hopefully and serve you.

$.each($('.items'),function(i,v){

        var cantidad = $(v).find('.cantidad').val()*1;
        var punitario = $(v).find('.punitario').text()*1;
        var total = cantidad * punitario;

        var impuesto = total*(18/100);
        var subtotal = total-impuesto;
        $(v).find('.total_prod').text(total);
        $('#subtotal').text(subtotal);
        $('#impuesto').text(impuesto);
        $('#total').text(total);
      }); 
    
answered by 11.09.2018 в 01:42