diff --git a/app/Http/Controllers/PrestamoController.php b/app/Http/Controllers/PrestamoController.php index 3014c21..904cb9b 100644 --- a/app/Http/Controllers/PrestamoController.php +++ b/app/Http/Controllers/PrestamoController.php @@ -21,15 +21,18 @@ class PrestamoController extends Controller // Busca en la columna 'nombre_solicitante' de la tabla 'prestamos' $prestamos = Prestamo::where('nombre_solicitante', 'LIKE', "%{$busqueda}%") ->where('eliminado', 0) + ->where('estado', 'pendiente') ->get(); if ($prestamos->isEmpty()) { - return redirect()->route('prestamo.index') + return redirect()->route('prestamos.index') ->with('error', 'No existe ningún préstamo con el solicitante "' . $busqueda . '". Por favor, inténtalo de nuevo.'); } } else { - // Si no hay búsqueda, mostrar todos los préstamos - $prestamos = Prestamo::where('eliminado', 0)->get(); + // Si no hay búsqueda, mostrar todos los préstamos pendientes + $prestamos = Prestamo::where('eliminado', 0) + ->where('estado', 'pendiente') + ->get(); } return view('prestamos', ['prestamos' => $prestamos]); @@ -142,4 +145,47 @@ class PrestamoController extends Controller $pdf = PDF::loadView('exports.prestamos-pdf', ['prestamos' => $prestamos]); return $pdf->download('prestamos.pdf'); } + + public function aceptados(Request $request) + { + $busqueda = $request->busqueda; + + if ($busqueda) { + $prestamos = Prestamo::where('nombre_solicitante', 'LIKE', "%{$busqueda}%") + ->where('eliminado', 0) + ->where('estado', 'aceptado') + ->get(); + + if ($prestamos->isEmpty()) { + return redirect()->route('prestamos.aceptados') + ->with('error', 'No existe ningún préstamo aceptado con el solicitante "' . $busqueda . '". Por favor, inténtalo de nuevo.'); + } + } else { + $prestamos = Prestamo::where('eliminado', 0) + ->where('estado', 'aceptado') + ->get(); + } + + return view('prestamos.aceptados', ['prestamos' => $prestamos]); + } + + public function aceptar($id) + { + $prestamo = Prestamo::findOrFail($id); + $prestamo->estado = 'aceptado'; + $prestamo->save(); + + return redirect()->route('prestamos.index') + ->with('success', 'Préstamo aceptado exitosamente.'); + } + + public function rechazar($id) + { + $prestamo = Prestamo::findOrFail($id); + $prestamo->estado = 'rechazado'; + $prestamo->save(); + + return redirect()->route('prestamos.index') + ->with('success', 'Préstamo rechazado exitosamente.'); + } } diff --git a/database/migrations/2025_03_28_175646_add_estado_to_prestamos_table.php b/database/migrations/2025_03_28_175646_add_estado_to_prestamos_table.php new file mode 100644 index 0000000..af9986e --- /dev/null +++ b/database/migrations/2025_03_28_175646_add_estado_to_prestamos_table.php @@ -0,0 +1,28 @@ +string('estado')->default('pendiente'); // pendiente, aceptado, rechazado + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('prestamos', function (Blueprint $table) { + $table->dropColumn('estado'); + }); + } +}; diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php new file mode 100644 index 0000000..83cf3d8 --- /dev/null +++ b/resources/views/layouts/navigation.blade.php @@ -0,0 +1,6 @@ + + {{ __('Préstamos') }} + + + {{ __('Préstamos Aceptados') }} + \ No newline at end of file diff --git a/resources/views/prestamos.blade.php b/resources/views/prestamos.blade.php index 8b18c89..dbc3f69 100644 --- a/resources/views/prestamos.blade.php +++ b/resources/views/prestamos.blade.php @@ -149,21 +149,31 @@ Activo - - - - -
- @csrf - @method('DELETE') - - + +
+ + - +
+ @csrf + @method('DELETE') + +
+
+ @csrf + +
+
+ @csrf + +
+
@endforeach diff --git a/resources/views/prestamos/aceptados.blade.php b/resources/views/prestamos/aceptados.blade.php new file mode 100644 index 0000000..2d5e6eb --- /dev/null +++ b/resources/views/prestamos/aceptados.blade.php @@ -0,0 +1,163 @@ +@extends('layouts.dashboard') + +@section('content') +
+ + @if(session('success')) + + @endif + + @if(session('error')) + + @endif + +
+ +
+

Préstamos Aceptados

+
+ +
+ + + + + + + + +
+
+
+ + +
+
+
+ +
+ +
+
+ + @if(request('busqueda')) + + Limpiar + + @endif +
+
+ + +
+ + + + + + + + + + + + + + + + + @foreach($prestamos as $index => $prestamo) + + + + + + + + + + + + + @endforeach + +
NúmeroNombre SolicitanteDestinoFecha y Hora SalidaFecha y Hora LlegadaMotivoDomicilioNúmero de PersonasChoferAcciones
+ {{ $index + 1 }} + +
+ + {{ $prestamo->nombre_solicitante }} +
+
+
+ + {{ $prestamo->destino }} +
+
+
+ + {{ \Carbon\Carbon::parse($prestamo->fecha_hora_salida)->format('d/m/Y H:i') }} +
+
+
+ + {{ \Carbon\Carbon::parse($prestamo->fecha_hora_llegada)->format('d/m/Y H:i') }} +
+
+
+ + {{ $prestamo->motivo }} +
+
+
+ + {{ $prestamo->domicilio }} +
+
+
+ + {{ $prestamo->numero_personas }} +
+
+
+ + {{ $prestamo->chofer ? 'Sí' : 'No' }} +
+
+
+ + + +
+ @csrf + @method('DELETE') + +
+
+
+
+
+
+ + +@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 6ef6a41..2819d88 100644 --- a/routes/web.php +++ b/routes/web.php @@ -51,6 +51,9 @@ use App\Http\Controllers\PrestamoController; // Primero las rutas de exportación (más específicas) Route::get('/prestamos/excel', [PrestamoController::class, 'exportExcel'])->name('prestamos.excel'); Route::get('/prestamos/pdf', [PrestamoController::class, 'exportPDF'])->name('prestamos.pdf'); + Route::get('/prestamos/aceptados', [PrestamoController::class, 'aceptados'])->name('prestamos.aceptados'); + Route::post('/prestamos/{id}/aceptar', [PrestamoController::class, 'aceptar'])->name('prestamos.aceptar'); + Route::post('/prestamos/{id}/rechazar', [PrestamoController::class, 'rechazar'])->name('prestamos.rechazar'); // Después la ruta de recurso (más general) Route::resource('prestamos', PrestamoController::class);