aboutsummaryrefslogtreecommitdiff
path: root/src/reports.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reports.c')
-rw-r--r--src/reports.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/reports.c b/src/reports.c
index 2ca7e45..d8ed0d2 100644
--- a/src/reports.c
+++ b/src/reports.c
@@ -58,8 +58,8 @@ static yyjson_mut_val *fy_json(yyjson_mut_doc *doc, const struct fy_info *fy)
return o;
}
-/* One row per account with IB and period movements. IB is the series "IB"
- voucher(s) of this fiscal year plus all non-IB history before `from`.
+/* One row per account with IB and period movements; IB as defined by
+ REPORT_IB_ROW_SQL.
Amounts signed: debit positive. */
static yyjson_mut_val *balance_query(yyjson_mut_doc *doc, sqlite3 *db,
int64_t org_id, int64_t fy_id,
@@ -69,19 +69,17 @@ static yyjson_mut_val *balance_query(yyjson_mut_doc *doc, sqlite3 *db,
char ib_series[16];
db_setting_copy(db, org_id, "series_ib", "IB", ib_series,
sizeof ib_series);
- char sql[1280];
+ char sql[2048];
snprintf(sql, sizeof sql,
"SELECT a.number,a.name,a.type,"
" COALESCE(SUM(CASE WHEN v.series <> 'IB' AND v.series <> ?5"
" AND v.date BETWEEN ?2 AND ?3 THEN r.debit_ore END),0),"
" COALESCE(SUM(CASE WHEN v.series <> 'IB' AND v.series <> ?5"
" AND v.date BETWEEN ?2 AND ?3 THEN r.credit_ore END),0),"
- " COALESCE(SUM(CASE WHEN ((v.series = 'IB' OR v.series = ?5)"
- " AND v.fiscal_year_id = ?4) OR (v.series <> 'IB'"
- " AND v.series <> ?5 AND v.date < ?2) THEN r.debit_ore END),0),"
- " COALESCE(SUM(CASE WHEN ((v.series = 'IB' OR v.series = ?5)"
- " AND v.fiscal_year_id = ?4) OR (v.series <> 'IB'"
- " AND v.series <> ?5 AND v.date < ?2) THEN r.credit_ore END),0)"
+ " COALESCE(SUM(CASE WHEN " REPORT_IB_ROW_SQL
+ " THEN r.debit_ore END),0),"
+ " COALESCE(SUM(CASE WHEN " REPORT_IB_ROW_SQL
+ " THEN r.credit_ore END),0)"
" FROM accounts a"
" LEFT JOIN (voucher_rows r JOIN vouchers v"
" ON v.org_id=r.org_id AND v.id=r.voucher_id)"