{% load static %}
<!DOCTYPE html>
<html lang="es">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<head>
  <title> Reimpresión de Cierre Caja Material</title>
  <link href="{% static 'boostbox/css/js/modules/boostbox/libs/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css' %}" rel="stylesheet">
  <link href="{% static 'boostbox/css/theme-5/bootstrap.min.css' %}" rel="stylesheet">
  <script src="{% static 'boostbox/css/js/modules/boostbox/libs/jquery/jquery.min.js' %}"></script>
  <script src="{% static 'boostbox/css/js/modules/boostbox/libs/bootstrap/bootstrap.min.js' %}"></script>
  <script src="{% static 'boostbox/css/js/modules/boostbox/libs/moment/Moment.js' %}"></script>
  <script src="{% static 'boostbox/css/js/modules/boostbox/libs/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js' %}"></script>
  <link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet"/>  
  <script src="{% static 'js/jquery.printarea.js' %}"></script>
  <script src="{% static 'js/jspdf.min.js' %}"></script>
  <script src="{% static 'js/jspdf.plugin.autotable.js' %}"></script>
   <script src="{% static 'js/printThis.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*/
    .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 style="background-color: #ffe2d5;">
  <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"  href="/" role="button"><i class="fa fa-mail-reply"></i> Atras</a> 
    <button type="button" class="btn btn-primary" id="refresh"><i class="fa fa-refresh"></i> Actualizar</button>
  </div>
</div>
  <br>
<div class="main" id="campoI">
  <div class="imp">
      <div style="margin-left:25px">
        <h4> <strong> SISTEMA INTEGRAL </strong> </label></h4>  
        <label> FECHA: <strong id="fechaOperacion"> </strong> </label>
      </div>
      
      <div style="margin-left:25px">
        <h4> <strong> COMPRA Y VENTA DE ORO </strong></h4>
      </div>

      <div style="margin-left:25px">
        <h5> BASE : <strong> {{ SITE_URL }}</strong></h5>
      </div>
      
      <div style="margin-left:25px">
        <h5> OPERADOR: <strong id="txtOperador"></strong></h5>
      </div>
      <div style="margin-left:25px">
        <h5>DESDE: <strong id="fechad" style="margin-right: 10px;">{{ F1 }}</strong>
            HASTA: <strong id="fechah">{{ F2 }}</strong></h5>
      </div>
  </div>
  <br>
  <div class="imp" style="text-align:center">
    <h5><strong> MOVIMIENTOS VENTANILLA - CUADRE CAJA</strong></h5>
  </div>
 
  <br>
  <div class="imp">
    <div >
      <table style="margin: 0 auto" id="headerMaterial">
        <tr>
          <td width="48%">
            <strong id="titulo1Material">=========================================================== MOVIMIENTOS MATERIAL =================================================================</strong>
          </td>
           
          <td width="25%">
            <strong id="titulo2Material"> ============================ GRAMOS DE MATERIAL ============================ </strong>
          </td> 
        </tr>   
      </table>
    </div>
    <br>
    <div >
      <table id="IEM" 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> 
          </tr>
         
          <tr>
            <td width="10%"></td>
            <td width="40%"> <LABEL> SALDO ANTERIOR</LABEL> </td>
            <td>&nbsp;</td>
            <td id="sim">{{ SIM }}</td>
            <td>&nbsp;</td> 
          </tr>
          
        </thead>
        <tbody id="listaIEM">
        </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="IM">{{ IM }}</label>
              </td>
              <td width="8%" class="row">
                <label id="EM">{{ EM }}</label>
              </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="SM">{{ SM }}</label>
              </td>
          </tr>
        </tfoot>
      </table>
    </div>
  </div>
  <div class="imp">
    <div >
       <table style="margin: 0 auto" id="headerDolares">
        <tr>
          <td width="48%">
            <strong id="titulo1MD">========================================================= DESCRIPCIÓN DE MOVIMIENTOS=============================================================== </strong>
          </td>
           
          <td width="25%">
            <strong  id="titulo2MD"> ================================== 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="45%" style="text-align:center">
            <label>CONCEPTO DETALLE</label>
          </td>
          <td width="10%">
            <label>FECHA</label>
          </td>
          <td width= "5%">TC</td><!-- tepo de cambio-->
           <td width="9%">
            <label> INGRESO</label>
          </td>
          <td width="8%">
            <label> EGRESO</label>
          </td>
        </tr>
      
        <tr>
          <td width="10%"></td>
          <td width="40%"> <LABEL> SALDO ANTERIOR</LABEL> </td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td id="sid">{{ SID }}</td>
          <td>&nbsp;</td>
        </tr>
         
      </thead>
      <tbody id="listaIED">
        
      </tbody>
      <tfoot>
        
        <tr>
            <td width="10%">
               &nbsp;
            </td>
            <td width="40%">
              &nbsp;
            </td>
             <td width="10%" class="row">
              <label id="tbancod"></label>
            </td>
            <td width="5%" class="row">
              <label id="tpromtc"></label>
            </td>
            <td width="9%">
             &nbsp;
            </td>
            <td width="8%">
              &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="9%" class="row">
              <label id="ID"></label>
            </td>
            <td width="8%" class="row">
              <label id="ED"></label>
            </td>
        </tr>
       
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
            <td width="10%" style="text-align:right">
              <label> </label> 
            </td>
            <td width="8%"  style="text-align:right">
              <label> &nbsp;</label>
            </td>
             <td width="9%" class="row" style="text-align:right">
              <label> SALDO TOTAL: </label>
            </td>
            <td width="8%" class="row">
              <label id="SD"> {{ SD }}</label>
            </td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>






  <div class="imp">
    <div >
       <table style="margin: 0 auto">
        <tr>
          <td width="48%">
            <strong>========================================================= DESCRIPCIÓN DE 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> OPERACION</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>
        </tr>
        
        <tr>
          <td width="10%"></td>
          <td width="40%"> <LABEL> SALDO ANTERIOR</LABEL> </td>
          <td>&nbsp;</td>
          <td id="sis">{{ SIS }}</td>
          <td>&nbsp;</td>
        </tr>
         
      </thead>
      <tbody id="listaIES">
       
      </tbody>
      <tfoot>
        
        <tr>
            <td width="10%">
               &nbsp;
            </td>
            <td width="40%">
              &nbsp;
            </td>
            <td width="10%" class="row">
              &nbsp;
            </td>
            <td width="9%">
             &nbsp;
            </td>
            <td width="8%">
              &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="9%" class="row">
              <label id="IS"></label>
            </td>
            <td width="8%" class="row">
              <label id="ES"></label>
            </td>
        </tr>
       
        <tr>
            <td width="10%"></td>
            <td width="40%"></td>
             <td width="9%" class="row" style="text-align:right">
              <label>SALDO TOTAL </label>
            </td>
            <td width="8%" class="row">
              <label id="SS">{{ SS }}</label>
            </td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>
  <div align="center">
    <div class="form-group">
      <label for="obse">OBSERVACIONES: </label>
      <textarea rows="2"  id="obse" placeholder="Observaciones de cierre" style="width:300px" readonly="readonly">{{ obs }}</textarea >
      <p id="texto_obse" style="width:300px" ></p>
    </div>
  </div>
  <div >
      <div align="center">
          <button type="button" class="btn btn-primary bc" id="imprimir"><i class="fa fa-print fa-1x"></i> IMPRIMIR</button>
      </div>
      <br>
  </div>
</div>
<div id="modalTipoRecibo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel"> ELIJA EL TIPO DE RECIBO PARA EL CIERRE</h4>
      </div>
      <div class="modal-body">
          
        <div class="row">
          <div class="col-md-12"> 
                <div class="row">
                  <div class="col-md-4 col-md-offset-4"> 
                     <div class="fg-line">
                      <div class="select">
                          <select class="form-control" id="CtipoRecibo">
                            <option value="ticket">Etiquetera (Bixolon)</option>
                            <option value="impresora">A4 (Impresora)</option>
                          </select>
                      </div>
                    </div>
                                  
                  </div>
                </div>
                <br>
                <div class="row">
                  
                  <div class="col-md-4 col-md-offset-4">
                     <button type="button" class="btn btn-success btn-block bc" id="imprimirTipo" data-dismiss="modal">ACEPTAR</button>
                    <!--<button type="button" class="btn btn-primary btn-block bc" id="cerraCaja" data-dismiss="modal">SI</button>-->
                  </div>
                </div>
                <br>
                <!--<div class="row">
                  <div  id="colorc" class="" role="alert" align="center">
                      <h4 id="loadc"></h4>
                  </div>
                </div>--> 
          </div>
        </div>
      </div>
      
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>



<div id="modalreciboIED" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">Detalles</h4>
        </div>
         <div class="modal-body">
          <div  id="platillaII" style="font-family:'arial', Monaco, monospace;font-size:13px;">
            
            <table>
               <tr>
                <td nowrap></td>
                <td nowrap><h4><b>CIERRE CAJA</b></h4></td>
                <td nowrap></td>
              </tr>
               
            </table>
             <table>
               <tr>
                <td nowrap></td>
                <td nowrap><h4><b>(INGRESOS/EGRESO DOLARES)</b></h4></td>
                <td nowrap></td>
              </tr>
               
            </table>
            <table>
              
              <tr>
                <td nowrap width="40%"><span id="fid"></span> </td>
                <td nowrap width="40%"><span id="ffd"></span> </td>
                <td nowrap></td>
              </tr>
              <tr>
                <td nowrap id="txtOperadorTicket">OPERADOR:</td>
                <td nowrap> </td>
                <td nowrap></td>
              </tr>
            </table> 
            
            
             <table>

              <tr>
                <td nowrap width="40%"> OPERACIÓN </td>
                <td nowrap width="80%">FECHA </td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">INGRESO</td> 
                
              </tr>
               <tr>
                <td nowrap width="40%">==========</td>
                <td nowrap width="80%">==============</td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">=======</td>  
              </tr>
               <tr>
                <td nowrap width="40%">SALDO INICIAL</td>
                <td nowrap width="80%"></td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%" id="sidr" style="font-size:15px">{{ SID }}</td>  
              </tr>
              
            </table> 
             <table id="movIDolaresRecibo">
               
            </table>
             <table>
              <tr>
                <td nowrap width="40%">==========</td>
                <td nowrap width="80%">==============</td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">=======</td>  
              </tr>


               <tr>
                <td nowrap width="40%">SUB-TOTAL : </td>
                <td nowrap width="80%"></td>
                 <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%" id="IDR" style="font-size:15px"></td>  
              </tr>
            </table> 
            <br></br>
             <table>
              
             <tr>
                <td nowrap width="40%"> OPERACIÓN </td>
                <td nowrap width="80%" style="padding-left: 10px">FECHA </td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">EGRESO</td> 
                
              </tr>
               <tr>
                <td nowrap width="40%">==========</td>
                <td nowrap width="80%">==============</td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">=======</td>  
              </tr>
               
            </table> 
             <table id="movEDolaresRecibo">
               
            </table> 
             
             <table>
              <tr>
                <td nowrap width="40%">==========</td>
                <td nowrap width="80%">==============</td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">=======</td>  
              </tr>


               <tr>
                <td nowrap width="40%">SUB-TOTAL : </td>
                <td nowrap width="80%"></td>
                 <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%" id="EDR" style="font-size:15px"></td> 
              </tr>
            </table> 
            <br></br>
             <table>
            <tr>
              <td nowrap width="40%">TOTAL SOLES: </td>
              <td nowrap width="80%"></td>
              <td width="30%"><label> &nbsp;</label></td>
              <td nowrap width="40%" style="font-size:15px">{{ SS }}</td> 
            </tr>
          </table>
          <br>
           <table>
            <tr>
              <td nowrap width="40%">TOTAL DOLARES: </td>
              <td nowrap width="80%"></td>
              <td width="30%"><label> &nbsp;</label></td>
              <td nowrap width="40%" style="font-size:15px">{{ SD }} </td> 
            </tr>
          </table>
          <br></br>
          
              
          </div> 
        <div class="modal-footer">
          <hr>
          <button type="button" class="btn btn-primary" data-dismiss="modal">Cerrar</button>
        </div>

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



<div id="modalreciboIES" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="myModalLabel">Detalles</h4>
        </div>
         <div class="modal-body">
          <div  id="platillaI" style="font-family:'arial', Monaco, monospace;font-size:13px;">
            
            <table>
               <tr>
                <td nowrap></td>
                <td nowrap><h4><b>CIERRE CAJA</b></h4></td>
                <td nowrap></td>
              </tr>
               
            </table>
             <table>
               <tr>
                <td nowrap></td>
                <td nowrap><h4><b>(INGRESOS/EGRESO SOLES)</b></h4></td>
                <td nowrap></td>
              </tr>
               
            </table>
            <table>
              
              <tr>
                <td nowrap width="40%"><span id="fis"></span> </td>
                <td nowrap width="40%"><span id="ffs"></span> </td>
                <td nowrap></td>
              </tr>
              <tr>
                <td nowrap id="txtOperadorTicketD">OPERADOR:</td>
                <td nowrap></td>
                <td nowrap></td>
              </tr>
            </table> 
            
            
             <table>
              
             
             <tr>
                <td nowrap width="40%"> OPERACIÓN </td>
                <td nowrap width="80%">FECHA </td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">INGRESO</td> 
                
              </tr>
               <tr>
                <td nowrap width="40%">==========</td>
                <td nowrap width="80%">==============</td>
                 <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">=======</td>  
              </tr>
               <tr>
                <td nowrap width="40%">SALDO INICIAL</td>
                <td nowrap width="80%"></td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%" id="sisr" style="font-size:15px">{{ SIS }}</td>  
              </tr>
            </table> 
             <table id="movISolesRecibo">
               
            </table>
             <table>
              <tr>
                <td nowrap width="40%">==========</td>
                <td nowrap width="80%">==============</td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap  width="40%">=======</td>  
              </tr>


               <tr>
                <td nowrap width="40%">SUB-TOTAL : </td>
                <td nowrap width="80%"></td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%" id="ISR" style="font-size:15px"></td>  
              </tr>
            </table> 
            <br></br>
             <table>
              
              <tr>
                <td nowrap width="40%"> OPERACIÓN </td>
                <td nowrap width="80%" style="padding-left: 10px">FECHA </td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">EGRESO</td> 
                
              </tr>
               <tr>
                <td nowrap width="40%">==========</td>
                <td nowrap width="80%">==============</td>
                 <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%">=======</td>  
              </tr>
               
            </table> 
             <table id="movESolesRecibo">
               
            </table> 
             
             <table>
              <tr>
                <td nowrap width="40%">==========</td>
                <td nowrap width="80%">==============</td>
                <td width="30%"><label> &nbsp;</label></td>
                <td nowrap  width="40%">=======</td>  
              </tr>


               <tr>
                <td nowrap width="40%">SUB-TOTAL : </td>
                <td nowrap width="80%"></td>
                 <td width="30%"><label> &nbsp;</label></td>
                <td nowrap width="40%" id="ESR" style="font-size:15px"></td> 
              </tr>
            </table> 
            <br></br>
           
          </div> 
        <div class="modal-footer">
          <hr>
          <button type="button" class="btn btn-primary" data-dismiss="modal">Cerrar</button>
        </div>

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

<br>

</body>
<script type="text/javascript">
  var bi=false,be=false;
  var listaSI="",listaSE="";
  var listaMI="",listaME="";
  var listaDI="",listaDE="";
  var operadorGlobal="";
  var urlbtt="{% static 'img/btt.png' %}";
  $(document).ready(function(){
    ajax_saldo();
    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();
    $("#fechaOperacion").text(textofecha+" "+textohora);
    var aux='';
    ajax_validar();
    function imprimirSD(){
      var doc = new jsPDF('p', 'pt'); 
      var resd= doc.autoTableHtmlToJson(document.getElementById("IED"));
      var ress= doc.autoTableHtmlToJson(document.getElementById("IES"));
      var resm= doc.autoTableHtmlToJson(document.getElementById("IEM"));

      var base='{{ SITE_URL }}';
      var operador=operadorGlobal;

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

      doc.text("MOVIMIENTOS MATERIAL (GRAMOS)", 10,85);
      doc.autoTable(resm.columns, resm.data, {
          startY: 95,
          margin: {horizontal: 10},
          headerStyles: {rowHeight: 12, fontSize: 7,valign: 'middle'},
          styles: {overflow: 'linebreak'},
          bodyStyles: {rowHeight: 12, fontSize: 8, valign: 'middle'}, 
          theme: 'grid',
          pageBreak: 'avoid',
      });
      var pos1= doc.autoTableEndPosY();
      doc.text("MOVIMIENTOS DOLARES", 10, pos1+20);
      doc.autoTable(resd.columns, resd.data, {
          startY: pos1+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',
      });
      var pos2= doc.autoTableEndPosY();
      doc.text("MOVIMIENTOS SOLES", 10, pos2+20);

      doc.autoTable(ress.columns, ress.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',
      });
      var pos3= doc.autoTableEndPosY();
      doc.text("Saldo que aparece en el sistema SOLES : "+ $("#sis_S").text()+ " DOLARES : "+$("#sis_D").text(), 10, pos3+30);

      doc.text("Observaciones : "+ $("#obse").val(), 10, pos3+50);

      doc.save('reporteCierreCajaSD.pdf'); 
    }
    $("#refresh").click(function(){
        $("#listaIES").html(" ");
        $("#listaIED").html(" ");
        $("#listaIEM").html(" ");

        $("#movISolesRecibo").html(" ");
        $("#movESolesRecibo").html(" ");

        $("#movEDolaresRecibo").html(" ");
        $("#movIDolaresRecibo").html(" ");
        ajax_validar();
      })
    //
     function ajax_Ingreso(){
            $.ajax({
              data:{'filtro':'f','F1':$('#fechad').text(),'F2':$('#fechah').text()},
              url:'/consultaIngreso_m_ajax/',
              type:'GET',
              dataType:'json',
              success: function(data){
                var html1 ="";
                var html2 ="";
                var htmlIR="";
                var htmlIRD="";

                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+'</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].monto+'</label></td><td width="8%" class="row"><label>&nbsp;</label></td></tr>';

                     htmlIR += '<tr><td width="40%" style="font-size: 15px">'+data[i].tipodoc+' - '+data[i].nroR+'</td><td width="80%" style="font-size: 15px">'+data[i].fecha+'</td><td width="30%"><label> &nbsp;</label></td><td width="40%"  style="font-size: 15px">'+data[i].monto+'</td></tr>';
                  }
                  else{
                    html2 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+'</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="5%" class="row"><label>'+data[i].tcd+'</label></td><td width="9%" class="row"><label>'+data[i].monto+'</label></td><td width="8%" class="row"><label>&nbsp;</label></td></tr>';
                  
                     htmlIRD += '<tr><td width="40%" style="font-size: 15px">'+data[i].tipodoc+' - '+data[i].nroR+'</td><td width="80%" style="font-size: 15px">'+data[i].fecha+'</td><td width="30%"><label> &nbsp;</label></td><td width="40%"  style="font-size: 15px">'+data[i].monto+'</td></tr>';
                  }
                }
                listaSI = html1;
                listaDI = html2;

                listaSIR=htmlIR;
                listaDIR=htmlIRD;
                //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);

                $("#ISR").text(data[data.length-1].total_soles);
                $("#IDR").text(data[data.length-1].total_dolares);

                
                //$("#CS").text(data[data.length-1].util_soles);
                //$("#CD").text(data[data.length-1].util_dolares);
                bi=true;
                ajax_Egreso(html1,html2,htmlIR,htmlIRD);
                /*
                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,listaIsR,listaIdR){
            $.ajax({
              data:{'filtro':'f','F1':$('#fechad').text(),'F2':$('#fechah').text()},
              url:'/consultaEgreso_m_ajax/',
              type:'GET',
              dataType:'json',
              success: function(data){
                var html1 ="";
                var html2 ="";

                var htmlER="";
                var htmlERD="";

                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+' &#9658 </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>&nbsp;</label></td><td width="8%" class="row"><label>'+data[i].monto+'</label></td></tr>';

                     htmlER += '<tr><td width="40%" style="font-size: 15px">'+data[i].tipodoc+' - '+data[i].nroR+'</td><td width="80%" style="font-size: 15px">'+data[i].fecha+'</td><td width="30%"><label> &nbsp;</label></td><td width="40%"  style="font-size: 15px">'+data[i].monto+'</td></tr>';

                  }else{
                    html2 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+' &#9658 </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="5%" class="row"><label> '+data[i].tcd+'</label></td><td width="9%" class="row"><label>&nbsp;</label></td><td width="8%" class="row"><label>'+data[i].monto+'</label></td></tr>';
                    htmlERD += '<tr><td width="40%" style="font-size: 15px">'+data[i].tipodoc+' - '+data[i].nroR+'</td><td width="80%" style="font-size: 15px">'+data[i].fecha+'</td><td width="30%"><label> &nbsp;</label></td><td width="40%"  style="font-size: 15px">'+data[i].monto+'</td></tr>';
                  }
                }
                listaSE=html1;
                listaDE=html2;

                 listaSER=htmlER;
                listaDER=htmlERD;


                //$('#listaE').html(html);
                $("#ES").text(data[data.length-1].total_soles);
                $("#ED").text(data[data.length-1].total_dolares);

                $("#ESR").text(data[data.length-1].total_soles);
                $("#EDR").text(data[data.length-1].total_dolares);

                be=true;
                var aux1=listaIs+html1
                var aux2=listaId+html2
                $("#listaIES").html(aux1);
                $("#listaIED").html(aux2);

                $("#movISolesRecibo").html(listaIsR);
                $("#movESolesRecibo").html(htmlER);
                $("#movIDolaresRecibo").html(listaIdR);
                $("#movEDolaresRecibo").html(htmlERD);
                  //ajax_saldo_inicial();
                //calcular_Saldo();
              },
               error: function(xhr, textStatus, errorThrown) {
                    console.log(xhr.responseText);
              },
            });
          };
      //
    //
    function ajax_Ingreso_Material(){
        $.ajax({
          data:{'filtro':'f','F1':$('#fechad').text(),'F2':$('#fechah').text()},
          url:'/consultaIngreso_material_ajax/',
          type:'GET',
          dataType:'json',
          success: function(data){
            var html1 ="";
            bi=false;
            for(var i=0;i<data.length-1;i++){
                html1 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+'</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].monto+'</label></td><td width="8%" class="row"><label>&nbsp;</label></td></tr>';
              
            }
            listaMI=html1; 
            $("#IM").text(data[data.length-1].total_material); 
            ajax_Egreso_Material(html1);
            
          },
           error: function(xhr, textStatus, errorThrown) {
                console.log(xhr.responseText);
          },
        });
      };
      function ajax_Egreso_Material(listaIm){
        $.ajax({
          data:{'filtro':'f','F1':$('#fechad').text(),'F2':$('#fechah').text()},
          url:'/consultaEgreso_material_ajax/',
          type:'GET',
          dataType:'json',
          success: function(data){
            var html1 =""; 
            for(var i=0;i<data.length-1;i++){ 
              html1 += '<tr><td width="10%" class="row"><label> '+data[i].tipodoc+' - '+data[i].nroR+'</td><td width="40%" class="row"><label>'+data[i].concepto+'</label></td><td width="10%" class="row"><label>'+data[i].fecha+'</label></td></td><td width="9%" class="row"><label>&nbsp;</label></td><td width="8%" class="row"><label>'+data[i].monto+'</label></td></tr>';
             
            }
            listaME=html1; 
            //$('#listaE').html(html);
            $("#EM").text(data[data.length-1].total_material);
          
            var aux1=listaIm+html1 
            $("#listaIEM").html(aux1);
              //ajax_saldo_inicial();
            var saldomaterial= parseFloat($("#IM").text())-parseFloat($("#EM").text())+parseFloat($("#sim").text()); 
            $("#SM").text(saldomaterial.toString());
          },
           error: function(xhr, textStatus, errorThrown) {
                console.log(xhr.responseText);
          },
        });
      };
       function ajax_validar(){//falta
          $("#ExitoMensaje").prop('class','');
          $("#texto").text("");
          bi=false;
          be=false;
          $("#listaIES").html("");
          $("#listaIED").html("");
          ajax_Ingreso(); 
          ajax_Ingreso_Material()
          $("#CerrarC").show();
          $("#sdSistema").removeClass("hidden");
          $("#ssSistema").removeClass("hidden");
      };
    //
    function ajax_saldo(){
          $.ajax({
            url:'/SaldoCaja_ajax/',
            type:'GET',
            dataType:'json',
            success: function(data){
              var enc= data.p_nombre +' '+ data.p_ap+' '+data.p_am;
              $("#txtOperador").text(enc);
              $("#txtOperadorTicket").text("OPERADOR :"+enc);
              $("#txtOperadorTicketD").text("OPERADOR :"+enc);
            }
          });
        };
    //
    $("#imprimir").click(function(){
      $("#modalTipoRecibo").modal("show");
    })

    $("#imprimirTipo").click(function(){
      if($("#CtipoRecibo").val()=="ticket"){
        $("#fis").text("DESDE: "+$("#fechad").text());
        $("#ffs").text("HASTA: "+$("#fechah").text());
          

        $("#fid").text("DESDE: "+$("#fechad").text());
        $("#ffd").text("HASTA: "+$("#fechah").text());

        $("#platillaI").printThis();
        $("#platillaII").printThis();
      }else{
            imprimirSD();
      }
    })

  });
</script>
 
</html>
 
