Summen in Report Monat/Personen klickbar zum gefilterten Dashboard verlinkt
Jede Summenangabe in rep-month.php und rep-person.php führt jetzt per Klick zum Dashboard mit exakt den Filtern (Jahr, Monat, Kategorie(n), Zahler), die in die jeweilige Summe eingeflossen sind. Außerdem Fix für rep-person.php: ohne ?categories[]-Parameter wurde $selectedCategories nie initialisiert, was zu einem Fatal Error führte - jetzt werden standardmäßig alle Kategorien vorausgewählt. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
d63b3d86d2
commit
9b3e8d03be
3 changed files with 37 additions and 7 deletions
|
|
@ -95,6 +95,11 @@ foreach ($entries as $entry) {
|
||||||
$filterZahlweise[$entry['zahlweise']] = true;
|
$filterZahlweise[$entry['zahlweise']] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Vorauswahl der Filter aus GET-Parametern (z. B. Link aus einem Report)
|
||||||
|
$presetZahler = isset($_GET['zahler']) ? $_GET['zahler'] : '';
|
||||||
|
$presetKategorie = isset($_GET['kategorie']) ? $_GET['kategorie'] : '';
|
||||||
|
$presetKategorien = isset($_GET['kategorien']) && is_array($_GET['kategorien']) ? $_GET['kategorien'] : [];
|
||||||
|
|
||||||
$filterZahler = array_keys($filterZahler);
|
$filterZahler = array_keys($filterZahler);
|
||||||
$filterPersonen = array_keys($filterPersonen);
|
$filterPersonen = array_keys($filterPersonen);
|
||||||
$filterKategorie = array_keys($filterKategorie);
|
$filterKategorie = array_keys($filterKategorie);
|
||||||
|
|
@ -155,7 +160,7 @@ sort($filterZahlweise, SORT_STRING | SORT_FLAG_CASE);
|
||||||
<select class="column-filter" data-col="1">
|
<select class="column-filter" data-col="1">
|
||||||
<option value="">Alle</option>
|
<option value="">Alle</option>
|
||||||
<?php foreach ($filterZahler as $wert): ?>
|
<?php foreach ($filterZahler as $wert): ?>
|
||||||
<option value="<?= htmlspecialchars($wert) ?>"><?= htmlspecialchars($wert) ?></option>
|
<option value="<?= htmlspecialchars($wert) ?>" <?= $wert === $presetZahler ? 'selected' : '' ?>><?= htmlspecialchars($wert) ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</th>
|
</th>
|
||||||
|
|
@ -171,7 +176,7 @@ sort($filterZahlweise, SORT_STRING | SORT_FLAG_CASE);
|
||||||
<select class="column-filter" data-col="3">
|
<select class="column-filter" data-col="3">
|
||||||
<option value="">Alle</option>
|
<option value="">Alle</option>
|
||||||
<?php foreach ($filterKategorie as $wert): ?>
|
<?php foreach ($filterKategorie as $wert): ?>
|
||||||
<option value="<?= htmlspecialchars($wert) ?>"><?= htmlspecialchars($wert) ?></option>
|
<option value="<?= htmlspecialchars($wert) ?>" <?= $wert === $presetKategorie ? 'selected' : '' ?>><?= htmlspecialchars($wert) ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</th>
|
</th>
|
||||||
|
|
@ -224,6 +229,8 @@ document.querySelector('.hamburger').addEventListener('click', function() {
|
||||||
(function() {
|
(function() {
|
||||||
const filters = document.querySelectorAll('.column-filter');
|
const filters = document.querySelectorAll('.column-filter');
|
||||||
const rows = document.querySelectorAll('#entries-body tr');
|
const rows = document.querySelectorAll('#entries-body tr');
|
||||||
|
// Mehrfach-Kategorie-Vorauswahl, z. B. per Link aus dem Personenreport (Kategorie-Select kann nur einen Wert anzeigen)
|
||||||
|
const presetKategorien = <?= json_encode(array_map('strtolower', $presetKategorien)) ?>;
|
||||||
|
|
||||||
function applyFilters() {
|
function applyFilters() {
|
||||||
const activeFilters = Array.from(filters)
|
const activeFilters = Array.from(filters)
|
||||||
|
|
@ -236,7 +243,7 @@ document.querySelector('.hamburger').addEventListener('click', function() {
|
||||||
const cell = cells[f.col];
|
const cell = cells[f.col];
|
||||||
if (!cell) return true;
|
if (!cell) return true;
|
||||||
return cell.textContent.trim().toLowerCase().includes(f.value);
|
return cell.textContent.trim().toLowerCase().includes(f.value);
|
||||||
});
|
}) && (presetKategorien.length === 0 || (cells[3] && presetKategorien.includes(cells[3].textContent.trim().toLowerCase())));
|
||||||
row.style.display = visible ? '' : 'none';
|
row.style.display = visible ? '' : 'none';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -245,6 +252,8 @@ document.querySelector('.hamburger').addEventListener('click', function() {
|
||||||
f.addEventListener('input', applyFilters);
|
f.addEventListener('input', applyFilters);
|
||||||
f.addEventListener('change', applyFilters);
|
f.addEventListener('change', applyFilters);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
applyFilters();
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,11 @@ if (isset($_GET['export']) && $_GET['export'] === 'csv') {
|
||||||
<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>
|
||||||
<td class="align-right"><?= htmlspecialchars(number_format($entry['summe_je_kategorie'], 2, ',', '.')) ?></td>
|
<td class="align-right">
|
||||||
|
<a href="dashboard.php?year=<?= $year ?>&month=<?= $month ?>&kategorie=<?= urlencode($entry['kategorie_name'] ?? '') ?>">
|
||||||
|
<?= htmlspecialchars(number_format($entry['summe_je_kategorie'], 2, ',', '.')) ?>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,10 @@ $categoryStmt = $pdo->query("SELECT category_id, name FROM categories ORDER BY n
|
||||||
$categories = $categoryStmt->fetchAll();
|
$categories = $categoryStmt->fetchAll();
|
||||||
|
|
||||||
// Standardmäßig alle Kategorien auswählen, falls keine Auswahl getroffen wurde
|
// Standardmäßig alle Kategorien auswählen, falls keine Auswahl getroffen wurde
|
||||||
// $selectedCategories = isset($_GET['categories']) ? $_GET['categories'] : array_column($categories, 'category_id');
|
|
||||||
|
|
||||||
if (array_key_exists('categories', $_GET) && $_GET['categories'] !== []) {
|
if (array_key_exists('categories', $_GET) && $_GET['categories'] !== []) {
|
||||||
$selectedCategories = $_GET['categories'];
|
$selectedCategories = $_GET['categories'];
|
||||||
|
} else {
|
||||||
|
$selectedCategories = array_column($categories, 'category_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -60,6 +60,14 @@ $params = array_merge([$month, $year], $selectedCategories);
|
||||||
$stmt = $pdo->prepare($sql);
|
$stmt = $pdo->prepare($sql);
|
||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
$entries = $stmt->fetchAll();
|
$entries = $stmt->fetchAll();
|
||||||
|
|
||||||
|
// Namen der aktuell ausgewählten Kategorien ermitteln (für den Link zum Dashboard)
|
||||||
|
$selectedCategoryNames = [];
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
if (in_array($category['category_id'], $selectedCategories)) {
|
||||||
|
$selectedCategoryNames[] = $category['name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
|
|
@ -126,7 +134,16 @@ $entries = $stmt->fetchAll();
|
||||||
<?php foreach ($entries as $entry): ?>
|
<?php foreach ($entries as $entry): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= htmlspecialchars($entry['username'] ?? '') ?></td>
|
<td><?= htmlspecialchars($entry['username'] ?? '') ?></td>
|
||||||
<td class="align-right"><?= htmlspecialchars(number_format($entry['gesamtbetrag'], 2, ',', '.')) ?></td>
|
<td class="align-right">
|
||||||
|
<a href="dashboard.php?<?= http_build_query([
|
||||||
|
'year' => $year,
|
||||||
|
'month' => $month,
|
||||||
|
'zahler' => $entry['username'] ?? '',
|
||||||
|
'kategorien' => $selectedCategoryNames,
|
||||||
|
]) ?>">
|
||||||
|
<?= htmlspecialchars(number_format($entry['gesamtbetrag'], 2, ',', '.')) ?>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue