/*
 * RC_TOLERANCE.pgc - rc 모듈 서비스 RC_TOLERANCE (one service = one file).
 * Moved verbatim from the former inline rc_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by rc_svr at tpsvrinit.
 */
#include "RC_TOLERANCE.h"

/* 8. RC_TOLERANCE - 허용오차 대사: |차이| <= 허용치면 MATCHED. */
void RC_TOLERANCE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    long pid, tol, diff, adiff, mid;
    pid = getl(b, T_PURCHASE_ID);
    diff = getl(b, T_DELTA);
    tol = getl(b, T_ARG1); if (tol <= 0) tol = 100;   /* 기본 허용치 100원 */
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    adiff = diff < 0 ? -diff : diff;
    mid = rcdb_insert_match(pid, "TOLERANCE", diff,
                            (adiff <= tol) ? "MATCHED" : "EXCEPTION", bizdate);
    if (mid < 0) FAIL(b);
    setl(b, T_RC, (adiff <= tol) ? 0 : 1);
    OK(b);
}

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