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:
parent
bf85a64a79
commit
cc8d7330f8
15 changed files with 478 additions and 76 deletions
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue