/*
 * cl_unclosed_days_dbio.pgc - cl 모듈 DB 접근 함수 (cl_unclosed_days_dbio), archived into libcldbio.a.
 * 일마감 누락 영업일 수.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "cl_unclosed_days_dbio.h"

/* DAILY 마감이 없는 매입 영업일 수. */
long clqdb_unclosed_days(void)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT count(DISTINCT p.biz_date) INTO :h_cnt FROM purchase p
        WHERE NOT EXISTS (SELECT 1 FROM cl_close_log c
            WHERE c.close_type = 'DAILY' AND c.biz_date = p.biz_date AND c.status <> 'X');
    if (sqlca.sqlcode < 0) { userlog("clqdb_unclosed_days FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_cnt;
}
