/*
 * ACQ_HOLD.pgc - ac 모듈 서비스 ACQ_HOLD (one service = one file).
 * 매입 보류: 접수/대사(A,M) 상태만 보류로 전이, 반영 건수를 T_RC 로.
 * Runs on the caller's XA branch (no EXEC SQL CONNECT). Advertised by ac_svr.
 */
#include "ACQ_HOLD.h"

void ACQ_HOLD(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    EXEC SQL BEGIN DECLARE SECTION;
    long h_pid, h_aff;
    EXEC SQL END DECLARE SECTION;

    h_pid = getl(b, T_PURCHASE_ID);
    /* only an approved(A)/matched(M) purchase may be put on hold */
    EXEC SQL UPDATE purchase SET status = 'H', updated_at = now()
        WHERE purchase_id = :h_pid AND status IN ('A', 'M');
    if (sqlca.sqlcode < 0) { userlog("ACQ_HOLD FAIL [%d] %s", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc); FAIL(b); }
    h_aff = sqlca.sqlerrd[2];
    if (h_aff > 0) Bchg(b, T_STATUS, 0, "H", 0L);
    setl(b, T_RC, h_aff > 0 ? 0 : 1);
    OK(b);
}
