/*
 * MM_MERCH_ACCT.pgc - mm 모듈 서비스 MM_MERCH_ACCT (one service = one file).
 * 기능: 정산계좌 변경 (직접 UPDATE + 이력).
 * 기존 인라인 mm_svr.pgc에서 분리; caller의 XA 브랜치에서 실행(EXEC SQL CONNECT 없음).
 * mm_svr가 tpsvrinit에서 이 서비스를 tpadvertise 한다.
 */
#include "MM_MERCH_ACCT.h"

void MM_MERCH_ACCT(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char merch[64], acct[64];
    EXEC SQL BEGIN DECLARE SECTION;
    char h_merch[64], h_acct[64];
    EXEC SQL END DECLARE SECTION;
    gets_(b, T_MERCHANT, merch, sizeof(merch));
    gets_(b, T_STR3, acct, sizeof(acct));
    strncpy(h_merch, merch, sizeof(h_merch)-1); h_merch[sizeof(h_merch)-1] = 0;
    strncpy(h_acct,  acct,  sizeof(h_acct)-1);  h_acct[sizeof(h_acct)-1]   = 0;
    EXEC SQL UPDATE mm_merchant_ext SET settle_acct = :h_acct, updated_at = now()
        WHERE merchant_id = :h_merch;
    if (sqlca.sqlcode < 0 || sqlca.sqlcode == 100) FAIL(b);
    if (mmdb_insert_merch_hist(merch, "ACCT", "", acct, "계좌 변경") < 0) FAIL(b);
    OK(b);
}
