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

/* 4. RC_RETURN - 반품 대사: 반품 원장 + 음수 대사 로그. */
void RC_RETURN(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    long pid = getl(b, T_PURCHASE_ID), amt = getl(b, T_AMOUNT), mid;
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    if (rcdb_insert_ledger(pid, "RETURN", -amt, bizdate) < 0) FAIL(b);
    mid = rcdb_insert_match(pid, "RETURN", -amt, "MATCHED", bizdate);
    if (mid < 0) FAIL(b);
    setl(b, T_ID1, mid);
    OK(b);
}

/* vim: set ts=4 sw=4 et smartindent: */
