summaryrefslogtreecommitdiff
path: root/src/sie.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sie.c')
-rw-r--r--src/sie.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/sie.c b/src/sie.c
index ba4c1a8..6e0eab4 100644
--- a/src/sie.c
+++ b/src/sie.c
@@ -8,6 +8,7 @@
#include <string.h>
#include <time.h>
+#include "db.h"
#include "ledger.h"
#include "log.h"
#include "util.h"
@@ -135,18 +136,22 @@ 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 series "IB" voucher(s) plus
- all non-IB history before the year; UB = everything through the end;
+ /* 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. */
+ 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'"
+ " COALESCE(SUM(CASE WHEN ((v.series = 'IB' OR v.series = ?5)"
" AND v.fiscal_year_id = ?4) OR (v.series <> 'IB'"
- " AND v.date < ?2) THEN r.debit_ore - r.credit_ore END),0),"
+ " AND v.series <> ?5 AND v.date < ?2)"
+ " THEN r.debit_ore - r.credit_ore END),0),"
" COALESCE(SUM(CASE WHEN v.date <= ?3"
" THEN r.debit_ore - r.credit_ore END),0),"
- " COALESCE(SUM(CASE WHEN v.series <> 'IB'"
+ " 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)"
" FROM accounts a LEFT JOIN (voucher_rows r JOIN vouchers v"
@@ -163,6 +168,7 @@ int sie_export_file(sqlite3 *db, int64_t org_id, int64_t fy_id,
sqlite3_bind_text(st, 2, start, -1, SQLITE_TRANSIENT);
sqlite3_bind_text(st, 3, end, -1, SQLITE_TRANSIENT);
sqlite3_bind_int64(st, 4, fy_id);
+ sqlite3_bind_text(st, 5, ib_series, -1, SQLITE_TRANSIENT);
while (sqlite3_step(st) == SQLITE_ROW) {
const char *number = (const char *)sqlite3_column_text(st, 0);
const char *name = (const char *)sqlite3_column_text(st, 1);