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

# QUERYS
$sTpuesto = "SELECT * FROM tpuesto ORDER BY tpu_nom";
$sGrupo = "SELECT * FROM grupo WHERE gru_emp='".$_SESSION['empCod']."'";
$sDep = "SELECT * FROM dep WHERE dep_emp='".$_SESSION['empCod']."'";
$sBodegapro = "SELECT * FROM bodegapro";

# EJECUCION DE QUERYS
$db = new dbExec();
$select["tpuesto"] = $db->query($sTpuesto);
$select["grupo"] = $db->query($sGrupo);
$select["dep"] = $db->query($sDep);
$select["bodegapro"] = $db->query($sBodegapro);

$dtFec=date("Y-m-d");
$nAnio=date("Y");
$nMes=date("m");

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

?>
<?php include_once('../includes/htmlOpen.php'); ?>
    <main class="main" style="">
      <?php 
        $li[0] = '<i class="fas fa-file-invoice"></i>';
        $li[1] = $_GET["opcNom"];
        include_once('../../../php/includes/ol.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">Generar Resumen por departamento y area</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">
                  <div class="form-row">
                    <div class="col-md-10">
                      <div class="form-group">
                        <div class="form-row">
                          <div class="col-2">
                                <label class="font-size-md" for="dtDel">Periodo del:</label>
                                <input type="date" class="form-control form-control-md form-control-as" id="dtDel" placeholder="">
                          </div>
                          <div class="col-2">
                                <label class="font-size-md" for="dtAl">Al</label>
                                <input type="date" class="form-control form-control-md form-control-as" id="dtAl" placeholder="">
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-sm-3">
                            <label  class="font-size-md" for="selGrupo">Grupo</label>
                            <select class="form-control form-control-md form-control-as" name="selGrupo" id="selGrupo">
                              <option value="000">Todos los Grupos</option>
                              <?php
                                while ($rec = $db->fetchAssoc($select['grupo'])) {
                                  echo  "<option value={$rec['gru_cod']}>".utf8_encode($rec['gru_nom']).'</option>';
                                }
                              ?>
                            </select>
                          </div>
                          <div class="col-sm-3">
                            <label class="font-size-md" for="selBodegapro">Bodega</label>
                            <select class="form-control form-control-md form-control-as" name="selBodegapro" id="selBodegapro">
                              <option value="000">Todas las Bodegas</option>
                              <?php
                                while ($rec = $db->fetchAssoc($select['bodegapro'])) {
                                  echo  "<option value={$rec['bp_cod']}>".utf8_encode($rec['bp_nom']).'</option>';
                                }
                              ?>
                            </select>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-3">
                            <label class="pr-1"></label><br>
                            <div class="custom-control custom-radio custom-control-inline">
                              <input type="radio" id="crTrepo1" name="crTrepo" class="custom-control-input" value="T">
                              <label class="custom-control-label" for="crTrepo1">Todos</label>
                            </div>
                            <div class="custom-control custom-radio custom-control-inline">
                              <input type="radio" id="crTrepo2" name="crTrepo" class="custom-control-input" value="S">
                              <label class="custom-control-label" for="crTrepo2">Si</label>
                            </div>
                            <div class="custom-control custom-radio custom-control-inline">
                              <input type="radio" id="crTrepo3" name="crTrepo" class="custom-control-input" value="N">
                              <label class="custom-control-label" for="crTrepo3">No</label>
                            </div>
                          </div>
                        </div>
                        <div class="form-row">
                        </div>
                        <div class="form-row">
                          <div class="col-9 mt-2">
                            <button class="btn btn-outline-success btn-block" id="btnExcel" type="button">Generar Excel</button>
                          </div>
                        </div>
                      </div>
                      <h3 class="text-light"></h3>
                      <h3 class="text-light"></h3>
                      <div class="form-group">
                        <div class="form-row">
                        </div>
                      </div>
                    </div>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
<?php include_once('../../../php/includes/htmlClose.php'); ?>

<script>
  var pressEnter = false;
  var nuevo = true;
  var nuevoArtic = true;
  var mesCerrado = false;
  var inputCtaMov = "txtCta";
  var totant = 0;
  var inputPlani = "numNum";
  var tblNomperAnt;
  var tblPolAnt;
  var btnAddEdit = "00";
  var inputArtic = "txtCodd";
  var unimed = "XXX";
  var ctaInc = false;
  var inputEmple = "numCoddag";

  
  const dtDel = document.thisform.dtDel;
  const dtAl = document.thisform.dtAl;
  const crTrepo = document.thisform.crTrepo;


  function restriccion(consultar = false){
  }

  function restriccionCamposVacios() {
  }
    
  function limpiar(todo = false){
    dtAl.value= '<?php echo $dtFec; ?>';
    dtDel.value= '<?php echo $dtFec; ?>';
  }

  $(document).ready(function() {
    $(this).find('input:visible:first').focus();
    //document.thisform.dtFec.value = '<?php echo $dtFec; ?>';
    //document.thisform.dtFvalida.value = '<?php echo $dtFec; ?>';
    dtDel.value = dateToday();
    dtAl.value = dateToday();
    crTrepo.value = "T";
    // SHOW MODAL
    $('#modalNomper, #modalNomperag').on('shown.bs.modal', function() {
      if (!isMobile()) {
        $(this).find('input:enabled:first').focus();
      }
    });

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

    // CLICK EXCEL
    $("#btnExcel").click(function (){
      if (restriccion(true)) {return};

      const getselGrupo = "?selGrupo="+selGrupo.value;
      const getdtDel = "&dtDel="+dtDel.value;      
      const getdtAl = "&dtAl="+dtAl.value;      
      const getselBodegapro = "&selBodegapro="+selBodegapro.value;
      const getcrTrepo = "&crTrepo="+crTrepo.value;

      var url = window.location.origin+window.location.pathname+"excel.php"+getselGrupo+getdtDel+getdtAl+getselBodegapro+getcrTrepo;

      window.location.href = url;
    });
  });

  // MODALDetao HIDDEN
  $('#modalNomper').on('hidden.bs.modal', function (e) {
    $("body").off("click", "#btnModificar");
  });


  // FOCUS PILL
  $('a[data-toggle="pill"]').on('shown.bs.tab', function (e) {
    if (!isMobile()) {
      const target = e.target.attributes.href.value;
      const relatedTarget = e.relatedTarget.attributes.href.value;

      if (target != "#pills-0") {
        $(target+' input:visible:first').focus();
      } else {
        (relatedTarget == "#pills-1") ? selBodegapro.focus() : 0;
      //  (relatedTarget == "#pills-000") ? numCoddag.focus() : 0;
      }
    }
  });

</script>

