Browse Source

nuevas funciones

falta el exel y tambien la paginacion pero ya esta el pdf y cambio de iconos
main
sergiomarquez778 7 days ago
parent
commit
c4ead4f8a9
  1. 35
      app/Exports/MarcasExport.php
  2. 15
      app/Http/Controllers/MarcaController.php
  3. 5
      composer.json
  4. 1183
      composer.lock
  5. 44
      resources/views/exports/marcas-pdf.blade.php
  6. 77
      resources/views/marcas.blade.php
  7. 3
      routes/web.php

35
app/Exports/MarcasExport.php

@ -0,0 +1,35 @@
<?php
namespace App\Exports;
use App\Models\Marca;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class MarcasExport implements FromCollection, WithHeadings
{
/**
* Método que devuelve la colección de datos a exportar.
*
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return Marca::where('eliminado', 0) // Solo marcas activas
->select('id', 'marca') // 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
'Marca', // Encabezado para la columna Marca
];
}
}

15
app/Http/Controllers/MarcaController.php

@ -4,6 +4,9 @@ namespace App\Http\Controllers;
use App\Models\Marca;
use Illuminate\Http\Request;
use App\Exports\MarcasExport;
use Maatwebsite\Excel\Facades\Excel;
use PDF;
class MarcaController extends Controller
{
@ -85,4 +88,16 @@ class MarcaController extends Controller
return redirect()->route('marca.index')->with('success', 'Marca inactivada correctamente.');
}
public function exportExcel()
{
return Excel::download(new MarcasExport, 'marcas.xlsx');
}
public function exportPDF()
{
$marcas = Marca::where('eliminado', 0)->get();
$pdf = PDF::loadView('exports.marcas-pdf', ['marcas' => $marcas]);
return $pdf->download('marcas.pdf');
}
}

5
composer.json

@ -6,11 +6,14 @@
"license": "MIT",
"require": {
"php": "^8.1",
"barryvdh/laravel-dompdf": "^3.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"laravel/ui": "^4.6"
"laravel/ui": "^4.6",
"maatwebsite/excel": "^3.1",
"phpoffice/phpspreadsheet": "^4.1"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

1183
composer.lock

File diff suppressed because it is too large

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

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>Lista de Marcas</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 Marcas</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Marca</th>
</tr>
</thead>
<tbody>
@foreach($marcas as $marca)
<tr>
<td>{{ $marca->id }}</td>
<td>{{ $marca->marca }}</td>
</tr>
@endforeach
</tbody>
</table>
</body>
</html>

77
resources/views/marcas.blade.php

@ -2,8 +2,6 @@
@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">
@ -18,15 +16,38 @@
@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 Marcas</h2>
<a href="{{ route('marca.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('marcas.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('marcas.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 nueva marca -->
<a href="{{ route('marca.create') }}"
class="text-blue-500 hover:text-blue-600 transition-colors duration-200"
title="Agregar nueva marca">
<i class="fas fa-plus text-xl"></i>
</a>
</div>
</div>
</div>
<!-- Barra de búsqueda -->
<div class="p-4 border-b border-gray-200 bg-gray-50">
<!-- Barra de búsqueda -->
<div class="p-4 border-b border-gray-200 bg-gray-50">
<form action="{{ route('marca.index') }}" method="GET" class="flex gap-2">
<div class="relative w-full sm:w-64">
<input type="text"
@ -49,13 +70,14 @@
</form>
</div>
<!-- Tabla de marcas -->
<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">Marca</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>
@ -67,8 +89,7 @@
<i class="fas fa-car text-blue-500 mr-2"></i>
{{ $marca->marca }}
</td>
{{-- todo esto funciona para mostrar el estatus de tiempo real de la actividad
<td class="px-6 py-4 whitespace-nowrap text-sm">
<td class="px-6 py-4 whitespace-nowrap text-sm">
@if($marca->eliminado == 0)
<span class="flex items-center">
<span class="h-2 w-2 bg-green-500 rounded-full mr-2"></span> Activo
@ -78,26 +99,32 @@
<span class="h-2 w-2 bg-red-500 rounded-full mr-2"></span> Inactivo
</span>
@endif
</td>--}}
</td>
<td class="flex space-x-2 px-6 py-4 whitespace-nowrap text-sm">
@if($marca->eliminado == 1)
<form action="{{ route('marca.update', $marca->id) }}" method="POST" class="d-inline">
@csrf
@method('PUT')
<input type="hidden" name="recuperar" value="1">
<a href="#" onclick="event.preventDefault(); this.closest('form').submit();" class="text-success">
<i class="fas fa-undo" style="color: green;"></i>
<a href="#" onclick="event.preventDefault(); this.closest('form').submit();"
class="text-green-600 hover:text-green-700 transition-colors duration-200"
title="Recuperar marca">
<i class="fas fa-undo"></i>
</a>
</form>
@else
<a href="{{ route('marca.edit', $marca->id) }}" class="text-warning">
<i class="fas fa-edit" style="color: orange;"></i>
<a href="{{ route('marca.edit', $marca->id) }}"
class="text-yellow-600 hover:text-yellow-700 transition-colors duration-200"
title="Editar marca">
<i class="fas fa-edit"></i>
</a>
<form action="{{ route('marca.destroy', $marca->id) }}" method="POST" class="d-inline">
@csrf
@method('DELETE')
<a href="#" onclick="event.preventDefault(); this.closest('form').submit();" class="text-danger">
<i class="fas fa-trash" style="color: red;"></i>
<a href="#" onclick="event.preventDefault(); this.closest('form').submit();"
class="text-red-600 hover:text-red-700 transition-colors duration-200"
title="Eliminar marca">
<i class="fas fa-trash"></i>
</a>
</form>
@endif
@ -119,18 +146,8 @@
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
setTimeout(function() {
var noResultsMessage = document.getElementById('no-results-message');
if (noResultsMessage) {
noResultsMessage.style.transition = 'opacity 0.5s ease';
noResultsMessage.style.opacity = '0';
setTimeout(function() {
noResultsMessage.remove();
}, 500); // Tiempo para remover el elemento después de la transición
}, 500);
}
}, 3000); // Tiempo en milisegundos antes de comenzar a desaparecer
}, 3000);
</script>
@endsection

3
routes/web.php

@ -38,6 +38,9 @@ Route::resource('tiposLicencias', TiposLicenciasController::class);
Route::resource('capacidades', CapacidadController::class);
Route::get('marcas/excel', [MarcaController::class, 'exportExcel'])->name('marcas.excel');
Route::get('marcas/pdf', [MarcaController::class, 'exportPDF'])->name('marcas.pdf');
// Rutas protegidas que requieren autenticación

Loading…
Cancel
Save