fix(stock-analytics): 입출고 컬럼 의미 수정

- credit = 출고 (환자에게 판매)
- debit = 입고 (도매상에서 들어옴)
- 약국 재고 관점에서 올바르게 표시
This commit is contained in:
thug0bin 2026-03-13 00:47:02 +09:00
parent 591af31da9
commit c9f89cb9b0

View File

@ -9730,13 +9730,14 @@ def api_stock_daily_trend():
cursor = conn.cursor()
# 특정 약품 또는 전체 일별 입출고 집계
# credit=출고, debit=입고 (약국 재고 기준)
if drug_code:
# 특정 약품
cursor.execute("""
SELECT
IM_DT_appl as date,
SUM(ISNULL(IM_QT_sale_credit, 0)) as inbound,
SUM(ISNULL(IM_QT_sale_debit, 0)) as outbound
SUM(ISNULL(IM_QT_sale_debit, 0)) as inbound,
SUM(ISNULL(IM_QT_sale_credit, 0)) as outbound
FROM IM_date_total
WHERE IM_DT_appl >= ?
AND IM_DT_appl <= ?
@ -9749,8 +9750,8 @@ def api_stock_daily_trend():
cursor.execute("""
SELECT
IM_DT_appl as date,
SUM(ISNULL(IM_QT_sale_credit, 0)) as inbound,
SUM(ISNULL(IM_QT_sale_debit, 0)) as outbound
SUM(ISNULL(IM_QT_sale_debit, 0)) as inbound,
SUM(ISNULL(IM_QT_sale_credit, 0)) as outbound
FROM IM_date_total
WHERE IM_DT_appl >= ?
AND IM_DT_appl <= ?
@ -9819,14 +9820,14 @@ def api_stock_top_usage():
drug_session = db_manager.get_session('PM_DRUG')
# 출고량 기준 TOP N
# 출고량 기준 TOP N (credit=출고, debit=입고)
query = text("""
SELECT TOP(:limit)
D.DrugCode as drug_code,
G.GoodsName as product_name,
G.SplName as supplier,
SUM(ISNULL(D.IM_QT_sale_debit, 0)) as total_outbound,
SUM(ISNULL(D.IM_QT_sale_credit, 0)) as total_inbound,
SUM(ISNULL(D.IM_QT_sale_credit, 0)) as total_outbound,
SUM(ISNULL(D.IM_QT_sale_debit, 0)) as total_inbound,
ISNULL(IT.IM_QT_sale_debit, 0) as current_stock
FROM IM_date_total D
LEFT JOIN CD_GOODS G ON D.DrugCode = G.DrugCode
@ -9834,7 +9835,7 @@ def api_stock_top_usage():
WHERE D.IM_DT_appl >= :start_date
AND D.IM_DT_appl <= :end_date
GROUP BY D.DrugCode, G.GoodsName, G.SplName, IT.IM_QT_sale_debit
ORDER BY SUM(ISNULL(D.IM_QT_sale_debit, 0)) DESC
ORDER BY SUM(ISNULL(D.IM_QT_sale_credit, 0)) DESC
""")
rows = drug_session.execute(query, {
@ -9914,11 +9915,12 @@ def api_stock_level():
supplier = stock_row.supplier if stock_row else ''
# 일별 입출고 데이터 (역순으로 누적 계산)
# credit=출고, debit=입고 (약국 재고 기준)
cursor.execute("""
SELECT
IM_DT_appl as date,
SUM(ISNULL(IM_QT_sale_credit, 0)) as inbound,
SUM(ISNULL(IM_QT_sale_debit, 0)) as outbound
SUM(ISNULL(IM_QT_sale_debit, 0)) as inbound,
SUM(ISNULL(IM_QT_sale_credit, 0)) as outbound
FROM IM_date_total
WHERE DrugCode = ?
AND IM_DT_appl >= ?