/*
 * vl_balance_dbio.pgc - 가맹점 매입 순액 합계 (정산완료) (libvldbio.a).
 * ECPG functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 */
#include <string.h>
#include <userlog.h>
#include "vl_balance_dbio.h"

long vldb_merch_net(const char *merch, const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    long h_net; char h_merch[64], h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT coalesce(sum(net),0) INTO :h_net FROM purchase
        WHERE merchant_id = :h_merch AND biz_date = :h_bizdate AND status = 'S';
    if (sqlca.sqlcode < 0) { userlog("vldb_merch_net FAIL [%d]", sqlca.sqlcode); return -1; }
    return h_net;
}
