{% extends "base.html" %}
{% block titulo %}
  Lista liquidaciones socios y agentes
{% endblock titulo %}
{% block titulo_left %}
  Lista Liquidaciones
{% endblock titulo_left %}

{% block titulo_center %}
  Administracion
{% endblock titulo_center %}

{% block content1 %}
<script type="text/javascript">
  $("#navIE").attr('class','dropdown active');
  $("#navListaLiqui").attr('class','active');
</script>
<div class="row">
  <div class="col-md-12">
    <div class="panel panel-default" >
        <div class="panel-heading panel-toolbar"> 
          <strong>LISTA DE LIQUIDACIONES</strong>
          <button type="button" class="btn btn-default btn-sm" id="btnRefrescar">Refrescar</button>
        </div>
        <div class="panel-body">
            <table class="table table-hover">
              <thead>
                <tr>
                    <th>fecha Liquidacion</th>
                    <th>Base</th>
                    <th>Operador</th>
                    <th>Desde Fecha</th>
                    <th>Hasta Fecha</th>
                    <th>Observacion</th>
                    <th>estado</th>
                </tr>
              </thead>
              <tbody id="listaL">
                
              </tbody>
            </table>
          </div>
        </div>
  </div>
</div>

<div id="modal-detalle-liquidacin" class="modal fade modal-height-lg modal-static" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <label>Detalle de liquidacion</label>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-12">
            <div class="row min-row hidden">
              <input type="text" id="txt-pk-li">
            </div>
            <div class="row">
              <div class="col-md-12">
                <label ><b>Base: </b></label> 
                <span class="black-text" style="font-size: 16px;" id="lbl-base"> </span>
              </div>
            </div>
            <div class="row">
              <div class="col-md-12">
                <label class="indigo-text"><b>Operador: </b></label>
                <span class="black-text" style="font-size: 16px;" id="lbl-personal"> </span>
              </div>
            </div>
            <div class="row">
              <div class="col-md-12">
                <label class="label-input-easy" for="obs"><b>Observaciones</b></label>
                <textarea id="obs" name="obs" class="form-control" data-length="100" placeholder=""></textarea>
                
              </div>
            </div>
            <div class="row" id="div-botones">
              <div class="col-md-12">
                <button class="btn btn-sm btn-danger" id="btn_anular">Anular</button>
                <button class="btn btn-sm btn-warning" id="btn_act_obs">Actualizar obs</button>
                <button class="btn btn-sm btn-success" id="btn_ver">Ver Liquidacion</button>
              </div>
            </div>
          </div>
        </div>
        

      </div>
    </div>
  </div>
</div>

<div id="modal-ver-liquidacion" class="modal fade modal-height-lg modal-static" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <label class="modal-title" id="exampleModalLabel">Detalle de liquidacion</label>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-12">
            <div class="row min-row">
              <div class="col-md-12">
                <div class="panel">
                  <div class="panel-body z-depth-1" style="padding-top: 0px;">
                    <div class="row min-row">
                      <div class="col-md-12">
                        <h5 class="green-text">Soles</h5>
                      </div>
                    </div>

                    <div class="row">
                      <div class="col-md-12" style="font-size: 13px;">
                        <table class="table table-striped">
                          <thead>
                            <tr>
                              <th colspan="11" class="center green lighten-4">
                                TRANSFERENCIAS CREADAS - SOLES
                              </th>
                            </tr>
                            <tr>
                              <th>Operacion</th>
                              <th>Concepto</th>
                              <th>Fecha</th>
                              <th>Capital</th>
                              <th>Com.<br>Bancos</th>
                              <th>Com.<br>Giro</th>
                              <th>Comision</th>
                              <th>Monto<br>Oficina</th>
                              <th>Monto<br>Central</th>
                              <th>Monto<br>Of. Compartida</th>
                              <th>Operador</th>
                            </tr>
                          </thead>
                          <tbody id="lista-st-s"></tbody>
                          <tfoot id="lista-t-st-s">
                            <!--
                            <tr>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <th class="right">Subtotal </th>
                              <th id="td-st-s-t-capital">0.00</th>
                              <th id="td-st-s-t-comi-banco">0.00</th>
                              <th id="td-st-s-t-comi-giro">0.00</th>
                              <th id="td-st-s-t-comi">0.00</th>
                              <th id="td-st-s-t-m-oficina">0.00</th>
                              <th id="td-st-s-t-m-central">0.00</th>
                              <th id="td-st-s-t-m-compart">0.00</th>
                            </tr>
                           -->
                          </tfoot>
                        </table>
                      </div>
                    </div>

                    <div class="row min-row">
                      <div class="col-md-12" style="font-size: 13px;">
                        <table class="table table-striped" id="table-pt-s">
                          <thead>
                            <tr>
                              <th colspan="11" class="center amber lighten-4">
                                TRANSFERENCIAS PAGADAS - SOLES
                              </th>
                            </tr>
                            <tr>
                              <th>Operacion</th>
                              <th>Concepto</th>
                              <th>ST</th>
                              <th>Fecha</th>
                              <th>Capital</th>
                              <th>Egreso<br>Extra</th>
                              <th>Comision</th>
                              <th>Monto<br>Oficina</th>
                              <th>Monto<br>Central</th>
                              <th>Monto<br>Of. Compartida</th>
                              <th>Operador</th>
                            </tr>
                          </thead>
                          <tbody id="lista-pt-s"></tbody>
                          <tfoot id="lista-t-pt-s">
                            <!--
                            <tr>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <th class="right">Subtotal </th>
                              <th id="td-pt-s-t-capital">0.00</th>
                              <th id="td-pt-s-t-egreso">0.00</th>
                              <th id="td-pt-s-t-comi">0.00</th>
                              <th id="td-pt-s-t-m-oficina">0.00</th>
                              <th id="td-pt-s-t-m-central">0.00</th>
                              <th id="td-pt-s-t-m-compart">0.00</th>
                            </tr>
                           -->
                          </tfoot>
                        </table>
                      </div>
                    </div>

                    <div class="row">
                      <div class="col-md-12" style="font-size: 13px;">
                        <table class="table table-striped">
                          <thead>
                            <tr>
                              <th colspan="11" class="center green lighten-4">
                                TRANSFERENCIAS BANCOS CREADAS
                              </th>
                            </tr>
                            <tr>
                              <th>Operacion</th>
                              <th>Concepto</th>
                              <th>Fecha</th>
                              <th>Capital</th>
                              <th>Com.<br>Bancos</th>
                              <th>Comision</th>
                              <th>Monto<br>Oficina</th>
                              <th>Monto<br>Central</th>
                              <th>Monto<br>Of. Compartida</th>
                              <th>Operador</th>
                            </tr>
                          </thead>
                          <tbody id="lista-st-b-s"></tbody>
                          <tfoot id="lista-t-st-b-s"></tfoot>
                        </table>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <div class="row min-row">
              <div class="col-md-12">
                <div class="panel">
                  <div class="panel-body z-depth-1" style="padding-top: 0px;">
                    <div class="row min-row">
                      <div class="col-md-12">
                        <h5 class="blue-text">Dolares</h5>
                      </div>
                    </div>
                    
                    <div class="row">
                      <div class="col-md-12" style="font-size: 13px;">
                        <table c class="table table-striped">
                          <thead>
                            <tr>
                              <th colspan="11" class="center light-blue lighten-4">
                                TRANSFERENCIAS CREADAS - DOLAREAS
                              </th>
                            </tr>
                            <tr>
                              <th>Operacion</th>
                              <th>Concepto</th>
                              <th>Fecha</th>
                              <th>Capital</th>
                              <th>Com.<br>Bancos</th>
                              <th>Com.<br>Giro</th>
                              <th>Comision</th>
                              <th>Monto<br>Oficina</th>
                              <th>Monto<br>Central</th>
                              <th>Monto<br>Of. Compartida</th>
                              <th>Operador</th>
                            </tr>
                          </thead>
                          <tbody id="lista-st-d"></tbody>
                          <tfoot id="lista-t-st-d">
                            <!--
                            <tr>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <th class="right">Subtotal </th>
                              <th id="td-st-d-t-capital">0.00</th>
                              <th id="td-st-d-t-comi-banco">0.00</th>
                              <th id="td-st-d-t-comi-giro">0.00</th>
                              <th id="td-st-d-t-comi">0.00</th>
                              <th id="td-st-d-t-m-oficina">0.00</th>
                              <th id="td-st-d-t-m-central">0.00</th>
                              <th id="td-st-d-t-m-compart">0.00</th>
                            </tr>
                           -->
                          </tfoot>
                        </table>
                      </div>
                    </div>

                    <div class="row min-row">
                      <div class="col-md-12" style="font-size: 13px;">
                        <table  class="table table-striped" id="table-pt-d">
                          <thead>
                            <tr>
                              <th colspan="11" class="center orange lighten-4">
                                TRANSFERENCIAS PAGADAS - DOLARES
                              </th>
                            </tr>
                            <tr>
                              <th>Operacion</th>
                              <th>Concepto</th>
                              <th>ST</th>
                              <th>Fecha</th>
                              <th>Capital</th>
                              <th>Egreso<br>Extra</th>
                              <th>Comision</th>
                              <th>Monto<br>Oficina</th>
                              <th>Monto<br>Central</th>
                              <th>Monto<br>Of. Compartida</th>
                              <th>Operador</th>
                            </tr>
                          </thead>
                          <tbody id="lista-pt-d"></tbody>
                          <tfoot id="lista-t-pt-d">
                            <!--
                            <tr>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <th class="right">Subtotal </th>
                              <th id="td-pt-d-t-capital">0.00</th>
                              <th id="td-pt-d-t-egreso">0.00</th>
                              <th id="td-pt-d-t-comi">0.00</th>
                              <th id="td-pt-d-t-m-oficina">0.00</th>
                              <th id="td-pt-d-t-m-central">0.00</th>
                              <th id="td-pt-d-t-m-compart">0.00</th>
                            </tr>
                          -->
                          </tfoot>
                        </table>
                      </div>
                    </div>


                  </div>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-md-12">
                <button class="btn btn-sm btn-info" id="btn-reimprimir">Reimprimir</button>
              </div>

            </div>
          </div>
        </div>
        
      </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>LIQUIDACION DE OFICINA</b></td>
        </tr>
      </table>
      
      <table  style="font-size: 13px;">
        <tr>
          <td><b>Oficina:</b></td>
          <td id="td-imprimir-base"></td>
        </tr>
        <tr>
          <td><b>Operador:</b></td>
          <td id="td-imprimir-ope"></td>
        </tr>
      </table>
      <br>
      <span class="titulos">DETALLE SOLES</span>
      <table class="tablep">
        <thead>
          <tr>
            <th colspan="9" class="center green lighten-4">
              TRANSFERENCIAS CREADAS - SOLES
            </th>
          </tr>
          <tr>
            <th>Operacion</th>
            <th>Concepto</th>
            <th>Fecha</th>
            <th>Capital</th>
            <th>Comision</th>
            <th>Monto<br>Oficina</th>
            <th>Monto<br>Central</th>
            <th>Monto<br>Of. Compartida</th>
            <th>Operador</th>
          </tr>
        </thead>
        <tbody id="imprimir-st-s"></tbody>
        <tfoot id="imprimir-t-st-s"></tfoot>
      </table>
      <br>
      <table class="tablep" id="imprimir-pt-s">
      </table>
      <br>
      <table class="tablep">
        <thead>
          <tr>
            <th colspan="9" class="center green lighten-4">
              TRANSFERENCIAS CREADAS - SOLES
            </th>
          </tr>
          <tr>
            <th>Operacion</th>
            <th>Concepto</th>
            <th>Fecha</th>
            <th>Capital</th>
            <th>Comision</th>
            <th>Monto<br>Oficina</th>
            <th>Monto<br>Central</th>
            <th>Monto<br>Of. Compartida</th>
            <th>Operador</th>
          </tr>
        </thead>
        <tbody id="imprimir-st-b-s"></tbody>
        <tfoot id="imprimir-t-st-b-s"></tfoot>
      </table>
      <br>
      <span class="titulos">DETALLE DOLARES</span>
      <table class="tablep">
        <thead>
          <tr>
            <th colspan="11" class="center light-blue lighten-4">
              TRANSFERENCIAS CREADAS - DOLAREAS
            </th>
          </tr>
          <tr>
            <th>Operacion</th>
            <th>Concepto</th>
            <th>Fecha</th>
            <th>Capital</th>
            <th>Com.<br>Bancos</th>
            <th>Com.<br>Giro</th>
            <th>Comision</th>
            <th>Monto<br>Oficina</th>
            <th>Monto<br>Central</th>
            <th>Monto<br>Of. Compartida</th>
            <th>Operador</th>
          </tr>
        </thead>
        <tbody id="imprimir-st-d"></tbody>
        <tfoot id="imprimir-t-st-d"></tfoot>
      </table>
      <br>
      <table class="tablep" id="imprimir-pt-d">
      </table>
    </div>
  </div>
</div>
<!-- /impresion -->
<script type="text/javascript">
  var saldo_i_s=0,
      saldo_i_d=0,
      ingreso_s=0,
      ingreso_d=0,
      egreso_s=0,
      egreso_d=0,
      saldo_t_s =0,
      saldo_t_d=0;
  var cfiltro, cf1,cf2, cpk;
  var lista_li=[];
  var indexL=0;
  document.addEventListener('DOMContentLoaded', function() {
    //---

    //--
    function format_cu(num){
        let formatter = new Intl.NumberFormat('es-PE', { style: 'currency', currency: 'PEN' });
        return formatter.format(num);
    }
    function format_monto(num){
        let formatter = new Intl.NumberFormat('es-PE',{minimumFractionDigits:2});
        return formatter.format(num);
    }
    function format_cu_usd(num){
        let formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });
        return formatter.format(num);
    }
    //--- fetch liquidaciones
    $("#btnRefrescar").click(function(){
      fetch_liqudaciones();
    })
    fetch_liqudaciones();
    function fetch_liqudaciones(){
      $('.table').waitMe({effect : 'progressBar',text : 'Recuperando Datos'});
      $.ajax({
        url:'/lista_liquidacion_ajax/',
        //async:false,
        data:{'filtro': cfiltro},
        type:'GET',
        dataType:'json',
        success: function(data){
          $('.table').waitMe('hide');
          lista_li = data;
          let html='';
          let estado='';
          for(var i=0;i<data.length;i++){
            estado='';
            if(data[i].est != 'liquidado'){
              estado='danger';
            }
           html += '<tr class="filaLi '+estado+'" id="'+i+'"><td>'+data[i].f+'</td><td>'+data[i].base+'</td><td>'+data[i].op+'</td><td>'+data[i].fd+'</td><td>'+data[i].fh+'</td><td>'+data[i].obs+'</td><td>'+data[i].est+'</td></tr>';

          }                        
          document.getElementById("listaL").innerHTML=html ;
          document.querySelectorAll(".filaLi").forEach((fila) => {
              fila.addEventListener('click', (event, element) => {
                $("#div-botones").hide();
                indexL=parseInt(fila.id);
                document.getElementById("txt-pk-li").value = data[indexL].pk;
                document.getElementById("lbl-base").innerHTML = data[indexL].base;
                document.getElementById("lbl-personal").innerHTML = data[indexL].op;
                document.getElementById("td-imprimir-base").innerHTML = data[indexL].base;
                document.getElementById("td-imprimir-ope").innerHTML = data[indexL].op;
                document.getElementById("obs").value=data[indexL].obs;
                if( data[indexL].est =="liquidado" ){
                  $("#div-botones").show();
                }
                //--- reimpresion
                cfiltro = 'ef';
                cf1 = data[indexL].fd;
                cf2 = data[indexL].fh;
                cpk = data[indexL].pkC;
                //--- /reimpresion
                //let instance_detail = M.Modal.getInstance(document.getElementById("modal-detalle-liquidacin"));
                //instance_detail.open();
                $("#modal-detalle-liquidacin").modal('show');

              });
            });

        }
      });
    }
    //--- anular
    function fetch_anular(){
      $('.table').waitMe({effect : 'progressBar',text : 'Recuperando Datos'});
      $.ajax({
        url:'/AnularLiquidCaja_admin/',
        //async:false,
        data:{'pkL': document.getElementById("txt-pk-li").value},
        type:'GET',
        dataType:'text',
        success: function(data){
          $('.table').waitMe('hide');
          if(data=='exito'){
            //M.toast({html: 'Liquidacion anulado!'});
            swal("Exito", "Se anulo liquidacion", "success");
            $('#modal-detalle-liquidacin').modal('hide')
            fetch_liqudaciones();
          }
          else{
            //M.toast({html: data.exito});
            swal("Error", data, "error");
            console.log(data);
          }
        }
      });
     
    }
    document.getElementById("btn_anular").onclick=function(){
      /*
      let toastHTML = '<span>Anular Liquidacion?</span><button class="btn-flat toast-action toast-confirmar-anu">ANULAR LIQUIDACION</button>';
      M.toast({html: toastHTML});
      document.querySelector(".toast-confirmar-anu").onclick=function(){
        M.Toast.dismissAll();
        fetch_anular();
        
      }
      */
      fetch_anular();
    }
    //--- actualizar obs
    function fetch_actualizar_obs(){
      $('.table').waitMe({effect : 'progressBar',text : 'Recuperando Datos'});
      $.ajax({
        url:'/ActObservacionesLiquidCaja_admin/',
        //async:false,
        data:{'pkL': document.getElementById("txt-pk-li").value,
        'obs': document.getElementById("obs").value},
        type:'GET',
        dataType:'text',
        success: function(data){
          $('.table').waitMe('hide');
          if(data=='exito'){
            //M.toast({html: 'Observacion actualizado!'});
            swal("Exito", "Se actualizo observacion", "success");
            $('#modal-detalle-liquidacin').modal('hide')
            fetch_liqudaciones();

          }
          else{
            //M.toast({html: data.exito});
            swal("Error", data, "error");
            console.log(data);
          }
        }
      });
      
    }
    document.getElementById("btn_act_obs").onclick=function(){
      /*
      let toastHTML = '<span>Modificar Observacion?</span><button class="btn-flat toast-action toast-confirmar-act">MODIFICAR OBSERVACION</button>';
      M.toast({html: toastHTML});
      document.querySelector(".toast-confirmar-act").onclick=function(){
        M.Toast.dismissAll();
        fetch_actualizar_obs();
        
      }
      */
      fetch_actualizar_obs();
    }
    document.getElementById("btn_ver").onclick=function(){
      //let instance_ver = M.Modal.getInstance(document.getElementById("modal-ver-liquidacion"));
      //instance_ver.open();
      $("#modal-ver-liquidacion").modal('show');
      fetch_st();
      fetch_pt();
      fetch_st_bancos();
    }
    //--- sonsult
    function fetch_st(){
      $('.table').waitMe({effect : 'progressBar',text : 'Recuperando Datos'});
      $.ajax({
        url:'/consulta_tras_creadas_caja_liquidado_fetch/',
        //async:false,
        data:{'filtro': cfiltro,
        'F1': cf1,
        'F2': cf2,
        'pkC': cpk,
        'pkL': document.getElementById('txt-pk-li').value},
        type:'GET',
        dataType:'json',
        success: function(data){
          $('.table').waitMe('hide');
        let html1 = '';
        let html2 = '';
        //--- impresio
        let html1i = '';
        let html2i = '';
        for(var i=0;i<data.length -1;i++){
          if(data[i].moneda =='soles'){
            html1 += '<tr><td>'+data[i].tipodoc+' - '+data[i].nroR+'</td><td>'+data[i].concepto+'</td><td>'+data[i].fecha+'</td><td>'+data[i].capi+'</td><td>'+data[i].comi_banco+'</td><td>'+data[i].comi_giro+'</td><td>'+data[i].comision+'</td><td>'+data[i].st_ca+'</td><td>'+data[i].st_ce+'</td><td>'+data[i].st_ot+'</td><td>'+data[i].ope+'</td></tr>';
            html1i += '<tr><td>'+data[i].tipodoc+' - '+data[i].nroR+'</td><td>'+data[i].concepto+'</td><td>'+data[i].fecha+'</td><td>'+data[i].capi+'</td><td>'+data[i].comision+'</td><td>'+data[i].st_ca+'</td><td>'+data[i].st_ce+'</td><td>'+data[i].st_ot+'</td><td>'+data[i].ope+'</td></tr>';
          }
          else{
            html2 += '<tr><td>'+data[i].tipodoc+' - '+data[i].nroR+'</td><td>'+data[i].concepto+'</td><td>'+data[i].fecha+'</td><td>'+data[i].capi+'</td><td>'+data[i].comi_banco+'</td><td>'+data[i].comi_giro+'</td><td>'+data[i].comision+'</td><td>'+data[i].st_ca+'</td><td>'+data[i].st_ce+'</td><td>'+data[i].st_ot+'</td><td>'+data[i].ope+'</td></tr>';
            html2i += '<tr><td>'+data[i].tipodoc+' - '+data[i].nroR+'</td><td>'+data[i].concepto+'</td><td>'+data[i].fecha+'</td><td>'+data[i].capi+'</td><td>'+data[i].comision+'</td><td>'+data[i].st_ca+'</td><td>'+data[i].st_ce+'</td><td>'+data[i].st_ot+'</td><td>'+data[i].ope+'</td></tr>';
          }
          
        }
        //---
        document.getElementById('lista-st-s').innerHTML = html1;
        document.getElementById('lista-st-d').innerHTML = html2;

        document.getElementById('lista-t-st-s').innerHTML ='<tr><td>&nbsp;</td><td>&nbsp;</td><th class="right">Subtotal </th><th>'+data[data.length-1].tcapis+'</th><th>'+data[data.length-1].tbancos+'</th><th>'+data[data.length-1].tgiroS+'</th><th>'+data[data.length-1].util_soles+'</th><th>'+data[data.length-1].tcof+'</th><th>'+data[data.length-1].tcce+'</th><th>'+data[data.length-1].tcot+'</th><td>&nbsp;</td></tr>';
        //-- impresion
        document.getElementById('imprimir-st-s').innerHTML = html1i;
        document.getElementById('imprimir-st-d').innerHTML = html2i;

        document.getElementById('imprimir-t-st-s').innerHTML ='<tr><td>&nbsp;</td><td>&nbsp;</td><th class="right">Subtotal </th><th>'+data[data.length-1].tcapis+'</th><th>'+data[data.length-1].util_soles+'</th><th>'+data[data.length-1].tcof+'</th><th>'+data[data.length-1].tcce+'</th><th>'+data[data.length-1].tcot+'</th><td>&nbsp;</td></tr>';
        }
      });
    }
    // transferencias bancos creados
    function fetch_st_bancos(){
      $('.table').waitMe({effect : 'progressBar',text : 'Recuperando Datos'});
      $.ajax({
        url:'/consulta_tras_bancos_creadas_caja_liquidado_fetch/',
        //async:false,
        data:{'filtro': cfiltro,
        'F1': cf1,
        'F2': cf2,
        'pkC': cpk,
        'pkL': document.getElementById('txt-pk-li').value},
        type:'GET',
        dataType:'json',
        success: function(data){
          $('.table').waitMe('hide');
        let html1 = '';
        //--- impresio
        let html1i = '';
        for(var i=0;i<data.length -1;i++){
          if(data[i].moneda =='soles'){
            html1 += '<tr><td>'+data[i].tipodoc+' - '+data[i].nroR+'</td><td>'+data[i].concepto+'</td><td>'+data[i].fecha+'</td><td>'+data[i].capi+'</td><td>'+data[i].comi_banco+'</td><td>'+data[i].comision+'</td><td>'+data[i].st_ca+'</td><td>'+data[i].st_ce+'</td><td>'+data[i].st_ot+'</td><td>'+data[i].ope+'</td></tr>';
            html1i += '<tr><td>'+data[i].tipodoc+' - '+data[i].nroR+'</td><td>'+data[i].concepto+'</td><td>'+data[i].fecha+'</td><td>'+data[i].capi+'</td><td>'+data[i].comision+'</td><td>'+data[i].st_ca+'</td><td>'+data[i].st_ce+'</td><td>'+data[i].st_ot+'</td><td>'+data[i].ope+'</td></tr>';
          }
          
          
        }
        //---
        document.getElementById('lista-st-b-s').innerHTML = html1;
        
        document.getElementById('lista-t-st-b-s').innerHTML ='<tr><td>&nbsp;</td><td>&nbsp;</td><th class="right">Subtotal </th><th>'+data[data.length-1].tcapis+'</th><th>'+data[data.length-1].tbancos+'</th><th>'+data[data.length-1].util_soles+'</th><th>'+data[data.length-1].tcof+'</th><th>'+data[data.length-1].tcce+'</th><th>'+data[data.length-1].tcot+'</th><td>&nbsp;</td></tr>';
        //-- impresion
        document.getElementById('imprimir-st-b-s').innerHTML = html1i;
        
        document.getElementById('imprimir-t-st-b-s').innerHTML ='<tr><td>&nbsp;</td><td>&nbsp;</td><th class="right">Subtotal </th><th>'+data[data.length-1].tcapis+'</th><th>'+data[data.length-1].util_soles+'</th><th>'+data[data.length-1].tcof+'</th><th>'+data[data.length-1].tcce+'</th><th>'+data[data.length-1].tcot+'</th><td>&nbsp;</td></tr>';
        }
      });
    }
    // transferencias pagados
    function fetch_pt(){
      $('.table').waitMe({effect : 'progressBar',text : 'Recuperando Datos'});
      $.ajax({
        url:'/consulta_tras_pagadas_caja_liquidado_fetch/',
        //async:false,
        data:{'filtro': cfiltro,
        'F1': cf1,
        'F2': cf2,
        'pkC': cpk,
        'pkL': document.getElementById('txt-pk-li').value},
        type:'GET',
        dataType:'json',
        success: function(data){
          $('.table').waitMe('hide');
        let html1 = '';
        let html2 = '';
        for(var i=0;i<data.length -1;i++){
          if(data[i].moneda =='soles'){
            html1 += '<tr><td>'+data[i].tipodoc+' - '+data[i].nroR+'</td><td>'+data[i].concepto+'</td><td>'+data[i].st+'</td><td>'+data[i].fecha+'</td><td>'+data[i].capi+'</td><td>'+data[i].egreso+'</td><td>'+data[i].comision+'</td><td>'+data[i].st_ca+'</td><td>'+data[i].st_ce+'</td><td>'+data[i].st_ot+'</td><td>'+data[i].ope+'</td></tr>';
          }
          else{
            html2 += '<tr><td>'+data[i].tipodoc+' - '+data[i].nroR+'</td><td>'+data[i].concepto+'</td><td>'+data[i].st+'</td><td>'+data[i].fecha+'</td><td>'+data[i].capi+'</td><td>'+data[i].egreso+'</td><td>'+data[i].comision+'</td><td>'+data[i].st_ca+'</td><td>'+data[i].st_ce+'</td><td>'+data[i].st_ot+'</td><td>'+data[i].ope+'</td></tr>';
          }
        }                        
        
        document.getElementById('lista-pt-s').innerHTML = html1;
        document.getElementById('lista-pt-d').innerHTML = html2;

        //--;
        document.getElementById('lista-t-pt-s').innerHTML ='<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><th class="right">Subtotal </th><th>'+data[data.length-1].capis+'</th><th>'+data[data.length-1].egresos+'</th><th>'+data[data.length-1].util_soles+'</th><th>'+data[data.length-1].tcof+'</th><th>'+data[data.length-1].tcce+'</th><th>'+data[data.length-1].tcot+'</th><td>&nbsp;</td></tr>';
        //calcular();
        //--- imprimesion
        document.getElementById('imprimir-pt-s').innerHTML = document.getElementById('table-pt-s').innerHTML;
        document.getElementById('imprimir-pt-d').innerHTML = document.getElementById('table-pt-d').innerHTML;
        }
      });
      
    }
    
    document.getElementById("btn-reimprimir").onclick=function(){
      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 open_data_uri_window(url) {
      let html = '<html><title>SISTEMA DE MATERIAL</title>' +
          '<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;}  </style>' +
          '<body>' +
          '<iframe src="' + url + '"></iframe>' +
          '</body></html>';
      var a = window.open();
      a.document.write(html);
    }
    
    function get_doc_in(){
      let doc = new jsPDF('l', 'pt');
      let inicia=80
      doc.setFontSize(11);
      doc.text("SISTEMA MATERIAL", 360, 40);
      doc.setFontSize(9);
      doc.text("REPORTE DE INGRESOS EN CAJA TRANSFERENCIAS", 20, 60);
      doc.text("CAJERO: "+"{{ nombre_usuario }}", 20, inicia);
      let resi=doc.autoTableHtmlToJson(document.getElementById("table-in")); 
      doc.autoTable(resi.columns, resi.data, {
          startY: inicia+10,
          margin: {horizontal: 10},
          headerStyles: {rowHeight: 12, fontSize: 8,valign: 'middle'},
          styles: {overflow: 'linebreak'},
          bodyStyles: {rowHeight: 12, fontSize: 8, valign: 'middle'}, 
          theme: 'grid',
          pageBreak: 'avoid',
      });
      return doc;
    
    }

    function get_doc_eg(){
      let doc = new jsPDF('l', 'pt');
      let inicia=80
      doc.setFontSize(11);
      doc.text("SISTEMA MATERIAL", 360, 40);
      doc.setFontSize(9);
      doc.text("REPORTE DE EGRESO EN CAJA TRANSFERENCIAS", 20, 60);
      doc.text("CAJERO: "+"{{ nombre_usuario }}", 20, inicia);
      let resi=doc.autoTableHtmlToJson(document.getElementById("table-eg")); 
      doc.autoTable(resi.columns, resi.data, {
          startY: inicia+10,
          margin: {horizontal: 10},
          headerStyles: {rowHeight: 12, fontSize: 8,valign: 'middle'},
          styles: {overflow: 'linebreak'},
          bodyStyles: {rowHeight: 12, fontSize: 8, valign: 'middle'}, 
          theme: 'grid',
          pageBreak: 'avoid',
      });
      return doc;
    }

    function imprimir_reporte_in(){
      let doc = get_doc_in();
      let uri = doc.output('datauristring');
      open_data_uri_window(uri);
      //
    }
    function export_pdf_in(){
      let doc = get_doc_in();
      doc.save('ReporteIngresosCajaTrans.pdf');
    }
    function imprimir_reporte_eg(){
      let doc = get_doc_eg();
      let uri = doc.output('datauristring');
      open_data_uri_window(uri);
      //
    }
    function export_pdf_eg(){
      let doc = get_doc_eg();
      doc.save('ReporteEgresosCajaTrans.pdf');
    }
    

  });
  
</script>
{% endblock content1 %}


