/*
 * PAY_XFERLINK.pgc - py 모듈 서비스 PAY_XFERLINK (one service = one file).
 * 이체 연계: 지급건에 대한 XFER 원장 엔트리를 py_ledger 에 기록.
 * 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_XFERLINK.h"

void PAY_XFERLINK(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pay, h_amt;
    char h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    h_pay = getl(b, T_ID1); h_amt = getl(b, T_AMOUNT);
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL INSERT INTO py_ledger (ledger_id, payout_id, entry_type, amount, biz_date)
        VALUES (nextval('py_ledger_seq'), :h_pay, 'XFER', :h_amt, :h_bizdate);
    if (sqlca.sqlcode < 0) FAIL(b);
    OK(b);
}
