drink-it-cold/views/dashboard.php
2026-11-13 01:19:05 +01:00

212 lines
12 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
/** @var string $today */
/** @var array $trailers */
/** @var array $roadmap */
/** @var array $upcoming */
/** @var array $reminders */
/** @var int $openReminderCount */
/** @var int $handoverCount */
/** @var int $employeeScope */
$rentedToday = 0;
foreach ($roadmap as $row) {
if ($row['bookings']) {
$rentedToday++;
}
}
$freeToday = count($trailers) - $rentedToday;
$isEmployeeView = $employeeScope > 0;
?>
<div class="page-head">
<div>
<p class="eyebrow"><?= e(fmt_date_long($today)) ?></p>
<h1><?= e(greeting()) ?><?= isset($user) ? ', ' . e($user['first_name']) : '' ?></h1>
<p class="page-head__lede">Was heute ansteht – und wer sich um welche Übergabe kümmert.</p>
</div>
<div class="page-head__actions">
<a class="btn" href="<?= e(url('/calendar')) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg> Kalender
</a>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
</div>
</div>
<section class="kpi-grid" aria-label="Kennzahlen">
<article class="kpi">
<span class="kpi__icon kpi__icon--blue"><svg class="ico" aria-hidden="true"><use href="#i-truck"/></svg></span>
<div><strong><?= $rentedToday ?> von <?= count($trailers) ?></strong><span>Heute vermietet</span></div>
</article>
<article class="kpi">
<span class="kpi__icon kpi__icon--green"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg></span>
<div><strong><?= $freeToday ?></strong><span>Heute frei</span></div>
</article>
<article class="kpi">
<span class="kpi__icon kpi__icon--amber"><svg class="ico" aria-hidden="true"><use href="#i-clock"/></svg></span>
<div><strong><?= $handoverCount ?></strong><span>Übergaben (7 Tage)</span></div>
</article>
<article class="kpi">
<span class="kpi__icon kpi__icon--red"><svg class="ico" aria-hidden="true"><use href="#i-bell"/></svg></span>
<div><strong><?= $openReminderCount ?></strong><span>Offene Erinnerungen</span></div>
</article>
</section>
<div class="dash-grid">
<div class="dash-main">
<section class="panel">
<div class="panel__head">
<div>
<h2>Heute im Einsatz</h2>
<p>Alle Anhänger auf einen Blick<?= $isEmployeeView ? ' – mit Ihren Buchungen hervorgehoben' : '' ?>.</p>
</div>
<a class="link-arrow" href="<?= e(url('/calendar?view=day')) ?>">Tagesansicht <svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></a>
</div>
<div class="trailer-grid">
<?php foreach ($roadmap as $row): ?>
<?php
$trailer = $row['trailer'];
$bookings = $row['bookings'];
$own = false;
foreach ($bookings as $b) {
if ($isEmployeeView && (int) $b['employee_id'] === $employeeScope) {
$own = true;
}
}
?>
<article class="trailer-card<?= $bookings ? ' is-rented' : ' is-free' ?><?= $own ? ' is-own' : '' ?>"
style="--trailer: <?= e($trailer['color_hex']) ?>; --trailer-text: <?= e(contrast_color($trailer['color_hex'])) ?>">
<div class="trailer-card__head">
<span class="trailer-dot"></span>
<div class="trailer-card__name">
<strong><?= e($trailer['label']) ?></strong>
<small><?= e($trailer['color_name']) ?></small>
</div>
<span class="pill <?= $bookings ? 'pill--red' : 'pill--green' ?>"><?= $bookings ? 'vermietet' : 'frei' ?></span>
</div>
<?php if ($bookings): ?>
<ul class="trailer-card__bookings">
<?php foreach ($bookings as $booking): ?>
<li>
<a href="<?= e(url('/bookings/' . (int) $booking['id'])) ?>" data-panel="<?= (int) $booking['id'] ?>">
<strong><?= e($booking['customer_name']) ?></strong>
<span><?= e(fmt_date_range($booking['start_date'], $booking['end_date'])) ?> · <?= e($booking['employee_name']) ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p class="trailer-card__free">Frei – neue Buchung möglich.</p>
<?php endif; ?>
</article>
<?php endforeach; ?>
</div>
</section>
<section class="panel">
<div class="panel__head">
<div>
<h2>Nächste Übergaben &amp; Rücknahmen</h2>
<p>Die kommenden 14 Tage.</p>
</div>
<a class="link-arrow" href="<?= e(url('/calendar')) ?>">Im Kalender <svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></a>
</div>
<?php if (!$upcoming): ?>
<div class="empty-state">
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg>
<h3>Keine Übergaben in den nächsten zwei Wochen</h3>
<p>Neue Buchungen erscheinen hier automatisch mit Übergabe- und Rücknahmetermin.</p>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">Buchung anlegen</a>
</div>
<?php else: ?>
<ul class="event-list">
<?php foreach ($upcoming as $event): ?>
<?php $b = $event['booking']; ?>
<li class="event-row">
<span class="event-row__icon <?= $event['type'] === 'handover' ? 'is-handover' : 'is-return' ?>">
<svg class="ico" aria-hidden="true"><use href="#<?= $event['type'] === 'handover' ? 'i-truck' : 'i-return' ?>"/></svg>
</span>
<div class="event-row__date">
<strong><?= e(fmt_weekday_short($event['date'])) ?>, <?= e(fmt_date($event['date'])) ?></strong>
<span class="<?= $event['date'] === $today ? 'is-today' : '' ?>"><?= e(relative_day($event['date'])) ?></span>
</div>
<div class="event-row__main">
<strong><?= e($b['customer_name']) ?></strong>
<span><?= $event['type'] === 'handover' ? 'Übergabe' : 'Rücknahme' ?> · <?= e($b['trailer_label']) ?> · <?= e($b['employee_name']) ?></span>
</div>
<a class="btn small" href="<?= e(url('/bookings/' . (int) $b['id'])) ?>" data-panel="<?= (int) $b['id'] ?>">Details</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
</div>
<aside class="dash-side">
<section class="panel panel--reminders">
<div class="panel__head">
<div>
<h2>Erinnerungen</h2>
<p>Fällig bis <?= e(fmt_date(add_days($today, 7))) ?>.</p>
</div>
<a class="link-arrow" href="<?= e(url('/reminders')) ?>">Alle <svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></a>
</div>
<?php if (($user['role'] ?? '') !== 'admin' && $employeeScope === 0): ?>
<div class="empty-state small"><p>Ihrem Konto ist noch kein Mitarbeiter zugeordnet.</p></div>
<?php elseif (!$reminders): ?>
<div class="empty-state small">
<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg>
<h3>Alles erledigt</h3>
<p>Keine offenen Erinnerungen in den nächsten Tagen.</p>
</div>
<?php else: ?>
<ul class="mini-reminders">
<?php foreach ($reminders as $reminder): ?>
<?php $b = $reminder['booking']; $overdue = $reminder['due_date'] < $today; ?>
<li class="mini-reminder<?= $overdue ? ' is-overdue' : '' ?>">
<div class="mini-reminder__top">
<span class="mini-reminder__date"><?= e(fmt_date($reminder['due_date'])) ?></span>
<span class="pill <?= $overdue ? 'pill--red' : 'pill--blue' ?>"><?= e(relative_day($reminder['due_date'])) ?></span>
</div>
<strong><?= e($reminder['label']) ?></strong>
<p><?= e($reminder['message']) ?></p>
<div class="mini-reminder__meta">
<span><?= e($b['customer_name']) ?> · <?= e($b['trailer_label']) ?></span>
<span><?= e($b['employee_name']) ?></span>
</div>
<div class="mini-reminder__actions">
<a href="<?= e(url('/bookings/' . (int) $b['id'])) ?>" data-panel="<?= (int) $b['id'] ?>">Buchung öffnen</a>
<form method="post" action="<?= e(url('/reminders/done')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="booking_id" value="<?= (int) $b['id'] ?>">
<input type="hidden" name="kind" value="<?= e($reminder['kind']) ?>">
<input type="hidden" name="done" value="1">
<input type="hidden" name="return_to" value="/">
<button class="link-button" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Erledigt</button>
</form>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
<section class="panel panel--quick">
<h2>Kurz zugreifen</h2>
<a class="quick-link" href="<?= e(url('/bookings/new')) ?>">
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg></span>
<span><strong>Neue Buchung</strong><small>Zeitraum und Kunde erfassen</small></span>
<svg class="ico chev" aria-hidden="true"><use href="#i-right"/></svg>
</a>
<a class="quick-link" href="<?= e(url('/search')) ?>">
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-search"/></svg></span>
<span><strong>Kunde suchen</strong><small>Buchung nach Name finden</small></span>
<svg class="ico chev" aria-hidden="true"><use href="#i-right"/></svg>
</a>
<a class="quick-link" href="<?= e(url('/reminders?range=all')) ?>">
<span class="quick-link__icon"><svg class="ico" aria-hidden="true"><use href="#i-bell"/></svg></span>
<span><strong>Alle Erinnerungen</strong><small>Offene Aufgaben prüfen</small></span>
<svg class="ico chev" aria-hidden="true"><use href="#i-right"/></svg>
</a>
</section>
</aside>
</div>