$(document).ready(function (){
  document.formCheques.dtFecIni.value = dateToday();
  document.formCheques.dtFecFin.value = dateToday();
});
function buscarCheques(b, a){
  const parametros = new FormData();
  parametros.append("dtFecIni", document.formCheques.dtFecIni.value);
  parametros.append("dtFecFin", document.formCheques.dtFecFin.value);
  parametros.append("numValor", document.formCheques.numValor.value);
  parametros.append("txtNom", document.formCheques.txtNom.value);

  $.ajax({
    data:  parametros,
    url:   "busCheques/data.php",
    type:  "post",
    contentType: false,
    processData: false,
    beforeSend: function () {
      alLoad("Consultando...")
    },
    success: function (jsonPhp) {
      const jsonJS = JSON.parse(jsonPhp);

      tblClear("tblCheques");
      jsonJS.cheques.forEach(function(i){
        addRowCheques(i.ch_ban, i.ban_nom, i.ch_num, i.ch_fec, i.ch_bene, i.ch_tcam, i.ch_tot);
      });

      $("#tblCheques tbody tr").dblclick(function() {
        selecCheques(a, $(this));
      });

      $("#tblCheques tbody #btnSelecCheques").click(function() {
        selecCheques(a, $(this).parents("tr"));
      });

      alClose();
    }
  });
}

function addRowCheques(numBan, nomBan,num,fec,bene,tcam,tot) {
  const markup =  "<tr>"
                    +"<td class='d-none'>"+numBan+"</td>"
                    +"<td>"+nomBan+"</td>"
                    +"<td>"+num+"</td>"
                    +"<td style='width: 35px;'>"+YMDToDMY(fec)+"</td>"
                    +"<td>"+bene+"</td>"
                    +"<td class='text-right'>"+tcam+"</td>"
                    +"<td class='text-right'>"+tot+"</td>"
                    +"<td><button class='btn btn-sm btn-warning badge' id='btnSelecCheques'>"+textBtnSelec+"</button></td>"
                  +"</tr>";
  $("#tblCheques tbody").append(markup);
}

function selecCheques(a, tr) {
  if (inputCheques == "numNum") {
    document.thisform.selBan.value = tr.find("td:eq(0)").text();
    document.thisform.numNum.value = tr.find("td:eq(2)").text();
    $("form[name='thisform'] #numNum").trigger("change");
  } else {
    $("#"+inputCheques).val(tr.find("td:eq(0)").text());
    $("#"+inputCheques+"bene").val(tr.find("td:eq(4)").text());
  }

  $("#pills-"+a+"-tab").click();
  $('html, body').animate( { scrollTop : 0 }, 500 );
  tblClear("tblCheques");
}