94 lines
4.9 KiB
PHP
94 lines
4.9 KiB
PHP
<?php use Steuerkram\View; $h = fn($v) => View::h($v); ?>
|
||
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<form method="get" style="display:flex;gap:.5rem;flex-wrap:wrap;align-items:center">
|
||
<input type="search" name="search" placeholder="Rechnungsnr., Betreff, Kunde…"
|
||
value="<?= $h($filter['search'] ?? '') ?>" style="width:240px">
|
||
<select name="status">
|
||
<option value="">Alle Status</option>
|
||
<?php foreach (['Entwurf','Gesendet','Bezahlt','Storniert'] as $s): ?>
|
||
<option value="<?= $s ?>"<?= ($filter['status'] ?? '') === $s ? ' selected' : '' ?>><?= $s ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
<select name="year">
|
||
<option value="">Alle Jahre</option>
|
||
<?php for ($y = (int)date('Y'); $y >= 2020; $y--): ?>
|
||
<option value="<?= $y ?>"<?= ($filter['year'] ?? '') == $y ? ' selected' : '' ?>><?= $y ?></option>
|
||
<?php endfor; ?>
|
||
</select>
|
||
<button type="submit" class="btn btn-secondary">Filtern</button>
|
||
<a href="/invoices" class="btn btn-secondary">✕</a>
|
||
</form>
|
||
</div>
|
||
<div class="toolbar-right"><span class="text-muted text-sm"><?= $total ?> Rechnungen</span></div>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<div class="table-wrap">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th>Rechnungsnr.</th>
|
||
<th>Datum</th>
|
||
<th>Kunde</th>
|
||
<th>Betreff</th>
|
||
<th class="td-right">Netto</th>
|
||
<th class="td-right">Brutto</th>
|
||
<th>Status</th>
|
||
<th></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($rows as $inv): ?>
|
||
<?php
|
||
$badgeClass = match($inv['status']) {
|
||
'Bezahlt' => 'badge-green',
|
||
'Storniert' => 'badge-red',
|
||
'Gesendet' => 'badge-yellow',
|
||
default => 'badge-gray',
|
||
};
|
||
$customerName = !empty($inv['firma']) ? $inv['firma'] : trim(($inv['vorname'] ?? '') . ' ' . $inv['nachname']);
|
||
?>
|
||
<tr>
|
||
<td><a href="/invoices/<?= $h($inv['id']) ?>" class="td-mono"><?= $h($inv['rechnungs_nr'] ?? 'Entwurf') ?></a></td>
|
||
<td class="td-muted"><?= View::formatDate($inv['rechnungs_datum']) ?></td>
|
||
<td><a href="/customers/<?= $h($inv['customer_id']) ?>"><?= $h($customerName) ?></a></td>
|
||
<td><?= $h(mb_strimwidth($inv['betreff'], 0, 40, '…')) ?></td>
|
||
<td class="td-right td-mono"><?= View::formatMoney($inv['betrag_netto']) ?></td>
|
||
<td class="td-right td-mono"><?= View::formatMoney($inv['betrag_brutto']) ?></td>
|
||
<td><span class="badge <?= $badgeClass ?>"><?= $h($inv['status']) ?></span></td>
|
||
<td>
|
||
<div style="display:flex;gap:.4rem">
|
||
<a href="/invoices/<?= $h($inv['id']) ?>" class="btn btn-secondary btn-sm">Öffnen</a>
|
||
<?php if ($inv['status'] !== 'Entwurf'): ?>
|
||
<a href="/invoices/<?= $h($inv['id']) ?>/pdf" class="btn btn-secondary btn-sm">PDF</a>
|
||
<?php endif; ?>
|
||
<?php if (!empty($settings['test_mode'])): ?>
|
||
<form method="post" action="/invoices/<?= $h($inv['id']) ?>/delete" style="display:inline"
|
||
onsubmit="return confirm('Rechnung wirklich löschen?')">
|
||
<button type="submit" class="btn btn-danger btn-sm">Löschen</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
<?php if (empty($rows)): ?>
|
||
<tr><td colspan="8" class="text-center text-muted" style="padding:2rem">Keine Rechnungen gefunden.</td></tr>
|
||
<?php endif; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<?php if ($pages > 1): ?>
|
||
<div class="pagination">
|
||
<?php if ($page > 1): ?><a href="?<?= http_build_query(array_merge($filter, ['page' => $page-1])) ?>">‹</a><?php endif; ?>
|
||
<?php for ($p = max(1,$page-3); $p <= min($pages,$page+3); $p++): ?>
|
||
<?php if ($p === $page): ?><span class="active"><?= $p ?></span>
|
||
<?php else: ?><a href="?<?= http_build_query(array_merge($filter, ['page' => $p])) ?>"><?= $p ?></a><?php endif; ?>
|
||
<?php endfor; ?>
|
||
<?php if ($page < $pages): ?><a href="?<?= http_build_query(array_merge($filter, ['page' => $page+1])) ?>">›</a><?php endif; ?>
|
||
</div>
|
||
<?php endif; ?>
|