/*
 * st_dtlfeesum_dbio.pgc - st 모듈 DB 접근 함수 세트 (st_dtlfeesum_dbio), archived into libstdbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * 수수료 종류별 정산 상세 금액 합계.
 */
#include <string.h>
#include <userlog.h>
#include "st_dtlfeesum_dbio.h"

long stdb_dtl_fee_sum(const char *bizdate, const char *fee_type)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16], h_type[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;
    strncpy(h_type, fee_type, sizeof(h_type)-1); h_type[sizeof(h_type)-1] = 0;
    EXEC SQL SELECT coalesce(sum(amount),0) INTO :h_v FROM st_settle_dtl
        WHERE biz_date = :h_bizdate AND fee_type = :h_type;
    if (sqlca.sqlcode < 0) { userlog("stdb_dtl_fee_sum FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
