/*
 * AUTH_REVERSE.pgc - au 모듈 서비스 AUTH_REVERSE (one service = one file).
 * 승인 역전(reversal) + 한도 원복.
 * 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 "AUTH_REVERSE.h"

void AUTH_REVERSE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char card[24];
    long auth_id = getl(b, T_ID1), amount = getl(b, T_AMOUNT);
    gets_(b, T_KEY1, card, sizeof(card));
    if (audb_update_auth_status(auth_id, "R") < 0) FAIL(b);
    if (card[0] && audb_limit_dec(card, -amount) < 0) FAIL(b);
    Bchg(b, T_STATUS, 0, "R", 0L);
    OK(b);
}
