/*
 * MM_LIMIT_INQ.pgc - mm 모듈 서비스 MM_LIMIT_INQ (one service = one file).
 * 기능: 가맹점 한도 조회.
 * 기존 인라인 mm_svr.pgc에서 분리; caller의 XA 브랜치에서 실행(EXEC SQL CONNECT 없음).
 * mm_svr가 tpsvrinit에서 이 서비스를 tpadvertise 한다.
 */
#include "MM_LIMIT_INQ.h"

void MM_LIMIT_INQ(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_daily, h_monthly, h_pertxn;
    char h_merch[64];
    EXEC SQL END DECLARE SECTION;
    char merch[64];
    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 daily_limit, monthly_limit, per_txn_limit
        INTO :h_daily, :h_monthly, :h_pertxn FROM mm_limit WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) FAIL(b);
    setl(b, T_AMT1, h_daily); setl(b, T_AMT2, h_monthly); setl(b, T_AMT3, h_pertxn);
    OK(b);
}
