From 6de812cfe6f7f7efd7bee6b1818d83299900be0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=9C=EA=B3=A8=EC=95=BD=EC=82=AC?= Date: Sun, 15 Feb 2026 12:13:50 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=9E=85=EC=B6=9C=EA=B3=A0=20=EC=9B=90?= =?UTF-8?q?=EC=9E=A5=20=ED=95=84=ED=84=B0=20=EA=B8=B0=EB=8A=A5=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 ## 버그 수정 - 약재 필터: 선택한 약재의 입출고 내역만 표시 (API 재호출) - 타입 필터: 입고/출고/전체 필터링 (클라이언트 사이드) - 필터 조합 가능 (약재 선택 후 입고만/출고만 보기) ## 구현 방식 - 원본 데이터를 currentLedgerData에 저장 - 타입 필터 변경시 저장된 데이터에서 필터링 - 약재 필터 변경시 새로운 데이터 로드 이제 필터가 정상 작동합니다! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- static/app.js | 76 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/static/app.js b/static/app.js index 90e7ac0..b341acf 100644 --- a/static/app.js +++ b/static/app.js @@ -1294,13 +1294,15 @@ $(document).ready(function() { } // 재고 원장 보기 + let currentLedgerData = []; // 원본 데이터 저장 + function viewStockLedger(herbId, herbName) { const url = herbId ? `/api/stock-ledger?herb_id=${herbId}` : '/api/stock-ledger'; $.get(url, function(response) { if (response.success) { - const tbody = $('#stockLedgerList'); - tbody.empty(); + // 원본 데이터 저장 + currentLedgerData = response.ledger; // 헤더 업데이트 if (herbName) { @@ -1309,7 +1311,40 @@ $(document).ready(function() { $('#stockLedgerModal .modal-title').html(` 전체 입출고 원장`); } - response.ledger.forEach(entry => { + // 필터 적용하여 표시 + applyLedgerFilters(); + + // 약재 필터 옵션 업데이트 + const herbFilter = $('#ledgerHerbFilter'); + if (herbFilter.find('option').length <= 1) { + response.summary.forEach(herb => { + herbFilter.append(``); + }); + } + + $('#stockLedgerModal').modal('show'); + } + }).fail(function() { + alert('입출고 내역을 불러오는데 실패했습니다.'); + }); + } + + // 필터 적용 함수 + function applyLedgerFilters() { + const typeFilter = $('#ledgerTypeFilter').val(); + const tbody = $('#stockLedgerList'); + tbody.empty(); + + // 필터링된 데이터 + let filteredData = currentLedgerData; + + // 타입 필터 적용 + if (typeFilter) { + filteredData = currentLedgerData.filter(entry => entry.event_type === typeFilter); + } + + // 데이터 표시 + filteredData.forEach(entry => { let typeLabel = ''; let typeBadge = ''; switch(entry.event_type) { @@ -1349,21 +1384,16 @@ $(document).ready(function() { ${entry.reference_no || '-'} `); - }); - - // 약재 필터 옵션 업데이트 - const herbFilter = $('#ledgerHerbFilter'); - if (herbFilter.find('option').length <= 1) { - response.summary.forEach(herb => { - herbFilter.append(``); - }); - } - - $('#stockLedgerModal').modal('show'); - } - }).fail(function() { - alert('입출고 내역을 불러오는데 실패했습니다.'); }); + + // 데이터가 없는 경우 + if (filteredData.length === 0) { + tbody.append(` + + 데이터가 없습니다. + + `); + } } // 입출고 원장 모달 버튼 이벤트 @@ -1372,11 +1402,10 @@ $(document).ready(function() { }); // 필터 변경 이벤트 - $('#ledgerHerbFilter, #ledgerTypeFilter').on('change', function() { - const herbId = $('#ledgerHerbFilter').val(); - const typeFilter = $('#ledgerTypeFilter').val(); + $('#ledgerHerbFilter').on('change', function() { + const herbId = $(this).val(); - // 재로드 (필터 적용은 프론트엔드에서 처리) + // 약재 필터 변경 시 데이터 재로드 if (herbId) { const herbName = $('#ledgerHerbFilter option:selected').text(); viewStockLedger(herbId, herbName); @@ -1385,6 +1414,11 @@ $(document).ready(function() { } }); + // 타입 필터 변경 이벤트 (현재 데이터에서 필터링만) + $('#ledgerTypeFilter').on('change', function() { + applyLedgerFilters(); + }); + function formatCurrency(amount) { if (amount === null || amount === undefined) return '0원'; return new Intl.NumberFormat('ko-KR', {