/*
 * PAY_HISTORY.pgc - py 모듈 서비스 PAY_HISTORY (one service = one file).
 * 가맹점 지급 이력 건수: 해당 가맹점의 전체 지급건 수를 집계해 회신.
 * Moved verbatim from the former inline py_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by py_svr at tpsvrinit.
 */
#include "PAY_HISTORY.h"

void PAY_HISTORY(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char merch[64];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt;
    char h_merch[64];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_MERCHANT, merch, sizeof(merch));
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_cnt FROM py_payout WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0) FAIL(b);
    setl(b, T_COUNT, h_cnt);
    OK(b);
}
