/*
 * PAY_CANCEL.pgc - py 모듈 서비스 PAY_CANCEL (one service = one file).
 * 지급 취소: 취소 조정(-amount)을 py_adjust 에 기록하고 지급건 상태 C 로 전이.
 * Moved verbatim from the former inline py_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by py_svr at tpsvrinit.
 */
#include "PAY_CANCEL.h"

void PAY_CANCEL(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16], reason[128];
    long payout_id, amt, adj;
    payout_id = getl(b, T_ID1);
    amt = getl(b, T_AMOUNT);
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    gets_(b, T_REASON, reason, sizeof(reason)); if (reason[0] == 0) strcpy(reason, "CANCEL");
    adj = pydb_insert_adjust(payout_id, -amt, reason, bizdate);
    if (adj < 0) FAIL(b);
    if (pydb_update_status(payout_id, "C") < 0) FAIL(b);
    setl(b, T_ADJ, adj);
    Bchg(b, T_STATUS, 0, "C", 0L);
    OK(b);
}
