1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
use parsers::csv::CsvFile;
pub struct Account {
name : String,
iban : String,
transactions : Vec<Transaction>
}
#[derive(Serialize)]
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
}
}
|