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.
* 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.');
}
+2 -2
View File
@@ -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;
+1 -2
View File
@@ -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)
+2 -5
View File
@@ -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);
-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) {
$table->id();
$table->string('nombre');
$table->string('telefono');
$table->string('name');
$table->string('phone');
$table->string('email');
$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->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();
});
}
@@ -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>
</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> --}}
+112 -116
View File
@@ -1,131 +1,128 @@
@extends('layouts.app')
<x-layout>
<div class="py-12 bg-gray-100 min-h-screen">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
@section('title', 'Nueva Venta')
@section('main')
<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="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
<div class="mb-6 border-b pb-2">
<h2 class="text-2xl font-bold text-gray-800">Nueva Venta en Mostrador</h2>
</div>
@if (session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4">
<strong class="font-bold">¡Éxito!</strong> {{ session('success') }}
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
<div class="mb-6 border-b pb-2">
<h2 class="text-2xl font-bold text-gray-800">Nueva Venta en Mostrador</h2>
</div>
@endif
@if (session('error'))
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4">
<strong class="font-bold">Error:</strong> {{ session('error') }}
</div>
@endif
@if ($errors->any())
<div class="bg-red-50 text-red-600 p-4 mb-4 rounded border border-red-200">
<ul>
@foreach ($errors->all() as $error)
<li> {{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ route('sales.store') }}" method="POST" id="sale-form">
@csrf
<div class="mb-6 bg-gray-50 p-4 rounded-lg border border-gray-200">
<label class="block text-sm font-medium text-gray-700 mb-1">Cliente</label>
<div class="flex gap-2">
<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>
@foreach($clients as $client)
<option value="{{ $client->id }}">{{ $client->nombre }} ({{ $client->telefono }})</option>
@endforeach
</select>
<a href="{{ route('clients.create') }}" target="_blank" class="bg-indigo-100 text-indigo-700 hover:bg-indigo-200 px-4 py-2 rounded-md font-bold flex items-center border border-indigo-200" title="Crear nuevo cliente">
+
</a>
@if (session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4">
<strong class="font-bold">¡Éxito!</strong> {{ session('success') }}
</div>
</div>
@endif
<div id="items-container" class="space-y-4">
<div class="item-row grid grid-cols-1 md:grid-cols-12 gap-4 items-end bg-gray-50 p-4 rounded-lg border border-gray-200">
<div class="md:col-span-6">
<label class="block text-sm font-medium text-gray-700 mb-1">Producto</label>
<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>
@foreach($products as $product)
<option value="{{ $product->id }}" data-price="{{ $product->precio }}">
{{ $product->codigo }} - {{ $product->nombre }} (${{ $product->precio }})
</option>
@if (session('error'))
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4">
<strong class="font-bold">Error:</strong> {{ session('error') }}
</div>
@endif
@if ($errors->any())
<div class="bg-red-50 text-red-600 p-4 mb-4 rounded border border-red-200">
<ul>
@foreach ($errors->all() as $error)
<li> {{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form action="{{ route('sales.store') }}" method="POST" id="sale-form">
@csrf
<div class="mb-6 bg-gray-50 p-4 rounded-lg border border-gray-200">
<label class="block text-sm font-medium text-gray-700 mb-1">Cliente</label>
<div class="flex gap-2">
<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>
@foreach($clients as $client)
<option value="{{ $client->id }}">{{ $client->name }} ({{ $client->phone }})</option>
@endforeach
</select>
<a href="{{ route('clients.create') }}" target="_blank" class="bg-indigo-100 text-indigo-700 hover:bg-indigo-200 px-4 py-2 rounded-md font-bold flex items-center border border-indigo-200" title="Crear nuevo cliente">
+
</a>
</div>
</div>
<div id="items-container" class="space-y-4">
<div class="item-row grid grid-cols-1 md:grid-cols-12 gap-4 items-end bg-gray-50 p-4 rounded-lg border border-gray-200">
<div class="md:col-span-6">
<label class="block text-sm font-medium text-gray-700 mb-1">Producto</label>
<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>
@foreach($products as $product)
<option value="{{ $product->id }}" data-price="{{ $product->price }}">
{{ $product->sku }} - {{ $product->name }} (${{ $product->price }})
</option>
@endforeach
</select>
</div>
<div class="md:col-span-3">
<label class="block text-sm font-medium text-gray-700 mb-1">Cantidad</label>
<input type="number" name="items[0][quantity]" value="1" min="1" class="quantity-input w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border" required oninput="calcularTotal()">
</div>
<div class="md:col-span-2 text-right font-mono text-gray-600 self-center pt-6">
$<span class="row-subtotal">0.00</span>
</div>
<div class="md:col-span-1 text-right">
<button type="button" class="text-gray-400 cursor-not-allowed" disabled>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 inline">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
</svg>
</button>
</div>
</div>
</div>
<div class="mt-4">
<button type="button" onclick="agregarFila()" class="flex items-center text-indigo-600 hover:text-indigo-800 font-semibold">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5 mr-1">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg>
Agregar otro producto
</button>
</div>
<div class="flex justify-end mt-6 border-t pt-4">
<div class="text-2xl font-bold text-gray-800">
Total a Pagar: <span class="text-indigo-600">$<span id="total-display">0.00</span></span>
</div>
</div>
<div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-6 items-center">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Método de Pago</label>
<select name="payment_method" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border">
<option value="Efectivo">Efectivo</option>
<option value="Tarjeta de Débito">Tarjeta de Débito</option>
<option value="Tarjeta de Crédito">Tarjeta de Crédito</option>
<option value="Transferencia">Transferencia</option>
</select>
</div>
<div class="md:col-span-3">
<label class="block text-sm font-medium text-gray-700 mb-1">Cantidad</label>
<input type="number" name="items[0][quantity]" value="1" min="1" class="quantity-input w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border" required oninput="calcularTotal()">
</div>
<div class="md:col-span-2 text-right font-mono text-gray-600 self-center pt-6">
$<span class="row-subtotal">0.00</span>
</div>
<div class="md:col-span-1 text-right">
<button type="button" class="text-gray-400 cursor-not-allowed" disabled>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 inline">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
</svg>
</button>
<div class="flex items-end gap-4 justify-end">
<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
</a>
<button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-6 rounded shadow-lg">
Confirmar Venta
</button>
</div>
</div>
</div>
<div class="mt-4">
<button type="button" onclick="agregarFila()" class="flex items-center text-indigo-600 hover:text-indigo-800 font-semibold">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5 mr-1">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
</svg>
Agregar otro producto
</button>
</div>
<div class="flex justify-end mt-6 border-t pt-4">
<div class="text-2xl font-bold text-gray-800">
Total a Pagar: <span class="text-indigo-600">$<span id="total-display">0.00</span></span>
</div>
</div>
<div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-6 items-center">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Método de Pago</label>
<select name="payment_method" class="w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 py-2 px-3 border">
<option value="Efectivo">Efectivo</option>
<option value="Tarjeta de Débito">Tarjeta de Débito</option>
<option value="Tarjeta de Crédito">Tarjeta de Crédito</option>
<option value="Transferencia">Transferencia</option>
</select>
</div>
<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">
Cancelar
</a>
<button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-6 rounded shadow-lg">
Confirmar Venta
</button>
</div>
</div>
</form>
</form>
</div>
</div>
</div>
</div>
</x-layout>
@push('scripts')
<script>
@@ -224,4 +221,3 @@
});
</script>
@endpush
@endsection
+3 -2
View File
@@ -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);
});