89 lines
3.6 KiB
PHP
89 lines
3.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$tenant_id = 1;
|
|
|
|
// Fetch Expense Files
|
|
$stmt = db()->prepare("
|
|
SELECT a.*, ex.entry_date, s.name as supplier_name, p.name as project_name
|
|
FROM attachments a
|
|
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'
|
|
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 - Expense Files";
|
|
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">Expense Files</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>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="6" class="text-center py-5 text-muted">No expense files found.</td></tr>
|
|
<?php endif; ?>
|
|
<?php foreach ($files as $f): ?>
|
|
<tr>
|
|
<td>
|
|
<i class="bi bi-file-earmark-pdf me-2 text-danger"></i>
|
|
<strong><?= htmlspecialchars($f['file_name']) ?></strong>
|
|
</td>
|
|
<td><small class="text-muted"><?= formatBytes((int)$f['file_size']) ?></small></td>
|
|
<td>
|
|
<div class="d-flex align-items-center">
|
|
<div class="bg-light rounded-circle p-1 me-2" style="width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;">
|
|
<i class="bi bi-person small"></i>
|
|
</div>
|
|
<small><?= htmlspecialchars($f['uploaded_by'] ?? 'System') ?></small>
|
|
</div>
|
|
</td>
|
|
<td class="small text-muted"><?= date('M j, Y H:i', strtotime($f['created_at'])) ?></td>
|
|
<td>
|
|
<div class="small">
|
|
<span class="fw-bold text-dark"><?= $f['entry_date'] ?></span><br>
|
|
<span class="text-muted"><?= htmlspecialchars($f['supplier_name']) ?> - <?= htmlspecialchars($f['project_name']) ?></span>
|
|
</div>
|
|
</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>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|