diff --git a/public/index.php b/public/index.php index 422201f..55abdb7 100644 --- a/public/index.php +++ b/public/index.php @@ -44,6 +44,7 @@ $router->get('/dashboard', fn($p) => (new AccountController())->dashboard($p)); $router->get('/accounts', fn($p) => (new AccountController())->index($p)); $router->get('/accounts/new', fn($p) => (new AccountController())->create($p)); $router->post('/accounts', fn($p) => (new AccountController())->store($p)); +$router->get('/accounts/{id}/journal', fn($p) => (new AccountController())->journal($p)); $router->get('/accounts/{id}/edit', fn($p) => (new AccountController())->edit($p)); $router->post('/accounts/{id}', fn($p) => (new AccountController())->update($p)); $router->post('/accounts/{id}/delete', fn($p) => (new AccountController())->destroy($p)); diff --git a/src/Controllers/AccountController.php b/src/Controllers/AccountController.php index 4aeb8e8..b56d6b5 100644 --- a/src/Controllers/AccountController.php +++ b/src/Controllers/AccountController.php @@ -198,6 +198,60 @@ class AccountController View::redirect($back, 'Konto gelöscht.'); } + public function journal(array $params): void + { + $id = (int)$params['id']; + $account = Account::find($id); + if (!$account) { http_response_code(404); return; } + + $availableYears = \Steuerkram\Database::fetchAll( + 'SELECT year FROM fiscal_years ORDER BY year DESC' + ); + $years = array_column($availableYears, 'year'); + if (empty($years)) { + $years = [(int)date('Y')]; + } + + $year = isset($_GET['year']) ? (int)$_GET['year'] : (int)date('Y'); + if (!in_array($year, $years, true)) { + $year = $years[0]; + } + + // Buchungen wo dieses Konto Kategorie-Konto ist (alle, auch Kindzeilen) + // ODER Zahlungs-Konto ist (nur Hauptbuchungen, Kindzeilen gehören nicht ans Zahlungskonto) + $bookings = \Steuerkram\Database::fetchAll( + 'SELECT bk.*, + k.kontonummer AS kategorie_nr, k.bezeichnung AS kategorie_name, + z.kontonummer AS zahlungs_nr, z.bezeichnung AS zahlungs_name, + bl.beleg_nr + FROM bookings bk + JOIN accounts k ON bk.kategorie_konto_id = k.id + JOIN accounts z ON bk.zahlungskonto_id = z.id + LEFT JOIN belege bl ON bk.beleg_id = bl.id + JOIN fiscal_years fy ON bk.fiscal_year_id = fy.id + WHERE fy.year = ? + AND ( + bk.kategorie_konto_id = ? + OR (bk.zahlungskonto_id = ? AND bk.parent_booking_id IS NULL + AND bk.kategorie_konto_id != ?) + ) + ORDER BY bk.buchungs_datum, bk.id', + [$year, $id, $id, $id] + ); + + $view = new View(); + $view->render('layout/base.php', [ + 'pageTitle' => 'Konto ' . $account['kontonummer'] . ' – Journal', + 'content' => $this->renderView('accounts/journal', [ + 'account' => $account, + 'bookings' => $bookings, + 'year' => $year, + 'years' => $years, + 'accountId' => $id, + ]), + ]); + } + public function search(array $params): void { $q = trim($_GET['q'] ?? ''); diff --git a/src/Views/accounts/journal.php b/src/Views/accounts/journal.php new file mode 100644 index 0000000..000ce28 --- /dev/null +++ b/src/Views/accounts/journal.php @@ -0,0 +1,124 @@ + View::h($v); +$fmt = fn($v) => number_format(abs((float)$v), 2, ',', '.'); + +// Jahr-Navigation +$prevYear = $year - 1; +$nextYear = $year + 1; +$hasPrev = in_array($prevYear, $years, true); +$hasNext = in_array($nextYear, $years, true); +?> + +
Keine Buchungen für dieses Konto in = $year ?>.
+| Datum | +Nummer | +Beleg | +Typ | +Gegenkonto | +Text | +Wert | +
|---|---|---|---|---|---|---|
| = $h($b['buchungs_datum']) ?> | += $h($b['buchungs_nr']) ?> | ++ + = $h($b['beleg_nr'] ?? '#' . $b['beleg_id']) ?> + + – + + | ++ + = $h($b['buchungstyp']) ?> + + | += $h($gegenkonto) ?> | += $h($b['buchungstext']) ?> | ++ = $wert < 0 ? '−' : '' ?>= $fmt($wert) ?> € + | +
| Kontostand = $year ?> (= count($bookings) ?> Buchungen) | ++ = $saldo < 0 ? '−' : '' ?>= $fmt($saldo) ?> € + | +|||||