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

void ACQ_VOID(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_id, h_pid, h_amt;
    char h_bizdate[16];
    EXEC SQL END DECLARE SECTION;
    h_pid = getl(b, T_PURCHASE_ID); h_amt = getl(b, T_AMOUNT);
    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 nextval('ac_cancel_seq') INTO :h_id;
    if (sqlca.sqlcode < 0) FAIL(b);
    EXEC SQL INSERT INTO ac_cancel (cancel_id, purchase_id, cancel_type, amount, reason, biz_date)
        VALUES (:h_id, :h_pid, 'VOID', :h_amt, 'VOID', :h_bizdate);
    if (sqlca.sqlcode < 0) FAIL(b);
    if (acdb_update_status(h_pid, "V") < 0) FAIL(b);
    setl(b, T_CANCEL_ID, h_id);
    Bchg(b, T_STATUS, 0, "V", 0L);
    OK(b);
}
