Steuerkram/src/Views/invoices/list.php

131 lines
7.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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','Finalisiert','Gesendet','Teilzahlung','Bezahlt','Überzahlt','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',
'Teilzahlung' => 'badge-orange',
'Überzahlt' => 'badge-purple',
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']) ?>"
style="background:none;border:none;cursor:pointer;color:var(--color-muted);padding:.2rem;line-height:1;display:inline-flex;align-items:center"
title="Bearbeiten">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
</svg>
</a>
<?php if ($inv['status'] !== 'Entwurf'): ?>
<a href="/invoices/<?= $h($inv['id']) ?>/pdf"
style="background:none;border:none;cursor:pointer;color:var(--color-muted);padding:.2rem;line-height:1;display:inline-flex;align-items:center"
title="PDF ansehen">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="2" y="4" width="20" height="16" rx="2"/>
<path d="M5 12s2.5-4 7-4 7 4 7 4-2.5 4-7 4-7-4-7-4z"/>
<circle cx="12" cy="12" r="1.5"/>
</svg>
</a>
<?php endif; ?>
<?php if (in_array($inv['status'], ['Finalisiert','Gesendet','Bezahlt']) && empty($inv['storno_of_id'])): ?>
<form method="post"
action="/invoices/<?= $h($inv['id']) ?>/cancel"
style="display:inline"
onsubmit="return confirm('Rechnung <?= $h($inv['rechnungs_nr']) ?> wirklich stornieren und eine Stornorechnung erstellen?')">
<button type="submit" class="btn btn-warning btn-sm">Storno</button>
</form>
<?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"
style="background:none;border:none;cursor:pointer;color:var(--color-danger);padding:.2rem;line-height:1;display:inline-flex;align-items:center"
title="Löschen">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="3,6 5,6 21,6"/>
<path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
<path d="M10 11v6M14 11v6"/>
<path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/>
</svg>
</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; ?>