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