
</style>

  <?php
	include_once("../header.php");
        include_once("../php/config.php");
		$usuario = $_COOKIE["usuario"];
		$nivel = $_COOKIE["nivel"];
		if($nivel=="Master"){
			$usuario = "";
		}
        $sql = mysql_query("select * from historico_cuadres where usuario like '%".$usuario."%' order by id2 desc") or die(mysql_error());
		$str_c = mysql_query("select * from cuadres where usuario='".$_COOKIE['usuario']."'") or die(mysql_error());
		$estado_caja = @mysql_result($str_c, 0, "estado");
	?>
<style>
  .form-control{
    font-size: 20px;
  }


b{
    font-size: 18px;
  }

  th{
    font-size:18px;
    text-align: left;
  }

    td{
    font-size:18px;
  }
</style>
<div class="container">
        
		<div class="row">
			<div class="col-md-12">
			    <span class="h2 text-success"><i class="fa fa-cubes"></i> Historial de cuadres</span><br>
       
          
		<hr>
        <a href="_nueva_venta.php" class="btn btn-default mb-2" href="javascript:void(0)" ><i class="fa fa-undo"></i> VOLVER ATRAS</a>
		
		<?php if($estado_caja=="Cerrada" OR $estado_caja==""){?>
		<a href="../drink/abrir_caja.php" class="btn btn-success mb-2" href="javascript:void(0)" ><i class="fa fa-upload"></i> NUEVA APERTURA</a>
		<?php }?>

        <script type="text/javascript">

        function cierre(){
          window.location.href="cierre.php?caja="+myCaja;
        }
          function modalTurno(){
            if(estadoCaja=="Abierto"){alert("Ya existe un turno abierto en esta caja!"); return;}
            $("#modalTurno").modal('show');
            setTimeout(function(){
            // $("#frm").trigger('reset'); 
            },500)
            
        }
        </script>
   
          <div class="panel-body">
            <div class="table-responsive border p-3">
          <table class="table  table-hover table-sm table-striped" data-page-length='8' style="width: 100%">
              
              <th>Fecha apert.</th>
              <th>Hora apert.</th>
               <th>Monto inicio</th>
              <th>Cajero</th>
               <th>Balance efectivo</th>

			  <th>Opciones</th>
            
            <tbody>
            <?php while($r=mysql_fetch_array($sql)){?>
              <tr>
                
                 <td><?php echo $r["fecha_inicio"]?></td>
                  <td><?php echo $r["hora_inicio"]?></td>
                <td><span class="text-primary"><?php echo @decimal($r["monto_inicio"])?></span></td>
                <td><?php echo $r["usuario"]?></td>
				 <td><?php echo $r["balance_efectivo"]?></td>
                
               
             
               <td>
			   
			   			   <a class="btn btn-default" href="../reportes/rptCierreTurno.php?id=<?php echo $r['id2']?>"><i class="fa fa-print"></i> Reimprimir</a></td>

			 </tr>
			<?php }?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    
        </div>
      </div>
      



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

          </div>

        

				
	<!---Modal Cliente-->
	<div class="modal fade" id="modalTurno" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-md" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h2 class="modal-title text-success" id="exampleModalLabel"><i class="fa  fa-edit"></i> Registro de Turnos</h2>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">
       
         
		      <form name="frm" action="" method="POST" id="frm">

			 

        <div class="row">
  				<label for="id" class="col-sm-3 col-form-label" >Id</label>
  				<div class="col-sm-3">
  				  <input autocomplete="off" type="text"  class="form-control  mb-2" id="id" value="" disabled>
  				</div>
			  </div>
			  
			   <div class="row">
          <label for="id" class="col-sm-3 col-form-label" >Caja</label>
          <div class="col-sm-9">
            <input autocomplete="off" type="text"  class="form-control mb-2 bold" id="txt-caja2" name="txt-caja2" value="" disabled>
          </div>
        </div>


			  
         <div class="row">
          <label for="monto" class="col-sm-3 col-form-label" ><b>Monto spertura</b></label>
          <div class="col-sm-9">
            <input autocomplete="off" type="number"  class="form-control mb-2" id="monto" name="monto" value="">
          </div>
        </div>

       
			  
		  </form>

          <div class="modal-footer">
            <button class="btn btn-success" type="button" onclick="grabar_turno()"><i class="fa fa-w fa-save"></i> Grabar</button>

                  <button class="btn btn-warning" type="button" onclick="borrar()" id="delete"><i class="fa fa-w fa-trash"></i> Borrar</button>

            <a class="btn btn-warning" data-dismiss="modal"> <i class="fa fa-w fa-home"></i> Salir</a>
          </div>
        </div>
      </div>
    </div>

        <?php
        include_once("../footer.php");

        function state($est) {

            if ($est == "1") {
                $b = "<span class='badge badge-success'>Activo</span>";
            } else {

                $b = "<span class='badge badge-danger'>Inactivo</span>";
            }

            return $b;
        }
        ?>
            
<script>
$("#delete").hide();
id_turno="";


function ver(id){
     window.open('../reportes/rptCierreTurno.php?id='+id,'_blank', 'toolbar=no,scrollbars=no,resizable=no,top=500,left=500,width=800,height=700');
        }
  
  function grabar_turno(){
     if(!confirm("Seguro(a) que desea abrir este turno?")){return;}                   
    
     var  caja= $("#txt-caja").val();
     var monto = $("#monto").val();
     
     if(caja=="" || monto==""){alert('Faltan datos'); return}
    var sql="";                            
        if(id_turno==""){
            sql="INSERT INTO apertura_caja set ";
            sql+="caja='"+myCaja+"'";
            sql+=", monto_apertura='"+monto+"'";
            sql+=", fecha_apertura=NOW()";
            sql+=", hora_apertura=NOW()"; 
            sql+=", usuario='"+myUser+"'";
            sql+=", estado='Abierto'";
            

        }else{
            sql="UPDATE apertura_caja set";
            sql+=" fecha_cierre=NOW()";
            sql+=", hora_cierre=NOW()";
            sql+=", contado='"+monto_cierre+"'";
            sql+=", balance='"+balance+"'"; 
            sql+=", diferencia='"+diferencia+"'";
            sql+=", estado='Cerrado'"; 
            
            
        }
        
    _enviar("../php/update.php",{"sql":sql})
    .done(function( data ){
      //var rs = JSON.parse(data);
      if(data=="1"){
       
        noti("success","Registro grabado con exito","Registro grabado");
        localStorage.setItem("estado_caja", "abierta");
        $("#delete").hide();
        dstry();
        id_turno="";
         $("#modalTurno").modal('hide');
        setTimeout(function(){window.location.reload()},2000)

      }else{
          alert(data);
          
      }
       
    })
}
  

 function borrar(){
  
     if(id_turno==""){msg('Seleccione un registro'); return}
     if(!confirm("Seguro(a) que desea eliminar este registro?")){return;}
    var sql="";                            
    sql="delete from Turnos where id='"+id_turno+"'";
        
    _enviar("../php/update.php",{"sql":sql})
    .done(function( data ){
      //var rs = JSON.parse(data);
      if(data=="1"){
        $("#modalcobrador").modal('hide');
        noti("success","Registro eliminado con exito","Registro grabado");
        $("#delete").hide();
        dstry();
        id_turno="";
        setTimeout(function(){window.location.reload()},1000)

      }else{
          msg(data);
          
      }
        $("#loading").modal('hide');
    })
}



$("#txt-caja2").val(myCaja);


function cierre_preview(){
	    	var param ="cierre="+cierre;
			  window.localtion.href='../reportes/rptCierreTurno.php?'+param;		
		
}

$("table").DataTable({
   "language": {
            "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json"
        }
});

 

 
        </script>

