/*
 * AUTH_CAPTURE.pgc - au 모듈 서비스 AUTH_CAPTURE (one service = one file).
 * 승인 매입확정(capture): 상태 A->M(매입대상).
 * 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_CAPTURE.h"

void AUTH_CAPTURE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_auth;
    EXEC SQL END DECLARE SECTION;
    h_auth = getl(b, T_ID1);
    EXEC SQL UPDATE au_authorization SET status = 'M', captured_at = now(), updated_at = now()
        WHERE auth_id = :h_auth AND status = 'A';
    if (sqlca.sqlcode < 0) FAIL(b);
    if (sqlca.sqlcode == 100) { setl(b, T_RC, 1); FAIL(b); }
    setl(b, T_RC, 0);
    Bchg(b, T_STATUS, 0, "M", 0L);
    OK(b);
}
