Merge branch 'giane' of https://github.com/BryamE/ProyectoLauck into bryam

This commit is contained in:
BryamE
2025-12-09 18:21:32 -03:00
2 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ class CatalogoController extends Controller
public function catalogo()
{
$productos = Product::all();
return view('catalogo', compact('productos'));
$products = Product::all();
return view('catalogo', compact('products'));
}
/**
+9 -9
View File
@@ -15,9 +15,9 @@ class SaleController extends Controller
public function create()
{
// Buscamos productos que tengan stock mayor a 0 para mostrar en el selector
$products = Product::where('stock', '>', 0)->get();
$products = Product::where('stock_quantity', '>', 0)->get();
$clients = \App\Models\Client::orderBy('nombre')->get();
$clients = \App\Models\Client::orderBy('name')->get();
return view('sales.create', compact('products', 'clients'));
}
@@ -34,13 +34,13 @@ class SaleController extends Controller
try {
DB::transaction(function () use ($request) {
$totalVenta = 0;
$totalSale = 0;
foreach ($request->items as $item) {
$product = Product::find($item['product_id']);
$totalVenta += $product->precio * $item['quantity'];
$totalSale += $product->precio * $item['quantity'];
if ($product->stock < $item['quantity']) {
if ($product->stock_quantity < $item['quantity']) {
throw new \Exception("No hay suficiente stock de " . $product->nombre);
}
}
@@ -49,7 +49,7 @@ class SaleController extends Controller
$sale = Sale::create([
//'user_id' => auth()->id(), //empleado logueado
'client_id' => $request->client_id,
'total' => $totalVenta,
'total' => $totalSale,
'payment_method' => $request->payment_method,
]);
@@ -60,10 +60,10 @@ class SaleController extends Controller
'sale_id' => $sale->id,
'product_id' => $product->id,
'cantidad' => $item['quantity'],
'precio' => $product->precio,
'precio' => $product->price,
]);
$nuevoStock = $product->stock - $item['quantity'];
$product->stock = $nuevoStock;
$nuevoStock = $product->stock_quantity - $item['quantity'];
$product->stock_quantity = $nuevoStock;
$product->save();
}
});