/*
 * LIMIT_CHK.pgc - au 모듈 서비스 LIMIT_CHK (one service = one file).
 * 카드 한도 점검 (사용가능 여부만 리턴).
 * Moved verbatim from the former inline au_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by au_svr at tpsvrinit.
 */
#include "LIMIT_CHK.h"

void LIMIT_CHK(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char card[24];
    long amount, lim = 0, used = 0;
    gets_(b, T_KEY1, card, sizeof(card));
    amount = getl(b, T_AMOUNT);
    if (audb_limit_get(card, &lim, &used) < 0) FAIL(b);
    setl(b, T_AMT1, lim);
    setl(b, T_AMT2, used);
    setl(b, T_RC, (used + amount > lim) ? 1 : 0);
    OK(b);
}
