Merge branch 'bryam' of https://github.com/BryamE/ProyectoLauck into lucas
This commit is contained in:
@@ -13,4 +13,28 @@ class CatalogoController extends Controller
|
|||||||
$productos = Product::all();
|
$productos = Product::all();
|
||||||
return view('catalogo', compact('productos'));
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class ClientController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for creating a new resource.
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*/
|
||||||
|
public function show(string $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
*/
|
||||||
|
public function edit(string $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*/
|
||||||
|
public function update(Request $request, string $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*/
|
||||||
|
public function destroy(string $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Product;
|
||||||
|
use App\Models\Sale;
|
||||||
|
use App\Models\SaleDetail;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
//
|
||||||
|
use App\Models\Client;
|
||||||
|
|
||||||
|
class SaleController extends Controller
|
||||||
|
{
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
// Buscamos productos que tengan stock mayor a 0 para mostrar en el selector
|
||||||
|
$products = Product::where('stock', '>', 0)->get();
|
||||||
|
|
||||||
|
$clients = \App\Models\Client::orderBy('nombre')->get();
|
||||||
|
|
||||||
|
return view('sales.create', compact('products', 'clients'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'payment_method' => 'required|string',
|
||||||
|
'client_id' => 'nullable|exists:clients,id',
|
||||||
|
'items' => 'required|array',
|
||||||
|
'items.*.product_id' => 'required|exists:products,id',
|
||||||
|
'items.*.quantity' => 'required|integer|min:1',
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::transaction(function () use ($request) {
|
||||||
|
$totalVenta = 0;
|
||||||
|
|
||||||
|
foreach ($request->items as $item) {
|
||||||
|
$product = Product::find($item['product_id']);
|
||||||
|
$totalVenta += $product->precio * $item['quantity'];
|
||||||
|
|
||||||
|
if ($product->stock < $item['quantity']) {
|
||||||
|
throw new \Exception("No hay suficiente stock de " . $product->nombre);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//cabecera
|
||||||
|
$sale = Sale::create([
|
||||||
|
//'user_id' => auth()->id(), //empleado logueado
|
||||||
|
'client_id' => $request->client_id,
|
||||||
|
'total' => $totalVenta,
|
||||||
|
'payment_method' => $request->payment_method,
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($request->items as $item) {
|
||||||
|
$product = Product::find($item['product_id']);
|
||||||
|
|
||||||
|
SaleDetail::create([
|
||||||
|
'sale_id' => $sale->id,
|
||||||
|
'product_id' => $product->id,
|
||||||
|
'cantidad' => $item['quantity'],
|
||||||
|
'precio' => $product->precio,
|
||||||
|
]);
|
||||||
|
$nuevoStock = $product->stock - $item['quantity'];
|
||||||
|
$product->stock = $nuevoStock;
|
||||||
|
$product->save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 5. REDIRECCIÓN DE ÉXITO
|
||||||
|
// Redirigimos al usuario con un mensaje flash [cite: 668]
|
||||||
|
return redirect()->route('sales.create')->with('success', '¡Venta registrada correctamente!');
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Si algo falló (ej: falta stock), volvemos atrás con el error
|
||||||
|
return back()->with('error', 'Error en la venta: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,9 +8,16 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class Client extends Model
|
class Client extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
protected $guarded = [];
|
||||||
protected $fillable = ['name', 'phone', 'email', 'address'];
|
protected $fillable = ['name', 'phone', 'email', 'address'];
|
||||||
|
|
||||||
|
// Un usuario (cliente) realiza muchas compras (ventas)
|
||||||
|
public function sales()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Sale::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Relación: Un cliente tiene muchos turnos
|
// Relación: Un cliente tiene muchos turnos
|
||||||
public function appointments()
|
public function appointments()
|
||||||
{
|
{
|
||||||
|
|||||||
+24
-11
@@ -8,21 +8,34 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class Product extends Model
|
class Product extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
protected $fillable = [
|
|
||||||
'name',
|
|
||||||
'sku',
|
|
||||||
'description',
|
|
||||||
'price',
|
|
||||||
'cost',
|
|
||||||
'stock_quantity',
|
|
||||||
'min_stock_alert',
|
|
||||||
'type',
|
|
||||||
'serial_number'
|
|
||||||
];
|
|
||||||
|
|
||||||
public function hasLowStock(): bool
|
public function hasLowStock(): bool
|
||||||
{
|
{
|
||||||
|
//cambiar
|
||||||
return $this->stock_quantity <= $this->min_stock_alert;
|
return $this->stock_quantity <= $this->min_stock_alert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function supplier()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Suppliers::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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/**$user->sales: Te da la lista de todas las compras de ese usuario.
|
||||||
|
|
||||||
|
$product->saleDetails->count(): Te dice cuántas veces aparece ese producto en tickets.**/
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
class Sale extends Model
|
||||||
|
{
|
||||||
|
//use HasFactory;
|
||||||
|
|
||||||
|
// Permitimos asignación masiva para poder guardar rápido
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
// Relación 1: Una venta pertenece a un Cliente (User)
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Relación 2: Una venta tiene muchos items o detalles
|
||||||
|
public function details()
|
||||||
|
{
|
||||||
|
return $this->hasMany(SaleDetail::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class SaleDetail extends Model
|
||||||
|
{
|
||||||
|
//use HasFactory;
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
// este detalle pertenece a una Venta específica
|
||||||
|
public function sale()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Sale::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// este detalle corresponde a un Producto
|
||||||
|
public function product()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Product::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Supplier extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'nombre',
|
||||||
|
'telefono',
|
||||||
|
'email'
|
||||||
|
];
|
||||||
|
public function products()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Product::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?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('suppliers', 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('suppliers');
|
||||||
|
}
|
||||||
|
};
|
||||||
+2
-1
@@ -26,6 +26,7 @@ return new class extends Migration
|
|||||||
$table->enum('type', ['bike', 'accessory', 'service']);
|
$table->enum('type', ['bike', 'accessory', 'service']);
|
||||||
$table->string('serial_number')->nullable(); // Solo para bicis
|
$table->string('serial_number')->nullable(); // Solo para bicis
|
||||||
|
|
||||||
|
$table->foreignId('suppliers_id')->constrained();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -37,4 +38,4 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::dropIfExists('products');
|
Schema::dropIfExists('products');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?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');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?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('sales', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
//$table->foreignId('user_id')->constrained();
|
||||||
|
// nullable para que no sea obligatrio
|
||||||
|
$table->foreignId('client_id')->nullable()->constrained();
|
||||||
|
$table->decimal('total', 10, 2);
|
||||||
|
$table->string('payment_method');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('sales');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?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('sale_details', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('sale_id')->constrained()->onDelete('cascade');
|
||||||
|
$table->foreignId('product_id')->constrained();
|
||||||
|
$table->integer('cantidad');
|
||||||
|
$table->decimal('precio', 10, 2);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('sale_details');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?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');
|
||||||
|
}
|
||||||
|
};
|
||||||
-165
@@ -1,165 +0,0 @@
|
|||||||
¡Perfecto\! Tus respuestas aclaran muchísimo el panorama. Al ser un sistema **Intranet (Local)** con un **Admin** y **Empleados** (visores/operadores), y con procesos manuales en el taller, podemos simplificar la arquitectura para lanzar un MVP (Producto Mínimo Viable) rápido y robusto, pero preparado para crecer.
|
|
||||||
|
|
||||||
Aquí tienes la **Guía Maestra de Desarrollo para Lauck Systems**.
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
### 1\. Arquitectura de Base de Datos (El Cimiento)
|
|
||||||
|
|
||||||
Antes de escribir código, definamos las tablas. Laravel hace esto fácil con migraciones.
|
|
||||||
|
|
||||||
#### Tablas Principales:
|
|
||||||
|
|
||||||
1. **`users`** (Ya viene en Laravel)
|
|
||||||
|
|
||||||
* Agregamos campo: `role` (enum: 'admin', 'employee').
|
|
||||||
* *Lógica:* El Admin crea, edita y borra. El Empleado solo ve y registra ventas/turnos (según definas).
|
|
||||||
|
|
||||||
2. **`clients`** (Clientes)
|
|
||||||
|
|
||||||
* `name`, `phone` (clave para WhatsApp), `email`, `address`.
|
|
||||||
* *Nota:* Fundamental para agendar turnos y registrar garantías.
|
|
||||||
|
|
||||||
3. **`products`** (Inventario Mixto)
|
|
||||||
|
|
||||||
* `name`, `sku` (código único), `description`.
|
|
||||||
* `price` (precio venta), `cost` (costo, solo visible para admin).
|
|
||||||
* `stock_quantity` (entero).
|
|
||||||
* `min_stock_alert` (entero, para la alerta que pediste).
|
|
||||||
* `type` (enum: 'bike', 'accessory', 'service').
|
|
||||||
* `serial_number` (nullable, solo para bicicletas).
|
|
||||||
|
|
||||||
4. **`appointments`** (Turnos / Taller)
|
|
||||||
|
|
||||||
* `client_id` (relación).
|
|
||||||
* `scheduled_at` (datetime - fecha y hora del turno).
|
|
||||||
* `bike_model` (texto libre, ej: "Venzo Loki 29").
|
|
||||||
* `problem_description` (motivo de la consulta).
|
|
||||||
* `status` (enum: 'pending', 'confirmed', 'in\_progress', 'ready', 'delivered').
|
|
||||||
* `notes` (uso interno del mecánico).
|
|
||||||
|
|
||||||
5. **`sales`** (Ventas Internas / Historial)
|
|
||||||
|
|
||||||
* `user_id` (quién vendió).
|
|
||||||
* `client_id` (opcional, si es consumidor final anónimo).
|
|
||||||
* `total_amount`.
|
|
||||||
* `payment_method` (efectivo, tarjeta, transferencia).
|
|
||||||
* `created_at` (fecha de venta).
|
|
||||||
|
|
||||||
6. **`sale_items`** (Detalle de venta)
|
|
||||||
|
|
||||||
* `sale_id`, `product_id`, `quantity`, `unit_price`.
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
### 2\. Estructura de Rutas y Controladores (Backend)
|
|
||||||
|
|
||||||
En Laravel, organizaremos esto por "Dominios".
|
|
||||||
|
|
||||||
* **Autenticación:** (Ya lo tienes con Breeze/Jetstream).
|
|
||||||
* **DashboardController:**
|
|
||||||
* `index()`: Muestra las tarjetas, alertas de stock bajo (query simple `Product::whereColumn('stock', '<=', 'min_stock')->get()`) y turnos de hoy.
|
|
||||||
* **ProductController:**
|
|
||||||
* CRUD completo (Crear, Leer, Actualizar, Borrar).
|
|
||||||
* Función extra `search()`: Para el buscador de precios de los empleados.
|
|
||||||
* **ClientController:**
|
|
||||||
* CRUD simple.
|
|
||||||
* **AppointmentController (Gestión de Taller):**
|
|
||||||
* `calendar()`: Vista de calendario o lista cronológica.
|
|
||||||
* `statusUpdate()`: Para mover el turno de "Pendiente" a "Listo".
|
|
||||||
* **SaleController:**
|
|
||||||
* `create()`: Formulario para registrar una salida de mercadería.
|
|
||||||
* `store()`: Resta el stock y guarda la venta.
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
### 3\. Componentes de UI (Frontend - Blade + Tailwind)
|
|
||||||
|
|
||||||
Para mantener el estilo "Lauck" que ya definimos, necesitaremos crear estos componentes reutilizables (además de los que ya tienes):
|
|
||||||
|
|
||||||
1. **`x-ui.status-badge`**:
|
|
||||||
* Una etiqueta pequeña redondeada que cambia de color según el estado (Verde para 'Stock Alto', Rojo para 'Sin Stock' o 'Turno Atrasado', Amarillo para 'En Reparación').
|
|
||||||
2. **`x-ui.table`**:
|
|
||||||
* Una tabla estilizada con el modo oscuro, filas alternadas y cabeceras fijas. Vital para listas de precios y clientes.
|
|
||||||
3. **`x-forms.input` / `x-forms.select`**:
|
|
||||||
* Inputs con el estilo oscuro y borde neón al hacer foco, para no repetir las clases de Tailwind en cada formulario.
|
|
||||||
4. **`x-ui.alert`**:
|
|
||||||
* Para mostrar mensajes de éxito ("Producto guardado") o alertas ("¡Quedan solo 2 cámaras rodado 29\!").
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
### 4\. Funcionalidades Específicas a Implementar
|
|
||||||
|
|
||||||
Aquí está la lógica para los requerimientos que mencionaste:
|
|
||||||
|
|
||||||
#### A. Alertas de Stock ⚠️
|
|
||||||
|
|
||||||
* **Lógica:** No necesitas un sistema complejo de notificaciones en tiempo real todavía.
|
|
||||||
* **Implementación:** En el `DashboardController`, pasas una variable `$lowStockProducts` a la vista.
|
|
||||||
* **Vista:** En el Dashboard, si esa lista no está vacía, muestras una tarjeta roja o amarilla avisando "X productos con stock crítico".
|
|
||||||
|
|
||||||
#### B. Consulta de Precios (Modo Solo Lectura) 🔍
|
|
||||||
|
|
||||||
* **Requerimiento:** Empleados consultan, no editan.
|
|
||||||
* **Implementación:**
|
|
||||||
* Crear una vista `products.checker`.
|
|
||||||
* Un input de búsqueda grande en el centro.
|
|
||||||
* Al escribir (AJAX o Livewire sería ideal aquí, pero un form simple con botón "Buscar" funciona), muestra una tarjeta gigante con el Nombre y el Precio.
|
|
||||||
* *Seguridad:* Usar **Laravel Gates** o **Policies**.
|
|
||||||
```php
|
|
||||||
// En AuthServiceProvider
|
|
||||||
Gate::define('edit-products', function ($user) {
|
|
||||||
return $user->role === 'admin';
|
|
||||||
});
|
|
||||||
```
|
|
||||||
En Blade: `@can('edit-products') <button>Editar</button> @endcan`. Así el empleado ve el producto pero no el botón de editar.
|
|
||||||
|
|
||||||
#### C. Agenda de Turnos 📅
|
|
||||||
|
|
||||||
* **Lógica:** "Consulta -\> Cita".
|
|
||||||
* **Implementación:**
|
|
||||||
* No te compliques con un calendario visual complejo (tipo Google Calendar) al principio.
|
|
||||||
* Usa una **Lista Agrupada por Días**.
|
|
||||||
* *Ejemplo visual:*
|
|
||||||
* **HOY:**
|
|
||||||
* 09:00 - Jose (Pincharura) [Ver]
|
|
||||||
* 10:30 - Maria (Service General) [Ver]
|
|
||||||
* **MAÑANA:**
|
|
||||||
* ...
|
|
||||||
|
|
||||||
-----
|
|
||||||
|
|
||||||
### 5\. Roadmap Sugerido (Paso a Paso)
|
|
||||||
|
|
||||||
Este es el orden lógico para programar sin perderse:
|
|
||||||
|
|
||||||
1. **Semana 1: Cimientos y Stock (Lo más urgente)**
|
|
||||||
|
|
||||||
* Configurar Migraciones (`products`, `clients`).
|
|
||||||
* Crear Modelos y Seeders (datos falsos para probar).
|
|
||||||
* Hacer el CRUD de Productos (Alta, Baja y Modificación).
|
|
||||||
* *Hito:* Poder cargar una bicicleta y verla en la lista.
|
|
||||||
|
|
||||||
2. **Semana 2: Seguridad y Consultas**
|
|
||||||
|
|
||||||
* Agregar campo `role` a Users.
|
|
||||||
* Crear la vista "Consulta de Precios" (solo lectura).
|
|
||||||
* Proteger las rutas de edición para que solo el Admin entre.
|
|
||||||
* *Hito:* El empleado puede loguearse y buscar un precio, pero no borrar nada.
|
|
||||||
|
|
||||||
3. **Semana 3: El Taller (Turnos)**
|
|
||||||
|
|
||||||
* Crear migración `appointments`.
|
|
||||||
* Crear formulario para "Nuevo Turno" (Seleccionar Cliente + Fecha + Motivo).
|
|
||||||
* Crear vista de "Lista de Turnos" en el Dashboard.
|
|
||||||
* *Hito:* Dejar de usar el cuaderno de papel para los turnos.
|
|
||||||
|
|
||||||
4. **Semana 4: Refinamiento**
|
|
||||||
|
|
||||||
* Alertas de stock visuales.
|
|
||||||
* Mejoras estéticas (Dark Mode en tablas).
|
|
||||||
* Pruebas finales en el servidor local.
|
|
||||||
|
|
||||||
### ¿Cómo seguimos?
|
|
||||||
|
|
||||||
¿Te gustaría que generemos el código para la **Migración de Productos** y el **Modelo**, o prefieres que diseñemos primero el componente visual de la **Tabla de Stock**?
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
@section('main')
|
||||||
|
<h1>formulario de crear cliente</h1>
|
||||||
|
|
||||||
|
@endsection
|
||||||
@@ -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' : '')]) !!}>
|
<!-- Contenedor relativo para posicionar la flecha personalizada si quisiéramos (opcional) -->
|
||||||
<option value="">Seleccione</option>
|
<div class="relative">
|
||||||
@if ($options)
|
<select {{ $disabled ? 'disabled' : '' }} {!! $attributes->merge(['class' => '
|
||||||
@foreach ($options as $key => $op)
|
appearance-none bg-transparent border-0 border-b-2 border-neutral-700 text-white text-sm
|
||||||
<option value={{$key}}>{{$op}}</option>
|
py-2.5 px-0 w-full focus:outline-none focus:ring-0 focus:border-neon-lime peer cursor-pointer
|
||||||
@endforeach
|
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
|
@endif
|
||||||
</select>
|
</div>
|
||||||
@if($error)
|
|
||||||
<p class="mt-1 text-xs text-red-400">{{ $error }}</p>
|
{{--
|
||||||
@endif
|
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,11 +36,16 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<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>
|
||||||
<li>
|
<li>
|
||||||
<a href="{{url('/ventas')}}" 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="{{ route('sales.create') }}"
|
||||||
</li>
|
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>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<h1 class="font-black text-4xl md:text-5xl text-white uppercase italic">
|
<h1 class="font-black text-4xl md:text-5xl text-white uppercase italic">
|
||||||
{{ $title }}
|
{{ $title }}
|
||||||
@if($highlight)
|
@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
|
@endif
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</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>
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@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>
|
||||||
|
@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>
|
||||||
|
</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->precio }}">
|
||||||
|
{{ $product->codigo }} - {{ $product->nombre }} (${{ $product->precio }})
|
||||||
|
</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="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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script>
|
||||||
|
let itemIndex = 0;
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
inicializarSelect2();
|
||||||
|
});
|
||||||
|
|
||||||
|
function inicializarSelect2() {
|
||||||
|
$('.select2-enable').select2({
|
||||||
|
width: '100%',
|
||||||
|
placeholder: "Escribe para buscar...",
|
||||||
|
allowClear: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function agregarFila() {
|
||||||
|
itemIndex++;
|
||||||
|
const container = document.getElementById('items-container');
|
||||||
|
const firstRow = container.querySelector('.item-row');
|
||||||
|
|
||||||
|
// 1. Destruimos Select2 temporalmente para clonar limpio
|
||||||
|
$('.select2-enable').select2('destroy');
|
||||||
|
|
||||||
|
// 2. Clonamos
|
||||||
|
const newRow = firstRow.cloneNode(true);
|
||||||
|
|
||||||
|
// 3. Reactivamos en los originales
|
||||||
|
inicializarSelect2();
|
||||||
|
|
||||||
|
// Limpiamos valores de la copia
|
||||||
|
const select = newRow.querySelector('select');
|
||||||
|
const input = newRow.querySelector('input');
|
||||||
|
const subtotal = newRow.querySelector('.row-subtotal');
|
||||||
|
|
||||||
|
select.name = `items[${itemIndex}][product_id]`;
|
||||||
|
select.value = "";
|
||||||
|
|
||||||
|
input.name = `items[${itemIndex}][quantity]`;
|
||||||
|
input.value = 1;
|
||||||
|
|
||||||
|
subtotal.innerText = "0.00";
|
||||||
|
|
||||||
|
// Botón Eliminar
|
||||||
|
const deleteBtnDiv = newRow.querySelector('div:last-child');
|
||||||
|
deleteBtnDiv.innerHTML = `
|
||||||
|
<button type="button" onclick="eliminarFila(this)" class="text-red-500 hover:text-red-700">
|
||||||
|
<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>
|
||||||
|
`;
|
||||||
|
|
||||||
|
container.appendChild(newRow);
|
||||||
|
|
||||||
|
// 4. Inicializamos en el nuevo
|
||||||
|
inicializarSelect2();
|
||||||
|
|
||||||
|
// Evento extra para Select2
|
||||||
|
$(select).on('select2:select', function (e) {
|
||||||
|
calcularTotal();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function eliminarFila(button) {
|
||||||
|
const row = button.closest('.item-row');
|
||||||
|
row.remove();
|
||||||
|
calcularTotal();
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcularTotal() {
|
||||||
|
let total = 0;
|
||||||
|
const rows = document.querySelectorAll('.item-row');
|
||||||
|
|
||||||
|
rows.forEach(row => {
|
||||||
|
const select = row.querySelector('.product-select');
|
||||||
|
const input = row.querySelector('.quantity-input');
|
||||||
|
const subtotalSpan = row.querySelector('.row-subtotal');
|
||||||
|
|
||||||
|
const selectedOption = $(select).find(':selected');
|
||||||
|
const price = parseFloat(selectedOption.attr('data-price')) || 0;
|
||||||
|
const quantity = parseInt(input.value) || 0;
|
||||||
|
|
||||||
|
const subtotal = price * quantity;
|
||||||
|
subtotalSpan.innerText = subtotal.toFixed(2);
|
||||||
|
|
||||||
|
total += subtotal;
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('total-display').innerText = total.toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on('select2:select', '.product-select', function (e) {
|
||||||
|
calcularTotal();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
@endsection
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>Document</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Gwssssssssssssssss</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+8
-1
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\AuthController;
|
use App\Http\Controllers\AuthController;
|
||||||
use App\Http\Controllers\CatalogoController;
|
use App\Http\Controllers\CatalogoController;
|
||||||
|
use App\Http\Controllers\SaleController;
|
||||||
|
use App\Http\Controllers\ClientController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\HomeController;
|
use App\Http\Controllers\HomeController;
|
||||||
use App\Http\Controllers\LoginController;
|
use App\Http\Controllers\LoginController;
|
||||||
@@ -41,9 +43,14 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
Route::resource('productos', ProductosController::class)->parameters([
|
Route::resource('productos', ProductosController::class)->parameters([
|
||||||
'productos' => 'producto'
|
'productos' => 'producto'
|
||||||
]);
|
]);
|
||||||
Route::get('/productos',[ProductosController::class,'index'])->name('productos.index');
|
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('/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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Route::get('/catalogo', [CatalogoController::class,'catalogo'])->name('catalogo');
|
Route::get('/catalogo', [CatalogoController::class,'catalogo'])->name('catalogo');
|
||||||
Route::get('/productos/{id}/vistaUsuario', [ProductosController::class,'vistaUsuario'])->name('productos.vistaUsuario');
|
Route::get('/productos/{id}/vistaUsuario', [ProductosController::class,'vistaUsuario'])->name('productos.vistaUsuario');
|
||||||
Reference in New Issue
Block a user