/*
 * STANDIN.pgc - au 모듈 서비스 STANDIN (one service = one file).
 * 발급사 무응답 시 대리승인(STANDIN, 소액 한도 내).
 * 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 "STANDIN.h"

void STANDIN(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char card[24], merch[64], bizdate[16];
    long amount, auth_id, stand_lim = 50000;
    gets_(b, T_KEY1, card, sizeof(card));
    gets_(b, T_MERCHANT, merch, sizeof(merch));
    amount = getl(b, T_AMOUNT);
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    if (amount > stand_lim) { setl(b, T_RC, 1); Bchg(b, T_STATUS, 0, "D", 0L); OK(b); }
    auth_id = audb_next_auth_id();
    if (auth_id < 0) FAIL(b);
    if (audb_insert_auth(auth_id, card, merch, amount, "STDIN0", "STANDIN", "A", bizdate) < 0) FAIL(b);
    setl(b, T_ID1, auth_id);
    setl(b, T_RC, 0);
    Bchg(b, T_STATUS, 0, "A", 0L);
    OK(b);
}
