/*
 * PAY_REJECT.pgc - py 모듈 서비스 PAY_REJECT (one service = one file).
 * 지급 반려: 상태를 반려(J)로 전이하고 반려 사유를 reject_reason 에 기록.
 * Moved verbatim from the former inline py_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by py_svr at tpsvrinit.
 */
#include "PAY_REJECT.h"

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