feat(booking): Restzahlung bar oder per Überweisung mit Zahlungserinnerung und Verfügbarkeitsampel
- Buchung: neues Feld balance_method (cash|transfer) inkl. Migration 019, Formularfeld, Validierung (Konto Pflicht bei Überweisung), Anzeige in Buchungsdetail und kopiertem Kundentext. - Auftragsbestätigung: bei Überweisung Bankverbindung der Buchung, Restbetrag mit Zahlungsziel (5 Tage vor Mietbeginn) und Hinweis auf die Erinnerung; bei Barzahlung unverändert "bei der Übergabe in bar fällig". - Zahlungserinnerung als eigene Unterlage (Migration 018): offener Betrag (Restbetrag bei Anzahlung, sonst Gesamtbetrag), Konto der Buchung, Frist, Erzeugen/Mailen über die Buchungsseite, Handbuch und README. - Automatischer Versand: payment_reminder_send_due() im Cron-Lauf, 10 Tage vor Mietbeginn (app.transfer_reminder_days), genau ein Versand pro Termin über payment_reminder_log, kein Doppelversand nach manuellem Mailen. - Startseite: öffentliche Verfügbarkeitsampel für Kühlanhänger ohne Truhen (GET /verfuegbarkeit.json, availability_public_days()), Monatskalender mit Grün (>2 frei), Gelb (1-2) und Rot (ausgebucht); neuer Abschnitt #verfuegbarkeit inkl. Navigation, Footer und noscript-Hinweis. - Aufräumen: payment_reminder_log nach einem Jahr, Cron-Report erweitert.
This commit is contained in:
parent
506d802b33
commit
7445740b90
21 changed files with 911 additions and 46 deletions
|
|
@ -74,6 +74,10 @@ function page_handle(string $method, string $path): void
|
|||
page_inquiry($method);
|
||||
return;
|
||||
}
|
||||
if ($path === '/verfuegbarkeit.json') {
|
||||
availability_public_json();
|
||||
return;
|
||||
}
|
||||
if ($path === '/abmelden') {
|
||||
page_unsubscribe($method);
|
||||
return;
|
||||
|
|
@ -229,6 +233,52 @@ function health_check(): void
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffentlicher Verfügbarkeitskalender für die Startseite: nur Zähler pro Tag
|
||||
* (keine Namen, keine Buchungsdetails). Ohne Login erreichbar, kurz gecacht.
|
||||
*/
|
||||
function availability_public_json(): void
|
||||
{
|
||||
if (!in_array(request_method(), ['GET', 'HEAD'], true)) {
|
||||
http_response_code(405);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo '{"ok":false}';
|
||||
exit;
|
||||
}
|
||||
|
||||
$today = today_iso();
|
||||
$from = query_string('from');
|
||||
$from = valid_date($from) ? $from : $today;
|
||||
$to = query_string('to');
|
||||
$to = valid_date($to) ? $to : add_days($from, 62);
|
||||
if ($to < $from) {
|
||||
$to = $from;
|
||||
}
|
||||
if (days_between($from, $to) > 120) {
|
||||
$to = add_days($from, 120);
|
||||
}
|
||||
|
||||
try {
|
||||
$data = availability_public_days($from, $to);
|
||||
} catch (Throwable) {
|
||||
http_response_code(503);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-store');
|
||||
echo '{"ok":false}';
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Cache-Control: public, max-age=300');
|
||||
json_response([
|
||||
'ok' => true,
|
||||
'total' => $data['total'],
|
||||
'today' => $today,
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'days' => array_values($data['days']),
|
||||
]);
|
||||
}
|
||||
|
||||
function cron_reminders(): void
|
||||
{
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
|
@ -245,11 +295,13 @@ function cron_reminders(): void
|
|||
$cleanup = privacy_cleanup();
|
||||
$push = push_dispatch_due();
|
||||
$mail = reminder_send_due();
|
||||
$payments = payment_reminder_send_due();
|
||||
echo 'Drink it cold – Erinnerungslauf ' . fmt_datetime(utc_now()) . "\n";
|
||||
echo sprintf(
|
||||
"Aufräumen: %d Login-Fehlversuche, %d Tokens, %d Einladungen, %d E-Mail-Protokolle, %d Push-Protokolle, %d Buchungsunterlagen entfernt%s.\n",
|
||||
"Aufräumen: %d Login-Fehlversuche, %d Tokens, %d Einladungen, %d E-Mail-Protokolle, %d Zahlungserinnerungs-Protokolle, %d Push-Protokolle, %d Buchungsunterlagen entfernt%s.\n",
|
||||
$cleanup['login_attempts'], $cleanup['auth_tokens'], $cleanup['user_invites'],
|
||||
$cleanup['reminder_mail_log'],
|
||||
$cleanup['payment_reminder_log'],
|
||||
$cleanup['reminder_push_log'], $cleanup['booking_documents'],
|
||||
$cleanup['log_rotated'] ? ', Fehlerprotokoll rotiert' : ''
|
||||
);
|
||||
|
|
@ -269,6 +321,15 @@ function cron_reminders(): void
|
|||
echo 'E-Mail-Fehler: ' . $error . "\n";
|
||||
}
|
||||
}
|
||||
if ($payments['enabled']) {
|
||||
echo sprintf("Zahlungserinnerungen: %d versendet, %d übersprungen.\n", $payments['sent'], $payments['skipped']);
|
||||
foreach ($payments['details'] as $detail) {
|
||||
echo ' ' . $detail . "\n";
|
||||
}
|
||||
foreach ($payments['errors'] as $error) {
|
||||
echo 'Zahlungserinnerung-Fehler: ' . $error . "\n";
|
||||
}
|
||||
}
|
||||
} catch (Throwable $error) {
|
||||
error_log('Cron-Erinnerungen: ' . $error->getMessage());
|
||||
http_response_code(500);
|
||||
|
|
@ -808,6 +869,7 @@ function booking_form_context(array $user, ?array $booking = null, array $values
|
|||
'canEditBilling' => auth_can_manage($user),
|
||||
'depositAccounts' => deposit_accounts(),
|
||||
'depositDueDays' => deposit_due_working_days(),
|
||||
'transferReminderDays' => transfer_reminder_days(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -824,6 +886,7 @@ function form_values_from_input(array $data): array
|
|||
'deposit' => number_format($data['deposit_cents'] / 100, 2, ',', ''),
|
||||
'deposit_required' => (int) ($data['deposit_required'] ?? 0),
|
||||
'deposit_account_id' => (int) ($data['deposit_account_id'] ?? 0),
|
||||
'balance_method' => (string) ($data['balance_method'] ?? 'cash') === 'transfer' ? 'transfer' : 'cash',
|
||||
'rent' => number_format($data['rent_cents'] / 100, 2, ',', ''),
|
||||
'delivery' => number_format($data['delivery_cents'] / 100, 2, ',', ''),
|
||||
'invoice' => (int) $data['invoice'],
|
||||
|
|
@ -881,6 +944,7 @@ function page_booking_new(array $user, string $method): void
|
|||
'deposit' => '',
|
||||
'deposit_required' => 0,
|
||||
'deposit_account_id' => (int) (deposit_accounts()[0]['id'] ?? 0),
|
||||
'balance_method' => 'cash',
|
||||
'rent' => '',
|
||||
'delivery' => '',
|
||||
'invoice' => 0,
|
||||
|
|
@ -940,6 +1004,7 @@ function page_booking_edit(array $user, int $id, string $method): void
|
|||
'deposit' => number_format((int) $booking['deposit_cents'] / 100, 2, ',', ''),
|
||||
'deposit_required' => (int) ($booking['deposit_required'] ?? 0),
|
||||
'deposit_account_id' => (int) ($booking['deposit_account_id'] ?? 0) ?: (int) (deposit_accounts()[0]['id'] ?? 0),
|
||||
'balance_method' => (string) ($booking['balance_method'] ?? 'cash') === 'transfer' ? 'transfer' : 'cash',
|
||||
'rent' => number_format((int) $booking['rent_cents'] / 100, 2, ',', ''),
|
||||
'delivery' => number_format((int) $booking['delivery_cents'] / 100, 2, ',', ''),
|
||||
'invoice' => (int) $booking['invoice'],
|
||||
|
|
@ -969,6 +1034,7 @@ function page_booking_edit(array $user, int $id, string $method): void
|
|||
$data['deposit_cents'] = (int) $booking['deposit_cents'];
|
||||
$data['deposit_required'] = (int) ($booking['deposit_required'] ?? 0);
|
||||
$data['deposit_account_id'] = (int) ($booking['deposit_account_id'] ?? 0);
|
||||
$data['balance_method'] = (string) ($booking['balance_method'] ?? 'cash') === 'transfer' ? 'transfer' : 'cash';
|
||||
$data['rent_cents'] = (int) $booking['rent_cents'];
|
||||
$data['delivery_cents'] = (int) $booking['delivery_cents'];
|
||||
$data['total_cents'] = (int) $booking['total_cents'];
|
||||
|
|
@ -1145,13 +1211,14 @@ function page_booking_documents_create(array $user, int $id): void
|
|||
}
|
||||
$kind = post_string('kind');
|
||||
$variant = post_string('variant');
|
||||
if (!in_array($kind, [DOCUMENT_KIND_CONTRACT, DOCUMENT_KIND_CONFIRMATION], true)) {
|
||||
if (!in_array($kind, [DOCUMENT_KIND_CONTRACT, DOCUMENT_KIND_CONFIRMATION, DOCUMENT_KIND_REMINDER], true)) {
|
||||
flash('error', 'Unbekannte Unterlagen-Art.');
|
||||
redirect('/bookings/' . $id . '#unterlagen');
|
||||
}
|
||||
// Auftragsbestätigungen legt nur die Verwaltung an, Mietverträge alle.
|
||||
if ($kind === DOCUMENT_KIND_CONFIRMATION && !auth_can_manage($user)) {
|
||||
abort_page(403, 'Auftragsbestätigungen darf nur der Administrator erstellen.');
|
||||
// Auftragsbestätigung und Zahlungserinnerung legt nur die Verwaltung an,
|
||||
// Mietverträge alle.
|
||||
if ($kind !== DOCUMENT_KIND_CONTRACT && !auth_can_manage($user)) {
|
||||
abort_page(403, 'Auftragsbestätigung und Zahlungserinnerung darf nur der Administrator erstellen.');
|
||||
}
|
||||
try {
|
||||
document_create($booking, $kind, $variant, (int) $user['id']);
|
||||
|
|
@ -1263,10 +1330,11 @@ function page_booking_document_action(array $user, string $method, int $bookingI
|
|||
|
||||
if ($action === 'delete') {
|
||||
// Mietverträge darf jede Mitarbeiterin/jeder Mitarbeiter löschen (inkl.
|
||||
// Unterschrift), Auftragsbestätigung und Rechnung nur die Verwaltung.
|
||||
// Unterschrift), Auftragsbestätigung, Zahlungserinnerung und Rechnung
|
||||
// nur die Verwaltung.
|
||||
$isContract = (string) $doc['kind'] === DOCUMENT_KIND_CONTRACT;
|
||||
if (!$isContract && !auth_can_manage($user)) {
|
||||
abort_page(403, 'Auftragsbestätigung und Rechnung darf nur der Administrator löschen.');
|
||||
abort_page(403, 'Auftragsbestätigung, Zahlungserinnerung und Rechnung darf nur der Administrator löschen.');
|
||||
}
|
||||
if (!auth_can_edit_booking($user)) {
|
||||
abort_page(403, 'Dafür fehlt dir die Berechtigung.');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue