
</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 cancelaciones where fecha=CURDATE() and usuario like '%".$usuario."%'") or die(mysql_error());
     
  ?>
<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> Cancelaciones de hoy</span><br>
     
        
      <hr>
      <a href="../drink/vender.php" class="btn btn-default mb-2" href="javascript:void(0)" ><i class="fa fa-undo"></i> VOLVER ATRAS</a>

 
        <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</th>
            <th>Hora</th>
            <th>Producto</th>
             <th>Monto</th>
            <th>Cajero</th>
            <th>Comentario</th>

           
          
          <tbody>
          <?php while($r=mysql_fetch_array($sql)){
            $id = $r["id"];
            ?>
            <tr>
              
               <td><?php echo $r["fecha"]?></td>
                <td><?php echo $r["hora"]?></td>
              <td><span class="text-primary"><?php echo @decimal($r["monto"])?></span></td>
              <td><?php echo $r["usuario"]?></td>
               <td><?php echo $r["comentario"]?></td>
              
             
           
             <td>
             
                            <a class="btn btn-default" id="<?php echo $id?>" onClick='imprimir(this.id)' href="#"> 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"
      }
});

function imprimir(id){

window.open("recibo_cancelacion.php?id="+id,'_blank', 'toolbar=no,scrollbars=no,resizable=no,top=500,left=500,width=300,height=850');
///window.location.reload()
}


      </script>

