Merge branch 'giane' of https://github.com/BryamE/ProyectoLauck into nLucas
This commit is contained in:
@@ -9,22 +9,15 @@ use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ImportarExcelLimpio extends Command
|
||||
{
|
||||
// Este es el comando que vas a escribir en la terminal
|
||||
protected $signature = 'importar:excel';
|
||||
protected $description = 'Importa el catálogo limpio desde el archivo CSV';
|
||||
protected $description = 'Importa el catálogo desde CSV con asociación dinámica de proveedores';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->info("Iniciando importación del Excel limpio...");
|
||||
$this->info("Iniciando importación del Excel con lógica de proveedores...");
|
||||
|
||||
// 1. Asegurarnos de que existe el proveedor comodín (para evitar el error de la llave foránea)
|
||||
Supplier::firstOrCreate(
|
||||
['id' => 1],
|
||||
[
|
||||
'name' => 'Proveedor General Lauck',
|
||||
'phone' => '0000000000'
|
||||
]
|
||||
);
|
||||
// Aseguramos que existan al menos los 3 proveedores básicos por si acaso
|
||||
$this->asegurarProveedores();
|
||||
|
||||
$rutaCompleta = storage_path('app/imports/catalogo_limpio.csv');
|
||||
|
||||
@@ -32,45 +25,58 @@ class ImportarExcelLimpio extends Command
|
||||
$this->error("No se encontró el archivo en: " . $rutaCompleta);
|
||||
return;
|
||||
}
|
||||
$file = fopen($rutaCompleta, 'r');
|
||||
|
||||
// Saltamos la primera fila (porque son los títulos: tipo, descripcion, costo, precio)
|
||||
fgetcsv($file);
|
||||
$file = fopen($rutaCompleta, 'r');
|
||||
fgetcsv($file); // Saltar cabecera
|
||||
|
||||
$contador = 0;
|
||||
|
||||
while (($fila = fgetcsv($file, 1000, ',')) !== false) {
|
||||
|
||||
// Asignamos las columnas del Excel (0 a 3)
|
||||
$tipoRaw = strtolower(trim($fila[0] ?? ''));
|
||||
$descripcion = trim($fila[1] ?? '');
|
||||
$costoRaw = trim($fila[2] ?? '');
|
||||
$precioRaw = trim($fila[3] ?? '');
|
||||
// 1. Lectura de las 6 columnas
|
||||
$tipoRaw = strtolower(trim($fila[0] ?? ''));
|
||||
$nombreRaw = trim($fila[1] ?? '');
|
||||
$descripcionRaw = trim($fila[2] ?? '');
|
||||
$costoRaw = trim($fila[3] ?? '');
|
||||
$precioRaw = trim($fila[4] ?? '');
|
||||
$proveedorId = trim($fila[5] ?? 1); // ID del proveedor
|
||||
|
||||
// Si la descripción está vacía, saltamos la fila
|
||||
if (empty($descripcion)) {
|
||||
continue;
|
||||
}
|
||||
if (empty($nombreRaw)) continue;
|
||||
|
||||
// --- Lógica de limpieza de Tipos ---
|
||||
// Si en el Excel dice "bicicleta", lo guardamos como "bike" para mantener el estándar.
|
||||
$tipoFinal = ($tipoRaw === 'bicicleta') ? 'bike' : $tipoRaw;
|
||||
// 2. Limpieza de Nombre (Primera letra de cada palabra)
|
||||
$nombreSinEspacios = preg_replace('/\s+/', ' ', $nombreRaw);
|
||||
$nombreFinal = mb_convert_case($nombreSinEspacios, MB_CASE_TITLE, "UTF-8");
|
||||
|
||||
// --- Lógica de limpieza de Precios ("$ 7,200" -> 7200.0) ---
|
||||
// Borramos el signo peso, los espacios y las comas de los miles
|
||||
// 3. Traductor de Categorías (Evita errores SQL de truncado)
|
||||
$tipoRaw = preg_replace('/[\xEF\xBB\xBF]/', '', $tipoRaw); // Limpieza de BOM
|
||||
$mapeoTipos = [
|
||||
'bicicleta' => 'bike', 'bicicletas' => 'bike', 'bike' => 'bike',
|
||||
'indumentaria' => 'clothing', 'ropa' => 'clothing', 'clothing' => 'clothing',
|
||||
'accesorio' => 'accessory', 'accesorios' => 'accessory', 'accessory' => 'accessory',
|
||||
'repuesto' => 'spare', 'repuestos' => 'spare', 'spare' => 'spare',
|
||||
'infantil' => 'children', 'niños' => 'children', 'children' => 'children',
|
||||
'rollers' => 'rollers', 'roller' => 'rollers',
|
||||
'skate' => 'skate', 'skates' => 'skate',
|
||||
'servicio' => 'service', 'service' => 'service',
|
||||
'otro' => 'other', 'otros' => 'other', 'other' => 'other'
|
||||
];
|
||||
$tipoFinal = $mapeoTipos[$tipoRaw] ?? 'other';
|
||||
|
||||
// 4. Limpieza de Precios
|
||||
$costoLimpio = (float) str_replace(['$', ' ', ','], '', $costoRaw);
|
||||
$precioLimpio = (float) str_replace(['$', ' ', ','], '', $precioRaw);
|
||||
|
||||
// Guardamos en la base de datos
|
||||
// 5. Creación o Actualización
|
||||
Product::updateOrCreate(
|
||||
['name' => $descripcion], // Buscamos por descripción
|
||||
['name' => $nombreFinal],
|
||||
[
|
||||
'type' => $tipoFinal,
|
||||
'cost' => $costoLimpio,
|
||||
'price' => $precioLimpio,
|
||||
'stock_quantity' => 20, // Al ser lista de precios, entra con stock 0
|
||||
'description' => $descripcionRaw,
|
||||
'type' => $tipoFinal,
|
||||
'cost' => $costoLimpio,
|
||||
'price' => $precioLimpio,
|
||||
'suppliers_id' => $proveedorId, // Asociación dinámica
|
||||
'stock_quantity' => 20,
|
||||
'min_stock_alert' => 5,
|
||||
'suppliers_id' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
@@ -78,6 +84,25 @@ class ImportarExcelLimpio extends Command
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
$this->info("¡Éxito! Se importaron/actualizaron {$contador} productos.");
|
||||
$this->info("¡Éxito! Se procesaron {$contador} productos con sus respectivos proveedores.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea los proveedores básicos si no existen para evitar errores de integridad.
|
||||
*/
|
||||
private function asegurarProveedores()
|
||||
{
|
||||
$proveedores = [
|
||||
1 => 'Proveedor General Lauck',
|
||||
2 => 'Distribuidora Norte',
|
||||
3 => 'Repuestos Express'
|
||||
];
|
||||
|
||||
foreach ($proveedores as $id => $name) {
|
||||
Supplier::firstOrCreate(
|
||||
['id' => $id],
|
||||
['name' => $name, 'phone' => '0000000000']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,14 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\Supplier;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProductosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Muestra la lista de productos con buscador y paginación.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
/*public function index(Request $request)
|
||||
{
|
||||
$query = $request->input('search');
|
||||
$status = $request->input('stock_status');
|
||||
@@ -40,89 +38,79 @@ class ProductosController extends Controller
|
||||
->where('type', '!=', 'service');
|
||||
}
|
||||
})
|
||||
->orderBy('stock_quantity', 'asc') // Ordena primero los que tienen poco stock
|
||||
->paginate(10) // Muestra de a 10 productos
|
||||
->withQueryString(); // Mantiene los filtros al pasar a la página 2, 3, etc.
|
||||
->orderBy('stock_quantity', 'asc')
|
||||
->paginate(10)
|
||||
->withQueryString();
|
||||
|
||||
return view('productos.index', compact('products'));
|
||||
}*/
|
||||
public function index()
|
||||
{
|
||||
// Traemos todos los productos ordenados (sin paginar, para que JS los pueda buscar todos)
|
||||
$products = Product::orderBy('name', 'asc')->get();
|
||||
|
||||
return view('productos.index', compact('products'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Muestra el formulario de creación.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('productos.create');
|
||||
$suppliers = Supplier::orderBy('name')->get();
|
||||
return view('productos.create', compact('suppliers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Guarda el producto nuevo en la base de datos.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// 1. Validamos los datos con las nuevas columnas
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255', // CORREGIDO: description en lugar de name
|
||||
'name' => 'required|string|max:255',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'cost' => 'nullable|numeric|min:0',
|
||||
'stock_quantity' => 'required|integer|min:0',
|
||||
'min_stock_alert' => 'required|integer|min:0',
|
||||
'type' => 'required|in:bike,accessory,clothing,spare,service,children,skate,rollers,other',
|
||||
'serial_number' => 'nullable|string|max:100',
|
||||
'image' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048',
|
||||
'image' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048',
|
||||
'suppliers_id' => 'required|exists:suppliers,id',
|
||||
'description' => 'nullable|string'
|
||||
]);
|
||||
|
||||
// 2. Validacion de imagenes
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('products', 'public');
|
||||
$validated['image_path'] = $path;
|
||||
}
|
||||
unset($validated['image']);
|
||||
|
||||
// Para no romper la logica del supplier
|
||||
$validated['suppliers_id'] = 1;
|
||||
|
||||
// 3. Creamos el producto
|
||||
Product::create($validated);
|
||||
|
||||
// 4. Redireccionamos
|
||||
return redirect()->route('productos.index')
|
||||
->with('success', 'Producto creado correctamente.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Muestra el detalle de un producto.
|
||||
*/
|
||||
public function show(Product $product)
|
||||
{
|
||||
return view('productos.show', compact('product'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Muestra el formulario de edición.
|
||||
*/
|
||||
public function edit(Product $product)
|
||||
{
|
||||
return view('productos.edit', compact('product'));
|
||||
$suppliers = Supplier::orderBy('name')->get();
|
||||
return view('productos.edit', compact('product', 'suppliers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza el producto existente.
|
||||
*/
|
||||
public function update(Request $request, Product $product)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255', // CORREGIDO
|
||||
'type' => 'required|in:bike,accessory,clothing,spare,service,children,skate,rollers,other', // CORREGIDO
|
||||
'name' => 'required|string|max:255',
|
||||
'type' => 'required|in:bike,accessory,clothing,spare,service,children,skate,rollers,other',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'cost' => 'nullable|numeric|min:0',
|
||||
'stock_quantity' => 'required|integer|min:0',
|
||||
'min_stock_alert' => 'required|integer|min:0',
|
||||
'serial_number' => 'nullable|string|max:100',
|
||||
'image' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048',
|
||||
'suppliers_id' => 'required|exists:suppliers,id',
|
||||
'description' => 'nullable|string'
|
||||
]);
|
||||
|
||||
// 2. Manejo de imagen al actualizar
|
||||
if ($request->hasFile('image')) {
|
||||
if ($product->image_path) {
|
||||
Storage::disk('public')->delete($product->image_path);
|
||||
@@ -132,8 +120,6 @@ class ProductosController extends Controller
|
||||
$validated['image_path'] = $path;
|
||||
}
|
||||
unset($validated['image']);
|
||||
|
||||
$validated['suppliers_id'] = 1;
|
||||
|
||||
$product->update($validated);
|
||||
|
||||
@@ -141,9 +127,6 @@ class ProductosController extends Controller
|
||||
->with('success', 'Producto actualizado exitosamente.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina el producto.
|
||||
*/
|
||||
public function destroy(Product $product)
|
||||
{
|
||||
if ($product->image_path) {
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Supplier;
|
||||
class SupplierController extends Controller
|
||||
{
|
||||
/**
|
||||
* grilla de proveedores con buscador
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = $request->input('search');
|
||||
|
||||
$suppliers = Supplier::query()
|
||||
->when($query, function ($q) use ($query) {
|
||||
return $q->where('name', 'like', "%{$query}%");
|
||||
})
|
||||
->orderBy('name', 'asc')
|
||||
->paginate(10)
|
||||
->withQueryString();
|
||||
|
||||
return view('suppliers.index', compact('suppliers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* para crear un proveedor
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('suppliers.create');
|
||||
}
|
||||
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'phone' => 'nullable|string|max:50',
|
||||
'email' => 'nullable|email|max:255|unique:suppliers,email',
|
||||
'address' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
Supplier::create($validated);
|
||||
|
||||
return redirect()->route('suppliers.index')
|
||||
->with('success', 'Proveedor creado correctamente.');
|
||||
}
|
||||
|
||||
/**
|
||||
* muestra un proveedor
|
||||
*/
|
||||
public function show(Supplier $supplier)
|
||||
{
|
||||
return view('suppliers.show', compact('supplier'));
|
||||
}
|
||||
|
||||
public function edit(Supplier $supplier)
|
||||
{
|
||||
return view('suppliers.edit', compact('supplier'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Supplier $supplier)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'phone' => 'nullable|string|max:50',
|
||||
'email' => 'nullable|email|max:255|unique:suppliers,email,' . $supplier->id,
|
||||
'address' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$supplier->update($validated);
|
||||
|
||||
return redirect()->route('suppliers.index')
|
||||
->with('success', 'Proveedor actualizado correctamente.');
|
||||
}
|
||||
|
||||
/**
|
||||
* elimina (solo si no tiene productos asociados)
|
||||
*/
|
||||
public function destroy(Supplier $supplier)
|
||||
{
|
||||
try {
|
||||
$supplier->delete();
|
||||
return redirect()->route('suppliers.index')
|
||||
->with('success', 'Proveedor eliminado correctamente.');
|
||||
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
// Si el proveedor tiene productos asociados, va a tirar un error de llave foránea.
|
||||
return back()->with('error', 'No se puede eliminar el proveedor porque tiene productos registrados en el inventario.');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* trae todos los productos de un proveedor
|
||||
*/
|
||||
public function order(Supplier $supplier)
|
||||
{
|
||||
$products = $supplier->products()->orderBy('name')->get();
|
||||
|
||||
return view('suppliers.order', compact('supplier', 'products'));
|
||||
}
|
||||
}
|
||||
+12
-6
@@ -8,7 +8,18 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Product extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $guarded = [];
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'type',
|
||||
'cost',
|
||||
'price',
|
||||
'stock_quantity',
|
||||
'min_stock_alert',
|
||||
'serial_number',
|
||||
'image_path',
|
||||
'suppliers_id'
|
||||
];
|
||||
|
||||
|
||||
public function hasLowStock(): bool
|
||||
@@ -20,16 +31,11 @@ class Product extends Model
|
||||
{
|
||||
return $this->belongsTo(Supplier::class);
|
||||
}
|
||||
|
||||
// Opción 1: Relación directa con los detalles (Renglones de ticket)
|
||||
// Útil para saber cantidad total vendida: $product->saleDetails->sum('quantity')
|
||||
public function saleDetails()
|
||||
{
|
||||
return $this->hasMany(SaleDetail::class);
|
||||
}
|
||||
|
||||
// Opción 2 (Pro Tip): Relación directa con las Ventas a través de los detalles
|
||||
// Útil para saber EN QUÉ fechas se vendió: $product->sales
|
||||
public function sales()
|
||||
{
|
||||
return $this->belongsToMany(Sale::class, 'sale_details');
|
||||
|
||||
+10
-7
@@ -1,15 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Supplier extends Model
|
||||
{
|
||||
protected $fillable = [ 'name', 'phone'];
|
||||
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'phone',
|
||||
'email',
|
||||
];
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class);
|
||||
return $this->hasMany(Product::class, 'suppliers_id');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,20 +13,13 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('products', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->enum('type', ['bike', 'accessory', 'clothing', 'spare', 'children', 'skate', 'rollers','other']); // Tipo de producto
|
||||
//$table->string('name');
|
||||
//$table->string('sku')->unique()->nullable(); // Código de barras o interno
|
||||
$table->enum('type', ['bike', 'accessory', 'clothing', 'spare', 'children', 'skate', 'rollers','other']);
|
||||
$table->text('name')->nullable();
|
||||
|
||||
$table->decimal('price', 10, 2); // Precio venta
|
||||
$table->decimal('cost', 10, 2)->nullable(); // Costo (solo admin)
|
||||
|
||||
$table->text('description')->nullable();;
|
||||
$table->decimal('price', 10, 2); // Precio
|
||||
$table->decimal('cost', 10, 2)->nullable(); // Costo
|
||||
$table->integer('stock_quantity')->default(100);
|
||||
$table->integer('min_stock_alert')->default(5); // Alerta
|
||||
|
||||
|
||||
$table->string('serial_number')->nullable(); // Solo para bicis
|
||||
|
||||
$table->foreignId('suppliers_id')->constrained()->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -39,8 +39,7 @@
|
||||
</x-ui.card>
|
||||
|
||||
<!-- Tarjeta Proveedores -->
|
||||
<x-ui.card href="#" title="Proveedores" description="Base de datos de proveedores." linkText="Ver Proveedores">
|
||||
<svg class="w-12 h-12 text-lime-500 dark:text-neon-lime" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<x-ui.card href="{{ url('/suppliers') }}" title="Proveedores" description="Base de datos de proveedores." linkText="Ver Proveedores"> <svg class="w-12 h-12 text-lime-500 dark:text-neon-lime" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
|
||||
</svg>
|
||||
</x-ui.card>
|
||||
|
||||
@@ -12,10 +12,18 @@
|
||||
<x-forms.label for="name" value="Nombre del Producto" />
|
||||
<x-forms.input id="name" name="name" type="text" :value="old('name')" required autofocus placeholder="Ej: Cámara 29 Válvula Auto" :error="$errors->first('name')" />
|
||||
</div>
|
||||
<!-- SKU -->
|
||||
<!-- proveedor -->
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="sku" value="Código SKU (Opcional)" />
|
||||
<x-forms.input id="sku" name="sku" type="text" :value="old('sku')" placeholder="Dejar vacío para generar auto" :error="$errors->first('sku')" />
|
||||
<x-forms.label for="suppliers_id" value="Proveedor" />
|
||||
<select id="suppliers_id" name="suppliers_id" required class="bg-gray-300 dark:bg-neutral-800 border border-neutral-400 dark:border-neutral-700 dark:text-white text-sm rounded-lg focus:ring-neon-lime focus:border-neon-lime block w-full p-2.5">
|
||||
<option value="" disabled selected>Seleccione un proveedor</option>
|
||||
@foreach($suppliers as $supplier)
|
||||
<option value="{{ $supplier->id }}" {{ old('suppliers_id') == $supplier->id ? 'selected' : '' }}>
|
||||
{{ $supplier->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('suppliers_id') <span class="text-red-500 text-xs mt-1">{{ $message }}</span> @enderror
|
||||
</div>
|
||||
<!-- Tipo -->
|
||||
<div class="md:col-span-2">
|
||||
|
||||
@@ -2,30 +2,37 @@
|
||||
<x-section-header subtitle="Inventario" title="Edicion de " highlight="Producto" />
|
||||
|
||||
<div class="w-full max-w-4xl mx-auto bg-gray-200 dark:bg-panel-bg border border-neutral-400 dark:border-neutral-800 rounded-xl p-8 shadow-lg">
|
||||
<form action="{{route('productos.update',$product)}}" method="POST">
|
||||
<form action="{{route('productos.update',$product)}}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6">
|
||||
|
||||
<!-- Nombre -->
|
||||
<div class="md:col-span-4">
|
||||
<x-forms.label for="name" value="Nombre del Producto" />
|
||||
<x-forms.input id="name" name="name" type="text" value="{{$product->name}}" required autofocus placeholder="Ej: Cámara 29 Válvula Auto" :error="$errors->first('name')" />
|
||||
<x-forms.input id="name" name="name" type="text" value="{{ old('name', $product->name) }}" required autofocus placeholder="Ej: Cámara 29 Válvula Auto" :error="$errors->first('name')" />
|
||||
</div>
|
||||
<!-- SKU -->
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="sku" value="Código SKU (Opcional)" />
|
||||
<x-forms.input id="sku" name="sku" type="text" value="{{$product->sku}}" placeholder="Dejar vacío para generar auto" :error="$errors->first('sku')" />
|
||||
<x-forms.label for="suppliers_id" value="Proveedor" />
|
||||
<select id="suppliers_id" name="suppliers_id" required class="bg-gray-300 dark:bg-neutral-800 border border-neutral-400 dark:border-neutral-700 dark:text-white text-sm rounded-lg focus:ring-neon-lime focus:border-neon-lime block w-full p-2.5">
|
||||
<option value="" disabled>Seleccione un proveedor</option>
|
||||
@foreach($suppliers as $supplier)
|
||||
<option value="{{ $supplier->id }}" {{ old('suppliers_id', $product->suppliers_id) == $supplier->id ? 'selected' : '' }}>
|
||||
{{ $supplier->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('suppliers_id') <span class="text-red-500 text-xs mt-1">{{ $message }}</span> @enderror
|
||||
</div>
|
||||
<!-- Tipo -->
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="type" value="Tipo de Producto" />
|
||||
<select id="type" name="type" class="bg-gray-300 dark:bg-neutral-800 border border-neutral-400 dark:border-neutral-700 dark:text-white text-sm rounded-lg focus:ring-neon-lime focus:border-neon-lime block w-full p-2.5">
|
||||
<option value="accessory" {{ $product->type == 'accessory' ? 'selected' : '' }}>Accesorio</option>
|
||||
<option value="bike" {{ $product->type == 'bike' ? 'selected' : '' }}>Bicicleta</option>
|
||||
<option value="clothing" {{ $product->type == 'clothing' ? 'selected' : '' }}>Indumentaria</option>
|
||||
<option value="spare" {{ $product->type == 'spare' ? 'selected' : '' }}>Repuesto</option>
|
||||
</select>
|
||||
<select id="type" name="type" required class="bg-gray-300 dark:bg-neutral-800 border border-neutral-400 dark:border-neutral-700 dark:text-white text-sm rounded-lg focus:ring-neon-lime focus:border-neon-lime block w-full p-2.5">
|
||||
<option value="accessory" {{ old('type', $product->type) == 'accessory' ? 'selected' : '' }}>Accesorio</option>
|
||||
<option value="bike" {{ old('type', $product->type) == 'bike' ? 'selected' : '' }}>Bicicleta</option>
|
||||
<option value="clothing" {{ old('type', $product->type) == 'clothing' ? 'selected' : '' }}>Indumentaria</option>
|
||||
<option value="spare" {{ old('type', $product->type) == 'spare' ? 'selected' : '' }}>Repuesto</option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Precios -->
|
||||
<div class="">
|
||||
|
||||
@@ -2,207 +2,242 @@
|
||||
|
||||
<x-section-header subtitle="Gestión de Inventario" title="Listado de " highlight="Productos" />
|
||||
|
||||
<!-- Mensajes de feedback -->
|
||||
<x-ui.alert />
|
||||
|
||||
<!-- Barra de Herramientas (Buscador + Botones) -->
|
||||
<div class="w-full flex flex-col xl:flex-row justify-between items-start xl:items-center gap-4 mb-6">
|
||||
|
||||
<!-- Buscador y Filtros -->
|
||||
<form action="{{ route('productos.index') }}" method="GET"
|
||||
class="w-full xl:w-4/5 flex flex-col md:flex-row gap-3">
|
||||
|
||||
<!-- 1. Buscador por Texto -->
|
||||
|
||||
<div class="w-full xl:w-4/5 flex flex-col md:flex-row gap-3">
|
||||
<div class="relative w-full md:w-2/5">
|
||||
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
|
||||
<svg class="w-4 h-4 text-gray-600 dark: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>
|
||||
<svg class="w-4 h-4 text-gray-600 dark:text-gray-500" 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-black dark:text-white border border-neutral-400 dark:border-neutral-700 rounded-lg bg-neutral-200 dark:bg-neutral-800 placeholder-gray-600 dark:placeholder-gray-500 focus:ring-neon-lime focus:border-neon-lime"
|
||||
placeholder="Buscar por nombre">
|
||||
<input type="text" id="searchInput" class="block w-full p-3 ps-10 text-sm text-black dark:text-white border border-neutral-400 dark:border-neutral-700 rounded-lg bg-neutral-200 dark:bg-neutral-800 placeholder-gray-600 dark:placeholder-gray-500 focus:ring-neon-lime focus:border-neon-lime" placeholder="Buscar por nombre...">
|
||||
</div>
|
||||
|
||||
<!-- 2. Filtro de Categoría (Tipo) -->
|
||||
<div class="w-full md:w-1/4">
|
||||
<select name="type" onchange="this.form.submit()"
|
||||
class="block w-full p-3 text-sm text-black dark:text-white border border-neutral-300 dark:border-neutral-700 rounded-lg bg-neutral-200 dark:bg-neutral-800 focus:ring-neon-lime focus:border-neon-lime cursor-pointer">
|
||||
<option value="">Todas las Categorías</option>
|
||||
<option value="bike" {{ request('type') == 'bike' ? 'selected' : '' }}>Bicicletas</option>
|
||||
<option value="clothing" {{ request('type') == 'clothing' ? 'selected' : '' }}>Indumentaria</option>
|
||||
<option value="accessory" {{ request('type') == 'accessory' ? 'selected' : '' }}>Accesorios</option>
|
||||
<option value="spare" {{ request('type') == 'spare' ? 'selected' : '' }}>Repuestos</option>
|
||||
<option value="children" {{ request('type') == 'children' ? 'selected' : '' }}>Infantil</option>
|
||||
<option value="rollers" {{ request('type') == 'rollers' ? 'selected' : '' }}>Rollers</option>
|
||||
<option value="skate" {{ request('type') == 'skate' ? 'selected' : '' }}>Skate</option>
|
||||
<option value="other" {{ request('type') == 'other' ? 'selected' : '' }}>Otros</option>
|
||||
<option value="service" {{ request('type') == 'service' ? 'selected' : '' }}>Servicios</option>
|
||||
<select id="typeFilter" class="block w-full p-3 text-sm text-black dark:text-white border border-neutral-300 dark:border-neutral-700 rounded-lg bg-neutral-200 dark:bg-neutral-800 focus:ring-neon-lime focus:border-neon-lime cursor-pointer">
|
||||
<option value="all">Todas las Categorías</option>
|
||||
<option value="bike">Bicicletas</option>
|
||||
<option value="clothing">Indumentaria</option>
|
||||
<option value="accessory">Accesorios</option>
|
||||
<option value="spare">Repuestos</option>
|
||||
<option value="children">Infantil</option>
|
||||
<option value="rollers">Rollers</option>
|
||||
<option value="skate">Skate</option>
|
||||
<option value="service">Servicios</option>
|
||||
<option value="other">Otros</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- 3. Filtro de Estado de Stock -->
|
||||
<div class="w-full md:w-1/4">
|
||||
<select name="stock_status" onchange="this.form.submit()"
|
||||
class="block w-full p-3 text-sm text-black dark:text-white border border-neutral-300 dark:border-neutral-700 rounded-lg bg-neutral-200 dark:bg-neutral-800 focus:ring-neon-lime focus:border-neon-lime cursor-pointer">
|
||||
<option value="">Cualquier Stock</option>
|
||||
<option value="low" {{ request('stock_status') == 'low' ? 'selected' : '' }}
|
||||
class="text-red-600 dark:text-red-300 font-semibold">Stock en Alerta</option>
|
||||
<option value="medium" {{ request('stock_status') == 'medium' ? 'selected' : '' }}
|
||||
class="text-yellow-600 dark:text-yellow-300 font-semibold">Stock Bajo</option>
|
||||
<option value="ok" {{ request('stock_status') == 'ok' ? 'selected' : '' }}
|
||||
class="text-green-600 dark:text-green-300 font-semibold">Stock Normal</option>
|
||||
<select id="stockFilter" class="block w-full p-3 text-sm text-black dark:text-white border border-neutral-300 dark:border-neutral-700 rounded-lg bg-neutral-200 dark:bg-neutral-800 focus:ring-neon-lime focus:border-neon-lime cursor-pointer">
|
||||
<option value="all">Cualquier Stock</option>
|
||||
<option value="low" class="text-red-600 dark:text-red-400 font-semibold">Stock en Alerta</option>
|
||||
<option value="medium" class="text-yellow-600 dark:text-yellow-400 font-semibold">Stock Bajo</option>
|
||||
<option value="ok" class="text-green-600 dark:text-green-400 font-semibold">Stock Normal</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Botón Limpiar Filtros -->
|
||||
@if (request('search') || request('type') || request('stock_status'))
|
||||
<div class="w-full md:w-auto flex">
|
||||
<a href="{{ route('productos.index') }}" title="Limpiar Filtros"
|
||||
class="flex items-center justify-center p-3 text-sm font-bold text-red-600 dark:text-red-400 bg-red-100 dark:bg-red-900/30 rounded-lg hover:bg-red-200 dark:hover:bg-red-900/50 border border-red-200 dark:border-red-800 transition-colors">
|
||||
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24"
|
||||
height="24" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M6 18 17.94 6M18 18 6.06 6" />
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
@endif
|
||||
</form>
|
||||
|
||||
<!-- Botón Nuevo -->
|
||||
<a href="{{ route('productos.create') }}"
|
||||
class="w-full xl:w-auto text-center px-5 py-3 text-sm font-bold text-neon-lime dark:text-neutral-900 bg-neutral-950 dark:bg-neon-lime rounded-lg hover:bg-neutral-900/80 hover:dark:bg-[#b3e600] transition-colors uppercase tracking-wide">
|
||||
<a href="{{ route('productos.create') }}" class="w-full xl:w-auto text-center px-5 py-3 text-sm font-bold text-neon-lime dark:text-neutral-900 bg-neutral-950 dark:bg-neon-lime rounded-lg hover:bg-neutral-900/80 hover:dark:bg-[#b3e600] transition-colors uppercase tracking-wide">
|
||||
+ Nuevo Producto
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Tabla de Productos -->
|
||||
<div class="relative overflow-x-auto shadow-md sm:rounded-lg border border-gray-400 dark:border-neutral-800 w-full">
|
||||
<div class="relative overflow-x-auto shadow-md sm:rounded-lg border border-gray-400 dark:border-neutral-800 w-full mb-4">
|
||||
<table class="w-full text-sm text-left rtl:text-right text-neutral-900 dark:text-white">
|
||||
<thead
|
||||
class="text-xs text-neutral-800 dark:text-gray-300 uppercase bg-gray-400 dark:bg-neutral-800 border-b border-gray-300 dark:border-neutral-700">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3">Producto</th>
|
||||
<th scope="col" class="px-6 py-3">Tipo</th>
|
||||
<th scope="col" class="px-6 py-3">
|
||||
<div class="flex items-center gap-6">
|
||||
<span class="w-40 shrink-0">Categoría</span>
|
||||
<span>Detalle del Producto</span>
|
||||
</div>
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3">Costo</th>
|
||||
<th scope="col" class="px-6 py-3">Precio</th>
|
||||
<th scope="col" class="px-6 py-3 text-center">Stock</th>
|
||||
<th scope="col" class="px-6 py-3 text-right">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody id="tabla-productos">
|
||||
@forelse($products as $product)
|
||||
<tr
|
||||
class="bg-gray-200/50 dark:bg-neutral-900/50 border-b border-gray-400 dark:border-neutral-800 hover:bg-gray-400 hover:dark:bg-neutral-800 transition-colors group">
|
||||
<td class="px-6 py-4 font-medium whitespace-nowrap">
|
||||
<div class="text-base font-bold">{{ $product->name }}</div>
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400 font-mono">
|
||||
{{ $product->sku ?? 'Sin SKU' }}</div>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
@if ($product->type === 'bike')
|
||||
<x-ui.badge color="neon">Bicicleta</x-ui.badge>
|
||||
@elseif($product->type === 'clothing')
|
||||
<x-ui.badge color="blue">Indumentaria</x-ui.badge>
|
||||
@elseif($product->type === 'spare')
|
||||
<x-ui.badge color="gray">Repuesto</x-ui.badge>
|
||||
@elseif($product->type === 'children')
|
||||
<x-ui.badge color="pink">Infantil</x-ui.badge>
|
||||
@elseif($product->type === 'rollers')
|
||||
<x-ui.badge color="purple">Rollers</x-ui.badge>
|
||||
@elseif($product->type === 'skate')
|
||||
<x-ui.badge color="orange">Skate</x-ui.badge>
|
||||
@else
|
||||
<x-ui.badge color="yellow">Accesorio / Otro</x-ui.badge>
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-6 py-4 font-mono">
|
||||
${{ number_format($product->price, 2) }}
|
||||
</td>
|
||||
<td class="px-6 py-4 text-center">
|
||||
@if ($product->stock_quantity < $product->min_stock_alert)
|
||||
<x-ui.badge color="red">{{ $product->stock_quantity }}</x-ui.badge>
|
||||
@elseif($product->stock_quantity <= $product->min_stock_alert + 5)
|
||||
<x-ui.badge color="yellow">{{ $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 flex items-center gap-2 justify-end">
|
||||
<a href="{{ route('productos.show', $product) }}" title="Ver Mas"
|
||||
class="font-semibold p-2 text-green-700 dark:text-green-400 border-2 border-green-700 rounded-lg hover:bg-green-700 dark:hover:bg-green-600 dark:hover:border-green-600 hover:text-white dark:hover:text-white transition-colors">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
|
||||
width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke="currentColor" stroke-width="2"
|
||||
d="M21 12c0 1.2-4.03 6-9 6s-9-4.8-9-6c0-1.2 4.03-6 9-6s9 4.8 9 6Z" />
|
||||
<path stroke="currentColor" stroke-width="2"
|
||||
d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
|
||||
</svg>
|
||||
<tr class="bg-gray-200/50 dark:bg-neutral-900/50 border-b border-gray-400 dark:border-neutral-800 hover:bg-gray-400 hover:dark:bg-neutral-800 transition-colors group product-row"
|
||||
data-name="{{ strtolower($product->name) }}"
|
||||
data-type="{{ $product->type }}"
|
||||
data-stock="{{ $product->stock_quantity }}"
|
||||
data-min="{{ $product->min_stock_alert }}">
|
||||
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center gap-6">
|
||||
<div class="text-sm font-bold tracking-wider shrink-0 w-40">
|
||||
@if($product->type === 'bike') <x-ui.badge color="neon">BICICLETA</x-ui.badge>
|
||||
@elseif($product->type === 'clothing') <x-ui.badge color="blue">INDUMENTARIA</x-ui.badge>
|
||||
@elseif($product->type === 'spare') <x-ui.badge color="gray">REPUESTO</x-ui.badge>
|
||||
@elseif($product->type === 'children') <x-ui.badge color="pink">INFANTIL</x-ui.badge>
|
||||
@elseif($product->type === 'rollers') <x-ui.badge color="purple">ROLLERS</x-ui.badge>
|
||||
@elseif($product->type === 'skate') <x-ui.badge color="orange">SKATE</x-ui.badge>
|
||||
@elseif($product->type === 'service') <x-ui.badge color="cyan">SERVICIO</x-ui.badge>
|
||||
@else <x-ui.badge color="yellow">ACCESORIO / OTRO</x-ui.badge> @endif
|
||||
</div>
|
||||
<div class="text-base font-semibold text-neutral-900 dark:text-white">
|
||||
{{ $product->name }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="px-6 py-4 font-mono text-base font-medium text-gray-600 dark:text-gray-400">
|
||||
${{ number_format($product->cost, 2) }}
|
||||
</td>
|
||||
|
||||
<td class="px-6 py-4 font-mono text-base font-bold text-black dark:text-white">
|
||||
${{ number_format($product->price, 2) }}
|
||||
</td>
|
||||
|
||||
<td class="px-6 py-4 text-center">
|
||||
@if($product->stock_quantity <= $product->min_stock_alert)
|
||||
<x-ui.badge color="red">{{ $product->stock_quantity }}</x-ui.badge>
|
||||
@elseif($product->stock_quantity <= $product->min_stock_alert+5)
|
||||
<x-ui.badge color="yellow">{{ $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">
|
||||
<div class="flex items-center gap-2 justify-end">
|
||||
<a href="{{ route('productos.show', $product) }}" title="Ver Mas" class="font-semibold p-2 text-green-700 dark:text-green-400 border-2 border-green-700 rounded-lg hover:bg-green-700 dark:hover:bg-green-600 dark:hover:border-green-600 hover:text-white dark:hover:text-white transition-colors">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-width="2" d="M21 12c0 1.2-4.03 6-9 6s-9-4.8-9-6c0-1.2 4.03-6 9-6s9 4.8 9 6Z"/><path stroke="currentColor" stroke-width="2" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"/></svg>
|
||||
</a>
|
||||
|
||||
@php
|
||||
$isAdmin = auth()->user()?->role === 'admin';
|
||||
$classes = $isAdmin
|
||||
? 'text-blue-800 border-blue-800 hover:bg-blue-800 hover:text-white'
|
||||
: 'border-black-400 text-black-400 opacity-50 cursor-not-allowed dark:border-gray-400 dark:text-gray-400';
|
||||
@endphp
|
||||
|
||||
<a @if ($isAdmin) href="{{ route('productos.edit', $product) }}" @endif
|
||||
title="Editar"
|
||||
class="font-semibold p-2 border-2 rounded-lg transition-colors {{ $classes }}">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
|
||||
width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="m14.304 4.844 2.852 2.852M7 7H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-4.5m2.409-9.91a2.017 2.017 0 0 1 0 2.853l-6.844 6.844L8 14l.713-3.565 6.844-6.844a2.015 2.015 0 0 1 2.852 0Z" />
|
||||
|
||||
</svg>
|
||||
<a href="{{ route('productos.edit', $product) }}" title="Editar" class="font-semibold p-2 text-blue-800 dark:text-blue-400 border-2 border-blue-800 rounded-lg hover:bg-blue-800 hover:text-white dark:hover:text-white transition-colors">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m14.304 4.844 2.852 2.852M7 7H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-4.5m2.409-9.91a2.017 2.017 0 0 1 0 2.853l-6.844 6.844L8 14l.713-3.565 6.844-6.844a2.015 2.015 0 0 1 2.852 0Z"/></svg>
|
||||
</a>
|
||||
|
||||
@if (auth()->user()?->role === 'admin')
|
||||
<form action="{{ route('productos.destroy', $product) }}" method="post"
|
||||
class="inline">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button title="Eliminar" type="submit"
|
||||
onclick="return confirm('¿Estás seguro de eliminar este producto?')"
|
||||
class="w-full sm:w-auto p-2 font-bold dark:font-medium text-red-600 dark:text-red-400 border-2 border-red-600 rounded-lg hover:bg-red-600 hover:text-white dark:hover:text-white transition-colors">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
|
||||
width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke="currentColor" stroke-linecap="round"
|
||||
stroke-linejoin="round" stroke-width="2"
|
||||
d="M5 7h14m-9 3v8m4-8v8M10 3h4a1 1 0 0 1 1 1v3H9V4a1 1 0 0 1 1-1ZM6 7h12v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V7Z" />
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
@else
|
||||
<button title="Eliminar" disabled
|
||||
class="w-full sm:w-auto p-2 border-2 dark:border-gray-400 dark:text-gray-400 border-black-400 text-black-400 rounded-lg cursor-not-allowed opacity-50">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
|
||||
width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M5 7h14m-9 3v8m4-8v8M10 3h4a1 1 0 0 1 1 1v3H9V4a1 1 0 0 1 1-1ZM6 7h12v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V7Z" />
|
||||
</svg>
|
||||
<form action="{{route('productos.destroy',$product)}}" method="post">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button title="Eliminar" type="submit" class="w-full sm:w-auto p-2 font-bold dark:font-medium text-red-600 dark:text-red-400 border-2 border-red-600 rounded-lg hover:bg-red-600 hover:text-white dark:hover:text-white transition-colors">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 7h14m-9 3v8m4-8v8M10 3h4a1 1 0 0 1 1 1v3H9V4a1 1 0 0 1 1-1ZM6 7h12v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V7Z"/></svg>
|
||||
</button>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="px-6 py-10 text-center font-semibold">
|
||||
No se encontraron productos.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="5" class="px-6 py-10 text-center font-semibold text-gray-500">
|
||||
No se encontraron productos en la base de datos.
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Paginación -->
|
||||
<div class="mt-4 w-full">
|
||||
{{ $products->links() }}
|
||||
<div class="flex items-center justify-between px-4 py-3 bg-gray-200 dark:bg-neutral-900 border border-gray-400 dark:border-neutral-800 rounded-lg">
|
||||
<div class="text-sm text-gray-700 dark:text-gray-400 font-semibold" id="pagination-info">
|
||||
Cargando productos...
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button id="btn-prev" class="px-4 py-2 text-sm font-bold text-gray-700 dark:text-gray-300 bg-white dark:bg-neutral-800 border border-gray-400 dark:border-neutral-600 rounded-lg hover:bg-gray-100 dark:hover:bg-neutral-700 transition-colors">
|
||||
Anterior
|
||||
</button>
|
||||
<button id="btn-next" class="px-4 py-2 text-sm font-bold text-gray-700 dark:text-gray-300 bg-white dark:bg-neutral-800 border border-gray-400 dark:border-neutral-600 rounded-lg hover:bg-gray-100 dark:hover:bg-neutral-700 transition-colors">
|
||||
Siguiente
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
const typeFilter = document.getElementById('typeFilter');
|
||||
const stockFilter = document.getElementById('stockFilter');
|
||||
const rows = Array.from(document.querySelectorAll('.product-row'));
|
||||
|
||||
const paginationInfo = document.getElementById('pagination-info');
|
||||
const btnPrev = document.getElementById('btn-prev');
|
||||
const btnNext = document.getElementById('btn-next');
|
||||
|
||||
// Configuración de la paginación
|
||||
let currentPage = 1;
|
||||
const itemsPerPage = 10; // Cambiá este número si querés mostrar 15 o 20 por página
|
||||
let filteredRows = [...rows]; // Al principio, todas las filas están "filtradas"
|
||||
|
||||
function aplicarFiltros() {
|
||||
const term = searchInput.value.toLowerCase();
|
||||
const type = typeFilter.value;
|
||||
const stock = stockFilter.value;
|
||||
|
||||
// Guardamos en un array nuevo solo las filas que cumplen las condiciones
|
||||
filteredRows = rows.filter(row => {
|
||||
const name = row.dataset.name;
|
||||
const rowType = row.dataset.type;
|
||||
const qty = parseInt(row.dataset.stock);
|
||||
const min = parseInt(row.dataset.min);
|
||||
|
||||
if (term !== '' && !name.includes(term)) return false;
|
||||
if (type !== 'all' && rowType !== type) return false;
|
||||
if (stock === 'low' && qty > min) return false;
|
||||
if (stock === 'medium' && (qty <= min || qty > min + 5)) return false;
|
||||
if (stock === 'ok' && qty <= min + 5) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// Siempre que filtramos, volvemos a la página 1
|
||||
currentPage = 1;
|
||||
renderPage();
|
||||
}
|
||||
|
||||
function renderPage() {
|
||||
// 1. Ocultamos todas las filas por las dudas
|
||||
rows.forEach(row => row.style.display = 'none');
|
||||
|
||||
// 2. Calculamos qué filas mostrar según la página
|
||||
const start = (currentPage - 1) * itemsPerPage;
|
||||
const end = start + itemsPerPage;
|
||||
const rowsToShow = filteredRows.slice(start, end);
|
||||
|
||||
// 3. Mostramos solo las que tocan
|
||||
rowsToShow.forEach(row => row.style.display = '');
|
||||
|
||||
// 4. Actualizamos los textos y botones
|
||||
const totalPages = Math.ceil(filteredRows.length / itemsPerPage) || 1;
|
||||
paginationInfo.innerText = `Página ${currentPage} de ${totalPages} (${filteredRows.length} resultados)`;
|
||||
|
||||
// Habilitar/Deshabilitar botones
|
||||
btnPrev.disabled = currentPage === 1;
|
||||
btnNext.disabled = currentPage === totalPages;
|
||||
|
||||
// Le damos estilo de "bloqueado" a los botones cuando corresponda
|
||||
btnPrev.classList.toggle('opacity-50', btnPrev.disabled);
|
||||
btnPrev.classList.toggle('cursor-not-allowed', btnPrev.disabled);
|
||||
btnNext.classList.toggle('opacity-50', btnNext.disabled);
|
||||
btnNext.classList.toggle('cursor-not-allowed', btnNext.disabled);
|
||||
}
|
||||
|
||||
function changePage(delta) {
|
||||
const totalPages = Math.ceil(filteredRows.length / itemsPerPage) || 1;
|
||||
const newPage = currentPage + delta;
|
||||
|
||||
if (newPage >= 1 && newPage <= totalPages) {
|
||||
currentPage = newPage;
|
||||
renderPage();
|
||||
}
|
||||
}
|
||||
|
||||
if(searchInput) {
|
||||
searchInput.addEventListener('input', aplicarFiltros);
|
||||
typeFilter.addEventListener('change', aplicarFiltros);
|
||||
stockFilter.addEventListener('change', aplicarFiltros);
|
||||
|
||||
btnPrev.addEventListener('click', () => changePage(-1));
|
||||
btnNext.addEventListener('click', () => changePage(1));
|
||||
|
||||
// Inicializar la tabla apenas carga la página
|
||||
renderPage();
|
||||
}
|
||||
</script>
|
||||
</x-layout>
|
||||
|
||||
@@ -1,42 +1,100 @@
|
||||
<x-layout title="Lauck - Ver Producto">
|
||||
|
||||
<x-section-header subtitle="Inventario" title="Detalle de " highlight="Producto" />
|
||||
|
||||
<!-- Header -->
|
||||
<x-section-header subtitle="Producto" title=" " highlight="{{$product->name}}"/>
|
||||
@php
|
||||
$proveedor = \App\Models\Supplier::find($product->suppliers_id);
|
||||
|
||||
// Mapeo para traducir el tipo de producto al español
|
||||
$tipos = [
|
||||
'accessory' => 'Accesorio',
|
||||
'bike' => 'Bicicleta',
|
||||
'clothing' => 'Indumentaria',
|
||||
'spare' => 'Repuesto',
|
||||
'children' => 'Infantil',
|
||||
'rollers' => 'Rollers',
|
||||
'skate' => 'Skate',
|
||||
'service' => 'Servicio',
|
||||
'other' => 'Otro'
|
||||
];
|
||||
$tipoTraducido = $tipos[$product->type] ?? 'Desconocido';
|
||||
@endphp
|
||||
|
||||
<div class="w-full min-h-7/12 mx-auto px-4 my-5 flex flex-col gap-5 items-center justify-center">
|
||||
<dl class="w-lg text-gray-900 dark:text-white *:border-b *:border-gray-200 *:dark:border-gray-400">
|
||||
<div class="flex flex-col pt-3">
|
||||
<dt class="mb-1 text-gray-500 md:text-lg dark:text-gray-400">Marca</dt>
|
||||
<dd class="text-lg font-semibold">{{$product->name}}</dd>
|
||||
<div class="w-full max-w-4xl mx-auto bg-gray-200 dark:bg-panel-bg border border-neutral-400 dark:border-neutral-800 rounded-xl p-8 shadow-lg mb-10">
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6">
|
||||
|
||||
<div class="md:col-span-4">
|
||||
<x-forms.label for="name" value="Nombre del Producto" />
|
||||
<div class="bg-gray-300/50 dark:bg-neutral-800/50 border border-neutral-400/50 dark:border-neutral-700/50 text-gray-900 dark:text-gray-100 text-sm rounded-lg block w-full p-2.5 font-semibold">
|
||||
{{ $product->name }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col pt-3">
|
||||
<dt class="mb-1 text-gray-500 md:text-lg dark:text-gray-400">SKU</dt>
|
||||
<dd class="text-lg font-semibold">{{$product->sku}}</dd>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="suppliers_id" value="Proveedor" />
|
||||
<div class="bg-gray-300/50 dark:bg-neutral-800/50 border border-neutral-400/50 dark:border-neutral-700/50 text-gray-900 dark:text-gray-100 text-sm rounded-lg block w-full p-2.5 font-semibold">
|
||||
{{ $proveedor ? $proveedor->name : 'Proveedor no asignado' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col pt-3">
|
||||
<dt class="mb-1 text-gray-500 md:text-lg dark:text-gray-400">Descripcion</dt>
|
||||
<dd class="text-lg font-semibold">{{$product->description}}</dd>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="type" value="Tipo de Producto" />
|
||||
<div class="bg-gray-300/50 dark:bg-neutral-800/50 border border-neutral-400/50 dark:border-neutral-700/50 text-gray-900 dark:text-gray-100 text-sm rounded-lg block w-full p-2.5 font-semibold uppercase tracking-wider">
|
||||
{{ $tipoTraducido }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col pt-3">
|
||||
<dt class="mb-1 text-gray-500 md:text-lg dark:text-gray-400">Costo</dt>
|
||||
<dd class="text-lg font-semibold">{{$product->cost}}</dd>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="price" value="Precio Venta" />
|
||||
<div class="bg-gray-300/50 dark:bg-neutral-800/50 border border-neutral-400/50 dark:border-neutral-700/50 text-green-700 dark:text-neon-lime text-lg rounded-lg block w-full p-2.5 font-black font-mono">
|
||||
${{ number_format($product->price, 2, ',', '.') }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col pt-3">
|
||||
<dt class="mb-1 text-gray-500 md:text-lg dark:text-gray-400">Precio</dt>
|
||||
<dd class="text-lg font-semibold">{{$product->price}}</dd>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="stock_quantity" value="Cantidad Actual" />
|
||||
<div class="bg-gray-300/50 dark:bg-neutral-800/50 border border-neutral-400/50 dark:border-neutral-700/50 text-gray-900 dark:text-gray-100 text-sm rounded-lg block w-full p-2.5 font-bold flex items-center gap-2">
|
||||
{{ $product->stock_quantity }} unidades
|
||||
|
||||
@if($product->stock_quantity <= $product->min_stock_alert)
|
||||
<span class="text-xs bg-red-600 text-white px-2 py-0.5 rounded uppercase shadow-sm shadow-red-900/50">¡Bajo Stock!</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col pt-3">
|
||||
<dt class="mb-1 text-gray-500 md:text-lg dark:text-gray-400">Cantidad en Stock</dt>
|
||||
<dd class="text-lg font-semibold">{{$product->stock_quantity}}</dd>
|
||||
|
||||
<div class="md:col-span-4">
|
||||
<x-forms.label for="description" value="Descripción / Notas" />
|
||||
<div class="bg-gray-300/50 dark:bg-neutral-800/50 border border-neutral-400/50 dark:border-neutral-700/50 text-gray-800 dark:text-gray-300 text-sm rounded-lg block w-full p-4 min-h-[80px] leading-relaxed">
|
||||
{{ $product->description ?: 'No hay descripción cargada para este producto.' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col pt-3">
|
||||
<dt class="mb-1 text-gray-500 md:text-lg dark:text-gray-400">Tipo</dt>
|
||||
<dd class="text-lg font-semibold">{{$product->type}}</dd>
|
||||
|
||||
<div class="md:col-span-4">
|
||||
<x-forms.label for="image" value="Fotografía del Producto" />
|
||||
<div class="mt-2">
|
||||
@if($product->image_path)
|
||||
<img src="{{ asset('storage/' . $product->image_path) }}" alt="{{ $product->name }}" class="w-full max-w-sm rounded-lg border border-neutral-400 dark:border-neutral-700 shadow-md">
|
||||
@else
|
||||
<div class="w-full max-w-sm h-40 bg-gray-300 dark:bg-neutral-800 border-2 border-dashed border-gray-400 dark:border-neutral-600 rounded-lg flex flex-col items-center justify-center text-gray-500">
|
||||
<svg class="w-8 h-8 mb-2 opacity-50" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
|
||||
<span class="text-sm font-semibold">Sin imagen asignada</span>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</dl>
|
||||
<div class="flex gap-5">
|
||||
<a href="{{route('productos.index')}}" class="w-full sm:w-auto p-2 rounded-lg text-stone-500 border-2 border-stone-500 font-semibold hover:text-white hover:bg-stone-500">Volver</a>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between md:justify-end space-x-4 border-t border-neutral-400 dark:border-neutral-700 pt-6">
|
||||
<a href="{{ route('productos.index') }}" class="text-gray-800 dark:text-gray-400 hover:text-black hover:dark:text-white font-medium text-sm transition-colors">
|
||||
Volver al listado
|
||||
</a>
|
||||
<a href="{{ route('productos.edit', $product) }}" class="px-6 py-2.5 bg-neutral-900 dark:bg-neon-lime text-neon-lime dark:text-neutral-900 font-bold rounded-lg hover:bg-neutral-800 hover:dark:bg-[#b3e600] transition-colors shadow-lg dark:shadow-neon-lime/20 flex items-center gap-2">
|
||||
<svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m14.304 4.844 2.852 2.852M7 7H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-4.5m2.409-9.91a2.017 2.017 0 0 1 0 2.853l-6.844 6.844L8 14l.713-3.565 6.844-6.844a2.015 2.015 0 0 1 2.852 0Z"/></svg>
|
||||
Editar Producto
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</x-layout>
|
||||
@@ -0,0 +1,43 @@
|
||||
<x-layout title="Lauck - Nuevo Proveedor">
|
||||
<x-section-header subtitle="Gestión de Proveedores" title="Nuevo " highlight="Proveedor" />
|
||||
|
||||
<div class="w-full max-w-4xl mx-auto bg-gray-200 dark:bg-panel-bg border border-neutral-400 dark:border-neutral-800 rounded-xl p-8 shadow-lg">
|
||||
<form action="{{ route('suppliers.store') }}" method="POST">
|
||||
@csrf
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6">
|
||||
|
||||
<div class="md:col-span-4">
|
||||
<x-forms.label for="name" value="Nombre de la Empresa o Contacto" />
|
||||
<x-forms.input id="name" name="name" type="text" :value="old('name')" required autofocus placeholder="Ej: Distribuidora Shimano Arg" :error="$errors->first('name')" />
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="phone" value="Teléfono / WhatsApp" />
|
||||
<x-forms.input id="phone" name="phone" type="text" :value="old('phone')" placeholder="Ej: 011 4545..." :error="$errors->first('phone')" />
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="email" value="Correo Electrónico" />
|
||||
<x-forms.input id="email" name="email" type="email" :value="old('email')" placeholder="ventas@proveedor.com" :error="$errors->first('email')" />
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-4">
|
||||
<x-forms.label for="address" value="Dirección / Domicilio / Depósito" />
|
||||
<textarea id="address" name="address" rows="3" class="bg-gray-300 dark:bg-neutral-800 border border-neutral-400 dark:border-neutral-700 dark:text-white text-sm rounded-lg focus:ring-neon-lime focus:border-neon-lime block w-full p-2.5 placeholder-neutral-600 dark:placeholder-gray-400" placeholder="Calle, número, galpón, ciudad...">{{ old('address') }}</textarea>
|
||||
@error('address')
|
||||
<span class="text-red-500 text-xs mt-1">{{ $message }}</span>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between md:justify-end space-x-4 border-t border-neutral-400 dark:border-neutral-700 pt-6">
|
||||
<a href="{{ route('suppliers.index') }}" class="text-gray-700 dark:text-gray-400 hover:text-black hover:dark:text-white font-medium text-sm transition-colors">Cancelar</a>
|
||||
<button type="submit" class="px-6 py-2.5 bg-neutral-900 dark:bg-neon-lime text-neon-lime dark:text-neutral-900 font-bold rounded-lg hover:bg-neutral-800 hover:dark:bg-[#b3e600] transition-colors shadow-lg dark:shadow-neon-lime/20">
|
||||
Guardar Proveedor
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</x-layout>
|
||||
@@ -0,0 +1,45 @@
|
||||
<x-layout title="Lauck - Editar Proveedor">
|
||||
<x-section-header subtitle="Gestión de Proveedores" title="Editar " highlight="Proveedor" />
|
||||
|
||||
<div class="w-full max-w-4xl mx-auto bg-gray-200 dark:bg-panel-bg border border-neutral-400 dark:border-neutral-800 rounded-xl p-8 shadow-lg">
|
||||
<form action="{{ route('suppliers.update', $supplier) }}" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6">
|
||||
|
||||
<div class="md:col-span-4">
|
||||
<x-forms.label for="name" value="Nombre de la Empresa o Contacto" />
|
||||
<x-forms.input id="name" name="name" type="text" :value="old('name', $supplier->name)" required autofocus placeholder="Ej: Distribuidora Shimano Arg" :error="$errors->first('name')" />
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="phone" value="Teléfono / WhatsApp" />
|
||||
<x-forms.input id="phone" name="phone" type="text" :value="old('phone', $supplier->phone)" placeholder="Ej: 011 4545..." :error="$errors->first('phone')" />
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2">
|
||||
<x-forms.label for="email" value="Correo Electrónico" />
|
||||
<x-forms.input id="email" name="email" type="email" :value="old('email', $supplier->email)" placeholder="ventas@proveedor.com" :error="$errors->first('email')" />
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-4">
|
||||
<x-forms.label for="address" value="Dirección / Domicilio / Depósito" />
|
||||
<textarea id="address" name="address" rows="3" class="bg-gray-300 dark:bg-neutral-800 border border-neutral-400 dark:border-neutral-700 dark:text-white text-sm rounded-lg focus:ring-neon-lime focus:border-neon-lime block w-full p-2.5 placeholder-neutral-600 dark:placeholder-gray-400" placeholder="Calle, número, galpón, ciudad...">{{ old('address', $supplier->address) }}</textarea>
|
||||
|
||||
@error('address')
|
||||
<span class="text-red-500 text-xs mt-1">{{ $message }}</span>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between md:justify-end space-x-4 border-t border-neutral-400 dark:border-neutral-700 pt-6">
|
||||
<a href="{{ route('suppliers.index') }}" class="text-gray-800 dark:text-gray-400 hover:text-black hover:dark:text-white font-medium text-sm transition-colors">Cancelar</a>
|
||||
<button type="submit" class="px-6 py-2.5 bg-neutral-900 dark:bg-neon-lime text-neon-lime dark:text-neutral-900 font-bold rounded-lg hover:bg-neutral-800 hover:dark:bg-[#b3e600] transition-colors shadow-lg dark:shadow-neon-lime/20">
|
||||
Actualizar Proveedor
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</x-layout>
|
||||
@@ -0,0 +1,114 @@
|
||||
<x-layout title="Lauck - Proveedores">
|
||||
|
||||
<x-section-header subtitle="Gestión de Proveedores" title="Directorio de " highlight="Proveedores" />
|
||||
|
||||
<x-ui.alert />
|
||||
@if(session('success'))
|
||||
<div class="bg-green-900/50 border border-green-500 text-green-300 px-4 py-3 rounded-lg mb-6 shadow-sm">
|
||||
{{ session('success') }}
|
||||
</div>
|
||||
@endif
|
||||
<!--@if(session('error'))
|
||||
<div class="bg-red-900/50 border border-red-500 text-red-300 px-4 py-3 rounded-lg mb-6 shadow-sm">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif-->
|
||||
|
||||
<div class="w-full flex flex-col md:flex-row justify-between items-center gap-4 mb-6">
|
||||
|
||||
<form action="{{ route('suppliers.index') }}" method="GET" class="w-full md:w-1/2">
|
||||
<div class="relative">
|
||||
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
|
||||
<svg class="w-4 h-4 text-gray-600 dark: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-black dark:text-white border border-neutral-400 dark:border-neutral-700 rounded-lg bg-neutral-200 dark:bg-neutral-800 placeholder-gray-600 dark:placeholder-gray-500"
|
||||
placeholder="Buscar por nombre...">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<a href="{{ route('suppliers.create') }}" class="w-full md:w-auto text-center px-5 py-3 text-sm font-bold text-neon-lime dark:text-neutral-900 bg-neutral-950 dark:bg-neon-lime rounded-lg hover:bg-neutral-900/80 hover:dark:bg-[#b3e600] transition-colors uppercase tracking-wide">
|
||||
+ Nuevo Proveedor
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="relative overflow-x-auto shadow-md sm:rounded-lg border border-gray-400 dark:border-neutral-800 w-full">
|
||||
<table class="w-full text-sm text-left rtl:text-right text-neutral-900 dark:text-white">
|
||||
<thead class="text-xs text-neutral-800 dark:text-gray-300 uppercase bg-gray-400 dark:bg-neutral-800 border-b border-gray-300 dark:border-neutral-700">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3">Proveedor / Email</th>
|
||||
<th scope="col" class="px-6 py-3">Teléfono / WhatsApp</th>
|
||||
<th scope="col" class="px-6 py-3">Dirección</th>
|
||||
<th scope="col" class="px-6 py-3 text-right">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($suppliers as $supplier)
|
||||
<tr class="bg-gray-200/50 dark:bg-neutral-900/50 border-b border-gray-400 dark:border-neutral-800 hover:bg-gray-400 hover:dark:bg-neutral-800 transition-colors group">
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<div class="text-base font-bold">{{ $supplier->name }}</div>
|
||||
<div class="text-xs text-gray-600 dark:text-gray-400 font-mono">
|
||||
{{ $supplier->email ?? 'Sin email registrado' }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
@if($supplier->phone)
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-mono">{{ $supplier->phone }}</span>
|
||||
<span class="text-xs text-green-600 border border-green-600 px-1.5 py-0.5 rounded">WA</span>
|
||||
</div>
|
||||
@else
|
||||
<span class="italic text-gray-500">No registrado</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<span class="truncate max-w-xs block" title="{{ $supplier->address }}">
|
||||
{{ $supplier->address ?? '-' }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right flex items-center justify-end gap-3">
|
||||
<a href="{{ route('suppliers.order', $supplier) }}" title="Hacer Pedido" class="font-semibold p-2 text-green-600 dark:text-green-400 border-2 border-green-600 rounded-lg hover:bg-green-600 hover:text-white dark:hover:text-white transition-colors">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 24 24">
|
||||
<path fill-rule="evenodd" d="M12 4a8 8 0 0 0-6.895 12.06l.569 1.167-1.076 2.872 3.018-1.045 1.18.528A8 8 0 1 0 12 4Zm5.1 10.3c-.28-.14-1.65-.815-1.905-.909-.255-.094-.44-.14-.625.14-.185.28-.72 1.054-.882 1.265-.162.21-.324.234-.604.094-.28-.14-1.178-.435-2.246-1.385-.83-.739-1.39-1.65-1.552-1.93-.162-.28-.017-.432.123-.57.126-.125.28-.328.42-.493.14-.165.187-.28.28-.468.093-.188.047-.35-.023-.491-.07-.14-.625-1.508-.857-2.064-.225-.544-.454-.47-.625-.478-.162-.008-.348-.01-.533-.01-.185 0-.485.07-.74.35-.255.28-.972.95-.972 2.316 0 1.366.995 2.687 1.133 2.874.138.188 1.956 2.986 4.74 4.153.662.277 1.18.442 1.583.565.665.204 1.27.175 1.745.106.531-.077 1.65-.674 1.882-1.325.232-.651.232-1.21.162-1.325-.07-.116-.255-.186-.535-.326Z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
</a>
|
||||
<a href="{{ route('suppliers.edit', $supplier) }}" title="Editar" class="font-semibold p-2 text-blue-700 dark:text-blue-400 border-2 border-blue-700 rounded-lg hover:bg-blue-700 hover:text-white dark:hover:text-white transition-colors">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m14.304 4.844 2.852 2.852M7 7H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-4.5m2.409-9.91a2.017 2.017 0 0 1 0 2.853l-6.844 6.844L8 14l.713-3.565 6.844-6.844a2.015 2.015 0 0 1 2.852 0Z"/>
|
||||
</svg>
|
||||
</a>
|
||||
<form action="{{route('suppliers.destroy', $supplier)}}" method="post">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button title="Eliminar" type="submit" class="w-full sm:w-auto p-2 font-bold dark:font-medium text-red-600 dark:text-red-400 border-2 border-red-600 rounded-lg hover:bg-red-600 hover:text-white dark:hover:text-white transition-colors">
|
||||
<svg class="size-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 7h14m-9 3v8m4-8v8M10 3h4a1 1 0 0 1 1 1v3H9V4a1 1 0 0 1 1-1ZM6 7h12v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V7Z"/>
|
||||
</svg>
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="4" class="px-6 py-10 text-center text-gray-500">
|
||||
<div class="flex flex-col items-center justify-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-10 mb-2 opacity-50" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
|
||||
</svg>
|
||||
<p>No se encontraron proveedores.</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 w-full">
|
||||
{{ $suppliers->links() }}
|
||||
</div>
|
||||
|
||||
</x-layout>
|
||||
@@ -0,0 +1,203 @@
|
||||
<x-layout title="Lauck - Armar Pedido">
|
||||
<x-section-header subtitle="Proveedores" title="Armar Pedido: " highlight="{{ $supplier->name }}" />
|
||||
|
||||
<div class="w-full max-w-5xl mx-auto bg-gray-200 dark:bg-panel-bg border border-neutral-400 dark:border-neutral-800 rounded-xl p-8 shadow-lg relative">
|
||||
|
||||
<div class="mb-6 flex justify-between items-end">
|
||||
<div>
|
||||
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">Seleccioná los productos</h3>
|
||||
<p class="text-sm text-gray-600 dark:text-gray-400">Teléfono registrado: {{ $supplier->phone ?? 'Ninguno' }}</p>
|
||||
</div>
|
||||
<a href="{{ route('suppliers.index') }}" class="text-sm font-bold text-gray-500 hover:text-white transition-colors">Volver al listado</a>
|
||||
</div>
|
||||
|
||||
@if($products->isEmpty())
|
||||
<div class="bg-yellow-900/30 border border-yellow-600 text-yellow-500 p-4 rounded-lg">
|
||||
Este proveedor todavía no tiene productos asociados en el sistema.
|
||||
</div>
|
||||
@else
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4 bg-gray-300 dark:bg-neutral-800 p-4 rounded-lg border border-gray-400 dark:border-neutral-700">
|
||||
<div class="relative">
|
||||
<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" 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" id="searchInput" class="block w-full p-2.5 ps-10 text-sm text-black dark:text-white border border-gray-400 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-900 focus:ring-neon-lime focus:border-neon-lime" placeholder="Buscar por nombre...">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<select id="typeFilter" class="block w-full p-2.5 text-sm text-black dark:text-white border border-gray-400 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-900 focus:ring-neon-lime focus:border-neon-lime">
|
||||
<option value="all">Todas las categorías</option>
|
||||
<option value="bike">Bicicletas</option>
|
||||
<option value="accessory">Accesorios</option>
|
||||
<option value="clothing">Indumentaria</option>
|
||||
<option value="spare">Repuestos</option>
|
||||
<option value="children">Infantil</option>
|
||||
<option value="rollers">Rollers</option>
|
||||
<option value="skate">Skate</option>
|
||||
<option value="other">Otros</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<select id="stockFilter" class="block w-full p-2.5 text-sm text-black dark:text-white border border-gray-400 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-900 focus:ring-neon-lime focus:border-neon-lime">
|
||||
<option value="all">Todo el inventario</option>
|
||||
<option value="low">Solo Bajo Stock (Alerta)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="relative overflow-x-auto overflow-y-auto max-h-[450px] border border-gray-400 dark:border-neutral-700 rounded-lg mb-6 custom-scrollbar">
|
||||
<table class="w-full text-sm text-left text-neutral-900 dark:text-gray-300">
|
||||
<thead class="text-xs uppercase bg-gray-400 dark:bg-neutral-800 border-b border-gray-400 dark:border-neutral-700 sticky top-0 z-10">
|
||||
<tr>
|
||||
<th class="px-4 py-3 text-center w-16">Pedir</th>
|
||||
<th class="px-4 py-3 w-24">Cantidad</th>
|
||||
<th class="px-4 py-3">Producto</th>
|
||||
<th class="px-4 py-3 text-center">Stock Actual</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tabla-productos">
|
||||
@foreach($products as $product)
|
||||
<tr class="border-b border-gray-300 dark:border-neutral-800 hover:bg-gray-300/50 dark:hover:bg-neutral-800/50 transition-colors product-row"
|
||||
data-name="{{ strtolower($product->name) }}"
|
||||
data-type="{{ $product->type }}"
|
||||
data-stock="{{ $product->stock_quantity }}"
|
||||
data-min="{{ $product->min_stock_alert }}">
|
||||
|
||||
<td class="px-4 py-3 text-center">
|
||||
<input type="checkbox" class="product-check w-5 h-5 text-neon-lime bg-gray-100 border-gray-400 rounded focus:ring-neon-lime dark:focus:ring-neon-lime dark:ring-offset-gray-800 focus:ring-2 dark:bg-neutral-700 dark:border-neutral-600 cursor-pointer">
|
||||
</td>
|
||||
<td class="px-4 py-3">
|
||||
<input type="number" min="1" value="1" class="product-qty bg-white dark:bg-neutral-900 border border-gray-400 dark:border-neutral-600 text-sm rounded-lg focus:ring-neon-lime focus:border-neon-lime block w-full p-2 text-center disabled:opacity-50" disabled>
|
||||
</td>
|
||||
<td class="px-4 py-3 font-semibold product-name">
|
||||
{{ $product->name }}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-center">
|
||||
@if($product->stock_quantity <= $product->min_stock_alert)
|
||||
<span class="px-2 py-1 rounded text-xs font-bold bg-red-200 text-red-800 dark:bg-red-900/50 dark:text-red-400">
|
||||
{{ $product->stock_quantity }} (¡Bajo!)
|
||||
</span>
|
||||
@else
|
||||
<span class="px-2 py-1 rounded text-xs font-bold bg-gray-300 text-gray-700 dark:bg-gray-800 dark:text-gray-400">
|
||||
{{ $product->stock_quantity }}
|
||||
</span>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end pt-4 border-t border-gray-400 dark:border-neutral-700 mt-4">
|
||||
<button onclick="enviarPedido()" class="flex items-center gap-2 px-6 py-3 bg-green-600 text-white font-bold rounded-lg hover:bg-green-500 transition-colors shadow-lg shadow-green-900/20">
|
||||
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 4a8 8 0 0 0-6.895 12.06l.569 1.167-1.076 2.872 3.018-1.045 1.18.528A8 8 0 1 0 12 4Zm5.1 10.3c-.28-.14-1.65-.815-1.905-.909-.255-.094-.44-.14-.625.14-.185.28-.72 1.054-.882 1.265-.162.21-.324.234-.604.094-.28-.14-1.178-.435-2.246-1.385-.83-.739-1.39-1.65-1.552-1.93-.162-.28-.017-.432.123-.57.126-.125.28-.328.42-.493.14-.165.187-.28.28-.468.093-.188.047-.35-.023-.491-.07-.14-.625-1.508-.857-2.064-.225-.544-.454-.47-.625-.478-.162-.008-.348-.01-.533-.01-.185 0-.485.07-.74.35-.255.28-.972.95-.972 2.316 0 1.366.995 2.687 1.133 2.874.138.188 1.956 2.986 4.74 4.153.662.277 1.18.442 1.583.565.665.204 1.27.175 1.745.106.531-.077 1.65-.674 1.882-1.325.232-.651.232-1.21.162-1.325-.07-.116-.255-.186-.535-.326Z" clip-rule="evenodd"/></svg>
|
||||
Armar Pedido por WhatsApp
|
||||
</button>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.custom-scrollbar::-webkit-scrollbar { width: 8px; }
|
||||
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
|
||||
.custom-scrollbar::-webkit-scrollbar-thumb { background-color: #4b5563; border-radius: 20px; }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
const typeFilter = document.getElementById('typeFilter');
|
||||
const stockFilter = document.getElementById('stockFilter');
|
||||
const rows = document.querySelectorAll('.product-row');
|
||||
|
||||
function aplicarFiltros() {
|
||||
if(!searchInput) return;
|
||||
|
||||
const term = searchInput.value.toLowerCase();
|
||||
const type = typeFilter.value;
|
||||
const stock = stockFilter.value;
|
||||
|
||||
rows.forEach(row => {
|
||||
const name = row.dataset.name;
|
||||
const rowType = row.dataset.type;
|
||||
const qty = parseInt(row.dataset.stock);
|
||||
const min = parseInt(row.dataset.min);
|
||||
|
||||
let show = true;
|
||||
|
||||
// filtrar por texto
|
||||
if (term !== '' && !name.includes(term)) show = false;
|
||||
|
||||
// filtrar por categoría
|
||||
if (type !== 'all' && rowType !== type) show = false;
|
||||
|
||||
// filtrar por stock
|
||||
if (stock === 'low' && qty > min) show = false;
|
||||
|
||||
// ocultar o mostrar fila
|
||||
row.style.display = show ? '' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
if(searchInput) {
|
||||
searchInput.addEventListener('input', aplicarFiltros);
|
||||
typeFilter.addEventListener('change', aplicarFiltros);
|
||||
stockFilter.addEventListener('change', aplicarFiltros);
|
||||
}
|
||||
|
||||
// logica de habilitar/deshabilitar cant
|
||||
document.querySelectorAll('.product-check').forEach(checkbox => {
|
||||
checkbox.addEventListener('change', function() {
|
||||
const tr = this.closest('tr');
|
||||
const qtyInput = tr.querySelector('.product-qty');
|
||||
qtyInput.disabled = !this.checked;
|
||||
|
||||
if(this.checked) {
|
||||
qtyInput.focus();
|
||||
qtyInput.select();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// enviar a wsp
|
||||
function enviarPedido() {
|
||||
let telefonoRaw = "{{ $supplier->phone }}";
|
||||
let telefono = telefonoRaw.replace(/\D/g, '');
|
||||
|
||||
if (!telefono) {
|
||||
alert('Oops! El proveedor no tiene un número de teléfono guardado. Editalo primero en la pestaña de Proveedores.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (telefono.length === 10) {
|
||||
telefono = '549' + telefono;
|
||||
}
|
||||
|
||||
let mensaje = `Hola *{{ $supplier->name }}*, me comunico de Bicicletería Lauck para realizar el siguiente pedido:\n\n`;
|
||||
let hayProductos = false;
|
||||
|
||||
document.querySelectorAll('.product-row').forEach(row => {
|
||||
const isChecked = row.querySelector('.product-check').checked;
|
||||
const qty = row.querySelector('.product-qty').value;
|
||||
const name = row.querySelector('.product-name').innerText.trim();
|
||||
|
||||
if (isChecked && qty > 0) {
|
||||
mensaje += `- ${qty}x ${name}\n`;
|
||||
hayProductos = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hayProductos) {
|
||||
alert('Por favor, tildá al menos un producto para hacer el pedido.');
|
||||
return;
|
||||
}
|
||||
|
||||
mensaje += `\n¡Muchas gracias!`;
|
||||
|
||||
const url = `https://wa.me/${telefono}?text=${encodeURIComponent(mensaje)}`;
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
</script>
|
||||
</x-layout>
|
||||
+6
-1
@@ -12,6 +12,7 @@ use App\Http\Controllers\RegisterController;
|
||||
use App\Http\Controllers\TallerController;
|
||||
use App\Http\Controllers\AgendaController;
|
||||
use App\Http\Controllers\AppointmentController;
|
||||
use App\Http\Controllers\SupplierController;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
@@ -37,6 +38,11 @@ Route::post('logout', function(){
|
||||
Route::middleware(['auth'])->group(function () {
|
||||
Route::view('dashboard', 'dashboard')->name('dashboard');
|
||||
Route::resource('clients', ClientController::class);
|
||||
Route::get('suppliers/{supplier}/order', [SupplierController::class, 'order'])->name('suppliers.order');
|
||||
Route::resource('suppliers', SupplierController::class);
|
||||
Route::resource('productos', ProductosController::class)->parameters([
|
||||
'productos' => 'product'
|
||||
]);
|
||||
Route::resource('sales', SaleController::class)->only(['index', 'create', 'store', 'show']);
|
||||
Route::get('/agenda', [AgendaController::class, 'index'])->name('agenda');
|
||||
Route::get('/appointments/{appointment}', [AppointmentController::class, 'show'])->name('appointments.show');
|
||||
@@ -61,6 +67,5 @@ Route::middleware(['auth'])->group(function () {
|
||||
->only(['create', 'store', 'edit', 'update', 'destroy'])
|
||||
->parameters(['productos' => 'product']);
|
||||
|
||||
// Si tienes más cosas de admin (ej: reportes), van aquí
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user