/*
 * ST_CAP.pgc - st 모듈 서비스 ST_CAP (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_CAP.h"

/* 27. ST_CAP - 수수료 상한 적용: 상한 초과분을 감액 조정 (dbio). */
void ST_CAP(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    long sid = getl(b, T_SETTLE_ID), pid = getl(b, T_PURCHASE_ID);
    long fee = getl(b, T_FEE), cap = getl(b, T_ARG1), over, adj;
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    if (cap <= 0) cap = 100000;                /* 기본 상한 */
    if (fee > cap) {
        over = fee - cap;
        adj = stdb_insert_adjust(sid, pid, -over, "FEE_CAP", bizdate);
        if (adj < 0) FAIL(b);
        setl(b, T_FEE, cap);
        setl(b, T_DELTA, -over);
    } else {
        setl(b, T_DELTA, 0);
    }
    OK(b);
}

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