account total

This commit is contained in:
thatscringebro
2025-12-10 12:58:45 -05:00
parent d512dedd21
commit e8b3eae889
4 changed files with 28 additions and 4 deletions

View File

@@ -77,6 +77,18 @@ pub fn get_account(con: &Connection, id: i64) -> Account {
}
}
pub fn get_account_total(id: i64, con: &Connection) -> f64 {
let query = "SELECT SUM(amount) as total FROM Transactions WHERE account_id = ?";
let mut statement = con.prepare(query).unwrap();
statement.bind((1, id)).unwrap();
if let Ok(State::Row) = statement.next() {
return statement.read::<f64, _>("total").unwrap();
} else {
return 0.0;
}
}
pub fn get_accounts(con: &Connection) -> Vec<Account> {
let query = "SELECT * FROM Accounts";
let mut statement = con.prepare(query).unwrap();