/*
 * PAY_CLOSE.pgc - py 모듈 서비스 PAY_CLOSE (one service = one file).
 * 일마감: 당일 지급완료(P)건을 마감(X)으로 일괄 전환하고 전환 건수를 회신.
 * 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_CLOSE.h"

void PAY_CLOSE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char bizdate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    char h_bizdate[16];
    long h_cnt;
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    EXEC SQL UPDATE py_payout SET status = 'X', updated_at = now()
        WHERE biz_date = :h_bizdate AND status = 'P';
    if (sqlca.sqlcode < 0) FAIL(b);
    h_cnt = sqlca.sqlerrd[2];
    setl(b, T_COUNT, h_cnt);
    OK(b);
}
