{% extends "base.html" %}
{% load static %}
{% block titulo %}
  Listado de Cierres
{% endblock titulo %}
{% block content1 %}
<script type="text/javascript">
  $("#navIE").attr('class','dropdown active');
  $("#navHistorialCierre").attr('class','active');
</script>
<div class="row">
  <div class="col-md-12 col-sm-12" >
      <div class="panel panel-default">
        <div class="panel-heading panel-toolbar"> 
          <strong>LISTADO DE CIERRES</strong>
          <button type="button" class="btn btn-default btn-sm" id="btnRefrescar"><span class="fa fa-refresh"></span> <b>Actualizar</b></button>
        </div>
        <div class="panel-body">
          <div class="row">
              <div class="col-md-12">
                  <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                          <tr>
                            <th>Cierre de</th>
                            <th>Inicial S/</th>
                            <th>Ingreso S/</th>
                            <th>Egreso S/</th>
                            <th>Saldo S/</th>
                            <th>Inicial $</th>
                            <th>Ingreso $</th>
                            <th>Egreso $</th>
                            <th>Saldo $</th>
                            <th>Observaciones</th>
                            <th>Momento del cierre</th>
                          </tr>
                        </thead>
                        <tbody id="listaC">
                            
                        </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-xl">
      <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>
          <h5 class="modal-title" id="myModalLabel">Detalles de Cliente</h5>
        </div>
        <div class="modal-body">
          <div class="row">
            <div class="col-md-12" id="body-cierre">
              <div class="panel panel-default">
                <div class="panel-heading panel-toolbar">
                  <strong>Cierre de caja</strong>
                  <div>
                    <button type="button" class="btn btn-default" id="refresh-movimiento"><i class="fa fa-refresh"></i> Actualizar</button>
                    <button type="button" class="btn btn-default btn-sm item-toolbar" id="btn-imprimir"><i class="fa fa-print" ></i> Imprimir</button>
                  </div>
                </div>
                <div class="panel-body ">
                  <div class="row" id="campoI">
                    <div class="col-md-12" id="div-datos" style="font-size:10px;">
                        <div  style="margin-left:25px">
                          <span> FECHA: <strong id="fechaOperacion"> </strong> </span>
                        </div>

                        <div style="margin-left:25px">
                          <span> OFICINA: <strong> {{ SITE_URL }}</strong></span>
                        </div>
                        
                        <div style="margin-left:25px">
                          <span> OPERADOR: <strong id="txtOperador">{{ usu_n_c }}</strong></span>
                        </div>
                        <div style="margin-left:25px">
                          <span>CIERRE DESDE: <strong  id="txtfecha11" style="margin-right: 10px;"></strong>
                          HASTA: <strong id="txtfecha21"></strong></span>
                        </div>
                        <p></p>
                    </div>
                    <div class="col-md-12">
                      <div >
                        <table id="IED" class="table table-striped" style="font-size:10px;">
                        <thead>
                          <tr >
                            <th colspan="10" style="text-align:center">MOVIMIENTOS DOLARES</th>
                          </tr>
                          <tr>
                            <th>
                              Operación
                            </th>
                            <th style="text-align:center">
                              Concepto
                            </th>
                            <th>ST</th>
                            <th>
                              Fecha
                            </th>
                            <th>Capital</th>
                            <th>Comision</th>
                            <th>C. Bancos</th>
                            <th>TC</th>
                             <th>
                              Ingreso
                            </th>
                            <th>
                              Egreso
                            </th>
                          </tr>
                        </thead>
                        <tbody id="listaIED">
                          
                        </tbody>
                        <tfoot>
                          
                          <tr>
                              <td>
                                 &nbsp;
                              </td>
                              <td>
                                &nbsp;
                              </td>
                              <td>
                                &nbsp;
                              </td>
                              <td >
                                &nbsp;
                              </td>
                              <td >
                                <label id="tcapid"></label>
                              </td>
                              <td >
                                <label id="tcomid"></label>
                              </td>
                               <td >
                                <label id="tbancod"></label>
                              </td>
                              <td >
                                <label id="tpromtc"></label>
                              </td>
                              <td >
                               &nbsp;
                              </td>
                              <td >
                                &nbsp;
                              </td>
                          </tr>
                         
                          <tr>
                              <td></td>
                              <td></td>
                              <td></td>
                              <td style="text-align:right" class="row">
                                <label> SUB-TOTAL</label>
                              </td>
                              <td >
                                <label> &nbsp;</label>
                              </td>
                              <td>
                                <label> &nbsp;</label>
                              </td>
                              <td >
                                <label> &nbsp;</label>
                              </td>
                              <td >
                                <label> &nbsp;</label>
                              </td>
                               <td >
                                <label id="ID"></label>
                              </td>
                              <td >
                                <label id="ED"></label>
                              </td>
                          </tr>
                        </tfoot>  
                        </table>
                      </div>
                    </div>

                    <div class="col-md-12">
                      <div >
                        <table id="IES" class="table table-striped" style="font-size:10px;">
                        <thead>
                          <tr>
                            <th colspan="9" style="text-align:center">MOVIMIENTOS SOLES</th>
                          </tr>
                          <tr>
                            <th >
                              Operacion
                            </th>
                            <th>
                              Concepto
                            </th>
                            <th>ST</th>
                            <th>
                              Fecha
                            </th>
                            <th >Capital</th>
                            <th>Comision</th>
                            <th>C. Bancos</th>
                             <th>
                              Ingreso
                              </th>
                            <th>
                              Egreso
                            </th>
                          </tr>
                         
                        </thead>
                        <tbody id="listaIES">
                         
                        </tbody>
                        <tfoot>
                          
                          <tr>
                              <td >
                                 &nbsp;
                              </td>
                              <td >
                                &nbsp;
                              </td>
                              <td >
                                &nbsp;
                              </td>
                              <td >
                                &nbsp;
                              </td>
                              <td id="tcapis">
                                
                              </td>
                              <td >
                                <label id="tcomis"></label>
                              </td>
                               <td >
                                <label id="tbancos"></label>
                              </td>
                              <td width="9%">
                               &nbsp;
                              </td>
                              <td width="8%">
                                &nbsp;
                              </td>
                          </tr>
                         
                          <tr>
                              <td ></td>
                              <td ></td>
                              <td ></td>
                              <td style="text-align:right">
                                <label> SUB-TOTAL</label>
                              </td>
                              <td >
                                <label> &nbsp;</label>
                              </td>
                              <td >
                                <label> &nbsp;</label>
                              </td>
                              <td >
                                <label> &nbsp;</label>
                              </td>
                               <td >
                                <label id="IS"></label>
                              </td>
                              <td >
                                <label id="ES"></label>
                              </td>
                          </tr>
                         
                          
                        </tfoot>  
                        </table>
                      </div>
                    </div>
                    <br>
                    <div class="row myb-4">
                      <div class="col-md-4 table-scroll">
                        <div class="table-responsive" >
                          <table class="table"style="font-size:11px;" id="resumen-soles">
                            <thead>
                              <tr>
                                <th colspan="2" class="center light-green lighten-4">
                                  SOLES
                                </th>
                              </tr>
                              <tr>
                                <th>Detalle</th>
                                <th class="right">Monto</th>
                              </tr>
                            </thead>
                            <tbody >
                              <tr>
                                <td>Saldo Inicial</td>
                                <td style="color: green;" class="right" id="re-si-so">+ 0.00</td>
                              </tr>
                              <tr>
                                <td>Total Ingresos</td>
                                <td style="color: green;" class="right" id="re-i-so">+ 0.00</td>
                              </tr>
                              <tr>
                                <td>Total Egresos</td>
                                <td style="color: red;" class="right" id="re-e-so">- 0.00</td>
                              </tr>
                            </tbody>
                            <tfoot>
                              <tr style="border: 1px solid #616161;">
                                <th>Diferencia:</th>
                                <td style="color: blue;" class="right" id="re-t-so">0.00</td>
                              </tr>
                            </tfoot>
                          </table>
                        </div>
                      </div>
                      <div class="col-md-4 table-scroll">
                        <div class="table-responsive" >
                          <table class="table" style="font-size:12px;" id="resumen-dolares">
                            <thead>
                              <tr>
                                <th colspan="2" class="center light-blue lighten-4">
                                  DOLARES
                                </th>
                              </tr>
                              <tr>
                                <th>Detalle</th>
                                <th class="right">Monto</th>
                              </tr>
                            </thead>
                            <tbody >
                              <tr>
                                <td>Saldo Inicial</td>
                                <td style="color: green;" class="right" id="re-si-do">+ 0.00</td>
                              </tr>
                              <tr>
                                <td>Total Ingresos</td>
                                <td style="color: green;" class="right" id="re-i-do">+ 0.00</td>
                              </tr>
                              <tr>
                                <td>Total Egresos</td>
                                <td style="color: red;" class="right" id="re-e-do">- 0.00</td>
                              </tr>
                            </tbody>
                            <tfoot>
                              <tr style="border: 1px solid #616161;">
                                <th>Diferencia:</th>
                                <td style="color: blue;" class="right" id="re-t-do">0.00</td>
                              </tr>
                            </tfoot>
                          </table>
                        </div>
                      </div>
                    </div>
                    <p></p>
                    <div class="row" align="center" is="div-saldos">
                      <div class="col-md-6 col-md-offset-3">
                        <table class="table">
                          <thead>
                            <tr>
                              <td colspan="4">SALDO DEL SISTEMA</td>
                            </tr>
                            <tr>
                              <td>Soles: </td>
                              <td id="soles_sistema">0.00</td>
                              <td >Dolares:</td>
                              <td id="dolares_sistema">0.00</td>
                            </tr>
                          </thead>
                        </table>
                      </div>
                    </div>
                    <br>

                    <div align="center" id="div-obs">
                      <div class="form-group">
                        <label for="obse">OBSERVACIONES: </label>
                        <p id="texto_obse" style="width:300px" ></p>
                      </div>
                    </div>

                  </div>
                </div>
              </div>
            </div>
          </div>
          <!--
          <form action="/reimprimir_cierre/" method="POST">{% csrf_token %}
          <div class="row">
              <div class="col-md-12" >
                  <div class="panel panel-default">
                      <div class="panel-heading panel-transferencia">DETALLE DE CIERRE</div>
                      <div class="panel-body">
                        <div class="row">
                          <div class="col-md-10 col-md-offset-1">
                            <div class="table-responsive">
                              <table class="table">
                                <thead>
                                  <tr>
                                    <th>&nbsp;</th>
                                    <th>Soles</th>
                                    <th>Dolares</th>
                                  </tr>
                                </thead>
                                <tbody>
                                  <tr>
                                    <th>Saldo Inicial</th>
                                    <td ><input type="text" id="SIS" name="SIS" class="form-control" readonly="readonly" style="border: 0px solid #6275B7;"></td>
                                    <td ><input type="text" id="SID" name="SID" class="form-control" readonly="readonly" style="border: 0px solid #6275B7;"></td>
                                  </tr>
                                  <tr>
                                    <th>Total Ingreso</th>
                                    <td ><input type="text" id="IS" name="IS" class="form-control" readonly="readonly" style="border: 0px solid #6275B7;"></td>
                                    <td ><input type="text" id="ID" name="ID" class="form-control" readonly="readonly" style="border: 0px solid #6275B7;"></td>
                                  </tr>
                                  <tr>
                                    <th>Total Egreso</th>
                                    <td ><input type="text" id="ES" name="ES" class="form-control" readonly="readonly" style="border: 0px solid #6275B7;"></td>
                                    <td ><input type="text" id="ED" name="ED" class="form-control" readonly="readonly" style="border: 0px solid #6275B7;"></td>
                                  </tr>
                                  <tr>
                                    <th>Saldo</th>
                                    <th ><input type="text" id="SS" name="SS" class="form-control" readonly="readonly" style="border: 0px solid #6275B7;"></th>
                                    <th ><input type="text" id="SD" name="SD" class="form-control" readonly="readonly" style="border: 0px solid #6275B7;"></th>
                                  </tr>
                                </tbody>
                              </table>
                            </div>
                            
                          </div>
                        </div>
                        <p></p>
                        <div class="row">
                          <div class="col-md-1 col-md-offset-1">
                            <h5>Desde</h5>
                          </div>
                          <div class="col-md-3">
                             <input type="text" class="form-control date" id="txtfecha11" name="F1" readonly="readonly" style="border: 0px solid #6275B7;">
                          </div>
                           <div class="col-md-1">
                            <h5>Hasta</h5>
                          </div>
                          <div class="col-md-3">
                            <input type="text" class="form-control date" id="txtfecha21" name="F2" readonly="readonly" style="border: 0px solid #6275B7;">
                          </div>
                        </div>
                        <p></p>
                        <div class="row">
                          <div class="col-md-2 col-md-offset-1">
                            <h5>Observaciones</h5>
                          </div>
                          <div class="col-md-4">
                             <input type="text" class="form-control date" id="txtobs" name="obs" readonly="readonly" style="border: 0px solid #6275B7;">
                          </div>
                        </div>
                        <p></p>
                        <div class="row" id="campoDetalle_recibidos">
                          <div class="col-md-4 col-md-offset-4">
                            <button class="btn btn-warning btn-block" type="submit">Reimprimir Detalles de Cierre</button>
                        </div>
                        <p></p>

                      </div>
                  </div>
              </div>
          </div>
          </form>
          -->
        </div>
      </div>
    </div>
</div>
<div id="modal-detalle-trans" class="modal">
  <div class="modal-content">
    <div id="impresion">
      <style type="text/css">
        table.tablep{
          border-collapse: collapse;
          border-color: grey;
          width: 100%;
            max-width: 100%;
            margin-bottom: 20px;
            background-color: transparent;
            display: table;
            border-top: 1px solid #ddd;
            font-size: 11px;
        }
        .tablep>thead>tr {
            color: #707070;
            font-weight: normal;
            background-color: #f8f8f8;
            background-image: -webkit-linear-gradient(top, #f8f8f8 0, #ececec 100%);
            background-image: linear-gradient(to bottom, #f8f8f8 0, #ececec 100%);
            background-repeat: repeat-x;
        }
        .tablep>tbody>tr>td, .tablep>tbody>tr>th, .tablep>tfoot>tr>td, .tablep>tfoot>tr>th, .tablep>thead>tr>td, .tablep>thead>tr>th {
              padding: 2px;
              padding-left: 5px;
              line-height: 1.42857143;
              vertical-align: top;
              border: 1px solid #ddd;
        }
        .titulos{
          font-size: 14px;
          margin-top:5px;
          margin-bottom:5px;
        }
      </style>
      <table style="width: 100%;">
        <tr>
          <td style="border-bottom: 1px solid #ddd;" align="center"><b>CIERRE DE CAJA</b></td>
        </tr>
      </table>
      
      <table  style="font-size: 12px;">
        <tr>
          <td id="im-datos">></td>

        </tr>
      </table>
      <br>
      <span class="titulos">RESUMEN DE CIERRE</span>
      <table class="tablep">
        <tr>
          <td  width="40%">
            <div >
              <table class="tablep" style="font-size:12px;" id="re-soles">
                
              </table>
            </div>
          </td>
          <td width="40%">
            <div>
              <table class="tablep" style="font-size:12px;" id="re-dolares">
                
              </table>
            </div>
          </td>
        </tr>
      </table>
      <br>
      <span class="titulos">DETALLE SOLES</span>
      <table class="tablep" id="det-soles">
       
      </table>
      <br>
      <span class="titulos">DETALLE DOLARES</span>
      <table class="tablep" id="det-dolares">
        
      </table>
      <br>
      <br>
      <table>
        <tr>
          <td id="im-saldos"></td>
        </tr>
      </table>
      <br>
      <table>
        <tr>
          <td id="im-obs"></td>
        </tr>
      </table>
      <br>

      <table style="width: 100%">
        <tr align="center">
          <td>
            _____________________________________________
          </td>
        </tr>
        <tr align="center">
          <td>{{usu_n_c}}</td>
        </tr>
      </table>
    </div>
  </div>
</div>
<script type="text/javascript">
  var Aux="";
  var filaI =0;
  //--
  var i_so=0;
  var si_so=0;
  var i_do=0;
  var si_do=0;
  var e_so=0;
  var e_do=0;
  var sa_so=0;
  var sa_do=0;
  $(document).ready(function () {
    ajax_Cierres();
    $("#btnRefrescar").click(function(){
      ajax_Cierres();
    });
    //
    /*
    $("#Impr").click(function(){
      $("#impresion").printThis();
    })*/
    //
    $(document).on("click",".filaC",function(){
      var fila= $(this).attr('class');
      var num = $(this).attr('id');
      filaI = num;
      //$("."+fila).attr('class','filaC');
      //$(this).attr('class','filaC info');
      $("#campoDetalle_recibidos").show();
      $("#txtfecha11").text(Aux[filaI].fd);
      $("#txtfecha21").text(Aux[filaI].fh);
      $("#fechaOperacion").text(Aux[filaI].fecha);
      $("#soles_sistema").text(Aux[filaI].soles_sistema);
      $("#dolares_sistema").text(Aux[filaI].dolares_sistema);
      //--
     si_so=parseFloat(Aux[filaI].sis);
     si_do=parseFloat(Aux[filaI].sid);
     $("#re-si-so").text("+ "+Aux[filaI].sis);
     $("#re-si-do").text("+ "+Aux[filaI].sid);
     ajax_Ingreso();
     //--
      $("#texto_obse").text(Aux[filaI].obs);
      // $('#listaI').html("");
      // $('#listaE').html("");
      if(Aux[filaI].est=='cancelado'){
        $("#campoDetalle_recibidos").hide();
      }
    });
    //
    /*
    $("#mostrarD").click(function(){
      ajax_EgresoB();
      ajax_IngresoB();
    })*/
    //
    $("#refresh-movimiento").click(function(){
      ajax_Ingreso();
    })
    $("#btn-imprimir").click(function(){
      imprimirSD();
    })
    function imprimirSD(){
      $("#im-datos").html($("#div-datos").html());
      $("#re-soles").html($("#resumen-soles").html());
      $("#re-dolares").html($("#resumen-dolares").html());
      $("#det-soles").html($("#IES").html());
      $("#det-dolares").html($("#IED").html());
      $("#im-obs").html($("#div-obs").html());
      $("#im-saldos").html($("#div-saldos").html());
      printElem('impresion');
    }
    function printElem(divId) {
        var content = document.getElementById(divId).innerHTML;
        var mywindow = window.open('about:blank', '_new', 'height=600,width=800');
        mywindow.document.write('<html><head><title>Print</title>');
        mywindow.document.write('</head><body>');
        mywindow.document.write('<style>body{font-family: "Lucida Console";}</style>');
        mywindow.document.write(content);
        mywindow.document.write('</body></html>');
        mywindow.document.close();
        mywindow.focus()
        setTimeout(function(){ mywindow.print(); mywindow.close()}, 500);
        return true;
    }
    function ajax_Cierres(){
      $('.table-responsive').waitMe({effect : 'progressBar',text : 'Recuperando Datos'});
      $.ajax({
        url:'/lista_cierre_caja/',
        type:'GET',
        dataType:'json',
        success: function(data){
          var html ="";
          Aux = data;
          var estado ="";
          for(var i=0;i<data.length;i++){
            estado ="";
            if(data[i].est=="cancelado"){
                  estado="danger";
                  
            }
            if(data[i].est =="cerrado"){
                  estado = "";
                  
            }
             html += '<tr class="filaC '+ estado+'" id="'+i+'" data-toggle="modal" data-target="#myModal"><td>'+data[i].fd+'</td><td style="color:green;">'+data[i].sis+'</td><td style="color:green;">'+data[i].is +'</td><td style="color:red;">'+data[i].es+'</td><td style="color:blue;">'+data[i].ss+'</td><td style="color:green;">'+data[i].sid+'</td><td style="color:green;">'+data[i].ide+'</td><td style="color:red;">'+data[i].ed+'</td><td style="color:blue;">'+data[i].sd+'</td><td>'+data[i].obs+'</td><td>'+data[i].fecha+'</td></tr>';
          }                        
          $('#listaC').html(html);
          $('.table-responsive').waitMe('hide');
        }
      });
    }
    function ajax_Ingreso(){
      $('#body-cierre').waitMe({effect : 'progressBar',text : 'Recuperando Datos'});
      $.ajax({
        data:{'filtro':'f','F1':$('#txtfecha11').text(),'F2':$('#txtfecha21').text()},
        url:'/consultaIngreso_cierre/',
        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><label> '+data[i].tipodoc+' - '+data[i].nroR+'  '+data[i].usuGlo+'</label></td><td><label>'+data[i].concepto+'</label></td><td><label> &nbsp;</label></td><td ><label>'+data[i].fecha+'</label></td><td>'+data[i].capi+'</td><td>'+data[i].comision+'</td><td>'+data[i].comi_banco+'</td><td><label>'+data[i].monto+'</label></td><td><label></label></td></tr>';
            }
            else{
              html2 += '<tr><td ><label> '+data[i].tipodoc+' - '+data[i].nroR+'  '+data[i].usuGlo+'</label></td><td ><label>'+data[i].concepto+'</label></td><td ><label> &nbsp;</label></td><td ><label>'+data[i].fecha+'</label></td><td ><label>'+data[i].capi+'</label></td><td ><label>'+data[i].comision+'</label></td><td ><label>'+data[i].comi_banco+'</label></td><td ><label>'+data[i].tcd+'</label></td><td width="9%" class="row"><label>'+data[i].monto+'</label></td><td ><label>&nbsp;</label></td></tr>';
            }
          }
          listaSI = html1;
          listaDI = html2;
          //console.log(html1);
          //console.log(html2);
          //$('#listaI').html(html);
          $("#IS").text(data[data.length-1].total_soles);
          $("#ID").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);
          //$("#CS").text(data[data.length-1].util_soles);
          //$("#CD").text(data[data.length-1].util_dolares);
          //---
          $("#re-i-so").text("+ "+data[data.length-1].total_soles);
          $("#re-i-do").text("+ "+data[data.length-1].total_dolares);
          i_so = parseFloat(data[data.length-1].total_soles);
          i_do = parseFloat(data[data.length-1].total_dolares);
          //--
          bi=true;
          ajax_Egreso(html1,html2);
          /*
          if(bi&&be){
            $("#listaIES").html(listaSI+listaSE);
            $("#listaIED").html(listaDI+listaDE);
            ajax_saldo_inicial();
            calcular_Saldo();
          }*/
        }, 
        error: function(xhr, textStatus, errorThrown) {
              console.log(xhr.responseText);
        },
      });
    };
    //
    function ajax_Egreso(listaIs,listaId){
      $.ajax({
        data:{'filtro':'f','F1':$('#txtfecha11').text(),'F2':$('#txtfecha21').text()},
        url:'/consultaEgreso_cierre/',
        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 ><label> '+data[i].tipodoc+' - '+data[i].nroR+'  </label></td><td ><label>'+data[i].concepto+'</label></td><td ><label>'+data[i].st +'</label></td><td ><label>'+data[i].fecha+'</label></td><td ><label> &nbsp;</label></td><td ><label> &nbsp;</label></td><td ><label> &nbsp;</label></td><td width="9%" class="row"><label>&nbsp;</label></td><td ><label>'+data[i].monto+'</label></td></tr>';
            }
            else{
              html2 += '<tr><td ><label> '+data[i].tipodoc+' - '+data[i].nroR+'  </label></td><td ><label>'+data[i].concepto+'</label></td><td ><label>'+data[i].st +'</label></td><td ><label>'+data[i].fecha+'</label></td><td ><label> &nbsp;</label></td><td ><label> &nbsp;</label></td><td ><label> &nbsp;</label></td><td ><label> '+data[i].tcd+'</label></td><td width="9%" class="row"><label>&nbsp;</label></td><td ><label>'+data[i].monto+'</label></td></tr>';
            }
          }
          listaSE=html1;
          listaDE=html2;
          //$('#listaE').html(html);
          $("#ES").text(data[data.length-1].total_soles);
          $("#ED").text(data[data.length-1].total_dolares);
          be=true;
          var aux1=listaIs+html1
          var aux2=listaId+html2
          $("#listaIES").html(aux1);
          $("#listaIED").html(aux2);
            //ajax_saldo_inicial();
          //---
          $("#re-e-so").text("- "+data[data.length-1].total_soles);
          $("#re-e-do").text("- "+data[data.length-1].total_dolares);
          e_so = parseFloat(data[data.length-1].total_soles);
          e_do = parseFloat(data[data.length-1].total_dolares);
          calcular_totales();
          $('#body-cierre').waitMe('hide');
        },
         error: function(xhr, textStatus, errorThrown) {
              console.log(xhr.responseText);
        },
      });
    };
    //
    function calcular_totales(){
      $("#re-t-so").text(round( si_so +i_so -e_so ,2));
      $("#re-t-do").text(round( si_do+i_do -e_do ,2));
    }
    //---
    function round(value, decimals) {
      return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
    }
  });
</script>
{% endblock content1 %}