From a62fd116eabbb685002afac6cb49bd98545458ef Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 22 Jul 2024 21:35:07 +0200 Subject: [PATCH 1/2] show halfprice for member fees if entry_year == current_year && start_date >= 1.7. Fixes #616 --- src/model/user.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/model/user.rs b/src/model/user.rs index a0f8da0..b940ff1 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -361,17 +361,34 @@ ASKÖ Ruderverein Donau Linz", self.name), ); } + let halfprice = if let Some(member_since_date) = &self.member_since_date { + let member_since_date = + NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d").unwrap(); + let halfprice_startdate = NaiveDate::from_ymd_opt(Local::now().year(), 7, 1).unwrap(); + member_since_date >= halfprice_startdate + } else { + false + }; + if self.has_role(db, "Unterstützend").await { fee.add("Unterstützendes Mitglied".into(), UNTERSTUETZEND); } else if self.has_role(db, "Förderndes Mitglied").await { fee.add("Förderndes Mitglied".into(), FOERDERND); } else if Family::find_by_opt_id(db, self.family_id).await.is_none() { if self.has_role(db, "Student").await || self.has_role(db, "Schüler").await { - fee.add("Schüler/Student".into(), STUDENT_OR_PUPIL); + if halfprice { + fee.add("Schüler/Student (Halbpreis)".into(), STUDENT_OR_PUPIL / 2); + } else { + fee.add("Schüler/Student".into(), STUDENT_OR_PUPIL); + } } else if self.has_role(db, "Ehrenmitglied").await { fee.add("Ehrenmitglied".into(), 0); } else { - fee.add("Mitgliedsbeitrag".into(), REGULAR); + if halfprice { + fee.add("Mitgliedsbeitrag (Halbpreis)".into(), REGULAR / 2); + } else { + fee.add("Mitgliedsbeitrag".into(), REGULAR); + } } } -- 2.45.2 From b1252e8d5c021af1221aa098d55589c1cf8c2554 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 22 Jul 2024 21:56:47 +0200 Subject: [PATCH 2/2] fix empty but non-null date entries --- src/model/user.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/model/user.rs b/src/model/user.rs index b940ff1..a018d3f 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -362,10 +362,14 @@ ASKÖ Ruderverein Donau Linz", self.name), } let halfprice = if let Some(member_since_date) = &self.member_since_date { - let member_since_date = - NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d").unwrap(); - let halfprice_startdate = NaiveDate::from_ymd_opt(Local::now().year(), 7, 1).unwrap(); - member_since_date >= halfprice_startdate + if let Ok(member_since_date) = NaiveDate::parse_from_str(member_since_date, "%Y-%m-%d") + { + let halfprice_startdate = + NaiveDate::from_ymd_opt(Local::now().year(), 7, 1).unwrap(); + member_since_date >= halfprice_startdate + } else { + false + } } else { false }; -- 2.45.2