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

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

      tblClear("tblOrdenesc");
      jsonJS.ordenc.forEach(function(i){
        addRowOrdenc(i.od_num, i.od_fec, i.od_prov, i.od_valor, i.sord_nom);
      });

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

      $("#tblOrdenesc tbody #btnSelecOrdenesc").click(function() {
        selecOrdenesc(a, $(this).parents("tr"));
      });

      alClose();
    }
  });
}

function addRowOrdenc(num,fec,prov,valor,statusnom) {
  const markup =  "<tr>"
                    +"<td style='font-size:16px;'>"+num+"</td>"
                    +"<td class='text-center' style='font-size:16px;'>"+YMDToDMY(fec)+"</td>"
                    +"<td style='font-size:16px;'>"+prov+"</td>"
                    +"<td class='text-right' style='font-size:16px;'>"+valor+"</td>"
                    +"<td class='text-center' style='font-size:16px;'>"+statusnom+"</td>"
                    +"<td><button class='btn btn-sm btn-warning badge' id='btnSelecOrdenesc'>"+textBtnSelec+"</button></td>"
                  +"</tr>";
  $("#tblOrdenesc tbody").append(markup);
}

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

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