/*
 * py_ledger_type_dbio.pgc - py 모듈 DB 접근 함수 세트 (py_ledger_type_dbio), archived into libpydbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "py_ledger_type_dbio.h"

/* 지정 엔트리 유형의 당일 원장 합계 (entry_type 인자). */
long pydb_ledger_type_total(const char *entry_type, const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_type[16], h_bizdate[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_type, entry_type, sizeof(h_type)-1); h_type[sizeof(h_type)-1] = 0;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT coalesce(sum(amount),0) INTO :h_v FROM py_ledger
        WHERE entry_type = :h_type AND biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("pydb_ledger_type_total FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
