diff --git a/expense_files.php b/expense_files.php index 4c61839..1b37a60 100644 --- a/expense_files.php +++ b/expense_files.php @@ -4,6 +4,34 @@ require_once __DIR__ . '/db/config.php'; $tenant_id = 1; +// Get Projects for filter +$projects_stmt = db()->prepare("SELECT id, name FROM projects WHERE tenant_id = ? ORDER BY name ASC"); +$projects_stmt->execute([$tenant_id]); +$all_projects = $projects_stmt->fetchAll(); + +// Filters +$project_filter = $_GET['project_id'] ?? ''; +$start_date = $_GET['start_date'] ?? ''; +$end_date = $_GET['end_date'] ?? ''; + +$where_clauses = ["a.tenant_id = ?", "a.entity_type = 'expense'"]; +$params = [$tenant_id]; + +if ($project_filter) { + $where_clauses[] = "ex.project_id = ?"; + $params[] = $project_filter; +} +if ($start_date) { + $where_clauses[] = "ex.entry_date >= ?"; + $params[] = $start_date; +} +if ($end_date) { + $where_clauses[] = "ex.entry_date <= ?"; + $params[] = $end_date; +} + +$where_sql = implode(" AND ", $where_clauses); + // Fetch Expense Files $stmt = db()->prepare(" SELECT a.*, ex.entry_date, s.name as supplier_name, p.name as project_name @@ -11,10 +39,10 @@ $stmt = db()->prepare(" JOIN expenses ex ON a.entity_id = ex.id JOIN suppliers s ON ex.supplier_id = s.id JOIN projects p ON ex.project_id = p.id - WHERE a.tenant_id = ? AND a.entity_type = 'expense' + WHERE $where_sql ORDER BY a.created_at DESC "); -$stmt->execute([$tenant_id]); +$stmt->execute($params); $files = $stmt->fetchAll(); function formatBytes($bytes, $precision = 2) { @@ -35,6 +63,37 @@ include __DIR__ . '/includes/header.php';
| = date('M j, Y', strtotime($f['created_at'])) ?> | - = htmlspecialchars($f['linked_entry_info'] ?? 'N/A') ?> + |
diff --git a/labour_files.php b/labour_files.php
index c77b63c..8a392b8 100644
--- a/labour_files.php
+++ b/labour_files.php
@@ -4,6 +4,34 @@ require_once __DIR__ . '/db/config.php';
$tenant_id = 1;
+// Get Projects for filter
+$projects_stmt = db()->prepare("SELECT id, name FROM projects WHERE tenant_id = ? ORDER BY name ASC");
+$projects_stmt->execute([$tenant_id]);
+$all_projects = $projects_stmt->fetchAll();
+
+// Filters
+$project_filter = $_GET['project_id'] ?? '';
+$start_date = $_GET['start_date'] ?? '';
+$end_date = $_GET['end_date'] ?? '';
+
+$where_clauses = ["a.tenant_id = ?", "a.entity_type = 'labour_entry'"];
+$params = [$tenant_id];
+
+if ($project_filter) {
+ $where_clauses[] = "le.project_id = ?";
+ $params[] = $project_filter;
+}
+if ($start_date) {
+ $where_clauses[] = "le.entry_date >= ?";
+ $params[] = $start_date;
+}
+if ($end_date) {
+ $where_clauses[] = "le.entry_date <= ?";
+ $params[] = $end_date;
+}
+
+$where_sql = implode(" AND ", $where_clauses);
+
// Fetch Labour Files
$stmt = db()->prepare("
SELECT a.*, le.entry_date, e.name as employee_name, p.name as project_name
@@ -11,10 +39,10 @@ $stmt = db()->prepare("
JOIN labour_entries le ON a.entity_id = le.id
JOIN employees e ON le.employee_id = e.id
JOIN projects p ON le.project_id = p.id
- WHERE a.tenant_id = ? AND a.entity_type = 'labour_entry'
+ WHERE $where_sql
ORDER BY a.created_at DESC
");
-$stmt->execute([$tenant_id]);
+$stmt->execute($params);
$files = $stmt->fetchAll();
function formatBytes($bytes, $precision = 2) {
@@ -35,6 +63,37 @@ include __DIR__ . '/includes/header.php';
Labour Files+ +
+
+
+
+
+ |