/*
 * lg_reverse_count_dbio.pgc - lg 모듈 DB 접근 함수 (lg_reverse_count_dbio), archived into liblgdbio.a.
 * 역분개(REVERSE) 전표 건수.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "lg_reverse_count_dbio.h"

/* 당일 역분개(REVERSE) 전표 수. */
long lgqdb_reverse_count(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_cnt = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM lg_voucher
        WHERE biz_date = :h_bizdate AND voucher_type = 'REVERSE';
    if (sqlca.sqlcode < 0) { userlog("lgqdb_reverse_count FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
