- Agregada libreria Dompdf para generar PDFs - Creada clase PDFGenerator con metodos reutilizables - Pagina de exportacion para ayudantes (mis-turnos.pdf) - Pagina de exportacion para admin (reporte-admin.pdf) - Boton Exportar PDF en pagina de ayudantes y admin - Corregido bug en getAsignacionActual() para usar domingo como inicio de semana
96 lines
3.4 KiB
PHP
96 lines
3.4 KiB
PHP
<?php
|
|
if (!defined('BASE_PATH')) {
|
|
define('BASE_PATH', dirname(__DIR__, 2));
|
|
}
|
|
require_once BASE_PATH . '/config/config.php';
|
|
require_once BASE_PATH . '/src/Auth.php';
|
|
require_once BASE_PATH . '/src/User.php';
|
|
require_once BASE_PATH . '/src/DiasHorarios.php';
|
|
require_once BASE_PATH . '/src/Asignacion.php';
|
|
require_once BASE_PATH . '/src/PDFGenerator.php';
|
|
|
|
$auth = new Auth();
|
|
$auth->requireAdmin();
|
|
|
|
$userModel = new User();
|
|
$horariosModel = new DiasHorarios();
|
|
$asignacionModel = new Asignacion();
|
|
$db = \Database::getInstance()->getConnection();
|
|
|
|
$totalUsuarios = count($userModel->getAll());
|
|
$totalAyudantes = count($userModel->getAyudantesActivos());
|
|
$totalHorarios = count($horariosModel->getAll());
|
|
$asignacionActual = $asignacionModel->getAsignacionActual();
|
|
|
|
$ayudantes = $userModel->getAyudantesActivos();
|
|
$horarios = $horariosModel->getAll();
|
|
$asignaciones = $asignacionModel->getTodasAsignaciones();
|
|
|
|
$html = PDFGenerator::getStyles();
|
|
$html .= PDFGenerator::getHeader('Reporte de Administración');
|
|
|
|
$html .= '<h2>Estadísticas</h2>';
|
|
$html .= '<table>';
|
|
$html .= '<thead><tr><th>Total Usuarios</th><th>Ayudantes Activos</th><th>Días Configurados</th><th>Turno Actual</th></tr></thead>';
|
|
$html .= '<tbody>';
|
|
$html .= '<tr>';
|
|
$html .= '<td class="text-center">' . $totalUsuarios . '</td>';
|
|
$html .= '<td class="text-center">' . $totalAyudantes . '</td>';
|
|
$html .= '<td class="text-center">' . $totalHorarios . '</td>';
|
|
$html .= '<td class="text-center">' . ($asignacionActual ? htmlspecialchars($asignacionActual['nombre']) : 'Sin asignar') . '</td>';
|
|
$html .= '</tr>';
|
|
$html .= '</tbody></table>';
|
|
|
|
$html .= '<h2>Ayudantes</h2>';
|
|
$html .= '<table>';
|
|
$html .= '<thead><tr><th>Nombre</th><th>Email</th><th>Username</th><th>Estado</th></tr></thead>';
|
|
$html .= '<tbody>';
|
|
|
|
foreach ($userModel->getAll() as $u) {
|
|
$html .= '<tr>';
|
|
$html .= '<td>' . htmlspecialchars($u['nombre']) . '</td>';
|
|
$html .= '<td>' . htmlspecialchars($u['email']) . '</td>';
|
|
$html .= '<td>' . htmlspecialchars($u['username'] ?: '-') . '</td>';
|
|
$html .= '<td>' . ($u['activo'] ? 'Activo' : 'Inactivo') . '</td>';
|
|
$html .= '</tr>';
|
|
}
|
|
|
|
$html .= '</tbody></table>';
|
|
|
|
$html .= '<h2>Horarios de Apertura</h2>';
|
|
$html .= '<table>';
|
|
$html .= '<thead><tr><th>Día</th><th>Hora Apertura</th><th>Hora Cierre</th><th>Estado</th></tr></thead>';
|
|
$html .= '<tbody>';
|
|
|
|
foreach ($horarios as $h) {
|
|
$html .= '<tr>';
|
|
$html .= '<td>' . ucfirst($h['dia_semana']) . '</td>';
|
|
$html .= '<td>' . date('H:i', strtotime($h['hora_apertura'])) . '</td>';
|
|
$html .= '<td>' . date('H:i', strtotime($h['hora_cierre'])) . '</td>';
|
|
$html .= '<td>' . ($h['activo'] ? 'Abierto' : 'Cerrado') . '</td>';
|
|
$html .= '</tr>';
|
|
}
|
|
|
|
$html .= '</tbody></table>';
|
|
|
|
$html .= '<h2>Historial de Asignaciones</h2>';
|
|
$html .= '<table>';
|
|
$html .= '<thead><tr><th>Semana Inicio</th><th>Semana Fin</th><th>Ayudante</th></tr></thead>';
|
|
$html .= '<tbody>';
|
|
|
|
$asignacionesLimit = array_slice($asignaciones, 0, 20);
|
|
foreach ($asignacionesLimit as $a) {
|
|
$html .= '<tr>';
|
|
$html .= '<td>' . date('d/m/Y', strtotime($a['semana_inicio'])) . '</td>';
|
|
$html .= '<td>' . date('d/m/Y', strtotime($a['semana_fin'])) . '</td>';
|
|
$html .= '<td>' . htmlspecialchars($a['nombre']) . '</td>';
|
|
$html .= '</tr>';
|
|
}
|
|
|
|
$html .= '</tbody></table>';
|
|
|
|
$html .= PDFGenerator::getFooter();
|
|
|
|
$pdf = new PDFGenerator();
|
|
$pdf->download($html, 'reporte-admin-' . date('Y-m-d') . '.pdf');
|