/*
 * RC_PROGRESS.pgc - rc 모듈 서비스 RC_PROGRESS (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_PROGRESS.h"

/* 21. RC_PROGRESS - 진행률(%) = MATCHED / 전체매입 * 100. */
void RC_PROGRESS(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_total, h_matched;
    char h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT count(*) INTO :h_total FROM purchase WHERE biz_date = :h_bizdate;
    if (sqlca.sqlcode < 0) FAIL(b);
    EXEC SQL SELECT count(*) INTO :h_matched FROM rc_match_log
        WHERE biz_date = :h_bizdate AND status = 'MATCHED';
    if (sqlca.sqlcode < 0) FAIL(b);
    setl(b, T_RC, h_total > 0 ? (h_matched * 100 / h_total) : 0);
    OK(b);
}

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