diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-22 19:52:19 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-22 19:52:19 +0200 |
| commit | 6e0e96cfc74b129950002456e21d401dd07e10fd (patch) | |
| tree | cce5c4b86150f6b28abe6d6d558b30d34e621be7 /src/reports.c | |
| parent | 4dee87e83257c81413b29ccb33989e4df109a61c (diff) | |
| download | bokf-6e0e96cfc74b129950002456e21d401dd07e10fd.tar.gz bokf-6e0e96cfc74b129950002456e21d401dd07e10fd.zip | |
reports, sie: carry earlier IB vouchers, restart P&L at year start
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/reports.c')
| -rw-r--r-- | src/reports.c | 16 |
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)" |
