/*
 * PAY_INQUIRY.pgc - py 모듈 서비스 PAY_INQUIRY (one service = one file).
 * 지급 단건 상세 조회: 가맹점/계좌/금액/수수료/순액/상태를 한 번에 회신.
 * 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_INQUIRY.h"

void PAY_INQUIRY(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char merch[64], acct[32], st[8];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pay, h_amt, h_fee, h_net;
    char h_merch[64], h_acct[32], h_status[8];
    EXEC SQL END DECLARE SECTION;
    h_pay = getl(b, T_ID1);
    EXEC SQL SELECT merchant_id, account_no, amount, fee, net, status
        INTO :h_merch, :h_acct, :h_amt, :h_fee, :h_net, :h_status
        FROM py_payout WHERE payout_id = :h_pay;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) FAIL(b);
    strncpy(merch, h_merch, sizeof(merch)-1); merch[sizeof(merch)-1] = 0;
    strncpy(acct, h_acct, sizeof(acct)-1); acct[sizeof(acct)-1] = 0;
    strncpy(st, h_status, sizeof(st)-1); st[sizeof(st)-1] = 0;
    Bchg(b, T_MERCHANT, 0, merch, 0L);
    Bchg(b, T_KEY1, 0, acct, 0L);
    Bchg(b, T_STATUS, 0, st, 0L);
    setl(b, T_AMOUNT, h_amt);
    setl(b, T_FEE, h_fee);
    setl(b, T_NET, h_net);
    OK(b);
}
