/*
 * lg_fee_income_dbio.pgc - lg 모듈 DB 접근 함수 (lg_fee_income_dbio), archived into liblgdbio.a.
 * 수수료수익(FEE_INC) 계정 대변 누계.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "lg_fee_income_dbio.h"

/* FEE_INC 계정의 당일 대변 누계 (수수료 수익). */
long lgqdb_fee_income(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_fee = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT coalesce(sum(amount),0) INTO :h_fee FROM lg_ledger_line
        WHERE acct = 'FEE_INC' AND dc = 'C' AND biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("lgqdb_fee_income FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_fee;
}
