/*
 * au_capture_query_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_capture_query_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: min AND max in one SELECT, computed range (매입확정 금액 범위).
 */
#include <string.h>
#include <userlog.h>
#include "au_capture_query_dbio.h"

/* 매입확정(M) 승인의 최대-최소 금액 폭. */
long audb_capture_amount_range(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_max = 0, h_min = 0;
    EXEC SQL END DECLARE SECTION;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL SELECT coalesce(max(amount),0), coalesce(min(amount),0)
        INTO :h_max, :h_min FROM au_authorization
        WHERE biz_date = :h_bizdate AND status = 'M';
    if (sqlca.sqlcode < 0) return -1;
    return h_max - h_min;
}
