FSCash/html/.Trash-1000/files/rep-month_old.php
2026-01-25 09:07:03 +01:00

112 lines
2.7 KiB
PHP

<?php
require 'config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: index.php');
exit;
}
// Prüfen, ob die user_id im Admin-Array ist
if (in_array($_SESSION['user_id'], $admin_ids, true)) {
$is_admin = "true";
}
// Aktuelles Jahr und Monat ermitteln, ggf. aus GET-Parametern
$year = isset($_GET['year']) ? (int)$_GET['year'] : (int)date('Y');
$month = isset($_GET['month']) ? (int)$_GET['month'] : (int)date('m');
// Monats- und Jahresgrenzen prüfen und anpassen
if ($month < 1) {
$month = 12;
$year--;
} elseif ($month > 12) {
$month = 1;
$year++;
}
// Daten abrufen für den ausgewählten Monat
$sql = "
SELECT
c.category_id AS kategorie_id,
c.name AS kategorie_name,
COALESCE(SUM(e.amount), 0) AS summe_je_kategorie
FROM
categories c
LEFT JOIN
entries e
ON e.category = c.category_id
AND EXTRACT(YEAR FROM e.date) = :year
AND EXTRACT(MONTH FROM e.date) = :month
GROUP BY
c.category_id, c.name
ORDER BY
c.category_id ASC
";
$stmt = $pdo->prepare($sql);
$stmt->execute([
'year' => $year,
'month' => $month
]);
$entries = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<title>FSCash - Monatsreport</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="container">
<!-- Navigation -->
<nav class="nav">
<button class="hamburger">☰</button>
<ul class="nav-list">
<li><a href="dashboard.php">Start</a></li>
<?php if ($is_admin === "true") echo '<li><a href="register.php">Neue User</a></li>'; ?>
<li><a href="rep-person.php">Report Personen</a></li>
<li><a href="menu5.php" style="display: none;">Menüpunkt 5</a></li>
</ul>
<!-- Container für die rechten Buttons -->
<div class="nav-right">
<a href="?year=<?= $year ?>&month=<?= $month - 1 ?>" class="nav-button"> &lt; </a>
<a href="?year=<?= $year ?>&month=<?= $month + 1 ?>" class="nav-button"> &gt; </a>
<a href="logout.php" class="logout">Logout</a>
</div>
</nav>
<h2><?= strftime('%B %Y', mktime(0, 0, 0, $month, 1, $year)) ?></h2>
<table class="thin">
<thead>
<tr>
<th>ID</th>
<th>Kategorie</th>
<th>Summe</th>
</tr>
</thead>
<tbody>
<?php foreach ($entries as $entry): ?>
<tr>
<td><?= htmlspecialchars($entry['kategorie_id'] ?? '') ?></td>
<td><?= htmlspecialchars($entry['kategorie_name'] ?? '') ?></td>
<td class="align-right"><?= htmlspecialchars(number_format($entry['summe_je_kategorie'], 2, ',', '.')) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- Neu-Button -->
<a href="new_entry.php" class="btn-xr">+</a>
</div>
<script>
// Hamburger-Menü-Funktion
document.querySelector('.hamburger').addEventListener('click', function() {
document.querySelector('.nav-list').classList.toggle('show');
});
</script>
</body>
</html>