/* @tier easy @module lg @transform ledger-online */ /* * lg_ol_0032.pgc - 원장 온라인 서비스 (LG_OL_0032) [tier=easy] * * 정산원장 대사: 지정 영업일의 정산완료(S) Σamount 와 처리완료(M) Σamount 를 * 비교하여 미정산 차액(=M합계, 아직 정산되지 않은 금액)을 응답한다. (조회 전용) */ #include #include #include "txcore.h" #include "txcore_dbio.h" #include "acq_util.h" #include "lg_core.h" EXEC SQL INCLUDE sqlca; /* * [업무 개요] * 정산 마감 전, 특정 영업일 원장에서 이미 정산확정(S) 된 금액과 아직 * 정산되지 않은 처리완료(M) 금액을 대사(對査) 하여, 당일 정산 진행 상태를 * 점검한다. 미정산 금액이 0 이면 당일 정산이 완결된 것으로 본다. * * [대사 산식] * SETTLEDSUM = Σ amount (status='S') 정산확정 합계 * DONESUM = Σ amount (status='M') 미정산(처리완료) 합계 * UNSETTLED = DONESUM 아직 정산 안 된 금액 * BALANCED = (UNSETTLED == 0) ? "Y" : "N" * * [처리 절차] * 1) BIZDATE 추출 및 형식 검증. * 2) 정산확정(S) 합계 집계 SELECT. * 3) 처리완료(M) 합계 집계 SELECT. * 4) 미정산 차액과 균형 여부를 응답. * * [응답 필드] * RESPCODE 처리결과코드 * BIZDATE 대상 영업일(에코) * SETTLEDSUM 정산확정(S) 합계 * DONESUM 처리완료(M) 합계 * UNSETTLED 미정산 차액 * UNSETTLEDWON 미정산 원화표기 * BALANCED 정산완결 여부 Y/N * * [주의] * 조회/대사 전용. 원장을 변경하지 않으며 집계 결과는 coalesce 로 0 보장. */ TX_SERVICE(LG_OL_0032, ctx) { EXEC SQL BEGIN DECLARE SECTION; char h_biz_date[9]; char h_status_s[2]; char h_status_m[2]; long h_settled_sum; long h_done_sum; EXEC SQL END DECLARE SECTION; char bizdate[16]; char wonbuf[32]; long unsettled; tx_log(TX_LOG_INFO, "[LG_OL_0032] 정산원장 대사 진입"); if (tx_buf_get(ctx->in, "BIZDATE", bizdate, sizeof(bizdate)) != TX_OK) { tx_log(TX_LOG_ERROR, "[LG_OL_0032] BIZDATE 누락"); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID); tx_return(ctx, TX_EINVAL, ctx->out); return; } if (!date_is_valid(bizdate)) { tx_log(TX_LOG_WARN, "[LG_OL_0032] 영업일 형식 오류 date=%s", bizdate); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID); tx_return(ctx, TX_EINVAL, ctx->out); return; } strncpy(h_biz_date, bizdate, sizeof(h_biz_date) - 1); h_biz_date[sizeof(h_biz_date) - 1] = '\0'; strncpy(h_status_s, LG_ST_SETTLED, sizeof(h_status_s) - 1); h_status_s[sizeof(h_status_s) - 1] = '\0'; strncpy(h_status_m, LG_ST_DONE, sizeof(h_status_m) - 1); h_status_m[sizeof(h_status_m) - 1] = '\0'; /* 정산완료(S) 합계 */ EXEC SQL SELECT coalesce(sum(amount), 0) INTO :h_settled_sum FROM lg_ledger WHERE biz_date = :h_biz_date AND status = :h_status_s; if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) { TX_DBIO_LOG_ERR("lg_ol_0032 settled"); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR); tx_return(ctx, TX_EDB, ctx->out); return; } /* 미정산(처리완료 M) 합계 */ EXEC SQL SELECT coalesce(sum(amount), 0) INTO :h_done_sum FROM lg_ledger WHERE biz_date = :h_biz_date AND status = :h_status_m; if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) { TX_DBIO_LOG_ERR("lg_ol_0032 done"); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESPCODE", RESP_SYSERR); tx_return(ctx, TX_EDB, ctx->out); return; } /* 미정산 차액 = 아직 정산확정되지 않은 처리완료 금액 */ unsettled = h_done_sum; amount_format_won(unsettled, wonbuf, sizeof(wonbuf)); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESPCODE", RESP_OK); tx_buf_sets(ctx->out, "BIZDATE", bizdate); tx_buf_setlong(ctx->out, "SETTLEDSUM", h_settled_sum); tx_buf_setlong(ctx->out, "DONESUM", h_done_sum); tx_buf_setlong(ctx->out, "UNSETTLED", unsettled); tx_buf_sets(ctx->out, "UNSETTLEDWON", wonbuf); tx_buf_sets(ctx->out, "BALANCED", (unsettled == 0) ? "Y" : "N"); tx_log(TX_LOG_INFO, "[LG_OL_0032] 정산대사 date=%s 정산=%ld 미정산=%ld", bizdate, h_settled_sum, unsettled); tx_return(ctx, TX_OK, ctx->out); }