Empezando prototipo de "Registro de Ventas", usa la tabla productos para ayuda visual. Agregado componente select.
This commit is contained in:
@@ -13,4 +13,28 @@ class CatalogoController extends Controller
|
||||
$productos = Product::all();
|
||||
return view('catalogo', compact('productos'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Muestra los registros de ventas con buscador y paginación.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Recuperamos lo que el usuario escribió en el buscador (si escribió algo)
|
||||
$query = $request->input('search');
|
||||
// Recuperamos el filtro aplicado (si aplica)
|
||||
$filter = $request->input('filter');
|
||||
|
||||
// Construimos la consulta
|
||||
$sales = Product::query()
|
||||
->when($query, function ($q) use ($query) {
|
||||
// Si hay búsqueda, filtra por nombre o SKU
|
||||
return $q->where('name', 'like', "%{$query}%")
|
||||
->orWhere('sku', 'like', "%{$query}%");
|
||||
})
|
||||
->orderBy('stock_quantity', 'asc') // Ordenamos primero los que tienen poco stock (Alerta visual)
|
||||
->paginate(10) // Paginamos de a 10
|
||||
->withQueryString(); // Mantiene el filtro de búsqueda al cambiar de página
|
||||
|
||||
return view('sales', compact('sales'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,39 @@
|
||||
@props(['disabled' => false, 'options', 'error' => null])
|
||||
@props(['disabled' => false, 'error' => null, 'options' => [], 'placeholder' => 'Seleccionar...'])
|
||||
|
||||
<select {{ $disabled ? 'disabled' : ''}} {!! $attributes->merge(['class' => 'bg-neutral-800 border-neutral-700 text-white text-sm rounded-lg focus:ring-neon-lime focus:border-neon-lime block w-full p-2.5 placeholder-gray-500 transition-colors ' . ($error ? 'border-red-500 focus:border-red-500 focus:ring-red-500' : '')]) !!}>
|
||||
<option value="">Seleccione</option>
|
||||
@if ($options)
|
||||
@foreach ($options as $key => $op)
|
||||
<option value={{$key}}>{{$op}}</option>
|
||||
@endforeach
|
||||
<!-- Contenedor relativo para posicionar la flecha personalizada si quisiéramos (opcional) -->
|
||||
<div class="relative">
|
||||
<select {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => '
|
||||
appearance-none bg-transparent border-0 border-b-2 border-neutral-700 text-white text-sm
|
||||
py-2.5 px-0 w-full focus:outline-none focus:ring-0 focus:border-neon-lime peer cursor-pointer
|
||||
transition-colors' . ($error ? 'border-red-500 focus:border-red-500' : '')
|
||||
]) !!}>
|
||||
|
||||
@if($placeholder)
|
||||
<option value="" disabled selected class="bg-neutral-800 text-gray-500">{{ $placeholder }}</option>
|
||||
@endif
|
||||
|
||||
{{ $slot }}
|
||||
|
||||
</select>
|
||||
|
||||
<!-- Flecha personalizada (SVG) posicionada a la derecha -->
|
||||
<div class="absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none">
|
||||
<svg class="w-4 h-4 text-gray-500 peer-focus:text-neon-lime transition-colors" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<!-- Mensaje de error -->
|
||||
@if($error)
|
||||
<p class="mt-1 text-xs text-red-400">{{ $error }}</p>
|
||||
@endif
|
||||
</select>
|
||||
@if($error)
|
||||
<p class="mt-1 text-xs text-red-400">{{ $error }}</p>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
{{--
|
||||
NOTA DE ESTILO:
|
||||
- `appearance-none`: Quita el estilo feo por defecto del navegador.
|
||||
- `bg-transparent`: Fondo transparente para que se vea el color de fondo de tu web.
|
||||
- `border-b-2`: Borde solo abajo (estilo línea).
|
||||
- `focus:ring-0`: Quita el anillo azul de Chrome al hacer click.
|
||||
- `peer`: Permite que el icono de la flecha cambie de color cuando el select tiene foco.
|
||||
--}}
|
||||
@@ -36,10 +36,16 @@
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" class="block py-2 px-3 text-white hover:text-neon-lime md:hover:bg-transparent md:border-0 md:p-0 transition-colors">Taller</a>
|
||||
<a href="#"
|
||||
class="block py-2 px-3 md:p-0 transition-colors {{ request()->is('mantenimiento*') ? 'text-neon-lime border-b-2 border-neon-lime' : 'text-white hover:text-neon-lime' }}">
|
||||
Taller
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" class="block py-2 px-3 text-white hover:text-neon-lime md:hover:bg-transparent md:border-0 md:p-0 transition-colors">Ventas</a>
|
||||
<a href="{{ url('/sales') }}"
|
||||
class="block py-2 px-3 md:p-0 transition-colors {{ request()->is('sales*') ? 'text-neon-lime border-b-2 border-neon-lime' : 'text-white hover:text-neon-lime' }}">
|
||||
Ventas
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<h1 class="font-black text-4xl md:text-5xl text-white uppercase italic">
|
||||
{{ $title }}
|
||||
@if($highlight)
|
||||
<span class="text-transparent bg-clip-text bg-gradient-to-r from-white to-gray-500">{{ $highlight }}</span>
|
||||
<span class="text-transparent bg-clip-text bg-gradient-to-r from-white to-gray-500 pe-2">{{ $highlight }}</span>
|
||||
@endif
|
||||
</h1>
|
||||
</div>
|
||||
@@ -1,17 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
|
||||
<title>@yield('title','Lauck - Home')</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<header>Cabeza</header>
|
||||
|
||||
@yield('main')
|
||||
|
||||
<footer>Pies</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,91 @@
|
||||
<x-layout title="Nuevo Producto">
|
||||
|
||||
<x-section-header subtitle="Ventas" title="Registro de " :highlight="'ventas ' . ' '" />
|
||||
<!-- Mensajes de feedback -->
|
||||
<x-ui.alert />
|
||||
|
||||
<!-- Barra de Herramientas (Buscador + Botón Crear) -->
|
||||
<div class="w-full flex flex-col md:flex-row justify-between items-center gap-4 mb-6">
|
||||
|
||||
<!-- Buscador -->
|
||||
<form action="{{ url('sales') }}" method="GET" class="flex flex-row w-full max-w-3xl gap-4">
|
||||
<div class="relative w-2/3">
|
||||
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
|
||||
<svg class="w-4 h-4 text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20">
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<input type="text" name="search" value="{{ request('search') }}"
|
||||
class="block w-full p-3 ps-10 text-sm text-white border border-neutral-700 rounded-lg bg-neutral-800 focus:ring-neon-lime focus:border-neon-lime placeholder-gray-500"
|
||||
placeholder="Buscar por nombre, SKU o marca...">
|
||||
</div>
|
||||
<div class="w-1/3">
|
||||
<x-forms.select id="type" name="type" :error="$errors->first('type')" placeholder="Filtro...">
|
||||
<option value="bike" class="bg-neutral-800">Bicicleta</option>
|
||||
<option value="accessory" class="bg-neutral-800">Accesorio</option>
|
||||
<option value="service" class="bg-neutral-800">Servicio</option>
|
||||
</x-forms.select>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Botón Nuevo -->
|
||||
<a href="{{ route('productos.create') }}" class="w-full md:w-auto text-center px-5 py-3 text-sm font-bold text-neutral-900 bg-neon-lime rounded-lg hover:bg-[#b3e600] transition-colors uppercase tracking-wide">
|
||||
+ Registrar Venta
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Tabla de Productos -->
|
||||
<div class="relative overflow-x-auto shadow-md sm:rounded-lg border border-neutral-800 w-full">
|
||||
<table class="w-full text-sm text-left rtl:text-right text-gray-400">
|
||||
<thead class="text-xs text-gray-300 uppercase bg-neutral-800 border-b border-neutral-700">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3">ID Venta</th>
|
||||
<th scope="col" class="px-6 py-3">Descripcion</th>
|
||||
<th scope="col" class="px-6 py-3">Cant. Productos</th>
|
||||
<th scope="col" class="px-6 py-3 text-center">Total Venta</th>
|
||||
<th scope="col" class="px-6 py-3 text-right">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($sales as $product)
|
||||
<tr class="bg-neutral-900/50 border-b border-neutral-800 hover:bg-neutral-800 transition-colors group">
|
||||
<td class="px-6 py-4 font-medium text-white whitespace-nowrap">
|
||||
<div class="text-gray-500 font-mono">{{ $product->sku }}</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 font-medium text-white whitespace-nowrap">
|
||||
<div class="text-base font-bold">{{ $product->name }}</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 font-mono text-white">
|
||||
{{ $product->stock_quantity }}
|
||||
</td>
|
||||
<td class="px-6 py-4 font-mono text-white text-center">
|
||||
${{ number_format(($product->price * 2), 2) }}
|
||||
{{-- @if($product->type === 'service')
|
||||
<span class="text-gray-600">-</span>
|
||||
@elseif($product->stock_quantity <= $product->min_stock_alert)
|
||||
<x-ui.badge color="red">{{ $product->stock_quantity }}</x-ui.badge>
|
||||
@else
|
||||
<x-ui.badge color="green">{{ $product->stock_quantity }}</x-ui.badge>
|
||||
@endif --}}
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<a href="{{ route('productos.edit', $product) }}" class="font-medium text-blue-400 hover:underline mr-3">Editar</a>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="px-6 py-10 text-center text-gray-500">
|
||||
No se encontraron productos.
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Paginación -->
|
||||
<div class="mt-4 w-full">
|
||||
{{ $sales->links() }}
|
||||
</div>
|
||||
|
||||
</x-layout>
|
||||
@@ -43,6 +43,7 @@ Route::middleware(['auth'])->group(function () {
|
||||
]);
|
||||
Route::get('/productos',[ProductosController::class,'index'])->name('productos.index');
|
||||
Route::get('/checker', [ProductosController::class, 'checker'])->name('productos.checker');
|
||||
Route::get('/sales', [CatalogoController::class,'index'])->name('sales.index');
|
||||
});
|
||||
|
||||
Route::get('/catalogo', [CatalogoController::class,'catalogo'])->name('catalogo');
|
||||
|
||||
Reference in New Issue
Block a user