prepare("SELECT * FROM company_settings WHERE id = 1"); $stmt->execute(); $company = $stmt->fetch(); // 2. Determine Fiscal Year Range $fiscal_end_raw = $company['fiscal_year_end'] ?? '12-31'; $fiscal_month = (int)date('m', strtotime($fiscal_end_raw)); $fiscal_day = (int)date('d', strtotime($fiscal_end_raw)); // If fiscal end is 2024-03-31, and selected year is 2024: // Start: 2023-04-01, End: 2024-03-31 $end_date = sprintf('%d-%02d-%02d', $selected_year, $fiscal_month, $fiscal_day); $start_date = date('Y-m-d', strtotime($end_date . ' -1 year +1 day')); // 3. Fetch Projects active in this period (with labour or expenses) $projects_query = " SELECT DISTINCT p.* FROM projects p LEFT JOIN labour_entries le ON p.id = le.project_id AND le.entry_date BETWEEN ? AND ? LEFT JOIN expenses e ON p.id = e.project_id AND e.entry_date BETWEEN ? AND ? WHERE (le.id IS NOT NULL OR e.id IS NOT NULL) ORDER BY p.name ASC "; $stmt = db()->prepare($projects_query); $stmt->execute([$start_date, $end_date, $start_date, $end_date]); $active_projects = $stmt->fetchAll(); // 4. Helper for Labour Data function getLabourForProject($projectId, $start, $end) { $stmt = db()->prepare(" SELECT le.*, e.name as employee_name, lt.name as labour_type FROM labour_entries le JOIN employees e ON le.employee_id = e.id LEFT JOIN labour_types lt ON le.labour_type_id = lt.id WHERE le.project_id = ? AND le.entry_date BETWEEN ? AND ? ORDER BY le.entry_date ASC "); $stmt->execute([$projectId, $start, $end]); return $stmt->fetchAll(); } // 5. Helper for Expense Data function getExpensesForProject($projectId, $start, $end) { $stmt = db()->prepare(" SELECT e.*, s.name as supplier_name, et.name as expense_type FROM expenses e JOIN suppliers s ON e.supplier_id = s.id LEFT JOIN expense_types et ON e.expense_type_id = et.id WHERE e.project_id = ? AND e.entry_date BETWEEN ? AND ? ORDER BY e.entry_date ASC "); $stmt->execute([$projectId, $start, $end]); return $stmt->fetchAll(); } // 6. Helper for Summary Calendar (Labour Hours) $summary_labour_query = " SELECT p.id as project_id, p.name as project_name, DATE_FORMAT(le.entry_date, '%Y-%m') as month, SUM(le.hours) as total_hours, SUM(le.hours * IFNULL(le.hourly_rate, 0)) as total_cost FROM labour_entries le JOIN projects p ON le.project_id = p.id WHERE le.entry_date BETWEEN ? AND ? GROUP BY p.id, p.name, month "; $stmt = db()->prepare($summary_labour_query); $stmt->execute([$start_date, $end_date]); $summary_labour_data = $stmt->fetchAll(); // 7. Helper for Summary Calendar (Expenses) $summary_expense_query = " SELECT p.id as project_id, p.name as project_name, DATE_FORMAT(e.entry_date, '%Y-%m') as month, SUM(e.amount) as total_amount FROM expenses e JOIN projects p ON e.project_id = p.id WHERE e.entry_date BETWEEN ? AND ? GROUP BY p.id, p.name, month "; $stmt = db()->prepare($summary_expense_query); $stmt->execute([$start_date, $end_date]); $summary_expense_data = $stmt->fetchAll(); // Organize Summary Data $months = []; try { $current_dt = new DateTime($start_date); $current_dt->modify('first day of this month'); $end_dt = new DateTime($end_date); $end_dt->modify('first day of this month'); while ($current_dt <= $end_dt) { $months[] = $current_dt->format('Y-m'); $current_dt->modify('+1 month'); if (count($months) > 13) break; // Safety for roughly 1 year } } catch (Exception $e) { // Fallback if DateTime fails $months = [date('Y-m', strtotime($start_date))]; } $labour_matrix = []; $project_names = []; foreach ($summary_labour_data as $row) { $pid = $row['project_id']; $project_names[$pid] = $row['project_name']; $labour_matrix[$pid][$row['month']] = ['hours' => $row['total_hours'], 'cost' => $row['total_cost']]; } $expense_matrix = []; foreach ($summary_expense_data as $row) { $pid = $row['project_id']; $project_names[$pid] = $row['project_name']; $expense_matrix[$pid][$row['month']] = $row['total_amount']; } $pageTitle = "SRED Claim Report - " . $selected_year; ?> <?= $pageTitle ?>
Back SRED Claim Report Generator
Logo

SRED CLAIM REPORT

Fiscal Year:

Range: to

,

Phone: | Email:

Website:

Business Number:

Table of Contents

1. Title Page1
2. Table of Contents2
Project:
Insights & Charts
Labour Detail Report
Expense Detail Report
Summarized Claim (Calendar Views)
Labour Summary
Expense Summary
$project): $labour = getLabourForProject($project['id'], $start_date, $end_date); $expenses = getExpensesForProject($project['id'], $start_date, $end_date); // Process Insights $employee_hours = []; $labour_type_hours = []; $total_proj_hours = 0; $total_proj_labour_cost = 0; foreach ($labour as $l) { $employee_hours[$l['employee_name']] = ($employee_hours[$l['employee_name']] ?? 0) + (float)$l['hours']; $labour_type_hours[$l['labour_type'] ?? 'Other'] = ($labour_type_hours[$l['labour_type'] ?? 'Other'] ?? 0) + (float)$l['hours']; $total_proj_hours += (float)$l['hours']; $total_proj_labour_cost += (float)$l['hours'] * (float)($l['hourly_rate'] ?? 0); } arsort($employee_hours); $top_employees = array_slice($employee_hours, 0, 5, true); $total_proj_expenses = 0; foreach ($expenses as $e) { $total_proj_expenses += (float)$e['amount']; } ?>
Project Analysis

Project ID:

Total Labour Hours

h

Total Estimated Cost

$

Top Employees by Hours
Labour by Category

Labour Detail Report:

Date Employee Activity Type Hours Rate Total Wage
No labour entries recorded.
0 ? '$'.number_format($cost, 2) : '-' ?>
Project Totals: h $
Note: Hourly rates are recorded at the time of entry to reflect historical wage adjustments accurately.

Expense Detail Report:

Date Supplier Expense Type Notes Allocation Amount
No expenses recorded.
% $
Total Expenses: $

Summarized Claim: Monthly Labour Hours

$data): $row_cost = 0; $pname = $project_names[$pid] ?? 'Unknown Project'; ?> $d) $m_hours += (float)($d[$m]['hours'] ?? 0); ?>
Project Name Total $
0 ? number_format($h, 1) : '-' ?> $
Monthly Totals 0 ? number_format($m_hours, 1) : '-' ?> $

All amounts are calculated using the recorded hourly rate at the time of labour entry.

Summarized Claim: Monthly Expenses

$data): $row_amount = 0; $pname = $project_names[$pid] ?? 'Unknown Project'; ?> $d) $m_amt += (float)($d[$m] ?? 0); ?>
Project Name Total $
0 ? '$'.number_format($a, 0) : '-' ?> $
Monthly Totals 0 ? '$'.number_format($m_amt, 0) : '-' ?> $
Total Captured Wages and Expenses for SR&ED Claim

$

Includes all Labour Wages and Project Expenses for Fiscal Year