{% extends "baseAdmin.html" %}
{% load static %}
{% block titulo %}
  .::Movimiento de Oficinas
{% endblock titulo %}
{% block content1 %}
    <div class="container">
      <script type="text/javascript">
        $("#navMovimientos").attr('class','dropdown active');
        $("#navAdminMovimientos").attr('class','active');
      </script>
        <div class="row">
          <div class="col-md-12 col-sm-12" >
              <div class="panel panel-default">
                <div class="panel panel-heading"> <strong>OFICINAS</strong></div>
                <div class="panel-body">
                  <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="col-md-10 col-md-offset-1">
                        <div class="table-responsive">
                          <table class="table table-bordered">
                              <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="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">
                            <form action="/MovimientosOficina_admin_tem/" method="POST" id="arqueo_oficina">{% csrf_token %}
                              <div class="col-md-2" align="right">
                                <h5>Oficina: </h5>
                              </div>
                              
                              <div class="col-md-2">
                                <h5><label id="tituloO"></label></h5>
                              </div>
                              <div class="col-md-4 col-md-offset-2">
                                 <button type="button" class="btn btn-danger btn-block" id="arqueoOfi">Movimientos ST/PT de Oficina</button>
                              </div>
                              <div class="col-md-2">
                                <input type="text" class="form-control" name="pkO" id="txtidOfi" readonly="readonly">
                                <p></p>
                              </div>
                            </form>
                          </div>
                          <div class="row">
                            <div class="col-md-12">
                              <h4 class="bg-success" align="center">
                                <!--&nbsp;-->
                                Consulta Cajas
                              </h4>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-md-12">
                              <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                      <tr>
                                        <th>Nombre</th>
                                        <th>Operador</th>
                                        <th>Estado</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">
                            <div class="row">
                              <div class="col-md-12">
                                <h4 class="bg-success" align="center">
                                  <!--&nbsp;-->
                                  Consulta de Movimientos
                                </h4>
                              </div>
                            </div>
                            <div class="row">
                              <div class="col-md-2" align="right">
                                <h5>Caja: </h5>
                              </div>
                              <div class="col-md-5">
                                <input type="text" class="form-control" id="txtnombreCa" disabled="disabled">
                                <p></p>
                              </div>
                              <div class="col-md-2" align="right">
                                <h5>Id: </h5>
                              </div>
                              <div class="col-md-3">
                                <input type="text" class="form-control" name="pkC" id="txtidCa" readonly="readonly">
                                <p></p>
                              </div>
                            </div>
                            <div class="row">
                              <div class="col-md-2" align="right">
                                <h5>Encargado: </h5>
                              </div>
                              <div class="col-md-10">
                                <input type="text" class="form-control" id="txtencargadoCa" disabled="disabled">
                                <p></p>
                              </div>
                            </div>
                            <div class="row">
                               <form action="/ArqueCaja_admin_tem/" method="POST" id="arqueoCaja">{% csrf_token %}
                                <div class="row">
                                  <input type="text" class="form-control hidden" name="pkC1" id="txtidCa2"> 
                                  <div class="col-md-6">
                                    <button type="submit" class="btn btn-primary btn-block" id="arqueoCa">Ver Movimientos</button>
                                  </div>
                                  <div class="col-md-6">
                                    <button type="button" class="btn btn-success btn-block" id="arqueoCaDolar">Ver Movimientos Dolares</button>
                                  </div>
                                </div>
                               </form>
                              <!--<div class="col-md-6 col-md-offset-3">
                                <button type="button" class="btn btn-success btn-block" id="movHoy">Ver Movimientos</button>
                              </div>-->
                            </div>
                            <p></p>
                            <div class="row" id="grupo_f">
                              <div class="col-md-2" align="right">
                                <h5>Fecha: </h5>
                              </div>
                              <div class="col-md-4">
                                <input type="text" class="form-control" id="txtfecha" name ="mf">
                                <p></p>
                              </div>
                              <div class="col-md-3">
                                <button type="button" class="btn btn-primary btn-block" id="mov_fe">Buscar</button>
                              </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>
     <script type="text/javascript">
      Aux=[];
      Aux3=[];
      $(document).ready(function (){
        $('#txtfecha').datetimepicker({
          locale: 'es',
          format: 'YYYY-MM-DD'
        });
        $("#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 info');
          ajax_caja(Aux[filaI2].pk);
          //insertando datos en el modal
          $("#txtidOfi").prop('value',Aux[filaI2].pk);
          $("#tituloO").text(Aux[filaI2].of);
        });
        $("#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 info');
          //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);
        });
        $("#movF").click(function(){
           $("#grupo_f").show();
        });
        $("#movHoy").click(function(){
          $("#form_mov").submit();
        });
        $("#mov_fe").click(function(){
          $("#form_mov").submit();
        });
        $("#arqueoOfi").click(function(){
          $("#arqueo_oficina").submit();
        });
        
        function ajax_caja(idOf){
          $.ajax({
            url:'/Admin/caja_personal_saldo_ajax/',
            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++){
                if (data[i].c_estado){
                  esta='activo';
                  sty='';
                }
                else{
                  esta='desactivo';
                  sty='style="color: #CB060A;"'
                }
                if(data[i].p_est){
                  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>'+esta+'</td></tr>';
                 
                }
                else{
                   html += '<tr data-toggle="modal" data-target="#Modalmovi" class="filaCa" '+sty+' id="'+i+'"><td>'+data[i].c_nombre+'</td><td><s><b>'+data[i].p_nombre+' '+data[i].p_ap+' '+data[i].p_am+'</b></s></td><td>'+esta+'</td></tr>';
                }
                  
              }                        
              $('#listaCa').html(html);
            }
          });
        };//end funcion ajax
        ajax_saldo_oficinas();
        $("#btnRefrescar").click(function(){
          ajax_saldo_oficinas();
        });
        function ajax_saldo_oficinas(){
          $.ajax({
            url:'/ver_saldo_oficinas_admin_ajax/',
            type:'GET',
            dataType:'json',
            success: function(data){
              Aux = data;
              var html ="" ,html1="",id_oficinaCentral="";
              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);
            }
          });
        };
        $("#arqueoCaDolar").click(function(e){
          e.preventDefault();
          $("#arqueoCaja").prop('action','/ArqueCaja_dolares_admin_tem/');
          $("#arqueoCaja").submit();
        })
        $(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 %}