/*
 * PAY_REMIT.pgc - py 모듈 서비스 PAY_REMIT (one service = one file).
 * 실지급 송금: 계좌 잔액을 확인해 부족하면 거절, 충분하면 차감 후 상태 P.
 * 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_REMIT.h"

void PAY_REMIT(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char acct[32], st[8];
    long payout_id, net, bal = 0;
    payout_id = getl(b, T_ID1);
    net = getl(b, T_NET);
    gets_(b, T_KEY1, acct, sizeof(acct));
    if (pydb_account_check(acct, st, &bal) < 0) FAIL(b);
    if (bal < net) { setl(b, T_RC, 1); FAIL(b); }
    if (pydb_account_add(acct, -net) < 0) FAIL(b);
    if (pydb_update_status(payout_id, "P") < 0) FAIL(b);
    setl(b, T_RC, 0);
    Bchg(b, T_STATUS, 0, "P", 0L);
    OK(b);
}
