/*
 * au_auth_incancel_dbio.pgc - au 모듈 DB 접근 함수 세트 (au_auth_incancel_dbio), archived into libaudbio.a.
 * ECPG (EXEC SQL) functions; run on the caller's XA branch. No EXEC SQL CONNECT.
 * Shape: IN 서브셀렉트(내부 WHERE 조건 포함) - 전액취소된 승인 금액 합.
 */
#include <string.h>
#include <userlog.h>
#include "au_auth_incancel_dbio.h"

/* 전액취소(FULL) 이력이 있는 승인들의 원승인 금액 합계. */
long audb_fullcancelled_auth_amount(const char *bizdate)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_v = 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(sum(amount),0) INTO :h_v FROM au_authorization
        WHERE biz_date = :h_bizdate
          AND auth_id IN (SELECT auth_id FROM au_cancel WHERE cancel_type = 'FULL');
    if (sqlca.sqlcode < 0) return -1;
    return h_v;
}
