//$(document).ready(function (){
//  document.formSuspen.numCods.value =  document.thisform.inputvCod;
//});

function buscarDescuentos(b, a){
  const parametros = new FormData();
  parametros.append("numCod", document.formDescuentos.numCod.value);

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

      tblClear("tblDescuentos");
      jsonJS.descuentos.forEach(function(i){
        addRowDescuentos(i.d_cod, i.td_cod, i.td_desc, i.d_feci, i.d_fecf, i.d_monto);
      });

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

      $("#tblDescuentos tbody #btnSelecDescuentos").click(function() {
        selectDescuentos(a, $(this).parents("tr"));
      });

      alClose();
    }
  });
}

function addRowDescuentos(cod, tipodesc, tipon, del, al, monto) {
  const markup =  "<tr>"
                    +"<td id='datacod' class='text-center'>"+cod+"</td>"
                    +"<td id='datatipodesc' class='text-left d-none'>"+tipodesc+"</td>"
                    +"<td id='datatipon' class='text-left'>"+tipon+"</td>"
                    +"<td id='datadel' class='text-center'>"+del+"</td>"
                    +"<td id='dataal' class='text-center'>"+al+"</td>"                    
                    +"<td id='datamonto' class='text-right'>"+monto+"</td>"                    
                    +"<td><button class='btn btn-sm btn-warning badge' id='btnSelecDescuentos'>"+textBtnSelec+"</button></td>"
                  +"</tr>";
  $("#tblDescuentos tbody").append(markup);
}

function selectDescuentos(a, tr) {
  $("#pills-"+a+"-tab").click();
  /*if (inputProvcp == "txtNit") {
    document.thisform.txtNit.value = tr.find("td:eq(0)").text();
    $("form[name='thisform'] #txtNit").trigger("change");
  } else {*/
    $("#"+inputEmple).val(tr.find("td:eq(0)").text());
    $("#"+inputTipodesc).val(tr.find("td:eq(1)").text());
    $("#"+inputDel).val(tr.find("td:eq(3)").text());
    $("#"+inputAl).val(tr.find("td:eq(4)").text());
    //if (!nomTF) {
    //  $("#"+inputEmple).trigger("change");
      //$("#"+inputAl).trigger("blur");
    //} else {
    //  $("#"+"txtNom1").val(tr.find("td:eq(1)").text());
    //}
  //}

  //$('html, body').animate( { scrollTop : 0 }, 500 );
  tblClear("tblDescuentos");
}