0) { $stmt = db()->prepare("INSERT INTO expenses (tenant_id, project_id, supplier_id, expense_type_id, amount, allocation_percent, entry_date, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$tenant_id, $project_id, $supplier_id, $expense_type_id, $amount, $allocation, $entry_date, $notes]); $expense_id = (int)db()->lastInsertId(); // Handle File Uploads if (!empty($_FILES['attachments']['name'][0])) { foreach ($_FILES['attachments']['tmp_name'] as $key => $tmp_name) { if ($_FILES['attachments']['error'][$key] === UPLOAD_ERR_OK) { $file_name = $_FILES['attachments']['name'][$key]; $file_size = $_FILES['attachments']['size'][$key]; $mime_type = $_FILES['attachments']['type'][$key]; $file_ext = pathinfo($file_name, PATHINFO_EXTENSION); $new_file_name = uniqid() . '.' . $file_ext; $file_path = 'uploads/' . $new_file_name; if (!is_dir('uploads')) mkdir('uploads', 0775, true); if (move_uploaded_file($tmp_name, $file_path)) { $stmt = db()->prepare("INSERT INTO attachments (tenant_id, entity_type, entity_id, file_name, file_path, file_size, mime_type) VALUES (?, 'expense', ?, ?, ?, ?, ?)"); $stmt->execute([$tenant_id, $expense_id, $file_name, $file_path, $file_size, $mime_type]); } } } } $stmt = db()->prepare("INSERT INTO activity_log (tenant_id, action, details) VALUES (?, ?, ?)"); $stmt->execute([$tenant_id, 'Expense Logged', "Logged \$" . number_format($amount, 2) . " expense for project ID $project_id"]); header("Location: expenses.php?success=1"); exit; } } // Fetch Data $expenseEntries = db()->prepare(" SELECT e.*, p.name as project_name, s.name as supplier_name, et.name as expense_type FROM expenses e JOIN projects p ON e.project_id = p.id JOIN suppliers s ON e.supplier_id = s.id LEFT JOIN expense_types et ON e.expense_type_id = et.id WHERE e.tenant_id = ? ORDER BY e.entry_date DESC, e.created_at DESC "); $expenseEntries->execute([$tenant_id]); $expenseList = $expenseEntries->fetchAll(); $projects = db()->prepare("SELECT id, name FROM projects WHERE tenant_id = ? ORDER BY name"); $projects->execute([$tenant_id]); $projectList = $projects->fetchAll(); $suppliers = db()->prepare("SELECT * FROM suppliers WHERE tenant_id = ? ORDER BY name"); $suppliers->execute([$tenant_id]); $supplierList = $suppliers->fetchAll(); $expenseTypes = db()->prepare("SELECT * FROM expense_types WHERE tenant_id = ? ORDER BY name"); $expenseTypes->execute([$tenant_id]); $expenseTypeList = $expenseTypes->fetchAll(); $pageTitle = "SR&ED Manager - Expenses"; include __DIR__ . '/includes/header.php'; ?>

Expenses

Date Supplier Project Amount Allocation Actions
No expenses found.

$
% SR&ED