Hola, = htmlspecialchars(explode(' ', $user['name'] ?: $user['email'])[0]) ?>.
Bienvenido a Donna. Elige una herramienta para empezar.
'', 'name' => ''];
$apps = $authed ? Apps::catalog(Auth::isSocio()) : [];
/**
* Devuelve los eventos del día agrupados:
* - manuales: visibles a todos
* - escrituras (fecha_solicitud=hoy): visibles a todos
* - trámites (solicitud/vencimiento/término=hoy): solo creador, abogado nombrado o involucrado
*/
function todays_events(array $u, int $myId, bool $isSocio): array {
try {
$pdo = Db::pdo();
$today = date('Y-m-d');
$manual = $pdo->prepare(
'SELECT id, titulo, tipo, fecha, hora_inicio, hora_fin, ubicacion, creado_por_nombre, creado_por
FROM calendar_events WHERE fecha = :d
ORDER BY (hora_inicio IS NULL), hora_inicio, id'
);
$manual->execute([':d' => $today]);
$manualRows = $manual->fetchAll();
$esc = $pdo->prepare(
'SELECT id, tramite, cliente, abogado, estatus
FROM escrituras_tramites WHERE DATE(fecha_solicitud) = :d
ORDER BY id DESC'
);
$esc->execute([':d' => $today]);
$escRows = $esc->fetchAll();
if ($isSocio) {
$tra = $pdo->prepare(
"SELECT id, codigo, departamento, nombre, tipo_tramite, tipo_proceso,
cliente, abogado, estatus, fecha_solicitud, fecha_vencimiento, fecha_termino
FROM tramites_legales
WHERE DATE(fecha_solicitud) = :d
OR fecha_vencimiento = :d2
OR fecha_termino = :d3
ORDER BY id DESC"
);
$tra->execute([':d' => $today, ':d2' => $today, ':d3' => $today]);
} else {
$tra = $pdo->prepare(
"SELECT DISTINCT t.id, t.codigo, t.departamento, t.nombre, t.tipo_tramite, t.tipo_proceso,
t.cliente, t.abogado, t.estatus, t.fecha_solicitud, t.fecha_vencimiento, t.fecha_termino
FROM tramites_legales t
LEFT JOIN users ua ON ua.name = t.abogado AND ua.activo = 1
LEFT JOIN tramites_involucrados ti ON ti.tramite_id = t.id AND ti.user_id = :uid
WHERE (DATE(t.fecha_solicitud) = :d
OR t.fecha_vencimiento = :d2
OR t.fecha_termino = :d3)
AND (t.creado_por = :email OR ua.id = :uid2 OR ti.user_id IS NOT NULL)
ORDER BY t.id DESC"
);
$tra->execute([
':uid' => $myId, ':uid2' => $myId, ':email' => $u['email'],
':d' => $today, ':d2' => $today, ':d3' => $today,
]);
}
$traRows = $tra->fetchAll();
// Expandir trámites en 1..N entradas (una por fecha que coincida hoy)
$traEvents = [];
foreach ($traRows as $t) {
$title = $t['nombre'] ?: $t['tipo_tramite'] ?: $t['tipo_proceso'] ?: 'Trámite';
if (substr((string)$t['fecha_solicitud'], 0, 10) === $today) {
$traEvents[] = $t + ['evento' => 'solicitud', 'evento_label' => 'Solicitud', 'title' => $title];
}
if (($t['fecha_vencimiento'] ?? '') === $today) {
$traEvents[] = $t + ['evento' => 'vencimiento', 'evento_label' => 'Vencimiento', 'title' => $title];
}
if (($t['fecha_termino'] ?? '') === $today) {
$traEvents[] = $t + ['evento' => 'termino', 'evento_label' => 'Término procesal', 'title' => $title];
}
}
return [
'manual' => $manualRows,
'escrituras' => $escRows,
'tramites' => $traEvents,
];
} catch (Throwable $e) {
error_log('todays_events error: ' . $e->getMessage());
return ['manual' => [], 'escrituras' => [], 'tramites' => []];
}
}
function fmt_hour(?string $t): string {
if (!$t) return '';
return substr($t, 0, 5);
}
$todayEvents = $authed
? todays_events($user, Auth::userId(), Auth::isSocio())
: ['manual' => [], 'escrituras' => [], 'tramites' => []];
$hasToday = $authed && (
!empty($todayEvents['manual']) || !empty($todayEvents['escrituras']) || !empty($todayEvents['tramites'])
);
$DEPT_LABELS = ['adm' => 'Admin', 'corp' => 'Corp', 'mig' => 'Migración', 'lit' => 'Litigios'];
$DEPT_COLORS = ['adm' => '#6c5b95', 'corp' => '#9E7C2E', 'mig' => '#2980b9', 'lit' => '#722f37'];
$TIPO_LABELS = ['reserva_sala' => 'Reserva de sala', 'cumpleanos' => 'Cumpleaños', 'recordatorio' => 'Recordatorio', 'evento' => 'Evento'];
$TIPO_COLORS = ['reserva_sala' => '#2e7d8f', 'cumpleanos' => '#c2185b', 'recordatorio' => '#e67e22', 'evento' => '#27ae60'];
function initials(string $name): string {
$parts = preg_split('/\s+/u', trim($name));
$a = mb_substr($parts[0] ?? '', 0, 1);
$b = mb_substr($parts[1] ?? '', 0, 1);
return strtoupper($a . $b) ?: 'AA';
}
function icon(string $name): string {
$svgs = [
'document' => '
Donna es el portal interno de AALN: control de escrituras, expedientes, agenda y herramientas internas en un solo lugar. Inicia sesión con tu correo corporativo.
Bienvenido a Donna. Elige una herramienta para empezar.