98 lines
4.3 KiB
PHP
98 lines
4.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$tenant_id = 1;
|
|
|
|
// Fetch All Files with their related context
|
|
$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
|
|
FROM attachments a
|
|
WHERE a.tenant_id = ?
|
|
ORDER BY a.created_at DESC
|
|
");
|
|
$stmt->execute([$tenant_id]);
|
|
$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';
|
|
?>
|
|
|
|
<div class="container-fluid py-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="fw-bold mb-0">System Files Report</h2>
|
|
</div>
|
|
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="table-responsive">
|
|
<table class="table align-middle mb-0">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th>Type</th>
|
|
<th>Filename</th>
|
|
<th>Size</th>
|
|
<th>Uploaded By</th>
|
|
<th>Created At</th>
|
|
<th>Linked Entry</th>
|
|
<th class="text-end">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($files)): ?>
|
|
<tr><td colspan="7" class="text-center py-5 text-muted">No files found in the system.</td></tr>
|
|
<?php endif; ?>
|
|
<?php foreach ($files as $f): ?>
|
|
<tr>
|
|
<td>
|
|
<?php if ($f['entity_type'] === 'labour_entry'): ?>
|
|
<span class="badge bg-soft-primary text-primary border">Labour</span>
|
|
<?php elseif ($f['entity_type'] === 'expense'): ?>
|
|
<span class="badge bg-soft-success text-success border">Expense</span>
|
|
<?php else: ?>
|
|
<span class="badge bg-soft-secondary text-secondary border"><?= ucfirst($f['entity_type']) ?></span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<strong><?= htmlspecialchars($f['file_name']) ?></strong>
|
|
</td>
|
|
<td><small class="text-muted"><?= formatBytes((int)$f['file_size']) ?></small></td>
|
|
<td><small><?= htmlspecialchars($f['uploaded_by'] ?? 'System') ?></small></td>
|
|
<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') ?>
|
|
</small>
|
|
</td>
|
|
<td class="text-end">
|
|
<a href="<?= htmlspecialchars($f['file_path']) ?>" target="_blank" class="btn btn-sm btn-outline-primary">View</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.bg-soft-primary { background-color: rgba(59, 130, 246, 0.1); }
|
|
.bg-soft-success { background-color: rgba(34, 197, 94, 0.1); }
|
|
.bg-soft-secondary { background-color: rgba(107, 114, 128, 0.1); }
|
|
</style>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|