/*
 * ac_dbio.h - ac 모듈 DB 접근 계층 (libacdbio.a).
 * These are ECPG (EXEC SQL) functions compiled into a static library and linked
 * into ac_svr and the ac 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 AC_DBIO_H
#define AC_DBIO_H

/* purchase */
long acdb_next_purchase_id(void);
int  acdb_insert_purchase(long pid, const char *merch, long amount, long fee,
                          long net, const char *status, const char *channel,
                          const char *bizdate);
int  acdb_update_status(long pid, const char *status);
int  acdb_get_status(long pid, char *out /* >= 2 bytes */);
int  acdb_update_amount(long pid, long amount, long fee, long net);
int  acdb_insert_approval(long pid, int approved);

/* fee / tax */
long acdb_insert_fee_adj(long pid, long delta, const char *reason, const char *bizdate);
long acdb_insert_wht(long pid, long tax, const char *bizdate);
long acdb_insert_tax_invoice(long pid, const char *merch, long supply, long vat,
                             const char *bizdate);

/* merchant */
int  acdb_merchant_mdr(const char *merch, long *bps_out);
int  acdb_upsert_merch_sum(const char *merch, const char *bizdate, long gross,
                           long fee, long net, long cnt);

/* misc ledger */
long acdb_insert_ledger(long pid, const char *type, long amount, const char *bizdate);

#endif /* AC_DBIO_H */
