From 803c1e5867bbd11d669534d090d3142dc9675a69 Mon Sep 17 00:00:00 2001 From: fds2610-bot Date: Sun, 26 Jul 2026 14:13:10 +0200 Subject: [PATCH] Feature: Zahlart-Filter im Personenreport (Issue #11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ergänzt rep-person.php um eine zweite Filtertabelle für Zahlweisen neben der Kategorien-Auswahl; die Summen werden entsprechend beider Filter berechnet. Der Link zum Dashboard gibt die gewählten Zahlweisen als Vorauswahl weiter, analog zur bestehenden Kategorien-Vorauswahl. --- html/assets/css/style.css | 12 +++++++- html/dashboard.php | 6 +++- html/lib/fscash.php | 17 ++++++++++++ html/rep-person.php | 58 ++++++++++++++++++++++++++++++++++----- tests/FscashTest.php | 26 ++++++++++++++++++ 5 files changed, 110 insertions(+), 9 deletions(-) diff --git a/html/assets/css/style.css b/html/assets/css/style.css index bced8d3..eeaae5a 100644 --- a/html/assets/css/style.css +++ b/html/assets/css/style.css @@ -97,10 +97,20 @@ h1 { outline: none; } -#categories_rep_person { +.category-checkbox-list { font-size: 12px; } +.filter-columns { + display: flex; + flex-wrap: wrap; + gap: 40px; +} + +.filter-column { + min-width: 160px; +} + .btn-submit { display: inline-block; background: var(--primary-color); diff --git a/html/dashboard.php b/html/dashboard.php index 592388d..bcd8f35 100644 --- a/html/dashboard.php +++ b/html/dashboard.php @@ -94,6 +94,7 @@ foreach ($entries as $entry) { $presetZahler = isset($_GET['zahler']) ? $_GET['zahler'] : ''; $presetKategorie = isset($_GET['kategorie']) ? $_GET['kategorie'] : ''; $presetKategorien = isset($_GET['kategorien']) && is_array($_GET['kategorien']) ? $_GET['kategorien'] : []; +$presetZahlweisen = isset($_GET['zahlweisen']) && is_array($_GET['zahlweisen']) ? $_GET['zahlweisen'] : []; $filterZahler = array_keys($filterZahler); $filterPersonen = array_keys($filterPersonen); @@ -240,6 +241,8 @@ document.querySelector('.hamburger').addEventListener('click', function() { const sumValue = document.getElementById('sum-value'); // Mehrfach-Kategorie-Vorauswahl, z. B. per Link aus dem Personenreport (Kategorie-Select kann nur einen Wert anzeigen) const presetKategorien = ; + // Mehrfach-Zahlweise-Vorauswahl, z. B. per Link aus dem Personenreport (Zahlweise-Select kann nur einen Wert anzeigen) + const presetZahlweisen = ; function applyFilters() { const activeFilters = Array.from(filters) @@ -253,7 +256,8 @@ document.querySelector('.hamburger').addEventListener('click', function() { const cell = cells[f.col]; if (!cell) return true; return cell.textContent.trim().toLowerCase().includes(f.value); - }) && (presetKategorien.length === 0 || (cells[3] && presetKategorien.includes(cells[3].textContent.trim().toLowerCase()))); + }) && (presetKategorien.length === 0 || (cells[3] && presetKategorien.includes(cells[3].textContent.trim().toLowerCase()))) + && (presetZahlweisen.length === 0 || (cells[4] && presetZahlweisen.includes(cells[4].textContent.trim().toLowerCase()))); row.style.display = visible ? '' : 'none'; if (visible) { const amountCell = cells[6]; diff --git a/html/lib/fscash.php b/html/lib/fscash.php index fd29cad..092f8c0 100644 --- a/html/lib/fscash.php +++ b/html/lib/fscash.php @@ -123,6 +123,23 @@ function fscash_resolve_selected_categories(array $allCategoryIds, $requestedCat return $allCategoryIds; } +/** + * Ermittelt die im Personenreport ausgewählten Zahlweise-IDs: die per + * Request übergebenen, sofern vorhanden, sonst alle verfügbaren. + * + * @param int[] $allPaymentMethodIds Alle in der DB vorhandenen Zahlweise-IDs. + * @param mixed $requestedPaymentMethodIds Roher Wert aus $_GET['payment_methods'] (oder null, falls nicht gesetzt). + * @return array + */ +function fscash_resolve_selected_payment_methods(array $allPaymentMethodIds, $requestedPaymentMethodIds): array +{ + if (is_array($requestedPaymentMethodIds) && $requestedPaymentMethodIds !== []) { + return $requestedPaymentMethodIds; + } + + return $allPaymentMethodIds; +} + /** * Extrahiert den aktuellen Kurs aus einer Alpha-Vantage GLOBAL_QUOTE-Antwort. * diff --git a/html/rep-person.php b/html/rep-person.php index d775e05..f65f9f1 100644 --- a/html/rep-person.php +++ b/html/rep-person.php @@ -32,8 +32,18 @@ $selectedCategories = fscash_resolve_selected_categories( $_GET['categories'] ?? null ); +// Zahlweisen aus der Datenbank abrufen +$paymentMethodStmt = $pdo->query("SELECT payment_method_id, name FROM payment_methods ORDER BY name"); +$paymentMethods = $paymentMethodStmt->fetchAll(); -// Daten abrufen für den ausgewählten Monat und die ausgewählten Kategorien +// Standardmäßig alle Zahlweisen auswählen, falls keine Auswahl getroffen wurde +$selectedPaymentMethods = fscash_resolve_selected_payment_methods( + array_column($paymentMethods, 'payment_method_id'), + $_GET['payment_methods'] ?? null +); + + +// Daten abrufen für den ausgewählten Monat, die ausgewählten Kategorien und Zahlweisen $sql = " SELECT u.id AS user_id, @@ -46,11 +56,12 @@ entries e ON e.user_id = u.id AND MONTH(e.date) = ? AND YEAR(e.date) = ? AND e.category IN (" . implode(',', array_fill(0, count($selectedCategories), '?')) . ") +AND e.payment_method IN (" . implode(',', array_fill(0, count($selectedPaymentMethods), '?')) . ") GROUP BY u.id, u.username; "; -$params = array_merge([$month, $year], $selectedCategories); +$params = array_merge([$month, $year], $selectedCategories, $selectedPaymentMethods); $stmt = $pdo->prepare($sql); $stmt->execute($params); $entries = $stmt->fetchAll(); @@ -62,6 +73,14 @@ foreach ($categories as $category) { $selectedCategoryNames[] = $category['name']; } } + +// Namen der aktuell ausgewählten Zahlweisen ermitteln (für den Link zum Dashboard) +$selectedPaymentMethodNames = []; +foreach ($paymentMethods as $paymentMethod) { + if (in_array($paymentMethod['payment_method_id'], $selectedPaymentMethods)) { + $selectedPaymentMethodNames[] = $paymentMethod['name']; + } +} ?> @@ -93,10 +112,13 @@ foreach ($categories as $category) {

- +
+ +
+
@@ -113,6 +135,27 @@ foreach ($categories as $category) {

+
+ +
+ + +
+ +
+ +
+
+
@@ -130,10 +173,11 @@ foreach ($categories as $category) { diff --git a/tests/FscashTest.php b/tests/FscashTest.php index 6e1c530..164fb9f 100644 --- a/tests/FscashTest.php +++ b/tests/FscashTest.php @@ -187,6 +187,32 @@ final class FscashTest extends TestCase ); } + // --- fscash_resolve_selected_payment_methods -------------------------- + + public function testResolveSelectedPaymentMethodsMitAuswahl(): void + { + $this->assertSame( + [2, 3], + fscash_resolve_selected_payment_methods([1, 2, 3, 4], [2, 3]) + ); + } + + public function testResolveSelectedPaymentMethodsOhneAuswahlLiefertAlle(): void + { + $this->assertSame( + [1, 2, 3, 4], + fscash_resolve_selected_payment_methods([1, 2, 3, 4], null) + ); + } + + public function testResolveSelectedPaymentMethodsBeiLeeremArrayLiefertAlle(): void + { + $this->assertSame( + [1, 2, 3, 4], + fscash_resolve_selected_payment_methods([1, 2, 3, 4], []) + ); + } + // --- fscash_extract_quote_price -------------------------------------- public function testExtractQuotePriceLiestPreisAus(): void