mercredi 19 août 2020

how to implement discount value in invoice using jQuery

I'm trying implementing a discount value getting in my form.

I tried this in jQuery code

$('tbody').delegate('.quantity,.price,.gst,.dsc', 'keyup', function() {
  var tr = $(this).parent().parent();
  var quantity = tr.find('.quantity').val();
  var price = tr.find('.price').val();
  var gst = tr.find('.gst').val();
  var dsc = tr.find('.dsc').val();
  var totalamountgst = (quantity * price * gst) / 100;
  var totalamountdcs = (quantity * price * dcs) / 100;
  var totalamounts = (quantity * price + totalamountgst);
  var totalamount = (totalamounts - totalamountdcs);


  tr.find('.totalamount').val(totalamount);
  total();
});

function total() {
  var total = 0;
  $('.totalamount').each(function(i, e) {
    var totalamount = $(this).val() - 0;
    total += totalamount;
  });
  $('.total').val(total + ".00");
} 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tbody>
    <tr>
      <td> <input style="text-align:center;" type="text" class="text-danger  input-lg form-control quantity" name="qty[]" id="validationServer01" placeholder="QTY" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+" numbers="onlynumbers" autocomplete="off"></td>
      <td> <input style="text-align:center;" type="text" class="text-danger  input-lg form-control gst " name="gst_amount[]" id="validationServer01" placeholder="GST" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+" numbers="onlynumbers" autocomplete="off"></td>
      <td> <input style="text-align:center;" type="text" class="text-danger  input-lg form-control dcs " name="dcs_amount[]" id="validationServer01" placeholder="DCS" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+" numbers="onlynumbers" autocomplete="off"></td>
      <td> <input style="text-align:center;" type="number" class="text-danger  input-lg form-control price" name="purchase_rate[]" id="validationServer01" placeholder="RATE" value="" required pattern="" numbers="" autocomplete="off"></td>
      <td> <input style="text-align:center;" type="text" class="text-danger  input-lg form-control totalamount" name="" id="validationServer01" placeholder="AMOUNT" value="" required pattern="[1-2-3-4-3-5-6-7-8-9-10-12]+" numbers="onlynumbers" disabled></td>
    </tr>
  </tbody>
</table>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire