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

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

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

# QUERYS
$sBancos = "SELECT *, 
              TRIM(ban_nom) as ban_nom,
              TRIM(ban_ctab) as ban_ctab,
              TRIM(ban_ctac) as ban_ctac
            FROM bancos WHERE ban_emp='$empCod'";

# EJECUCION DE QUERYS
$db = new dbExec();
$select["bancos"] = $db->query($sBancos);
?>
<?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">Cheques Bono 14</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.5">
                                <label class="font-size-sm" for="numAno">Año al que corresponde</label>
                                <input type="number" class="form-control form-control-sm form-control-as" id="numAno" placeholder="0">
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-6">
                            <label class="font-size-sm text-success" for="selBan">Cuenta para Generar Cheques</label>
                            <select class="form-control form-control-sm form-control-as" name="selBan" id="selBan">
                              <?php
                                while ($rec = $db->fetchAssoc($select['bancos'])) {
                                  echo  '<option value="'.$rec['ban_num'].'" data-ctab="'.$rec['ban_ctab'].'" data-ctac="'.$rec['ban_ctac'].'" data-forma="'.$rec['ban_forma'].'">'.utf8_encode($rec['ban_nom']).'</option>';
                                }
                              ?>
                            </select>
                          </div>
                          <div class="col-3">
                              <label class="font-size-sm" for="dtFec">Fecha de Emision:</label>
                              <input type="date" class="form-control form-control-sm form-control-as" id="dtFec">
                          </div>
                        </div>
                        <div class="form-row">
                        </div>
                      </div>

                      <h3 class="text-light"></h3>
                      <h3 class="text-light"></h3>
                      <div class="form-group">
                        <div class="form-row">
                        </div>
                      </div>
                    </div>

                    <div class="col-md-2">
                      <div class="form-group position-fixed-md">
                        <div class="form-row">
                          <div class="col-12 mt-2">
                            <button class="btn btn-outline-success btn-block" id="btnImprimir" type="button">Generar Cheques</button>
                          </div>
                          <div class="col-3 col-md-12"></div>
                        </div>
                        <div class="form-row">
                          <div class="col-12 mt-2">
                            <button class="btn btn-outline-info btn-block" id="btnReImprimir" type="button">Reimprimir Listado</button>
                          </div>
                          <div class="col-3 col-md-12"></div>
                        </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 btnAddEdit = "00";
  var inputArtic = "txtCodd";
  var inputEmple = "txtCoddm";
  var unimed = "XXX";
  var ctaInc = false;
  
  const numAno = document.thisform.numAno;
  const dtFec = document.thisform.dtFec;


  function restriccion(consultar = false){
    if (!consultar) {
      if (isNullPer(numAno.value)  || numAno.value == 0) {
        numAno.focus();
        alWarning({"msg":{"title":"Campo Vacío","text":"Es necesario ingresar el NO. DE AÑO"}});
        return true;
      }
    } else {
      if (isNullPer(numAno.value)) {
        numAno.focus();
        alWarning({"msg":{"title":"Campo Vacío","text":"Es necesario ingresar el NO. DE AÑO"}});
        return true;
      }
    }
    return false;
  }

  function restriccionCamposVacios() {
    if (isNullPer(numAno.value)) {
      numAno.focus();
      alWarning({"msg":{"title":"Campo Vacío","text":"Es necesario ingresar el NO. DE AÑO"}});
      return true;
    }
    return false;
  }

  function limpiar(){
    dtFec.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; ?>';
    numAno.value = <?php echo $nAnio; ?>;
    dtFec.value = dateToday();

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

  });

    // FOCUS ORDEN DE COMPRA
  //  $("#numOrdenc").change(function (){
  //    consultarOrden();
  //  });



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

      const getnumAno = "?numAno="+numAno.value;
      const getdtFec = "&dtFec="+dtFec.value;      
      const getselBan = "&selBan="+selBan.value;
      const getBannom = "&Bannom="+$('#selBan').find('option:selected').data('ban_nom');
      const getBanctab = "&Banctab="+$('#selBan').find('option:selected').data('ctab');
      const getBanctac = "&Banctac="+$('#selBan').find('option:selected').data('ctac');

      var url = window.location.origin+window.location.pathname+"reprint.php"+getnumAno+getdtFec+getselBan+getBannom+getBanctab+getBanctac;

      window.open(url, '_blank');

    });


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

      const getnumAno = "?numAno="+numAno.value;
      const getdtFec = "&dtFec="+dtFec.value;      
      const getselBan = "&selBan="+selBan.value;
      const getBannom = "&Bannom="+$('#selBan').find('option:selected').data('ban_nom');
      const getBanctab = "&Banctab="+$('#selBan').find('option:selected').data('ctab');
      const getBanctac = "&Banctac="+$('#selBan').find('option:selected').data('ctac');

      var url = window.location.origin+window.location.pathname+"print.php"+getnumAno+getdtFec+getselBan+getBannom+getBanctab+getBanctac;

      window.open(url, '_blank');

      numNum.focus();

    });


  // 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") ? numCoddm.focus() : 0;
        (relatedTarget == "#pills-2") ? selBan.focus() : 0;
      }
      //$(target+' input:visible:first').focus();
    }
  });

</script>

