From 3e122048281092a79b21aa0c8c41d0453b4af999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gestor=C3=ADa=20LP?= Date: Mon, 2 Mar 2026 00:36:10 +0000 Subject: [PATCH] feat: admin reminders module Co-Authored-By: Claude Opus 4.6 --- admin/recordatorios.php | 389 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+) create mode 100644 admin/recordatorios.php diff --git a/admin/recordatorios.php b/admin/recordatorios.php new file mode 100644 index 0000000..6f0c4c8 --- /dev/null +++ b/admin/recordatorios.php @@ -0,0 +1,389 @@ +prepare("INSERT INTO recordatorios + (cliente_id, tramite_id, titulo, descripcion, fecha, completado, created_at) + VALUES (?, ?, ?, ?, ?, 0, NOW())"); + $stmt->execute([ + $clienteId > 0 ? $clienteId : null, + $tramiteId > 0 ? $tramiteId : null, + $titulo, + $descripcion, + $fecha, + ]); + header('Location: recordatorios.php?added=1' . (!empty($_GET['show_completed']) ? '&show_completed=1' : '')); + exit; + } + break; + + // ── Complete reminder ───────────────────────────────────── + case 'complete_reminder': + $id = (int)($_POST['reminder_id'] ?? 0); + if ($id > 0) { + $stmt = $db->prepare("UPDATE recordatorios SET completado = 1 WHERE id = ?"); + $stmt->execute([$id]); + } + header('Location: recordatorios.php?completed=1' . (!empty($_GET['show_completed']) ? '&show_completed=1' : '')); + exit; + + // ── Delete reminder ─────────────────────────────────────── + case 'delete_reminder': + $id = (int)($_POST['reminder_id'] ?? 0); + if ($id > 0) { + $stmt = $db->prepare("DELETE FROM recordatorios WHERE id = ?"); + $stmt->execute([$id]); + } + header('Location: recordatorios.php?deleted=1' . (!empty($_GET['show_completed']) ? '&show_completed=1' : '')); + exit; + } +} + +// ── Flash messages from redirect ──────────────────────────────── +if (isset($_GET['added'])) $success = 'Recordatorio creado correctamente.'; +if (isset($_GET['completed'])) $success = 'Recordatorio marcado como completado.'; +if (isset($_GET['deleted'])) $success = 'Recordatorio eliminado correctamente.'; + +// ── Filters & pagination ──────────────────────────────────────── +$showCompleted = isset($_GET['show_completed']) && $_GET['show_completed'] === '1'; +$page = max(1, (int)($_GET['page'] ?? 1)); +$perPage = 20; +$offset = ($page - 1) * $perPage; + +// Build WHERE clause +$where = ''; +$params = []; +if (!$showCompleted) { + $where = 'WHERE r.completado = 0'; +} + +// Count total +$countSql = "SELECT COUNT(*) FROM recordatorios r $where"; +$countStmt = $db->prepare($countSql); +$countStmt->execute($params); +$totalRecordatorios = $countStmt->fetchColumn(); +$totalPages = max(1, (int)ceil($totalRecordatorios / $perPage)); + +if ($page > $totalPages) $page = $totalPages; +$offset = ($page - 1) * $perPage; + +// Fetch reminders with client name +$sql = "SELECT r.*, c.nombre AS cliente_nombre + FROM recordatorios r + LEFT JOIN clientes c ON r.cliente_id = c.id + $where + ORDER BY r.fecha ASC + LIMIT $perPage OFFSET $offset"; +$stmt = $db->prepare($sql); +$stmt->execute($params); +$recordatorios = $stmt->fetchAll(); + +// Count overdue (for badge in header) +$stmtOverdue = $db->prepare("SELECT COUNT(*) FROM recordatorios WHERE completado = 0 AND fecha < ?"); +$stmtOverdue->execute([$today]); +$countOverdue = (int)$stmtOverdue->fetchColumn(); + +// Fetch clients for dropdown +$clientesStmt = $db->query("SELECT id, nombre FROM clientes ORDER BY nombre ASC"); +$clientesList = $clientesStmt->fetchAll(); + +// Fetch tramites for dropdown +$tramitesStmt = $db->query("SELECT t.id, t.tipo, c.nombre AS cliente_nombre + FROM tramites t + LEFT JOIN clientes c ON t.cliente_id = c.id + ORDER BY t.created_at DESC LIMIT 100"); +$tramitesList = $tramitesStmt->fetchAll(); +$tipoLabels = [ + 'visa' => 'Visa', + 'sentri' => 'Sentri/Global', + 'pasaporte' => 'Pasaporte', + 'adelanto_cita' => 'Adelanto Cita', + 'doble_nacionalidad' => 'Doble Nacionalidad', +]; +?> + +
+

+ Recordatorios + 0): ?> + + vencido 1 ? 's' : '' ?> + + +

+

Gestiona tus recordatorios y tareas pendientes

+
+ + + +
+ +
+ + + +
+ +
    + +
  • + +
+
+ + + +
+
+ Nuevo Recordatorio +
+
+
+ + + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+ + +
+ + +
+
+
+ + +
+
+ + + Ocultar completados + + + + Mostrar todos + + + + recordatorio + + +
+
+ + +
+
+ +
+ +

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FechaTítuloDescripciónClienteEstadoAcciones
+ + + + + + + 80 ? mb_substr($desc, 0, 80) . '...' : $desc); + ?> + + + + + + + - + + + + Completado + + Pendiente + + +
+ +
+ + + + +
+ +
+ + + + +
+
+
+
+ + + 1): ?> + + + +
+
+ +