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

/* 2-테이블 JOIN: 생성(G)된 파일에 편성된 지급건의 순액 합. */
long pydb_payout_filed_net(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(pp.net),0) INTO :h_v
        FROM py_payout pp JOIN py_file pf ON pp.file_id = pf.file_id
        WHERE pf.biz_date = :h_bizdate AND pf.status = 'G';
    if (sqlca.sqlcode < 0) { userlog("pydb_payout_filed_net FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
