/*
 * lg_dbio.h - lg 모듈 (원장/복식부기) DB 접근 계층 (liblgdbio.a).
 * ECPG (EXEC SQL) functions compiled into a static library and linked into
 * lg_svr and the lg batches. They run on the caller's XA branch/connection
 * (no EXEC SQL CONNECT); sqlca is the shared per-thread ECPG SQLCA.
 * Return convention: 0 = ok, -1 = SQL error (caller may also inspect sqlca).
 */
#ifndef LG_DBIO_H
#define LG_DBIO_H

/* 전표 (voucher) */
long lgdb_next_voucher_id(void);
long lgdb_next_line_id(void);
int  lgdb_insert_voucher(long vid, const char *vtype, long ref_id,
                         const char *status, const char *bizdate, const char *memo);
int  lgdb_update_voucher_status(long vid, const char *status);
int  lgdb_get_voucher_status(long vid, char *out /* >= 2 bytes */);

/* 원장 라인 (ledger_line) - 차변(D)/대변(C) 분개 */
int  lgdb_insert_line(long vid, const char *acct, const char *dc, long amount,
                      const char *merch, const char *bizdate, const char *status);

/* 계정/가맹점 잔액 (balance) */
int  lgdb_recalc_acct_bal(const char *acct, const char *bizdate);
int  lgdb_get_acct_bal(const char *acct, const char *bizdate, long *bal_out);
int  lgdb_upsert_acct_bal(const char *acct, const char *bizdate, long debit, long credit);
int  lgdb_upsert_merch_bal(const char *merch, const char *bizdate);

#endif /* LG_DBIO_H */
