/*
 * st_paynotexists_dbio.pgc - 지급이 없는 정산 가맹점 (st_paynotexists_dbio), libstdbio.a.
 * ECPG; merchant_id+biz_date 2컬럼 상관 NOT EXISTS 로 st_payment 가 없는 st_merch_settle 를 센다.
 */
#include <string.h>
#include <userlog.h>
#include "st_paynotexists_dbio.h"

long stdb_merch_without_payment(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 count(*) INTO :h_v FROM st_merch_settle ms
        WHERE ms.biz_date = :h_bizdate
          AND NOT EXISTS (SELECT 1 FROM st_payment p
                          WHERE p.merchant_id = ms.merchant_id AND p.biz_date = ms.biz_date);
    if (sqlca.sqlcode < 0) { userlog("stdb_merch_without_payment FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); return -1; }
    return h_v;
}
