Browse Source

Reapply "Prestamos aceptados"

This reverts commit 5fe7ff7b42.
main^2
TheSilva7 4 days ago
parent
commit
4df1bfed90
  1. 52
      app/Http/Controllers/PrestamoController.php
  2. 28
      database/migrations/2025_03_28_175646_add_estado_to_prestamos_table.php
  3. 28
      database/migrations/2025_03_28_182126_add_estado_to_prestamos_table.php
  4. 28
      database/migrations/2025_03_28_183038_add_estado_to_prestamos_table.php
  5. 6
      resources/views/layouts/navigation.blade.php
  6. 38
      resources/views/prestamos.blade.php
  7. 163
      resources/views/prestamos/aceptados.blade.php
  8. 3
      routes/web.php

52
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.');
}
}

28
database/migrations/2025_03_28_175646_add_estado_to_prestamos_table.php

@ -0,0 +1,28 @@
<?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::table('prestamos', function (Blueprint $table) {
//
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('prestamos', function (Blueprint $table) {
//
});
}
};

28
database/migrations/2025_03_28_182126_add_estado_to_prestamos_table.php

@ -0,0 +1,28 @@
<?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::table('prestamos', function (Blueprint $table) {
//
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('prestamos', function (Blueprint $table) {
//
});
}
};

28
database/migrations/2025_03_28_183038_add_estado_to_prestamos_table.php

@ -0,0 +1,28 @@
<?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::table('prestamos', function (Blueprint $table) {
$table->string('estado')->default('pendiente'); // pendiente, aceptado, rechazado
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('prestamos', function (Blueprint $table) {
$table->dropColumn('estado');
});
}
};

6
resources/views/layouts/navigation.blade.php

@ -0,0 +1,6 @@
<x-nav-link :href="route('prestamos.index')" :active="request()->routeIs('prestamos.index')">
{{ __('Préstamos') }}
</x-nav-link>
<x-nav-link :href="route('prestamos.aceptados')" :active="request()->routeIs('prestamos.aceptados')">
{{ __('Préstamos Aceptados') }}
</x-nav-link>

38
resources/views/prestamos.blade.php

@ -149,21 +149,31 @@
<i class="fas fa-check-circle mr-1"></i> Activo
</span>
</td>
<td class="flex space-x-2 px-6 py-4 whitespace-nowrap text-sm">
<a href="{{ route('prestamos.edit', $prestamo->id) }}"
class="text-yellow-600 hover:text-yellow-700 transition-colors duration-200"
title="Editar préstamo">
<i class="fas fa-pencil-alt"></i>
</a>
<form action="{{ route('prestamos.destroy', $prestamo->id) }}" method="POST" class="d-inline">
@csrf
@method('DELETE')
<a href="#" onclick="event.preventDefault(); confirmarEliminacion(this);"
class="text-red-600 hover:text-red-700 transition-colors duration-200"
title="Eliminar préstamo">
<i class="fas fa-trash-alt"></i>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<div class="flex space-x-2">
<a href="{{ route('prestamos.edit', $prestamo->id) }}" class="text-blue-600 hover:text-blue-900">
<i class="fas fa-edit"></i>
</a>
</form>
<form action="{{ route('prestamos.destroy', $prestamo->id) }}" method="POST" class="inline">
@csrf
@method('DELETE')
<button type="submit" class="text-red-600 hover:text-red-900" onclick="return confirm('¿Estás seguro de que deseas eliminar este préstamo?')">
<i class="fas fa-trash"></i>
</button>
</form>
<form action="{{ route('prestamos.aceptar', $prestamo->id) }}" method="POST" class="inline">
@csrf
<button type="submit" class="text-green-600 hover:text-green-900" onclick="return confirm('¿Estás seguro de que deseas aceptar este préstamo?')">
<i class="fas fa-check"></i>
</button>
</form>
<form action="{{ route('prestamos.rechazar', $prestamo->id) }}" method="POST" class="inline">
@csrf
<button type="submit" class="text-yellow-600 hover:text-yellow-900" onclick="return confirm('¿Estás seguro de que deseas rechazar este préstamo?')">
<i class="fas fa-times"></i>
</button>
</form>
</div>
</td>
</tr>
@endforeach

163
resources/views/prestamos/aceptados.blade.php

@ -0,0 +1,163 @@
@extends('layouts.dashboard')
@section('content')
<div class="container mx-auto px-4 py-6">
<!-- Mensajes de éxito y error -->
@if(session('success'))
<div id="success-message" class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4" role="alert">
<span class="block sm:inline">{{ session('success') }}</span>
</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" role="alert">
<span class="block sm:inline">{{ session('error') }}</span>
</div>
@endif
<div class="bg-white rounded-lg shadow-lg">
<!-- Encabezado con título y botones de acción -->
<div class="p-4 border-b border-gray-200 flex justify-between items-center">
<h2 class="text-2xl font-bold">Préstamos Aceptados</h2>
<div class="flex items-center space-x-6">
<!-- Íconos de exportación -->
<div class="flex space-x-4">
<!-- Exportar a Excel -->
<a href="{{ route('prestamos.excel') }}?estado=aceptado" class="text-green-600 hover:text-green-800 text-2xl">
<i class="fas fa-file-excel"></i>
</a>
<!-- Exportar a PDF -->
<a href="{{ route('prestamos.pdf') }}?estado=aceptado" class="text-red-600 hover:text-red-800 text-2xl">
<i class="fas fa-file-pdf"></i>
</a>
</div>
</div>
</div>
<!-- Barra de búsqueda -->
<div class="p-4 border-b border-gray-200 bg-gray-50">
<form action="{{ route('prestamos.aceptados') }}" method="GET" class="flex gap-2">
<div class="relative w-full sm:w-64">
<input type="text"
name="busqueda"
placeholder="Buscar préstamo..."
value="{{ request('busqueda') }}"
class="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<div class="absolute left-3 top-2.5 text-gray-400">
<i class="fas fa-search"></i>
</div>
</div>
<button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600">
Buscar
</button>
@if(request('busqueda'))
<a href="{{ route('prestamos.aceptados') }}" class="px-4 py-2 bg-gray-500 text-white rounded-lg hover:bg-gray-600">
Limpiar
</a>
@endif
</form>
</div>
<!-- Tabla de préstamos -->
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Número</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nombre Solicitante</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Destino</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Fecha y Hora Salida</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Fecha y Hora Llegada</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Motivo</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Domicilio</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Número de Personas</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Chofer</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acciones</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach($prestamos as $index => $prestamo)
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<span class="font-medium">{{ $index + 1 }}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<div class="flex items-center">
<i class="fas fa-user text-blue-500 mr-2"></i>
{{ $prestamo->nombre_solicitante }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<div class="flex items-center">
<i class="fas fa-map-marker-alt text-red-500 mr-2"></i>
{{ $prestamo->destino }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<div class="flex items-center">
<i class="fas fa-clock text-green-500 mr-2"></i>
{{ \Carbon\Carbon::parse($prestamo->fecha_hora_salida)->format('d/m/Y H:i') }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<div class="flex items-center">
<i class="fas fa-clock text-red-500 mr-2"></i>
{{ \Carbon\Carbon::parse($prestamo->fecha_hora_llegada)->format('d/m/Y H:i') }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<div class="flex items-center">
<i class="fas fa-info-circle text-blue-500 mr-2"></i>
{{ $prestamo->motivo }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<div class="flex items-center">
<i class="fas fa-home text-purple-500 mr-2"></i>
{{ $prestamo->domicilio }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<div class="flex items-center">
<i class="fas fa-users text-yellow-500 mr-2"></i>
{{ $prestamo->numero_personas }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<div class="flex items-center">
<i class="fas fa-id-card text-gray-500 mr-2"></i>
{{ $prestamo->chofer ? 'Sí' : 'No' }}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<div class="flex space-x-2">
<a href="{{ route('prestamos.edit', $prestamo->id) }}" class="text-blue-600 hover:text-blue-900">
<i class="fas fa-edit"></i>
</a>
<form action="{{ route('prestamos.destroy', $prestamo->id) }}" method="POST" class="inline">
@csrf
@method('DELETE')
<button type="submit" class="text-red-600 hover:text-red-900" onclick="return confirm('¿Estás seguro de que deseas eliminar este préstamo?')">
<i class="fas fa-trash"></i>
</button>
</form>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
<script>
// Ocultar el mensaje de éxito después de 3 segundos
setTimeout(function() {
const successMessage = document.getElementById('success-message');
if (successMessage) {
successMessage.style.display = 'none';
}
}, 3000);
</script>
@endsection

3
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);

Loading…
Cancel
Save