drink-it-cold/views/booking_detail.php

202 lines
12 KiB
PHP
Raw Normal View History

<?php
/** @var array $booking */
/** @var array $reminders */
/** @var array $doneMap */
/** @var string $copyText */
/** @var bool $canDelete */
/** @var bool $deleteBlocked */
/** @var bool $isAdmin */
$cancelled = $booking['status'] === 'cancelled';
$lines = explode("\n", $copyText);
$due = due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents']);
$returnTo = '/bookings/' . (int) $booking['id'];
?>
<div class="breadcrumb">
<a href="<?= e(url('/calendar?date=' . $booking['start_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-left"/></svg> Kalender</a>
<span>/</span>
<span>Buchung #<?= (int) $booking['id'] ?></span>
</div>
<div class="page-head page-head--compact">
<div>
<p class="eyebrow">
<?= e(fmt_date_with_time($booking['start_date'], $booking['start_time'] ?? null)) ?> –
<?= e(fmt_date_with_time($booking['end_date'], $booking['end_time'] ?? null)) ?> ·
<?= e($booking['trailer_label']) ?> · <?= e(booking_employee_summary($booking)) ?>
</p>
<h1><?= e($booking['customer_name']) ?>
<span class="pill <?= $cancelled ? 'pill--grey' : 'pill--green' ?>"><?= $cancelled ? 'storniert' : 'aktiv' ?></span>
</h1>
</div>
<div class="page-head__actions">
<a class="btn" href="<?= e(url($returnTo . '/edit')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Bearbeiten</a>
<?php if ($isAdmin): ?>
<a class="btn" href="<?= e(url('/bookings/new')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung</a>
<?php endif; ?>
<?php if (!$cancelled): ?>
<form method="post" action="<?= e(url($returnTo . '/cancel')) ?>" data-confirm="Buchung von <?= e($booking['customer_name']) ?> wirklich stornieren?">
<?= csrf_field() ?>
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
<button class="btn danger" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-close"/></svg> Stornieren</button>
</form>
<?php else: ?>
<form method="post" action="<?= e(url($returnTo . '/restore')) ?>" data-confirm="Buchung wieder aktivieren?">
<?= csrf_field() ?>
<button class="btn" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-return"/></svg> Wiederherstellen</button>
</form>
<?php endif; ?>
</div>
</div>
<?php if ($cancelled): ?>
<div class="alert alert--warning">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Storniert<?= $booking['cancelled_at'] ? ' am ' . e(fmt_datetime($booking['cancelled_at'])) : '' ?>.</strong> Die Erinnerungen für diese Buchung entfallen.</div>
</div>
<?php endif; ?>
<div class="detail-grid">
<div class="detail-main">
<section class="card card--copy" data-copy-wrap>
<div class="card__head card__head--row">
<div>
<h2>Buchungsinformation</h2>
<p>Genau diese Reihenfolge wird beim Kopieren übernommen.</p>
</div>
<button class="btn primary" type="button" data-copy>
<svg class="ico" aria-hidden="true"><use href="#i-copy"/></svg> Alles kopieren
</button>
</div>
<textarea class="copy-source" readonly aria-hidden="true" tabindex="-1"><?= e($copyText) ?></textarea>
<dl class="copy-list">
<?php foreach ($lines as $line): ?>
<?php
$parts = explode(': ', $line, 2);
$label = $parts[0] ?? $line;
$value = $parts[1] ?? '';
?>
<div class="copy-list__row<?= $label === 'Noch zu zahlen' ? ' is-strong' : '' ?>">
<dt><?= e($label) ?></dt>
<dd><?= e($value) ?></dd>
</div>
<?php endforeach; ?>
</dl>
<p class="copy-hint"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Zeilenumbrüche und Formatierung bleiben beim Kopieren erhalten.</p>
</section>
<section class="card">
<div class="card__head">
<h2>Automatische Erinnerungen</h2>
<p>Wird der Termin verschoben, passen sich die Fälligkeiten automatisch an.</p>
</div>
<?php if ($cancelled): ?>
<div class="empty-state small"><p>Diese Buchung ist storniert – es werden keine Erinnerungen erzeugt.</p></div>
<?php else: ?>
<ul class="reminder-list">
<?php foreach ($reminders as $reminder): ?>
<?php
$key = reminder_done_key($booking, $reminder['kind'], $reminder['due_date']);
$done = isset($doneMap[$key]);
$overdue = !$done && $reminder['due_date'] < today_iso();
?>
<li class="reminder-row<?= $done ? ' is-done' : '' ?><?= $overdue ? ' is-overdue' : '' ?>">
<div class="reminder-row__date">
<strong><?= e(fmt_date($reminder['due_date'])) ?></strong>
<span><?= e(relative_day($reminder['due_date'])) ?></span>
</div>
<div class="reminder-row__body">
<strong><?= e($reminder['label']) ?></strong>
<p><?= e($reminder['message']) ?></p>
<span class="muted small"><?= e($reminder['short']) ?> · <?= e($reminder['kind'] === 'end_1' ? booking_return_employee_name($booking) : $booking['employee_name']) ?></span>
</div>
<div class="reminder-row__action">
<?php if ($done): ?>
<span class="pill pill--green"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> erledigt</span>
<form method="post" action="<?= e(url('/reminders/done')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="booking_id" value="<?= (int) $booking['id'] ?>">
<input type="hidden" name="kind" value="<?= e($reminder['kind']) ?>">
<input type="hidden" name="done" value="0">
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
<button class="link-button small" type="submit">rückgängig</button>
</form>
<?php else: ?>
<form method="post" action="<?= e(url('/reminders/done')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="booking_id" value="<?= (int) $booking['id'] ?>">
<input type="hidden" name="kind" value="<?= e($reminder['kind']) ?>">
<input type="hidden" name="done" value="1">
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
<button class="btn small" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Erledigt</button>
</form>
<?php endif; ?>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
</div>
<aside class="detail-side">
<section class="card">
<h2>Zuordnung</h2>
<dl class="meta-list">
<div>
<dt>Kühlanhänger</dt>
<dd>
<span class="trailer-chip" style="--trailer: <?= e($booking['trailer_color']) ?>; --trailer-text: <?= e(contrast_color($booking['trailer_color'])) ?>">
<span class="trailer-dot" style="--trailer: <?= e($booking['trailer_color']) ?>"></span>
<?= e($booking['trailer_label']) ?>
</span>
</dd>
</div>
<div><dt>Übergabe</dt><dd><?= e($booking['employee_name']) ?></dd></div>
<div><dt>Rücknahme</dt><dd><?= e(booking_return_employee_name($booking)) ?></dd></div>
<div><dt>Von</dt><dd><?= e(fmt_date_long($booking['start_date'])) ?><?php if (fmt_time($booking['start_time'] ?? null) !== ''): ?> · <?= e(fmt_time($booking['start_time'])) ?> Uhr<?php endif; ?></dd></div>
<div><dt>Bis</dt><dd><?= e(fmt_date_long($booking['end_date'])) ?><?php if (fmt_time($booking['end_time'] ?? null) !== ''): ?> · <?= e(fmt_time($booking['end_time'])) ?> Uhr<?php endif; ?></dd></div>
<div><dt>Art</dt><dd><span class="pill pill--blue"><?= e(booking_kind_label((string) $booking['kind'])) ?></span></dd></div>
<div><dt>Rechnung</dt><dd><span class="pill <?= (int) $booking['invoice'] === 1 ? 'pill--green' : 'pill--grey' ?>"><?= e(booking_invoice_label($booking['invoice'])) ?></span></dd></div>
<?php if (trim((string) ($booking['invoice_no'] ?? '')) !== ''): ?>
<div><dt>Rechnungsnummer</dt><dd><?= e((string) $booking['invoice_no']) ?></dd></div>
<?php endif; ?>
</dl>
<hr>
<dl class="money-list">
<div><dt>Miete</dt><dd><?= e(fmt_money((int) $booking['rent_cents'])) ?></dd></div>
<div><dt>Lieferkosten</dt><dd><?= e(fmt_money((int) $booking['delivery_cents'])) ?></dd></div>
<div><dt>Gesamtbetrag</dt><dd><?= e(fmt_money((int) $booking['total_cents'])) ?></dd></div>
<div><dt>Anzahlung</dt><dd><?= e(fmt_money((int) $booking['deposit_cents'])) ?></dd></div>
<div class="is-strong"><dt>Noch zu zahlen</dt><dd><?= e(fmt_money($due)) ?></dd></div>
</dl>
</section>
<section class="card">
<h2>Aktionen</h2>
<div class="stack-actions">
<a class="btn btn--block" href="<?= e(url($returnTo . '/edit')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Buchung bearbeiten</a>
<?php if ($isAdmin): ?>
<a class="btn btn--block" href="<?= e(url('/bookings/new?trailer=' . (int) $booking['trailer_id'] . '&start=' . $booking['end_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anschlussbuchung anlegen</a>
<?php endif; ?>
<?php if ($canDelete): ?>
<form method="post" action="<?= e(url($returnTo . '/delete')) ?>" data-confirm="Buchung endgültig löschen? Das kann nicht rückgängig gemacht werden.">
<?= csrf_field() ?>
<button class="btn danger-ghost btn--block" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Endgültig löschen</button>
</form>
<?php elseif ($isAdmin && $deleteBlocked): ?>
<p class="muted small">
Diese Buchung ist als Rechnung markiert und unterliegt der gesetzlichen Aufbewahrungspflicht.
Löschen ist deshalb gesperrt. Wenn keine Rechnung erstellt wurde, kann die Markierung unter
<strong>Bearbeiten</strong> entfernt werden.
</p>
<?php endif; ?>
</div>
</section>
<p class="muted small detail-meta">
Angelegt am <?= e(fmt_datetime($booking['created_at'])) ?>.
Zuletzt geändert am <?= e(fmt_datetime($booking['updated_at'])) ?>.
</p>
</aside>
</div>