summaryrefslogtreecommitdiff
path: root/src/reports.h
blob: 82c29e54329e307eccfebd31c1213cceecc01c26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef BOKF_REPORTS_H
#define BOKF_REPORTS_H

#include <sqlite3.h>
#include <stdint.h>

#include "yyjson.h"

/* SQL condition: voucher row `r` of voucher `v` on account `a` belongs to the
   opening balance of fiscal year ?4 (org ?1) for a period starting ?2; ?5 is
   the configured IB series. Balance accounts carry all earlier history,
   including earlier years' IB vouchers; P&L accounts restart at the year
   start, so only this year's IB vouchers and movements before ?2 count. */
#define REPORT_IB_ROW_SQL                                                    \
    "((v.series = 'IB' OR v.series = ?5) AND (v.fiscal_year_id = ?4"         \
    " OR (v.date < (SELECT f.start_date FROM fiscal_years f"                 \
    "   WHERE f.org_id = ?1 AND f.id = ?4)"                                  \
    "   AND a.type NOT IN ('revenue','expense'))))"                          \
    " OR (v.series <> 'IB' AND v.series <> ?5 AND v.date < ?2"               \
    " AND (a.type NOT IN ('revenue','expense') OR v.date >="                 \
    " (SELECT f.start_date FROM fiscal_years f"                              \
    "   WHERE f.org_id = ?1 AND f.id = ?4)))"

yyjson_mut_val *report_trial_balance(yyjson_mut_doc *doc, sqlite3 *db,
                                     int64_t org_id, int64_t fy_id,
                                     const char *from, const char *to,
                                     int include_zero, char **err);
yyjson_mut_val *report_income_statement(yyjson_mut_doc *doc, sqlite3 *db,
                                        int64_t org_id, int64_t fy_id,
                                        const char *from, const char *to,
                                        char **err);
yyjson_mut_val *report_balance_sheet(yyjson_mut_doc *doc, sqlite3 *db,
                                     int64_t org_id, int64_t fy_id,
                                     const char *to, char **err);
yyjson_mut_val *report_vat(yyjson_mut_doc *doc, sqlite3 *db, int64_t org_id,
                           const char *from, const char *to, char **err);
yyjson_mut_val *report_general_ledger(yyjson_mut_doc *doc, sqlite3 *db,
                                      int64_t org_id, int64_t fy_id,
                                      const char *from, const char *to,
                                      yyjson_val *accounts, char **err);
yyjson_mut_val *report_voucher_list(yyjson_mut_doc *doc, sqlite3 *db,
                                    int64_t org_id, int64_t fy_id,
                                    const char *series, char **err);
yyjson_mut_val *report_vat_eskd(yyjson_mut_doc *doc, sqlite3 *db,
                                int64_t org_id, const char *from,
                                const char *to, const char *upplysning,
                                char **err);

#endif