- Cambiar getAyudantesActivos() por getAyudantesPorOrden() en todos los PDFs y bot - Añadir tabla 'Turnos de Ayudantes' en ambos PDFs (ayudante y admin) - Mostrar 4 próximas fechas para cada ayudante en orden correcto - En PDF de ayudante: resaltar fila del usuario con badge 'Tu' - Corregir sendPDF() y sendPDFGeneral() en bot de Telegram - Asegurar consistencia: Ana → Esperanza → Mary → Bety → Mariela - Sincronizar completamente web, PDFs y bot con nuevo orden de rotación
130 lines
4.5 KiB
PHP
130 lines
4.5 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 = $asignacionModel->getAyudantesPorOrden();
|
|
$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 .= '<h2>Turnos de Ayudantes</h2>';
|
|
$html .= '<table>';
|
|
$html .= '<thead><tr><th>Ayudante</th><th class="text-center">Fecha 1</th><th class="text-center">Fecha 2</th><th class="text-center">Fecha 3</th><th class="text-center">Fecha 4</th></tr></thead>';
|
|
$html .= '<tbody>';
|
|
|
|
foreach ($ayudantes as $ayudante) {
|
|
$stmt = $db->prepare("
|
|
SELECT semana_inicio, semana_fin
|
|
FROM asignaciones_turnos
|
|
WHERE user_id = ? AND semana_inicio >= CURDATE()
|
|
ORDER BY semana_inicio
|
|
LIMIT 4
|
|
");
|
|
$stmt->execute([$ayudante['id']]);
|
|
$turnos = $stmt->fetchAll();
|
|
|
|
$html .= '<tr>';
|
|
$html .= '<td>' . htmlspecialchars($ayudante['nombre']) . '</td>';
|
|
|
|
for ($i = 0; $i < 4; $i++) {
|
|
$html .= '<td class="text-center">';
|
|
if (isset($turnos[$i])) {
|
|
$html .= date('d/m/Y', strtotime($turnos[$i]['semana_inicio'])) . ' - ';
|
|
$html .= date('d/m/Y', strtotime($turnos[$i]['semana_fin']));
|
|
} else {
|
|
$html .= '-';
|
|
}
|
|
$html .= '</td>';
|
|
}
|
|
$html .= '</tr>';
|
|
}
|
|
|
|
$html .= '</tbody></table>';
|
|
|
|
$html .= PDFGenerator::getFooter();
|
|
|
|
$pdf = new PDFGenerator();
|
|
$pdf->download($html, 'reporte-admin-' . date('Y-m-d') . '.pdf');
|