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
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue