prepare(" SELECT p.*, CONCAT(e.first_name, ' ', e.last_name) as owner_name, COALESCE((SELECT SUM(hours) FROM labour_entries WHERE project_id = p.id), 0) as total_hours FROM projects p LEFT JOIN employees e ON p.owner_id = e.id WHERE p.tenant_id = ? ORDER BY p.created_at DESC LIMIT 5 "); $projectHighlights->execute([$tenant_id]); $projectList = $projectHighlights->fetchAll(); $labourHighlights = db()->prepare(" SELECT le.*, p.name as project_name, e.name as employee_name FROM labour_entries le JOIN projects p ON le.project_id = p.id JOIN employees e ON le.employee_id = e.id WHERE le.tenant_id = ? ORDER BY le.entry_date DESC, le.created_at DESC LIMIT 5 "); $labourHighlights->execute([$tenant_id]); $labourList = $labourHighlights->fetchAll(); $expenseHighlights = db()->prepare(" SELECT e.*, p.name as project_name, s.name as supplier_name FROM expenses e JOIN projects p ON e.project_id = p.id JOIN suppliers s ON e.supplier_id = s.id WHERE e.tenant_id = ? ORDER BY e.entry_date DESC, e.created_at DESC LIMIT 5 "); $expenseHighlights->execute([$tenant_id]); $expenseList = $expenseHighlights->fetchAll(); $employeeHighlights = db()->prepare(" SELECT e.* FROM employees e WHERE e.tenant_id = ? ORDER BY e.created_at DESC LIMIT 5 "); $employeeHighlights->execute([$tenant_id]); $employeeList = $employeeHighlights->fetchAll(); // Chart Data $chart_days = isset($_GET['chart_days']) ? (int)$_GET['chart_days'] : 7; if (!in_array($chart_days, [7, 14, 30])) $chart_days = 7; $chartDataQuery = db()->prepare(" SELECT entry_date, SUM(hours) as total_hours FROM labour_entries WHERE tenant_id = ? AND entry_date > DATE_SUB(CURRENT_DATE, INTERVAL ? DAY) GROUP BY entry_date ORDER BY entry_date ASC "); $chartDataQuery->execute([$tenant_id, $chart_days]); $rawChartData = $chartDataQuery->fetchAll(PDO::FETCH_KEY_PAIR); $chartLabels = []; $chartValues = []; for ($i = $chart_days - 1; $i >= 0; $i--) { $date = date('Y-m-d', strtotime("-$i days")); $chartLabels[] = date('M d', strtotime($date)); $chartValues[] = (float)($rawChartData[$date] ?? 0); } $activities = db()->prepare("SELECT * FROM activity_log WHERE tenant_id = ? ORDER BY created_at DESC LIMIT 10"); $activities->execute([$tenant_id]); $activityList = $activities->fetchAll(); $pageTitle = "SR&ED Manager - Dashboard"; include __DIR__ . '/includes/header.php'; ?>
Labour Hours Overview
Recent Projects
View All
PROJECT STATUS HOURS
Recent Labour
View All
DATE EMPLOYEE HOURS
h
Recent Expenses
View All
DATE SUPPLIER AMOUNT
$
New Employees
View All
NAME POSITION JOINED
Recent Activity
TIME ACTION DETAILS