From ce3bbcd183bcf505b525396db3ba4b9e71c83f55 Mon Sep 17 00:00:00 2001 From: jvech Date: Tue, 30 Apr 2024 07:45:28 -0500 Subject: add: note field implemented --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/database.rs | 17 +++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d492724..e25fb25 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,7 +193,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "debt" -version = "0.1.0" +version = "0.2.0" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 0719f33..f6c417d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "debt" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/database.rs b/src/database.rs index 14f04d9..8752255 100644 --- a/src/database.rs +++ b/src/database.rs @@ -48,7 +48,7 @@ impl Database { pub fn view_history(filepath: &PathBuf, filter: Option) -> Result<()> { let conn = Connection::open(filepath)?; let mut hist_query: String = " - SELECT date(r.register_date, 'auto'), a.name, r.amount + SELECT date(r.register_date, 'auto'), a.name, r.amount, r.note FROM Registers r INNER JOIN Agents a ON a.id = r.agent_id @@ -69,20 +69,21 @@ impl Database { } }; let mut total = 0; - println!("+{:-<10}+{:-<20}+{:-<10}+", "", "", ""); - println!("|{:^10}|{:^20}|{:^10}|", "date", "name", "amount"); - println!("+{:-<10}+{:-<20}+{:-<10}+", "", "", ""); + println!("+{:-<10}+{:-<20}+{:-<10}+{:-<20}+", "", "", "", ""); + println!("|{:^10}|{:^20}|{:^10}|{:^20}|", "date", "name", "amount", "note"); + println!("+{:-<10}+{:-<20}+{:-<10}+{:-<20}+", "", "", "", ""); while let Some(row) = regs.next()? { let date: String = row.get(0)?; let name: String = row.get(1)?; let amount: i32 = row.get(2)?; + let note: Option = row.get(3)?; - println!("|{}|{:>20}|{:>10}|", date, name, amount); + println!("|{}|{:>20}|{:>10}|{:>20}|", date, name, amount, note.unwrap_or("".to_string())); total += amount; } - println!("+{:-<10}+{:-<20}+{:-<10}+", "", "", ""); - println!("|{:^10}{:>32}|", "total", total); - println!("+{:-<10}+{:-<20}+{:-<10}+", "", "", ""); + println!("+{:-<10}+{:-<20}+{:-<10}+{:-<20}+", "", "", "", ""); + println!("|{:^10}|{:>52}|", "total", total); + println!("+{:-<10}+{:-<52}+", "", ""); Ok(()) } -- cgit v1.2.3-70-g09d2