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

/* 9. CM_AMT_SPLIT - 금액 균등 분할 (순수 계산): n등분 + 잔액. */
void CM_AMT_SPLIT(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    long amt = getl(b, T_AMOUNT), n = getl(b, T_ARG1), each, rem;
    if (n < 1) n = 1;
    each = amt / n;
    rem = amt - each * n;          /* 첫 회차에 잔액 가산 */
    setl(b, T_AMT1, each);
    setl(b, T_AMT2, rem);
    setl(b, T_COUNT, n);
    OK(b);
}
