drink-it-cold/views/dashboard.php

252 lines
14 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 */
/** @var int $reminderScope */
/** @var bool $remindersWithoutEmployee */
/** @var array $user */
$canCreate = ($user['role'] ?? '') === 'admin';
// Admins dürfen aus der Übersicht heraus die Gesamtsicht aller Erinnerungen öffnen.
$remindersUrl = $canCreate ? '/reminders?all=1' : '/reminders';
$rentedTrailers = 0;
$rentedChests = 0;
$freeTrailers = 0;
$freeChests = 0;
$totalTrailers = 0;
$totalChests = 0;
foreach ($roadmap as $row) {
$isChest = trailer_is_chest($row['trailer']);
if ($isChest) {
$totalChests++;
} else {
$totalTrailers++;
}
if ($row['bookings']) {
if ($isChest) {
$rentedChests++;
} else {
$rentedTrailers++;
}
} elseif ($isChest) {
$freeChests++;
} else {
$freeTrailers++;
}
}
$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'] . ' ' . $user['last_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('/availability')) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg> Verfügbarkeit
</a>
<?php if ($canCreate): ?>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
</a>
<?php endif; ?>
</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><?= $rentedTrailers ?> von <?= $totalTrailers ?></strong><span>Vermietete Anhänger</span></div>
</article>
<article class="kpi">
<span class="kpi__icon kpi__icon--blue"><svg class="ico" aria-hidden="true"><use href="#i-snow"/></svg></span>
<div><strong><?= $rentedChests ?> von <?= $totalChests ?></strong><span>Vermietete Truhen</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><?= $freeTrailers ?> von <?= $totalTrailers ?></strong><span>Freie Anhänger</span></div>
</article>
<article class="kpi">
<span class="kpi__icon kpi__icon--green"><svg class="ico" aria-hidden="true"><use href="#i-snow"/></svg></span>
<div><strong><?= $freeChests ?> von <?= $totalChests ?></strong><span>Freie Truhen</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
|| (int) ($b['return_employee_id'] ?? 0) === $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>
</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_summary($booking)) ?></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>
<?php if ($canCreate): ?>
<a class="btn primary" href="<?= e(url('/bookings/new')) ?>">Buchung anlegen</a>
<?php endif; ?>
</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($event['type'] === 'return' ? booking_return_employee_name($b) : $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($remindersUrl)) ?>">Alle <svg class="ico" aria-hidden="true"><use href="#i-right"/></svg></a>
</div>
<?php if ($remindersWithoutEmployee): ?>
<div class="empty-state small">
<p>Ihrem Konto ist noch kein Mitarbeiter zugeordnet. Alle Erinnerungen finden Sie über „Alle“.</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($reminder['kind'] === 'end_1' ? booking_return_employee_name($b) : $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>
<?php if ($canCreate): ?>
<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>
<?php endif; ?>
<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($canCreate ? '/reminders?range=all&all=1' : '/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>