From cf9b79e56e175eab2feedb5d3dfc59958772ca3a Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 21 Aug 2024 16:14:54 +0200 Subject: [PATCH] care about einschreibgebuehr --- seeds.sql | 1 + src/model/user.rs | 12 ++++++++++++ src/tera/admin/user.rs | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/seeds.sql b/seeds.sql index 0331795..1c42ed3 100644 --- a/seeds.sql +++ b/seeds.sql @@ -10,6 +10,7 @@ INSERT INTO "role" (name) VALUES ('Vorstand'); INSERT INTO "role" (name) VALUES ('Bootsführer'); INSERT INTO "role" (name) VALUES ('schnupperant'); INSERT INTO "role" (name) VALUES ('kassier'); +INSERT INTO "role" (name) VALUES ('no-einschreibgebuehr'); INSERT INTO "user" (name, pw) VALUES('admin', '$argon2id$v=19$m=19456,t=2,p=1$dS/X5/sPEKTj4Rzs/CuvzQ$4P4NCw4Ukhv80/eQYTsarHhnw61JuL1KMx/L9dm82YM'); INSERT INTO "user_role" (user_id, role_id) VALUES(1,1); INSERT INTO "user_role" (user_id, role_id) VALUES(1,2); diff --git a/src/model/user.rs b/src/model/user.rs index 6f25d7c..94bdd75 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -29,6 +29,7 @@ const REGULAR: i32 = 22000; const UNTERSTUETZEND: i32 = 2500; const FOERDERND: i32 = 8500; pub const SCHECKBUCH: i32 = 3000; +const EINSCHREIBGEBUEHR: i32 = 3500; #[derive(FromRow, Serialize, Deserialize, Clone, Debug, Eq, Hash, PartialEq)] pub struct User { @@ -361,6 +362,17 @@ ASKÖ Ruderverein Donau Linz", self.name), ); } + if let Some(member_since_date) = &self.member_since_date { + if let Ok(member_since_date) = NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d") + { + if member_since_date.year() == Local::now().year() + && !self.has_role(db, "no-einschreibgebuehr").await + { + fee.add("Einschreibgebühr".into(), EINSCHREIBGEBUEHR); + } + } + } + let halfprice = if let Some(member_since_date) = &self.member_since_date { if let Ok(member_since_date) = NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d") { diff --git a/src/tera/admin/user.rs b/src/tera/admin/user.rs index 3a98508..c9382e1 100644 --- a/src/tera/admin/user.rs +++ b/src/tera/admin/user.rs @@ -437,6 +437,10 @@ async fn schnupper_to_scheckbuch( let scheckbuch = Role::find_by_name(db, "scheckbuch").await.unwrap(); user.add_role(db, &scheckbuch).await; + if let Some(noEinschreibgebuehr) = Role::find_by_name(db, "no-einschreibgebuehr").await { + user.add_role(db, &noEinschreibgebuehr).await; + } + user.send_welcome_email(db, &config.smtp_pw).await.unwrap(); Log::create(