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

# QUERYS
$sTipopol = "SELECT * FROM tipopol";

# EJECUCION DE QUERYS
$db = new dbExec();
$select["tipopol"] = $db->query($sTipopol);
$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">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 align-items-end mt-3">
                      <div class="col-6">
                        <label for="dtFecI" class="font-size-lg">Fecha Inicial</label>
                        <input type="date" class="form-control form-control-sm form-control-as font-size-lg" id="dtFecI" placeholder="">
                      </div>
                      <div class="col-6">
                        <label for="dtFecF" class="font-size-lg">Fecha Final</label>
                        <input type="date" class="form-control form-control-sm form-control-as font-size-lg" id="dtFecF" placeholder="">
                      </div>
                    </div>
                    <div class="form-row align-items-end">
                      <div class="col-md-6">
                        <label for="txtTitulo" class="font-size-lg">Título del Reporte</label>
                        <input type="text" class="form-control form-control-sm form-control-as font-size-lg" id="txtTitulo" placeholder="">
                      </div>
                      <div class="col-6">
                        <label for="numHoja" class="font-size-lg">No. Última Hoja</label>
                        <input type="number" class="form-control form-control-sm form-control-as font-size-lg" id="numHoja" placeholder="">
                      </div>

                    </div>
                    <div class="form-row align-items-end mt-3">
                      <div class="col-md-3">
                        <div class="custom-control custom-switch">
                          <input type="checkbox" class="custom-control-input" name="cbFecsn" id="cbFecsn">
                          <label class="custom-control-label" for="cbFecsn">Incluye fecha y hora</label>
                        </div>
                      </div>
                      <div class="col-md-2">
                        <div class="custom-control custom-switch">
                          <input type="checkbox" class="custom-control-input" name="cbNoFol" id="cbNoFol">
                          <label class="custom-control-label" for="cbNoFol" class="font-size-lg">Incluye No. Folio</label>
                        </div>
                      </div>
                    </div>
                  </div>

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

                  <div class="form-group">
                    <div class="form-row">
                      <div class="form-group col">
                        <button class="btn btn-primary btn-lg btn-block" id="btnImprimir" type="button">Imprimir</button>
                      </div>
                      <div class="form-group col">
                        <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 dtFecI = document.thisform.dtFecI;
  const dtFecF = document.thisform.dtFecF;
  const txtTitulo = document.thisform.txtTitulo;
  const numHoja = document.thisform.numHoja;
  const cbFecsn = document.thisform.cbFecsn;
  const cbNoFol = document.thisform.cbNoFol;
    
  function restriccion() {
  }

  $(document).ready(function() {
    $(this).find('input:visible:first').focus();
    dtFecI.value = dateToday();
    dtFecF.value = dateToday();
    txtTitulo.value = "Libro Diario";
    numHoja.value = 0;
    cbFecsn.checked = true;
    cbNoFol.checked = true;


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

    // CLICK IMPRIMIR
    $("#btnImprimir").click(function (){
      if (restriccion()) {return};
      
      const getFecI = "?dtFecI="+dtFecI.value;
      const getFecF = "&dtFecF="+dtFecF.value;
      const getTitulo = "&txtTitulo="+txtTitulo.value;
      const getHoja = "&numHoja="+numHoja.value;
      const getFecsn = "&cbFecsn="+cbFecsn.checked;
      const getNoFol = "&cbNoFol="+cbNoFol.checked;

      var url = window.location.origin+window.location.pathname+"print.php"+getFecI+getFecF+getTitulo+getHoja+getFecsn+getNoFol;

      window.open(url, '_blank');
    });

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

      const getFecI = "?dtFecI="+dtFecI.value;
      const getFecF = "&dtFecF="+dtFecF.value;
      const getTitulo = "&txtTitulo="+txtTitulo.value;
      const getHoja = "&numHoja="+numHoja.value;
      const getFecsn = "&cbFecsn="+cbFecsn.checked;
      const getNoFol = "&cbNoFol="+cbNoFol.checked;

      var url = window.location.origin+window.location.pathname+"excel.php"+getFecI+getFecF+getTitulo+getHoja+getFecsn+getNoFol;

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

</script>