diff options
Diffstat (limited to 'src/reports.c')
| -rw-r--r-- | src/reports.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/reports.c b/src/reports.c index 0316abf..96b1344 100644 --- a/src/reports.c +++ b/src/reports.c @@ -58,12 +58,12 @@ 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`. - skip_closings drops the source system's "Stäng ..." closing vouchers from - the period movements (imported years close the P&L accounts straight to - 2099, so the year otherwise nets to zero); the K2 report and the SRU - export use the same convention. Amounts signed: debit positive. */ +/* One row per account with IB and period movements; IB as defined by + REPORT_IB_ROW_SQL. skip_closings drops the source system's "Stäng ..." + closing vouchers (SIE-imported only) from the period movements: imported + years close the P&L accounts straight to 2099, so the year otherwise nets + to zero; the TUI årsredovisning uses the same convention. Amounts signed: + debit positive. */ static yyjson_mut_val *balance_query(yyjson_mut_doc *doc, sqlite3 *db, int64_t org_id, int64_t fy_id, const char *from, const char *to, @@ -73,21 +73,21 @@ 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 (COALESCE(v.description,'') NOT LIKE 'Stäng%%' OR ?6 = 0)" + " AND (?6 = 0 OR v.source <> 'sie_import'" + " OR COALESCE(v.description,'') NOT LIKE 'Stäng%%')" " 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 (COALESCE(v.description,'') NOT LIKE 'Stäng%%' OR ?6 = 0)" + " AND (?6 = 0 OR v.source <> 'sie_import'" + " OR COALESCE(v.description,'') NOT LIKE 'Stäng%%')" " 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)" |
