Kalender: Abwesenheiten als eigene Zeilen mit dunklen Balken, kollidierende Buchungen blinken
This commit is contained in:
parent
e83d6dc606
commit
87fd553464
6 changed files with 128 additions and 3 deletions
29
app/data.php
29
app/data.php
|
|
@ -952,6 +952,35 @@ function calendar_lanes(array $bookings): array
|
|||
return ['bookings' => $out, 'lanes' => max(1, count($laneEnds))];
|
||||
}
|
||||
|
||||
/**
|
||||
* Abwesenheiten, die eine Buchung betreffen: Übergabe-Mitarbeiter ab dem
|
||||
* Erinnerungs-Vorlauf bis Mietbeginn, Rücknahme-Mitarbeiter entsprechend bis
|
||||
* Mietende (gleiche Regel wie die Sperre in booking_validate()).
|
||||
*/
|
||||
function booking_absent_hits(array $booking, array $absences): array
|
||||
{
|
||||
$handoverEmployee = (int) ($booking['employee_id'] ?? 0);
|
||||
$returnEmployee = (int) ($booking['return_employee_id'] ?? 0) ?: $handoverEmployee;
|
||||
$start = (string) $booking['start_date'];
|
||||
$end = (string) $booking['end_date'];
|
||||
$handoverFrom = add_days($start, -BOOKING_LEAD_DAYS);
|
||||
$returnFrom = add_days($end, -BOOKING_LEAD_DAYS);
|
||||
$hits = [];
|
||||
foreach ($absences as $absence) {
|
||||
$employee = (int) $absence['employee_id'];
|
||||
$absenceStart = (string) $absence['start_date'];
|
||||
$absenceEnd = (string) $absence['end_date'];
|
||||
if ($employee === $handoverEmployee && $absenceStart <= $start && $absenceEnd >= $handoverFrom) {
|
||||
$hits[] = $absence;
|
||||
continue;
|
||||
}
|
||||
if ($employee === $returnEmployee && $absenceStart <= $end && $absenceEnd >= $returnFrom) {
|
||||
$hits[] = $absence;
|
||||
}
|
||||
}
|
||||
return $hits;
|
||||
}
|
||||
|
||||
/** Position eines Balkens im sichtbaren Zeitraum (Prozent). */
|
||||
function calendar_geometry(array $booking, string $from, string $to, int $lanes): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -492,6 +492,7 @@ function page_calendar(array $user): void
|
|||
$bars[] = [
|
||||
'booking' => $booking,
|
||||
'geo' => calendar_geometry($booking, $from, $to, $lanes),
|
||||
'absent' => booking_absent_hits($booking, $absences) !== [],
|
||||
];
|
||||
}
|
||||
$rows[] = [
|
||||
|
|
@ -527,6 +528,31 @@ function page_calendar(array $user): void
|
|||
|
||||
$employees = employees_all();
|
||||
$absences = absence_list($from, $to);
|
||||
|
||||
// Abwesenheiten als eigene Zeilen unterhalb der Anhänger.
|
||||
$absencesByEmployee = [];
|
||||
foreach ($absences as $absence) {
|
||||
$absencesByEmployee[(int) $absence['employee_id']][] = $absence;
|
||||
}
|
||||
$absenceRows = [];
|
||||
foreach ($absencesByEmployee as $employeeAbsences) {
|
||||
$laneInfo = calendar_lanes($employeeAbsences);
|
||||
$bars = [];
|
||||
foreach ($laneInfo['bookings'] as $absence) {
|
||||
$bars[] = [
|
||||
'absence' => $absence,
|
||||
'geo' => calendar_geometry($absence, $from, $to, $laneInfo['lanes']),
|
||||
];
|
||||
}
|
||||
$absenceRows[] = [
|
||||
'employee_name' => (string) $employeeAbsences[0]['employee_name'],
|
||||
'employee_id' => (int) $employeeAbsences[0]['employee_id'],
|
||||
'bars' => $bars,
|
||||
'count' => count($employeeAbsences),
|
||||
'height' => max($rowMin, $barBase * $laneInfo['lanes'] + 16),
|
||||
];
|
||||
}
|
||||
|
||||
render_page('calendar', [
|
||||
'view' => $view,
|
||||
'date' => $date,
|
||||
|
|
@ -544,6 +570,7 @@ function page_calendar(array $user): void
|
|||
'employees' => $employees,
|
||||
'bookingCount' => count($bookings),
|
||||
'absences' => $absences,
|
||||
'absenceRows' => $absenceRows,
|
||||
'urlFor' => static function (string $d) use ($view, $employeeId, $showCancelled): string {
|
||||
return calendar_url($d, $view, $employeeId, $showCancelled);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ function url(string $path = '/'): string
|
|||
}
|
||||
|
||||
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
|
||||
const DIC_ASSET_VERSION = '24';
|
||||
const DIC_ASSET_VERSION = '25';
|
||||
|
||||
function asset(string $path): string
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue