Terminadas standarizaciones

This commit is contained in:
BryamE
2025-12-09 19:44:20 -03:00
parent 38d44f58a6
commit 5d12ec10a3
12 changed files with 136 additions and 252 deletions
+9 -9
View File
@@ -73,28 +73,28 @@ class ProductosController extends Controller
* Muestra el detalle de un producto. * Muestra el detalle de un producto.
* Usamos Route Model Binding: Laravel busca el ID solo. * 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. * 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. * Actualiza el producto existente.
*/ */
public function update(Request $request, Product $producto) public function update(Request $request, Product $product)
{ {
$validated = $request->validate([ $validated = $request->validate([
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
// Validamos que el SKU sea único PERO ignoramos el ID de este producto actual // 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', 'description' => 'nullable|string',
'price' => 'required|numeric|min:0', 'price' => 'required|numeric|min:0',
'cost' => 'nullable|numeric|min:0', 'cost' => 'nullable|numeric|min:0',
@@ -104,7 +104,7 @@ class ProductosController extends Controller
'serial_number' => 'nullable|string|max:100', 'serial_number' => 'nullable|string|max:100',
]); ]);
$producto->update($validated); $product->update($validated);
return redirect()->route('productos.index') return redirect()->route('productos.index')
->with('success', 'Producto actualizado exitosamente.'); ->with('success', 'Producto actualizado exitosamente.');
@@ -113,9 +113,9 @@ class ProductosController extends Controller
/** /**
* Elimina el producto. * Elimina el producto.
*/ */
public function destroy(Product $producto) public function destroy(Product $product)
{ {
$producto->delete(); $product->delete();
return redirect()->route('productos.index') return redirect()->route('productos.index')
->with('success', 'Producto eliminado.'); ->with('success', 'Producto eliminado.');
} }
+2 -2
View File
@@ -59,8 +59,8 @@ class SaleController extends Controller
SaleDetail::create([ SaleDetail::create([
'sale_id' => $sale->id, 'sale_id' => $sale->id,
'product_id' => $product->id, 'product_id' => $product->id,
'cantidad' => $item['quantity'], 'quantity' => $item['quantity'],
'precio' => $product->price, 'price' => $product->price,
]); ]);
$nuevoStock = $product->stock_quantity - $item['quantity']; $nuevoStock = $product->stock_quantity - $item['quantity'];
$product->stock_quantity = $nuevoStock; $product->stock_quantity = $nuevoStock;
+1 -2
View File
@@ -13,13 +13,12 @@ class Product extends Model
public function hasLowStock(): bool public function hasLowStock(): bool
{ {
//cambiar
return $this->stock_quantity <= $this->min_stock_alert; return $this->stock_quantity <= $this->min_stock_alert;
} }
public function supplier() 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) // Opción 1: Relación directa con los detalles (Renglones de ticket)
+2 -5
View File
@@ -6,11 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class Supplier extends Model class Supplier extends Model
{ {
protected $fillable = [ protected $fillable = [ 'name', 'phone', 'email' ];
'nombre',
'telefono',
'email'
];
public function products() public function products()
{ {
return $this->hasMany(Product::class); return $this->hasMany(Product::class);
-40
View File
@@ -1,40 +0,0 @@
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Alert2 extends Component
{
public $class;
//* Create a new component instance.
public function __construct($type = 'dark')
{
switch ($type) {
case 'info':
$class = 'text-blue-800 bg-blue-50 dark:text-blue-400';
break;
case 'danger':
$class = 'text-red-800 bg-red-50 dark:text-red-400';
break;
case 'success':
$class = 'text-green-800 bg-green-50 dark:text-green-400';
break;
case 'warning':
$class = 'text-yellow-800 bg-yellow-50 dark:text-yellow-300';
break;
default:
$class = 'text-gray-800 bg-gray-50 dark:text-gray-300';
break;
}
$this->class = $class;
}
//* Get the view / contents that represent the component.
public function render(): View|Closure|string
{
return view('components.alert2');
}
}
@@ -13,8 +13,8 @@ return new class extends Migration
{ {
Schema::create('suppliers', function (Blueprint $table) { Schema::create('suppliers', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nombre'); $table->string('name');
$table->string('telefono'); $table->string('phone');
$table->string('email'); $table->string('email');
$table->timestamps(); $table->timestamps();
}); });
@@ -1,30 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('clients', function (Blueprint $table) {
$table->id();
$table->string('nombre');
$table->string('telefono');
$table->string('email');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('clients');
}
};
@@ -15,8 +15,8 @@ return new class extends Migration
$table->id(); $table->id();
$table->foreignId('sale_id')->constrained()->onDelete('cascade'); $table->foreignId('sale_id')->constrained()->onDelete('cascade');
$table->foreignId('product_id')->constrained(); $table->foreignId('product_id')->constrained();
$table->integer('cantidad'); $table->integer('quantity');
$table->decimal('precio', 10, 2); $table->decimal('price', 10, 2);
$table->timestamps(); $table->timestamps();
}); });
} }
@@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('appointments', function (Blueprint $table) {
$table->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');
}
};
-6
View File
@@ -48,9 +48,3 @@
</div> </div>
</x-layout> </x-layout>
{{-- componente alerta --}}
{{-- <x-alert type="success">
<x-slot name="title">Jose!</x-slot>
<x-slot name="content">Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero, vel omnis</x-slot>
</x-alert> --}}
+6 -10
View File
@@ -1,8 +1,4 @@
@extends('layouts.app') <x-layout>
@section('title', 'Nueva Venta')
@section('main')
<div class="py-12 bg-gray-100 min-h-screen"> <div class="py-12 bg-gray-100 min-h-screen">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8"> <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
@@ -44,7 +40,7 @@
<select name="client_id" class="select2-enable w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border"> <select name="client_id" class="select2-enable w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border">
<option value="">-- Consumidor Final (Anónimo) --</option> <option value="">-- Consumidor Final (Anónimo) --</option>
@foreach($clients as $client) @foreach($clients as $client)
<option value="{{ $client->id }}">{{ $client->nombre }} ({{ $client->telefono }})</option> <option value="{{ $client->id }}">{{ $client->name }} ({{ $client->phone }})</option>
@endforeach @endforeach
</select> </select>
@@ -61,8 +57,8 @@
<select name="items[0][product_id]" class="product-select select2-enable w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border" required onchange="calcularTotal()"> <select name="items[0][product_id]" class="product-select select2-enable w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border" required onchange="calcularTotal()">
<option value="" data-price="0" selected disabled>Seleccione...</option> <option value="" data-price="0" selected disabled>Seleccione...</option>
@foreach($products as $product) @foreach($products as $product)
<option value="{{ $product->id }}" data-price="{{ $product->precio }}"> <option value="{{ $product->id }}" data-price="{{ $product->price }}">
{{ $product->codigo }} - {{ $product->nombre }} (${{ $product->precio }}) {{ $product->sku }} - {{ $product->name }} (${{ $product->price }})
</option> </option>
@endforeach @endforeach
</select> </select>
@@ -114,7 +110,7 @@
</div> </div>
<div class="flex items-end gap-4 justify-end"> <div class="flex items-end gap-4 justify-end">
<a href="{{ url('/') }}" class="bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow"> <a href="{{ route('sales.index') }}" class="bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow">
Cancelar Cancelar
</a> </a>
<button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-6 rounded shadow-lg"> <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-6 rounded shadow-lg">
@@ -126,6 +122,7 @@
</div> </div>
</div> </div>
</div> </div>
</x-layout>
@push('scripts') @push('scripts')
<script> <script>
@@ -224,4 +221,3 @@
}); });
</script> </script>
@endpush @endpush
@endsection
+3 -2
View File
@@ -43,12 +43,13 @@ Route::middleware(['auth'])->group(function () {
Route::resource('productos', ProductosController::class)->parameters([ Route::resource('productos', ProductosController::class)->parameters([
'productos' => 'producto' '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}', [ProductosController::class,'show'])->name('productos.show');
Route::get('/productos/{id}/edit', [ProductosController::class,'edit'])->name('productos.edit'); 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', [SaleController::class, 'index'])->name('sales.index');
Route::get('/sales/create', [SaleController::class, 'create'])->name('sales.create'); Route::get('/sales/create', [SaleController::class, 'create'])->name('sales.create');
Route::resource('clients', ClientController::class);
}); });