/*
 * AUTH_DECLINE.pgc - au 모듈 서비스 AUTH_DECLINE (one service = one file).
 * 승인 거절 처리: 거절 사유와 함께 상태 D 로 갱신.
 * 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_DECLINE.h"

void AUTH_DECLINE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char reason[128];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_auth;
    char h_reason[128];
    EXEC SQL END DECLARE SECTION;
    h_auth = getl(b, T_ID1);
    gets_(b, T_REASON, reason, sizeof(reason)); if (reason[0] == 0) strcpy(reason, "DECLINE");
    strncpy(h_reason, reason, sizeof(h_reason)-1); h_reason[sizeof(h_reason)-1] = 0;
    EXEC SQL UPDATE au_authorization SET status = 'D', decline_reason = :h_reason, updated_at = now()
        WHERE auth_id = :h_auth;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) FAIL(b);
    Bchg(b, T_STATUS, 0, "D", 0L);
    OK(b);
}
