session_start();
date_default_timezone_set('America/Montevideo');
$ActiveUser = $_SESSION['user'];
include "conexion.php";
$guardar = $_GET['guardar'];
if (isset($_SESSION['Productos']))
{
$Productos = $_SESSION['Productos'];
}
else
{
$Productos = array();
}
if (isset($_SESSION['Productos'])) {
echo "
";
$Total = 0;
for ($Prods = 0; $Prods < count($Productos); $Prods++) {
if ($Productos[$Prods][4] == "venta")
{
$Precio = $Productos[$Prods][2];
if (strpos($Precio, "USD") === 0)
{
$Cotizacion = $_SESSION["Cotizacion"];
$Precio = str_replace("USD", "", $Precio);
$Precio = $Precio * $Cotizacion;
}
echo " ".$Productos[$Prods][1]." x ".$Productos[$Prods][3].", Total: $".$Precio." [+]
";
$Total = $Total + ($Precio * $Productos[$Prods][3]);
}
elseif ($Productos[$Prods][4] == "reversionV")
{
echo $Productos[$Prods][1]." x ".$Productos[$Prods][3].", Total: $".$Precio." [-]
";
$Total = $Total - ($Precio * $Productos[$Prods][3]);
}
}
echo "
TOTAL A PAGAR: $ $Total
";
}
if ($guardar=="pre")
{
$CODis = $_POST['codBarras'];
$Cantidad = $_POST['cantidad'];
$Operacion = $_POST['operacion'];
$Prod = $_POST['ProdExist'];
$Ubicacion = $_SESSION['Local'];
if ($CODis)
{
$busqueda = "SELECT * FROM stock WHERE Codigo=$CODis AND Ubicacion='$Ubicacion'";
$ID = $CODis;
$Tipo = "Cod";
}
elseif ($Prod)
{
$busqueda = "SELECT * FROM stock WHERE Articulo='$Prod' AND Ubicacion='$Ubicacion'";
$ID = $Prod;
$Tipo = "Art";
}
$queryResult = mysqli_query($conexion, $busqueda) or die("Error en: $busqueda: " . mysqli_error());
$row=mysqli_fetch_row($queryResult);
if ($busqueda && $row)
{
$Nombre = $row[1];
$CantidadActualPre = $row[2];
$Precio = $row[5];
$Productos[] = array($ID, $Nombre, $Precio, $Cantidad, $Operacion, $Ubicacion, $Tipo);
$_SESSION['Productos'] = $Productos;
echo "";
}
else
{
echo'';
}
echo '';
}
?>