From 87fd553464246ebd7e8557e45448b28b567a3338 Mon Sep 17 00:00:00 2001
From: torsten
Date: Wed, 25 Nov 2026 23:05:35 +0100
Subject: [PATCH] Kalender: Abwesenheiten als eigene Zeilen mit dunklen Balken,
kollidierende Buchungen blinken
---
app/data.php | 29 +++++++++++++++++++++++++++++
app/pages.php | 27 +++++++++++++++++++++++++++
app/util.php | 2 +-
views/calendar.php | 46 +++++++++++++++++++++++++++++++++++++++++++++-
web/assets/app.css | 25 +++++++++++++++++++++++++
web/sw.js | 2 +-
6 files changed, 128 insertions(+), 3 deletions(-)
diff --git a/app/data.php b/app/data.php
index e6ac2c1..d574eed 100644
--- a/app/data.php
+++ b/app/data.php
@@ -952,6 +952,35 @@ function calendar_lanes(array $bookings): array
return ['bookings' => $out, 'lanes' => max(1, count($laneEnds))];
}
+/**
+ * Abwesenheiten, die eine Buchung betreffen: Übergabe-Mitarbeiter ab dem
+ * Erinnerungs-Vorlauf bis Mietbeginn, Rücknahme-Mitarbeiter entsprechend bis
+ * Mietende (gleiche Regel wie die Sperre in booking_validate()).
+ */
+function booking_absent_hits(array $booking, array $absences): array
+{
+ $handoverEmployee = (int) ($booking['employee_id'] ?? 0);
+ $returnEmployee = (int) ($booking['return_employee_id'] ?? 0) ?: $handoverEmployee;
+ $start = (string) $booking['start_date'];
+ $end = (string) $booking['end_date'];
+ $handoverFrom = add_days($start, -BOOKING_LEAD_DAYS);
+ $returnFrom = add_days($end, -BOOKING_LEAD_DAYS);
+ $hits = [];
+ foreach ($absences as $absence) {
+ $employee = (int) $absence['employee_id'];
+ $absenceStart = (string) $absence['start_date'];
+ $absenceEnd = (string) $absence['end_date'];
+ if ($employee === $handoverEmployee && $absenceStart <= $start && $absenceEnd >= $handoverFrom) {
+ $hits[] = $absence;
+ continue;
+ }
+ if ($employee === $returnEmployee && $absenceStart <= $end && $absenceEnd >= $returnFrom) {
+ $hits[] = $absence;
+ }
+ }
+ return $hits;
+}
+
/** Position eines Balkens im sichtbaren Zeitraum (Prozent). */
function calendar_geometry(array $booking, string $from, string $to, int $lanes): array
{
diff --git a/app/pages.php b/app/pages.php
index d964aae..d7e3ff9 100644
--- a/app/pages.php
+++ b/app/pages.php
@@ -492,6 +492,7 @@ function page_calendar(array $user): void
$bars[] = [
'booking' => $booking,
'geo' => calendar_geometry($booking, $from, $to, $lanes),
+ 'absent' => booking_absent_hits($booking, $absences) !== [],
];
}
$rows[] = [
@@ -527,6 +528,31 @@ function page_calendar(array $user): void
$employees = employees_all();
$absences = absence_list($from, $to);
+
+ // Abwesenheiten als eigene Zeilen unterhalb der Anhänger.
+ $absencesByEmployee = [];
+ foreach ($absences as $absence) {
+ $absencesByEmployee[(int) $absence['employee_id']][] = $absence;
+ }
+ $absenceRows = [];
+ foreach ($absencesByEmployee as $employeeAbsences) {
+ $laneInfo = calendar_lanes($employeeAbsences);
+ $bars = [];
+ foreach ($laneInfo['bookings'] as $absence) {
+ $bars[] = [
+ 'absence' => $absence,
+ 'geo' => calendar_geometry($absence, $from, $to, $laneInfo['lanes']),
+ ];
+ }
+ $absenceRows[] = [
+ 'employee_name' => (string) $employeeAbsences[0]['employee_name'],
+ 'employee_id' => (int) $employeeAbsences[0]['employee_id'],
+ 'bars' => $bars,
+ 'count' => count($employeeAbsences),
+ 'height' => max($rowMin, $barBase * $laneInfo['lanes'] + 16),
+ ];
+ }
+
render_page('calendar', [
'view' => $view,
'date' => $date,
@@ -544,6 +570,7 @@ function page_calendar(array $user): void
'employees' => $employees,
'bookingCount' => count($bookings),
'absences' => $absences,
+ 'absenceRows' => $absenceRows,
'urlFor' => static function (string $d) use ($view, $employeeId, $showCancelled): string {
return calendar_url($d, $view, $employeeId, $showCancelled);
},
diff --git a/app/util.php b/app/util.php
index e3f6842..db7e7d9 100644
--- a/app/util.php
+++ b/app/util.php
@@ -92,7 +92,7 @@ function url(string $path = '/'): string
}
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
-const DIC_ASSET_VERSION = '24';
+const DIC_ASSET_VERSION = '25';
function asset(string $path): string
{
diff --git a/views/calendar.php b/views/calendar.php
index 0818fb9..81bfb34 100644
--- a/views/calendar.php
+++ b/views/calendar.php
@@ -8,6 +8,7 @@
/** @var string $calTitle */
/** @var string $focusFrom */
/** @var array $absences */
+/** @var array $absenceRows */
/** @var string $prevDate */
/** @var string $nextDate */
/** @var string $today */
@@ -165,7 +166,7 @@ $minWidth = match ($view) {
. fmt_date_with_time($booking['end_date'], $booking['end_time'] ?? null)
. ', ' . booking_employee_summary($booking) . ($cancelled ? ', storniert' : '');
?>
-
+
+
+ Abwesenheiten
+
+
+
+
+ = e($absenceRow['employee_name']) ?>
+ abwesend
+
+
+
+
+
@@ -198,6 +236,12 @@ $minWidth = match ($view) {
Farbige Balken gehören zum jeweiligen Anhänger. Zwei Buchungen dürfen sich am Wechseltag (letzter Tag = erster Tag) überschneiden – beide Balken bleiben sichtbar.
+
+
+
+ Dunkle Striche sind Abwesenheiten der Mitarbeiter. Blinkende Buchungen kollidieren mit einer Abwesenheit (inkl. = (int) BOOKING_LEAD_DAYS ?> Tagen Vorlauf).
+
+
diff --git a/web/assets/app.css b/web/assets/app.css
index 908cbbb..00b754e 100644
--- a/web/assets/app.css
+++ b/web/assets/app.css
@@ -536,6 +536,31 @@ a .ico, button .ico { pointer-events: none; }
.cal-cell.is-today:hover { background: rgba(211, 230, 249, .7); }
.cal-cell.is-week-start { border-left: 2px solid var(--line); }
.cal-track.is-drop-target { background: rgba(25, 106, 188, .06); }
+/* Abwesenheiten: eigene Zeilen unter den Anhängern, dunkle Striche. */
+.cal-separator {
+ grid-column: 1 / -1; display: flex; align-items: center; gap: 8px;
+ padding: 6px 12px; background: #f4f6f8; border-top: 1px solid var(--line);
+ font-size: .64rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
+}
+.cal-label--absence { background: #fbfcfd; }
+.absence-dot {
+ width: 10px; height: 10px; border-radius: 3px; background: #2b3742; flex: 0 0 auto; display: inline-block;
+}
+.cal-track--absence { background: #fbfcfd; }
+.cal-bar.cal-bar--absence {
+ background: #2b3742; color: #fff; border: 1px solid #1d262e;
+ box-shadow: 0 1px 2px rgba(10, 20, 28, .25);
+}
+.cal-bar.cal-bar--absence .cal-bar__name { color: #fff; }
+.cal-bar.is-absent-conflict { animation: dic-absence-blink 1.6s ease-in-out infinite; }
+@keyframes dic-absence-blink {
+ 0%, 100% { box-shadow: 0 0 0 0 rgba(212, 68, 52, 0), inset 0 0 0 0 rgba(255, 255, 255, 0); }
+ 50% { box-shadow: 0 0 0 2px rgba(212, 68, 52, .95), inset 0 0 0 1px rgba(255, 255, 255, .55); }
+}
+@media (prefers-reduced-motion: reduce) {
+ .cal-bar.is-absent-conflict { animation: none; box-shadow: 0 0 0 2px rgba(212, 68, 52, .95); }
+}
+
.cal-bar {
position: absolute; z-index: 2; display: flex; flex-direction: column; justify-content: center;
diff --git a/web/sw.js b/web/sw.js
index d4da165..c92e813 100644
--- a/web/sw.js
+++ b/web/sw.js
@@ -6,7 +6,7 @@
* zwischengespeichert, damit niemand veraltete Buchungen sieht.
*/
-const VERSION = 'dic-v16';
+const VERSION = 'dic-v17';
const CACHE = VERSION;
const BASE = new URL(self.registration.scope).pathname.replace(/\/$/, '');