Verfügbarkeit: nur tatsächlich freie Anhänger und Truhen auflisten

Belegte Fahrzeuge erscheinen nicht mehr in der Auswahl; die Kopfzeile
nennt weiterhin "x von y frei". Ist für eine Gruppe nichts frei, steht
dort ein kurzer Hinweis.
This commit is contained in:
torsten 2026-11-18 21:47:11 +01:00
parent 771954ba3d
commit f27dea310c
2 changed files with 26 additions and 30 deletions

View file

@ -474,17 +474,18 @@ function page_availability(array $user): void
}
$groups = ['trailer' => [], 'chest' => []];
$totals = ['trailer' => 0, 'chest' => 0];
$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,
];
$key = trailer_is_chest($trailer) ? 'chest' : 'trailer';
$totals[$key]++;
// Nur tatsächlich freie Fahrzeuge ausweisen; belegte entfallen.
if (booking_conflicts((int) $trailer['id'], $from, $to)) {
continue;
}
$freeCount++;
$groups[$key][] = ['trailer' => $trailer];
}
}
@ -494,8 +495,9 @@ function page_availability(array $user): void
'checked' => $checked,
'errors' => $errors,
'groups' => $groups,
'totals' => $totals,
'freeCount' => $freeCount,
'total' => count($groups['trailer']) + count($groups['chest']),
'total' => $totals['trailer'] + $totals['chest'],
'user' => $user,
], 'Verfügbarkeit');
}

View file

@ -10,8 +10,16 @@ $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.'],
'trailer' => [
'title' => 'Anhänger',
'empty' => 'Keine Anhänger hinterlegt.',
'none_free' => 'Im Zeitraum ist kein Anhänger frei.',
],
'chest' => [
'title' => 'Truhen',
'empty' => 'Keine Truhen hinterlegt.',
'none_free' => 'Im Zeitraum ist keine Truhe frei.',
],
];
?>
<div class="page-head page-head--compact">
@ -70,41 +78,27 @@ $groupMeta = [
<?php foreach ($groupMeta as $key => $meta): ?>
<?php
$rows = $groups[$key];
$free = count(array_filter($rows, static fn (array $row): bool => $row['free']));
$groupTotal = (int) ($totals[$key] ?? 0);
?>
<div class="availability-group">
<h3>
<?= e($meta['title']) ?>
<span class="muted small"><?= $free ?> von <?= count($rows) ?> frei</span>
<span class="muted small"><?= count($rows) ?> von <?= $groupTotal ?> frei</span>
</h3>
<?php if (!$rows): ?>
<p class="muted small"><?= e($meta['empty']) ?></p>
<p class="muted small"><?= e($groupTotal === 0 ? $meta['empty'] : $meta['none_free']) ?></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' ?>">
<li class="availability-row is-free">
<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; ?>
<a class="btn small primary" href="<?= e(url($bookingUrl($trailer))) ?>">Buchen</a>
</li>
<?php endforeach; ?>
</ul>