fix: 작업자 비활성화 기능 완전 수정

작업자 퇴사 시 비활성화 기능이 제대로 작동하지 않던 문제 해결

백엔드 수정:
- is_active 가상 필드 추가 (status 기반 자동 생성)
- ISO 8601 날짜 형식을 MySQL DATE 형식으로 변환
- 작업자 업데이트 필드 오류 수정 (salary, annual_leave 제거)

프론트엔드 수정 (11개 파일):
- 모든 페이지에서 비활성 작업자 필터링 로직 추가
- 대시보드, 작업보고서, 근태관리, 사용자관리 등 전체 페이지 적용

영향받는 기능:
- 작업자 관리: 비활성화 상태가 DB에 저장되고 새로고침 후에도 유지
- 모든 페이지: 비활성화된 작업자가 선택 목록에서 제외됨

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2025-12-09 17:45:57 +09:00
parent a2669e08c4
commit 5c8f553f87
13 changed files with 317 additions and 36 deletions

View File

@@ -38,7 +38,13 @@ function fillSelectOptions() {
async function fetchWorkers() {
try {
const res = await fetch(`${API}/workers`, { headers: getAuthHeaders() });
workers = await res.json();
const allWorkers = await res.json();
// 활성화된 작업자만 필터링
workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
workers.sort((a, b) => a.worker_id - b.worker_id);
} catch (err) {
alert('작업자 불러오기 실패');

View File

@@ -30,7 +30,7 @@ export async function getWorkersByDate(date) {
// 현재는 기존 로직을 최대한 활용하여 구현합니다.
let workers = [];
const reports = await apiGet(`/daily-work-reports?date=${date}`);
if (reports && reports.length > 0) {
const workerMap = new Map();
reports.forEach(r => {
@@ -41,7 +41,12 @@ export async function getWorkersByDate(date) {
workers = Array.from(workerMap.values());
} else {
// 보고서가 없으면 전체 작업자 목록을 가져옵니다.
workers = await apiGet('/workers');
const allWorkers = await apiGet('/workers');
// 활성화된 작업자만 필터링
workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
}
return workers.sort((a, b) => a.worker_name.localeCompare(b.worker_name));
} catch (error) {

View File

@@ -207,8 +207,14 @@ async function loadWorkers() {
try {
console.log('Workers API 호출 중... (통합 API 사용)');
const data = await window.apiCall(`${window.API}/workers`);
workers = Array.isArray(data) ? data : (data.data || data.workers || []);
console.log('✅ Workers 로드 성공:', workers.length);
const allWorkers = Array.isArray(data) ? data : (data.data || data.workers || []);
// 활성화된 작업자만 필터링
workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
console.log(`✅ Workers 로드 성공: ${workers.length}명 (전체: ${allWorkers.length}명)`);
} catch (error) {
console.error('작업자 로딩 오류:', error);
throw error;
@@ -334,8 +340,8 @@ function addWorkEntry() {
entryDiv.innerHTML = `
<div class="work-entry-header">
<div class="work-entry-title">작업 항목 #${workEntryCounter}</div>
<button type="button" class="remove-work-btn" onclick="removeWorkEntry(${workEntryCounter})" title="이 작업 삭제">
<button type="button" class="remove-work-btn" onclick="event.stopPropagation(); removeWorkEntry(${workEntryCounter})" title="이 작업 삭제">
🗑️ 삭제
</button>
</div>
@@ -477,10 +483,15 @@ function setupWorkEntryEvents(entryDiv) {
// 작업 항목 제거
function removeWorkEntry(id) {
const entry = document.querySelector(`[data-id="${id}"]`);
console.log('🗑️ removeWorkEntry 호출됨, id:', id);
const entry = document.querySelector(`.work-entry[data-id="${id}"]`);
console.log('🗑️ 찾은 entry:', entry);
if (entry) {
entry.remove();
updateTotalHours();
console.log('✅ 작업 항목 삭제 완료');
} else {
console.log('❌ 작업 항목을 찾을 수 없음');
}
}

View File

@@ -246,12 +246,18 @@ async function loadWorkerOptions() {
const res = await fetch(`${API}/workers`, {
headers: getAuthHeaders()
});
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`);
}
const workers = await res.json();
const allWorkers = await res.json();
// 활성화된 작업자만 필터링
const workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
if (Array.isArray(workers)) {
workers.forEach(w => {
const opt = document.createElement('option');

View File

@@ -127,8 +127,14 @@ async function loadWorkers() {
try {
console.log('작업자 데이터 로딩 중... (통합 API)');
const data = await apiCall(`${API}/workers`);
workers = Array.isArray(data) ? data : (data.data || data.workers || []);
console.log('✅ 작업자 로드 성공:', workers.length);
const allWorkers = Array.isArray(data) ? data : (data.data || data.workers || []);
// 활성화된 작업자만 필터링
workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
console.log(`✅ 작업자 로드 성공: ${workers.length}명 (전체: ${allWorkers.length}명)`);
} catch (error) {
console.error('작업자 로딩 오류:', error);
throw error;

View File

@@ -216,8 +216,14 @@ async function loadWorkers() {
try {
console.log('👥 작업자 데이터 로딩...');
const response = await window.apiCall('/workers');
workersData = Array.isArray(response) ? response : (response.data || []);
console.log(`✅ 작업자 ${workersData.length}명 로드 완료`);
const allWorkers = Array.isArray(response) ? response : (response.data || []);
// 활성화된 작업자만 필터링
workersData = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
console.log(`✅ 작업자 ${workersData.length}명 로드 완료 (전체: ${allWorkers.length}명)`);
return workersData;
} catch (error) {
console.error('작업자 데이터 로딩 오류:', error);

View File

@@ -8,11 +8,17 @@ import { apiGet } from './api-helper.js';
*/
export async function getMasterData() {
try {
const [workers, projects, tasks] = await Promise.all([
const [allWorkers, projects, tasks] = await Promise.all([
apiGet('/workers'),
apiGet('/projects'),
apiGet('/tasks')
]);
// 활성화된 작업자만 필터링
const workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
return { workers, projects, tasks };
} catch (error) {
console.error('마스터 데이터 로딩 실패:', error);

View File

@@ -8,17 +8,22 @@ import { apiGet, apiPost } from './api-helper.js';
*/
export async function getInitialData() {
try {
const [workers, projects, tasks] = await Promise.all([
const [allWorkers, projects, tasks] = await Promise.all([
apiGet('/workers'),
apiGet('/projects'),
apiGet('/tasks')
]);
// 활성화된 작업자만 필터링
const workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
// 데이터 형식 검증
if (!Array.isArray(workers) || !Array.isArray(projects) || !Array.isArray(tasks)) {
throw new Error('서버에서 받은 데이터 형식이 올바르지 않습니다.');
}
// 작업자 목록은 ID 기준으로 정렬
workers.sort((a, b) => a.worker_id - b.worker_id);

View File

@@ -102,12 +102,18 @@ function setupEventListeners() {
// 작업자 데이터 로드 (캐시)
async function loadWorkersData() {
if (allWorkers.length > 0) return allWorkers;
try {
console.log('👥 작업자 데이터 로딩...');
const response = await window.apiCall('/workers');
allWorkers = Array.isArray(response) ? response : (response.data || []);
console.log(`✅ 작업자 ${allWorkers.length}명 로드 완료`);
const workers = Array.isArray(response) ? response : (response.data || []);
// 활성화된 작업자만 필터링
allWorkers = workers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
console.log(`✅ 작업자 ${allWorkers.length}명 로드 완료 (전체: ${workers.length}명)`);
return allWorkers;
} catch (error) {
console.error('작업자 데이터 로딩 오류:', error);

View File

@@ -28,10 +28,15 @@ async function loadReports() {
if (![wRes, pRes, rRes].every(res => res.ok)) throw new Error('불러오기 실패');
const [workers, projects, reports] = await Promise.all([
const [allWorkers, projects, reports] = await Promise.all([
wRes.json(), pRes.json(), rRes.json()
]);
// 활성화된 작업자만 필터링
const workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
// 배열 체크
if (!Array.isArray(workers) || !Array.isArray(projects) || !Array.isArray(reports)) {
throw new Error('잘못된 데이터 형식');

View File

@@ -55,7 +55,13 @@ class WorkReportReviewManager {
throw new Error(`API 응답 오류: Workers(${workersRes.status}), Projects(${projectsRes.status})`);
}
this.workers = await workersRes.json();
const allWorkers = await workersRes.json();
// 활성화된 작업자만 필터링
this.workers = allWorkers.filter(worker => {
return worker.status === 'active' || worker.is_active === 1 || worker.is_active === true;
});
this.projects = await projectsRes.json();
// 새로운 API들 로드 (실패해도 기본값 사용)