Steuerkram/src/Controllers/EuerController.php
2026-03-25 00:19:33 +01:00

62 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace Steuerkram\Controllers;
use Steuerkram\Models\Setting;
use Steuerkram\Models\FiscalYear;
use Steuerkram\Services\EuerCalculator;
use Steuerkram\Services\PdfEuerService;
use Steuerkram\View;
class EuerController
{
public function index(array $params): void
{
$years = FiscalYear::availableYears();
if (empty($years)) $years = [(int)date('Y')];
$view = new View();
$view->render('layout/base.php', [
'pageTitle' => 'EÜR – Einnahmen-Überschuss-Rechnung',
'content' => $this->renderView('tax/euer_index', ['years' => $years]),
]);
}
public function show(array $params): void
{
$year = (int)$params['year'];
$calc = new EuerCalculator();
$euer = $calc->calculate($year);
$view = new View();
$view->render('layout/base.php', [
'pageTitle' => "EÜR {$year}",
'content' => $this->renderView('tax/euer_show', [
'euer' => $euer,
'year' => $year,
]),
'topbarActions' => '<a href="/tax/euer/' . $year . '/pdf" class="btn btn-secondary">PDF herunterladen</a>',
]);
}
public function pdf(array $params): void
{
$year = (int)$params['year'];
$calc = new EuerCalculator();
$euer = $calc->calculate($year);
$settings = Setting::get();
$svc = new PdfEuerService();
$svc->render($euer, $settings);
}
private function renderView(string $template, array $data): string
{
extract($data, EXTR_SKIP);
ob_start();
include dirname(__DIR__) . '/Views/' . $template . '.php';
return ob_get_clean();
}
}