Kundenmail 26.11.: Feiertage NRW, Abwesenheitsfilter, Von/Bis-Automatik, Navigation, zweiter Mitarbeiter im Kalender, Bearbeitungsrechte, Bemerkungsfeld, Frei-bis
- Feiertage NRW im Kalender markiert (eigene Osterformel, keine Extra-Extension) - Abwesenheiten: Zeitraeume 'Naechster Monat'/'Alle' plus Mitarbeiterfilter - 'Bis' folgt 'Von' per data-date-pair; Kalender waehlt Zeitraum mit zwei Klicks - Hauptnavigation: Uebersicht - Erinnerungen - Kalender - Abwesenheiten - Verwaltung - Kalender zeigt abweichenden Ruecknahme-Mitarbeiter auch bei kurzen Buchungen - Buchungen bearbeiten/verschieben fuer alle Mitarbeiter; Anlegen, Storno, Loeschen und Betraege/Rechnungsdaten bleiben beim Admin (serverseitig erzwungen) - Bemerkungsfeld je Buchung (Migration 008_booking_note.sql, nicht im Kundentext) - Uebersicht: 'Frei bis <Datum>' bei freien Anhaengern
This commit is contained in:
parent
1ade7624e2
commit
7e462d84a1
20 changed files with 969 additions and 91 deletions
26
app/auth.php
26
app/auth.php
|
|
@ -314,6 +314,32 @@ function auth_can_manage(User|null|array $user): bool
|
|||
return is_array($user) && ($user['role'] ?? '') === 'admin';
|
||||
}
|
||||
|
||||
/**
|
||||
* Buchungen anlegen dürfen nur Admins (Stammdatenpflege, Preise).
|
||||
*/
|
||||
function auth_can_create_booking(User|null|array $user): bool
|
||||
{
|
||||
return auth_can_manage($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Buchungen bearbeiten – Termine, Uhrzeiten, Anhänger, Mitarbeiter und
|
||||
* Bemerkung – dürfen alle angemeldeten Mitarbeiter: sie stimmen Übergabe und
|
||||
* Rückgabe mit dem Kunden ab.
|
||||
*/
|
||||
function auth_can_edit_booking(User|null|array $user): bool
|
||||
{
|
||||
return is_array($user) && (int) ($user['id'] ?? 0) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stornieren, Wiederherstellen und Löschen bleiben dem Admin vorbehalten.
|
||||
*/
|
||||
function auth_can_cancel_booking(User|null|array $user): bool
|
||||
{
|
||||
return auth_can_manage($user);
|
||||
}
|
||||
|
||||
function auth_employee_id(array $user): int
|
||||
{
|
||||
return (int) ($user['employee_id'] ?? 0);
|
||||
|
|
|
|||
46
app/data.php
46
app/data.php
|
|
@ -125,6 +125,13 @@ function booking_conflicts(int $trailerId, string $start, string $end, int $excl
|
|||
}
|
||||
|
||||
/** Formulardaten in ein normalisiertes Array übersetzen. */
|
||||
/** Bemerkung normalisieren: Zeilenumbrüche vereinheitlichen und trimmen. */
|
||||
function booking_note_clean(string $note): string
|
||||
{
|
||||
$note = str_replace(["\r\n", "\r"], "\n", $note);
|
||||
return trim($note);
|
||||
}
|
||||
|
||||
function booking_input(array $source): array
|
||||
{
|
||||
$kind = (string) ($source['kind'] ?? 'pickup');
|
||||
|
|
@ -163,6 +170,7 @@ function booking_input(array $source): array
|
|||
'city' => trim((string) ($source['city'] ?? '')),
|
||||
'mobile' => trim((string) ($source['mobile'] ?? '')),
|
||||
'email' => trim((string) ($source['email'] ?? '')),
|
||||
'note' => booking_note_clean((string) ($source['note'] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -189,6 +197,7 @@ function booking_to_input(array $booking): array
|
|||
'city' => (string) $booking['city'],
|
||||
'mobile' => (string) $booking['mobile'],
|
||||
'email' => (string) $booking['email'],
|
||||
'note' => (string) ($booking['note'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -248,6 +257,9 @@ function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId =
|
|||
} elseif (mb_strlen($data['customer_name']) > 190) {
|
||||
$errors['customer_name'] = 'Der Kundenname ist zu lang (max. 190 Zeichen).';
|
||||
}
|
||||
if (mb_strlen((string) ($data['note'] ?? '')) > 500) {
|
||||
$errors['note'] = 'Die Bemerkung ist zu lang (max. 500 Zeichen).';
|
||||
}
|
||||
foreach (['street' => 'Straße', 'city' => 'Ort', 'mobile' => 'Handy'] as $field => $label) {
|
||||
if (mb_strlen((string) $data[$field]) > 190) {
|
||||
$errors[$field] = $label . ' ist zu lang (max. 190 Zeichen).';
|
||||
|
|
@ -345,6 +357,21 @@ function absence_find(int $id): ?array
|
|||
return $row ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Früheste und späteste Abwesenheit – Zeitfenster für die Vollansicht
|
||||
* „Alle“ auf der Team-Seite.
|
||||
*
|
||||
* @return array{0: string, 1: string} [erster Tag, letzter Tag] oder ['', '']
|
||||
*/
|
||||
function absence_bounds(): array
|
||||
{
|
||||
$row = db()->query('SELECT MIN(start_date) AS first_day, MAX(end_date) AS last_day FROM absences')->fetch();
|
||||
if (!$row || $row['first_day'] === null) {
|
||||
return ['', ''];
|
||||
}
|
||||
return [(string) $row['first_day'], (string) $row['last_day']];
|
||||
}
|
||||
|
||||
/** Abwesenheit, die den Mitarbeiter im Zeitraum (inkl. Vorlauf) betrifft. */
|
||||
function booking_absence_conflict(int $employeeId, string $startDate, string $endDate): ?array
|
||||
{
|
||||
|
|
@ -460,8 +487,8 @@ function booking_create(array $data, int $userId): int
|
|||
'INSERT INTO bookings
|
||||
(trailer_id, employee_id, return_employee_id, start_date, end_date, start_time, end_time, deposit_cents,
|
||||
rent_cents, delivery_cents, total_cents, invoice, invoice_no, kind,
|
||||
customer_name, street, city, mobile, email, status, created_at, updated_at, created_by, updated_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "active", ?, ?, ?, ?)'
|
||||
customer_name, street, city, mobile, email, note, status, created_at, updated_at, created_by, updated_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "active", ?, ?, ?, ?)'
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['trailer_id'], $data['employee_id'], $data['return_employee_id'] ?: null,
|
||||
|
|
@ -470,6 +497,7 @@ function booking_create(array $data, int $userId): int
|
|||
$data['deposit_cents'], $data['rent_cents'], $data['delivery_cents'], $data['total_cents'],
|
||||
$data['invoice'], null_if_empty($data['invoice_no']), $data['kind'],
|
||||
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
|
||||
(string) ($data['note'] ?? ''),
|
||||
utc_now(), utc_now(), $userId, $userId,
|
||||
]);
|
||||
$id = (int) $pdo->lastInsertId();
|
||||
|
|
@ -500,7 +528,7 @@ function booking_update(int $id, array $data, int $userId): void
|
|||
'UPDATE bookings SET trailer_id = ?, employee_id = ?, return_employee_id = ?, start_date = ?, end_date = ?,
|
||||
start_time = ?, end_time = ?, deposit_cents = ?, rent_cents = ?, delivery_cents = ?,
|
||||
total_cents = ?, invoice = ?, invoice_no = ?, kind = ?, customer_name = ?, street = ?,
|
||||
city = ?, mobile = ?, email = ?, updated_at = ?, updated_by = ? WHERE id = ?'
|
||||
city = ?, mobile = ?, email = ?, note = ?, updated_at = ?, updated_by = ? WHERE id = ?'
|
||||
);
|
||||
$stmt->execute([
|
||||
$data['trailer_id'], $data['employee_id'], $data['return_employee_id'] ?: null,
|
||||
|
|
@ -509,6 +537,7 @@ function booking_update(int $id, array $data, int $userId): void
|
|||
$data['deposit_cents'], $data['rent_cents'], $data['delivery_cents'], $data['total_cents'],
|
||||
$data['invoice'], null_if_empty($data['invoice_no']), $data['kind'],
|
||||
$data['customer_name'], $data['street'], $data['city'], $data['mobile'], $data['email'],
|
||||
(string) ($data['note'] ?? ''),
|
||||
utc_now(), $userId, $id,
|
||||
]);
|
||||
$pdo->commit();
|
||||
|
|
@ -1001,6 +1030,17 @@ function calendar_geometry(array $booking, string $from, string $to, int $lanes)
|
|||
];
|
||||
}
|
||||
|
||||
/** Nächste aktive Buchung eines Anhängers ab einem Datum (für „Frei bis …“). */
|
||||
function next_booking_start(int $trailerId, string $fromDate): ?array
|
||||
{
|
||||
$sql = BOOKING_SELECT . " WHERE b.trailer_id = ? AND b.status = 'active' AND b.start_date > ?
|
||||
ORDER BY b.start_date LIMIT 1";
|
||||
$stmt = db()->prepare($sql);
|
||||
$stmt->execute([$trailerId, $fromDate]);
|
||||
$row = $stmt->fetch();
|
||||
return $row ?: null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- Auswertung */
|
||||
|
||||
function bookings_by_date(string $date): array
|
||||
|
|
|
|||
132
app/pages.php
132
app/pages.php
|
|
@ -374,9 +374,20 @@ function page_dashboard(array $user): void
|
|||
|
||||
$roadmap = [];
|
||||
foreach ($trailers as $trailer) {
|
||||
$bookings = $byTrailer[(int) $trailer['id']] ?? [];
|
||||
// Frei bis: Tag vor dem nächsten Mietbeginn. Ohne Folge-Buchung bleibt
|
||||
// der Anhänger dauerhaft frei (null).
|
||||
$freeUntil = null;
|
||||
if (!$bookings) {
|
||||
$next = next_booking_start((int) $trailer['id'], $today);
|
||||
if ($next !== null) {
|
||||
$freeUntil = add_days((string) $next['start_date'], -1);
|
||||
}
|
||||
}
|
||||
$roadmap[] = [
|
||||
'trailer' => $trailer,
|
||||
'bookings' => $byTrailer[(int) $trailer['id']] ?? [],
|
||||
'bookings' => $bookings,
|
||||
'free_until' => $freeUntil,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -478,6 +489,7 @@ function page_calendar(array $user): void
|
|||
'is_weekend' => (int) date_obj($cursor)->format('N') >= 6,
|
||||
'is_week_start' => date_obj($cursor)->format('N') === '1',
|
||||
'is_first_of_month' => date_obj($cursor)->format('j') === '1',
|
||||
'holiday' => holiday_name($cursor),
|
||||
];
|
||||
$cursor = add_days($cursor, 1);
|
||||
}
|
||||
|
|
@ -497,11 +509,20 @@ function page_calendar(array $user): void
|
|||
'absent' => booking_absent_hits($booking, $absences) !== [],
|
||||
];
|
||||
}
|
||||
// Zeigt ein Balken zusätzlich den abweichenden Rücknahme-Mitarbeiter,
|
||||
// braucht er eine Zeile mehr – die Anhängerzeile wächst entsprechend.
|
||||
$extraMeta = false;
|
||||
foreach ($laneInfo['bookings'] as $booking) {
|
||||
if (booking_has_separate_return($booking)) {
|
||||
$extraMeta = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$rows[] = [
|
||||
'trailer' => $trailer,
|
||||
'lanes' => $lanes,
|
||||
'bars' => $bars,
|
||||
'height' => max($rowMin, $barBase * $lanes + 16),
|
||||
'height' => max($rowMin, $barBase * $lanes + 16 + ($extraMeta ? 14 : 0)),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -672,6 +693,7 @@ function booking_form_context(array $user, ?array $booking = null, array $values
|
|||
'employees' => $employeeOptions,
|
||||
'user' => $user,
|
||||
'isEdit' => $booking !== null,
|
||||
'canEditBilling' => auth_can_manage($user),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -696,12 +718,13 @@ function form_values_from_input(array $data): array
|
|||
'city' => (string) $data['city'],
|
||||
'mobile' => (string) $data['mobile'],
|
||||
'email' => (string) $data['email'],
|
||||
'note' => (string) ($data['note'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
function page_booking_new(array $user, string $method): void
|
||||
{
|
||||
if (!auth_can_manage($user)) {
|
||||
if (!auth_can_create_booking($user)) {
|
||||
abort_page(403, 'Nur Administratoren dürfen Buchungen anlegen.');
|
||||
}
|
||||
|
||||
|
|
@ -747,6 +770,7 @@ function page_booking_new(array $user, string $method): void
|
|||
'city' => '',
|
||||
'mobile' => '',
|
||||
'email' => '',
|
||||
'note' => '',
|
||||
];
|
||||
$errors = [];
|
||||
|
||||
|
|
@ -772,6 +796,10 @@ function page_booking_new(array $user, string $method): void
|
|||
|
||||
function page_booking_edit(array $user, int $id, string $method): void
|
||||
{
|
||||
if (!auth_can_edit_booking($user)) {
|
||||
abort_page(403, 'Bitte anmelden, um Buchungen zu bearbeiten.');
|
||||
}
|
||||
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
|
|
@ -796,12 +824,26 @@ function page_booking_edit(array $user, int $id, string $method): void
|
|||
'city' => (string) $booking['city'],
|
||||
'mobile' => (string) $booking['mobile'],
|
||||
'email' => (string) $booking['email'],
|
||||
'note' => (string) ($booking['note'] ?? ''),
|
||||
];
|
||||
$errors = [];
|
||||
|
||||
// Beträge und Rechnungsdaten darf nur ein Admin ändern; sie werden bei
|
||||
// allen anderen aus der bestehenden Buchung übernommen – auch dann, wenn
|
||||
// sie manipuliert mitgeschickt wurden.
|
||||
$canEditBilling = auth_can_manage($user);
|
||||
|
||||
if ($method === 'POST') {
|
||||
require_post();
|
||||
$data = booking_input($_POST);
|
||||
if (!$canEditBilling) {
|
||||
$data['deposit_cents'] = (int) $booking['deposit_cents'];
|
||||
$data['rent_cents'] = (int) $booking['rent_cents'];
|
||||
$data['delivery_cents'] = (int) $booking['delivery_cents'];
|
||||
$data['total_cents'] = (int) $booking['total_cents'];
|
||||
$data['invoice'] = (int) $booking['invoice'];
|
||||
$data['invoice_no'] = (string) ($booking['invoice_no'] ?? '');
|
||||
}
|
||||
$values = form_values_from_input($data);
|
||||
$errors = booking_validate($data, $id, (int) $booking['trailer_id'], (int) $booking['employee_id']);
|
||||
if (!$errors) {
|
||||
|
|
@ -833,6 +875,11 @@ function booking_detail_context(array $booking, array $user): array
|
|||
'canDelete' => $isAdmin && !$deleteBlocked,
|
||||
'deleteBlocked' => $deleteBlocked,
|
||||
'isAdmin' => $isAdmin,
|
||||
// Bearbeiten (Termine, Zeiten, Mitarbeiter, Bemerkung) dürfen alle
|
||||
// angemeldeten Mitarbeiter; Stornieren/Löschen bleibt beim Admin.
|
||||
'canEdit' => auth_can_edit_booking($user),
|
||||
'canCancel' => auth_can_cancel_booking($user),
|
||||
'canEditBilling' => $isAdmin,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -858,6 +905,9 @@ function page_booking_panel(array $user, int $id): void
|
|||
function page_booking_cancel(array $user, int $id): void
|
||||
{
|
||||
require_post();
|
||||
if (!auth_can_cancel_booking($user)) {
|
||||
abort_page(403, 'Nur Administratoren dürfen Buchungen stornieren.');
|
||||
}
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
|
|
@ -873,6 +923,9 @@ function page_booking_cancel(array $user, int $id): void
|
|||
function page_booking_restore(array $user, int $id): void
|
||||
{
|
||||
require_post();
|
||||
if (!auth_can_cancel_booking($user)) {
|
||||
abort_page(403, 'Nur Administratoren dürfen Buchungen wiederherstellen.');
|
||||
}
|
||||
$booking = booking_find($id);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Buchung nicht gefunden.');
|
||||
|
|
@ -895,7 +948,7 @@ function page_booking_restore(array $user, int $id): void
|
|||
function page_booking_delete(array $user, int $id): void
|
||||
{
|
||||
require_post();
|
||||
if (($user['role'] ?? '') !== 'admin') {
|
||||
if (!auth_can_manage($user)) {
|
||||
abort_page(403, 'Nur Administratoren dürfen Buchungen löschen.');
|
||||
}
|
||||
$booking = booking_find($id);
|
||||
|
|
@ -916,6 +969,9 @@ function page_booking_delete(array $user, int $id): void
|
|||
function page_booking_move(array $user, int $id): void
|
||||
{
|
||||
require_post();
|
||||
if (!auth_can_edit_booking($user)) {
|
||||
abort_page(403, 'Bitte anmelden, um Buchungen zu verschieben.');
|
||||
}
|
||||
$result = booking_move(
|
||||
$id,
|
||||
post_string('start_date'),
|
||||
|
|
@ -1033,7 +1089,7 @@ function page_absences(array $user, string $method): void
|
|||
$employees = employees_all(false);
|
||||
|
||||
$period = query_string('period', 'weeks');
|
||||
if (!in_array($period, ['weeks', 'month'], true)) {
|
||||
if (!in_array($period, ['weeks', 'month', 'next_month', 'all'], true)) {
|
||||
$period = 'weeks';
|
||||
}
|
||||
$today = today_iso();
|
||||
|
|
@ -1041,8 +1097,32 @@ function page_absences(array $user, string $method): void
|
|||
if (!valid_date($date)) {
|
||||
$date = query_string('from') !== '' && valid_date(query_string('from')) ? query_string('from') : $today;
|
||||
}
|
||||
$from = $period === 'month' ? month_start($date) : week_start($date);
|
||||
$to = $period === 'month' ? month_end($date) : add_days($from, CALENDAR_WEEKS * 7 - 1);
|
||||
|
||||
// Mitarbeiterfilter: 0 = alle, sonst genau eine Person.
|
||||
$employeeFilter = query_int('employee');
|
||||
if ($employeeFilter > 0 && !array_filter($employees, static fn (array $e): bool => (int) $e['id'] === $employeeFilter)) {
|
||||
$employeeFilter = 0;
|
||||
}
|
||||
|
||||
if ($period === 'month') {
|
||||
$from = month_start($date);
|
||||
$to = month_end($date);
|
||||
$anchor = $from;
|
||||
} elseif ($period === 'next_month') {
|
||||
// Kunde: „den nächsten Monat oder alle anzeigen lassen“.
|
||||
$anchor = date_obj(month_start($date))->modify('+1 month')->format('Y-m-d');
|
||||
$from = month_start($anchor);
|
||||
$to = month_end($anchor);
|
||||
} elseif ($period === 'all') {
|
||||
[$firstDay, $lastDay] = absence_bounds();
|
||||
$anchor = $today;
|
||||
$from = $firstDay !== '' ? min($firstDay, $today) : $today;
|
||||
$to = $lastDay !== '' ? max($lastDay, $today) : $today;
|
||||
} else {
|
||||
$from = week_start($date);
|
||||
$to = add_days($from, CALENDAR_WEEKS * 7 - 1);
|
||||
$anchor = $from;
|
||||
}
|
||||
|
||||
$editId = query_int('edit');
|
||||
$editing = $editId > 0 ? absence_find($editId) : null;
|
||||
|
|
@ -1050,11 +1130,17 @@ function page_absences(array $user, string $method): void
|
|||
abort_page(403, 'Diese Abwesenheit gehört zu einem anderen Mitarbeiter.');
|
||||
}
|
||||
|
||||
$defaultStart = $period === 'all' ? $today : $from;
|
||||
$prefillEnd = query_string('to');
|
||||
if (!valid_date($prefillEnd) || $prefillEnd < $defaultStart) {
|
||||
$prefillEnd = $defaultStart;
|
||||
}
|
||||
|
||||
$values = [
|
||||
'id' => $editing ? (int) $editing['id'] : 0,
|
||||
'employee_id' => $editing ? (int) $editing['employee_id'] : ($isAdmin ? 0 : $ownEmployeeId),
|
||||
'start_date' => $editing ? (string) $editing['start_date'] : $from,
|
||||
'end_date' => $editing ? (string) $editing['end_date'] : $from,
|
||||
'employee_id' => $editing ? (int) $editing['employee_id'] : ($isAdmin ? ($employeeFilter ?: 0) : $ownEmployeeId),
|
||||
'start_date' => $editing ? (string) $editing['start_date'] : $defaultStart,
|
||||
'end_date' => $editing ? (string) $editing['end_date'] : $prefillEnd,
|
||||
'note' => $editing ? (string) $editing['note'] : '',
|
||||
];
|
||||
$errors = [];
|
||||
|
|
@ -1080,12 +1166,15 @@ function page_absences(array $user, string $method): void
|
|||
$message .= ' Achtung: Es gibt bereits Buchungen in diesem Zeitraum – bitte Mitarbeiter tauschen.';
|
||||
}
|
||||
flash('success', $message);
|
||||
redirect('/absences?date=' . rawurlencode((string) $values['start_date']) . '&period=' . $period . '#abwesenheit-' . $id);
|
||||
redirect('/absences?date=' . rawurlencode((string) $values['start_date'])
|
||||
. '&period=' . rawurlencode($period)
|
||||
. ($employeeFilter > 0 ? '&employee=' . $employeeFilter : '')
|
||||
. '#abwesenheit-' . $id);
|
||||
}
|
||||
http_response_code(422);
|
||||
}
|
||||
|
||||
$rows = absence_list($from, $to);
|
||||
$rows = absence_list($from, $to, $employeeFilter);
|
||||
$byEmployee = [];
|
||||
foreach ($employees as $employee) {
|
||||
$byEmployee[(int) $employee['id']] = [
|
||||
|
|
@ -1112,12 +1201,18 @@ function page_absences(array $user, string $method): void
|
|||
}
|
||||
}
|
||||
|
||||
$prevDate = $period === 'month'
|
||||
? date_obj($from)->modify('-1 month')->format('Y-m-d')
|
||||
: add_days($date, -CALENDAR_WEEKS * 7);
|
||||
$nextDate = $period === 'month'
|
||||
? date_obj($from)->modify('+1 month')->format('Y-m-d')
|
||||
: add_days($date, CALENDAR_WEEKS * 7);
|
||||
$prevDate = match ($period) {
|
||||
'month' => date_obj(month_start($anchor))->modify('-1 month')->format('Y-m-d'),
|
||||
'next_month' => month_start($anchor),
|
||||
'all' => $anchor,
|
||||
default => add_days($anchor, -CALENDAR_WEEKS * 7),
|
||||
};
|
||||
$nextDate = match ($period) {
|
||||
'month' => date_obj(month_start($anchor))->modify('+1 month')->format('Y-m-d'),
|
||||
'next_month' => date_obj(month_start($anchor))->modify('+2 months')->format('Y-m-d'),
|
||||
'all' => $anchor,
|
||||
default => add_days($anchor, CALENDAR_WEEKS * 7),
|
||||
};
|
||||
|
||||
render_page('absences', [
|
||||
'user' => $user,
|
||||
|
|
@ -1129,6 +1224,7 @@ function page_absences(array $user, string $method): void
|
|||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'period' => $period,
|
||||
'employeeFilter' => $employeeFilter,
|
||||
'date' => $date,
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
|
|
|
|||
72
app/util.php
72
app/util.php
|
|
@ -92,7 +92,7 @@ function url(string $path = '/'): string
|
|||
}
|
||||
|
||||
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
|
||||
const DIC_ASSET_VERSION = '25';
|
||||
const DIC_ASSET_VERSION = '26';
|
||||
|
||||
function asset(string $path): string
|
||||
{
|
||||
|
|
@ -355,6 +355,76 @@ function month_end(string $iso): string
|
|||
return date_obj($iso)->modify('last day of this month')->format('Y-m-d');
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ Feiertage */
|
||||
|
||||
/**
|
||||
* Ostersonntag nach der anonymen gregorianischen Osterformel. Bewusst ohne
|
||||
* `easter_date()`, damit keine zusätzliche PHP-Extension nötig ist.
|
||||
*/
|
||||
function easter_sunday(int $year): string
|
||||
{
|
||||
$a = $year % 19;
|
||||
$b = intdiv($year, 100);
|
||||
$c = $year % 100;
|
||||
$d = intdiv($b, 4);
|
||||
$e = $b % 4;
|
||||
$f = intdiv($b + 8, 25);
|
||||
$g = intdiv($b - $f + 1, 3);
|
||||
$h = (19 * $a + $b - $d - $g + 15) % 30;
|
||||
$i = intdiv($c, 4);
|
||||
$k = $c % 4;
|
||||
$l = (32 + 2 * $e + 2 * $i - $h - $k) % 7;
|
||||
$m = intdiv($a + 11 * $h + 22 * $l, 451);
|
||||
$month = intdiv($h + $l - 7 * $m + 114, 31);
|
||||
$day = (($h + $l - 7 * $m + 114) % 31) + 1;
|
||||
return sprintf('%04d-%02d-%02d', $year, $month, $day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gesetzliche Feiertage in Nordrhein-Westfalen als `['Y-m-d' => Name]`.
|
||||
* Grundlage für die farbliche Markierung im Kalender (Wochenenden und
|
||||
* Feiertage werden preislich anders berechnet).
|
||||
*/
|
||||
function holidays_nrw(int $year): array
|
||||
{
|
||||
static $cache = [];
|
||||
if (isset($cache[$year])) {
|
||||
return $cache[$year];
|
||||
}
|
||||
|
||||
$easter = easter_sunday($year);
|
||||
$map = [
|
||||
sprintf('%04d-01-01', $year) => 'Neujahr',
|
||||
add_days($easter, -2) => 'Karfreitag',
|
||||
add_days($easter, 1) => 'Ostermontag',
|
||||
sprintf('%04d-05-01', $year) => 'Tag der Arbeit',
|
||||
add_days($easter, 39) => 'Christi Himmelfahrt',
|
||||
add_days($easter, 50) => 'Pfingstmontag',
|
||||
add_days($easter, 60) => 'Fronleichnam',
|
||||
sprintf('%04d-10-03', $year) => 'Tag der Deutschen Einheit',
|
||||
sprintf('%04d-11-01', $year) => 'Allerheiligen',
|
||||
sprintf('%04d-12-25', $year) => '1. Weihnachtstag',
|
||||
sprintf('%04d-12-26', $year) => '2. Weihnachtstag',
|
||||
];
|
||||
ksort($map);
|
||||
$cache[$year] = $map;
|
||||
return $map;
|
||||
}
|
||||
|
||||
/** Name des Feiertags am Datum oder `null`, wenn kein gesetzlicher Feiertag (NRW). */
|
||||
function holiday_name(string $iso): ?string
|
||||
{
|
||||
if (!valid_date($iso)) {
|
||||
return null;
|
||||
}
|
||||
return holidays_nrw((int) substr($iso, 0, 4))[$iso] ?? null;
|
||||
}
|
||||
|
||||
function is_holiday(string $iso): bool
|
||||
{
|
||||
return holiday_name($iso) !== null;
|
||||
}
|
||||
|
||||
function fmt_date(string $iso): string
|
||||
{
|
||||
return valid_date($iso) ? date_obj($iso)->format('d.m.Y') : '–';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue