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

# QUERYS
$sMeses = "SELECT * FROM meses";

# EJECUCION DE QUERYS
$db = new dbExec();
$select["meses"] = $db->query($sMeses);
$db->close();

$AnoTrab=date("Y", strtotime($_SESSION['empFtrab']));
$MesTrab=date("m", strtotime($_SESSION['empFtrab']));
?>
<?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">
                      <div class="col-md-12">
                        <div class="form-row">
                          <div class="col-2">
                            <label class="font-size-md" for="selMes">Mes</label>
                            <select class="form-control form-control-md form-control-as" name="selMes" id="selMes">
                              <option value="0">Seleccionar...</option>
                              <?php
                                while ($rec = $db->fetchAssoc($select['meses'])) {
                                  echo  '<option value="'.$rec['mes_cod'].'">'.utf8_encode($rec['mes_nom']).'</option>';
                                }
                              ?>
                            </select>
                          </div>

                          <div class="col-2">
                            <label class="font-size-md" for="numAno">Año</label>
                            <input type="number" class="form-control form-control-md form-control-as" id="numAno" placeholder="">
                          </div>
                          <div class="col-2">
                            <label  class="font-size-md" for="numFecp">Fecha de Presentacion</label>
                            <input type="date" class="form-control form-control-md form-control-as" id="numFecp" placeholder="">
                          </div>
                        </div>  
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-2">
                          <label  class="font-size-md" for="numRemloc">Remanente Local</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numRemloc" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numRemex">Remanente Exportacion</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numRemex" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numRemiva">Rem. Ret Iva</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numRemiva" placeholder="">
                      </div>
                      <div class="col-1">
                          <label  class="font-size-md" for="numExen">No.Exenciones</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numExen" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numValex">Valor Exenciones</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numValex" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numEspdeb">Fact. Especiales Debito</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numEspdeb" placeholder="">
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-2">
                          <label  class="font-size-md" for="numCreexp">Credi. Fiscal Export</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numCreexp" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numEspcre">Fact. Especiales Credito</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numEspcre" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numNumrec">Declaracion que rectifica</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numNumrec" placeholder="">
                      </div>
                      <div class="col-1">
                          <label  class="font-size-md" for="numValrec">Valor Rectifica</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numValrec" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numCantcone">Cant.Const Emitidas</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numCantcone" placeholder="">
                      </div>
                      <div class="col-3">
                          <label  class="font-size-md" for="numConsrec">No.Const. Adqui Insumos Loc Recibidas</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numConsrec" placeholder="">
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-3">
                          <label  class="font-size-md" for="numConsemi">No.Const. Adqui Insumos Loc Emitidas</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numConsemi" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numCantconr">Cant. Constan. Recibidas</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numCantconr" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numValriva">Val. Reten Iva</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numValriva" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numMulta">Multa</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numMulta" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numInte">Interes</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numInte" placeholder="">
                      </div>
                    </div>
                    <div class="form-row">
                      <div class="col-2">
                          <label  class="font-size-md" for="numMora">Mora</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numMora" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numPoriva">% de Iva P/Locales</label>
                          <input type="number" class="form-control form-control-md form-control-as" id="numPoriva" placeholder="">
                      </div>
                      <div class="col-2">
                          <label  class="font-size-md" for="numNitcon">Nit Contador</label>
                          <input type="text" class="form-control form-control-md form-control-as" id="numNitcon" placeholder="">
                      </div>
                    </div>

                    <div class="form-row">
                      <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>
                  </div>

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

                  <div class="form-group">
                    <div class="form-row">
                      <div class="form-group col-6">
                        <button class="btn btn-primary btn-lg btn-block" id="btnImprimir" type="button">Imprimir</button>
                      </div>
                    </div>
                  </div>
                </form>

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

<script>
  const selMes = document.thisform.selMes;
  const numAno = document.thisform.numAno;
  const numFecp = document.thisform.numFecp;
  const numRemloc = document.thisform.numRemloc;
  const numRemex = document.thisform.numRemex;
  const numRemiva = document.thisform.numRemiva;
  const numExen = document.thisform.numExen;
  const numValex = document.thisform.numValex;
  const numEspdeb = document.thisform.numEspdeb;
  const numCreexp = document.thisform.numCreexp;
  const numEspcre = document.thisform.numEspcre;
  const numNumrec = document.thisform.numNumrec;
  const numValrec = document.thisform.numValrec;
  const numCantcone = document.thisform.numCantcone;
  const numConsrec = document.thisform.numConsrec;
  const numConsemi = document.thisform.numConsemi;
  const numCantconr = document.thisform.numCantconr;
  const numValriva = document.thisform.numValriva;
  const numMulta = document.thisform.numMulta;
  const numInte = document.thisform.numInte;
  const numMora = document.thisform.numMora;
  const numPoriva = document.thisform.numPoriva;
  const numNitcon = document.thisform.numNitcon;
  const cbFecsn = document.thisform.cbFecsn;

  function restriccion() {
    if (isNullPer(selMes.value)) {
      selMes.focus();
      alWarning({"msg":{"title":"Campo Vacío","text":"Es necesario ingresar el Mes"}});
      return true;
    }
    return false;
  }


  function getElements(locationPHP) {
    const getMes = "?selMes="+selMes.value;
    const getMesNom = "&selMesNom="+$("#selMes option:selected").text();
    const getAno = "&numAno="+numAno.value;
    const getFecp = "&numFecp="+numFecp.value;
    const getRemloc = "&numRemloc="+numRemloc.value;
    const getRemex = "&numRemex="+numRemex.value;
    const getRemiva = "&numRemiva="+numRemiva.value;
    const getExen = "&numExen="+numExen.value;
    const getValex = "&numValex="+numValex.value;
    const getEspdeb = "&numEspdeb="+numEspdeb.value;
    const getCreexp = "&numCreexp="+numCreexp.value;
    const getEspcre = "&numEspcre="+numEspcre.value;
    const getNumrec = "&numNumrec="+numNumrec.value;
    const getValrec = "&numValrec="+numValrec.value;
    const getCantcone = "&numCantcone="+numCantcone.value;
    const getConsrec = "&numConsrec="+numConsrec.value;  
    const getConsemi = "&numConsemi="+numConsemi.value;
    const getCantconr = "&numCantconr="+numCantconr.value;
    const getValriva = "&numValriva="+numValriva.value;
    const getMulta = "&numMulta="+numMulta.value;
    const getInte = "&numInte="+numInte.value;
    const getMora = "&numMora="+numMora.value;
    const getPoriva = "&numPoriva="+numPoriva.value;
    const getNitcon = "&numNitcon="+numNitcon.value;
    const getFecsn = "&cbFecsn="+cbFecsn.checked;

    return window.location.origin+window.location.pathname+locationPHP+".php"+getMes+getMesNom+getAno+getFecsn+getFecp+getRemloc+getRemex+getRemiva+getExen+getValex+getEspdeb+getCreexp+getEspcre+getNumrec+getValrec+getCantcone+getConsrec+getConsemi+getCantconr+getValriva+getMulta+getInte+getMora+getPoriva+getNitcon;
  }

  $(document).ready(function() {
    $(this).find('select:visible:first').focus();
    selMes.value = <?php echo $MesTrab; ?>;
    numAno.value = <?php echo $AnoTrab; ?>;
    numFecp.value =  dateToday();
    cbFecsn.checked = true;

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

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

      window.open(getElements("print"), '_blank');
    });
  });

</script>