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

void ACQ_EDC(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char merch[64], bizdate[16];
    long amount, bps = 25, fee, net, pid;

    gets_(b, T_MERCHANT, merch, sizeof(merch));
    amount = getl(b, T_AMOUNT);
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    if (acdb_merchant_mdr(merch, &bps) < 0) bps = 25;
    fee = acq_fee(amount, bps); net = amount - fee;
    pid = acdb_next_purchase_id();
    if (pid < 0) FAIL(b);
    if (acdb_insert_purchase(pid, merch, amount, fee, net, "A", "EDC", bizdate) < 0) FAIL(b);
    if (acdb_insert_approval(pid, 1) < 0) FAIL(b);
    setl(b, T_PURCHASE_ID, pid); setl(b, T_FEE, fee); setl(b, T_NET, net);
    OK(b);
}
