diff options
Diffstat (limited to 'src/banking/account.rs')
| -rw-r--r-- | src/banking/account.rs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/banking/account.rs b/src/banking/account.rs new file mode 100644 index 0000000..6994bb4 --- /dev/null +++ b/src/banking/account.rs @@ -0,0 +1,77 @@ +use parsers::csv::CsvFile; + +pub struct Account { + pub name : String, + pub iban : String, + pub transactions : Vec<Transaction>, + pub institute : String +} + +impl Account { + pub fn new(name : String, iban : String, transactions : Vec<String>, institute : String) -> Account { + let mut trans = Vec::new(); + if institute == "Sparkasse" { + // TODO als function/lambda übergeben die konvertierung.. + for trans_file in transactions { + let file = CsvFile::from_file(&trans_file, ";", true); + match file { + Ok(f) => { let mut tran = Transaction::from_sparkasse_csv_file(f); + trans.append(&mut tran); + }, + Err(e) => panic!("account: new: error reading csv transaction file: {}", e) + } + } + } + Account { name : name, iban : iban, transactions : trans, institute : institute } + } +} + +#[derive(Serialize)] +#[derive(Clone)] +pub struct Transaction { + pub sender_name : String, + pub amount : f32, + pub reference : String, + pub date : chrono::NaiveDate +} + +impl Transaction { + pub fn from_sparkasse_csv_file(file : CsvFile) -> Vec<Transaction> { + let mut ret = Vec::new(); + for line in file.iter() { + let mut sender_name_f = String::from(""); + let mut sender_iban_f = String::from(""); + let mut amount_f : f32 = 0.0; + let mut reference_f = String::from(""); + let mut date_f = chrono::NaiveDate::parse_from_str("01.01.2019", "%d.%m.%Y").unwrap(); + match line.get(&String::from("Kontonummer")) { + Some(value) => sender_iban_f = value.to_string(), + None => println!("missing sender") + } + match line.get(&String::from("Beguenstigter/Zahlungspflichtiger")) { + Some(value) => sender_name_f = value.to_string(), + None => println!("missing sender") + } + match line.get(&String::from("Verwendungszweck")) { + Some(value) => reference_f = value.to_string(), + None => println!("missing refernce") + } + match line.get(&String::from("Betrag")) { + Some(value) => amount_f = value.parse().unwrap(), + None => println!("missing amount") + } + match line.get(&String::from("Valutadatum")) { + Some(value) => { + date_f = chrono::NaiveDate::parse_from_str(value, "%d.%m.%y").unwrap();} , + None => println!("missing date") + } + ret.push(Transaction { + sender_name : sender_name_f, + amount : amount_f, + reference : reference_f, + date : date_f }); + + } + ret + } +} |
