<?php 
include_once('../../../php/sessionStart.php');
include_once('../../../php/db/dbExec.php');
include_once('../../../php/maxExecTime.php');

$empCod = $_SESSION['empCod'];
$empNom = $_SESSION['empNom'];
$empNit = $_SESSION['empNit'];

# QUERYS
# EJECUCION DE QUERYS
$db = new dbExec();
$db->close();
?>
<?php include_once('../includes/htmlOpen.php'); ?>
    <main class="main" style="">
      <?php 
        $li[0] = '<i class="fas fa-file-excel"></i>';
        $li[1] = $_GET["opcNom"];
        include_once('../../../php/includes/ol.php');

        $modalImp = "modalImp";
        include_once('../../../php/includes/modalImp.php');
      ?>
      <div class="container-as">
        <div class="row">
          <div class="col">
            <ul class="nav nav-pills mb-1" id="pills-tab" role="tablist">
              <li class="nav-item">
                <a class="nav-link active" id="pills-0-tab" data-toggle="pill" href="#pills-0" role="tab" aria-controls="pills-0" aria-selected="true"></a>
              </li>
            </ul>
            <div class="tab-content bg-transparent border-0" id="pills-tabContent">
              <div class="tab-pane fade show active" id="pills-0" role="tabpanel" aria-labelledby="pills-0-tab">
                <form action="" name="thisform" autocomplete="off" enctype="multipart/form-data">
                  
                  <h3 class="text-light"></h3>

                  <div class="form-group">
                    <div class="form-row">
                      <div class="col-md-3">
                        <label> </label>
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-md-3">
                        <label> </label>
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-md-3">
                        <label> </label>
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-md-3">
                        <label> </label>
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-md-1">
                        <label> </label>
                      </div>
                      <div class="col-md-6">
                        <button class="btn btn-primary btn-lg btn-block" id="btnProceso" type="button">Generar Autorizacion Para Descuentos</button>
                      </div>
                    </div>
                  </div>
                </form>

              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
<?php include_once('../../../php/includes/htmlClose.php'); ?>

<script>

  $(document).ready(function() {
    $(this).find('input:visible:first').focus();


    // SUBMIT FORM
    $('form').submit(function() {
      return false;
    });

    // CLICK BORRAR
    $("#btnProceso").click(function (){
      const fnT = function(){
        const parametros = new FormData();
        parametros.append("action", "proceso");
        
        $.ajax({
          data:  parametros,
          url:   window.location.origin+window.location.pathname+"actions.php",
          type:  "post",
          contentType: false,
          processData: false,
          beforeSend: function () {
            alLoad("Espere mientras se realiza el proceso...")
          },
          success: function (jsonPhp) {
            console.log(jsonPhp);
            const jsonJS = JSON.parse(jsonPhp);

            if(jsonJS.error==true){
              alError(jsonJS);
            } else {
              //alSuccess(jsonJS);
              alWarning({"msg":{"title":"No. AUTORIZACION: "+jsonJS.numauto,"text":""}});
              return true;
            }
          }
        });
      }

      const fnF = function(){
        return true;
      }

      usuClave(fnT, fnF);
    });


  });

  // FOCUS PILL
  $('a[data-toggle="pill"]').on('shown.bs.tab', function (e) {
    if (!isMobile()) {
      const target = e.target.attributes.href.value;
      if ($(target+' select:visible:first').length) {
        $(target+' select:visible:first').focus();
      } else {
        $(target+' select:visible:first').focus();
      }
    }
  });

</script>