{% load static %}
<!DOCTYPE html>
<html lang="es">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<head>
  <title> Arqueo de Caja</title>
   <link href="{% static 'bootstrap/css/bootstrap-datetimepicker.css' %}" rel="stylesheet"/>

  <link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet"/> 
  <link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet"/>  

  <script src="{% static 'bootstrap/js/jquery.min.js' %}"></script>
  <script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
  <script src="{% static 'bootstrap/js/Moment.js' %}"></script>
  <script src="{% static 'bootstrap/js/bootstrap-datetimepicker.js' %}"></script>
  <script src="{% static 'js/jspdf.min.js' %}"></script>
  <script src="{% static 'js/jspdf.plugin.autotable.js' %}"></script>
  
  <style type="text/css">
     td.row{
        padding: 2px;
        border-right-width: 1px;
        border-right-color: #4C4B4B;
        border-right-style: solid;
        margin-top: 0px;
        border-bottom-width: 1px;
        border-bottom-style:dashed;
        border-bottom-color: #7A7979;
    }
    
    body{
      font-size: 10px;
    }
    .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
      padding: 4px;
      line-height: 1.42857143;
      vertical-align: top;
      border-top: 1px solid #ddd;
    }
  </style>
   
</head>
<body>
  <div class="row" >
    <div class="" role="alert" align="center" id="ExitoMensaje">
      <h4 id="texto"></h4>
    </div>
  </div>
  <div class="row">
    <div style="margin-left:40px">
      <a class="btn btn-danger btn-sm"  href="/Movimientos_admin_tem/" role="button"><i class="fa fa-mail-reply"></i> Atras</a> 
      <button type="button" class="btn btn-primary btn-sm" id="refresh"><i class="fa fa-refresh"></i> Actualizar</button>
    </div>
  </div>
  <div class="row">
    <div style="margin-left:40px">
      <div class="checkbox" id="campoChk">
        <label class="checkbox-inline" style="font-size: initial;"><input type="checkbox" id="cierrefecha" value="1"> Ver movimientos de otras fechas</label>
        <!--<label>
          <input type="checkbox" id="cierrefecha" value="1"><h5>Ver movimientos de otras fechas</h5>
        </label>-->
      </div>
    </div>
  </div>
<div class="row"  id="campoCierre">
  <div class="col-md-2" id="combob" style="margin-left:40px">
    <select class="form-control" id="comboFiltroF">
      <option value="-1">Seleccione una fecha</option>
      <option value="h">Hoy</option>
      <option value="f">Fecha</option>
      <option value="ef">Entre Fechas</option>
    </select>
    <p></p>
  </div>
  <div class="col-md-2" style="margin-left:40px">
    <input type="text" class="form-control" id="txtfecha1">
    <p></p>
  </div>
  <div class="col-md-2">
    <input type="text" class="form-control" id="txtfecha2">
    <p></p>
  </div>
  <script type="text/javascript">
    $(document).ready(function (){
      $('#txtfecha1').datetimepicker({
        locale: 'es',
        format: 'YYYY-MM-DD'
      });
      $('#txtfecha2').datetimepicker({
        locale: 'es',
        format: 'YYYY-MM-DD'
      });
    });
  </script>
  <div class="col-md-1" >
    <button type="button" class="btn btn-primary btn-sm" id="buscarF">Filtrar</button>
    <p></p>
  </div>
 
</div>
<br>
<div class="main" id="campoI">
  <div class="imp">
      <div style="margin-left:25px">
        <h4> <strong> SISTEMA INTEGRAL </strong> </label></h4>  
      </div>
      
      <div style="margin-left:25px">
        <h4> <strong> TRANSFERENCIAS Y DEPOSITOS </strong></h4>
      </div>

      <div style="margin-left:25px">
        <h5> BASE : <strong> {{ oficina }}</strong></h5>
      </div>
      
      <div style="margin-left:25px">
        <h5> OPERADOR: <strong >{{ operador }}</strong></h5>
      </div>
      <div style="margin-left:25px">
        <h5>DESDE: <strong id="fechad" style="margin-right: 10px;">{{ fd }} </strong>
            HASTA: <strong id="fechah">{{ fh }}</strong></h5>
      </div>
  </div>
  <br>
  <div class="imp" style="text-align:center">
    <h5><strong> MOVIMIENTOS VENTANILLA - CUADRE CAJA</strong></h5>
  </div>
  <!-- MATERIAL VENDIDO -->
  <div class="imp">
    <div >
      <table style="margin: 0 auto">
        <tr>
          <td width="40%">
            <strong>=================================================== TRANSFERENCIAS CREADAS =========================================================</strong>
          </td>
           
          <td width="25%">
            <strong> ====================================== DOLARES ====================================== </strong>
          </td>
        </tr>   
      </table>
    </div>
    <br>
    <div >
      <table  id="TCD" class="table table-bordered table-striped">
      <thead>
        <tr>
          <td width="10%" style="text-align:center">
            <label> OPERACIÓN</label>
          </td>
          <td width="40%" style="text-align:center">
            <label>CONCEPTO DETALLE</label>
          </td>
          <td width="10%">
            <label>FECHA</label>
          </td>
          <td width= "8%">Capital</td>
          <td width= "5%">Comisión</td>
          <td width= "5%">C. Bancos</td>
           <td width="9%">
            <label> INGRESO</label>
          </td>
          <td width="13%">
            <label>OPERADOR</label>
          </td>
        </tr>
       
      </thead>
      <tbody id="listaTCD">
      </tbody>
      <tfoot>
        <tr>
            <td width="10%">
               &nbsp;
            </td>
            <td width="40%">
              &nbsp;
            </td>
            <td width="10%" class="row">
              &nbsp;
            </td>
            <td width="8%" class="row">
              <label id="tcapid"></label>
            </td>
            <td width="5%" class="row">
              <label id="tcomid"></label>
            </td>
             <td width="5%" class="row">
              <label id="tbancod"></label>
            </td>
            <td width="9%">
             &nbsp;
            </td>
            <td width="13%">
              &nbsp;
            </td>
        </tr>
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="10%" style="text-align:right" class="row">
              <label> SUB-TOTAL </label>
            </td>
            <td width="8%" class="row">
              <label> &nbsp;</label>
            </td>
            <td width="5%" class="row">
              <label> &nbsp;</label>
            </td>
            <td width="5%" class="row">
              <label> &nbsp;</label>
            </td>
             <td width="9%" class="row">
              <label id="TTCD">S</label>
            </td>
            <td width="13%" class="row">
              <label> &nbsp;</label>
            </td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>
  <br>
  <br>
  <div class="imp">
    <div >
      <table style="margin: 0 auto">
         <td width="40%">
            <strong>=================================================== TRANSFERENCIAS CREADAS =========================================================</strong>
          </td>
           
          <td width="25%">
            <strong> ====================================== SOLES ====================================== </strong>
          </td>
        <!--<tr>
          <td width="70%">
            <strong>============================== TRANSFERENCIAS CREADAS ================================</strong>
          </td>
          <td width="25%">
            <strong>========== SOLES =========== </strong>
          </td>
        </tr> -->  
      </table>
    </div>
    <br>
    <div >
      <table id="TCS" class="table table-bordered table-striped">
      <thead>
        <tr>
          <td width="10%" style="text-align:center">
            <label> OPERACIÓN</label>
          </td>
          <td width="40%" style="text-align:center">
            <label>CONCEPTO DETALLE</label>
          </td>
          <td width="10%">
            <label>FECHA</label>
          </td>
          <td width= "8%">Capital</td>
          <td width= "5%">Comisión</td>
          <td width= "5%">C. Bancos</td>
           <td width="9%">
            <label> INGRESO</label>
          </td>
          <td width="13%">
            <label> OPERADOR </label>
          </td>
        </tr>
        
      </thead>
      <tbody id="listaTCS">
      </tbody>
      <tfoot>
        <tr>
            <td width="10%">
               &nbsp;
            </td>
            <td width="40%">
              &nbsp;
            </td>
            <td width="10%" class="row">
              &nbsp;
            </td>
            <td width="8%" class="row">
              <label id="tcapis"></label>
            </td>
            <td width="5%" class="row">
              <label id="tcomis"></label>
            </td>
             <td width="5%" class="row">
              <label id="tbancos"></label>
            </td>
            <td width="9%">
             &nbsp;
            </td>
            <td width="13%">
              &nbsp;
            </td>
        </tr>
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="10%" style="text-align:right" class="row">
              <label> SUB-TOTAL:</label>
            </td>
            <td width="8%" class="row">
              <label> &nbsp;</label>
            </td>
            <td width="5%" class="row">
              <label> &nbsp;</label>
            </td>
            <td width="5%" class="row">
              <label> &nbsp;</label>
            </td>
             <td width="9%" class="row">
              <label id="TTCS">S</label>
            </td>
            <td width="13%" class="row">
              <label> &nbsp;</label>
            </td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>
  <!-- END -->
  <!-- TRANSFERENCIAS PAGADAS -->
  <br>
  <div class="imp">
    <div >
      <table style="margin: 0 auto">
         <td width="48%">
            <strong>========================================================= TRANSFERENCIAS PAGADAS ===============================================================</strong>
          </td>
           
          <td width="25%">
            <strong> ================================ DOLARES ================================== </strong>
          </td>
        <!--<tr>
          <td width="70%">
            <strong>========================== TRANSFERENCIAS PAGADAS ================================</strong>
          </td>
           
          <td width="25%">
            <strong> ========= DOLARES ========= </strong>
          </td>
        </tr>-->   
      </table>
    </div>
    <br>
    <div >
      <table id="TPD" class="table table-bordered table-striped">
      <thead>
        <tr>
          <td width="10%" style="text-align:center">
            <label> OPERACIÓN</label>
          </td>
          <td width="40%" style="text-align:center">
            <label>CONCEPTO DETALLE</label>
          </td>
          <td width= "5%">ST</td>
          <td width="10%">
            <label>FECHA</label>
          </td>
          <td width="9%">
            <label> MONTO</label>
          </td>
          <td width="9%">
            <label> EGRESO EXTRA</label>
          </td>
          <td width="9%">
            <label>N° R/E egreso extra</label>
          </td>
          <td width="13%">
            <label> OPERADOR </label>
          </td>
        </tr>
       
      </thead>
      <tbody id="listaTPD">
      </tbody>
      <tfoot>
        <tr>
            <td width="10%">
               &nbsp;
            </td>
            <td width="40%">
              &nbsp;
            </td>
            <td width="5%">
              &nbsp;
            </td>
            <td width="10%" class="row">
              &nbsp;
            </td>
            <td width="8%" class="row">
              <label id="tcapid"></label>
            </td>
             <td width="5%" class="row">
              <label id="tbancod"></label>
            </td>
            <td width="9%">
             &nbsp;
            </td>
            <td width="13%">
              &nbsp;
            </td>
        </tr>
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="5%"></td>
            <td width="10%" style="text-align:right" class="row">
              <label> SUB-TOTAL:</label>
            </td>
            <td width="5%" class="row">
              <label> &nbsp;</label>
            </td>
             <td width="9%" class="row">
              <label id="TTPD"></label>
            </td>
            <td width="13%" class="row">
              <label> &nbsp;</label>
            </td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>
  <br>
  <br>
  <div class="imp">
    <div >
      <table style="margin: 0 auto">
         <td width="48%">
            <strong>========================================================= TRANSFERENCIAS PAGADAS =============================================================</strong>
          </td>
           
          <td width="25%">
            <strong> ================================= SOLES ================================= </strong>
          </td>
        <!--<tr>
          <td width="70%">
            <strong>============================== TRANSFERENCIAS PAGADAS ================================</strong>
          </td>
          <td width="25%">
            <strong>========== SOLES =========== </strong>
          </td>
        </tr>-->   
      </table>
    </div>
    <br>
    <div >
      <table id="TPS" class="table table-bordered table-striped">
      <thead>
        <tr>
          <td width="10%" style="text-align:center">
            <label> OPERACIÓN</label>
          </td>
          <td width="40%" style="text-align:center">
            <label>CONCEPTO DETALLE</label>
          </td>
          <td width= "5%">ST</td>
          <td width="10%">
            <label>FECHA</label>
          </td>
          <td width="9%">
            <label> MONTO</label>
          </td>
          <td width="9%">
            <label> EGRESO EXTRA</label>
          </td>
          <td width="9%">
            <label>N° R/E egreso extra</label>
          </td>
          <td width="13%">
            <label> OPERADOR </label>
          </td>
        </tr>
       
      </thead>
      <tbody id="listaTPS">
      </tbody>
      <tfoot>
        <tr>
            <td width="10%">
               &nbsp;
            </td>
            <td width="40%">
              &nbsp;
            </td>
            <td width="5%">
              &nbsp;
            </td>
            <td width="10%" class="row">
              &nbsp;
            </td>
            <td width="5%" class="row">
              &nbsp;
            </td>
             <td width="5%" class="row">
              <label id="tbancos"></label>
            </td>
            <td width="8%">
             &nbsp;
            </td>
            <td width="13%">
              &nbsp;
            </td>
        </tr>
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="5%"></td>
            <td width="10%" style="text-align:right" class="row">
              <label> SUB-TOTAL:</label>
            </td>
             <td width="9%" class="row">
              <label id="TTPS">S</label>
            </td>
            <td width="13%" class="row">
              <label> &nbsp;</label>
            </td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>
  <!-- END -->

  <br>
  <div class="imp">
    <div >
      <table style="margin: 0 auto">
        <tr>
          <td width="48%">
            <strong>==================================================== EXTRACTO DE LOS MOVIMIENTOS ==========================================================</strong>
          </td>
           
          <td width="25%">
            <strong> ================================== DOLARES ================================= </strong>
          </td> 
        </tr>   
      </table>
    </div>
    <br>
    <div >
      <table id="IED" class="table table-bordered table-striped">
      <thead>
        <tr>
          <td width="10%" style="text-align:center">
            <label> OPERACIÓN</label>
          </td>
          <td width="40%" style="text-align:center">
            <label>CONCEPTO DETALLE</label>
          </td>
          <td width="10%">
            <label>FECHA</label>
          </td>
           <td width="9%">
            <label> INGRESO</label>
          </td>
          <td width="8%">
            <label> EGRESO</label>
          </td>
          <td width="13%">
            <label> OPERADOR </label>
          </td>
        </tr>
       
        <tr>
          <td width="10%"></td>
          <td width="40%"> <LABEL> SALDO ANTERIOR</LABEL> </td>
          <td>&nbsp;</td>
          <td id="sid"></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="10%"></td>
          <td width="40%"> <LABEL> TRANSFERENCIAS CREADAS</LABEL> </td>
          <td>&nbsp;</td>
          <td id="tcd"></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="10%"></td>
          <td width="40%"> <LABEL> TRANSFERENCIAS PAGADAS</LABEL> </td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td id="tpd"></td>
          <td>&nbsp;</td>
        </tr>
      </thead>
      <tbody id="listaIED">
      </tbody>
      <tfoot>
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="10%" style="text-align:right" class="row">
              <label> SUB-TOTAL:</label>
            </td>
             <td width="9%" class="row">
              <label id="ID">S</label>
            </td>
            <td width="8%" class="row">
              <label id="ED"></label>
            </td>
            <td width="13%"></td>
        </tr>
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="10%" style="text-align:right">
            </td>
             <td width="9%" class="row" style="text-align:right">
              <label> SALDO TOTAL: </label>
            </td>
            <td width="8%" class="row">
              <label id="SD"></label>
            </td>
            <td width="13%"></td>
        </tr>
      </tfoot>
      </table>
    </div>
  </div>
  <br>
  <br>
  <br>
  <div class="imp">
    <div >
      <table class="table">
        <tr>
          <td width="48%">
            <strong>====================================================== EXTRACTO DE LOS MOVIMIENTOS ===========================================================</strong>
          </td>
           
          <td width="25%">
            <strong> ================================= SOLES ================================= </strong>
          </td> 
        </tr>
        <!--<tr>
          <td width="70%">
            <strong>============================== EXTRACTO DE LOS MOVIMIENTOS ================================</strong>
          </td>
          <td width="25%">
            <strong>========== SOLES =========== </strong>
          </td>
        </tr>-->   
      </table>
    </div>
    <br>
    <div >
      <table id="IES" class="table table-bordered table-striped">
      <thead>
        <tr>
          <td width="10%" style="text-align:center">
            <label> OPERACIÓN</label>
          </td>
          <td width="40%" style="text-align:center">
            <label>CONCEPTO DETALLE</label>
          </td>
          <td width="10%">
            <label>FECHA</label>
          </td>
           <td width="9%">
            <label> INGRESO</label>
          </td>
          <td width="8%">
            <label> EGRESO</label>
          </td>
          <td width="8%">
            <label> OPERADOR</label>
          </td>
        </tr>
       
        <tr>
          <td width="10%"></td>
          <td width="40%"> <LABEL> SALDO ANTERIOR</LABEL> </td>
          <td>&nbsp;</td>
          <td id="sis"></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="10%"></td>
          <td width="40%"> <LABEL> TRANSFERENCIAS CREADAS</LABEL> </td>
          <td>&nbsp;</td>
          <td id="tcs"></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="10%"></td>
          <td width="40%"> <LABEL> TRANSFERENCIAS PAGADAS</LABEL> </td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td id="tps"></td>
          <td>&nbsp;</td>
        </tr>
         
      </thead>
      <tbody id="listaIES">
      </tbody>
      <tfoot>
       <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="10%" style="text-align:right" class="row">
              <label> SUB-TOTAL:</label>
            </td>
             <td width="9%" class="row">
              <label id="IS">S</label>
            </td>
            <td width="8%" class="row">
              <label id="ES"></label>
            </td>
            <td width="13%"></td>
        </tr>
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="10%" style="text-align:right">
            </td>
             <td width="9%" class="row" style="text-align:right">
              <label> SALDO TOTAL: </label>
            </td>
            <td width="8%" class="row">
              <label id="SS"></label>
            </td>
            <td width="13%"></td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>
  <div >
      <div align="center">
          <button type="button" class="btn btn-inverse bc" id="CerrarC"><i class="fa fa-print"></i> Imprimir</button>
      </div>
      <br>
  </div>
</div>
<br>
</body>
<script type="text/javascript">
  var bi=false,be=false;
  var pkCa ={{ pkc }};
  var listaSI="",listaSE="";
  var listaDI="",listaDE="";
  var urlbtt="{% static 'img/btt.png' %}";
  $(document).ready(function(){
    var fecha = new Date();
    var mes = ["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];
    var textofecha= fecha.getDate() + " de " + mes[fecha.getMonth()] + " del " + fecha.getFullYear();
    var hora = new Date();
    var textohora = hora.getHours() + ":" + hora.getMinutes();
    var aux='';
    //ajax_validar();
    $("#txtfecha1").hide();
    $("#txtfecha2").hide();
    $("#comboFiltroF").change(function(){
      if($("#comboFiltroF").val()=="ef"){
        $("#txtfecha1").show();
        $("#txtfecha1").prop("value","");
        $("#txtfecha2").show();
        $("#txtfecha2").prop("value","");
        }
      if($("#comboFiltroF").val()=="f"){
        $("#txtfecha1").prop("value","");
        $("#txtfecha1").show();
        $("#txtfecha2").hide();
        }
      if($("#comboFiltroF").val()=="h"){
        $("#txtfecha1").prop("value","");
        $("#txtfecha1").hide();
        $("#txtfecha2").prop("value","");
        $("#txtfecha2").hide();
        }
    });
    

    function imprimir(){
      var stilo="<style>body{font-size: 10px;}</style>"
      var ori = $("body").html();
      var areai= $("#campoI").html();
      $("body").html(stilo+areai);
      window.print();
      $("body").html(ori);
    }
    $("#cierrefecha").click(function(){
      if($("#cierrefecha").prop('checked')){
        $("#campoCierre").show();
        //$("#imprime").hide();
      }
      else{
        $("#campoCierre").hide();
      }
    });
    $("#campoCierre").hide();
    //
    $("#buscarF").click(function(){
      $("#listaIES").html(" ");
      $("#listaIED").html(" ");
      if ($("#comboFiltroF").val()=='h'){
         Date.prototype.yyyymmdd = function() {
            var yyyy = this.getFullYear().toString();
            var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
            var dd  = this.getDate().toString();
            return yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]); // padding
          };

          d = new Date();
        $("#fechad").text(d.yyyymmdd());
      }
      else{
        //var t=$('#txtfecha1').val() +"  al  "+$('#txtfecha2').val();
        $("#fechad").text($('#txtfecha1').val());
        $("#fechah").text($('#txtfecha2').val());
      }
      ajax_validar();
    });
    $("#refresh").click(function(){
      $("#listaMC").html(" ");
      $("#listaMV").html(" ");
      $("#listaIES").html(" ");
      $("#listaIED").html(" ");
      ajax_validar();
    })
    //
    //

    //



    function ajax_transCreadas(){
          $.ajax({
            data:{'filtro':$('#comboFiltroF').val() ,'F1':$('#fechad').text(),'F2':$('#fechah').text(),'pkC':pkCa},
            url:'/consulta_tras_creadas_caja_report_ajax/',
            type:'GET',
            dataType:'json',
            success: function(data){
              var html1 ="";
              var html2 ="";
              bi=false;
              for(var i=0;i<data.length-1;i++){
                if (data[i].moneda =="soles"){
                  html1 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+'<img src="'+urlbtt+'" width="8%" height="5%" style="margin-left:8px;margin-right:1px"></label></td><td width="40%" class="row"><label>'+data[i].concepto+'</label></td><td width="10%" class="row"><label>'+data[i].fecha+'</label></td><td width="8%" class="row"><label>'+data[i].capi+'</label></td><td width="5%" class="row"><label>'+data[i].comision+'</label></td><td width="5%" class="row"><label>'+data[i].comi_banco+'</label></td><td width="9%" class="row"><label>'+data[i].monto+'</label></td><td width="13%" class="row"><label>&nbsp;</label></td></tr>';
                }
                else{
                  html2 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+'<img src="'+urlbtt+'" width="8%" height="5%" style="margin-left:8px;margin-right:1px"></label></td><td width="40%" class="row"><label>'+data[i].concepto+'</label></td><td width="10%" class="row"><label>'+data[i].fecha+'</label></td><td width="8%" class="row"><label>'+data[i].capi+'</label></td><td width="5%" class="row"><label>'+data[i].comision+'</label></td><td width="5%" class="row"><label>'+data[i].comi_banco+'</label></td><td width="9%" class="row"><label>'+data[i].monto+'</label></td><td width="13%" class="row"><label>&nbsp;</label></td></tr>';
                }
              }
              $("#listaTCS").html(html1);
              $("#listaTCD").html(html2);
              $("#TTCS").text(data[data.length-1].total_soles);
              $("#TTCD").text(data[data.length-1].total_dolares);
              $("#tcapis").text(data[data.length-1].tcapis);
              $("#tcapid").text(data[data.length-1].tcapid);
              $("#tbancos").text(data[data.length-1].tbancos);
              $("#tbancod").text(data[data.length-1].tbancod);
              $("#tcomis").text(data[data.length-1].util_soles);
              $("#tcomid").text(data[data.length-1].util_dolares);
            },
             error: function(xhr, textStatus, errorThrown) {      
                console.log(xhr.responseText);
              },
          });
        };
        ///
         
        function ajax_transPagdas(){
          $.ajax({
            data:{'filtro':$('#comboFiltroF').val(),'F1':$('#fechad').text(),'F2':$('#fechah').text(),'pkC':pkCa},
            url:'/consulta_tras_pagadas_caja_report_ajax/',
            type:'GET',
            dataType:'json',
            success: function(data){
              var html1 ="";
              var html2 ="";
              be=false;
              for(var i=0;i<data.length-1;i++){
                if (data[i].moneda =="soles"){
                  html1 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+' <img src="'+urlbtt+'" width="8%" height="5%" style="margin-left:8px;margin-right:1px"></label></td><td width="40%" class="row"><label>'+data[i].concepto+'</label></td><td width="5%" class="row"><label>'+data[i].st +'</label></td><td width="10%" class="row"><label>'+data[i].fecha+'</label></td><td width="9%" class="row"><label>'+data[i].monto+'</label></td><td width="9%" class="row"><label>'+data[i].egreso+'</label></td><td width="9%" class="row"><label>'+data[i].egreso_re+'</label></td><td width="13%" class="row"><label>&nbsp;</label></td></tr>';
                }
                else{
                  html2 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+' <img src="'+urlbtt+'" width="8%" height="5%" style="margin-left:8px;margin-right:1px"></label></td><td width="40%" class="row"><label>'+data[i].concepto+'</label></td><td width="5%" class="row"><label>'+data[i].st +'</label></td><td width="10%" class="row"><label>'+data[i].fecha+'</label></td><td width="9%" class="row"><label>'+data[i].monto+'</label></td><td width="9%" class="row"><label>'+data[i].egreso+'</label></td><td width="9%" class="row"><label>'+data[i].egreso_re+'</label></td><td width="13%" class="row"><label>&nbsp;</label></td></tr>';
                }
              }
              $("#TTPS").text(data[data.length-1].total_soles);
              $("#TTPD").text(data[data.length-1].total_dolares);
              $("#tcomispt").text(data[data.length-1].util_soles);
              $("#listaTPS").html(html1);
              $("#listaTPD").html(html2);
            },
             error: function(xhr, textStatus, errorThrown) {      
                console.log(xhr.responseText);
              },
          });
        };
    //
    function ajax_Extracto(){
          $.ajax({
            data:{'filtro':$('#comboFiltroF').val() ,'F1':$('#fechad').text(),'F2':$('#fechah').text(),'pkC':pkCa},
            url:'/consulta_extraxt_caja_report_ajax/',
            type:'GET',
            dataType:'json',
            success: function(data){
              var html1 ="";
              var html2 ="";
              bi=false;
              for(var i=0;i<data.length-1;i++){
                if (data[i].moneda =="soles"){
                  html1 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+'<img src="'+urlbtt+'" width="8%" height="5%" style="margin-left:8px;margin-right:1px"></label></td><td width="40%" class="row"><label>'+data[i].concepto+'</label></td><td width="10%" class="row"><label>'+data[i].fecha+'</label></td><td width="9%" class="row"><label>'+data[i].montoi+'</label></td><td width="8%" class="row"><label>'+data[i].montoe+'</label></td><td width="13%" class="row"><label>&nbsp;</label></td></tr>';
                }
                else{
                  html2 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+'<img src="'+urlbtt+'" width="8%" height="5%" style="margin-left:8px;margin-right:1px"></label></td><td width="40%" class="row"><label>'+data[i].concepto+'</label></td><<td width="10%" class="row"><label>'+data[i].fecha+'</label></td><td width="9%" class="row"><label>'+data[i].montoi+'</label></td><td width="8%" class="row"><label>'+data[i].montoe+'</label></td><td width="13%" class="row"><label>&nbsp;</label></td></tr>';
                }
              }
              $("#listaIES").html(html1);
              $("#listaIED").html(html2);
              $("#IS").text(data[data.length-1].totali_soles);
              $("#ID").text(data[data.length-1].totali_dolares);
              $("#ES").text(data[data.length-1].totale_soles);
              $("#ED").text(data[data.length-1].totale_dolares);
              $("#tcs").text(data[data.length-1].tc_soles);
              $("#tcd").text(data[data.length-1].tc_dolares);
              $("#tps").text(data[data.length-1].tp_soles);
              $("#tpd").text(data[data.length-1].tp_dolares);
            },
             error: function(xhr, textStatus, errorThrown) {      
                console.log(xhr.responseText);
              },
          });
        };
        ///
       
        //
    function ajax_saldo_inicial(){
          $.ajax({
            url:'/SaldoInicialCaja_ajax/',
            //async:false,
            type:'GET',
            dataType:'json',
            success: function(data){
             $('#sis').text(data[0].sis);
             $("#sid").text(data[0].sid);
             $("#sim").text(data[0].sim);
             calcular_Saldo();
            },
             error: function(xhr, textStatus, errorThrown) {      
                console.log(xhr.responseText);
              },
          });
        };
    $("#CerrarC").click(function(){

          var doc = new jsPDF('p', 'pt');

          var res = doc.autoTableHtmlToJson(document.getElementById("TCD"));
          var res1= doc.autoTableHtmlToJson(document.getElementById("TCS"));
          var res2= doc.autoTableHtmlToJson(document.getElementById("TPD"));
          var res3= doc.autoTableHtmlToJson(document.getElementById("TPS"));
          var res4= doc.autoTableHtmlToJson(document.getElementById("IED"));
          var res5= doc.autoTableHtmlToJson(document.getElementById("IES"));

          var base='{{ oficina }}';
          var operador='{{ operador }}'

          doc.setFontSize(10);
          doc.setFontStyle('bold');
          doc.text("SISTEMA INTEGRAL - TRANSFERENCIAS Y DEPOSITOS", 10, 20);
          doc.setFontSize(8);
          doc.setFontStyle('normal');
          doc.text("BASE : " + base, 10, doc.autoTableEndPosY()+35);
          doc.text("OPERADOR: "+ operador, 10, doc.autoTableEndPosY()+50);
          doc.text("FECHA DESDE : "+$("#fechad").text(), 10, doc.autoTableEndPosY()+65);
          doc.text("FECHA HASTA : "+$("#fechah").text(), 140, doc.autoTableEndPosY()+65);
          

          doc.setFontSize(8);
          doc.setFontStyle('bold');

           doc.text("TRANSFERENCIAS CREADAS DOLARES", 10, doc.autoTableEndPosY()+20);

          doc.autoTable(res.columns, res.data, {
              startY: doc.autoTableEndPosY()+30,
              margin: {horizontal: 10},
              headerStyles: {rowHeight: 12, fontSize: 7,valign: 'middle'},
              styles: {overflow: 'linebreak'},
              bodyStyles: {rowHeight: 12, fontSize: 8, valign: 'middle'}, 
              theme: 'grid',
              pageBreak: 'avoid',
          });


          doc.text("TRANSFERENCIAS CREADAS SOLES", 10, doc.autoTableEndPosY()+20);  
           
          doc.autoTable(res1.columns, res1.data, {
              startY: doc.autoTableEndPosY()+30,
              margin: {horizontal: 10},
              headerStyles: {rowHeight: 12, fontSize: 7,valign: 'middle'},
              styles: {overflow: 'linebreak'},
              bodyStyles: {rowHeight: 12, fontSize: 8, valign: 'middle'}, 
              theme: 'grid',
              pageBreak: 'avoid',
          });

          doc.text("TRANSFERENCIAS PAGADAS DOLARES", 10, doc.autoTableEndPosY()+20);   

           doc.autoTable(res2.columns, res2.data, {
              startY: doc.autoTableEndPosY()+30,
              margin: {horizontal: 10},
               headerStyles: {rowHeight: 12, fontSize: 7,valign: 'middle'},
              styles: {overflow: 'linebreak'},
              bodyStyles: {rowHeight: 12, fontSize: 8, valign: 'middle'}, 
              theme: 'grid',
              pageBreak: 'avoid',
          });

           doc.text("TRANSFERENCIAS PAGADAS SOLES", 10, doc.autoTableEndPosY()+20);

            doc.autoTable(res3.columns, res3.data, {
              startY: doc.autoTableEndPosY()+30,
              margin: {horizontal: 10},
               headerStyles: {rowHeight: 12, fontSize: 7,valign: 'middle'},
              styles: {overflow: 'linebreak'},
              bodyStyles: {rowHeight: 12, fontSize: 8, valign: 'middle'}, 
              theme: 'grid',
              pageBreak: 'avoid',
          });   


           doc.text("EXTRACTO DE MOVIMIENTOS DOLARES", 10, doc.autoTableEndPosY()+20);

            doc.autoTable(res4.columns, res4.data, {
              startY: doc.autoTableEndPosY()+30,
              margin: {horizontal: 10},
               headerStyles: {rowHeight: 12, fontSize: 7,valign: 'middle'},
              styles: {overflow: 'linebreak'},
              bodyStyles: {rowHeight: 12, fontSize: 7, valign: 'middle'}, 
              theme: 'grid',
              pageBreak: 'avoid',
          });   


           doc.text("EXTRACTO DE MOVIMIENTOS SOLES", 10, doc.autoTableEndPosY()+20);

            doc.autoTable(res5.columns, res5.data, {
              startY: doc.autoTableEndPosY()+30,
              margin: {horizontal: 10},
               headerStyles: {rowHeight: 12, fontSize: 7,valign: 'middle'},
              styles: {overflow: 'linebreak'},
              bodyStyles: {rowHeight: 12, fontSize: 8, valign: 'middle'}, 
              theme: 'grid',
              pageBreak: 'avoid',
          });         

          doc.save('reporteMovimientosCaja.pdf');
      //imprimir();
    });
     function ajax_validar(){//falta
      ajax_transCreadas();
      ajax_transPagdas();
      ajax_Extracto();
    };
    //
    //
    function calcular_Saldo()
    {
      //alert($("#IS").html());
      var saldosoles= parseFloat($("#IS").text())-parseFloat($("#ES").text());
      var saldodolares= parseFloat($("#ID").text())-parseFloat($("#ED").text());
      
      $("#SS").text(saldosoles.toString());
      $("#SD").text(saldodolares.toString());
     
    }
    //
  });
</script>
<script src="{% static 'Bootstrap/js/Moment.js' %}"></script>
<script src="{% static 'Bootstrap/js/bootstrap.min.js' %}"></script>
<script src="{% static 'Bootstrap/js/bootstrap-datetimepicker.js' %}"></script>
<script src="{% static 'js/jspdf.min.js' %}"></script>
<script src="{% static 'js/jspdf.plugin.autotable.js' %}"></script>
</html>
 
