/*
 * cl_snap_gross_dbio.pgc - cl 모듈 DB 접근 함수 (cl_snap_gross_dbio), archived into libcldbio.a.
 * 마감 스냅샷 총매출(gross) 합계.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "cl_snap_gross_dbio.h"

/* 특정 마감 스냅샷의 gross 합. */
long clqdb_snap_gross(long cid)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cid = cid, h_gross = 0;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL SELECT coalesce(sum(gross_amount),0) INTO :h_gross
        FROM cl_snapshot WHERE close_id = :h_cid;
    if (sqlca.sqlcode < 0) { userlog("clqdb_snap_gross FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_gross;
}
