/*
 * ST_SPLIT.pgc - st 모듈 서비스 ST_SPLIT (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_SPLIT.h"

/* 13. ST_SPLIT - 분할 지급: net 을 n 회로 나눠 지급 레코드 생성 (dbio 루프). */
void ST_SPLIT(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char merch[64], bizdate[16];
    long net = getl(b, T_NET), n = getl(b, T_INSTALL_N), part, i, pay;
    gets_(b, T_MERCHANT, merch, sizeof(merch));
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    if (n < 1) n = 2;
    part = net / n;
    for (i = 0; i < n; i++) {
        pay = stdb_insert_payment(merch, part, bizdate, "SCHEDULED", bizdate);
        if (pay < 0) FAIL(b);
    }
    setl(b, T_COUNT, n);
    OK(b);
}

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