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

/* 28. CM_NETTING_CALC - 네팅 계산 (순수 계산): 차변-대변. */
void CM_NETTING_CALC(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    long debit = getl(b, T_AMT1), credit = getl(b, T_AMT2), net;
    net = debit - credit;
    setl(b, T_NET, net);
    setl(b, T_RC, net > 0 ? 1 : (net < 0 ? -1 : 0));   /* 1=수취, -1=지급 */
    OK(b);
}
