diff --git a/src/model/user.rs b/src/model/user.rs index a27bbfb..3bbc351 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -142,10 +142,15 @@ impl User { let mut fee = Fee::new(); if let Some(family) = Family::find_by_opt_id(db, self.family_id).await { - fee.name(format!("{} + Familie", self.name)); + let mut names = String::new(); for member in family.members(db).await { + if !names.is_empty() { + names.push_str(" + "); + } + names.push_str(&member.name); fee.merge(member.fee_without_families(db).await); } + fee.name(names); if family.amount_family_members(db).await > 2 { fee.add("Familie 3+ Personen".into(), FAMILY_THREE_OR_MORE); } else { @@ -357,6 +362,26 @@ ORDER BY last_access DESC .unwrap() } + pub async fn all_payer_groups(db: &SqlitePool) -> Vec { + sqlx::query_as!( + Self, + " +SELECT id, name, pw, deleted, last_access, dob, weight, sex, member_since_date, birthdate, mail, nickname, notes, phone, address, family_id FROM user +WHERE family_id IS NOT NULL +GROUP BY family_id + +UNION + +-- Select users with a null family_id, without grouping +SELECT id, name, pw, deleted, last_access, dob, weight, sex, member_since_date, birthdate, mail, nickname, notes, phone, address, family_id FROM user +WHERE family_id IS NULL; + " + ) + .fetch_all(db) + .await + .unwrap() + } + pub async fn ergo(db: &SqlitePool) -> Vec { sqlx::query_as!( Self, diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index 6b67bbb..e47df2c 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -56,7 +56,7 @@ async fn fees( ) -> Template { let mut context = Context::new(); - let users = User::all(db).await; + let users = User::all_payer_groups(db).await; let mut fees = Vec::new(); for user in users { if let Some(fee) = user.fee(db).await { diff --git a/staging-diff.sql b/staging-diff.sql index a3db7ce..e69de29 100644 --- a/staging-diff.sql +++ b/staging-diff.sql @@ -1,5 +0,0 @@ -CREATE TABLE IF NOT EXISTS "family" ( - "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT -); - -ALTER TABLE "user" ADD COLUMN "family_id" INTEGER REFERENCES family(id);