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

long acdb_refund_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(amount),0) INTO :h_v FROM ac_cancel WHERE biz_date = :h_bizdate AND cancel_type = 'REFUND';
    if (sqlca.sqlcode < 0) { userlog("acdb_refund_sum FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
