From c9f89cb9b01d8d17434b0036c61ff8c5eb6bee4e Mon Sep 17 00:00:00 2001 From: thug0bin Date: Fri, 13 Mar 2026 00:47:02 +0900 Subject: [PATCH] =?UTF-8?q?fix(stock-analytics):=20=EC=9E=85=EC=B6=9C?= =?UTF-8?q?=EA=B3=A0=20=EC=BB=AC=EB=9F=BC=20=EC=9D=98=EB=AF=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - credit = 출고 (환자에게 판매) - debit = 입고 (도매상에서 들어옴) - 약국 재고 관점에서 올바르게 표시 --- backend/app.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/app.py b/backend/app.py index a4da214..ab26c9a 100644 --- a/backend/app.py +++ b/backend/app.py @@ -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 >= ?