diff options
author | jvech <jmvalenciae@unal.edu.co> | 2024-04-30 07:45:28 -0500 |
---|---|---|
committer | jvech <jmvalenciae@unal.edu.co> | 2024-04-30 07:45:28 -0500 |
commit | ce3bbcd183bcf505b525396db3ba4b9e71c83f55 (patch) | |
tree | e4987cf3f390c783c8ce269e112eaaf70331b988 | |
parent | a361eb833f516befe79b45a8b6ed3162a21bc06a (diff) |
add: note field implemented
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/database.rs | 17 |
3 files changed, 11 insertions, 10 deletions
@@ -193,7 +193,7 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "debt" -version = "0.1.0" +version = "0.2.0" dependencies = [ "chrono", "clap", @@ -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<String>) -> 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<String> = 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(()) } |