Standarizando archivos
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user