fix: 입출고 원장 필터 기능 수정
## 버그 수정 - 약재 필터: 선택한 약재의 입출고 내역만 표시 (API 재호출) - 타입 필터: 입고/출고/전체 필터링 (클라이언트 사이드) - 필터 조합 가능 (약재 선택 후 입고만/출고만 보기) ## 구현 방식 - 원본 데이터를 currentLedgerData에 저장 - 타입 필터 변경시 저장된 데이터에서 필터링 - 약재 필터 변경시 새로운 데이터 로드 이제 필터가 정상 작동합니다! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
496a99ff98
commit
6de812cfe6
@ -1294,13 +1294,15 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 재고 원장 보기
|
// 재고 원장 보기
|
||||||
|
let currentLedgerData = []; // 원본 데이터 저장
|
||||||
|
|
||||||
function viewStockLedger(herbId, herbName) {
|
function viewStockLedger(herbId, herbName) {
|
||||||
const url = herbId ? `/api/stock-ledger?herb_id=${herbId}` : '/api/stock-ledger';
|
const url = herbId ? `/api/stock-ledger?herb_id=${herbId}` : '/api/stock-ledger';
|
||||||
|
|
||||||
$.get(url, function(response) {
|
$.get(url, function(response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
const tbody = $('#stockLedgerList');
|
// 원본 데이터 저장
|
||||||
tbody.empty();
|
currentLedgerData = response.ledger;
|
||||||
|
|
||||||
// 헤더 업데이트
|
// 헤더 업데이트
|
||||||
if (herbName) {
|
if (herbName) {
|
||||||
@ -1309,7 +1311,40 @@ $(document).ready(function() {
|
|||||||
$('#stockLedgerModal .modal-title').html(`<i class="bi bi-journal-text"></i> 전체 입출고 원장`);
|
$('#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 typeLabel = '';
|
||||||
let typeBadge = '';
|
let typeBadge = '';
|
||||||
switch(entry.event_type) {
|
switch(entry.event_type) {
|
||||||
@ -1351,19 +1386,14 @@ $(document).ready(function() {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 약재 필터 옵션 업데이트
|
// 데이터가 없는 경우
|
||||||
const herbFilter = $('#ledgerHerbFilter');
|
if (filteredData.length === 0) {
|
||||||
if (herbFilter.find('option').length <= 1) {
|
tbody.append(`
|
||||||
response.summary.forEach(herb => {
|
<tr>
|
||||||
herbFilter.append(`<option value="${herb.herb_item_id}">${herb.herb_name}</option>`);
|
<td colspan="8" class="text-center text-muted">데이터가 없습니다.</td>
|
||||||
});
|
</tr>
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#stockLedgerModal').modal('show');
|
|
||||||
}
|
|
||||||
}).fail(function() {
|
|
||||||
alert('입출고 내역을 불러오는데 실패했습니다.');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 입출고 원장 모달 버튼 이벤트
|
// 입출고 원장 모달 버튼 이벤트
|
||||||
@ -1372,11 +1402,10 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 필터 변경 이벤트
|
// 필터 변경 이벤트
|
||||||
$('#ledgerHerbFilter, #ledgerTypeFilter').on('change', function() {
|
$('#ledgerHerbFilter').on('change', function() {
|
||||||
const herbId = $('#ledgerHerbFilter').val();
|
const herbId = $(this).val();
|
||||||
const typeFilter = $('#ledgerTypeFilter').val();
|
|
||||||
|
|
||||||
// 재로드 (필터 적용은 프론트엔드에서 처리)
|
// 약재 필터 변경 시 데이터 재로드
|
||||||
if (herbId) {
|
if (herbId) {
|
||||||
const herbName = $('#ledgerHerbFilter option:selected').text();
|
const herbName = $('#ledgerHerbFilter option:selected').text();
|
||||||
viewStockLedger(herbId, herbName);
|
viewStockLedger(herbId, herbName);
|
||||||
@ -1385,6 +1414,11 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 타입 필터 변경 이벤트 (현재 데이터에서 필터링만)
|
||||||
|
$('#ledgerTypeFilter').on('change', function() {
|
||||||
|
applyLedgerFilters();
|
||||||
|
});
|
||||||
|
|
||||||
function formatCurrency(amount) {
|
function formatCurrency(amount) {
|
||||||
if (amount === null || amount === undefined) return '0원';
|
if (amount === null || amount === undefined) return '0원';
|
||||||
return new Intl.NumberFormat('ko-KR', {
|
return new Intl.NumberFormat('ko-KR', {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user