diff --git a/README.md b/README.md index eed7c26..2188e82 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ Die Anforderungen stammen aus Rechnung JA/NEIN samt Rechnungsnummer, Abholung/Lieferung und vollständigen Kundendaten. Das Formular folgt der Reihenfolge der Excel-Vorlage „Neuanlage"; eine kopierte Spalte wird beim Einfügen auf die Felder verteilt. +- **Verfügbarkeit prüfen**: Zeitraum wählen, freie und belegte Anhänger/Truhen + sehen und mit einem Klick in die neue Buchung springen (Knopf links neben + „Kalender" auf der Übersicht). - **Buchungstext kopieren** mit einem Klick – exakt in der geforderten Reihenfolge und mit erhaltenen Zeilenumbrüchen. - **Doppelbelegungsschutz**: Ein Anhänger kann im gleichen Zeitraum nicht diff --git a/app/pages.php b/app/pages.php index a3d84bc..16ba468 100644 --- a/app/pages.php +++ b/app/pages.php @@ -83,6 +83,10 @@ function page_handle(string $method, string $path): void page_calendar($user); return; } + if ($path === '/availability') { + page_availability($user); + return; + } if ($path === '/bookings/new') { page_booking_new($user, $method); return; @@ -438,6 +442,64 @@ function page_calendar(array $user): void ], 'Kalender'); } +/* ----------------------------------------------------------- Verfügbarkeit */ + +function page_availability(array $user): void +{ + $from = query_string('from'); + $to = query_string('to'); + $checked = $from !== '' || $to !== ''; + $errors = []; + + if (!$checked) { + $from = today_iso(); + $to = add_days($from, 3); + } else { + if (!valid_date($from)) { + $errors['from'] = 'Bitte ein gültiges Startdatum angeben.'; + } + if ($to === '') { + $to = $from; + } + if (!valid_date($to)) { + $errors['to'] = 'Bitte ein gültiges Enddatum angeben.'; + } + if (!$errors) { + if ($to < $from) { + $errors['to'] = 'Das Ende darf nicht vor dem Beginn liegen.'; + } elseif (days_between($from, $to) > 365) { + $errors['to'] = 'Der Zeitraum darf höchstens 365 Tage betragen.'; + } + } + } + + $groups = ['trailer' => [], 'chest' => []]; + $freeCount = 0; + if ($checked && !$errors) { + foreach (trailers_all() as $trailer) { + $conflicts = booking_conflicts((int) $trailer['id'], $from, $to); + $free = !$conflicts; + $freeCount += $free ? 1 : 0; + $groups[trailer_is_chest($trailer) ? 'chest' : 'trailer'][] = [ + 'trailer' => $trailer, + 'free' => $free, + 'conflicts' => $conflicts, + ]; + } + } + + render_page('availability', [ + 'from' => $from, + 'to' => $to, + 'checked' => $checked, + 'errors' => $errors, + 'groups' => $groups, + 'freeCount' => $freeCount, + 'total' => count($groups['trailer']) + count($groups['chest']), + 'user' => $user, + ], 'Verfügbarkeit'); +} + /* --------------------------------------------------------------- Buchungen */ function booking_form_context(array $user, ?array $booking = null, array $values = [], array $errors = []): array diff --git a/app/util.php b/app/util.php index b2f2847..448a811 100644 --- a/app/util.php +++ b/app/util.php @@ -89,7 +89,7 @@ function url(string $path = '/'): string } /** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */ -const DIC_ASSET_VERSION = '13'; +const DIC_ASSET_VERSION = '14'; function asset(string $path): string { diff --git a/views/availability.php b/views/availability.php new file mode 100644 index 0000000..11839a1 --- /dev/null +++ b/views/availability.php @@ -0,0 +1,127 @@ + (string) ($errors[$key] ?? ''); +$bookingUrl = static fn (array $trailer): string => '/bookings/new?trailer=' . (int) $trailer['id'] + . '&start=' . rawurlencode($from) . '&end=' . rawurlencode($to); +$groupMeta = [ + 'trailer' => ['title' => 'Anhänger', 'empty' => 'Keine Anhänger hinterlegt.'], + 'chest' => ['title' => 'Truhen', 'empty' => 'Keine Truhen hinterlegt.'], +]; +?> +
Übersicht
+Zeitraum wählen – die App zeigt, welche Anhänger und Truhen in dieser Zeit frei sind.
+Ein Wechseltag ist erlaubt: Endet eine Buchung am Tag des neuen Beginns, gilt das Fahrzeug als frei.
+= e(fmt_date_range($from, $to)) ?> · = (int) $freeCount ?> von = (int) $total ?> frei
+= e($meta['empty']) ?>
+ += e($message) ?>
+Zeitraum wählen und „Verfügbarkeit prüfen" – danach kannst du direkt buchen.
+Was heute ansteht – und wer sich um welche Übergabe kümmert.