<?php
  $ruta="../../../";
  include_once($ruta."class/tipobanca.php");
  $tipobanca=new tipobanca;


  include_once($ruta."funciones/funciones.php");
  session_start();
?>
<!DOCTYPE html>
<html lang="es">
<head>
  <?php
    $hd_titulo="Administrar Banca ";
    include_once($ruta."includes/head_basico.php");
    include_once($ruta."includes/head_tabla.php");
    include_once($ruta."includes/head_tablax.php");
  ?>
</head>
<body>
    <?php
      include_once($ruta."head.php");
    ?>
    <div id="main">
      <div class="wrapper">
        <?php
          $idmenu=1038;
          include_once($ruta."aside.php");
        ?>
        <section id="content">
          <!--breadcrumbs start-->
          <div id="breadcrumbs-wrapper">
            <div class="container">
              <div class="row">
                <div class="col s12 m12 l12">
                  <h5 class="breadcrumbs-title"><i class="fa fa-tag"></i> <?php echo $hd_titulo; ?></h5>
                </div>
              </div>
            </div>
          </div>
          <div class="container">
            <div class="section">
            <a href="#modal1" class="btn waves-effect waves-light indigo modal-trigger"><i class="fa fa-plus-square"></i> Nueva Banca</a><br><br>
                <div id="modal1" class="modal">
                  <div class="modal-content">
                  <h1>Nueva Banca</h1>
                    <form class="col s12" id="idform" action="return false" onsubmit="return false" method="POST">
                      <div class="row">
                        <div class="input-field col s12 m6 l6">
                          <input id="idnombre" name="idnombre"   type="text" class="validate">
                          <label for="first_name">NOMBRE BANCA</label>
                        </div> 
                        <div class="input-field col s12 m6 l6">
                          <input id="iddescripcion" name="iddescripcion"  type="text" class="validate">
                          <label for="first_name">Descripcion Banca</label>
                        </div>
                        <div class="input-field col s6">
                          <input id="iddeposito" name="iddeposito" type="number" class="validate">
                          <label for="iddeposito">Desposito acumulado (%)</label>
                        </div>
                        <div class="input-field col s6">
                          <input id="idinteres" name="idinteres" type="number" class="validate">
                          <label for="idinteres">Interés (%)</label>
                        </div> 
                        <div class="input-field col s6">
                          <input id="idseguro" name="idseguro" type="number" class="validate">
                          <label for="idseguro">Seguro (%)</label>
                        </div>
                        <div class="input-field col s12 m12 l6">
                         <label>TIPO PLANILLA</label>
                          <select id="tipoplanilla" name="tipoplanilla">
                            <option value="0">A: CON CREDITO INTERNO</option>
                            <option value="1">B: SIN CREDITO INTERNO</option>
                            <option value="2">C: INDIVIDUAL BANCA</option>
                          </select>
                        </div>
                      </div>
                    </form>
                  </div>
                  <div class="modal-footer">
                    <a href="#" class="btn waves-effect waves-light red modal-action modal-close"><i class="fa fa-times"></i> CANCELAR</a>
                    <button id="btnSave" href="#" class="btn waves-effect waves-light green"><i class="fa fa-save"></i> CREAR BANCA</button>
                  </div>
                </div>
              <div class="col s12 m12 l6">
                <table id="example" class="display" cellspacing="0" width="100%">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>Nombre</th>
                      <th>Descripcion</th>
                      <th>Desposito acumulado</th>
                      <th>Interes</th>
                      <th>Seguro</th>
                      <th>Estado</th>
                      <th>Acciones</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
                    $sw=true;
                    foreach($tipobanca->mostrarTodo("") as $f)
                    {
                      $lblcode=ecUrl($f['idtipobanca']);
                      switch ($f['estado']) {
                        case '0':
                          $estilo="background-color: #f4a742;";
                        break;
                        case '1':
                          $estilo="background-color: #41f462;";
                        break;
                        case '2':
                          $estilo="background-color: #f46741;";
                        break;
                      }
                    ?>
                    <tr style="<?php echo $estilo ?>">
                      <td><?php echo $f['idtipobanca'] ?></td>
                      <td><?php echo $f['nombre'] ?></td>
                      <td><?php echo $f['descripcion'] ?></td>
                      <td><?php echo $f['depositoacumulado'] ?></td>
                      <td><?php echo $f['interes'] ?></td>
                      <td><?php echo $f['seguro'] ?></td> 
                      <td><?php 
                        switch ($f['estado']) {
                          case '0':
                            echo "INACTIVO";
                          break;
                          case '1':
                            echo "ACTIVO";
                          break;
                          case '2':
                            echo "PASADO";
                          break;
                        }
                      ?></td>
                      
                               <td> 
                                  <?php 

                          if ($f['estado']==0) {
                            ?>
                              <button onclick="cambiaestado('<?php echo $lblcode ?>','1');" class="btn-jh darken-4 green">HABILITAR</button>
                            <?php
                          }else {
                            ?>
                              <button onclick="cambiaestado('<?php echo $lblcode ?>','0');" class="btn-jh red">DESHABILITAR</button>
                            <?php
                          }
                        ?>
                        <a href="../parametros/?lblcode=<?php echo $lblcode ?>" class="btn-jh waves-effect darken-4 cyan"><i class="fa fa-cog"></i>Fondo Garantía</a> 
                      
                      </td>
                    </tr>
                    <?php
                      }
                    ?>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
          <?php
            include_once("../../footer.php");
          ?>
        </section>
      </div>
    </div>
    <div id="idresultado"></div>
    <!-- end -->
    <!-- jQuery Library -->
    <?php
      include_once($ruta."includes/script_basico.php");
      include_once($ruta."includes/script_tabla.php");
      include_once($ruta."includes/script_tablax.php");
    ?>
    <script type="text/javascript">
    $(document).ready(function() {
      $('#example').DataTable({
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
      });
      $('#btnSave').click(function(){
         var str=$("#idform").serialize();; 
       //  alert(str);
          $.ajax({
            url: "guardar.php",
            type: "POST",
            data: str,
            success: function(resp){
              console.log(resp);
              $("#idresultado").html(resp);
            }
          });
      });
    });
     function cambiaestado(id,estado){
      swal({
        title: "Estas Seguro?",
        text: "Cambiaras el estado al ejecutivo",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#28e29e",
        confirmButtonText: "Estoy Seguro",
        closeOnConfirm: false
      }, function () {      
        $.ajax({
          url: "cambiarestado.php",
          type: "POST",
          data: "id="+id+"&estado="+estado,
          success: function(resp){
            console.log(resp);
            $("#idresultado").html(resp);
          }   
        });
      }); 
    }
    </script>
</body>

</html>