From 3171ea001a54ec9920807bb09fc2e38c47e1be73 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Tue, 31 Mar 2026 11:48:57 +0200 Subject: [PATCH] feat(reports): add membership structure breakdown to fees report Shows: total active, paying members, subsidiaries (fee in parent), resignations, standard vs premium fee tier counts. All dynamic from database. Co-Authored-By: Claude Opus 4.6 (1M context) --- blueprints/reports/routes.py | 31 +++++++++++++++++++++++++++++++ templates/reports/fees.html | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/blueprints/reports/routes.py b/blueprints/reports/routes.py index 5c59fa1..a2afc3b 100644 --- a/blueprints/reports/routes.py +++ b/blueprints/reports/routes.py @@ -219,6 +219,32 @@ def fees_report(): total_companies_with_fees = len(by_company) total_active = db.query(Company).filter(Company.status == 'active').count() + # Membership structure breakdown + subsidiaries_count = db.query(Company).filter( + Company.status == 'active', + Company.fee_included_in_parent == True + ).count() + paying_companies = db.query(Company).filter( + Company.status == 'active', + Company.fee_included_in_parent != True + ).count() + + # Fee tier breakdown: standard (200) vs premium (300+) + from sqlalchemy import func, distinct + standard_fee = 0 + premium_fee = 0 + for company_id, company_fees in by_company.items(): + if company_fees: + avg_amount = sum(float(f.amount) for f in company_fees) / len(company_fees) + if avg_amount > 200: + premium_fee += 1 + else: + standard_fee += 1 + + resigned_count = db.query(Company).filter( + Company.membership_status == 'resigned' + ).count() + fully_paid = 0 partially_paid = 0 no_payments = 0 @@ -279,6 +305,11 @@ def fees_report(): monthly_stats=monthly_stats, months_names=MONTHS_NAMES, generated_at=datetime.now(), + subsidiaries_count=subsidiaries_count, + paying_companies=paying_companies, + standard_fee=standard_fee, + premium_fee=premium_fee, + resigned_count=resigned_count, ) finally: db.close() diff --git a/templates/reports/fees.html b/templates/reports/fees.html index c18e807..59dfc95 100644 --- a/templates/reports/fees.html +++ b/templates/reports/fees.html @@ -99,6 +99,41 @@ + +
+

Struktura członków Izby

+
+
+
{{ total_active }}
+
Wszystkie aktywne firmy
+
+
+
{{ paying_companies }}
+
Płacące składki
+
+
+
{{ subsidiaries_count }}
+
Podspółki (składka w spółce głównej)
+
+
+
{{ resigned_count }}
+
Rezygnacje
+
+
+
+
+

Składka standardowa (200 zł/mies.)

+
{{ standard_fee }}
+
firm
+
+
+

Składka podwyższona (300 zł/mies.)

+
{{ premium_fee }}
+
firm
+
+
+
+

Podział firm