Verfügbarkeitsprüfung für einen Zeitraum ergänzen
Neue Seite /availability (Knopf links neben „Kalender" auf der Übersicht): - Zeitraum eingeben, ausgewertet wird pro aktivem Anhänger und pro Truhe - Übersicht in zwei Gruppen mit „frei"/„belegt", bei Belegung mit Zeitraum, Kunde und Link zur Buchung (auch bei mehreren Überschneidungen) - freie Fahrzeuge führen direkt in die neue Buchung, Anhänger und Zeitraum sind vorausgefüllt - Wechseltag zählt wie im Kalender als frei (booking_conflicts) - KPI: „x von y frei" gesamt und je Gruppe - Cache-Buster auf Version 14
This commit is contained in:
parent
0f122d020c
commit
771954ba3d
6 changed files with 216 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue