better ac list
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user