{% extends "baseAdmin.html" %}
{% load static %}
{% block titulo %}
  .::Configuración Nro Recibos
{% endblock titulo %}
{% block content1 %}
    <div class="container">
      <script type="text/javascript">
        $("#navOficinas").attr('class','dropdown active');
        $("#navConfigNroRecibo").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>

    <div id="modalOficinaCentral" 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">Opciones</h4>
            </div>
            <div class="modal-body">
              <div class="row">
                <div class="col-md-4 col-md-offset-1" align="right"> 
                   <label>Oficina Central:</label> 
                </div>
                <div class="col-md-5">  
                 <div class="fg-line">
                  <div class="select">
                  <select class="form-control" id="ComboOficina">    
                  </select>
                  </div>
                  </div>
                </div>
              </div>
              <p></p>
              <div class="row">
                <div class="col-md-4 col-md-offset-4 col-xs-4 col-xs-offset-4">
                  <button type="button" class="btn btn-warning btn-block" id="cambiarOfi">Guardar</button>
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <div class="row">
                <div class="col-md-2 col-md-offset-10">
                   <button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
                </div>
              </div>
            </div>

          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

     <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;-->
                                Detalles 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>Nro RE</th>
                                        <th>Nro RI</th>
                                        <th>Nro ST</th>
                                        <th>Nro PT</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/configurarnrorecibo/" 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" name="pkO" id="txtpkO" 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 Nro de Recibos
                                </h4>
                              </div>
                            </div>
                            
                            <p></p>
                             
                            <div class="row">
                              <div class="col-md-3 col-md-offset-2" >
                                <label>Número RE: </label>
                              </div>
                              <div class="col-md-3">
                               <div class="fg-line"> 
                                <input type="text" class="form-control"  name ="re" id="txtre"  required>
                                </div>
                                <p></p>
                              </div>
                            </div>
                             <p></p>
                             
                            <div class="row">
                              <div class="col-md-3 col-md-offset-2" >
                                <label>Número RI: </label>
                              </div>
                              <div class="col-md-3">
                               <div class="fg-line"> 
                                <input type="text" class="form-control"  name ="ri" id="txtri"  required>
                                </div>
                                <p></p>
                              </div>
                            </div>
                             <p></p>
                             
                            
                            <div class="row">
                              <div class="col-md-3 col-md-offset-2" >
                                <label>Número ST: </label>
                              </div>
                              <div class="col-md-3">
                               <div class="fg-line"> 
                                <input type="text" class="form-control"  name ="st" id="txtst"  required>
                                </div>
                                <p></p>
                              </div>
                            </div>
                             <p></p>
                             
                            <div class="row">
                              <div class="col-md-3 col-md-offset-2" >
                                <label>Número PT: </label>
                              </div>
                              <div class="col-md-3">
                               <div class="fg-line"> 
                                <input type="text" class="form-control"  name ="pt" id="txtpt"  required>
                                </div>
                                <p></p>
                              </div>
                            </div>
                            <p></p>
                             <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="button">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=[];

      $("#btnActualizar").click(function(){
          $("#formConfiguracion").submit();
      });

      //function submitForm(){
        //console.log("data");
        //$("#formConfiguracion").submit();
      //}

      $(document).ready(function (){
        $("#txtre").numeric();
        $("#txtri").numeric();
        $("#txtst").numeric();
        $("#txtpt").numeric();
        //--------------- transferencias globales

         $("#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);
          $("#txtpkO").prop('value',Aux[filaI2].pk);
          $("#txtof").text(Aux[filaI2].of);
        });

        $("#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);
          $("#txtpkC").prop('value',Aux3[filaI3].c_id);
          $("#txtre").prop('value',Aux3[filaI3].re);
          $("#txtri").prop('value',Aux3[filaI3].ri);
          $("#txtst").prop('value',Aux3[filaI3].st);
          $("#txtpt").prop('value',Aux3[filaI3].pt);
          
          
          $("#txtnombreCa").prop('value',Aux3[filaI3].c_nombre);
          $("#txtencargadoCa").prop('value',Aux3[filaI3].p_nombre+' '+Aux3[filaI3].p_ap+' '+Aux3[filaI3].p_am); 
        });
        
        function ajax_caja(idOf){

           $.ajax({
                url:'/NeroRecibosCajas/',
                data:{'idOfi':idOf},
                type:'GET',
                dataType:'json',
                success: function(data){
                  Aux3 = data;
                  var html ="";
                  var esta='';
                  var sty ='';       

                  for(var i=0;i<data.length;i++){
                      html += '<tr data-toggle="modal" data-target="#Modalmovi" class="filaCa" '+sty+' 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].re+'</td><td>'+data[i].ri+'</td><td>'+data[i].st+'</td><td>'+data[i].pt+'</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;
              console.log(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);
                },
          });
        };
        

       
        
        $("#listaCa").on("click",".filaCa",function(){
          $("#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);
          $("#txtidCa2").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);
        });
       
       
        
        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 %}