{% load static %}
<!DOCTYPE html>
<html lang="es">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">
<head>
  <title> Cierre Caja Material</title> 
  <link href="{% static 'bootstrap/css/bootstrap-datetimepicker.css' %}" rel="stylesheet"/>
  <link href="{% static 'css/waitMe.css' %}" rel="stylesheet"/>
  <link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet"/> 
  <link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet"/>  

  <script src="{% static 'bootstrap/js/jquery.min.js' %}"></script>
  <script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
  <script src="{% static 'bootstrap/js/Moment.js' %}"></script>
  <script src="{% static 'bootstrap/js/bootstrap-datetimepicker.js' %}"></script>
  <script src="{% static 'js/jspdf.min.js' %}"></script>
  <script src="{% static 'js/jspdf.plugin.autotable.js' %}"></script>
  <script src="{% static 'js/FileSaver.min.js' %}"></script>
  <script src="{% static 'js/jquery.wordexport.js' %}"></script>
  <script src="{% static 'js/printThis.js' %}"></script>
 <script src="{% static 'js/apiLoad.js' %}"></script>
  <script src="{% static 'js/waitMe.min.js' %}"></script>
  <script src="{% static 'bootbox/js/bootbox.min.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;
      margin-left: 10px;
    }

    .waitMe_container .waitMe .waitMe_text {
        position: relative;
        margin: 20px 0 0;
        font-size: 25px;
    }
    /*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 id="bodyCierre" 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 btn-sm"  href="/" role="button"><i class="fa fa-mail-reply"></i> Atras</a> 
    <button type="button" class="btn btn-primary btn-sm" id="refresh"><i class="fa fa-refresh"></i> Actualizar</button>
  </div>
</div>
<div class="row">
  <div style="margin-left:40px">
    <div class="checkbox" id="campoChk">
      <label class="checkbox-inline" style="font-size: initial;"><input type="checkbox" id="cierrefecha" value="1"> Cierre entre Fechas</label>
    </div>
  </div>
</div>

<div class="row"  id="campoCierre">
  <div class="col-md-2" id="combob" style="margin-left:40px">
    <select class="form-control" id="comboFiltroF">
      <option value="h">Hoy</option>
      <option value="f">Fecha</option>
      <option value="ef">Entre Fechas</option>
    </select>
    <p></p>
  </div>
  <div class="col-md-2" style="margin-left:40px">
    <input type="text" class="form-control" id="txtfecha1">
    <p></p>
  </div>
  <div class="col-md-2">
    <input type="text" class="form-control" id="txtfecha2">
    <p></p>
  </div>
  <script type="text/javascript">
    $(document).ready(function (){
      $('#txtfecha1').datetimepicker({
        locale: 'es',
        format: 'YYYY-MM-DD'
      });
      $('#txtfecha2').datetimepicker({
        locale: 'es',
        format: 'YYYY-MM-DD'
      });
    });
  </script>
  <div class="col-md-1" >
    <button type="button" class="btn btn-primary " id="buscarF">Filtrar</button>
    <p></p>
  </div>
</div>
<br>
<div class="row" 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">{{ usu_n_c }}</strong></h5>
      </div>
      <div style="margin-left:25px">
        <h5>DESDE: <strong id="fechad" style="margin-right: 10px;"></strong>
            HASTA: <strong id="fechah"></strong></h5>
      </div>
  </div>
 
  <br>

   <table class="table hidden" id="headerSistema" >
        <thead>
          <tr> 
            <th style="text-align: left;"><h5><strong>SISTEMA INTEGRAL - COMPRA Y VENTA DE ORO</strong></h5></th>
          </tr>
          <tr> 
            <th style="text-align: left;"><h5>FECHA : <strong id="fechaOperacionT"></strong></h5></th>
          </tr>
          <tr>
            <th style="text-align: left;"><h5>BASE : <strong>{{ SITE_URL }}</strong></h5></th> 
            <th style="text-align: left;"><h5>OPERADOR : <strong id="txtOperadorT"></strong></h5></th>
            <th style="text-align: left;"><h5>DESDE : <strong id="fechadT"></strong></h5> <h5>HASTA : <strong id="fechahT"></strong></h5></th>
          </tr>
        </thead>
        <tbody id="listaTransf">
        </tbody>
    </table>

  
  <div class="imp" style="text-align:center">
    <h5><strong> MOVIMIENTOS VENTANILLA - CUADRE CAJA</strong></h5>
  </div>

  <table class="table table-hover hidden" id="headerMovimientos">
        <thead>
          <tr></tr>
          <tr >
            <th></th> 
            <th style="text-align: right;"><h5><strong>MOVIMIENTOS VENTANILLA DOLARES</strong></h5></th>
            <th style="text-align: left;"><h5><strong>CUADRE CAJA</strong></h5></th>
            <th></th> 
          </tr>
        </thead>
        <tbody id="listaTransf">
        </tbody>
    </table>
   
  <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"></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"></label>
              </td>
              <td width="8%" class="row">
                <label id="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"></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"></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">
              &nbsp;
            </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="9%" class="row" style="text-align:right">
              <label> SALDO TOTAL: </label>
            </td>
            <td width="8%" class="row">
              <label id="SD"></label>
            </td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>




  <div class="imp">
    <div >
       <table style="margin: 0 auto" id="headerSoles">
        <tr>
          <td width="48%">
            <strong id="titulo1MS">========================================================= DESCRIPCIÓN DE MOVIMIENTOS=============================================================== </strong>
          </td>
           
         <td width="25%">
            <strong id="titulo2MS"> ================================== 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"></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"></label>
            </td>
        </tr>
      </tfoot>  
      </table>
    </div>
  </div>
  <br>
  <table class="table table-hover hidden" id="footerSistema">
        <thead>
          <tr></tr>
          <tr >
            <th><h5>SALDO QUE APARECE EN EL SISTEMA : </h5> </th>
            <th style="text-align: left;"><strong id="ssSistemaT"></strong></th> 
            <th style="text-align: left;"><strong id="sdSistemaT"></strong></th>
          </tr>
           <tr >
            <th><h5>OBSERVACIONES <strong id="obseT"></strong></h5> </th> 
          </tr>
        </thead>
        <tbody id="listaTransf">
        </tbody>
    </table>
  <div align="center">
      <p>Saldo que aparece en el sistema | <label id="ssSistema" class="hidden">Soles: <span id="sis_S"></span></label> | <label id="sdSistema" class="hidden">Dolares: <span id="sis_D"></span>|<label id="smSistema" class="hidden">Gramos: <span id="sis_M"></span></label> |</p>
  </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"></textarea >
      <p id="texto_obse" style="width:300px" ></p>
    </div>
  </div>
  <div >
      <div align="center">
          <button type="button" class="btn btn-primary bc" id="CerrarC" data-toggle="modal" data-target="#myModal2">Cerrar Caja</button>

           <!--<button type="button" class="btn btn-danger" onclick="tablesToExcel(['headerSistema','headerMovimientos','headerDolares','IED','headerSoles','IES','footerSistema'], ['first', 'second'], 'myfile.xls')">Imprimir</button>-->

           <!--<button type="button" class="btn btn-primary bc" onclick="exportExcell();" id="excelC">Excel</button>-->
          <!--<button type="button" class="btn btn-danger" id="ImprimirC">Imprimir</button>-->
      </div>
      <br>
  </div>
</div>

<br>
<div id="myModal1" 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">ALERTA</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-default">
              <div class="panel-body">  
                <div class="row">
                  <div class="col-md-12">
                    <div class="alert alert-danger" role="alert" align="center" id="modaltitulo">
                      <br>
                      <br>
                      <h4 id="modalTexto">TU CAJA YA ESTA CERRADA</h4>
                      <br>
                      <br>
                    </div>
                  </div>
                </div>

              </div>
            </div> 
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Ok</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<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="cerraCaja" 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><!-- /.modal -->


<div id="myModal2" 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">ALERTA</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-12">
            <div class="panel panel-default">
              <div class="panel-heading" style="color: #fff;background-color: #c43e00;"><strong>CAJA MATERIAL</strong></div>
              <div class="panel-body">  
                <div class="row">
                  <div class="col-md-12">
                    <div  class="alert alert-info" role="alert" align="center" id="modaltitulo">
                      <h4> CERRAR CAJA? </h4>
                    </div>
                  </div>
                </div>
                <br>
                <div class="row">
                  <div class="col-md-3 col-md-offset-3">
                    <button type="button" class="btn btn-danger btn-block bc" data-dismiss="modal">NO</button>
                  </div>
                  <div class="col-md-3">
                     <button type="button" class="btn btn-primary btn-block bc" id="tipoReciboCerrar" data-toggle="modal" data-target="#modalTipoRecibo" data-dismiss="modal">SI</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>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary bc" data-dismiss="modal" >Cerrar</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<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:12px;">
            
            <table>
               <tr>
                <td nowrap></td>
                <td nowrap><h4><b>CIERRE MATERIAL</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><span id="fid"></span> </td>
                <td nowrap><span id="ffd"></span> </td>
                <td nowrap></td>
              </tr>
              <tr>
                <td nowrap>OPERADOR:  {{ nombre_usuario }}</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"></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: 5px">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>
              
          </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:12px;">
            
            <table>
               <tr>
                <td nowrap></td>
                <td nowrap><h4><b>CIERRE MATERIAL</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><span id="fis"></span> </td>
                <td nowrap><span id="ffs"></span> </td>
                <td nowrap></td>
              </tr>
              <tr>
                <td nowrap>OPERADOR:  {{ nombre_usuario }}</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"></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: 5px">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> 
          <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%" id="SSRecibo" style="font-size:15px"></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%" id="SDRecibo" style="font-size:15px"></td> 
            </tr>
          </table>

            <br></br>
          <table>
            <tr>
              <td>
                <div align="center">
                    <p>Saldo que aparece en el sistema | <label>Soles: <span id="sis_SRecibo"></span></label> | <label>Dolares: <span id="sis_DRecibo"></span></p>
                </div>
              </td>
            </tr>
          </table>

              
          </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 -->

</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' %}";

     function tablesToExcel(table, name, filename){
        $("#titulo1Material").text("MOVIMIENTOS MATERIAL");
        $("#titulo2Material").text("GRAMOS DE MATERIAL");

        $("#titulo1MD").text("DESCRIPCIÓN DE MOVIMIENTOS");
        $("#titulo2MD").text("DOLARES");

        $("#titulo1MS").text("DESCRIPCIÓN DE MOVIMIENTOS");
        $("#titulo2MS").text("SOLES");

        var uri = 'data:application/vnd.ms-excel;base64,'
        , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets>'
        , templateend = '</x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>'
        , body = '<body>'
        , tablevar = '<table>{table'
        , tablevarend = '}</table>'
        , bodyend = '</body></html>'
        , worksheet = '<x:ExcelWorksheet><x:Name>'
        , worksheetend = '</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>'
        , worksheetvar = '{worksheet'
        , worksheetvarend = '}'
        , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
        , format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
        , wstemplate = ''
        , tabletemplate = ''; 

        var tables = table;

        for (var i = 0; i < tables.length; ++i) {
            wstemplate += worksheet + worksheetvar + i + worksheetvarend + worksheetend;
            tabletemplate += tablevar + i + tablevarend;
        }

        var allTemplate = template + wstemplate + templateend;
        var allWorksheet = body + tabletemplate + bodyend;
        var allOfIt = allTemplate + allWorksheet;

        var ctx = {};
        for (var j = 0; j < tables.length; ++j) {
            ctx['worksheet' + j] = name[j];
        }

        for (var k = 0; k < tables.length; ++k) {
            var exceltable;
            if (!tables[k].nodeType) exceltable = document.getElementById(tables[k]);
            ctx['table' + k] = exceltable.innerHTML;
        }

        //document.getElementById("dlink").href = uri + base64(format(template, ctx));
        //document.getElementById("dlink").download = filename;
        //document.getElementById("dlink").click();

        window.location.href = uri + base64(format(allOfIt, ctx));
    }



     function exportExcell(){
           var doc = new jsPDF('p', 'pt'); 
          var resd= doc.autoTableHtmlToJson(document.getElementById("IED"));
          var ress= doc.autoTableHtmlToJson(document.getElementById("IES"));

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

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


          doc.text("MOVIMIENTOS DOLARES", 10, doc.autoTableEndPosY()+85);
          doc.autoTable(resd.columns, resd.data, {
              startY: 95,
              margin: {horizontal: 10},
              tableWidth: 'wrap',
              margin:{top:10},
              styles: {cellPadding: 2},
              headerStyles: {rowHeight: 14, fontSize: 12,valign: 'middle'},
              styles: {overflow: 'linebreak'},
              bodyStyles: {rowHeight: 16, fontSize: 12,fontStyle:'normal', valign: 'middle'}, 
              theme: 'plain',
              pageBreak: 'avoid',
          });

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

          doc.autoTable(ress.columns, ress.data, {
              startY: doc.autoTableEndPosY()+30,
              tableWidth: 'wrap',
              styles: {cellPadding: 2},
              margin: {horizontal: 10},
              margin:{top:10},
              headerStyles: {rowHeight: 14, fontSize: 12,valign: 'middle'},
              styles: {overflow: 'linebreak'},
              bodyStyles: {rowHeight: 16, fontSize: 12,fontStyle:'normal', valign: 'middle'}, 
              theme: 'plain',
              pageBreak: 'avoid',
          });

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

          doc.text("SALDO QUE APARECE EN EL SISTEMA SOLES : "+ $("#sis_S").text()+ " DOLARES : "+$("#sis_D").text(), 10, doc.autoTableEndPosY()+30);

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

          doc.save('reporteCierreCajaSD.pdf');  
    }

    $(document).ready(function(){
      var fecha = new Date();
      var mes = [
          "Enero",
          "Febrero",
          "Marzo",
          "Abril",
          "Mayo",
          "Junio",
          "Julio",
          "Agosto",
          "Septiembre",
          "Octubre",
          "Noviembre",
          "Diciembre"
          ];
      var textofecha= fecha.getDate() + " de " + mes[fecha.getMonth()] + " del " + fecha.getFullYear();
      var hora = new Date();
      var textohora = hora.getHours() + ":" + hora.getMinutes();
      $("#fechaOperacion").text(textofecha+" "+textohora);
      $("#fechaOperacionT").text(textofecha+" "+textohora);
      var aux='';
      ajax_validar();
      $("#txtfecha1").hide();
      $("#txtfecha2").hide();
      $("#imprime").prop('disabled',true);

      $("#comboFiltroF").change(function(){
        $("#fechad").text("");
        $("#fechah").text("");
        $("#fechadT").text("");
        $("#fechahT").text("");
        if($("#comboFiltroF").val()=="ef"){
          $("#txtfecha1").show();
          $("#txtfecha1").prop("value","");
          $("#txtfecha2").show();
          $("#txtfecha2").prop("value","");
          }
        if($("#comboFiltroF").val()=="f"){
          $("#txtfecha1").prop("value","");
          $("#txtfecha1").show();
          $("#txtfecha2").prop("value","");
          $("#txtfecha2").hide();
          }
        if($("#comboFiltroF").val()=="h"){
          $("#txtfecha1").prop("value","");
          $("#txtfecha1").hide();
          $("#txtfecha2").prop("value","");
          $("#txtfecha2").hide();
          }
      });
      
      $('#imprime').click(function() {
          imprimirSD();
      });

      $("#cerraCaja").click(function(){
        run_waitMe($('#bodyCierre'), 1, "pulse","Cerrando Caja. Espere un momento...");

        $("#texto_obse").text($("#obse").val());
        $("#obse").hide();
        cierreSolesDolares_ajax();
      })
     
      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='{{ usu_n_c }}';

          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, doc.autoTableEndPosY()+35);
          doc.text("OPERADOR: "+ operador, 10, doc.autoTableEndPosY()+50);
          doc.text("FECHA DESDE : "+$("#fechad").text(), 10, doc.autoTableEndPosY()+65);
          doc.text("FECHA HASTA : "+$("#fechah").text(), 140, doc.autoTableEndPosY()+65);
          
          doc.setFontSize(8);
          doc.setFontStyle('bold');

          doc.text("MOVIMIENTOS MATERIAL (GRAMOS)", 10, doc.autoTableEndPosY()+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',
          });

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

          doc.text("MOVIMIENTOS SOLES", 10, doc.autoTableEndPosY()+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',
          });

          doc.text("Saldo que aparece en el sistema SOLES : "+ $("#sis_S").text()+ " DOLARES : "+$("#sis_D").text()+ " GRAMOS : "+$("#sis_M").text(), 10, doc.autoTableEndPosY()+30);

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

          doc.save('reporteCierreCajaMaterial.pdf'); 
            
           
      }



      /*$("#ImprimirC").click(function(){
        imprimir();
      });*/


      $("#cierrefecha").click(function(){
        if($("#cierrefecha").prop('checked')){
          $("#campoCierre").show();
          //$("#imprime").hide();
        }
        else{
          $("#campoCierre").hide();
        }
      });
      
      $("#campoCierre").hide();
      //
      $("#buscarF").click(function(){
        $("#listaIES").html(" ");
        $("#listaIED").html(" ");
        if ($("#comboFiltroF").val()=='h' || $("#comboFiltroF").val()=='-1'){
           Date.prototype.yyyymmdd = function() {
              var yyyy = this.getFullYear().toString();
              var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
              var dd  = this.getDate().toString();
              return yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]); // padding
            };

            d = new Date();
          $("#fechad").text(d.yyyymmdd());
          $("#fechadT").text(d.yyyymmdd());
        }
        else{
          //var t=$('#txtfecha1').val() +"  al  "+$('#txtfecha2').val();
          $("#fechad").text($('#txtfecha1').val());
          $("#fechah").text($('#txtfecha2').val());
          $("#fechadT").text($('#txtfecha1').val());
          $("#fechahT").text($('#txtfecha2').val());
        }
        ajax_validar();
      });
      
      $("#refresh").click(function(){
        $("#listaIES").html(" ");
        $("#listaIED").html(" ");
        $("#listaIEM").html(" ");
        if ($("#comboFiltroF").val()=='h' || $("#comboFiltroF").val()=='-1'){
           Date.prototype.yyyymmdd = function() {
              var yyyy = this.getFullYear().toString();
              var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
              var dd  = this.getDate().toString();
              return yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]); // padding
            };

            d = new Date();
          $("#fechad").text(d.yyyymmdd());
          $("#fechadT").text(d.yyyymmdd());
        }
        else{ 
          $("#fechad").text($('#txtfecha1').val());
          $("#fechah").text($('#txtfecha2').val());

          $("#fechadT").text($('#txtfecha1').val());
          $("#fechahT").text($('#txtfecha2').val());
        }
        ajax_validar();
      })
      //
      function ajax_Ingreso(){
        $.ajax({
          data:{'filtro':$('#comboFiltroF').val(),'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>';
              }
            }

            //$("#movSolesRecibo").html(htmlIR);

            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':$('#comboFiltroF').val(),'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

            //var auxISR=listaIsR;//+htmlER;

            $("#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':$('#comboFiltroF').val(),'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':$('#comboFiltroF').val(),'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_saldo(){
        $.ajax({
          url:'/SaldoCaja_ajax/',
          //async:false,
          type:'GET',
          dataType:'json',
          success: function(data){
            $("#sis_S").text(data.saldo_soles_ma);
            $("#sis_D").text(data.saldo_dolares_ma);
            $("#sis_M").text(data.saldo_material);
            $("#ssSistemaT").text("SOLES : "+data.saldo_soles_ma);
            $("#sdSistemaT").text("DOLARES : "+data.saldo_dolares_ma);

            $("#sis_SRecibo").text("SOLES : "+data.saldo_soles_ma);
            $("#sis_DRecibo").text("DOLARES : "+data.saldo_dolares_ma);

          },
          error: function(xhr, textStatus, errorThrown) {
                console.log(xhr.responseText);
            },
        });
      };

      function ajax_saldo_inicial(){
        $.ajax({
          url:'/SaldoInicialCajaMaterial_ajax/',
          //async:false,
          type:'GET',
          dataType:'json',
          success: function(data){
           $('#sis').text(data[0].sis);
           $('#sisr').text(data[0].sis);
           $('#sidr').text(data[0].sid);
           $("#sid").text(data[0].sid);
           $('#sim').text(data[0].sim);
           calcular_Saldo();
          },
           error: function(xhr, textStatus, errorThrown) {
                console.log(xhr.responseText);
          },
        });
      };
      
      function cierreSolesDolares_ajax(){
        $.ajax({
          data:{'fd':$('#fechad').text(),'fh':$('#fechah').text(),'IS':$('#IS').text(),'ID':$('#ID').text(),'ES':$('#ES').text(),'ED':$('#ED').text(),'SS':$('#SS').text(),'SD':$('#SD').text(),'IM':$('#IM').text(),'EM':$('#EM').text(),'SM':$('#SM').text(),'obs':$('#obse').val(),'sistema_s':$("#sis_S").text(),'sistema_d':$("#sis_D").text(),'sistema_m':$("#sis_M").text()},
          url:'/cerrarCajaMaterial_ajax/',
          //async:false,
          type:'GET',
          dataType:'text',
          success: function(data){
            if(data=='exito'){
                //$("#ExitoMensaje").prop('class',"alert alert-success");
                //$("#texto").text("CAJA CERRADA!");  
                $('#bodyCierre').waitMe('hide');
                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();

                  setTimeout(function(){
                    window.location.href='/';
                   },4000);
                  //$("#modalreciboIES").modal("show");
                  //$("#modalreciboIED").modal("show");
                }else{
                  imprimirSD();
                   window.location.href='/';
                }
                //ajax_validar();
                //window.location.href='/';
            }
            else{
                $('#bodyCierre').waitMe('hide');
                bootbox.alert("La operación fallo. "+data);
            }

          },
           error: function(xhr, textStatus, errorThrown) {

                    console.log(xhr.responseText);
            },
        });
      };


      //
     
      function ajax_validar(){//falta
        $.ajax({
          data:{'F1':$('#txtfecha1').val(),'F2':$('#txtfecha2').val()},
          url:'/validarCierreMaterial/',
          //async:false,
          type:'GET',
          dataType:'text',
          success: function(data){
            if(data=='exito'){
              $("#ExitoMensaje").prop('class','');
              $("#texto").text("");
              bi=false;
              be=false;
                
                $("#listaIES").html("");
                $("#listaIED").html("");
                ajax_Ingreso(); 
                ajax_saldo();
                ajax_saldo_inicial();
                $("#listaIEM").html("");
                ajax_Ingreso_Material(); 
                $("#CerrarC").show();
                $("#smSistema").removeClass("hidden");
                $("#sdSistema").removeClass("hidden");
                $("#ssSistema").removeClass("hidden");
             
              //$("#detalle").show();
              if ($("#comboFiltroF").val()=='h' || $("#comboFiltroF").val()=='-1'){
                 Date.prototype.yyyymmdd = function() {
                    var yyyy = this.getFullYear().toString();
                    var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
                    var dd  = this.getDate().toString();
                    return yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]); // padding
                  };

                  d = new Date();
                $("#fechad").text(d.yyyymmdd());
                $("#fechadT").text(d.yyyymmdd());
              }
              else{
                $("#fechad").text($('#txtfecha1').val());
                $("#fechah").text($('#txtfecha2').val());

                $("#fechadT").text($('#txtfecha1').val());
            $("#fechahT").text($('#txtfecha2').val());
              }
             }
           else{
              $("#ExitoMensaje").prop('class','alert alert-danger');
              $("#texto").text("TU CAJA YA ESTA CERRADA!!");
              $("#CerrarC").hide();

              //$("#detalle").hide();
              //$("#myModal").modal('show');
             }
          },
          error: function(xhr, textStatus, errorThrown) {
            console.log(xhr.responseText);
          },
        });
      };
      //
      //
      function calcular_Saldo()
      {
        //alert($("#IS").html());
        var saldosoles= parseFloat($("#IS").text())-parseFloat($("#ES").text())+parseFloat($("#sis").text());
        var saldodolares= parseFloat($("#ID").text())-parseFloat($("#ED").text())+parseFloat($("#sid").text());
        $("#SS").text(saldosoles.toString());
        $("#SD").text(saldodolares.toString());

        $("#SSRecibo").text(saldosoles.toString());
        $("#SDRecibo").text(saldodolares.toString());
        //material
        
      }


      //
    });
  </script>
 
</html>
 
