getConnection(); } $__trWidgetHr = isset($user) && ( $user->hasRole('Admin') || $user->hasRole('Superuser') || $user->hasRole('employee-hr') || $user->hasRole('manager')); if (!$__trWidgetHr) { return; } /* Only the most recent record per (employee, topic) — older history rows ignored. */ $__trRows = $pdo->query(" SELECT et.id, et.next_due_date, et.reminder_days, tt.default_reminder_days FROM employee_trainings et JOIN training_topics tt ON tt.id = et.training_topic_id WHERE et.next_due_date IS NOT NULL AND NOT EXISTS ( SELECT 1 FROM employee_trainings et2 WHERE et2.employee_id = et.employee_id AND et2.training_topic_id = et.training_topic_id AND (et2.completed_date > et.completed_date OR (et2.completed_date = et.completed_date AND et2.id > et.id)) ) ")->fetchAll(PDO::FETCH_ASSOC); $__expiredCount = 0; $__dueSoonCount = 0; $__today = new DateTime('today'); foreach ($__trRows as $__r) { $__rem = $__r['reminder_days'] !== null ? (int)$__r['reminder_days'] : ($__r['default_reminder_days'] !== null ? (int)$__r['default_reminder_days'] : 30); $__due = DateTime::createFromFormat('Y-m-d', $__r['next_due_date']); if (!$__due) continue; $__days = (int)$__today->diff($__due)->format('%r%a'); if ($__days < 0) { $__expiredCount++; } elseif ($__days <= $__rem) { $__dueSoonCount++; } } /* Missing mandatory trainings (status = not_present) */ $__notPresentCount = (int)$pdo->query(" SELECT COUNT(*) FROM employees e CROSS JOIN training_topics tt WHERE tt.is_active = 1 AND tt.is_mandatory = 1 AND NOT EXISTS ( SELECT 1 FROM employee_trainings et WHERE et.employee_id = e.id AND et.training_topic_id = tt.id ) ")->fetchColumn(); if ($__expiredCount === 0 && $__dueSoonCount === 0 && $__notPresentCount === 0) { return; } ?>
0): ?> Formazion 0): ?> Formazion 0): ?> Obbligator