Erinnerungsversand erst ab 60 Minuten Buchungsalter; abweichende Rücknahme als Sonderfall im Formular

This commit is contained in:
torsten 2026-11-25 21:49:40 +01:00
parent 14f9346763
commit e1e2332ce4
9 changed files with 75 additions and 22 deletions

View file

@ -146,7 +146,10 @@ function booking_input(array $source): array
return [
'trailer_id' => (int) ($source['trailer_id'] ?? 0),
'employee_id' => (int) ($source['employee_id'] ?? 0),
'return_employee_id' => (int) ($source['return_employee_id'] ?? 0),
// Abweichende Rücknahme ist ein Sonderfall: Sie gilt nur, wenn das
// Formular sie über die Checkbox ausdrücklich aktiviert hat.
'separate_return' => !empty($source['separate_return']),
'return_employee_id' => !empty($source['separate_return']) ? (int) ($source['return_employee_id'] ?? 0) : 0,
'start_date' => trim((string) ($source['start_date'] ?? '')),
'end_date' => trim((string) ($source['end_date'] ?? '')),
'start_time' => normalize_time($source['start_time'] ?? ''),
@ -208,7 +211,9 @@ function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId =
// Optionaler, abweichender Mitarbeiter für die Abholung/Rücknahme.
$returnEmployeeId = (int) ($data['return_employee_id'] ?? 0);
if ($returnEmployeeId > 0) {
if (!empty($data['separate_return']) && $returnEmployeeId <= 0) {
$errors['return_employee_id'] = 'Bitte einen Mitarbeiter für die Rücknahme auswählen.';
} elseif ($returnEmployeeId > 0) {
$returnEmployee = employee_find($returnEmployeeId);
if (!$returnEmployee || ((int) $returnEmployee['active'] !== 1 && (int) $returnEmployee['id'] !== $allowEmployeeId)) {
$errors['return_employee_id'] = 'Bitte einen gültigen Mitarbeiter für die Rücknahme auswählen.';
@ -642,7 +647,15 @@ function reminder_done_key(array $booking, string $kind, string $dueDate): strin
* Buchungsdaten berechnet und sind damit bei Terminänderungen automatisch
* aktuell; eine Stornierung entfernt sie, weil nur aktive Buchungen zählen.
*/
function reminder_list(string $from, string $to, int $employeeId = 0, bool $includeDone = false): array
/**
* Mindestalter einer Buchung in Minuten, bevor ihre Erinnerungen per Push
* oder E-Mail verschickt werden. So kann der Ersteller die Buchungsdaten
* nach dem Anlegen noch korrigieren, ohne dass eine Erinnerung zur
* unfertigen Version rausgeht. Für die Anzeige in der App gilt das nicht.
*/
const REMINDER_SEND_MIN_AGE_MINUTES = 60;
function reminder_list(string $from, string $to, int $employeeId = 0, bool $includeDone = false, int $minBookingAgeMinutes = 0): array
{
if ($from > $to) {
[$from, $to] = [$to, $from];
@ -656,6 +669,11 @@ function reminder_list(string $from, string $to, int $employeeId = 0, bool $incl
$params[] = $employeeId;
$params[] = $employeeId;
}
if ($minBookingAgeMinutes > 0) {
// Nur Buchungen, die schon lange genug bestehen (created_at ist UTC).
$sql .= ' AND b.created_at <= ?';
$params[] = utc_after(-$minBookingAgeMinutes * 60);
}
$sql .= ' ORDER BY b.start_date, b.id';
$stmt = db()->prepare($sql);
$stmt->execute($params);

View file

@ -71,7 +71,7 @@ function reminder_send_due(int $lookbackDays = 7): array
$today = today_iso();
$from = add_days($today, -max(1, $lookbackDays));
$recipients = reminder_mail_recipients();
$rows = reminder_list($from, $today, 0, false);
$rows = reminder_list($from, $today, 0, false, REMINDER_SEND_MIN_AGE_MINUTES);
if (!$rows) {
return $result;
}

View file

@ -621,6 +621,7 @@ function form_values_from_input(array $data): array
'trailer_id' => (int) $data['trailer_id'],
'employee_id' => (int) $data['employee_id'],
'return_employee_id' => (int) ($data['return_employee_id'] ?? 0),
'separate_return' => !empty($data['separate_return']) ? 1 : 0,
'start_date' => (string) $data['start_date'],
'end_date' => (string) $data['end_date'],
'start_time' => (string) ($data['start_time'] ?? ''),

View file

@ -207,7 +207,7 @@ function push_dispatch_due(int $lookbackDays = 7): array
$today = today_iso();
$from = add_days($today, -max(1, $lookbackDays));
$rows = reminder_list($from, $today, 0, false);
$rows = reminder_list($from, $today, 0, false, REMINDER_SEND_MIN_AGE_MINUTES);
if (!$rows) {
return $result;
}