CSV Export im Monatsreport hinzugefügt
This commit is contained in:
parent
e9fa1af2f4
commit
2f4c608de7
3 changed files with 179 additions and 7 deletions
112
html/.Trash-1000/files/rep-month_old.php
Normal file
112
html/.Trash-1000/files/rep-month_old.php
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
<?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"> < </a>
|
||||||
|
<a href="?year=<?= $year ?>&month=<?= $month + 1 ?>" class="nav-button"> > </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>
|
||||||
3
html/.Trash-1000/info/rep-month_old.php.trashinfo
Normal file
3
html/.Trash-1000/info/rep-month_old.php.trashinfo
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[Trash Info]
|
||||||
|
Path=rep-month_old.php
|
||||||
|
DeletionDate=2026-01-25T09:06:35
|
||||||
|
|
@ -23,8 +23,8 @@ if ($month < 1) {
|
||||||
$year++;
|
$year++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Daten abrufen für den ausgewählten Monat
|
// Daten für die Summen-Tabelle abrufen
|
||||||
$sql = "
|
$sql_sum = "
|
||||||
SELECT
|
SELECT
|
||||||
c.category_id AS kategorie_id,
|
c.category_id AS kategorie_id,
|
||||||
c.name AS kategorie_name,
|
c.name AS kategorie_name,
|
||||||
|
|
@ -42,13 +42,68 @@ ORDER BY
|
||||||
c.category_id ASC
|
c.category_id ASC
|
||||||
";
|
";
|
||||||
|
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt_sum = $pdo->prepare($sql_sum);
|
||||||
$stmt->execute([
|
$stmt_sum->execute([
|
||||||
'year' => $year,
|
'year' => $year,
|
||||||
'month' => $month
|
'month' => $month
|
||||||
]);
|
]);
|
||||||
$entries = $stmt->fetchAll();
|
$entries_sum = $stmt_sum->fetchAll();
|
||||||
|
|
||||||
|
// Daten für den CSV-Export (alle Einträge) abrufen
|
||||||
|
$sql_csv = "
|
||||||
|
SELECT
|
||||||
|
e.id AS id,
|
||||||
|
e.user_id AS benutzer_id,
|
||||||
|
u.username AS benutzer_name,
|
||||||
|
c.category_id AS kategorie_id,
|
||||||
|
c.name AS kategorie_name,
|
||||||
|
e.amount AS betrag,
|
||||||
|
pm.name AS zahlungsmethode,
|
||||||
|
e.subject AS betreff,
|
||||||
|
e.date AS datum
|
||||||
|
FROM
|
||||||
|
entries e
|
||||||
|
LEFT JOIN
|
||||||
|
categories c ON e.category = c.category_id
|
||||||
|
LEFT JOIN
|
||||||
|
users u ON e.user_id = u.id
|
||||||
|
LEFT JOIN
|
||||||
|
payment_methods pm ON e.payment_method = pm.payment_method_id
|
||||||
|
WHERE
|
||||||
|
EXTRACT(YEAR FROM e.date) = :year
|
||||||
|
AND EXTRACT(MONTH FROM e.date) = :month
|
||||||
|
ORDER BY
|
||||||
|
e.date ASC
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmt_csv = $pdo->prepare($sql_csv);
|
||||||
|
$stmt_csv->execute([
|
||||||
|
'year' => $year,
|
||||||
|
'month' => $month
|
||||||
|
]);
|
||||||
|
$entries_csv = $stmt_csv->fetchAll();
|
||||||
|
|
||||||
|
// CSV-Export-Logik
|
||||||
|
if (isset($_GET['export']) && $_GET['export'] === 'csv') {
|
||||||
|
header('Content-Type: text/csv; charset=utf-8');
|
||||||
|
header('Content-Disposition: attachment; filename=monatsreport_'.$year.'_'.$month.'.csv');
|
||||||
|
$output = fopen('php://output', 'w');
|
||||||
|
fputcsv($output, ['ID', 'Datum', 'Benutzer', 'Kat-ID', 'Kategorie', 'Betreff', 'Betrag', 'Zahlungsmethode'], ';');
|
||||||
|
foreach ($entries_csv as $entry) {
|
||||||
|
fputcsv($output, [
|
||||||
|
$entry['id'] ?? '',
|
||||||
|
$entry['datum'] ?? '',
|
||||||
|
$entry['benutzer_name'] ?? '',
|
||||||
|
$entry['kategorie_id'] ?? '',
|
||||||
|
$entry['kategorie_name'] ?? '',
|
||||||
|
$entry['betreff'] ?? '',
|
||||||
|
number_format($entry['betrag'], 2, ',', '.'),
|
||||||
|
$entry['zahlungsmethode'] ?? ''
|
||||||
|
], ';');
|
||||||
|
}
|
||||||
|
fclose($output);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
|
|
@ -88,7 +143,7 @@ $entries = $stmt->fetchAll();
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($entries as $entry): ?>
|
<?php foreach ($entries_sum as $entry): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= htmlspecialchars($entry['kategorie_id'] ?? '') ?></td>
|
<td><?= htmlspecialchars($entry['kategorie_id'] ?? '') ?></td>
|
||||||
<td><?= htmlspecialchars($entry['kategorie_name'] ?? '') ?></td>
|
<td><?= htmlspecialchars($entry['kategorie_name'] ?? '') ?></td>
|
||||||
|
|
@ -98,8 +153,10 @@ $entries = $stmt->fetchAll();
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<!-- Neu-Button -->
|
<!-- Buttons -->
|
||||||
|
<div class="button-group">
|
||||||
<a href="new_entry.php" class="btn-xr">+</a>
|
<a href="new_entry.php" class="btn-xr">+</a>
|
||||||
|
<a href="?year=<?= $year ?>&month=<?= $month ?>&export=csv" class="btn-xr">CSV</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue