<?php
include_once "../header.php";
include_once("../php/config.php");
		      mysql_query("delete from ventas where total<=0") or die(mysql_error());

$sql = mysql_query("select * from ventas where estado='Abierta' and usuario='".$_GET['usuario']."' and  caja='".$_GET['caja']."' and total<=0") or die(mysql_error());
?>

  <style>
 td{
	 font-size:16px;
 }
 
  th{
	 font-size:18px;
 }
 
   .form-control{
	 font-size:18px;
 }
 </style>
 
<center>
    <h1>Crear una nueva venta?</h1>
</hr>
<button class="btn btn-success" id="btn-nuevo" onClick="nueva(); $('#btn-nuevo').prop('disabled', true)"> <b>CREAR NUEVA</b></button>
<button class="btn btn-danger" onClick="window.location.href='ventas_abiertas.php'"> <b>CANCELAR</b></button>

<br>
<div class="table-respdfonsive borddfer p-3"><br><br><br><br>
     <small>Ventas abiertas sin items agregados</small>
					 <table class="table table-striped table-hover table-sm" data-page-length='8' style="width: 80%">
						<thead1>
							<th>Folio</th>
							<th>Fecha</th>
              <th>Cliente</th>
              <th>Tcket</th>
              <th>Monto</th>
             
              <th>Editar</th>
						</thead>
						<tbody>
            <?php while($r=mysql_fetch_array($sql)){
              $folio = $r["id_venta"];
              $c++;
              $total+=$r["total"];
              $balance+=$r["balance"];
              $costo+=$r["costo"];
              
              ?>
							<tr>
				<td><a href='facturacion.php?id_venta=<?php echo $folio;?>'><?php echo $r["id_venta"]?></a></td>
                <td><a href='facturacion.php?id_venta=<?php echo $folio;?>'><span class="text-primary"><?php echo ($r["hora"])?></span></a></td>
								<td><a href='facturacion.php?id_venta=<?php echo $folio;?>'><?php echo $r["cliente"]?></a></td>

                  <td><a href='facturacion.php?id_venta=<?php echo $folio;?>'><i class="fa fa-users fa-lg"></i> <?php echo $r["ticket"]?></a></td>

                 <td><?php echo decimal($r["total"])?></td>
               
               
             
               <td><a class="" href="javascript:void(0)" onClick="reimprimir('<?php echo $folio?>')" ><i class="fa fa-edit"></i></a></td>
							</tr>
                                                        <?php }?>
						</tbody>
            <tfoot>
              <br>
              <th>
                Cant. ventas: <?php echo $c?>
              </th>
              <th class="text-success">
                Total: <?php echo decimal($total)?>
              </th>


              
            </tfoot>
					</table>
				</div>
</center>
<?php
include_once "../footer.php";
?>

<script>
nueva()

function nueva(){
    window.location.href="nueva_venta.php?caja="+myCaja+"&usuario="+myUser;
   }  

///checkVentas()
function checkVentas(){

            var _c = 0;
            var sql="select * from ventas  where estado='Abierta'"
            _enviar("../php/traer_datos.php",{"sql":sql})
            .done(function( data ){
              if(data=="null"){ nueva(); $('#btn-nuevo').prop('disabled', true);}
                    var rs = JSON.parse(data);
                    
                    for( var i in rs.data){
                        
                        _c++;
                        ////document.write(_c+" "+" Factura encontradas<br>");
                      }
                      if(_c>0){
                        ///document.write(i+" "+" Factura encontradas<br>");
                      }else{
                        
                        nueva(); $('#btn-nuevo').prop('disabled', true);
                      }
             })
        }
  


  

</script>