/*
 * CM_FX_CONV.pgc - cm 모듈 서비스 CM_FX_CONV (one service = one file).
 * Split out of the former inline cm_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by cm_svr at tpsvrinit.
 */
#include "CM_FX_CONV.h"

/* 12. CM_FX_CONV - 환율 환산 (cm_fx_rate + compute): 외화 -> 원화. */
void CM_FX_CONV(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char ccy[8], bizdate[16];
    long rate, fx, krw;
    gets_(b, T_CCY, ccy, sizeof(ccy)); if (ccy[0] == 0) strcpy(ccy, "USD");
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    if (bizdate[0] == 0) { if (cmdb_get_param("BIZ_DATE", bizdate) < 0) strcpy(bizdate, "2026-07-19"); }
    fx = getl(b, T_FX_AMT);
    if (cmdb_get_fx_rate(ccy, bizdate, &rate) < 0) FAIL(b);
    krw = fx * rate / 100;         /* rate_bps = KRW*100 per unit */
    setl(b, T_AMOUNT, krw);
    setl(b, T_ARG1, rate);
    OK(b);
}
