/*
 * cl_snap_in_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_in_dbio), archived into libcldbio.a.
 * 특정 마감유형에 속한 스냅샷 net 합 (IN 서브셀렉트).
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "cl_snap_in_dbio.h"

/* close_type 에 해당하는 close_id 집합(IN)의 스냅샷 net 합계. */
long clqdb_snap_in_net(const char *ctype)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_type[16];
    long h_v = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_type, ctype, sizeof(h_type)-1); h_type[sizeof(h_type)-1] = 0;
    EXEC SQL SELECT coalesce(sum(net_amount),0) INTO :h_v FROM cl_snapshot
        WHERE close_id IN (SELECT close_id FROM cl_close_log
                           WHERE close_type = :h_type AND status <> 'X');
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
