From 5533106aca1926f9c5db6233d9e0c6995d061c70 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 20 Mar 2024 13:34:21 +0100 Subject: [PATCH] show total club km --- src/model/stat.rs | 10 ++++++++++ src/tera/stat.rs | 6 ++++-- templates/stat.people.html.tera | 11 +++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/model/stat.rs b/src/model/stat.rs index 165c455..6344a2d 100644 --- a/src/model/stat.rs +++ b/src/model/stat.rs @@ -88,6 +88,16 @@ AND u.name != 'Externe Steuerperson'; } } + pub async fn sum_people(db: &SqlitePool, year: Option) -> i32 { + let stats = Self::people(db, year).await; + let mut sum = 0; + for stat in stats { + sum += stat.rowed_km; + } + + sum + } + pub async fn people(db: &SqlitePool, year: Option) -> Vec { let year = match year { Some(year) => year, diff --git a/src/tera/stat.rs b/src/tera/stat.rs index 5db94fb..6489fd5 100644 --- a/src/tera/stat.rs +++ b/src/tera/stat.rs @@ -35,25 +35,27 @@ async fn index_boat_kiosk( #[get("/?", rank = 2)] async fn index(db: &State, user: DonauLinzUser, year: Option) -> Template { let stat = Stat::people(db, year).await; + let club_km = Stat::sum_people(db, year).await; let guest_km = Stat::guest(db, year).await; let personal = stat::get_personal(db, &user).await; let kiosk = false; Template::render( "stat.people", - context!(loggedin_user: &UserWithRoles::from_user(user.into(), db).await, stat, personal, kiosk, guest_km), + context!(loggedin_user: &UserWithRoles::from_user(user.into(), db).await, stat, personal, kiosk, guest_km, club_km), ) } #[get("/?")] async fn index_kiosk(db: &State, _kiosk: KioskCookie, year: Option) -> Template { let stat = Stat::people(db, year).await; + let club_km = Stat::sum_people(db, year).await; let guest_km = Stat::guest(db, year).await; let kiosk = true; Template::render( "stat.people", - context!(stat, kiosk, show_kiosk_header: true, guest_km), + context!(stat, kiosk, show_kiosk_header: true, guest_km, club_km), ) } diff --git a/templates/stat.people.html.tera b/templates/stat.people.html.tera index f054583..46237cc 100644 --- a/templates/stat.people.html.tera +++ b/templates/stat.people.html.tera @@ -22,7 +22,7 @@
{% set_global km = 0 %} {% set_global index = 1 %} {% for s in stat %} -
@@ -38,7 +38,14 @@ {% set_global km = s.rowed_km %}
{% endfor %} -
+ + Gesamtkilometer Donau Linz + {{ club_km }} km +
+
-- 2.45.2