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:
parent
771954ba3d
commit
f27dea310c
2 changed files with 26 additions and 30 deletions
|
|
@ -474,17 +474,18 @@ function page_availability(array $user): void
|
||||||
}
|
}
|
||||||
|
|
||||||
$groups = ['trailer' => [], 'chest' => []];
|
$groups = ['trailer' => [], 'chest' => []];
|
||||||
|
$totals = ['trailer' => 0, 'chest' => 0];
|
||||||
$freeCount = 0;
|
$freeCount = 0;
|
||||||
if ($checked && !$errors) {
|
if ($checked && !$errors) {
|
||||||
foreach (trailers_all() as $trailer) {
|
foreach (trailers_all() as $trailer) {
|
||||||
$conflicts = booking_conflicts((int) $trailer['id'], $from, $to);
|
$key = trailer_is_chest($trailer) ? 'chest' : 'trailer';
|
||||||
$free = !$conflicts;
|
$totals[$key]++;
|
||||||
$freeCount += $free ? 1 : 0;
|
// Nur tatsächlich freie Fahrzeuge ausweisen; belegte entfallen.
|
||||||
$groups[trailer_is_chest($trailer) ? 'chest' : 'trailer'][] = [
|
if (booking_conflicts((int) $trailer['id'], $from, $to)) {
|
||||||
'trailer' => $trailer,
|
continue;
|
||||||
'free' => $free,
|
}
|
||||||
'conflicts' => $conflicts,
|
$freeCount++;
|
||||||
];
|
$groups[$key][] = ['trailer' => $trailer];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -494,8 +495,9 @@ function page_availability(array $user): void
|
||||||
'checked' => $checked,
|
'checked' => $checked,
|
||||||
'errors' => $errors,
|
'errors' => $errors,
|
||||||
'groups' => $groups,
|
'groups' => $groups,
|
||||||
|
'totals' => $totals,
|
||||||
'freeCount' => $freeCount,
|
'freeCount' => $freeCount,
|
||||||
'total' => count($groups['trailer']) + count($groups['chest']),
|
'total' => $totals['trailer'] + $totals['chest'],
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
], 'Verfügbarkeit');
|
], 'Verfügbarkeit');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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']
|
$bookingUrl = static fn (array $trailer): string => '/bookings/new?trailer=' . (int) $trailer['id']
|
||||||
. '&start=' . rawurlencode($from) . '&end=' . rawurlencode($to);
|
. '&start=' . rawurlencode($from) . '&end=' . rawurlencode($to);
|
||||||
$groupMeta = [
|
$groupMeta = [
|
||||||
'trailer' => ['title' => 'Anhänger', 'empty' => 'Keine Anhänger hinterlegt.'],
|
'trailer' => [
|
||||||
'chest' => ['title' => 'Truhen', 'empty' => 'Keine Truhen hinterlegt.'],
|
'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">
|
<div class="page-head page-head--compact">
|
||||||
|
|
@ -70,41 +78,27 @@ $groupMeta = [
|
||||||
<?php foreach ($groupMeta as $key => $meta): ?>
|
<?php foreach ($groupMeta as $key => $meta): ?>
|
||||||
<?php
|
<?php
|
||||||
$rows = $groups[$key];
|
$rows = $groups[$key];
|
||||||
$free = count(array_filter($rows, static fn (array $row): bool => $row['free']));
|
$groupTotal = (int) ($totals[$key] ?? 0);
|
||||||
?>
|
?>
|
||||||
<div class="availability-group">
|
<div class="availability-group">
|
||||||
<h3>
|
<h3>
|
||||||
<?= e($meta['title']) ?>
|
<?= e($meta['title']) ?>
|
||||||
<span class="muted small"><?= $free ?> von <?= count($rows) ?> frei</span>
|
<span class="muted small"><?= count($rows) ?> von <?= $groupTotal ?> frei</span>
|
||||||
</h3>
|
</h3>
|
||||||
<?php if (!$rows): ?>
|
<?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: ?>
|
<?php else: ?>
|
||||||
<ul class="availability-list">
|
<ul class="availability-list">
|
||||||
<?php foreach ($rows as $row): ?>
|
<?php foreach ($rows as $row): ?>
|
||||||
<?php $trailer = $row['trailer']; ?>
|
<?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="availability-row__name">
|
||||||
<span class="trailer-chip" style="--trailer: <?= e($trailer['color_hex']) ?>; --trailer-text: <?= e(contrast_color($trailer['color_hex'])) ?>">
|
<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>
|
<span class="trailer-dot" style="--trailer: <?= e($trailer['color_hex']) ?>"></span>
|
||||||
<?= e($trailer['label']) ?> · <?= e($trailer['color_name']) ?>
|
<?= e($trailer['label']) ?> · <?= e($trailer['color_name']) ?>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<?php if ($row['free']): ?>
|
<a class="btn small primary" href="<?= e(url($bookingUrl($trailer))) ?>">Buchen</a>
|
||||||
<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>
|
</li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue