/*
 * st_netsum_dbio.pgc - st 모듈 DB 접근 함수 세트 (st_netsum_dbio), archived into libstdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 당일 정산 net 단순 합계.
 */
#include <string.h>
#include <userlog.h>
#include "st_netsum_dbio.h"

long stdb_settle_net_sum(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_v = 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(net),0) INTO :h_v FROM settlement WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) { userlog("stdb_settle_net_sum FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
