/*
 * ACQ_WHT.pgc - ac 모듈 서비스 ACQ_WHT (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_WHT.h"

void ACQ_WHT(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    long pid, tax, wht_id;
    EXEC SQL BEGIN DECLARE SECTION;
    long e_pid, e_fee;
    EXEC SQL END DECLARE SECTION;
    pid = getl(b, T_PURCHASE_ID);
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    e_pid = pid;
    EXEC SQL SELECT fee INTO :e_fee FROM purchase WHERE purchase_id = :e_pid;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) FAIL(b);
    tax = acq_wht_amt(e_fee, 2200);          /* 22% */
    wht_id = acdb_insert_wht(pid, tax, bizdate);
    if (wht_id < 0) FAIL(b);
    setl(b, T_TAX, tax);
    OK(b);
}
