/*
 * PAY_SCHEDULE.pgc - py 모듈 서비스 PAY_SCHEDULE (one service = one file).
 * 지급 예약 등록: 지정 실행일로 py_schedule 예약(S) 레코드를 생성.
 * 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_SCHEDULE.h"

void PAY_SCHEDULE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char rundate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    long h_id, h_pay;
    char h_rundate[16];
    EXEC SQL END DECLARE SECTION;
    h_pay = getl(b, T_ID1);
    gets_(b, T_BIZDATE, rundate, sizeof(rundate));
    strncpy(h_rundate, rundate, sizeof(h_rundate)-1); h_rundate[sizeof(h_rundate)-1] = 0;
    EXEC SQL SELECT nextval('py_schedule_seq') INTO :h_id;
    if (sqlca.sqlcode < 0) FAIL(b);
    EXEC SQL INSERT INTO py_schedule (schedule_id, payout_id, run_date, status)
        VALUES (:h_id, :h_pay, :h_rundate, 'S');
    if (sqlca.sqlcode < 0) FAIL(b);
    setl(b, T_ID2, h_id);
    OK(b);
}
