fix(balance): use transactions.date column (not transaction_date)

The schema's transactions table uses `date` (see schema.sql:67), not
`transaction_date`. Compile-checked the column name was correct.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-04-25 16:24:13 -04:00
parent 0381dd48bb
commit 23ff8466c0

View file

@ -129,16 +129,18 @@ fn read_cash_flows(
period_start: &str, period_start: &str,
period_end: &str, period_end: &str,
) -> Result<Vec<(NaiveDate, f64)>, String> { ) -> Result<Vec<(NaiveDate, f64)>, String> {
// NOTE: the transactions table column is `date` (not `transaction_date`).
// See `src-tauri/src/database/schema.sql:67`.
let mut stmt = conn let mut stmt = conn
.prepare( .prepare(
"SELECT t.transaction_date, "SELECT t.date,
ABS(t.amount) AS abs_amount, ABS(t.amount) AS abs_amount,
bat.direction bat.direction
FROM balance_account_transfers bat FROM balance_account_transfers bat
JOIN transactions t ON t.id = bat.transaction_id JOIN transactions t ON t.id = bat.transaction_id
WHERE bat.account_id = ?1 WHERE bat.account_id = ?1
AND t.transaction_date BETWEEN ?2 AND ?3 AND t.date BETWEEN ?2 AND ?3
ORDER BY t.transaction_date", ORDER BY t.date",
) )
.map_err(|e| format!("prepare flows query: {}", e))?; .map_err(|e| format!("prepare flows query: {}", e))?;
@ -146,6 +148,8 @@ fn read_cash_flows(
.query_map( .query_map(
rusqlite::params![account_id, period_start, period_end], rusqlite::params![account_id, period_start, period_end],
|row| { |row| {
// `transactions.date` may come back as String (TEXT) — keep
// the decoder generic enough.
let date_str: String = row.get(0)?; let date_str: String = row.get(0)?;
let amount: f64 = row.get(1)?; let amount: f64 = row.get(1)?;
let direction: String = row.get(2)?; let direction: String = row.get(2)?;