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() {