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/sie.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/sie.c')
| -rw-r--r-- | src/sie.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -11,6 +11,7 @@ #include "db.h" #include "ledger.h" #include "log.h" +#include "reports.h" #include "util.h" #include "version.h" @@ -136,24 +137,21 @@ int sie_export_file(sqlite3 *db, int64_t org_id, int64_t fy_id, put_date(f, end); put(f, "\n"); - /* accounts and balances: IB = this year's IB-series voucher(s) plus all - non-IB history before the year; UB = everything through the end; - RES = the year's non-IB movements. */ + /* accounts and balances: IB per REPORT_IB_ROW_SQL, UB = IB plus the + year's non-IB movements, RES = those movements. #IB/#UB are written + for balance accounts only, #RES for P&L accounts only. */ char ib_series[16]; db_setting_copy(db, org_id, "series_ib", "IB", ib_series, sizeof ib_series); if (sqlite3_prepare_v2( db, "SELECT a.number,a.name," - " 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 - r.credit_ore END),0)," - " COALESCE(SUM(CASE WHEN v.date <= ?3" + " COALESCE(SUM(CASE WHEN " REPORT_IB_ROW_SQL " THEN r.debit_ore - r.credit_ore END),0)," " COALESCE(SUM(CASE WHEN v.series <> 'IB' AND v.series <> ?5" " AND v.date >= ?2 AND v.date <= ?3" - " THEN r.debit_ore - r.credit_ore END),0)" + " THEN r.debit_ore - r.credit_ore END),0)," + " a.type IN ('revenue','expense')" " FROM accounts a LEFT JOIN (voucher_rows r JOIN vouchers v" " ON v.org_id=r.org_id AND v.id=r.voucher_id)" " ON r.org_id=a.org_id AND r.account_id=a.id" @@ -173,8 +171,13 @@ int sie_export_file(sqlite3 *db, int64_t org_id, int64_t fy_id, const char *number = (const char *)sqlite3_column_text(st, 0); const char *name = (const char *)sqlite3_column_text(st, 1); int64_t ib = sqlite3_column_int64(st, 2); - int64_t ub = sqlite3_column_int64(st, 3); - int64_t res = sqlite3_column_int64(st, 4); + int64_t res = sqlite3_column_int64(st, 3); + int pl = sqlite3_column_int(st, 4); + int64_t ub = ib + res; + if (pl) + ib = ub = 0; + else + res = 0; put(f, "#KONTO "); put(f, number); put(f, " "); |
