prepare($projects_sql); $projects_stmt->execute([$tenant_id]); $all_projects = $projects_stmt->fetchAll(); $where_clauses = ["a.tenant_id = ?"]; $params = [$tenant_id]; if (!$include_archived) { $where_clauses[] = "(lp.is_archived = 0 OR ep.is_archived = 0 OR (a.entity_type NOT IN ('labour_entry', 'expense')))"; } if ($project_filter) { $where_clauses[] = "(le.project_id = ? OR ex.project_id = ?)"; $params[] = $project_filter; $params[] = $project_filter; } if ($start_date) { $where_clauses[] = "(le.entry_date >= ? OR ex.entry_date >= ?)"; $params[] = $start_date; $params[] = $start_date; } if ($end_date) { $where_clauses[] = "(le.entry_date <= ? OR ex.entry_date <= ?)"; $params[] = $end_date; $params[] = $end_date; } $where_sql = implode(" AND ", $where_clauses); // Fetch All Files with their related context using LEFT JOINs for better filtering $stmt = db()->prepare(" SELECT a.*, le.entry_date as labour_date, e.name as employee_name, lp.name as labour_project, ex.entry_date as expense_date, s.name as supplier_name, ep.name as expense_project FROM attachments a LEFT JOIN labour_entries le ON a.entity_id = le.id AND a.entity_type = 'labour_entry' LEFT JOIN employees e ON le.employee_id = e.id LEFT JOIN projects lp ON le.project_id = lp.id LEFT JOIN expenses ex ON a.entity_id = ex.id AND a.entity_type = 'expense' LEFT JOIN suppliers s ON ex.supplier_id = s.id LEFT JOIN projects ep ON ex.project_id = ep.id WHERE $where_sql ORDER BY a.created_at DESC "); $stmt->execute($params); $files = $stmt->fetchAll(); function formatBytes($bytes, $precision = 2) { $units = ['B', 'KB', 'MB', 'GB', 'TB']; $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= pow(1024, $pow); return round($bytes, $precision) . ' ' . $units[$pow]; } $pageTitle = "SR&ED Manager - All Files Report"; include __DIR__ . '/includes/header.php'; ?>

System Files Report

onchange="this.form.submit()">
Reset
Type Filename Size Uploaded By Created At Linked Entry Actions
No files found in the system.
Labour Expense View