From 38d44f58a674ea9bb397852e2f0bbce4ea3dcd3f Mon Sep 17 00:00:00 2001 From: BryamE Date: Tue, 9 Dec 2025 18:21:07 -0300 Subject: [PATCH 1/3] Standarizando archivos --- app/Http/Controllers/CatalogoController.php | 4 ++-- app/Http/Controllers/SaleController.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/CatalogoController.php b/app/Http/Controllers/CatalogoController.php index e74a30a..f41ac4a 100644 --- a/app/Http/Controllers/CatalogoController.php +++ b/app/Http/Controllers/CatalogoController.php @@ -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')); } /** diff --git a/app/Http/Controllers/SaleController.php b/app/Http/Controllers/SaleController.php index aedf1ba..b954b1a 100644 --- a/app/Http/Controllers/SaleController.php +++ b/app/Http/Controllers/SaleController.php @@ -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(); } }); From 5d12ec10a32ceb78ae3940384aaf6eabe3b79f46 Mon Sep 17 00:00:00 2001 From: BryamE Date: Tue, 9 Dec 2025 19:44:20 -0300 Subject: [PATCH 2/3] Terminadas standarizaciones --- app/Http/Controllers/ProductosController.php | 18 +- app/Http/Controllers/SaleController.php | 4 +- app/Models/Product.php | 3 +- app/Models/Supplier.php | 7 +- app/View/Components/Alert2.php | 40 --- ...25_12_06_182356_create_suppliers_table.php | 4 +- ...2025_12_06_184833_create_clients_table.php | 30 --- ...12_06_201853_create_sale_details_table.php | 4 +- ...12_07_023045_create_appointments_table.php | 33 --- resources/views/productos/show.blade.php | 8 +- resources/views/sales/create.blade.php | 232 +++++++++--------- routes/web.php | 5 +- 12 files changed, 136 insertions(+), 252 deletions(-) delete mode 100644 app/View/Components/Alert2.php delete mode 100644 database/migrations/2025_12_06_184833_create_clients_table.php delete mode 100644 database/migrations/2025_12_07_023045_create_appointments_table.php diff --git a/app/Http/Controllers/ProductosController.php b/app/Http/Controllers/ProductosController.php index d288937..76fb067 100644 --- a/app/Http/Controllers/ProductosController.php +++ b/app/Http/Controllers/ProductosController.php @@ -73,28 +73,28 @@ class ProductosController extends Controller * Muestra el detalle de un producto. * Usamos Route Model Binding: Laravel busca el ID solo. */ - public function show(Product $producto) + public function show(Product $product) { - return view('productos.show', compact('producto')); + return view('productos.show', compact('product')); } /** * Muestra el formulario de edición. */ - public function edit(Product $producto) + public function edit(Product $product) { - return view('productos.edit', compact('producto')); + return view('productos.edit', compact('product')); } /** * Actualiza el producto existente. */ - public function update(Request $request, Product $producto) + public function update(Request $request, Product $product) { $validated = $request->validate([ 'name' => 'required|string|max:255', // Validamos que el SKU sea único PERO ignoramos el ID de este producto actual - 'sku' => ['nullable', 'string', Rule::unique('products')->ignore($producto->id)], + 'sku' => ['nullable', 'string', Rule::unique('products')->ignore($product->id)], 'description' => 'nullable|string', 'price' => 'required|numeric|min:0', 'cost' => 'nullable|numeric|min:0', @@ -104,7 +104,7 @@ class ProductosController extends Controller 'serial_number' => 'nullable|string|max:100', ]); - $producto->update($validated); + $product->update($validated); return redirect()->route('productos.index') ->with('success', 'Producto actualizado exitosamente.'); @@ -113,9 +113,9 @@ class ProductosController extends Controller /** * Elimina el producto. */ - public function destroy(Product $producto) + public function destroy(Product $product) { - $producto->delete(); + $product->delete(); return redirect()->route('productos.index') ->with('success', 'Producto eliminado.'); } diff --git a/app/Http/Controllers/SaleController.php b/app/Http/Controllers/SaleController.php index b954b1a..8e8a7f7 100644 --- a/app/Http/Controllers/SaleController.php +++ b/app/Http/Controllers/SaleController.php @@ -59,8 +59,8 @@ class SaleController extends Controller SaleDetail::create([ 'sale_id' => $sale->id, 'product_id' => $product->id, - 'cantidad' => $item['quantity'], - 'precio' => $product->price, + 'quantity' => $item['quantity'], + 'price' => $product->price, ]); $nuevoStock = $product->stock_quantity - $item['quantity']; $product->stock_quantity = $nuevoStock; diff --git a/app/Models/Product.php b/app/Models/Product.php index 25d29cf..f9ce056 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -13,13 +13,12 @@ class Product extends Model public function hasLowStock(): bool { - //cambiar return $this->stock_quantity <= $this->min_stock_alert; } public function supplier() { - return $this->belongsTo(Suppliers::class); + return $this->belongsTo(Supplier::class); } // Opción 1: Relación directa con los detalles (Renglones de ticket) diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 8acf047..c72f08a 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -6,11 +6,8 @@ use Illuminate\Database\Eloquent\Model; class Supplier extends Model { - protected $fillable = [ - 'nombre', - 'telefono', - 'email' - ]; + protected $fillable = [ 'name', 'phone', 'email' ]; + public function products() { return $this->hasMany(Product::class); diff --git a/app/View/Components/Alert2.php b/app/View/Components/Alert2.php deleted file mode 100644 index bf1d9bb..0000000 --- a/app/View/Components/Alert2.php +++ /dev/null @@ -1,40 +0,0 @@ -class = $class; - } - - //* Get the view / contents that represent the component. - public function render(): View|Closure|string - { - return view('components.alert2'); - } -} diff --git a/database/migrations/2025_12_06_182356_create_suppliers_table.php b/database/migrations/2025_12_06_182356_create_suppliers_table.php index c5e0c12..ed43605 100644 --- a/database/migrations/2025_12_06_182356_create_suppliers_table.php +++ b/database/migrations/2025_12_06_182356_create_suppliers_table.php @@ -13,8 +13,8 @@ return new class extends Migration { Schema::create('suppliers', function (Blueprint $table) { $table->id(); - $table->string('nombre'); - $table->string('telefono'); + $table->string('name'); + $table->string('phone'); $table->string('email'); $table->timestamps(); }); diff --git a/database/migrations/2025_12_06_184833_create_clients_table.php b/database/migrations/2025_12_06_184833_create_clients_table.php deleted file mode 100644 index 398e55b..0000000 --- a/database/migrations/2025_12_06_184833_create_clients_table.php +++ /dev/null @@ -1,30 +0,0 @@ -id(); - $table->string('nombre'); - $table->string('telefono'); - $table->string('email'); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('clients'); - } -}; diff --git a/database/migrations/2025_12_06_201853_create_sale_details_table.php b/database/migrations/2025_12_06_201853_create_sale_details_table.php index e357fa9..3e0818a 100644 --- a/database/migrations/2025_12_06_201853_create_sale_details_table.php +++ b/database/migrations/2025_12_06_201853_create_sale_details_table.php @@ -15,8 +15,8 @@ return new class extends Migration $table->id(); $table->foreignId('sale_id')->constrained()->onDelete('cascade'); $table->foreignId('product_id')->constrained(); - $table->integer('cantidad'); - $table->decimal('precio', 10, 2); + $table->integer('quantity'); + $table->decimal('price', 10, 2); $table->timestamps(); }); } diff --git a/database/migrations/2025_12_07_023045_create_appointments_table.php b/database/migrations/2025_12_07_023045_create_appointments_table.php deleted file mode 100644 index 3bac73b..0000000 --- a/database/migrations/2025_12_07_023045_create_appointments_table.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - $table->foreignId('client_id')->constrained(); - $table->datetime('fecha_programada'); - $table->string('modelo_bici')->nullable(); - $table->string('descripcion')->nullable(); - $table->string('estado')->default('pendiente'); - $table->string('notas')->nullable(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('appointments'); - } -}; diff --git a/resources/views/productos/show.blade.php b/resources/views/productos/show.blade.php index 71bb8b7..b74c74f 100644 --- a/resources/views/productos/show.blade.php +++ b/resources/views/productos/show.blade.php @@ -47,10 +47,4 @@ - - - {{-- componente alerta --}} - {{-- - Jose! - Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero, vel omnis - --}} \ No newline at end of file + \ No newline at end of file diff --git a/resources/views/sales/create.blade.php b/resources/views/sales/create.blade.php index fd20768..843616c 100644 --- a/resources/views/sales/create.blade.php +++ b/resources/views/sales/create.blade.php @@ -1,131 +1,128 @@ -@extends('layouts.app') - -@section('title', 'Nueva Venta') - -@section('main') -
-
- -
-
-

Nueva Venta en Mostrador

-
- - @if (session('success')) -
- ¡Éxito! {{ session('success') }} -
- @endif - - @if (session('error')) -
- Error: {{ session('error') }} -
- @endif + +
+
- @if ($errors->any()) -
-
    - @foreach ($errors->all() as $error) -
  • • {{ $error }}
  • - @endforeach -
+
+
+

Nueva Venta en Mostrador

- @endif - - - -
- @csrf - -
- -
- - - - + - + + @if (session('success')) +
+ ¡Éxito! {{ session('success') }}
-
- -
-
-
- - + + @foreach($clients as $client) + @endforeach -
- -
- - -
- -
- $0.00 -
- -
- + + + + +
-
- -
- -
- -
-
- Total a Pagar: $0.00 + +
+
+
+ + +
+ +
+ + +
+ +
+ $0.00 +
+ +
+ +
+
-
- -
-
- - -
- -
- - Cancelar - -
-
- + +
+
+ Total a Pagar: $0.00 +
+
+ +
+
+ + +
+ +
+ + Cancelar + + +
+
+ +
-
+ @push('scripts') -@endpush -@endsection \ No newline at end of file +@endpush \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index bd87c32..d243303 100644 --- a/routes/web.php +++ b/routes/web.php @@ -43,12 +43,13 @@ Route::middleware(['auth'])->group(function () { Route::resource('productos', ProductosController::class)->parameters([ 'productos' => 'producto' ]); + Route::resource('clients', ClientController::class); + Route::get('/checker', [ProductosController::class, 'checker'])->name('productos.checker'); Route::get('/productos/{id}', [ProductosController::class,'show'])->name('productos.show'); Route::get('/productos/{id}/edit', [ProductosController::class,'edit'])->name('productos.edit'); - Route::get('/checker', [ProductosController::class, 'checker'])->name('productos.checker'); + //Route::get('/sales', [SaleController::class, 'index'])->name('sales.index'); Route::get('/sales/create', [SaleController::class, 'create'])->name('sales.create'); - Route::resource('clients', ClientController::class); }); From 6e7fc2367faf05def52ffb9e1aa91eb25a16148d Mon Sep 17 00:00:00 2001 From: BryamE Date: Tue, 9 Dec 2025 19:54:15 -0300 Subject: [PATCH 3/3] finally.... --- resources/views/catalogo.blade.php | 4 ++-- resources/views/productos/edit.blade.php | 22 +++++++++++----------- resources/views/sales/create.blade.php | 2 +- routes/web.php | 5 +++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/resources/views/catalogo.blade.php b/resources/views/catalogo.blade.php index 3f718c4..3538fd1 100644 --- a/resources/views/catalogo.blade.php +++ b/resources/views/catalogo.blade.php @@ -2,9 +2,9 @@

CATÁLOGO

- @if ($productos->count() > 0) + @if ($products->count() > 0)
- @foreach ($productos as $prod) + @foreach ($products as $prod)
{{-- Imagen si existe --}} @if (!empty($prod->imagen)) diff --git a/resources/views/productos/edit.blade.php b/resources/views/productos/edit.blade.php index 5e7752f..fc58a00 100644 --- a/resources/views/productos/edit.blade.php +++ b/resources/views/productos/edit.blade.php @@ -1,44 +1,44 @@ Lauck - Editar - Editar - {{$producto->nombre}} + Editar - {{$product->nombre}}
-
+ @csrf @method('PUT')
- +
- +
- +
- +
- +
- +
- +
- precio}} name="precio" id="precio" class="block py-2.5 px-0 w-full text-sm text-gray-300 bg-transparent border-0 border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600 peer" step="0.01"/> + precio}} name="precio" id="precio" class="block py-2.5 px-0 w-full text-sm text-gray-300 bg-transparent border-0 border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600 peer" step="0.01"/>
@@ -46,7 +46,7 @@ - + Volver
diff --git a/resources/views/sales/create.blade.php b/resources/views/sales/create.blade.php index 843616c..26ec74a 100644 --- a/resources/views/sales/create.blade.php +++ b/resources/views/sales/create.blade.php @@ -110,7 +110,7 @@
- + Cancelar