{% extends "baseAdmin.html" %}
{% load static %}
{% block titulo %}
  .::Configuración de Sistema
{% endblock titulo %}
{% block content1 %}
<script type="text/javascript">
  $("#navOficinas").attr('class','dropdown active');
  $("#navConfigSistema").attr('class','active');
</script>
<div class="row">
  <div class="col-md-12 col-sm-12" >
      <div class="panel panel-default">
        <div class="panel-heading"> <strong>OFICINAS</strong></div>
        <div class="panel-body">
        <p></p>
          <div class="row">
            <div class="col-md-2 col-md-offset-1">
              <button type="button" class="btn btn-primary btn-block  btn-sm" id="btnRefrescar"><span class="fa fa-refresh"></span> Actualizar</button>
            </div>
          </div>
          <p></p>
          <div class="row">
             <div class="row" id="Result">
            {% ifnotequal resultado None %}
            {% ifnotequal resultado '' %}
            {% ifequal resultado 'exito' %}
            <div class="alert alert-success" role="alert" align="center">
              <h4>OPERACION EXITOSA!!</h4>
            </div>
            {% else %}
            <div class="alert alert-danger" role="alert" align="center">
              <h4>FALLO OPERACIÓN :( {{resultado}}</h4>
            </div>
            {% endifequal %}
            {% endifnotequal %}
            {% endifnotequal %}
          </div>
            <div class="col-md-10 col-md-offset-1">
                <div class="table-responsive m-b-10">
                  <table class="table table-bordered table-striped">
                      <thead>
                        <tr>
                          <th>Nro</th>
                          <th>Oficina</th>
                        </tr>
                      </thead>
                      <tbody id="listaR">
                          
                      </tbody>
                  </table>
                </div>
            </div>
            
          </div>
        </div>
      </div>
  </div>
</div>

     <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel">Detalles</h4>
            </div>
            <div class="modal-body">
              <div class="row">
                <div class="col-md-12">
                  <div class="panel panel-default">
                        <div class="panel-body">
                          <div class="row">
                            <div class="col-md-12">
                              <h4 class="bg-success" align="center">
                                <!--&nbsp;-->
                                Configuración Cajas
                              </h4>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-md-10" align="right">
                              <label>Oficina: </label>
                            </div>
                            <div class="col-md-2">
                              <input type="text" class="form-control" id="txtidOfi" >
                              <p></p>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-md-12">
                              <div class="table-responsive">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                      <tr>
                                        <th>Nombre</th>
                                        <th>Operador</th>
                                        <th>Tipo de sistema</th>
                                        <th>Caja Dolar</th>
                                      </tr>
                                    </thead>
                                    <tbody id="listaCa">
                                    </tbody>
                                </table>
                              </div>
                            </div>
                          </div>

                        </div><!--fin panel body-->
                      </div>
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
            </div>
          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
      </div>

      <div id="Modalmovi" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel">Detalles</h4>
            </div>
            <div class="modal-body">
              <div class="row">
                <div class="col-md-12">
                  <div class="panel panel-default">
                        <div class="panel-body">
                          <form id="formConfiguracion" action="/Admin/configurarTiposistema_caja/" method="POST" data-toggle="validator" role="form"> {% csrf_token %}
                            <div class="row">
                              <div class="col-md-12">
                                <h4 class="bg-success" align="center">
                                  <!--&nbsp;-->
                                  Información de la Caja
                                </h4>
                              </div>
                            </div>
                            <div class="row">
                              <div class="col-md-2" align="right">
                                <label>Caja: </label>
                              </div>
                              <div class="col-md-5">
                                <input type="text" class="form-control" id="txtnombreCa" readonly>
                                <p></p>
                              </div>
                              <div class="col-md-2" align="right">
                                <label>Id Caja: </label>
                              </div>
                              <div class="col-md-3">
                                <input type="text" class="form-control" name="pkC" id="txtidCa" readonly>
                                <p></p>
                              </div>

                              <input type="text" class="form-control hidden" id="txtpkConf" readonly="readonly">
                                   
                            </div>
                            <div class="row">
                              <div class="col-md-2" align="right">
                                <label>Encargado: </label>
                              </div>
                              <div class="col-md-8">
                                <input type="text" class="form-control" id="txtencargadoCa" readonly>
                                <p></p>
                              </div>
                            </div>
                            <p></p>
                            <div class="row">
                              <div class="col-md-12">
                                <h4 class="bg-success" align="center">
                                  <!--&nbsp;-->
                                  Configuración  de Sistema
                                </h4>
                              </div>
                            </div>
                            <div class="row">
                              <div class="col-md-4 col-md-offset-1"  align="right">
                                <label>Tipo de Sistema: </label>
                              </div>
                              <div class="col-md-6">
                                <div class="select"> 
                                  <select class="form-control" name="ts" id="txtts" >
                                    <option value="transferencia">Transferencias</option>
                                    <option value="hibrido">Transferencias y Material</option>
                                    <option value="material">Material</option>
                                  </select>
                                </div>
                                <p></p>
                              </div>
                            </div>
                            <p></p>
                            <div class="row">
                              <div class="col-md-4 col-md-offset-1" align="right">
                                <label>Caja Dolar: </label>
                              </div>
                              <div class="col-md-3">
                              <div class="fg-line"> 
                                <div class="select"> 
                                  <select class="form-control" name="cd" id="txtcd">
                                    <option value="si">si</option>
                                    <option value="no">no</option>
                                  </select>
                                </div>
                              </div>
                                <p></p>
                              </div>
                            </div>
                            <p></p>
                            <div class="row alert alert-warning">
                              <div class="col-md-4 col-md-offset-1" align="right">
                                <label>Tesoreria: </label>
                              </div>
                              <div class="col-md-3">
                              <div class="fg-line"> 
                                <div class="select"> 
                                  <select class="form-control" name="te" id="txtte">
                                    <option value="si">si</option>
                                    <option value="no">no</option>
                                  </select>
                                </div>
                              </div>
                             
                              </div>
                              <label > Atencion: Solo se permite una caja como TESORERIA, y debe de estar en la oficina central</label>
                            </div>
                               <p></p>
                              <p></p>
                            <div class="row">
                              <div class="col-md-4 col-md-offset-1" align="right">
                                <label>Monitor tactil en Compra Material: </label>
                              </div>
                              <div class="col-md-3">
                              <div class="fg-line"> 
                                <div class="select"> 
                                  <select class="form-control" name="cota" id="txtcota">
                                    <option value="si">si</option>
                                    <option value="no">no</option>
                                  </select>
                                </div>
                              </div>
                                <p></p>
                              </div>
                            </div>
                          <div class="row">
                                <div class="col-md-4 col-md-offset-4 col-xs-4 col-xs-offset-4">
                                  <button class="btn btn-primary btn-block" id="btnActualizar"type="submit">Actualizar</button>
                                </div>
                              </div>
                           </form>  
                        </div><!--fin panel body-->
                      </div>
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
            </div>
          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
      </div>
     <script type="text/javascript">
      Aux=[];
      Aux3=[];
      $(document).ready(function (){
        //ajax oficinas
         $("#listaR").on("click",".filaOf",function(){
          var num = $(this).prop('id');
          filaI2 = num;
          var fila= $(this).prop('class');
          $("."+fila).prop('class','filaOf');
          $(this).prop('class','filaOf warning');
          ajax_caja(Aux[filaI2].pk);
          //insertando datos en el modal
          $("#txtidOfi").prop('value',Aux[filaI2].pk);
          $("#txtof").text(Aux[filaI2].of);
        });
         //ajax caja conf
        $("#listaCa").on("click",".filaCa",function(){
          $("#listaO").html("");
          $("#grupo_f").hide();
          var num = $(this).prop('id');
          filaI3 = num;
          var fila= $(this).prop('class');
          $("."+fila).prop('class','filaCa');
          $(this).prop('class','filaCa warning');
          //insertando datos al modal
          $("#txtidCa").prop('value',Aux3[filaI3].c_id);
          $("#txtnombreCa").prop('value',Aux3[filaI3].c_nombre);
          $("#txtencargadoCa").prop('value',Aux3[filaI3].p_nombre+' '+Aux3[filaI3].p_ap+' '+Aux3[filaI3].p_am);
          $("#txtts").prop('value',Aux3[filaI3].ts);
          $("#txtcd").prop('value',Aux3[filaI3].cd);
          $("#txtte").prop('value',Aux3[filaI3].te);
          $("#txtcota").prop('value',Aux3[filaI3].cota);
        });
        
        function ajax_caja(idOf){
          $.ajax({
            url:'/Admin/CajasConfigSistema_ajax/',
            data:{'idOfi':idOf},
            type:'GET',
            dataType:'json',
            success: function(data){
              Aux3 = data;
              var html ="";      

              for(var i=0;i<data.length;i++){
                  html += '<tr data-toggle="modal" data-target="#Modalmovi" class="filaCa" id="'+i+'"><td>'+data[i].c_nombre+'</td><td>'+data[i].p_nombre+' '+data[i].p_ap+' '+data[i].p_am+'</td><td>'+data[i].ts+'</td><td>'+data[i].cd+'</td></tr>';
              }                        
              $('#listaCa').html(html);
            },
            error: function(xhr, textStatus, errorThrown) {
              console.log(xhr.responseText);
            }
          });
        };


        function ajax_saldo_oficinas(){
          $.ajax({
            url:'/ver_saldo_oficinas_admin_ajax/',
            type:'GET',
            dataType:'json',
            success: function(data){
              Aux = data;
              var html ="";
              for(var i=0;i<data.length;i++){
                html += '<tr data-toggle="modal" data-target="#myModal" class="filaOf" id="'+i+'" ><th scope="row">'+(i+1)+'</th><td>'+data[i].of+'</td></tr>';
              }                        
              $('#listaR').html(html);
            },
            error: function(xhr, textStatus, errorThrown) {
              console.log(xhr.responseText);
            }
          });
        };

        ajax_saldo_oficinas();
        
        $("#btnRefrescar").click(function(){
          ajax_saldo_oficinas();
        });
      
        $(document).on('show.bs.modal', '.modal', function () {
            var zIndex = 1040 + (10 * $('.modal:visible').length);
            $(this).css('z-index', zIndex);
            setTimeout(function() {
                $('.modal-backdrop').not('.modal-stack').css('z-index', zIndex - 1).addClass('modal-stack');
            }, 0);
        });
        $(document).on('hidden.bs.modal', '.modal', function () {
            $('.modal:visible').length && $(document.body).addClass('modal-open');
        });
      });

    
      
    </script>
{% endblock content1 %}