This commit is contained in:
Flatlogic Bot 2026-02-15 01:43:55 +00:00
parent 87b38e5dfa
commit 33ad9419e5
3 changed files with 204 additions and 13 deletions

View File

@ -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';
<h2 class="fw-bold mb-0">Expense Files</h2>
</div>
<!-- Filters -->
<div class="card border-0 shadow-sm mb-4">
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-4">
<label class="form-label small fw-bold">Project</label>
<select name="project_id" class="form-select">
<option value="">All Projects</option>
<?php foreach ($all_projects as $p): ?>
<option value="<?= $p['id'] ?>" <?= $project_filter == $p['id'] ? 'selected' : '' ?>><?= htmlspecialchars($p['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label small fw-bold">Start Date</label>
<input type="date" name="start_date" class="form-control" value="<?= htmlspecialchars($start_date) ?>">
</div>
<div class="col-md-3">
<label class="form-label small fw-bold">End Date</label>
<input type="date" name="end_date" class="form-control" value="<?= htmlspecialchars($end_date) ?>">
</div>
<div class="col-md-2 d-flex align-items-end">
<div class="d-grid w-100 gap-2 d-md-flex">
<button type="submit" class="btn btn-primary">Filter</button>
<a href="expense_files.php" class="btn btn-outline-secondary">Reset</a>
</div>
</div>
</form>
</div>
</div>
<div class="card border-0 shadow-sm">
<div class="table-responsive">
<table class="table align-middle mb-0">

View File

@ -4,19 +4,53 @@ require_once __DIR__ . '/db/config.php';
$tenant_id = 1;
// Fetch All Files with their related context
// 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 = ?"];
$params = [$tenant_id];
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.*,
CASE
WHEN a.entity_type = 'labour_entry' THEN (SELECT CONCAT(le.entry_date, ' - ', e.name, ' - ', p.name) FROM labour_entries le JOIN employees e ON le.employee_id = e.id JOIN projects p ON le.project_id = p.id WHERE le.id = a.entity_id)
WHEN a.entity_type = 'expense' THEN (SELECT CONCAT(ex.entry_date, ' - ', s.name, ' - ', p.name) FROM expenses ex JOIN suppliers s ON ex.supplier_id = s.id JOIN projects p ON ex.project_id = p.id WHERE ex.id = a.entity_id)
ELSE 'Other'
END as linked_entry_info
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
WHERE a.tenant_id = ?
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([$tenant_id]);
$stmt->execute($params);
$files = $stmt->fetchAll();
function formatBytes($bytes, $precision = 2) {
@ -37,6 +71,37 @@ include __DIR__ . '/includes/header.php';
<h2 class="fw-bold mb-0">System Files Report</h2>
</div>
<!-- Filters -->
<div class="card border-0 shadow-sm mb-4">
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-4">
<label class="form-label small fw-bold">Project</label>
<select name="project_id" class="form-select">
<option value="">All Projects</option>
<?php foreach ($all_projects as $p): ?>
<option value="<?= $p['id'] ?>" <?= $project_filter == $p['id'] ? 'selected' : '' ?>><?= htmlspecialchars($p['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label small fw-bold">Start Date</label>
<input type="date" name="start_date" class="form-control" value="<?= htmlspecialchars($start_date) ?>">
</div>
<div class="col-md-3">
<label class="form-label small fw-bold">End Date</label>
<input type="date" name="end_date" class="form-control" value="<?= htmlspecialchars($end_date) ?>">
</div>
<div class="col-md-2 d-flex align-items-end">
<div class="d-grid w-100 gap-2 d-md-flex">
<button type="submit" class="btn btn-primary">Filter</button>
<a href="files.php" class="btn btn-outline-secondary">Reset</a>
</div>
</div>
</form>
</div>
</div>
<div class="card border-0 shadow-sm">
<div class="table-responsive">
<table class="table align-middle mb-0">
@ -74,7 +139,15 @@ include __DIR__ . '/includes/header.php';
<td class="small text-muted"><?= date('M j, Y', strtotime($f['created_at'])) ?></td>
<td>
<small class="text-muted text-truncate d-inline-block" style="max-width: 300px;">
<?= htmlspecialchars($f['linked_entry_info'] ?? 'N/A') ?>
<?php
if ($f['entity_type'] === 'labour_entry') {
echo htmlspecialchars(($f['labour_date'] ?? '') . ' - ' . ($f['employee_name'] ?? '') . ' - ' . ($f['labour_project'] ?? ''));
} elseif ($f['entity_type'] === 'expense') {
echo htmlspecialchars(($f['expense_date'] ?? '') . ' - ' . ($f['supplier_name'] ?? '') . ' - ' . ($f['expense_project'] ?? ''));
} else {
echo 'N/A';
}
?>
</small>
</td>
<td class="text-end">

View File

@ -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';
<h2 class="fw-bold mb-0">Labour Files</h2>
</div>
<!-- Filters -->
<div class="card border-0 shadow-sm mb-4">
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-4">
<label class="form-label small fw-bold">Project</label>
<select name="project_id" class="form-select">
<option value="">All Projects</option>
<?php foreach ($all_projects as $p): ?>
<option value="<?= $p['id'] ?>" <?= $project_filter == $p['id'] ? 'selected' : '' ?>><?= htmlspecialchars($p['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label small fw-bold">Start Date</label>
<input type="date" name="start_date" class="form-control" value="<?= htmlspecialchars($start_date) ?>">
</div>
<div class="col-md-3">
<label class="form-label small fw-bold">End Date</label>
<input type="date" name="end_date" class="form-control" value="<?= htmlspecialchars($end_date) ?>">
</div>
<div class="col-md-2 d-flex align-items-end">
<div class="d-grid w-100 gap-2 d-md-flex">
<button type="submit" class="btn btn-primary">Filter</button>
<a href="labour_files.php" class="btn btn-outline-secondary">Reset</a>
</div>
</div>
</form>
</div>
</div>
<div class="card border-0 shadow-sm">
<div class="table-responsive">
<table class="table align-middle mb-0">