fix: Corregir orden de ayudantes en PDFs y bot de Telegram

- 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
This commit is contained in:
nickpons666
2026-01-30 22:52:32 -06:00
parent 6823a5d6d3
commit ffda892859
3 changed files with 81 additions and 7 deletions

View File

@@ -20,14 +20,16 @@ class TelegramBot {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// --- MEJORAS ---
// 1. Forzar el uso de IPv4. Un problema común en entornos Docker
// es un timeout al intentar resolver AAAA (IPv6) antes de usar A (IPv4).
// 1. Forzar el uso de IPv4.
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
// 2. Añadir timeouts para evitar que el script se cuelgue indefinidamente.
// 2. Añadir timeouts de seguridad.
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // 5 segundos para conectar
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 10 segundos para la transferencia total
// 3. (ÚLTIMO INTENTO) Forzar versión de TLS.
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
if ($httpMethod === 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
@@ -269,7 +271,7 @@ class TelegramBot {
$db = \Database::getInstance()->getConnection();
$horarios = $horariosModel->getActivos();
$ayudantes = $userModel->getAyudantesActivos();
$ayudantes = $asignacionModel->getAyudantesPorOrden();
$semanasFuturas = [];
$hoy = new DateTime();
@@ -398,7 +400,7 @@ class TelegramBot {
$db = \Database::getInstance()->getConnection();
$horarios = $horariosModel->getActivos();
$ayudantes = $userModel->getAyudantesActivos();
$ayudantes = $asignacionModel->getAyudantesPorOrden();
$semanasFuturas = [];
$hoy = new DateTime();

View File

@@ -22,7 +22,7 @@ $totalAyudantes = count($userModel->getAyudantesActivos());
$totalHorarios = count($horariosModel->getAll());
$asignacionActual = $asignacionModel->getAsignacionActual();
$ayudantes = $userModel->getAyudantesActivos();
$ayudantes = $asignacionModel->getAyudantesPorOrden();
$horarios = $horariosModel->getAll();
$asignaciones = $asignacionModel->getTodasAsignaciones();
@@ -89,6 +89,40 @@ foreach ($asignacionesLimit as $a) {
$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();

View File

@@ -21,7 +21,7 @@ $db = Database::getInstance()->getConnection();
$horarios = $horariosModel->getActivos();
$userModel = new User();
$ayudantes = $userModel->getAyudantesActivos();
$ayudantes = $asignacionModel->getAyudantesPorOrden();
$semanasFuturas = [];
$hoy = new DateTime();
@@ -127,6 +127,44 @@ foreach ($semanasFuturas as $index => $semana) {
$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 class="' . ($ayudante['id'] == $user['id'] ? 'table-success' : '') . '">';
$html .= '<td>' . htmlspecialchars($ayudante['nombre']);
if ($ayudante['id'] == $user['id']) {
$html .= ' <span class="badge badge-success">Tu</span>';
}
$html .= '</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();