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

/* 30. ST_STATUS - 정산 상태 조회. */
void ST_STATUS(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid;
    char h_status[16];
    EXEC SQL END DECLARE SECTION;
    h_pid = getl(b, T_PURCHASE_ID);
    EXEC SQL SELECT status INTO :h_status FROM settlement
        WHERE purchase_id = :h_pid ORDER BY settlement_id DESC LIMIT 1;
    if (sqlca.sqlcode < 0) FAIL(b);
    if (sqlca.sqlcode == 100) strcpy(h_status, "NONE");
    Bchg(b, T_STATUS, 0, h_status, 0L);
    OK(b);
}

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