$(document).ready(function () {

    $("body").on("click", '.remove', remove);
    $("body").on("input", '.passport', Calrows);
    $("body").on("blur keyup change click", '.passport', Calamt);
    $("body").on("keyup blur", ".passport", getPassdetail);


    function Calamt() {
        var memadd = 0;
        $(".memcash").each(function () {
          if (!isNaN(this.value) && this.value.length != 0) {
            memadd += parseFloat(this.value);
          }
        });
        $(".totamt").val(memadd);
      }


  function getPassdetail() {

    var tr = $(this).closest("tr"),
        passport = tr.find(".passport").val();

    $.ajax({
      type: "POST",
      dataType: "json",
      url: "getinvdetail.php",
      data: { passport: passport },
      success: function (response) {
        if (response != "") {
          var paxname = response.paxname,
              submission_date = response.submission_date,
              memcash = response.memcash,
              mofano = response.mofano,
              delvstatus = response.delvstatus;

          tr.find(".paxname").val(paxname);
          tr.find(".memcash").val(memcash);
          tr.find(".submission_date").val(submission_date);
          tr.find(".mofano").val(mofano);
          tr.find(".delvstatus").val(delvstatus);
        }
      },
      error: function (request, textStatus, errorThrown) {},
    });
  }
  





    $('#addnew').click(function () {
        AddRows();
    }); 
    
    function AddRows() {
        var ctr = $('#items').val();
        var hide_check = "";
        if ($("#del_all").prop("checked")) {
            hide_check = 0;
        } else {
            hide_check = 1;
        }
        $.post('entinvoice_add.php', {ctr: ctr, hide: hide_check}, function (data) {
            $(data).appendTo('#tabledata');
            ctr++;
            $('#items').val(ctr);
        });
    }

    function remove() {
        $(this).closest("tr").remove();
    }



    function Calrows() {
       var rowCount = $('#tabledata tr').length;
        $('.nofpass').val(rowCount);
    }

});