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

@ -23,12 +23,13 @@ Die Anforderungen stammen aus
`web/assets/icons/`.
- **Anzahlung in der Auftragsbestätigung**: Im Buchungsformular wird neben dem Betrag festgelegt, ob eine
Anzahlung fällig ist (`bookings.deposit_required`) und auf welches Konto sie geht
(`bookings.deposit_account`); die Konten stehen in `deposit_accounts()` (`app/documents.php`, überschreibbar
über `app.deposit_accounts`). Die Auftragsbestätigung nennt Betrag, Frist
Anzahlung fällig ist (`bookings.deposit_required`) und auf welches Konto sie geht (`bookings.deposit_account_id`);
die Konten (Bezeichnung, Inhaber, Bank, IBAN, Sortierung) pflegt der Administrator unter
**Verwaltung → Konten** – Tabelle `deposit_accounts`, Migration `016_deposit_accounts.sql`, Konten, die in
Buchungen verwendet werden, sind gegen Löschen geschützt. Die Auftragsbestätigung nennt Betrag, Frist
(`app.deposit_due_working_days`, Standard 7 Werktage Mo–Sa ohne NRW-Feiertage) mit Datum, Kontoinhaber/Bank/IBAN,
Verwendungszweck und den Hinweis, dass der Termin erst nach Zahlungseingang reserviert ist. Migration
`015_booking_deposit.sql`.
Verwendungszweck und den Hinweis, dass der Termin erst nach Zahlungseingang reserviert ist (Migrationen
`015_booking_deposit.sql`, `016_deposit_accounts.sql`).
- **Sicherungen**: Unter **Verwaltung → Sicherungen** legt der Admin mit einem
Klick ein Archiv aus Datenbank und allen abgelegten Dateien an, lädt es
herunter, spielt einen früheren Stand wieder ein (mit automatischer

View file

@ -86,6 +86,10 @@
- **Umsetzung:** Migration `015_booking_deposit.sql` ergänzt `bookings.deposit_required` und `bookings.deposit_account` (bestehende Buchungen mit Betrag > 0 werden auf „JA“ gesetzt). Im Formular stehen „Anzahlung fällig: JA/NEIN“ und die Kontoauswahl neben dem Betrag (nur Verwaltung); Nicht-Admins können die Werte nicht ändern. `deposit_accounts()`/`deposit_due_date()` in `app/documents.php` liefern Konto und Frist (7 Werktage Mo–Sa, ohne NRW-Feiertage, per `app.deposit_due_working_days` einstellbar). Die Auftragsbestätigung druckt den Block „Anzahlung und verbindliche Reservierung“ mit Betrag, Datum, Kontoinhaber, Bank, IBAN, Verwendungszweck und dem Hinweis, dass der Termin erst nach Zahlungseingang reserviert ist; Beträge und Signatur rücken dafür kompakter zusammen und bleiben auf einer Seite. Buchungsdetail und Kopiertext zeigen Fälligkeit/Konto.
- **Prüfung:** Buchung mit „JA“ und 50 € anlegen – Auftragsbestätigung nennt 50,00 €, Fristdatum in 7 Werktagen, Konto und Reservierungshinweis; „NEIN“ erzeugt keine Anzahlungszeile und keinen Absatz (Anzahlung = 0,00 €); „JA“ ohne Betrag meldet einen Fehler; Nicht-Admin sieht die Felder gesperrt; bestehende Buchung mit Anzahlung zeigt nach der Migration „JA“.
- [x] **Feature 25: Anzahlungskonten pflegbar (zwei IBANs)**
- **Umsetzung:** Migration `016_deposit_accounts.sql` legt die Tabelle `deposit_accounts` an (label, holder, bank, iban, sort_order) und füllt sie mit Postbank (`DE12 1001 0010 0464 1261 30`) und Sparkasse (`DE83 3206 0362 3303 2140 10`); `bookings.deposit_account` wird zu `bookings.deposit_account_id` mit Fremdschlüssel (ON DELETE SET NULL), Altbestand wird auf das erste Konto gemappt. Neue Admin-Seite **Verwaltung → Konten** (`/admin/accounts`) mit Anlegen, Ändern, Löschen (Löschen nur ohne Buchungsbezug) und Anzeige der Verwendung; Buchungsformular wählt aus dieser Liste, Auftragsbestätigung druckt das gewählte Konto mit IBAN.
- **Prüfung:** Migration auf einer Kopie der Live-DB: zwei Konten vorhanden, alle Buchungen mit „Anzahlung fällig“ zeigen Konto 1; Buchung mit Konto 2 erzeugen – Auftragsbestätigung nennt `DE83 3206 0362 3303 2140 10`; Konto anlegen/umbenennen/löschen funktioniert, Löschen eines verwendeten Kontos wird abgewiesen; ungültige IBAN wird gemeldet.
## Rückmeldungen Michael (30.11.2026)
- [x] **Feature 20: Logo und Namensumbruch im Mietvertrag**

View file

@ -46,6 +46,10 @@ function admin_handle(string $path, array $user): void
admin_mailings($user);
return;
}
if ($path === '/admin/accounts') {
admin_accounts();
return;
}
if ($path === '/admin/backups') {
admin_backups($user);
return;
@ -836,3 +840,79 @@ function admin_backup_download(string $name): void
readfile($path);
exit;
}
/* -------------------------------------------------- Anzahlungskonten */
function admin_accounts(): void
{
$errors = [];
$createErrors = [];
$createValues = ['label' => '', 'holder' => '', 'bank' => '', 'iban' => '', 'sort_order' => ''];
$rowValues = [];
if (is_post()) {
require_post();
$action = post_string('action');
try {
if ($action === 'create') {
$createValues = deposit_account_input($_POST);
$createErrors = deposit_account_validate($createValues);
if ($createErrors === []) {
$id = deposit_account_create($createValues);
flash('success', 'Konto „' . $createValues['label'] . '“ angelegt (ID ' . $id . ').');
redirect('/admin/accounts');
}
} elseif ($action === 'update') {
$id = (int) post_string('id');
$account = deposit_account($id);
if ($account === null) {
throw new RuntimeException('Dieses Konto gibt es nicht (mehr).');
}
$rowValues[$id] = deposit_account_input($_POST);
$rowErrors = deposit_account_validate($rowValues[$id]);
if ($rowErrors !== []) {
throw new InvalidArgumentException(implode(' ', $rowErrors));
}
deposit_account_update($id, $rowValues[$id]);
flash('success', 'Konto „' . $rowValues[$id]['label'] . '“ gespeichert.');
redirect('/admin/accounts');
} elseif ($action === 'delete') {
$id = (int) post_string('id');
$account = deposit_account($id);
if ($account === null) {
throw new RuntimeException('Dieses Konto gibt es nicht (mehr).');
}
if (!deposit_account_delete($id)) {
$used = deposit_account_usage($id);
throw new RuntimeException('Das Konto wird in ' . $used . ' Buchung' . ($used === 1 ? '' : 'en')
. ' verwendet und kann deshalb nicht gelöscht werden. Bitte nur umbenennen oder die '
. 'Buchungen auf ein anderes Konto umstellen.');
}
flash('success', 'Konto „' . (string) $account['label'] . '“ gelöscht.');
redirect('/admin/accounts');
}
} catch (InvalidArgumentException $error) {
$decoded = json_decode($error->getMessage(), true);
$errors = is_array($decoded) ? $decoded : ['general' => $error->getMessage()];
} catch (Throwable $error) {
error_log('Anzahlungskonten: ' . $error->getMessage());
$errors['general'] = $error->getMessage();
}
http_response_code(422);
}
$accounts = deposit_accounts();
$usage = [];
foreach ($accounts as $account) {
$usage[(int) $account['id']] = deposit_account_usage((int) $account['id']);
}
render_page('admin_accounts', [
'accounts' => $accounts,
'usage' => $usage,
'errors' => $errors,
'createErrors' => $createErrors,
'createValues' => $createValues,
'rowValues' => $rowValues,
], 'Konten');
}

View file

@ -56,16 +56,9 @@ return [
// Maximale Größe einer hochgeladenen Sicherung (MB).
'backup_max_mb' => 200,
// Anzahlung in der Auftragsbestätigung: Frist in Werktagen (Mo–Sa ohne
// gesetzliche Feiertage). Die Konten stehen als Standard in
// app/documents.php (deposit_accounts()) und lassen sich hier
// überschreiben: Schlüssel => ['label', 'holder', 'bank', 'iban'].
// gesetzliche Feiertage). Die Konten selbst pflegt der Administrator
// unter Verwaltung → Konten (Tabelle deposit_accounts).
'deposit_due_working_days' => 7,
// 'deposit_accounts' => [
// 'postbank' => ['label' => 'Postbank – Michael Schmitz', 'holder' => 'Michael Schmitz',
// 'bank' => 'Postbank', 'iban' => 'DE…'],
// 'sparkasse' => ['label' => 'Sparkasse – Drink it cold', 'holder' => '…',
// 'bank' => '…', 'iban' => 'DE…'],
// ],
],
// Optional: Angaben für Impressum und Datenschutz überschreiben. Die
// Standardwerte stehen in app/legal.php. Hinweis: tools/deploy.sh erzeugt

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'],

View file

@ -419,56 +419,149 @@ function document_pdf_rows(PdfDoc $pdf, float $top, array $rows, float $valueX =
}
/**
* Konten, auf die eine Anzahlung überwiesen werden kann.
* Anzahlungskonten (Verwaltung → Konten), sortiert.
*
* Standard steht in dieser Funktion, damit sie auch dann greift, wenn die
* app/config.local.php beim Deployment neu erzeugt wird (dort wird kein
* `app.deposit_accounts` geschrieben). Weitere Konten lassen sich hier
* ergänzen oder per `app.deposit_accounts` in der lokalen Konfiguration
* überschreiben (Schlüssel => label/holder/bank/iban).
* Der Stamm liegt in der Tabelle deposit_accounts und wird vom Administrator
* gepflegt; die Auftragsbestätigung druckt das in der Buchung gewählte Konto.
*
* @return array<string, array{label: string, holder: string, bank: string, iban: string}>
* @return list<array{id: int, label: string, holder: string, bank: string, iban: string, sort_order: int}>
*/
function deposit_accounts(): array
function deposit_accounts(bool $refresh = false): array
{
$defaults = [
'postbank' => [
'label' => 'Postbank – Michael Schmitz',
'holder' => 'Michael Schmitz',
'bank' => 'Postbank',
'iban' => 'DE12 1001 0010 0464 1261 30',
],
];
$configured = config('app.deposit_accounts', null);
if (!is_array($configured) || $configured === []) {
return $defaults;
static $cache = null;
if ($refresh) {
$cache = null;
}
$accounts = [];
foreach ($configured as $key => $account) {
if (!is_array($account)) {
continue;
}
$accounts[(string) $key] = [
'label' => (string) ($account['label'] ?? $key),
'holder' => (string) ($account['holder'] ?? ''),
'bank' => (string) ($account['bank'] ?? ''),
'iban' => (string) ($account['iban'] ?? ''),
if (is_array($cache)) {
return $cache;
}
$cache = [];
try {
$rows = db()->query('SELECT id, label, holder, bank, iban, sort_order FROM deposit_accounts ORDER BY sort_order, id')
->fetchAll();
} catch (Throwable) {
return $cache; // Tabelle fehlt noch (Migration ausstehend)
}
foreach ($rows as $row) {
$cache[] = [
'id' => (int) $row['id'],
'label' => (string) $row['label'],
'holder' => (string) $row['holder'],
'bank' => (string) $row['bank'],
'iban' => (string) $row['iban'],
'sort_order' => (int) $row['sort_order'],
];
}
return $accounts !== [] ? $accounts : $defaults;
return $cache;
}
/** Konto zur Kennung; ohne gültige Kennung das erste Konto (oder null). */
function deposit_account(string $key): ?array
/** Einzelnes Konto; ohne gültige Kennung null. */
function deposit_account(int $id): ?array
{
$accounts = deposit_accounts();
if ($key !== '' && isset($accounts[$key])) {
return $accounts[$key];
foreach (deposit_accounts() as $account) {
if ((int) $account['id'] === $id) {
return $account;
}
}
$first = reset($accounts);
return $first === false ? null : $first;
return null;
}
/** Anzeigename inklusive IBAN-Ende, damit zwei Konten unterscheidbar sind. */
function deposit_account_label(array $account): string
{
$iban = preg_replace('/\s+/', '', (string) $account['iban']) ?? '';
return (string) $account['label'] . ($iban !== '' ? ' (…' . substr($iban, -4) . ')' : '');
}
/** Eingabewerte eines Anzahlungskontos normalisieren. */
function deposit_account_input(array $source): array
{
return [
'label' => trim((string) ($source['label'] ?? '')),
'holder' => trim((string) ($source['holder'] ?? '')),
'bank' => trim((string) ($source['bank'] ?? '')),
'iban' => mb_strtoupper(trim((string) ($source['iban'] ?? ''))),
'sort_order' => (int) ($source['sort_order'] ?? 0),
];
}
/** @return array<string, string> */
function deposit_account_validate(array $data): array
{
$errors = [];
if ($data['label'] === '') {
$errors['label'] = 'Bitte eine Bezeichnung angeben (z. B. „Postbank – Michael Schmitz“).';
} elseif (mb_strlen($data['label']) > 80) {
$errors['label'] = 'Die Bezeichnung ist zu lang (max. 80 Zeichen).';
}
if ($data['holder'] === '') {
$errors['holder'] = 'Bitte den Kontoinhaber angeben.';
} elseif (mb_strlen($data['holder']) > 120) {
$errors['holder'] = 'Der Kontoinhaber ist zu lang (max. 120 Zeichen).';
}
if (mb_strlen($data['bank']) > 80) {
$errors['bank'] = 'Der Bankname ist zu lang (max. 80 Zeichen).';
}
$iban = preg_replace('/\s+/', '', $data['iban']) ?? '';
if ($iban === '') {
$errors['iban'] = 'Bitte die IBAN angeben.';
} elseif (mb_strlen($iban) < 15 || mb_strlen($iban) > 34 || preg_match('/^[A-Z]{2}[0-9A-Z]+$/', $iban) !== 1) {
$errors['iban'] = 'Die IBAN sieht nicht gültig aus (z. B. DE12 1001 0010 0464 1261 30).';
}
return $errors;
}
function deposit_account_create(array $data): int
{
$errors = deposit_account_validate($data);
if ($errors !== []) {
throw new InvalidArgumentException((string) json_encode($errors, JSON_UNESCAPED_UNICODE));
}
$stmt = db()->prepare(
'INSERT INTO deposit_accounts (label, holder, bank, iban, sort_order, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?)'
);
$stmt->execute([
$data['label'], $data['holder'], $data['bank'], $data['iban'], $data['sort_order'],
utc_now(), utc_now(),
]);
$id = (int) db()->lastInsertId(); // vor dem Neuladen der Liste lesen
deposit_accounts(true);
return $id;
}
function deposit_account_update(int $id, array $data): void
{
$errors = deposit_account_validate($data);
if ($errors !== []) {
throw new InvalidArgumentException((string) json_encode($errors, JSON_UNESCAPED_UNICODE));
}
db()->prepare(
'UPDATE deposit_accounts SET label = ?, holder = ?, bank = ?, iban = ?, sort_order = ?, updated_at = ?
WHERE id = ?'
)->execute([
$data['label'], $data['holder'], $data['bank'], $data['iban'], $data['sort_order'], utc_now(), $id,
]);
deposit_accounts(true);
}
/** Anzahl der Buchungen, die dieses Konto verwenden. */
function deposit_account_usage(int $id): int
{
$stmt = db()->prepare('SELECT COUNT(*) FROM bookings WHERE deposit_account_id = ?');
$stmt->execute([$id]);
return (int) $stmt->fetchColumn();
}
/** Löscht ein Konto – nur solange keine Buchung darauf verweist. */
function deposit_account_delete(int $id): bool
{
if (deposit_account_usage($id) > 0) {
return false;
}
db()->prepare('DELETE FROM deposit_accounts WHERE id = ?')->execute([$id]);
deposit_accounts(true);
return true;
}
/** Frist für die Anzahlung in Werktagen (Mo–Sa, ohne gesetzliche Feiertage). */
@ -750,12 +843,12 @@ function document_confirmation_pdf(array $booking, string $variant): string
}
// Anzahlung: vereinbart (Häkchen in der Buchung) und Betrag > 0.
$depositRequired = (int) ($booking['deposit_required'] ?? 0) === 1;
$account = $depositRequired && $paid > 0 ? deposit_account((string) ($booking['deposit_account'] ?? '')) : null;
$account = $depositRequired && $paid > 0 ? deposit_account((int) ($booking['deposit_account_id'] ?? 0)) : null;
$dueDate = $account !== null ? deposit_due_date() : null;
$workingDays = deposit_due_working_days();
if ($paid > 0) {
$priceRows[] = [
$depositRequired ? 'Anzahlung (bis ' . fmt_date((string) $dueDate) . ')' : 'Anzahlung',
$account !== null ? 'Anzahlung (bis ' . fmt_date((string) $dueDate) . ')' : 'Anzahlung',
'− ' . fmt_money($paid),
];
}

View file

@ -823,7 +823,7 @@ function form_values_from_input(array $data): array
'end_time' => (string) ($data['end_time'] ?? ''),
'deposit' => number_format($data['deposit_cents'] / 100, 2, ',', ''),
'deposit_required' => (int) ($data['deposit_required'] ?? 0),
'deposit_account' => (string) ($data['deposit_account'] ?? ''),
'deposit_account_id' => (int) ($data['deposit_account_id'] ?? 0),
'rent' => number_format($data['rent_cents'] / 100, 2, ',', ''),
'delivery' => number_format($data['delivery_cents'] / 100, 2, ',', ''),
'invoice' => (int) $data['invoice'],
@ -877,7 +877,7 @@ function page_booking_new(array $user, string $method): void
'end_time' => '',
'deposit' => '',
'deposit_required' => 0,
'deposit_account' => '',
'deposit_account_id' => (int) (deposit_accounts()[0]['id'] ?? 0),
'rent' => '',
'delivery' => '',
'invoice' => 0,
@ -933,7 +933,7 @@ function page_booking_edit(array $user, int $id, string $method): void
'end_time' => (string) ($booking['end_time'] ?? ''),
'deposit' => number_format((int) $booking['deposit_cents'] / 100, 2, ',', ''),
'deposit_required' => (int) ($booking['deposit_required'] ?? 0),
'deposit_account' => (string) ($booking['deposit_account'] ?? ''),
'deposit_account_id' => (int) ($booking['deposit_account_id'] ?? 0) ?: (int) (deposit_accounts()[0]['id'] ?? 0),
'rent' => number_format((int) $booking['rent_cents'] / 100, 2, ',', ''),
'delivery' => number_format((int) $booking['delivery_cents'] / 100, 2, ',', ''),
'invoice' => (int) $booking['invoice'],
@ -959,7 +959,7 @@ function page_booking_edit(array $user, int $id, string $method): void
if (!$canEditBilling) {
$data['deposit_cents'] = (int) $booking['deposit_cents'];
$data['deposit_required'] = (int) ($booking['deposit_required'] ?? 0);
$data['deposit_account'] = (string) ($booking['deposit_account'] ?? '');
$data['deposit_account_id'] = (int) ($booking['deposit_account_id'] ?? 0);
$data['rent_cents'] = (int) $booking['rent_cents'];
$data['delivery_cents'] = (int) $booking['delivery_cents'];
$data['total_cents'] = (int) $booking['total_cents'];

View file

@ -0,0 +1,42 @@
-- Anzahlungskonten pflegbar machen (Verwaltung → Konten).
--
-- Bisher stand das Konto als Schlüssel in bookings.deposit_account und der
-- Kontenstamm im Code. Jetzt gibt es eine Tabelle, die der Administrator
-- pflegt; Buchungen verweisen per Fremdschlüssel darauf.
CREATE TABLE IF NOT EXISTS deposit_accounts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
label VARCHAR(80) NOT NULL,
holder VARCHAR(120) NOT NULL,
bank VARCHAR(80) NOT NULL DEFAULT '',
iban VARCHAR(34) NOT NULL,
sort_order INT NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
KEY idx_deposit_accounts_sort (sort_order, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO deposit_accounts (label, holder, bank, iban, sort_order, created_at, updated_at)
VALUES
('Postbank – Michael Schmitz', 'Michael Schmitz', 'Postbank', 'DE12 1001 0010 0464 1261 30', 1, UTC_TIMESTAMP(), UTC_TIMESTAMP()),
('Sparkasse – Michael Schmitz', 'Michael Schmitz', 'Sparkasse', 'DE83 3206 0362 3303 2140 10', 2, UTC_TIMESTAMP(), UTC_TIMESTAMP());
ALTER TABLE bookings ADD COLUMN deposit_account_id BIGINT UNSIGNED NULL AFTER deposit_account;
UPDATE bookings SET deposit_account_id = (SELECT MIN(id) FROM deposit_accounts)
WHERE deposit_account = 'postbank';
UPDATE bookings SET deposit_account_id = (SELECT MAX(id) FROM deposit_accounts)
WHERE deposit_account <> '' AND deposit_account_id IS NULL;
-- Buchungen mit „Anzahlung fällig“, aber ohne gespeichertes Konto (Altbestand
-- aus 015) bekommen das erste Konto, damit die Auftragsbestätigung weiterhin
-- Konto und Frist nennt.
UPDATE bookings SET deposit_account_id = (SELECT MIN(id) FROM deposit_accounts)
WHERE deposit_required = 1 AND deposit_account_id IS NULL;
ALTER TABLE bookings DROP COLUMN deposit_account;
ALTER TABLE bookings
ADD CONSTRAINT fk_bookings_deposit_account FOREIGN KEY (deposit_account_id)
REFERENCES deposit_accounts (id) ON DELETE SET NULL;

View file

@ -55,6 +55,19 @@ CREATE TABLE IF NOT EXISTS users (
CONSTRAINT fk_users_employee FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS deposit_accounts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
label VARCHAR(80) NOT NULL,
holder VARCHAR(120) NOT NULL,
bank VARCHAR(80) NOT NULL DEFAULT '',
iban VARCHAR(34) NOT NULL,
sort_order INT NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id),
KEY idx_deposit_accounts_sort (sort_order, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS bookings (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
trailer_id BIGINT UNSIGNED NOT NULL,
@ -67,7 +80,7 @@ CREATE TABLE IF NOT EXISTS bookings (
deposit_cents INT UNSIGNED NOT NULL DEFAULT 0,
-- Anzahlung laut Auftragsbestätigung: vereinbart? auf welches Konto?
deposit_required TINYINT(1) NOT NULL DEFAULT 0,
deposit_account VARCHAR(40) NOT NULL DEFAULT '',
deposit_account_id BIGINT UNSIGNED NULL DEFAULT NULL,
rent_cents INT UNSIGNED NOT NULL DEFAULT 0,
delivery_cents INT UNSIGNED NOT NULL DEFAULT 0,
total_cents INT UNSIGNED NOT NULL DEFAULT 0,
@ -96,6 +109,7 @@ CREATE TABLE IF NOT EXISTS bookings (
CONSTRAINT fk_bookings_trailer FOREIGN KEY (trailer_id) REFERENCES trailers (id) ON DELETE RESTRICT,
CONSTRAINT fk_bookings_employee FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE RESTRICT,
CONSTRAINT fk_bookings_return_employee FOREIGN KEY (return_employee_id) REFERENCES employees (id) ON DELETE SET NULL,
CONSTRAINT fk_bookings_deposit_account FOREIGN KEY (deposit_account_id) REFERENCES deposit_accounts (id) ON DELETE SET NULL,
CONSTRAINT fk_bookings_created_by FOREIGN KEY (created_by) REFERENCES users (id) ON DELETE SET NULL,
CONSTRAINT fk_bookings_updated_by FOREIGN KEY (updated_by) REFERENCES users (id) ON DELETE SET NULL,
CONSTRAINT fk_bookings_cancelled_by FOREIGN KEY (cancelled_by) REFERENCES users (id) ON DELETE SET NULL

View file

@ -5,6 +5,7 @@ $items = [
'/admin/employees' => ['label' => 'Mitarbeiter', 'icon' => 'i-users'],
'/admin/trailers' => ['label' => 'Anhänger', 'icon' => 'i-truck'],
'/admin/mailings' => ['label' => 'Rundmail', 'icon' => 'i-mail'],
'/admin/accounts' => ['label' => 'Konten', 'icon' => 'i-bank'],
'/admin/backups' => ['label' => 'Sicherungen', 'icon' => 'i-database'],
];
?>

163
views/admin_accounts.php Normal file
View file

@ -0,0 +1,163 @@
<?php
/** @var list<array{id: int, label: string, holder: string, bank: string, iban: string}> $accounts */
/** @var array<int, int> $usage */
/** @var array<string, string> $errors */
/** @var array<string, string> $createErrors */
/** @var array<string, mixed> $createValues */
/** @var array<int, array<string, mixed>> $rowValues */
$error = static fn (string $key): string => (string) ($errors[$key] ?? '');
$createError = static fn (string $key): string => (string) ($createErrors[$key] ?? '');
?>
<div class="page-head page-head--compact">
<div>
<p class="eyebrow">Verwaltung</p>
<h1>Konten</h1>
<p class="page-head__lede">Konten, auf die Kunden die <strong>Anzahlung</strong> überweisen. Im Buchungsformular
wird je Buchung eines davon ausgewählt; die Auftragsbestätigung druckt Kontoinhaber, Bank und IBAN.
Änderungen gelten für alle <em>neu</em> erzeugten Auftragsbestätigungen.</p>
</div>
</div>
<?php require __DIR__ . '/_admin_nav.php'; ?>
<?php if ($error('general') !== ''): ?>
<div class="alert alert--error" role="alert">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Das hat nicht geklappt.</strong><p><?= e($error('general')) ?></p></div>
</div>
<?php endif; ?>
<section class="panel">
<div class="panel__head">
<div>
<h2>Hinterlegte Konten</h2>
<p><?= count($accounts) ?> Konto<?= count($accounts) === 1 ? '' : 'en' ?>. Reihenfolge über „Sortierung“
(kleinere Zahl zuerst).</p>
</div>
<div class="panel__actions">
<details class="create-trailer"<?= $createErrors ? ' open' : '' ?>>
<summary class="btn small create-trailer__summary">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Konto anlegen
</summary>
<div class="create-trailer__body">
<form method="post" action="<?= e(url('/admin/accounts')) ?>" class="form-grid">
<?= csrf_field() ?>
<input type="hidden" name="action" value="create">
<label class="field<?= $createError('label') !== '' ? ' has-error' : '' ?>">
<span>Bezeichnung</span>
<input type="text" name="label" maxlength="80" value="<?= e((string) $createValues['label']) ?>" placeholder="Postbank – Michael Schmitz" required>
<?php if ($createError('label')): ?><em class="field-error"><?= e($createError('label')) ?></em><?php endif; ?>
</label>
<label class="field<?= $createError('holder') !== '' ? ' has-error' : '' ?>">
<span>Kontoinhaber</span>
<input type="text" name="holder" maxlength="120" value="<?= e((string) $createValues['holder']) ?>" required>
<?php if ($createError('holder')): ?><em class="field-error"><?= e($createError('holder')) ?></em><?php endif; ?>
</label>
<label class="field<?= $createError('bank') !== '' ? ' has-error' : '' ?>">
<span>Bank</span>
<input type="text" name="bank" maxlength="80" value="<?= e((string) $createValues['bank']) ?>" placeholder="Postbank">
<?php if ($createError('bank')): ?><em class="field-error"><?= e($createError('bank')) ?></em><?php endif; ?>
</label>
<label class="field<?= $createError('iban') !== '' ? ' has-error' : '' ?>">
<span>IBAN</span>
<input type="text" name="iban" maxlength="34" value="<?= e((string) $createValues['iban']) ?>" placeholder="DE12 1001 0010 0464 1261 30" required>
<?php if ($createError('iban')): ?><em class="field-error"><?= e($createError('iban')) ?></em><?php endif; ?>
</label>
<label class="field">
<span>Sortierung</span>
<input type="number" name="sort_order" value="<?= e((string) $createValues['sort_order']) ?>" step="1" placeholder="1">
</label>
<div class="form-actions field--full">
<button class="btn primary" type="submit">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Konto anlegen
</button>
</div>
</form>
</div>
</details>
</div>
</div>
<?php if ($accounts === []): ?>
<p class="muted">Noch kein Konto hinterlegt – ohne Konto kann keine Anzahlung in der Auftragsbestätigung genannt werden.</p>
<?php else: ?>
<div class="table-wrap">
<table class="data-table">
<thead>
<tr>
<th>Bezeichnung</th>
<th>Kontoinhaber</th>
<th>Bank</th>
<th>IBAN</th>
<th>Sortierung</th>
<th>Verwendet in</th>
<th class="ta-right">Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach ($accounts as $account): ?>
<?php
$id = (int) $account['id'];
$values = $rowValues[$id] ?? [
'label' => $account['label'],
'holder' => $account['holder'],
'bank' => $account['bank'],
'iban' => $account['iban'],
'sort_order' => $account['sort_order'] ?? 0,
];
$used = (int) ($usage[$id] ?? 0);
?>
<tr>
<td colspan="5">
<form method="post" action="<?= e(url('/admin/accounts')) ?>" class="form-grid" id="account-<?= $id ?>">
<?= csrf_field() ?>
<input type="hidden" name="action" value="update">
<input type="hidden" name="id" value="<?= $id ?>">
<label class="field">
<span>Bezeichnung</span>
<input type="text" name="label" maxlength="80" value="<?= e((string) $values['label']) ?>" required>
</label>
<label class="field">
<span>Kontoinhaber</span>
<input type="text" name="holder" maxlength="120" value="<?= e((string) $values['holder']) ?>" required>
</label>
<label class="field">
<span>Bank</span>
<input type="text" name="bank" maxlength="80" value="<?= e((string) $values['bank']) ?>">
</label>
<label class="field">
<span>IBAN</span>
<input type="text" name="iban" maxlength="34" value="<?= e((string) $values['iban']) ?>" required>
</label>
<label class="field">
<span>Sortierung</span>
<input type="number" name="sort_order" step="1" value="<?= e((string) $values['sort_order']) ?>">
</label>
</form>
</td>
<td><?= $used === 0 ? '<span class="muted small">–</span>' : (int) $used . ' Buchung' . ($used === 1 ? '' : 'en') ?></td>
<td class="ta-right">
<div class="danger-actions">
<button class="btn small" type="submit" form="account-<?= $id ?>">
<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Speichern
</button>
<form method="post" action="<?= e(url('/admin/accounts')) ?>"
data-confirm="Konto „<?= e((string) $account['label']) ?>“ löschen?">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?= $id ?>">
<button class="btn small danger-ghost" type="submit"<?= $used > 0 ? ' disabled title="Wird in Buchungen verwendet"' : '' ?>>
<svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Löschen
</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<p class="muted small">Konten, die bereits in Buchungen verwendet werden, lassen sich nur ändern, nicht löschen –
sonst ginge die Zuordnung in alten Auftragsbestätigungen verloren.</p>
<?php endif; ?>
</section>

View file

@ -203,10 +203,10 @@ $returnTo = '/bookings/' . (int) $booking['id'];
<div><dt>Gesamtbetrag</dt><dd><?= e(fmt_money((int) $booking['total_cents'])) ?></dd></div>
<div><dt>Anzahlung</dt><dd><?= e(fmt_money((int) $booking['deposit_cents'])) ?><?php
if ((int) ($booking['deposit_required'] ?? 0) === 1 && (int) $booking['deposit_cents'] > 0) {
$depositTarget = deposit_account((string) ($booking['deposit_account'] ?? ''));
$depositTarget = deposit_account((int) ($booking['deposit_account_id'] ?? 0));
echo ' · fällig bis ' . e(fmt_date(deposit_due_date()));
if ($depositTarget !== null) {
echo ' auf ' . e((string) $depositTarget['label']);
echo ' auf ' . e(deposit_account_label($depositTarget));
}
}
?></dd></div>

View file

@ -7,7 +7,7 @@
/** @var array $user */
/** @var bool $isEdit */
/** @var bool $canEditBilling */
/** @var array<string, array{label: string, holder: string, bank: string, iban: string}> $depositAccounts */
/** @var list<array{id: int, label: string, holder: string, bank: string, iban: string}> $depositAccounts */
/** @var int $depositDueDays */
$fieldError = static fn (string $key): string => (string) ($errors[$key] ?? '');
$cancelled = $isEdit && ($booking['status'] ?? '') === 'cancelled';
@ -232,9 +232,9 @@ $backUrl = $isEdit ? '/bookings/' . (int) $booking['id'] : '/calendar';
<div class="field<?= $fieldError('deposit_account') !== '' ? ' has-error' : '' ?>">
<span>Anzahlung fällig · Konto</span>
<div class="field-with-aside">
<select name="deposit_account" aria-label="Konto für die Anzahlung"<?= empty($canEditBilling) ? ' disabled' : '' ?>>
<?php foreach ($depositAccounts as $accountKey => $accountRow): ?>
<option value="<?= e_attr((string) $accountKey) ?>"<?= (string) $values['deposit_account'] === (string) $accountKey ? ' selected' : '' ?>><?= e((string) $accountRow['label']) ?></option>
<select name="deposit_account_id" aria-label="Konto für die Anzahlung"<?= empty($canEditBilling) ? ' disabled' : '' ?>>
<?php foreach ($depositAccounts as $accountRow): ?>
<option value="<?= (int) $accountRow['id'] ?>"<?= (int) $values['deposit_account_id'] === (int) $accountRow['id'] ? ' selected' : '' ?>><?= e(deposit_account_label($accountRow)) ?></option>
<?php endforeach; ?>
</select>
<span class="segmented-radio segmented-radio--compact">
@ -244,7 +244,8 @@ $backUrl = $isEdit ? '/bookings/' . (int) $booking['id'] : '/calendar';
</div>
<?php if ($fieldError('deposit_account')): ?><em class="field-error"><?= e($fieldError('deposit_account')) ?></em><?php endif; ?>
<em class="muted small">Bei „JA“ fordert die Auftragsbestätigung die Anzahlung mit
Frist (<?= (int) $depositDueDays ?> Werktage) und nennt das Konto.</em>
Frist (<?= (int) $depositDueDays ?> Werktage) und nennt das Konto. Konten pflegt die
Verwaltung unter „Konten“.</em>
</div>
<div class="field<?= $fieldError('invoice_no') !== '' ? ' has-error' : '' ?>" data-paste-field="invoice_no">
@ -295,7 +296,10 @@ $backUrl = $isEdit ? '/bookings/' . (int) $booking['id'] : '/calendar';
<div><dt>Gesamtbetrag</dt><dd data-summary-total><?= e(fmt_money(parse_money((string) $values['rent']) + parse_money((string) $values['delivery']))) ?></dd></div>
<div><dt>Anzahlung</dt><dd data-summary-deposit><?= e(fmt_money(parse_money((string) $values['deposit']))) ?><?= (int) $values['deposit_required'] === 1 ? ' · fällig' : '' ?></dd></div>
<?php if ((int) $values['deposit_required'] === 1): ?>
<div><dt>Konto</dt><dd><?= e((string) ($depositAccounts[(string) $values['deposit_account']]['label'] ?? '')) ?></dd></div>
<div><dt>Konto</dt><dd><?php
$currentAccount = deposit_account((int) $values['deposit_account_id']);
echo e($currentAccount !== null ? deposit_account_label($currentAccount) : '–');
?></dd></div>
<?php endif; ?>
<div class="is-strong"><dt>Noch zu zahlen</dt><dd data-summary-due><?= e(fmt_money(due_cents(parse_money((string) $values['rent']) + parse_money((string) $values['delivery']), parse_money((string) $values['deposit'])))) ?></dd></div>
</dl>

View file

@ -74,6 +74,7 @@ $navActive = static function (string $area) use ($path): string {
<symbol id="i-snow" viewBox="0 0 24 24"><path d="M12 2v20M4.5 6.8l15 10.4M19.5 6.8 4.5 17.2M12 6.4 9.6 4M12 6.4 14.4 4M12 17.6 9.6 20M12 17.6l2.4 2.4"/></symbol>
<symbol id="i-sun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9 7 7M17 17l2.1 2.1M19.1 4.9 17 7M7 17l-2.1 2.1"/></symbol>
<symbol id="i-download" viewBox="0 0 24 24"><path d="M12 3v12M7 10l5 5 5-5"/><path d="M5 20h14"/></symbol>
<symbol id="i-bank" viewBox="0 0 24 24"><path d="M3 9.5 12 4l9 5.5"/><path d="M5 10v9M9.5 10v9M14.5 10v9M19 10v9"/><path d="M3 21h18"/></symbol>
<symbol id="i-database" viewBox="0 0 24 24"><ellipse cx="12" cy="5.5" rx="8" ry="3"/><path d="M4 5.5v13c0 1.7 3.6 3 8 3s8-1.3 8-3v-13"/><path d="M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3"/></symbol>
</defs>
</svg>

View file

@ -104,7 +104,8 @@ $admin = !empty($isAdmin);
Unterschrift entfernt; danach lässt sich die passende Variante neu erzeugen. Ein bereits an den Kunden
gemailtes PDF bleibt natürlich in dessen Postfach.</p>
<p><strong>Anzahlung:</strong> Im Buchungsformular lässt sich bei den Beträgen einstellen, ob eine Anzahlung
fällig ist („Anzahlung fällig: JA/NEIN“) und auf <strong>welches Konto</strong> sie überwiesen werden soll.
fällig ist („Anzahlung fällig: JA/NEIN“) und auf <strong>welches Konto</strong> sie überwiesen werden soll
(die Konten pflegt der Administrator unter <strong>Verwaltung → Konten</strong>).
Bei „JA“ nennt die Auftragsbestätigung den Betrag, die <strong>Frist von 7 Werktagen</strong> mit
konkretem Datum, das Konto mit IBAN und den Verwendungszweck – verbunden mit dem Hinweis, dass der Termin
erst nach Zahlungseingang verbindlich reserviert ist. Ohne Anzahlung erscheint der Absatz nicht.
@ -303,6 +304,9 @@ $admin = !empty($isAdmin);
erscheinen nicht mehr in neuen Buchungen, bleiben historisch erhalten.</li>
<li><strong>Benutzer</strong>: Konten anlegen und einladen, Mitarbeiterkonto zuordnen (steuert Erinnerungen und Push).</li>
<li><strong>Rundmail</strong>: Empfänger aus Buchungen, Testmail, Versand in Häppchen, Protokoll je Empfänger.</li>
<li><strong>Konten</strong>: Konten für die Anzahlung (Bezeichnung, Inhaber, Bank, IBAN, Sortierung) anlegen
und ändern. Sie erscheinen im Buchungsformular und in der Auftragsbestätigung; Konten, die bereits in
Buchungen verwendet werden, lassen sich nicht löschen.</li>
<li><strong>Konfiguration</strong> (<code>app/config.local.php</code>): Mailversand, Kaution, Aufbewahrung
(<code>app.document_retention_days</code>), Vertragstexte je Variante (<code>documents.delivery|pickup|chest</code>).</li>
</ul>