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
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
127
views/availability.php
Normal file
127
views/availability.php
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
/** @var string $from */
|
||||
/** @var string $to */
|
||||
/** @var bool $checked */
|
||||
/** @var array $errors */
|
||||
/** @var array $groups */
|
||||
/** @var int $freeCount */
|
||||
/** @var int $total */
|
||||
$fieldError = static fn (string $key): string => (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.'],
|
||||
];
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Übersicht</p>
|
||||
<h1>Verfügbarkeit</h1>
|
||||
<p class="page-head__lede">Zeitraum wählen – die App zeigt, welche Anhänger und Truhen in dieser Zeit frei sind.</p>
|
||||
</div>
|
||||
<div class="page-head__actions">
|
||||
<a class="btn" href="<?= e(url('/calendar?view=month&date=' . $from)) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg> Im Kalender
|
||||
</a>
|
||||
<a class="btn" href="<?= e(url('/')) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-grid"/></svg> Zur Übersicht
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2>Zeitraum</h2>
|
||||
<p>Ein Wechseltag ist erlaubt: Endet eine Buchung am Tag des neuen Beginns, gilt das Fahrzeug als frei.</p>
|
||||
</div>
|
||||
<form method="get" action="<?= e(url('/availability')) ?>" class="form-grid">
|
||||
<label class="field<?= $fieldError('from') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Von</span>
|
||||
<input type="date" name="from" value="<?= e($from) ?>" required>
|
||||
<?php if ($fieldError('from')): ?><em class="field-error"><?= e($fieldError('from')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<label class="field<?= $fieldError('to') !== '' ? ' has-error' : '' ?>">
|
||||
<span>Bis</span>
|
||||
<input type="date" name="to" value="<?= e($to) ?>" required>
|
||||
<?php if ($fieldError('to')): ?><em class="field-error"><?= e($fieldError('to')) ?></em><?php endif; ?>
|
||||
</label>
|
||||
<div class="field field--wide">
|
||||
<button class="btn primary" type="submit">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg> Verfügbarkeit prüfen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<?php if ($checked && !$errors): ?>
|
||||
<section class="card">
|
||||
<div class="card__head card__head--row">
|
||||
<div>
|
||||
<h2>Ergebnis</h2>
|
||||
<p><?= e(fmt_date_range($from, $to)) ?> · <?= (int) $freeCount ?> von <?= (int) $total ?> frei</p>
|
||||
</div>
|
||||
<a class="btn small" href="<?= e(url('/bookings/new?start=' . rawurlencode($from) . '&end=' . rawurlencode($to))) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="availability-grid">
|
||||
<?php foreach ($groupMeta as $key => $meta): ?>
|
||||
<?php
|
||||
$rows = $groups[$key];
|
||||
$free = count(array_filter($rows, static fn (array $row): bool => $row['free']));
|
||||
?>
|
||||
<div class="availability-group">
|
||||
<h3>
|
||||
<?= e($meta['title']) ?>
|
||||
<span class="muted small"><?= $free ?> von <?= count($rows) ?> frei</span>
|
||||
</h3>
|
||||
<?php if (!$rows): ?>
|
||||
<p class="muted small"><?= e($meta['empty']) ?></p>
|
||||
<?php else: ?>
|
||||
<ul class="availability-list">
|
||||
<?php foreach ($rows as $row): ?>
|
||||
<?php $trailer = $row['trailer']; ?>
|
||||
<li class="availability-row<?= $row['free'] ? ' is-free' : ' is-busy' ?>">
|
||||
<span class="availability-row__name">
|
||||
<span class="trailer-chip" style="--trailer: <?= e($trailer['color_hex']) ?>; --trailer-text: <?= e(contrast_color($trailer['color_hex'])) ?>">
|
||||
<span class="trailer-dot" style="--trailer: <?= e($trailer['color_hex']) ?>"></span>
|
||||
<?= e($trailer['label']) ?> · <?= e($trailer['color_name']) ?>
|
||||
</span>
|
||||
</span>
|
||||
<?php if ($row['free']): ?>
|
||||
<span class="pill pill--green">frei</span>
|
||||
<a class="btn small primary" href="<?= e(url($bookingUrl($trailer))) ?>">Buchen</a>
|
||||
<?php else: ?>
|
||||
<?php $conflict = $row['conflicts'][0]; ?>
|
||||
<span class="pill pill--grey">belegt</span>
|
||||
<span class="availability-row__hint muted small">
|
||||
<?= e(fmt_date_range((string) $conflict['start_date'], (string) $conflict['end_date'])) ?>
|
||||
· <?= e((string) $conflict['customer_name']) ?>
|
||||
<?php if (count($row['conflicts']) > 1): ?>
|
||||
(+<?= count($row['conflicts']) - 1 ?>)
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
<a class="link-button small" href="<?= e(url('/bookings/' . (int) $conflict['id'])) ?>">Ansehen</a>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php elseif ($checked): ?>
|
||||
<div class="alert alert--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Bitte den Zeitraum prüfen.</strong>
|
||||
<?php foreach ($errors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="empty-state small">
|
||||
<p>Zeitraum wählen und „Verfügbarkeit prüfen" – danach kannst du direkt buchen.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
|
@ -41,6 +41,9 @@ $isEmployeeView = $employeeScope > 0;
|
|||
<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>
|
||||
<a class="btn" href="<?= e(url('/calendar')) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg> Kalender
|
||||
</a>
|
||||
|
|
|
|||
|
|
@ -342,8 +342,26 @@ a .ico, button .ico { pointer-events: none; }
|
|||
.kpi strong { display: block; font-family: var(--font-display); font-size: 1.3rem; color: var(--ink); line-height: 1.1; }
|
||||
.kpi span { font-size: .78rem; color: var(--muted); }
|
||||
|
||||
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(300px, .85fr); gap: 18px; align-items: start; }
|
||||
.dash-main, .dash-side { display: grid; gap: 18px; min-width: 0; }
|
||||
/* ---------------------------------------------------------- Verfügbarkeit */
|
||||
.availability-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
|
||||
.availability-group h3 {
|
||||
display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
|
||||
margin: 0 0 8px; font-size: .95rem;
|
||||
}
|
||||
.availability-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
||||
.availability-row {
|
||||
display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
|
||||
padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
|
||||
}
|
||||
.availability-row.is-free { border-color: #bfe3bf; background: #f8fdf8; }
|
||||
.availability-row.is-busy { background: #fbfcfd; }
|
||||
.availability-row__name { flex: 1 1 auto; min-width: 0; }
|
||||
.availability-row__hint { flex: 1 1 100%; }
|
||||
@media (max-width: 760px) {
|
||||
.availability-grid { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(300px, .85fr); gap: 18px; align-items: start; }.dash-main, .dash-side { display: grid; gap: 18px; min-width: 0; }
|
||||
.trailer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.trailer-card {
|
||||
border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 13px;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue