<?php 
include_once('../../../php/sessionStart.php'); 
include_once('../../../php/db/dbExec.php');
$empCod=$_SESSION['empCod'];
# QUERYS
$sBodegas = "SELECT * FROM bodegas where bod_emp='$empCod' and bod_tienda='S' ORDER BY bod_cod";
# EJECUCION DE QUERYS
$db = new dbExec();
$select["bodegas"] = $db->query($sBodegas);
?>
<?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');
      ?>

      <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 Reporte</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-2">
                        <label></label>
                      </div>
                      <div class="col-6">
                        <label class="font-size-sm" for="selBodega">De que Bodega</label>
                        <select class="form-control form-control-sm form-control-as" name="selBodega" id="selBodega" enabled>
                          <?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></label>
                      </div>
                      <div class="col-3">
                        <label for="dtFeci" class="font-size-md">De que Fecha</label>
                        <input type="date" class="form-control form-control-sm form-control-as font-size-md" id="dtFeci" placeholder="">
                      </div>
                      <div class="col-3">
                        <label for="dtFecf" class="font-size-md">A que Fecha</label>
                        <input type="date" class="form-control form-control-sm form-control-as font-size-md" id="dtFecf" placeholder="">
                      </div>
                    </div>
                  </div>
                  <h3 class="text-light"></h3>
                  <div class="form-row">
                    <div class="col-2">
                      <label></label>
                    </div>
                    <div class="col-3">
                      <button class="btn btn-outline-primary btn-block" style="font-size:25px; font-weight:bold;" id="btnImprimirR" type="button">Imprimir</button>
                    </div>
                    <div class="col-3">
                      <button class="btn btn-outline-success btn-block" style="font-size:25px; font-weight:bold;" id="btnExcel" type="button">Generar Excel</button>
                    </div>
                  </div>
                </form>

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

<script>
  function getElements(locationPHP) {
    const getFeci = "?dtFeci="+dtFeci.value;
    const getFecf = "&dtFecf="+dtFecf.value;
    const getselBodega = "&selBodega="+selBodega.value;
    const getBodegaNom = "&BodegaNom="+$("#selBodega option:selected").text();
    return window.location.origin+window.location.pathname+locationPHP+".php"+getFeci+getFecf+getselBodega+getBodegaNom;
  }

  $(document).ready(function() {
    $(this).find('select:visible:first').focus();
    dtFeci.value = dateToday();
    dtFecf.value = dateToday();

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

    // CLICK IMPRIMIR
    $("#btnImprimirR").click(function (){
      window.open(getElements("print"), '_blank');
    });

    // CLICK EXCEL
    $("#btnExcel").click(function (){
      window.location.href = getElements("excel");
    });
  });
</script>