<?php include 'sesion_user.php';?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Panel</title>



<style>

.caca {

    max-width: 200px;

	max-height:200px;

}</style>



  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">


</head>



<body onload="document.forms['form14']['busqueda'].focus()">





<div class="container-fluid">



<div class="row">



  <div class="col-lg-3 col-md-3 col-sm-12" style="background-color: #dfdfdf;">





<?php

include 'nav.php';?>

<label>



</label>

</div>



<div class="col-lg-9 col-md-9 col-sm-12">







<?

include 'concha.php';



mysql_connect("$host","$usuario","$contra");



mysql_select_db ("$basedatos");









$sql = "SELECT * FROM `caja_cigarrillos` ORDER BY ID desc LIMIT 1";



$consulta = mysql_query ($sql);



while ($row = mysql_fetch_array($consulta))



{

$total_caja_cigarrillo  = $row["total_caja"];





}



mysql_free_result($consulta);











$sql = "SELECT * FROM `ID_ventas` LIMIT 1";









$consulta = mysql_query ($sql);



while ($row = mysql_fetch_array($consulta))



{





$ID_venta = $row["ID"];



}



mysql_free_result($consulta);








$A = date(Y);

$M = date(m);

$D = date(d);

$HORA = date(H);

$MIN = date(i);







$fecha = "$A$M$D$HORA$MIN";







mysql_db_query("$basedatos","





INSERT INTO `ventas` (`ID`, `fecha`, `hora`, `total`, `usuario`, `forma_pago`) VALUES ('$ID_venta', '$fecha', '0', '', '$user_con', '');



");




mysql_db_query("$basedatos","





INSERT INTO `ventas_costo` (`ID`, `fecha`, `hora`, `total`, `total_costo`, `usuario`, `forma_pago`) VALUES ('$ID_venta', '$fecha', '0', '',  '', '$user_con', '');



");







?>





<h2>VENTA Nº <?php echo $ID_venta ?></h2><hr />



<H3>DETALLE DE LA COMPRA:</H3> <HR>



<?

$total = 0;

mysql_connect("$host","$usuario","$contra");



mysql_select_db ("$basedatos");



$ID_mesa = (int)$_GET['ID'];

$sql = "SELECT * FROM `mesas_temp` WHERE `ID_mesa` = '$ID_mesa'";




$consulta = mysql_query ($sql);



while ($row = mysql_fetch_array($consulta))



{



$barcode = $row["barcode"];

$cantidad = $row["cant"];

$ID_mesa = $row["ID_mesa"];





$sql22 = "SELECT * FROM `articulos` WHERE `barcode` = '$barcode' LIMIT 1";



$consulta22 = mysql_query ($sql22);



while ($row22 = mysql_fetch_array($consulta22))



{



$ID_producto = $row22["ID"];

$titulo = $row22["titulo"];

$foto = $row22["foto"];

$precio = $row22["precio"];

$stock = $row22["stock"];

$barcode = $row22["barcode"];
$precio_costo = $row22["precio_costo"];

$cat = $row22["cat"];

$limite  = $row22["limite"];

$total_c  = $precio * $cantidad;

$stock_ahora = $stock - $cantidad;

}



mysql_free_result($consulta22);


$sSQL="INSERT INTO `movimientos` (`ID`, `ID_venta`, `ID_articulo`, `precio`, `cantidad`, `detalle`) VALUES (NULL, '$ID_venta', '$ID_producto', '$precio', '$cantidad', 'mesa $ID_mesa');";

mysql_db_query("$basedatos",$sSQL);



if ($cat == 'CIGARRILLOS') {



$total_caja_cigarrillo = $total_caja_cigarrillo + $total_c;

$sSQL="INSERT INTO `caja_cigarrillos` (`ID`, `detalle`, `monto`, `total_caja`, `fecha`) VALUES (NULL, '$titulo', '$precio', '$total_caja_cigarrillo', CURRENT_TIMESTAMP);";

mysql_db_query("$basedatos",$sSQL);



};






$precio = $precio * $cantidad;

$precio_costo = $precio_costo * $cantidad;

$total = $total + $precio;

$total_costo = $total_costo + $precio_costo;


?>

<b><?php  if ($detalle == '') {echo $titulo; } else { echo $detalle; }; ?> </b> |  x<?php echo $cantidad ?> | <B>$ <?php echo $precio ?></B>  <hr />

<?



$sSQL="UPDATE `articulos` SET `stock` = '$stock_ahora' WHERE `articulos`.`ID` = '$ID_producto' LIMIT 1;";

mysql_db_query("$basedatos",$sSQL);


$DDD = date("d"); 
$MMM = date("m"); 
$AAA = date("Y"); 

$texto = "<B>ALARMA DE STOCK</B>: QUEDAN $stock_ahora UNIDADES DE <B>$titulo</B> / $barcode <hr> $DDD / $MMM / $AAA ";



if ($limite == 0) {} else {



if ($limite == $stock_ahora) { $sSQL="INSERT INTO `avisos` (`ID`, `aviso`) VALUES (NULL, '$texto');";

mysql_db_query("$basedatos",$sSQL);



}; };



?><?



}



mysql_free_result($consulta);


//sumo uno al ID de ventas
$masuno = $ID_venta + 1;





////meto en la caja de ventas
$sSQL="UPDATE `ventas` SET `total` = '$total' WHERE `ventas`.`ID` = '$ID_venta';";

mysql_db_query("$basedatos",$sSQL);


////meto en la caja de ventas_costo si el costos
$sSQL="UPDATE `ventas_costo` SET `total_costo` = '$total_costo' WHERE `ventas_costo`.`ID` = '$ID_venta';";

mysql_db_query("$basedatos",$sSQL);
////y el total comun con el costo
$sSQL="UPDATE `ventas_costo` SET `total` = '$total' WHERE `ventas_costo`.`ID` = '$ID_venta';";

mysql_db_query("$basedatos",$sSQL);




$total_caja_new = $total_caja + $total;



$sSQL="INSERT INTO `caja` (`ID`, `detalle`, `monto`, `total_caja`, `fecha`) VALUES (NULL, 'Venta nº $ID_venta', '$total', '$total_caja_new', CURRENT_TIMESTAMP);

";

mysql_db_query("$basedatos",$sSQL);





$total_caja_new = $total_caja + $total;



$sSQL="INSERT INTO `caja_costo` (`ID`, `detalle`, `monto`, `monto_costo`, `total_caja`, `fecha`) VALUES (NULL, 'Venta nº $ID_venta', '$total',  '$total_costo', '$total_caja_new', CURRENT_TIMESTAMP);

";
mysql_db_query("$basedatos",$sSQL);













$sSQL="DELETE FROM `mesas_temp` WHERE `ID_mesa` = '$ID_mesa'";

mysql_db_query("$basedatos",$sSQL);

$sSQL="UPDATE `mesas` SET `atendida` = '' WHERE `mesas`.`ID` =  '$ID_mesa' LIMIT 1";

mysql_db_query("$basedatos",$sSQL);

?>





<h1 style="color:red"> Total: $ <b><?php echo $total ?></b></h1>









<hr>
<div >
<form id="form1" name="form1" method="post" action="vuelto.php">



<input name="total" type="hidden" value="<?php echo $total ?>" />

¿CON CUANTO PAGO?

$

<input name="cuanto_pago" type="text" id="cuanto_pago" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" size="10" maxlength="10" >



<label> <br />

<input type="submit" name="button" id="button" value="CALCULAR VUELTO" />

</label>

</form>


</div>

<hr>


<div>
<form id="form1" name="form1" method="post" action="hacer_descuento.php">


  <input type="hidden" value="<? echo $ID_venta ?>" name="ID_venta">


<input name="total" type="hidden" value="<?php echo $total ?>" />

HACER UN DESCUENTO SOBRE EL TOTAL.

<input name="descuento_portentaje" type="text" id="cuanto_pago" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" size="3" maxlength="3" placeholder="%" >



<label> <br />

<input type="submit" name="button" id="button" value="HACER UN DESCUENTO" />

</label>

</form>
<hr>

<br>
<p>TICKET DE COMPRA</p>
<P>PRESIONE <B>F2</B> PARA INICIAR UNA NUEVA VENTA O <B>F3</B> Y <b>ENTER</b> PARA IMPRIMIR EL TICKET.</P>
<HR>
<iframe id="printf" src="imprimir_ticket_barra_especial.php?ID=<? echo $ID_venta ?>" height="560px;"></iframe>


</div>
</hr>






<br />





<?php $p = $_GET['p']; ?>



VENTA FINALIZADA


<hr>

<p>IMPRIMIR FACTURA FISCAL (OPCIONAL)</p>

<a href="factura_fiscal.php?p=<?php echo $total ?>"><button>IMPRIMIR FACTURA FISCAL</button></a>

</div>

</div>



</div>











  <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>







  <script type="text/javascript">window.setInterval(function(){

  $('.grid').isotope({

  itemSelector: '.grid-item'

});

}, 2000);

</script>



<script language=javascript>

function ventanaSecundaria56 (URL){

   window.open(URL,"ventana1","width=960,height=630,scrollbars=NO")

}

  </script>

  
      <script language="javascript">
    function PulsarTecla(event)
    {
        tecla = event.keyCode;
     
        if(tecla==114)
        {
           document.getElementById("printf").contentWindow.print();
        }
        if(tecla==113)
        {
            location.href ='nueva_venta.php';
        }
        
        
        
    }
     
    window.onkeydown=PulsarTecla;
    </script>
</body>

</html>


<?
$sSQL="UPDATE `ID_ventas` SET `ID` = '$masuno' LIMIT 1;";

mysql_db_query("$basedatos",$sSQL);

?>