feat(admin): Anzahlungskonten in der Verwaltung pflegen (zwei IBANs)

- Migration 016_deposit_accounts.sql: Tabelle deposit_accounts (label, holder,
  bank, iban, sort_order), gefüllt mit Postbank (DE12 …1261 30) und Sparkasse
  (DE83 3206 0362 3303 2140 10); bookings.deposit_account -> deposit_account_id
  mit Fremdschlüssel (ON DELETE SET NULL), Altbestand wird aufs erste Konto
  gemappt; schema.sql nachgezogen
- Neue Seite Verwaltung → Konten (/admin/accounts): anlegen, ändern, löschen
  (Löschen nur ohne Buchungsbezug), Anzeige der Verwendung je Konto
- Buchungsformular wählt aus dieser Liste (Anzeige mit IBAN-Ende), Validierung
  prüft IBAN-Format, Auftragsbestätigung druckt das gewählte Konto
- deposit_accounts()/deposit_account() lesen aus der DB (Cache wird nach
  Änderungen verworfen); Konfigurations-Override entfällt
- Anleitung (Abschnitt 3 und 15), README, config.example.php und ROADMAP
  (Feature 25) aktualisiert
This commit is contained in:
torsten 2026-11-30 17:10:24 +01:00
parent bf85a64a79
commit cc8d7330f8
15 changed files with 478 additions and 76 deletions

View file

@ -190,7 +190,7 @@ function booking_input(array $source): array
'end_time' => normalize_time($source['end_time'] ?? ''),
'deposit_cents' => $depositRequired ? parse_money((string) ($source['deposit'] ?? '0')) : 0,
'deposit_required' => $depositRequired,
'deposit_account' => trim((string) ($source['deposit_account'] ?? '')),
'deposit_account_id' => (int) ($source['deposit_account_id'] ?? 0),
'rent_cents' => $rent,
'delivery_cents' => $delivery,
'total_cents' => $rent + $delivery,
@ -219,7 +219,7 @@ function booking_to_input(array $booking): array
'end_time' => normalize_time($booking['end_time'] ?? ''),
'deposit_cents' => (int) $booking['deposit_cents'],
'deposit_required' => (int) ($booking['deposit_required'] ?? 0),
'deposit_account' => (string) ($booking['deposit_account'] ?? ''),
'deposit_account_id' => (int) ($booking['deposit_account_id'] ?? 0),
'rent_cents' => (int) ($booking['rent_cents'] ?? $booking['total_cents']),
'delivery_cents' => (int) ($booking['delivery_cents'] ?? 0),
'total_cents' => (int) $booking['total_cents'],
@ -326,7 +326,7 @@ function booking_validate(array $data, int $excludeId = 0, int $allowTrailerId =
} elseif ((int) ($data['deposit_required'] ?? 0) === 1 && $data['deposit_cents'] <= 0) {
$errors['deposit'] = 'Bitte den Betrag der Anzahlung angeben oder „Anzahlung: NEIN“ wählen.';
}
if ((int) ($data['deposit_required'] ?? 0) === 1 && !deposit_account((string) ($data['deposit_account'] ?? ''))) {
if ((int) ($data['deposit_required'] ?? 0) === 1 && !deposit_account((int) ($data['deposit_account_id'] ?? 0))) {
$errors['deposit_account'] = 'Bitte das Konto für die Anzahlung auswählen.';
}
@ -525,7 +525,7 @@ function booking_create(array $data, int $userId): int
$stmt = $pdo->prepare(
'INSERT INTO bookings
(trailer_id, employee_id, return_employee_id, start_date, end_date, start_time, end_time, deposit_cents,
deposit_required, deposit_account,
deposit_required, deposit_account_id,
rent_cents, delivery_cents, total_cents, invoice, invoice_no, kind,
customer_name, street, city, mobile, email, note, status, created_at, updated_at, created_by, updated_by)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "active", ?, ?, ?, ?)'
@ -534,7 +534,8 @@ function booking_create(array $data, int $userId): int
$data['trailer_id'], $data['employee_id'], $data['return_employee_id'] ?: null,
$data['start_date'], $data['end_date'],
null_if_empty($data['start_time']), null_if_empty($data['end_time']),
$data['deposit_cents'], (int) ($data['deposit_required'] ?? 0), (string) ($data['deposit_account'] ?? ''),
$data['deposit_cents'], (int) ($data['deposit_required'] ?? 0),
((int) ($data['deposit_account_id'] ?? 0)) > 0 ? (int) $data['deposit_account_id'] : null,
$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'],
@ -567,7 +568,7 @@ function booking_update(int $id, array $data, int $userId): void
}
$stmt = $pdo->prepare(
'UPDATE bookings SET trailer_id = ?, employee_id = ?, return_employee_id = ?, start_date = ?, end_date = ?,
start_time = ?, end_time = ?, deposit_cents = ?, deposit_required = ?, deposit_account = ?,
start_time = ?, end_time = ?, deposit_cents = ?, deposit_required = ?, deposit_account_id = ?,
rent_cents = ?, delivery_cents = ?, total_cents = ?, invoice = ?, invoice_no = ?, kind = ?,
customer_name = ?, street = ?, city = ?, mobile = ?, email = ?, note = ?, updated_at = ?,
updated_by = ? WHERE id = ?'
@ -576,7 +577,8 @@ function booking_update(int $id, array $data, int $userId): void
$data['trailer_id'], $data['employee_id'], $data['return_employee_id'] ?: null,
$data['start_date'], $data['end_date'],
null_if_empty($data['start_time']), null_if_empty($data['end_time']),
$data['deposit_cents'], (int) ($data['deposit_required'] ?? 0), (string) ($data['deposit_account'] ?? ''),
$data['deposit_cents'], (int) ($data['deposit_required'] ?? 0),
((int) ($data['deposit_account_id'] ?? 0)) > 0 ? (int) $data['deposit_account_id'] : null,
$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'],