query("SELECT COUNT(*) FROM objects WHERE status='active'"); $stats['objects'] = $stmt->fetchColumn(); // Active tasks $stmt = $pdo->query("SELECT COUNT(*) FROM tasks WHERE status IN ('open','in_progress')"); $stats['tasks'] = $stmt->fetchColumn(); // Open incidents $stmt = $pdo->query("SELECT COUNT(*) FROM incidents WHERE status IN ('open','in_progress')"); $stats['incidents'] = $stmt->fetchColumn(); // Active SLA contracts $stmt = $pdo->query("SELECT COUNT(*) FROM sla_contracts WHERE status='active'"); $stats['sla_count'] = $stmt->fetchColumn(); // Latest SHS $stmt = $pdo->query("SELECT shs_score, shs_status FROM shs_records ORDER BY id DESC LIMIT 1"); $stats['shs'] = $stmt->fetch(); // Engineer-specific: tasks assigned to me if ($role === 'engineer' || $role === 'technician') { $stmt = $pdo->prepare("SELECT COUNT(*) FROM tasks WHERE assigned_to = ? AND status IN ('open','in_progress')"); $stmt->execute([$session['user_id']]); $stats['my_tasks'] = $stmt->fetchColumn(); } // SLA compliance (overall) $stmt = $pdo->query("SELECT COUNT(*) as total, SUM(CASE WHEN sla_compliant=TRUE THEN 1 ELSE 0 END) as compliant FROM tasks WHERE closed_at IS NOT NULL"); $slaData = $stmt->fetch(); $stats['sla_compliance'] = $slaData['total'] > 0 ? round(($slaData['compliant'] / $slaData['total']) * 100, 1) : 0; $shsAlert = null; if ($stats['shs'] && $stats['shs']['shs_score'] < 70) { $shsAlert = 'SHS ниже 70 (' . $stats['shs']['shs_score'] . ') — ' . $stats['shs']['shs_status']; } require __DIR__ . '/inc/header.php'; ?>