Browse Source

EXEL,PDF,AGREGAR (ICONOS)

ya estan funcionales los botones, solo al de pdf y exel faltan un pequeño ajuste
main
Rubi 6 days ago
parent
commit
d31e874447
  1. 35
      app/Exports/tiposLicenciasExport.php
  2. 17
      app/Http/Controllers/TiposLicenciasController.php
  3. 44
      resources/views/exports/tiposLicencias-pdf.blade.php
  4. 146
      resources/views/tiposLicencia.blade.php
  5. 5
      routes/web.php

35
app/Exports/tiposLicenciasExport.php

@ -0,0 +1,35 @@
<?php
namespace App\Exports;
use App\Models\tiposLicencias;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class TiposLicenciasExport implements FromCollection, WithHeadings
{
/**
* Método que devuelve la colección de datos a exportar.
*
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return tiposLicencias::where('eliminado', 0) // Solo marcas activas
->select('id', 'tipoLicencia') // Selecciona los campos que deseas exportar
->get();
}
/**
* Método que define los encabezados de las columnas en el archivo Excel.
*
* @return array
*/
public function headings(): array
{
return [
'ID', // Encabezado para la columna ID
'Tipo de licencia', // Encabezado para la columna Tipo de licencia
];
}
}

17
app/Http/Controllers/TiposLicenciasController.php

@ -3,6 +3,9 @@
namespace App\Http\Controllers;
use App\Models\tiposLicencias;
use App\Exports\TiposLicenciasExport;
use PDF;
use Excel;
use Illuminate\Http\Request;
@ -101,4 +104,16 @@ class TiposLicenciasController extends Controller
$tipoLicencia->save();
return redirect()->route('tiposLicencias.index')->with('success', 'Tipo de licencia eliminado exitosamente.');
}
}
public function exportExcel()
{
return Excel::download(new tiposLicenciasExport(), 'tiposLicencias.xlsx');
}
public function exportPDF()
{
$marcas = tiposLicencias::where('eliminado', 0)->get();
$pdf = PDF::loadView('exports.tiposlicencias-pdf', ['tiposlicencias' => $marcas]);
return $pdf->download('tiposlicencias.pdf');
}
}

44
resources/views/exports/tiposLicencias-pdf.blade.php

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>Lista de tiposLicencias</title>
<style>
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
h2 {
color: #333;
margin-bottom: 20px;
}
</style>
</head>
<body>
<h2>Lista de tiposLicencias</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>tipoLicencias</th>
</tr>
</thead>
<tbody>
@foreach($tiposlicencias as $tiposlicencias)
<tr>
<td>{{ $tiposlicencias->id }}</td>
<td>{{ $tiposlicencias->tiposlicencias }}</td>
</tr>
@endforeach
</tbody>
</table>
</body>
</html>

146
resources/views/tiposLicencia.blade.php

@ -2,7 +2,7 @@
@section('content')
<div class="container mx-auto px-4 py-6">
<!-- Encabezado -->
<!-- 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>
@ -16,13 +16,34 @@
@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">Gestión de Tipos de Licencias</h2>
<a href="{{ route('tiposLicencias.create') }}"
class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 flex items-center gap-2">
<i class="fas fa-plus"></i>
Agregar
</a>
<div class="flex items-center space-x-6">
<!-- Íconos de exportación y agregar -->
<div class="flex space-x-4">
<!-- Exportar a Excel -->
<a href="{{ route('tiposLicencias.excel') }}"
class="text-green-600 hover:text-green-700 transition-colors duration-200"
title="Exportar a Excel">
<i class="fas fa-file-excel text-xl"></i>
</a>
<!-- Exportar a PDF -->
<a href="{{ route('tiposLicencias.pdf') }}"
class="text-red-600 hover:text-red-700 transition-colors duration-200"
title="Exportar a PDF">
<i class="fas fa-file-pdf text-xl"></i>
</a>
<!-- Agregar nuevo tipo de licencia -->
<a href="{{ route('tiposLicencias.create') }}"
class="text-blue-500 hover:text-blue-600 transition-colors duration-200"
title="Agregar nuevo tipo de licencia">
<i class="fas fa-plus text-xl"></i>
</a>
</div>
</div>
</div>
<!-- Barra de búsqueda -->
@ -49,12 +70,14 @@
</form>
</div>
<!-- Tabla de tipos de licencias -->
<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">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Tipo de Licencia</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Estado</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Acciones</th>
</tr>
</thead>
@ -63,31 +86,46 @@
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $tipoLicencia->id }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
<i class="fas fa-car text-blue-500 mr-2"></i>
<i class="fas fa-id-card text-blue-500 mr-2"></i>
{{ $tipoLicencia->tipoLicencia }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
@if($tipoLicencia->eliminado == 1)
<span class="flex items-center">
<span class="h-2 w-2 bg-green-500 rounded-full mr-2"></span> Activo
</span>
@else
<span class="flex items-center">
<span class="h-2 w-2 bg-red-500 rounded-full mr-2"></span> Inactivo
</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<div class="flex gap-2">
<a href="{{ route('tiposLicencias.edit', $tipoLicencia->id) }}"
class="text-blue-600 hover:text-blue-900">
<i class="fas fa-edit"></i>
</a>
<a href="{{ route('tiposLicencias.toggle-status', $tipoLicencia->id) }}"
class="{{ $tipoLicencia->eliminado ? 'text-green-600 hover:text-green-900' : 'text-yellow-600 hover:text-yellow-900' }}">
<i class="fas {{ $tipoLicencia->eliminado ? 'fa-check-circle' : 'fa-times-circle' }}"></i>
</a>
<form action="{{ route('tiposLicencias.destroy', $tipoLicencia->id) }}"
method="POST"
class="inline"
onsubmit="return false;">
@csrf
@method('DELETE')
<button type="button"
onclick="confirmarEliminacion(this)"
class="text-red-600 hover:text-red-900">
<i class="fas fa-trash"></i>
</button>
</form>
@if($tipoLicencia->eliminado == 0)
<a href="{{ route('tiposLicencias.toggle-status', $tipoLicencia->id) }}"
class="text-green-600 hover:text-green-700 transition-colors duration-200"
title="Recuperar tipo de licencia">
<i class="fas fa-undo"></i>
</a>
@else
<a href="{{ route('tiposLicencias.edit', $tipoLicencia->id) }}"
class="text-yellow-600 hover:text-yellow-700 transition-colors duration-200"
title="Editar tipo de licencia">
<i class="fas fa-edit"></i>
</a>
<form action="{{ route('tiposLicencias.destroy', $tipoLicencia->id) }}"
method="POST"
class="inline">
@csrf
@method('DELETE')
<button type="submit"
class="text-red-600 hover:text-red-700 transition-colors duration-200"
title="Eliminar tipo de licencia">
<i class="fas fa-trash"></i>
</button>
</form>
@endif
</div>
</td>
</tr>
@ -99,50 +137,16 @@
</div>
<script>
function confirmarEdicion(url) {
Swal.fire({
title: '¿Editar tipo de licencia?',
text: "¿Estás seguro de que deseas editar este tipo de licencia?",
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Sí, editar',
cancelButtonText: 'Cancelar'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = url;
// Desaparecer el mensaje después de 3 segundos
setTimeout(function() {
var message = document.getElementById('success-message');
if (message) {
message.style.transition = 'opacity 0.5s ease';
message.style.opacity = '0';
setTimeout(function() {
message.remove();
}, 500);
}
});
}
function confirmarEliminacion(button) {
Swal.fire({
title: '¿Estás seguro?',
text: "Esta acción no se puede deshacer",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Sí, eliminar',
cancelButtonText: 'Cancelar'
}).then((result) => {
if (result.isConfirmed) {
button.closest('form').onsubmit = null;
button.closest('form').submit();
}
});
}
// Desaparecer el mensaje después de 3 segundos
setTimeout(function() {
var message = document.getElementById('success-message');
if (message) {
message.style.transition = 'opacity 0.5s ease';
message.style.opacity = '0';
setTimeout(function() {
message.remove();
}, 500); // Tiempo para remover el elemento después de la transición
}
}, 3000); // Tiempo en milisegundos antes de comenzar a desaparecer
}, 3000);
</script>
@endsection

5
routes/web.php

@ -35,6 +35,8 @@ Route::resource('vehiculos', TiposVeiculosController::class);
Route::resource('tiposLicencias', TiposLicenciasController::class);
Route::get('tiposLicencias/excel', [TiposLicenciasController::class, 'exportExcel'])->name('tiposLicencias.excel');
Route::get('tiposLicencias/pdf', [TiposLicenciasController::class, 'exportPDF'])->name('tiposLicencias.pdf');
Route::get('/tiposLicencias/{id}/toggle-status', [TiposLicenciasController::class, 'toggleStatus'])->name('tiposLicencias.toggle-status');
Route::resource('capacidades', CapacidadController::class);
@ -45,6 +47,9 @@ Route::get('marcas/pdf', [MarcaController::class, 'exportPDF'])->name('marcas.pd
Route::get('/docentes/export/{format}', [DocentesController::class, 'export'])->name('docentes.export');
Route::get('/docentes/{id}/toggle-status', [DocentesController::class, 'toggleStatus'])->name('docentes.toggle-status');
Route::get('tiposLicencias/excel', [TiposLicenciasController::class, 'exportExcel'])->name('tiposLicencias.excel');
Route::get('tiposLicencias/pdf', [TiposLicenciasController::class, 'exportPDF'])->name('tiposLicencias.pdf');
// Rutas protegidas que requieren autenticación
Route::middleware(['auth'])->group(function () {
Route::get('/dashboard', [HomeController::class, 'index'])->name('dashboard');

Loading…
Cancel
Save