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

$empCod = $_SESSION['empCod'];

# QUERYS

# EJECUCION DE QUERYS
$db = new dbExec();
?>
<?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">Mantenimiento</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" id="pills-1-tab" data-toggle="pill" href="#pills-1" role="tab" aria-controls="pills-1" aria-selected="false">Buscar Cuentas</a>
              </li>
              <li class="nav-item">
                <a class="nav-link" id="pills-2-tab" data-toggle="pill" href="#pills-2" role="tab" aria-controls="pills-2" aria-selected="false">Buscar Departamentos</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-12 col-sm-9">
                      <div class="form-group">
                        <div class="form-row">
                          <div class="col-12 col-sm-6 col-md-3">
                            <label for="numCod">Codigo</label>
                            <input type="number" class="form-control form-control-sm form-control-as" id="numCod">
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-10">
                            <label for="txtNom">Nombre del Departamento</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtNom" maxlength="80">
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtaord">Cuenta Ordinario</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaord" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaordNom">Nombre de Cuenta Salario Ordinario</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaordNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtahext">Cuenta Extras</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtahext" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtahextNom">Nombre de Cuenta Extras</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtahextNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtabonil">Cuenta Bonif. Ley</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtabonil" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtabonilnom">Nombre de Cuenta Bonif. Ley</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtabonilNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtabonii">Cuenta Boni. Incentivo</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtabonii" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaboniiNom">Nombre de Cuenta Boni. Incentivo</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaboniiNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtacomi">Cuenta Comisiones</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtacomi" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtacomiNom">Nombre Cuenta Comisiones</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtacomiNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtabonoe">Cuenta Bono Extra</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtabonoe" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtabonoeNom">Nombre de Cuenta Bono Extra</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtabonoeNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtadepre">Cuenta Depre. Vehiculo</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtadepre" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtadepreNom">Nombre Cuenta Depre. Vehiculo</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtadepreNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaviati">Cuenta Viaticos</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaviati" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaviatiNom">Nombre Cuenta Viaticos</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaviatiNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtadevisr">Cuenta Devolucion ISR</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtadevisr" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtadevisrNom">Nombre Cuenta Devolucion ISR</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtadevisrNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaotring">Cuenta Otros/Ingre.</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaotring" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaotringNom">Nombre Cuenta Pago Otros Ingresos</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaotringNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtaigss">Cuenta Para Igss Laboral</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaigss" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaigssNom">Nombre Cuenta Para Igss Laboral</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaigssNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaisr">Cuenta Para ISR</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaisr" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaisrNom">Nombre de Cuenta Para ISR</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaisrNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtapreb">Cuenta Para Prestamos Bancarios</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtapreb" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaprebNom">Nombre de Cuenta Para Prestamos Bancarios</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaprebNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtapree">Cuenta Para Prestamos Empresa</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtapree" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtapreeNom">Nombre de Cuenta Prestamos Empresa</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtapreeNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtadesj">Cuenta Para Desc. Judicial</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtadesj" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtadesjNom">Nombre de Cuenta Desc. Judicial</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtadesjNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaunif">Cuenta Para Uniforme</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaunif" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaunifNom">Nombre de Cuenta Uniforme</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaunifNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtalent">Cuenta Lentes</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtalent" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtalentNom">Nombre de Cuenta Lentes</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtalentNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaanti">Cuenta Para Anticipos</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaanti" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaantiNom">Nombre de Cuenta Anticipos</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaantiNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtaotrd">Cuenta Otros/Desc.</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaotrd" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaotrdNom">Nombre de Cuenta Otros Descuentos</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaotrdNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>

                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtasueldos">Cuenta Para Sueldos (Pasivo)</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtasueldos" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtasueldosNom">Nombre de Cuenta Para Sueldos</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtasueldosNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaigssp">Cuenta Para Igss Patronal</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaigssp" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaigsspNom">Nombre de Cuenta Igss Patronal</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaigsspNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtairtra">Cuenta Para IRTRA</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtairtra" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtairtraNom">Nombre de Cuenta IRTRA</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtairtraNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaintecap">Cuenta Para INTECAP</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaintecap" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaintecapNom">Nombre de Cuenta INTECAP</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaintecapNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtavaca">Cuenta Vacaciones</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtavaca" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtavacaNom">Nombre de Cuenta Vacaciones</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtavacaNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaaguinal">Cuenta Para aguinaldo</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaaguinal" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaaguinalNom">Nombre de Cuenta Aguinaldo</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaaguinalNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtabono14">Cuenta Bono 14</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtabono14" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtabono14Nom">Nombre de Cuenta Bono 14</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtabono14Nom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaindem">Cuenta Para Indemnización</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaindem" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaindemNom">Nombre de Cuenta Indemnización</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaindemNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtaprovaca">Cuenta Provision Vacaciones</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaprovaca" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaprovacaNom">Nombre de Cuenta Prov. Vacaciones</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaprovacaNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaproaguinal">Cuenta Para Provision aguinaldo</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaproaguinal" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaproaguinalNom">Nombre de Cuenta Prov. Aguinaldo</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaproaguinalNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtaprobono14">Cuenta Provision Bono 14</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaprobono14" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaprobono14Nom">Nombre de Cuenta Prov.Bono 14</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaprobono14Nom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-md-2">
                            <label for="txtCtaproindem">Cuenta Para Provision Indemnización</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaproindem" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaproindemNom">Nombre de Cuenta Prov.Indemnización</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaproindemNom" placeholder="Cuenta no definida" disabled>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-md-2">
                            <label for="txtCtaprocpi">Cuenta Provision Cuota Patronal</label>
                            <input type="text" class="form-control form-control-sm form-control-as" id="txtCtaprocpi" placeholder="">
                          </div>
                          <div class="col-md-4">
                            <label for="txtCtaprocpiNom">Nombre de Cuenta Prov. Cuota Patronal</label>
                            <input type="text" class="form-control form-control-sm form-control-as form-info" id="txtCtaprocpiNom" placeholder="Cuenta no definida" disabled>
                          </div>
                          <div class="col-1">
                            <label> </label>
                          </div>
                        </div>
                      </div>
                      <div class="form-group">
                        <div class="form-row">
                          <div class="col-2">
                            <label> </label>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-2">
                            <label> </label>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-2">
                            <label> </label>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-2">
                            <label> </label>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="col-12 col-lg-3 col-xl-2 text-left mt-5">
                      <div class="form-group position-fixed-lg w-lg-3 w-xl-2">
                        <div class="form-row">
                          <div class="col-11 mt-2">
                            <button class="btn btn-success btn-lg btn-block" id="btnGuardar" type="button">Guardar</button>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-11 mt-2">
                            <button class="btn btn-danger btn-lg btn-block" id="btnBorrar" type="button">Borrar</button>
                          </div>
                        </div>
                        <div class="form-row">
                          <div class="col-11 mt-2">
                            <button class="btn btn-info btn-lg btn-block" id="btnLista" type="button">Listado de Departamentos</button>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </form>
              </div>
              <div class="tab-pane fade" id="pills-1" role="tabpanel" aria-labelledby="pills-1-tab">
                <?php
                  $a='0';
                  $b='1';
                  include('../busCuentasMov/index.html')
                ?>
              </div>
              <div class="tab-pane fade" id="pills-2" role="tabpanel" aria-labelledby="pills-2-tab">
                <?php
                  $a='0';
                  $b='2';
                  include('../busDeppla/index.html')
                ?>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
<?php include_once('../../../php/includes/htmlClose.php'); ?>

<script>
  var pressEnter = false;
  var nuevo = true;
  var inputNumb = "numNumb";
  var inputCtaMov = "txtCtaord";
  var inputClien = "txtCli"
  var inputCod = "numCod";

  const txtCodp = document.thisform.txtCodp;
  const txtNom = document.thisform.txtNom;
  const txtCtaord = document.thisform.txtCtaord;
  const txtCtahext = document.thisform.txtCtahext;
  const txtCtabonil = document.thisform.txtCtabonil;
  const txtCtabonii = document.thisform.txtCtabonii;
  const txtCtacomi = document.thisform.txtCtacomi;
  const txtCtabonoe= document.thisform.txtCtabonoe;
  const txtCtadepre= document.thisform.txtCtadepre;
  const txtCtaviati= document.thisform.txtCtaviati;
  const txtCtadevisr= document.thisform.txtCtadevisr;
  const txtCtaotring = document.thisform.txtCtaotring;
  const txtCtaigss = document.thisform.txtCtaigss;
  const txtCtaisr = document.thisform.txtCtaisr;
  const txtCtapreb = document.thisform.txtCtapreb;
  const txtCtapree = document.thisform.txtCtapree;
  const txtCtadesj = document.thisform.txtCtadesj;
  const txtCtaunif = document.thisform.txtCtaunif;
  const txtCtalent = document.thisform.txtCtalent;
  const txtCtaanti = document.thisform.txtCtaanti;
  const txtCtaotrd = document.thisform.txtCtaotrd;
  const txtCtasueldos = document.thisform.txtCtasueldos;
  const txtCtaigssp = document.thisform.txtCtaigssp;
  const txtCtairtra = document.thisform.txtCtairtra;
  const txtCtaintecap = document.thisform.txtCtaintecap;
  const txtCtavaca = document.thisform.txtCtavaca;
  const txtCtaaguinal = document.thisform.txtCtaaguinal;
  const txtCtabono14 = document.thisform.txtCtabono14;
  const txtCtaindem = document.thisform.txtCtaindem;
  const txtCtaprovaca = document.thisform.txtCtaprovaca;
  const txtCtaproaguinal = document.thisform.txtCtaproaguinal;
  const txtCtaprobono14 = document.thisform.txtCtaprobono14;
  const txtCtaproindem = document.thisform.txtCtaproindem;
  const txtCtaprocpi = document.thisform.txtCtaprocpi;


  function restriccion(consultar = false){
    if (!consultar) {
      if (isNullPer(numCod.value)) {
        numCod.focus();
        alWarning({"msg":{"title":"Campo Vacío","text":"Es necesario ingresar el CÓDIGO DEL DEPARTAMENTO"}});
        return true;
      }
      if (isNullPer(txtNom.value)) {
        txtNom.focus();
        alWarning({"msg":{"title":"Campo Vacío","text":"Es necesario ingresar el Nombre del Departamento"}});
        return true;
      }
    } else {
      if (isNullPer(numCod.value)) {
        limpiar();
        return true;
      }
    }
    return false;
  }
  
  function restriccionCamposVacios() {
    if (isNullPer(numCod.value)) {
      numCod.focus();
      alWarning({"msg":{"title":"Campo Vacío","text":"Es necesario ingresar EL CODIGO DEL DEPARTAMENTO"}});
      return true;
    }
    return false;
  }

  function restriccionCtadif() {
    if (isNullPer(txtThis.value)) {
      txtCtadNom.value = "";
      return true;
    }
    return false;
  }

  function restriccionCtac() {
    if (isNullPer(txtThis.value)) {
      txtThis.value = "";
      return true;
    }
    return false;
  }

  function limpiar(){
    txtNom.value = "";
    txtCtaord.value = "";
    txtCtaordNom.value = "";
    txtCtahext.value = "";
    txtCtahextNom.value = "";
    txtCtabonil.value = "";
    txtCtabonilNom.value = "";
    txtCtabonii.value = "";
    txtCtaboniiNom.value = "";
    txtCtacomi.value = "";
    txtCtacomiNom.value = "";
    txtCtabonoe.value = "";
    txtCtabonoeNom.value = "";
    txtCtadepre.value = "";
    txtCtadepreNom.value = "";
    txtCtaviati.value = "";
    txtCtaviatiNom.value = "";
    txtCtadevisr.value = "";
    txtCtadevisrNom.value = "";
    txtCtaotring.value = "";
    txtCtaotringNom.value = "";
    txtCtaigss.value = "";
    txtCtaigssNom.value = "";
    txtCtaisr.value = "";
    txtCtaisrNom.value = "";
    txtCtapreb.value = "";
    txtCtaprebNom.value = "";
    txtCtapree.value = "";
    txtCtapreeNom.value = "";
    txtCtadesj.value = "";
    txtCtadesjNom.value = "";
    txtCtaunif.value = "";
    txtCtaunifNom.value = "";
    txtCtalent.value = "";
    txtCtalentNom.value = "";
    txtCtaanti.value = "";
    txtCtaantiNom.value = "";
    txtCtaotrd.value = "";
    txtCtaotrdNom.value = "";
    txtCtasueldos.value = "";
    txtCtasueldosNom.value = "";
    txtCtaigssp.value = "";
    txtCtaigsspNom.value = "";
    txtCtairtra.value = "";
    txtCtairtraNom.value = "";
    txtCtaintecap.value = "";
    txtCtaintecapNom.value = "";
    txtCtavaca.value = "";
    txtCtavacaNom.value = "";
    txtCtaaguinal.value = "";
    txtCtaaguinalNom.value = "";
    txtCtabono14.value = "";
    txtCtabono14Nom.value = "";
    txtCtaindem.value = "";
    txtCtaindemNom.value = "";
    txtCtaprovaca.value = "";
    txtCtaprovacaNom.value = "";
    txtCtaproaguinal.value = "";
    txtCtaproaguinalNom.value = "";
    txtCtaprobono14.value = "";
    txtCtaprobono14Nom.value = "";
    txtCtaproindem.value = "";
    txtCtaproindemNom.value = "";
    txtCtaprocpi.value = "";
    txtCtaprocpiNom.value = "";
  }

  $(document).ready(function() {
    $(this).find('input:visible:first').focus();
    txtNom.value = "";
    txtCtaord.value = "";
    txtCtaordNom.value = "";
    txtCtahext.value = "";
    txtCtahextNom.value = "";
    txtCtabonil.value = "";
    txtCtabonilNom.value = "";
    txtCtabonii.value = "";
    txtCtaboniiNom.value = "";
    txtCtacomi.value = "";
    txtCtacomiNom.value = "";
    txtCtabonoe.value = "";
    txtCtabonoeNom.value = "";
    txtCtadepre.value = "";
    txtCtadepreNom.value = "";
    txtCtaviati.value = "";
    txtCtaviatiNom.value = "";
    txtCtadevisr.value = "";
    txtCtadevisrNom.value = "";
    txtCtaotring.value = "";
    txtCtaotringNom.value = "";
    txtCtaigss.value = "";
    txtCtaigssNom.value = "";
    txtCtaisr.value = "";
    txtCtaisrNom.value = "";
    txtCtapreb.value = "";
    txtCtaprebNom.value = "";
    txtCtapree.value = "";
    txtCtapreeNom.value = "";
    txtCtadesj.value = "";
    txtCtadesjNom.value = "";
    txtCtaunif.value = "";
    txtCtaunifNom.value = "";
    txtCtalent.value = "";
    txtCtalentNom.value = "";
    txtCtaanti.value = "";
    txtCtaantiNom.value = "";
    txtCtaotrd.value = "";
    txtCtaotrdNom.value = "";
    txtCtasueldos.value = "";
    txtCtasueldosNom.value = "";
    txtCtaigssp.value = "";
    txtCtaigsspNom.value = "";
    txtCtairtra.value = "";
    txtCtairtraNom.value = "";
    txtCtaintecap.value = "";
    txtCtaintecapNom.value = "";
    txtCtavaca.value = "";
    txtCtavacaNom.value = "";
    txtCtaaguinal.value = "";
    txtCtaaguinalNom.value = "";
    txtCtabono14.value = "";
    txtCtabono14Nom.value = "";
    txtCtaindem.value = "";
    txtCtaindemNom.value = "";
    txtCtaprovaca.value = "";
    txtCtaprovacaNom.value = "";
    txtCtaproaguinal.value = "";
    txtCtaproaguinalNom.value = "";
    txtCtaprobono14.value = "";
    txtCtaprobono14Nom.value = "";
    txtCtaproindem.value = "";
    txtCtaproindemNom.value = "";
    txtCtaprocpi.value = "";
    txtCtaprocpi.value = "";

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

    // FOCUS INPUT
    $("form[name='thisform'] input, select").focus(function (){
      if (!($("input:visible:first").is(":focus"))) {
        if (restriccionCamposVacios()) {return};
      }
    });

    // VALID CODIGO PROYECTO
    $("#numCod")
    .focus(function() {
      numCod.value = "";
      limpiar();
      inputCod = $(this).attr('id');
    })
    .keypress(function(e) {
      const keycode = e.keyCode || e.which;
      if (keycode == '13') {pressEnter = true;}
    })
    .keydown(function(e){
      if(ctrlBus(e)) { document.getElementById("pills-2-tab").click(); }
    })
    .change(function (){
      txtThis = this;
      const parametros = new FormData();
      parametros.append("action", "consultar");
      parametros.append("numCod", numCod.value);

      $.ajax({
        data:  parametros,
        url:   window.location.origin+window.location.pathname+"actions.php",
        type:  "post",
        contentType: false,
        processData: false,
        success: function (jsonPhp) {
          //console.log(jsonPhp);
          const jsonJS = JSON.parse(jsonPhp);

          if(jsonJS.error == true){
            alError(jsonJS);
            nuevo = true;
          } else {
            if (isNullPer(jsonJS.dep)) {
              nuevo = true;
            } else {
              txtNom.value = jsonJS.dep.dep_nom;
              txtCtaord.value = jsonJS.dep.dep_ctaord;
              txtCtaordNom.value = jsonJS.dep.dep_ctaordnom;
              txtCtahext.value = jsonJS.dep.dep_ctahext;
              txtCtahextNom.value = jsonJS.dep.dep_ctahextnom;
              txtCtabonil.value = jsonJS.dep.dep_ctabonil;
              txtCtabonilNom.value = jsonJS.dep.dep_ctabonilnom;
              txtCtabonii.value = jsonJS.dep.dep_ctabonii;
              txtCtaboniiNom.value = jsonJS.dep.dep_ctaboniinom;
              txtCtacomi.value = jsonJS.dep.dep_ctacomi;
              txtCtacomiNom.value = jsonJS.dep.dep_ctacominom;
              txtCtabonoe.value = jsonJS.dep.dep_ctabonoe;
              txtCtabonoeNom.value = jsonJS.dep.dep_ctabonoenom;
              txtCtadepre.value = jsonJS.dep.dep_ctadepre;
              txtCtadepreNom.value = jsonJS.dep.dep_ctadeprenom;
              txtCtaviati.value = jsonJS.dep.dep_ctaviati;
              txtCtaviatiNom.value = jsonJS.dep.dep_ctaviatinom;
              txtCtadevisr.value = jsonJS.dep.dep_ctadevisr;
              txtCtadevisrNom.value = jsonJS.dep.dep_ctadevisrnom;
              txtCtaotring.value = jsonJS.dep.dep_ctaotrp;
              txtCtaotringNom.value = jsonJS.dep.dep_ctaotrpnom;
              txtCtaigss.value = jsonJS.dep.dep_ctaigss;
              txtCtaigssNom.value = jsonJS.dep.dep_ctaigssnom;
              txtCtaisr.value = jsonJS.dep.dep_ctaisr;
              txtCtaisrNom.value = jsonJS.dep.dep_ctaisrnom;
              txtCtapreb.value = jsonJS.dep.dep_ctapreb;
              txtCtaprebNom.value = jsonJS.dep.dep_ctaprebnom;
              txtCtapree.value = jsonJS.dep.dep_ctapree;
              txtCtapreeNom.value = jsonJS.dep.dep_ctapreenom;
              txtCtadesj.value = jsonJS.dep.dep_ctadesj;
              txtCtadesjNom.value = jsonJS.dep.dep_ctadesjnom;
              txtCtaunif.value = jsonJS.dep.dep_ctaunif;
              txtCtaunifNom.value = jsonJS.dep.dep_ctaunifnom;
              txtCtalent.value = jsonJS.dep.dep_ctalent;
              txtCtalentNom.value = jsonJS.dep.dep_ctalentnom;
              txtCtaanti.value = jsonJS.dep.dep_ctaanti;
              txtCtaantiNom.value = jsonJS.dep.dep_ctaantinom;
              txtCtaotrd.value = jsonJS.dep.dep_ctaotrd;
              txtCtaotrdNom.value = jsonJS.dep.dep_ctaotrdnom;
              txtCtasueldos.value = jsonJS.dep.dep_ctasueldos;
              txtCtasueldosNom.value = jsonJS.dep.dep_ctasueldosnom;
              txtCtaigssp.value = jsonJS.dep.dep_ctacpi;
              txtCtaigsspNom.value = jsonJS.dep.dep_ctacpinom;
              txtCtairtra.value = jsonJS.dep.dep_ctairtra;
              txtCtairtraNom.value = jsonJS.dep.dep_ctairtranom;
              txtCtaintecap.value = jsonJS.dep.dep_ctaintecap;
              txtCtaintecapNom.value = jsonJS.dep.dep_ctaintecapnom;
              txtCtavaca.value = jsonJS.dep.dep_ctavac;
              txtCtavacaNom.value = jsonJS.dep.dep_ctavacnom;
              txtCtaaguinal.value = jsonJS.dep.dep_ctaag;
              txtCtaaguinalNom.value = jsonJS.dep.dep_ctaagnom;
              txtCtabono14.value = jsonJS.dep.dep_ctabon;
              txtCtabono14Nom.value = jsonJS.dep.dep_ctabonnom;
              txtCtaindem.value = jsonJS.dep.dep_ctaind;
              txtCtaindemNom.value = jsonJS.dep.dep_ctaindnom;
              txtCtaprovaca.value = jsonJS.dep.dep_ctaprovac;
              txtCtaprovacaNom.value = jsonJS.dep.dep_ctaprovacnom;
              txtCtaproaguinal.value = jsonJS.dep.dep_ctaproag;
              txtCtaproaguinalNom.value = jsonJS.dep.dep_ctaproagnom;
              txtCtaprobono14.value = jsonJS.dep.dep_ctaprobon;
              txtCtaprobono14Nom.value = jsonJS.dep.dep_ctaprobonnom;
              txtCtaproindem.value = jsonJS.dep.dep_ctaproind;
              txtCtaproindemNom.value = jsonJS.dep.dep_ctaproindnom;
              txtCtaprocpi.value = jsonJS.dep.dep_ctaprocpi;
              txtCtaprocpiNom.value = jsonJS.dep.dep_ctaprocpinom;

              nuevo = false;
            }
          }
        }
      });
    });

    // VALID PARA LAS CUENTAS CONTABLES.
    $("#txtCtaord, #txtCtahext, #txtCtabonil, #txtCtabonii, #txtCtacomi, #txtCtabonoe, #txtCtadepre, #txtCtaviati, #txtCtadevisr, #txtCtaotring, #txtCtaigss, #txtCtaisr, #txtCtapreb, #txtCtapree, #txtCtadesj, #txtCtaunif, #txtCtalent, #txtCtaanti, #txtCtaotrd, #txtCtasueldos, #txtCtaigssp, #txtCtairtra, #txtCtaintecap, #txtCtavaca, #txtCtaaguinal, #txtCtabono14, #txtCtaindem, #txtCtaprovaca, #txtCtaproaguinal, #txtCtaprobono14, #txtCtaproindem, #txtCtaprocpi")
    .focus(function() {
      inputCtaMov = $(this).attr('id');
    })
    .keypress(function(e) {
      const keycode = e.keyCode || e.which;
      if (keycode == '13') {pressEnter = true;}
    })
    .keydown(function(e){
      if(ctrlBus(e)) { document.getElementById("pills-1-tab").click(); }
    })
    .change(function (){
      txtThis = this;
      txtGetValue = $('#'+inputCtaMov+'Nom');
      //document.getElementById("txtCtaNom");
      txtNext = $('#'+inputCtaMov+'Nom');
      console.log(inputCtaMov,txtNext, txtGetValue);      
      //document.getElementById("txtCtad");
      $(txtThis).off("blur");
      if (restriccionCtac()) {return};

      const parametros = new FormData();
      parametros.append("action", "consultarCta");
      parametros.append("txtCta", txtThis.value);

      $.ajax({
        data:  parametros,
        url:   window.location.origin+window.location.pathname+"actions.php",
        type:  "post",
        contentType: false,
        processData: false,
        beforeSend: function () {
          alLoad("Consultando...")
        },
        success: function (jsonPhp) {
          //console.log(jsonPhp);
          const jsonJS = JSON.parse(jsonPhp);

          if(jsonJS.error == true){
            alError(jsonJS);
          } else {
            if (jsonJS.cuentas === null) {
              txtGetValue.value = "";
              alErrorFocus({"msg":{"type":"error","title":"No existe","text":"La cuenta "+txtThis.value+" no ha sido registrada", "ok":"Aceptar"}}, txtThis);
            } else {
              txtGetValue.value = jsonJS.cuentas.cta_nom;
              (pressEnter) ? alClose() : alCloseFocus(txtNext);
            }
            pressEnter = false;
            blurOn(txtThis, txtGetValue);
          }
        }
      });
    });


    // CLICK BORRAR
    $("#btnBorrar").click(function (){
      if (restriccion()) {return};
      const fnT = function(){
        const parametros = new FormData();
        parametros.append("action", "borrar");

        parametros.append("numCod", numCod.value);
        parametros.append("txtNom", txtNom.value);
        
        $.ajax({
          data:  parametros,
          url:   window.location.origin+window.location.pathname+"actions.php",
          type:  "post",
          contentType: false,
          processData: false,
          beforeSend: function () {
            alLoad("Cargando...")
          },
          success: function (jsonPhp) {
            const jsonJS = JSON.parse(jsonPhp);

            if(jsonJS.error==true){
              alError(jsonJS);
            } else {
              alSuccess(jsonJS);
              limpiar();
              numCod.value = "";
            }
          }
        });
      }

      const fnF = function(){
        return true;
      }

      usuClave(fnT, fnF);
    });

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

      const parametros = new FormData();
      parametros.append("action", "guardar");

      parametros.append("nuevo", nuevo);
      parametros.append("numCod", numCod.value);
      parametros.append("txtNom", txtNom.value);
      parametros.append("txtCtaord", txtCtaord.value);
      parametros.append("txtCtahext", txtCtahext.value);
      parametros.append("txtCtabonil", txtCtabonil.value);
      parametros.append("txtCtabonii", txtCtabonii.value);
      parametros.append("txtCtacomi", txtCtacomi.value);
      parametros.append("txtCtabonoe", txtCtabonoe.value);
      parametros.append("txtCtadepre", txtCtadepre.value);
      parametros.append("txtCtaviati", txtCtaviati.value);
      parametros.append("txtCtadevisr", txtCtadevisr.value);
      parametros.append("txtCtaotrp", txtCtaotring.value);
      parametros.append("txtCtaigss", txtCtaigss.value);
      parametros.append("txtCtaisr", txtCtaisr.value);
      parametros.append("txtCtapreb", txtCtapreb.value);
      parametros.append("txtCtapree", txtCtapree.value);
      parametros.append("txtCtadesj", txtCtadesj.value);
      parametros.append("txtCtaunif", txtCtaunif.value);
      parametros.append("txtCtalent", txtCtalent.value);
      parametros.append("txtCtaanti", txtCtaanti.value);
      parametros.append("txtCtaotrd", txtCtaotrd.value);
      parametros.append("txtCtasueldos", txtCtasueldos.value);
      parametros.append("txtCtacpi", txtCtaigssp.value);
      parametros.append("txtCtairtra", txtCtairtra.value);
      parametros.append("txtCtaintecap", txtCtaintecap.value);
      parametros.append("txtCtavac", txtCtavaca.value);
      parametros.append("txtCtaag", txtCtaaguinal.value);
      parametros.append("txtCtabon", txtCtabono14.value);
      parametros.append("txtCtaind", txtCtaindem.value);
      parametros.append("txtCtaprovac", txtCtaprovaca.value);
      parametros.append("txtCtaproag", txtCtaproaguinal.value);
      parametros.append("txtCtaprobon", txtCtaprobono14.value);
      parametros.append("txtCtaproind", txtCtaproindem.value);
      parametros.append("txtCtaprocpi", txtCtaprocpi.value);

      numCod.focus();
      
      $.ajax({
        data:  parametros,
        url:   window.location.origin+window.location.pathname+"actions.php",
        type:  "post",
        contentType: false,
        processData: false,
        beforeSend: function () {
          alLoad("Cargando...")
        },
        success: function (jsonPhp) {
          console.log(jsonPhp);
          const jsonJS = JSON.parse(jsonPhp);

          if(jsonJS.error==true){
            alError(jsonJS);
          } else {
            alSuccess(jsonJS);
            limpiar();
            numCod.value = "";
          }
        }
      });
    });
    // CLICK IMPRIMIR
    $("#btnLista").click(function (){

      //const getselClasi = "?selClasi="+selClasi.value;
      var url = window.location.origin+window.location.pathname+"print.php";

      window.open(url, '_blank');

      numCod.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" && isNullPer(numCod.value)) || target != "#pills-0") {
        $(target+' input:visible:first').focus();
      } else {
        (relatedTarget == "#pills-1") ? $('#'+inputCtaMov).focus() : 0;
        (relatedTarget == "#pills-2") ? txtNom.focus() : 0;
      }
    }
  });

</script>