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

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

# QUERYS
$sClasii = "SELECT * FROM clasii where cla_emp='$empCod'";
$sBodegas = "SELECT * FROM bodegas where bod_emp='$empCod' ORDER BY bod_cod";
# EJECUCION DE QUERYS
$db = new dbExec();
$select["clasii"] = $db->query($sClasii);
$select["bodegas"] = $db->query($sBodegas);
$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">Reporte de Articulos para Toma Fisica</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-group">
                    <div class="form-row">
                      <div class="col-4">
                        <label class="font-size-md" for="selClasi">Clasificacion</label>
                        <select class="form-control form-control-md form-control-as" name="selClasi" id="selClasi">
                          <option value="000">Todas las Clasificaciones</option>
                          <?php
                            while ($rec = $db->fetchAssoc($select['clasii'])) {
                              echo  "<option value={$rec['cla_cod']}>".utf8_encode($rec['cla_nom']).'</option>';
                            }
                          ?>
                        </select>
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-6">
                        <label class="font-size-md" for="selBodega">De que Bodega</label>
                        <select class="form-control form-control-md form-control-as" name="selBodega" id="selBodega">
                          <?php
                            while ($rec = $db->fetchAssoc($select['bodegas'])) {
                              echo  '<option value="'.$rec['bod_cod'].'">'.utf8_encode($rec['bod_nom']).'</option>';
                            }
                          ?>
                        </select>
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-2">
                        <label for="txtGrupo" class="font-size-md">Grupo Codigo</label>
                        <input type="text" class="form-control form-control-sm form-control-as font-size-md" id="txtGrupo" placeholder="" maxlength="20">
                      </div>
                      <div class="col-1">
                        <label > </label>
                      </div>
                      <div class="col-3">
                        <label class="font-size-md" for="dtFec" class="font-size-md">A que Fecha</label>
                        <input type="date" class="form-control form-control-sm form-control-as font-size-md" id="dtFec" placeholder="">
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-3">
                        <label class="pr-1">Incluye Existencias en el reporte</label><br>
                        <div class="custom-control custom-radio custom-control-inline">
                          <input type="radio" id="crInclue1" name="crInclue" class="custom-control-input" value="S">
                          <label class="custom-control-label" for="crInclue1">Si</label>
                        </div>
                        <div class="custom-control custom-radio custom-control-inline">
                          <input type="radio" id="crInclue2" name="crInclue" class="custom-control-input" value="N">
                          <label class="custom-control-label" for="crInclue2">No</label>
                        </div>
                      </div>
                      <div class="col-3">
                        <label class="pr-1"></label><br>
                        <div class="custom-control custom-radio custom-control-inline">
                          <input type="radio" id="crTse1" name="crTse" class="custom-control-input" value="T">
                          <label class="custom-control-label" for="crTse1">Todos los Articulos</label>
                        </div>
                        <div class="custom-control custom-radio custom-control-inline">
                          <input type="radio" id="crTse2" name="crTse" class="custom-control-input" value="E">
                          <label class="custom-control-label" for="crTse2">Solo con Existencia</label>
                        </div>
                      </div>
                    </div>
                  </div>

                  <h3 class="text-light"></h3>

                  <div class="form-group">
                    <div class="form-row">
                      <div class="col-md-3">
                        <button class="btn btn-primary btn-lg btn-block" id="btnImprimir" type="button">Imprimir</button>
                      </div>
                      <div class="col-md-3">
                        <button class="btn btn-success btn-lg btn-block" id="btnExcel" type="button">Excel</button>
                      </div>
                    </div>
                  </div>
                </form>

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

<script>
  const selClasi = document.thisform.selClasi;
  const selBodega = document.thisform.selBodega;
  const crInclue = document.thisform.crInclue;
  const crTse = document.thisform.crTse;
  const dtFec = document.thisform.dtFec;
  const txtGrupo = document.thisform.txtGrupo;

  $(document).ready(function() {
    $(this).find('select:visible:first').focus();
    crInclue.value='S';
    crTse.value="T";
    dtFec.value = dateToday();
    txtGrupo.value = "";

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

    // CLICK IMPRIMIR
    $("#btnImprimir").click(function (){
      const getselClasi = "?selClasi="+selClasi.value;
      const getselBodega = "&selBodega="+selBodega.value;
      const getBodegaNom = "&BodegaNom="+$("#selBodega option:selected").text();
      const getcrInclue = "&crInclue="+crInclue.value;
      const getcrTse = "&crTse="+crTse.value;
      const getdtFec = "&dtFec="+dtFec.value;
      const getGrupo = "&txtGrupo="+txtGrupo.value;

      var url = window.location.origin+window.location.pathname+"print.php"+getselClasi+getselBodega+getcrInclue+getdtFec+getBodegaNom+getcrTse+getGrupo;
      window.open(url, '_blank');
      txtGrupo.value="";
    });

    // CLICK EXCEL
    $("#btnExcel").click(function (){
      const getselClasi = "?selClasi="+selClasi.value;
      const getselBodega = "&selBodega="+selBodega.value;
      const getBodegaNom = "&BodegaNom="+$("#selBodega option:selected").text();
      const getcrInclue = "&crInclue="+crInclue.value;
      const getcrTse = "&crTse="+crTse.value;
      const getdtFec = "&dtFec="+dtFec.value;
      const getGrupo = "&txtGrupo="+txtGrupo.value;

      var url = window.location.origin+window.location.pathname+"excel.php"+getselClasi+getselBodega+getcrInclue+getdtFec+getBodegaNom+getcrTse+getGrupo;
      window.location.href = url;
      txtGrupo.value="";
    });
  });

  // 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>