/*include "..//index.php";*/
session_start();
//COMPRUEBA QUE EL USUARIO ESTA AUTENTIFICADO
if ($_SESSION["password"] != "alm") {
header("Location: ..//index.php");
exit();
}
if (isset($_SESSION["Local"]))
{
$MiDeposito = $_SESSION["Local"];
}
include "funcionesCaja.php";
echo "
";
$ActiveUser = $_SESSION['user'];
include "conexion.php";
$guardar = $_GET['guardar'];
echo '';
if ($guardar=="false")
{
echo"
Interfaz de Venta - Electronica Ituzaingo
VENTAS DEL DIA";
$Month = $_GET['month'];
$today = date("d-m-Y");
$currMonth = substr($today, 3, 7);
$file = $_SERVER['DOCUMENT_ROOT'] . "/Stock/Logs/Ventas/$currMonth/$today.txt";
/*$myfile = fopen($file, "r") or die("Unable to open file!");*/
//$pageText = fread($myfile, filesize($file));
//echo nl2br($pageText);
//fclose($myfile);
$myfile = file($file);
$myfile = array_reverse($myfile);
foreach($myfile as $f){
if (strpos($f, $MiDeposito))
{
echo $f." ";
}
}
echo "
|
";
}
elseif ($guardar=="true")
{
if (isset($_SESSION['Productos']))
{
$Productos = $_SESSION['Productos'];
$Pago = $_POST['pago'];
for ($Prods = 0; $Prods < count($Productos); $Prods++) {
$ID = $Productos[$Prods][0];
$Ubicacion = $Productos[$Prods][5];
$Tipo = $Productos[$Prods][6];
if ($Tipo == "Art")
{
$busqueda = "SELECT * FROM stock WHERE Articulo='$ID' AND Ubicacion='$Ubicacion'";
}
elseif ($Tipo == "Cod")
{
$busqueda = "SELECT * FROM stock WHERE Codigo=$ID AND Ubicacion='$Ubicacion'";
}
$queryResult = mysqli_query($conexion, $busqueda) or die("Error en: $busqueda: " . mysqli_error());
$row=mysqli_fetch_row($queryResult);
$Nombre = $row[1];
$CantidadActualPre = $row[2];
$today = date("d-m-Y");
$month = substr($today, 3, 7);
$Hora = Time();
date('H:i:s:u a',$Hora);
$Hora = Time() + (60 * 60);
$time = date('H:i:s a',$Hora);
$Precio = $row[5];
$Marca = $row[12];
$Modelo = $row[13];
$NombreVenta = $Nombre." ".$Marca." ".$Modelo;
$Cantidad = $Productos[$Prods][3];
if (strpos($Precio, "USD") === 0)
{
$Precio = trim(str_replace("USD", "", $Precio));
//$Cotizacion = obtenerCotizacion("Hoy");
$Precio = $Precio * $Cotizacion;
}
$ValorVenta = $Precio * $Cantidad;
$Operacion = $Productos[$Prods][4];
if ($Operacion == "venta")
{
$CantidadActual = $CantidadActualPre - $Cantidad;
$file = fopen($_SERVER['DOCUMENT_ROOT'] . "/Stock/Logs/Ventas/$month/$today.txt", "a");
$file2 = fopen($_SERVER['DOCUMENT_ROOT'] . "/Stock/Logs/Empleados/$ActiveUser.txt", "a");
$i = 0;
registrarVenta($NombreVenta, $Ubicacion, $ActiveUser, $ValorVenta, "UYU", $Cantidad, $Pago);
while ($i < (int)$Cantidad)
{
fwrite($file, "[$today - $time - $ActiveUser][NUEVA VENTA][$Ubicacion][$ID] $Cantidad Unidades -$Nombre - Cantidad Remanente: $CantidadActual - Precio - $Precio $Pago" . PHP_EOL);
fwrite($file2, "[$today - $time - $ActiveUser][NUEVA VENTA][$Ubicacion][$ID] $Cantidad Unidades -$Nombre - Cantidad Remanente: $CantidadActual - Precio - $Precio $Pago" . PHP_EOL);
$i++;
}
}
elseif ($Operacion == "reversionV")
{
$CantidadActual = $CantidadActualPre + $Cantidad;
$file = fopen($_SERVER['DOCUMENT_ROOT'] . "/Stock/Logs/Ventas/$month/$today.txt", "a");
$file2 = fopen($_SERVER['DOCUMENT_ROOT'] . "/Stock/Logs/Empleados/$ActiveUser.txt", "a");
$i = 0;
$CantidadRev = $Cantidad * -1;
$ValorVenta = $Precio * $Cantidad;
$ValorVentaRev = $ValorVenta * -1;
revertirVenta($NombreVenta, $Ubicacion, $ActiveUser, $ValorVentaRev, "UYU", $CantidadRev);
while ($i < (int)$Cantidad)
{
fwrite($file, "[$today - $time - $ActiveUser][VENTA REVERTIDA][$Ubicacion][$ID] $Cantidad Unidades -$Nombre - $Marca - $Modelo - Cantidad Remanente: $CantidadActual - Precio - $Precio" . PHP_EOL);
fwrite($file2, "[$today - $time - $ActiveUser][VENTA REVERTIDA][$Ubicacion][$ID] $Cantidad Unidades -$Nombre - $Marca - $Modelo - Cantidad Remanente: $CantidadActual - Precio - $Precio" . PHP_EOL);
$i++;
}
}
fclose($file);
fclose($file2);
if ($Tipo == "Art")
{
$result=mysqli_query($conexion, "UPDATE stock SET Cantidad='$CantidadActual' WHERE Articulo = '$ID' AND Ubicacion = '$Ubicacion'");
if ($INTEGRACIONACTIVA)
{
stockProductoW($ID, $CantidadActual);
}
}
elseif ($Tipo == "Cod")
{
$result=mysqli_query($conexion, "UPDATE stock SET Cantidad='$CantidadActual' WHERE Codigo = $ID AND Ubicacion = '$Ubicacion'");
$IDS = convertirCodigoBarraAID($CODis);
if ($INTEGRACIONACTIVA)
{
stockProductoW($IDS, $CantidadActual);
}
}
unset($_SESSION['Productos']);
}
}
else
{
echo'';
echo '
';
}
echo '
';
}
elseif ($guardar=="cancelar")
{
unset($_SESSION['Productos']);
echo '
';
}
?>