<?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>
  <script language=javascript>
function ventanaSecundaria56 (URL){
   window.open(URL,"ventana1","width=300,height=400,scrollbars=NO")
}
  </script>

<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"> 
<link href="http://radioshosting.com/css/delalora4new.css" rel="stylesheet">
<link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css"/>
<link rel="stylesheet" href="http://ejemplo.radiosnet.com.ar/css/font-awesome.min.css"/>

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


<?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 `ID_ventas` LIMIT 1";




$consulta = mysql_query ($sql);

while ($row = mysql_fetch_array($consulta))

{


$ID_venta = $row["ID"];

}

mysql_free_result($consulta);




$barcode = $_POST['barcode'];
$cantidad = $_POST['cantidad'];
$varios = $_POST['varios'];

$precio_varios = $_POST['precio_varios'];
include 'concha.php';

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

mysql_select_db ("$basedatos");


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




$consulta = mysql_query ($sql);

while ($row = mysql_fetch_array($consulta))

{

$ID_producto = $row["ID"];
$titulo = $row["titulo"];
$foto = $row["foto"];
$precio = $row["precio"];
$stock = $row["stock"];
$barcode = $row["barcode"];

}

mysql_free_result($consulta);




?>
<div class="row">
<div class="col-lg-6 col-sm-12 col-md-6">
<button type="button" class="btn btn-info">VENTA Nº <?php echo $ID_venta ?></button> </div>
<div class="col-lg-6 col-sm-12 col-md-6" align="right">
<a href="finalizar_venta.php"><button type="button" class="btn btn-danger">Finalizar Venta</button></a>
</div>

</div>
<hr /> 

<?

if($barcode == '' and $varios == '') {} else {


if ($varios == '') {

mysql_db_query("$basedatos","


INSERT INTO `movimientos` (`ID`, `ID_venta`, `ID_articulo`, `precio`, `cantidad`, `detalle`) VALUES (NULL, '$ID_venta', '$ID_producto', '$precio', '$cantidad', '$detalle');

"); } else { mysql_db_query("$basedatos","


INSERT INTO `movimientos` (`ID`, `ID_venta`, `ID_articulo`, `precio`, `cantidad`, `detalle`) VALUES (NULL, '$ID_venta', '0', '$precio_varios', '$cantidad', '$varios');

"); }; }; ?>



<?
$total = 0;
mysql_connect("$host","$usuario","$contra");

mysql_select_db ("$basedatos");


$sql = "SELECT * FROM `movimientos` WHERE `ID_venta` = '$ID_venta'";


$consulta = mysql_query ($sql);

while ($row = mysql_fetch_array($consulta))

{
$ID_mov = $row["ID"];
$ID_articulo = $row["ID_articulo"];
$precio = $row["precio"];
$cantidad = $row["cantidad"];
$detalle = $row["detalle"];


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

$consulta22 = mysql_query ($sql22);

while ($row22 = mysql_fetch_array($consulta22))

{
$ID_producto = $row22["ID"];
$titulo = $row22["titulo"];
$foto = $row22["foto"];
$stock = $row22["stock"];
$barcode = $row22["barcode"];

}

mysql_free_result($consulta22);

$precio = $precio * $cantidad;
$total = $total + $precio;

?><div class="row" style="background-color:#FFFFFF">
<div class="col-lg-6 col-sm-12 col-md-6">
<i class="fa fa-check"></i> <span ><?php if($ID_articulo == 0) { echo $detalle; } else { echo $titulo; }; ?> - (x <?php echo $cantidad ?>) <br />
<a href="borrar_producto_de_venta.php?ID=<?php echo $ID_mov ?>">(X)</a></span></div>
<div class="col-lg-6 col-sm-12 col-md-6" align="right">
<span style="color:#006600;"><b>$ <?php echo $precio ?> </b></span></div> 
 </div><hr>
<?



}

mysql_free_result($consulta);

?> <hr><div align="right"> <h2>Total:</h2> <h1><span style="color:#006600">$ <?php echo $total ?></span></h1></div> <? 

?>



<hr />


<div class="row">

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

<form action="agregar_productos.php" method="post">

CANTIDAD x <input name="cantidad" type="text" id="cantidad" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" value="1" size="2" maxlength="9" >
<br />

Lea el codigo de barras del producto con la lectora.<br />
<input autofocus name="barcode" type="text" /> 
<a href="javascript:ventanaSecundaria56('ref_envases.php')"><img src="envases.png" width="40" height="29" /></a><br />
<hr />
<input name="varios" type="text" placeholder="Productos Varios."/> / $ <input name="precio_varios" type="text" id="cantidad" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;" size="4" maxlength="9" placeholder="Precio">
<br /><br />


<input class="btn-info" type="submit" name="button" id="button" value="PROCESAR" />

</form>

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


<?

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

mysql_select_db ("$basedatos");


$sql = "SELECT * FROM `movimientos` WHERE `ID_venta` = '$ID_venta' ORDER BY ID desc LIMIT 1";


$consulta = mysql_query ($sql);

while ($row = mysql_fetch_array($consulta))

{

$ID_articulo = $row["ID_articulo"];
$precio = $row["precio"];
$cantidad = $row["cantidad"];
$detalle = $row["detalle"];


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

$consulta22 = mysql_query ($sql22);

while ($row22 = mysql_fetch_array($consulta22))

{
$ID_producto = $row22["ID"];
$titulo = $row22["titulo"];
$foto = $row22["foto"];
$stock = $row22["stock"];
$barcode = $row22["barcode"];

}

mysql_free_result($consulta22);

?>
<h2 style="background-color:#FFFFFF"><?php if($ID_articulo == 0) { echo $detalle; } else { echo $titulo; }; ?> - (x <?php echo $cantidad ?>)</h2>
<br />
 <h1 style="color: #FF3300;">$ <?php echo $precio ?></h1>
 <a href="finalizar_venta.php"><button type="button" class="btn btn-danger">Finalizar Venta</button></a>
 
<?



}

mysql_free_result($consulta);


?>

</div>

</div>


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


</body>
</html>
