/*
 * ST_RECALC.pgc - st 모듈 서비스 ST_RECALC (one service = one file).
 * Moved verbatim from the former inline st_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by st_svr at tpsvrinit.
 */
#include "ST_RECALC.h"

/* 19. ST_RECALC - 매입 수수료 기준 정산 net 재계산 + 갱신. */
void ST_RECALC(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid, h_amount, h_fee, h_net;
    EXEC SQL END DECLARE SECTION;
    h_pid = getl(b, T_PURCHASE_ID);
    EXEC SQL SELECT amount, fee INTO :h_amount, :h_fee FROM purchase WHERE purchase_id = :h_pid;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) FAIL(b);
    h_net = h_amount - h_fee;
    EXEC SQL UPDATE settlement SET net = :h_net WHERE purchase_id = :h_pid;
    if (sqlca.sqlcode < 0) FAIL(b);
    setl(b, T_NET, h_net);
    OK(b);
}

/* vim: set ts=4 sw=4 et smartindent: */
