/*
 * VELOCITY_CHK.pgc - au 모듈 서비스 VELOCITY_CHK (one service = one file).
 * 속도(velocity) 점검: 당일 카드 승인건수/합계.
 * 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 "VELOCITY_CHK.h"

void VELOCITY_CHK(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char card[24], bizdate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_cnt, h_sum;
    char h_card[24], h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_KEY1, card, sizeof(card));
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    strncpy(h_card, card, sizeof(h_card)-1); h_card[sizeof(h_card)-1] = 0;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(*), coalesce(sum(amount),0) INTO :h_cnt, :h_sum
        FROM au_authorization WHERE card_no = :h_card AND biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) FAIL(b);
    setl(b, T_COUNT, h_cnt);
    setl(b, T_GROSS, h_sum);
    setl(b, T_RC, (h_cnt > 10) ? 1 : 0);
    OK(b);
}
