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

/* 4. CM_NEXTBIZ - 다음 영업일 (주말 skip=common util + 휴일 skip=cm_holiday). */
void CM_NEXTBIZ(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char in[16], cur[16], nxt[16];
    int hol, guard = 0;
    gets_(b, T_STR1, in, sizeof(in));
    if (in[0] == 0) { if (cmdb_get_param("BIZ_DATE", in) < 0) strcpy(in, "2026-07-19"); }
    strncpy(cur, in, sizeof(cur)-1); cur[sizeof(cur)-1] = 0;
    do {
        if (acq_next_bizday(cur, nxt) < 0) FAIL(b);   /* 주말 건너뜀 */
        strncpy(cur, nxt, sizeof(cur)-1); cur[sizeof(cur)-1] = 0;
        hol = cmdb_is_holiday(nxt);
        if (hol < 0) FAIL(b);
        if (++guard > 30) break;
    } while (hol == 1);                                /* 휴일이면 다시 +1영업일 */
    sets_(b, T_STR3, nxt);
    OK(b);
}
