/*
 * CM_PRORATE.pgc - cm 모듈 서비스 CM_PRORATE (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_PRORATE.h"

/* 27. CM_PRORATE - 일할 계산 (순수 계산): 금액*사용일/총일. */
void CM_PRORATE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    long amt = getl(b, T_AMOUNT), used = getl(b, T_ARG1), total = getl(b, T_ARG2), pro;
    if (total <= 0) FAIL(b);
    if (used < 0) used = 0;
    if (used > total) used = total;
    pro = amt * used / total;
    setl(b, T_AMT1, pro);
    OK(b);
}
