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

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

# QUERYS
$sClasic = "SELECT *, TRIM(cla_nom) as cla_nom FROM clasic";
# EJECUCION DE QUERYS
$db = new dbExec();
$select["clasic"] = $db->query($sClasic);

?>
<?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">SALDOS DE ANTIGUEDAD POR DOCUMENTO (CxC)
                </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-md-6">
                        <label for="selClasi">Grupo</label>
                        <select class="form-control form-control-sm form-control-as font-size-m" name="selClasi" id="selClasi">
                          <option value="000">Todos los Grupos</option>
                          <?php
                            while ($rec = $db->fetchAssoc($select['clasic'])) {
                              echo  '<option value="'.$rec['cla_cod'].'">'.utf8_encode($rec['cla_nom']).'</option>';
                            }
                          ?>
                        </select>
                      </div>
                      <div class="col-3">
                        <label for="dtFec">A que fecha</label>
                        <input type="date" class="form-control form-control-sm form-control-as" id="dtFec" placeholder="">
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-3">
                        <label class="pr-1">Moneda en que se generará el reporte</label><br>
                        <div class="custom-control custom-radio custom-control-inline">
                          <input type="radio" id="crTmone1" name="crTmone" class="custom-control-input" value="L">
                          <label class="custom-control-label" for="crTmone1">Moneda Local     </label>
                        </div>
                        <div class="custom-control custom-radio custom-control-inline">
                          <input type="radio" id="crTmone2" name="crTmone" class="custom-control-input" value="E">
                          <label class="custom-control-label" for="crTmone2">Moneda Extranjera</label>
                        </div>
                      </div>
                      <div class="col-1">
                      </div>
                      <div class="col-3">
                        <label class="pr-1">Tipo de Reporte</label><br>
                        <div class="custom-control custom-radio custom-control-inline">
                          <input type="radio" id="crTrepo1" name="crTrepo" class="custom-control-input" value="C">
                          <label class="custom-control-label" for="crTrepo1">Solo Cartera</label>
                        </div>
                        <div class="custom-control custom-radio custom-control-inline">
                          <input type="radio" id="crTrepo2" name="crTrepo" class="custom-control-input" value="A">
                          <label class="custom-control-label" for="crTrepo2">Incluir Anticipos Pendientes de aplicar</label>
                        </div>
                      </div>
                  </div>

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

                  <div class="form-group">
                    <div class="form-row">
                      <div class="col-md-5">
                        <button class="btn btn-primary btn-lg btn-block" id="btnImprimir" type="button">Imprimir</button>
                      </div>
                      <div class="col-md-5">
                        <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 dtFec = document.thisform.dtFec;
  const crTmone = document.thisform.crTmone;
  const crTrepo = document.thisform.crTrepo;

  $(document).ready(function() {
    $(this).find('select:visible:first').focus();
    dtFec.value= '<?php echo $dtFec; ?>';    
    crTmone.value="L";
    crTrepo.value="C";

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

    // CLICK IMPRIMIR
    $("#btnImprimir").click(function (){

      const getselClasi = "?selClasi="+selClasi.value;
      const getdtFec = "&dtFec="+dtFec.value;      
      const getcrTmone = "&crTmone="+crTmone.value;      
      const getcrTrepo = "&crTrepo="+crTrepo.value;      
      var url = window.location.origin+window.location.pathname+"print.php"+getselClasi+getdtFec+getcrTmone+getcrTrepo;

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

    // CLICK EXCEL
    $("#btnExcel").click(function (){
      const getselClasi = "?selClasi="+selClasi.value;
      const getdtFec = "&dtFec="+dtFec.value;      
      const getcrTmone = "&crTmone="+crTmone.value;      
      const getcrTrepo = "&crTrepo="+crTrepo.value;      
      var url = window.location.origin+window.location.pathname+"excel.php"+getselClasi+getdtFec+getcrTmone+getcrTrepo;

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

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