create fee reminder mail
All checks were successful
CI/CD Pipeline / test (push) Successful in 9m10s
CI/CD Pipeline / deploy-staging (push) Successful in 4m7s
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
philipp 2024-01-19 11:19:24 +01:00
parent 578e3df9e9
commit 0ed740ec47
2 changed files with 106 additions and 2 deletions

View File

@ -12,7 +12,7 @@ use sqlx::SqlitePool;
use crate::tera::admin::mail::MailToSend; use crate::tera::admin::mail::MailToSend;
use super::role::Role; use super::{family::Family, role::Role, user::User};
pub struct Mail {} pub struct Mail {}
@ -62,4 +62,97 @@ impl Mail {
}; };
false false
} }
pub async fn fees(db: &SqlitePool, smtp_pw: String) {
let users = User::all_payer_groups(db).await;
for user in users {
if user.has_role(db, "paid").await {
if user.name == "Philipp Hofer" {
let mut is_family = false;
let mut send_to = String::new();
match Family::find_by_opt_id(db, user.family_id).await {
Some(family) => {
is_family = true;
for member in family.members(db).await {
if let Some(mail) = member.mail {
send_to.push_str(&format!("{mail},"))
}
}
}
None => {
if let Some(mail) = &user.mail {
send_to.push_str(&mail)
}
}
}
let fees = user.fee(db).await;
if let Some(fees) = fees {
let mut content = format!(
"Liebes Vereinsmitglied, \n\
\n
dein Vereinsbeitrag für das aktuelle Jahr beträgt {}",
fees.sum_in_cents / 100,
);
if fees.parts.len() == 1 {
content.push_str(&format!(" ({}).\n", fees.parts[0].0))
} else {
content
.push_str(". Dieser setzt sich aus folgenden Teilen zusammen: \n");
for (desc, fee_in_cents) in fees.parts {
content.push_str(&format!("- {}: {}\n", desc, fee_in_cents / 100))
}
}
if is_family {
content.push_str(&format!(
"Dieser gilt für die gesamte Familie ({}).\n",
fees.name
))
}
content.push_str("\n Bitte überweise diesen auf folgendes Konto: IBAN: AT13 1200 0804 1300 1200. Auf https://app.rudernlinz.at/planned findest du einen QR Code, den du mit deiner Bankapp scannen kannst um alle Eingaben bereits ausgefüllt zu haben.\n\n\
Falls die Berechnung nicht stimmt (korrekte Preise findest du unter https://rudernlinz.at/unser-verein/gebuhren/) melde dich bitte an it@rudernlinz.at. @Studenten: Bitte Bestätigung an it@rudernlinz.at schicken.\n\n\
Beste Grüße\n\
Der Vorstand
");
let mut email = Message::builder()
.from(
"ASKÖ Ruderverein Donau Linz <no-reply@rudernlinz.at>"
.parse()
.unwrap(),
)
.reply_to(
"ASKÖ Ruderverein Donau Linz <it@rudernlinz.at>"
.parse()
.unwrap(),
)
.to("ASKÖ Ruderverein Donau Linz <no-reply@rudernlinz.at>"
.parse()
.unwrap());
let splitted = send_to.split(',');
for single_rec in splitted {
email = email.bcc(single_rec.parse().unwrap());
}
let email = email
.subject("ASKÖ Ruderverein Donau Linz | Vereinsgebühren")
.header(ContentType::TEXT_PLAIN)
.body(content)
.unwrap();
let creds =
Credentials::new("no-reply@rudernlinz.at".to_owned(), smtp_pw.clone());
let mailer = SmtpTransport::relay("mail.your-server.de")
.unwrap()
.credentials(creds)
.build();
// Send the email
mailer.send(&email).unwrap();
}
}
}
}
}
} }

View File

@ -33,6 +33,17 @@ async fn index(
Template::render("admin/mail", context.into_json()) Template::render("admin/mail", context.into_json())
} }
#[get("/mail/fee")]
async fn fee(
db: &State<SqlitePool>,
admin: AdminUser,
config: &State<Config>,
flash: Option<FlashMessage<'_>>,
) -> &'static str {
Mail::fees(db, config.smtp_pw.clone()).await;
"SUCC"
}
#[derive(FromForm, Debug)] #[derive(FromForm, Debug)]
pub struct MailToSend<'a> { pub struct MailToSend<'a> {
pub(crate) role_id: i32, pub(crate) role_id: i32,
@ -57,7 +68,7 @@ async fn update(
} }
pub fn routes() -> Vec<Route> { pub fn routes() -> Vec<Route> {
routes![index, update] routes![index, update, fee]
} }
#[cfg(test)] #[cfg(test)]