Steuerkram/src/Views/invoices/show.php
2026-03-25 00:19:33 +01:00

186 lines
9.4 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);
$fmt = fn($v) => View::formatMoney($v);
$customerName = !empty($invoice['firma'])
? $invoice['firma']
: trim(($invoice['anrede'] ?? '') . ' ' . ($invoice['vorname'] ?? '') . ' ' . $invoice['nachname']);
$lz = '';
if (!empty($invoice['leistungszeitraum_von'])) {
$lz = View::formatDate($invoice['leistungszeitraum_von']);
if (!empty($invoice['leistungszeitraum_bis'])) {
$lz .= ' – ' . View::formatDate($invoice['leistungszeitraum_bis']);
}
}
$badgeClass = match($invoice['status']) {
'Bezahlt' => 'badge-green',
'Storniert' => 'badge-red',
'Gesendet' => 'badge-yellow',
default => 'badge-gray',
};
?>
<!-- Aktionsleiste -->
<div class="toolbar mb-2">
<div class="toolbar-left">
<span class="badge <?= $badgeClass ?>" style="font-size:.9rem;padding:.3rem .8rem"><?= $h($invoice['status']) ?></span>
</div>
<div class="toolbar-right" style="gap:.5rem">
<?php if ($invoice['status'] === 'Entwurf'): ?>
<a href="/invoices/<?= $h($invoice['id']) ?>/edit" class="btn btn-secondary">Bearbeiten</a>
<form method="post" action="/invoices/<?= $h($invoice['id']) ?>/finalize"
data-confirm="Rechnung finalisieren? Danach kann sie nicht mehr bearbeitet werden.">
<button type="submit" class="btn btn-primary">Finalisieren &amp; Nummerieren</button>
</form>
<?php endif; ?>
<?php if ($invoice['status'] !== 'Entwurf'): ?>
<a href="/invoices/<?= $h($invoice['id']) ?>/pdf" class="btn btn-primary">PDF herunterladen</a>
<?php endif; ?>
<?php if ($invoice['status'] === 'Gesendet' && empty($invoice['beleg_id'])): ?>
<form method="post" action="/invoices/<?= $h($invoice['id']) ?>/book"
data-confirm="Rechnung jetzt buchen?">
<button type="submit" class="btn btn-success">Buchen</button>
</form>
<?php endif; ?>
<?php if ($invoice['status'] === 'Gesendet'): ?>
<form method="post" action="/invoices/<?= $h($invoice['id']) ?>/mark-paid">
<button type="submit" class="btn btn-success">Als bezahlt markieren</button>
</form>
<?php endif; ?>
<?php if (in_array($invoice['status'], ['Entwurf','Gesendet'])): ?>
<form method="post" action="/invoices/<?= $h($invoice['id']) ?>/cancel"
data-confirm="Rechnung stornieren?">
<button type="submit" class="btn btn-danger">Stornieren</button>
</form>
<?php endif; ?>
</div>
</div>
<!-- Rechnungsvorschau (DIN 5008 ähnlich) -->
<div class="invoice-preview">
<!-- Logo -->
<?php if (!empty($settings['logo_path'])): ?>
<div style="text-align:center;margin-bottom:1.5rem">
<img src="/<?= $h($settings['logo_path']) ?>" alt="Logo" style="max-height:60px;max-width:250px">
</div>
<?php endif; ?>
<!-- Adressbereich -->
<div style="display:grid;grid-template-columns:100mm 1fr;gap:1rem;margin-bottom:1.5rem">
<div>
<div style="font-size:8pt;color:#666;border-bottom:1px solid #ccc;padding-bottom:2px;margin-bottom:4px">
<?= $h($settings['firma'] ?? '') ?> · <?= $h($settings['strasse'] ?? '') ?> · <?= $h(($settings['plz'] ?? '') . ' ' . ($settings['ort'] ?? '')) ?>
</div>
<div style="line-height:1.5">
<?= $h($customerName) ?><br>
<?= $h($invoice['strasse']) ?><br>
<?= $h($invoice['plz']) ?> <?= $h($invoice['ort']) ?>
<?php if ($invoice['land'] !== 'DE'): ?><br><?= $h($invoice['land']) ?><?php endif; ?>
</div>
</div>
<div style="text-align:left;font-size:.85rem;line-height:1.7">
<strong><?= $h($settings['firma'] ?? '') ?></strong><br>
<?= $h($settings['inhaber'] ?? '') ?><br>
<?= $h($settings['strasse'] ?? '') ?><br>
<?= $h(($settings['plz'] ?? '') . ' ' . ($settings['ort'] ?? '')) ?><br>
<?= $h($settings['telefon'] ?? '') ?><br>
<?= $h($settings['email'] ?? '') ?><br>
USt-ID: <?= $h($settings['ust_id'] ?? '') ?>
</div>
</div>
<!-- Meta-Tabelle -->
<table style="width:100%;border-collapse:collapse;margin-bottom:1.5rem;font-size:.9rem">
<thead>
<tr style="background:#f0f0f0">
<th style="padding:.4rem .5rem;text-align:left;border:1px solid #ddd;font-size:.8rem">Betreff</th>
<th style="padding:.4rem .5rem;text-align:left;border:1px solid #ddd;font-size:.8rem">Rechnungsnummer</th>
<th style="padding:.4rem .5rem;text-align:left;border:1px solid #ddd;font-size:.8rem">Kundennummer</th>
<th style="padding:.4rem .5rem;text-align:left;border:1px solid #ddd;font-size:.8rem">Leistungszeitraum</th>
<th style="padding:.4rem .5rem;text-align:left;border:1px solid #ddd;font-size:.8rem">Datum</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding:.4rem .5rem;border:1px solid #ddd"><?= $h($invoice['betreff']) ?></td>
<td style="padding:.4rem .5rem;border:1px solid #ddd;font-weight:700"><?= $h($invoice['rechnungs_nr'] ?? 'Entwurf') ?></td>
<td style="padding:.4rem .5rem;border:1px solid #ddd"><?= $h($invoice['kundennummer']) ?></td>
<td style="padding:.4rem .5rem;border:1px solid #ddd"><?= $h($lz ?: '–') ?></td>
<td style="padding:.4rem .5rem;border:1px solid #ddd"><?= View::formatDate($invoice['rechnungs_datum']) ?></td>
</tr>
</tbody>
</table>
<!-- Positionen -->
<table style="width:100%;border-collapse:collapse;margin-bottom:1.5rem;font-size:.9rem">
<thead>
<tr style="background:#1e293b;color:#fff">
<th style="padding:.5rem;text-align:left;width:40px">Pos.</th>
<th style="padding:.5rem;text-align:left">Bezeichnung</th>
<th style="padding:.5rem;text-align:right;width:70px">Menge</th>
<th style="padding:.5rem;text-align:left;width:70px">Einheit</th>
<th style="padding:.5rem;text-align:right;width:60px">USt.</th>
<th style="padding:.5rem;text-align:right;width:100px">Einzelpreis</th>
<th style="padding:.5rem;text-align:right;width:110px">Gesamt</th>
</tr>
</thead>
<tbody>
<?php foreach ($lines as $line): ?>
<tr style="border-bottom:1px solid #eee">
<td style="padding:.4rem .5rem"><?= $h($line['position']) ?></td>
<td style="padding:.4rem .5rem"><?= $h($line['bezeichnung']) ?></td>
<td style="padding:.4rem .5rem;text-align:right"><?= number_format((float)$line['menge'], 3, ',', '.') ?></td>
<td style="padding:.4rem .5rem"><?= $h($line['einheit']) ?></td>
<td style="padding:.4rem .5rem;text-align:right"><?= number_format((float)$line['ust_satz'], 0) ?> %</td>
<td style="padding:.4rem .5rem;text-align:right"><?= $fmt($line['einzelpreis']) ?></td>
<td style="padding:.4rem .5rem;text-align:right;font-weight:600"><?= $fmt($line['betrag_brutto']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- Summen -->
<div style="display:flex;justify-content:flex-end;margin-bottom:1.5rem">
<table style="width:260px">
<tr><td style="padding:.3rem 0">Nettobetrag:</td><td style="text-align:right"><?= $fmt($invoice['betrag_netto']) ?></td></tr>
<tr><td style="padding:.3rem 0">zzgl. Umsatzsteuer:</td><td style="text-align:right"><?= $fmt($invoice['betrag_ust']) ?></td></tr>
<tr style="font-weight:700;font-size:1.05rem;border-top:2px solid #000">
<td style="padding:.5rem 0">Rechnungsbetrag:</td>
<td style="text-align:right"><?= $fmt($invoice['betrag_brutto']) ?></td>
</tr>
</table>
</div>
<!-- Zahlungshinweis -->
<div style="background:#f0f4ff;border-left:3px solid #2563eb;padding:.75rem 1rem;margin-bottom:2rem;font-size:.9rem">
Bitte überweisen Sie den Rechnungsbetrag innerhalb <?= $h($invoice['payment_days'] ?? 14) ?> Tagen auf das unten genannte Konto.
<strong>Fällig am: <?= View::formatDate($invoice['faellig_datum']) ?></strong>
</div>
<!-- Fußzeile -->
<div style="border-top:1px solid #ccc;padding-top:.75rem;display:grid;grid-template-columns:1fr 1fr 1fr 80px;gap:1rem;font-size:.75rem;color:#555">
<div>
<strong><?= $h($settings['firma'] ?? '') ?></strong><br>
<?= $h($settings['inhaber'] ?? '') ?><br>
<?= $h($settings['strasse'] ?? '') ?><br>
<?= $h(($settings['plz'] ?? '') . ' ' . ($settings['ort'] ?? '')) ?><br>
USt-ID: <?= $h($settings['ust_id'] ?? '') ?>
</div>
<div>
Tel: <?= $h($settings['telefon'] ?? '') ?><br>
E-Mail: <?= $h($settings['email'] ?? '') ?><br>
Web: <?= $h($settings['website'] ?? '') ?>
</div>
<div>
<?= $h($settings['bank_name'] ?? '') ?><br>
IBAN: <?= $h($settings['iban'] ?? '') ?><br>
BIC: <?= $h($settings['bic'] ?? '') ?>
</div>
<div style="text-align:right">Seite 1 von 1</div>
</div>
</div>