249 lines
12 KiB
PHP
249 lines
12 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../src/config.php';
|
|
require_once __DIR__ . '/../src/auth.php';
|
|
require_once __DIR__ . '/../src/db.php';
|
|
require_once __DIR__ . '/../src/journal_functions.php';
|
|
require_once __DIR__ . '/../src/icons.php';
|
|
require_login();
|
|
|
|
$years = get_journal_years();
|
|
|
|
$year_id = isset($_GET['year_id']) ? (int)$_GET['year_id'] : null;
|
|
if (!$year_id && $years) {
|
|
$current_cal_year = (int)date('Y');
|
|
foreach ($years as $y) {
|
|
if ($y['year'] == $current_cal_year) {
|
|
$year_id = $y['id'];
|
|
break;
|
|
}
|
|
}
|
|
if (!$year_id) $year_id = $years[0]['id'];
|
|
}
|
|
|
|
$current_year = null;
|
|
foreach ($years as $y) {
|
|
if ($y['id'] == $year_id) {
|
|
$current_year = $y;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$summary = null;
|
|
$profitability = null;
|
|
if ($year_id) {
|
|
$summary = calculate_yearly_summary($year_id);
|
|
$profitability = calculate_yearly_profitability($year_id);
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Journal Jahresübersicht <?= $current_year ? (int)$current_year['year'] : '' ?></title>
|
|
<link rel="stylesheet" href="assets/style.css">
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<h1>PIRP</h1>
|
|
<nav>
|
|
<a href="<?= url_for('index.php') ?>"><?= icon_dashboard() ?>Dashboard</a>
|
|
<a href="<?= url_for('invoices.php') ?>"><?= icon_invoices() ?>Rechnungen</a>
|
|
<a href="<?= url_for('customers.php') ?>"><?= icon_customers() ?>Kunden</a>
|
|
<a href="<?= url_for('expenses.php') ?>"><?= icon_expenses() ?>Ausgaben</a>
|
|
<a href="<?= url_for('belegarchiv.php') ?>"><?= icon_archive() ?>Belege</a>
|
|
<a href="<?= url_for('journal.php') ?>" class="active"><?= icon_journal() ?>Journal</a>
|
|
<a href="<?= url_for('euer.php') ?>"><?= icon_euer() ?>EÜR</a>
|
|
<a href="<?= url_for('settings.php') ?>"><?= icon_settings() ?>Einstellungen</a>
|
|
<a href="<?= url_for('logout.php') ?>"><?= icon_logout() ?>Logout (<?= htmlspecialchars($_SESSION['username'] ?? '') ?>)</a>
|
|
<span class="cmd-k-hint" onclick="document.dispatchEvent(new KeyboardEvent('keydown',{key:'k',ctrlKey:true}))"><kbd>Ctrl+K</kbd></span>
|
|
</nav>
|
|
</header>
|
|
<main>
|
|
<div class="journal-subnav">
|
|
<a href="<?= url_for('journal.php?year_id=' . $year_id) ?>">Monatsansicht</a>
|
|
<a href="<?= url_for('journal_summary.php') ?>" class="active">Jahressummen</a>
|
|
<a href="<?= url_for('journal_search.php') ?>">Suche</a>
|
|
</div>
|
|
|
|
<?php if (empty($years)): ?>
|
|
<p class="warning">Bitte zuerst ein <a href="<?= url_for('settings.php?tab=journal') ?>">Jahr anlegen</a>.</p>
|
|
<?php elseif ($summary): ?>
|
|
|
|
<!-- Jahr-Dropdown -->
|
|
<div class="journal-controls">
|
|
<form method="get" class="journal-year-select">
|
|
<label>Jahr:
|
|
<select name="year_id" onchange="this.form.submit();">
|
|
<?php foreach ($years as $y): ?>
|
|
<option value="<?= $y['id'] ?>" <?= $y['id'] == $year_id ? 'selected' : '' ?>>
|
|
<?= (int)$y['year'] ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</label>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Spaltengruppen berechnen -->
|
|
<?php
|
|
$columns = $summary['columns'];
|
|
$groups = [];
|
|
foreach ($columns as $col) {
|
|
$g = $col['group'];
|
|
if (!isset($groups[$g])) $groups[$g] = 0;
|
|
$groups[$g]++;
|
|
}
|
|
?>
|
|
|
|
<!-- Jahresübersicht Tabelle -->
|
|
<section>
|
|
<h2>Monatssummen <?= $current_year ? (int)$current_year['year'] : '' ?></h2>
|
|
<div class="journal-table-wrap">
|
|
<table class="journal-table">
|
|
<thead>
|
|
<tr class="journal-group-header">
|
|
<th colspan="2"></th>
|
|
<th colspan="2">Summen</th>
|
|
<?php foreach ($groups as $gname => $gcount): ?>
|
|
<th colspan="<?= $gcount ?>"><?= htmlspecialchars($gname) ?></th>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
<tr>
|
|
<th>Monat</th>
|
|
<th class="journal-col-betrag">Betrag</th>
|
|
<th class="journal-soll">Soll</th>
|
|
<th class="journal-haben">Haben</th>
|
|
<?php foreach ($columns as $col): ?>
|
|
<th class="journal-col-amount journal-<?= $col['side'] ?>"><?= htmlspecialchars($col['label']) ?></th>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
<!-- Jahressummen oben (wie Excel) -->
|
|
<tr class="journal-top-sums">
|
|
<td style="text-align:right;"><strong>S</strong></td>
|
|
<td class="journal-col-betrag"></td>
|
|
<td class="journal-col-amount journal-soll"><strong><?= journal_format_amount($summary['yearly_soll']) ?></strong></td>
|
|
<td class="journal-col-amount journal-haben"></td>
|
|
<?php foreach ($columns as $col): ?>
|
|
<td class="journal-col-amount journal-<?= $col['side'] ?>">
|
|
<?php if ($col['side'] === 'soll'): ?>
|
|
<strong><?= journal_format_amount($summary['yearly_totals'][$col['key']] ?? 0) ?></strong>
|
|
<?php endif; ?>
|
|
</td>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
<tr class="journal-top-sums">
|
|
<td style="text-align:right;"><strong>H</strong></td>
|
|
<td class="journal-col-betrag"></td>
|
|
<td class="journal-col-amount journal-soll"></td>
|
|
<td class="journal-col-amount journal-haben"><strong><?= journal_format_amount($summary['yearly_haben']) ?></strong></td>
|
|
<?php foreach ($columns as $col): ?>
|
|
<td class="journal-col-amount journal-<?= $col['side'] ?>">
|
|
<?php if ($col['side'] === 'haben'): ?>
|
|
<strong><?= journal_format_amount($summary['yearly_totals'][$col['key']] ?? 0) ?></strong>
|
|
<?php endif; ?>
|
|
</td>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php for ($m = 1; $m <= 12; $m++): ?>
|
|
<?php $mt = $summary['months'][$m]; ?>
|
|
<tr>
|
|
<td>
|
|
<a href="<?= url_for('journal.php?year_id=' . $year_id . '&month=' . $m) ?>">
|
|
<?= journal_month_name_full($m) ?>
|
|
</a>
|
|
</td>
|
|
<td class="journal-col-betrag"><?= journal_format_amount($mt['_amount'] ?? 0) ?></td>
|
|
<td class="journal-col-amount journal-soll"><?= journal_format_amount($mt['_soll'] ?? 0) ?></td>
|
|
<td class="journal-col-amount journal-haben"><?= journal_format_amount($mt['_haben'] ?? 0) ?></td>
|
|
<?php foreach ($columns as $col): ?>
|
|
<?php $col_val = $mt[$col['key']] ?? 0; ?>
|
|
<td class="journal-col-amount journal-<?= $col['side'] ?>">
|
|
<?php if ($col_val != 0): ?>
|
|
<a href="<?= url_for('journal_detail.php?year_id=' . $year_id . '&month=' . $m . '&col_key=' . urlencode($col['key'])) ?>" style="color:inherit;text-decoration:none;" title="Details anzeigen">
|
|
<?= journal_format_amount($col_val) ?>
|
|
</a>
|
|
<?php else: ?>
|
|
<?= journal_format_amount($col_val) ?>
|
|
<?php endif; ?>
|
|
</td>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
<?php endfor; ?>
|
|
</tbody>
|
|
<tfoot>
|
|
<tr class="journal-totals-row">
|
|
<td><strong>Jahressumme</strong></td>
|
|
<td class="journal-col-betrag"><strong><?= journal_format_amount($summary['yearly_amount']) ?></strong></td>
|
|
<td class="journal-col-amount journal-soll"><strong><?= journal_format_amount($summary['yearly_soll']) ?></strong></td>
|
|
<td class="journal-col-amount journal-haben"><strong><?= journal_format_amount($summary['yearly_haben']) ?></strong></td>
|
|
<?php foreach ($columns as $col): ?>
|
|
<td class="journal-col-amount journal-<?= $col['side'] ?>">
|
|
<strong><?= journal_format_amount($summary['yearly_totals'][$col['key']] ?? 0) ?></strong>
|
|
</td>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
</tfoot>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Gewinnberechnung -->
|
|
<?php if ($profitability): ?>
|
|
<section>
|
|
<h2>Gewinnberechnung <?= $current_year ? (int)$current_year['year'] : '' ?></h2>
|
|
<div>
|
|
<table class="list">
|
|
<thead>
|
|
<tr>
|
|
<th>Monat</th>
|
|
<th style="text-align:right;">Erlöse</th>
|
|
<th style="text-align:right;">Wareneingang</th>
|
|
<th style="text-align:right;">Aufwand</th>
|
|
<th style="text-align:right;">Gewinn</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$sum_er = 0; $sum_we = 0; $sum_au = 0; $sum_gw = 0;
|
|
for ($m = 1; $m <= 12; $m++):
|
|
$p = $profitability[$m];
|
|
$sum_er += $p['erloese'];
|
|
$sum_we += $p['wareneingang'];
|
|
$sum_au += $p['aufwand'];
|
|
$sum_gw += $p['gewinn'];
|
|
?>
|
|
<tr>
|
|
<td><?= journal_month_name_full($m) ?></td>
|
|
<td style="text-align:right;"><?= journal_format_amount($p['erloese']) ?></td>
|
|
<td style="text-align:right;"><?= journal_format_amount($p['wareneingang']) ?></td>
|
|
<td style="text-align:right;"><?= journal_format_amount($p['aufwand']) ?></td>
|
|
<td style="text-align:right;<?= $p['gewinn'] < 0 ? 'color:var(--error);' : '' ?>">
|
|
<strong><?= journal_format_amount($p['gewinn']) ?></strong>
|
|
</td>
|
|
</tr>
|
|
<?php endfor; ?>
|
|
</tbody>
|
|
<tfoot>
|
|
<tr>
|
|
<td><strong>Jahressumme</strong></td>
|
|
<td style="text-align:right;"><strong><?= journal_format_amount($sum_er) ?></strong></td>
|
|
<td style="text-align:right;"><strong><?= journal_format_amount($sum_we) ?></strong></td>
|
|
<td style="text-align:right;"><strong><?= journal_format_amount($sum_au) ?></strong></td>
|
|
<td style="text-align:right;<?= $sum_gw < 0 ? 'color:var(--error);' : '' ?>">
|
|
<strong><?= journal_format_amount($sum_gw) ?></strong>
|
|
</td>
|
|
</tr>
|
|
</tfoot>
|
|
</table>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
<?php endif; ?>
|
|
</main>
|
|
<script src="assets/command-palette.js"></script>
|
|
</body>
|
|
</html>
|