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

/* 14. ST_PAYDATE - 지급일 산정(익영업일) 후 지급일 갱신. */
void ST_PAYDATE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char merch[64], bizdate[16], paydate[16];
    EXEC SQL BEGIN DECLARE SECTION;
    char h_merch[64], h_bizdate[16], h_paydate[16];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_MERCHANT, merch, sizeof(merch));
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    if (acq_next_bizday(bizdate, paydate) < 0) FAIL(b);
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    strncpy(h_bizdate, bizdate, sizeof(h_bizdate)-1); h_bizdate[sizeof(h_bizdate)-1] = 0;
    strncpy(h_paydate, paydate, sizeof(h_paydate)-1); h_paydate[sizeof(h_paydate)-1] = 0;
    EXEC SQL UPDATE st_payment SET pay_date = :h_paydate
        WHERE merchant_id = :h_merch AND biz_date = :h_bizdate AND status = 'SCHEDULED';
    if (sqlca.sqlcode < 0) FAIL(b);
    Bchg(b, T_KEY1, 0, paydate, 0L);
    OK(b);
}

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