fix: 입출고 원장 필터 기능 수정

## 버그 수정
- 약재 필터: 선택한 약재의 입출고 내역만 표시 (API 재호출)
- 타입 필터: 입고/출고/전체 필터링 (클라이언트 사이드)
- 필터 조합 가능 (약재 선택 후 입고만/출고만 보기)

## 구현 방식
- 원본 데이터를 currentLedgerData에 저장
- 타입 필터 변경시 저장된 데이터에서 필터링
- 약재 필터 변경시 새로운 데이터 로드

이제 필터가 정상 작동합니다!

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
시골약사 2026-02-15 12:13:50 +00:00
parent 496a99ff98
commit 6de812cfe6

View File

@ -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(`<i class="bi bi-journal-text"></i> 전체 입출고 원장`);
}
response.ledger.forEach(entry => {
// 필터 적용하여 표시
applyLedgerFilters();
// 약재 필터 옵션 업데이트
const herbFilter = $('#ledgerHerbFilter');
if (herbFilter.find('option').length <= 1) {
response.summary.forEach(herb => {
herbFilter.append(`<option value="${herb.herb_item_id}">${herb.herb_name}</option>`);
});
}
$('#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() {
<td>${entry.reference_no || '-'}</td>
</tr>
`);
});
// 약재 필터 옵션 업데이트
const herbFilter = $('#ledgerHerbFilter');
if (herbFilter.find('option').length <= 1) {
response.summary.forEach(herb => {
herbFilter.append(`<option value="${herb.herb_item_id}">${herb.herb_name}</option>`);
});
}
$('#stockLedgerModal').modal('show');
}
}).fail(function() {
alert('입출고 내역을 불러오는데 실패했습니다.');
});
// 데이터가 없는 경우
if (filteredData.length === 0) {
tbody.append(`
<tr>
<td colspan="8" class="text-center text-muted">데이터가 없습니다.</td>
</tr>
`);
}
}
// 입출고 원장 모달 버튼 이벤트
@ -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', {