better ac list

This commit is contained in:
thatscringebro
2025-12-17 13:49:31 -05:00
parent 33fb39e732
commit dd6b6f7b2c
4 changed files with 55 additions and 5 deletions

View File

@@ -78,9 +78,16 @@ 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 query = "SELECT SUM(amount) as total FROM Transactions".to_owned();
if id != 0 {
query.push_str("WHERE account_id = ?")
}
let mut statement = con.prepare(query).unwrap();
statement.bind((1, id)).unwrap();
if id != 0 {
statement.bind((1, id)).unwrap();
}
if let Ok(State::Row) = statement.next() {
return statement.read::<f64, _>("total").unwrap();
@@ -227,6 +234,10 @@ pub fn get_transaction(con: &Connection, id: i64) -> Transaction {
}
pub fn get_account_transactions(con: &Connection, ac_id: i64) -> Vec<Transaction> {
if ac_id == 0 {
return get_transactions(con);
}
let query = "SELECT * FROM Transactions WHERE account_id = ?";
let mut statement = con.prepare(query).unwrap();
statement.bind((1, ac_id)).unwrap();