Compare commits
2 Commits
ae8887c72d
...
14a5952e14
Author | SHA1 | Date | |
---|---|---|---|
14a5952e14 | |||
e498b4be3b |
@ -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<Self> {
|
||||
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<Self> {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
Loading…
Reference in New Issue
Block a user