/*
 * PAY_FEEDED.pgc - py 모듈 서비스 PAY_FEEDED (one service = one file).
 * 수수료 공제(fee deduction): bps 로 수수료를 산출해 fee/net 을 재계산·갱신.
 * 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_FEEDED.h"

void PAY_FEEDED(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    long amount, bps, fee, net;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pay, h_fee, h_net;
    EXEC SQL END DECLARE SECTION;
    h_pay = getl(b, T_ID1);
    amount = getl(b, T_AMOUNT);
    bps = getl(b, T_ARG1); if (bps <= 0) bps = 30;
    fee = acq_fee(amount, bps); net = amount - fee;
    h_fee = fee; h_net = net;
    EXEC SQL UPDATE py_payout SET fee = :h_fee, net = :h_net, updated_at = now()
        WHERE payout_id = :h_pay;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) FAIL(b);
    setl(b, T_FEE, fee); setl(b, T_NET, net);
    OK(b);
}
