feat: 다수 기능 개선 - 순찰, 출근, 작업분석, 모바일 UI 등

- 순찰/점검 기능 개선 (zone-detail 페이지 추가)
- 출근/근태 시스템 개선 (연차 조회, 근무현황)
- 작업분석 대분류 그룹화 및 마이그레이션 스크립트
- 모바일 네비게이션 UI 추가
- NAS 배포 도구 및 문서 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-02-09 14:41:01 +09:00
parent 1548253f56
commit 2b1c7bfb88
633 changed files with 361224 additions and 1090 deletions

View File

@@ -0,0 +1,762 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>연간 연차 현황 | 테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<style>
.page-wrapper {
padding: 1.5rem;
max-width: 1200px;
}
.page-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; }
.page-desc { color: #6b7280; font-size: 0.875rem; margin-top: 0.25rem; }
.controls { display: flex; gap: 0.5rem; align-items: center; }
.controls select {
padding: 0.5rem;
border: 1px solid #d1d5db;
border-radius: 0.375rem;
}
.btn {
padding: 0.5rem 1rem;
border: none;
border-radius: 0.375rem;
cursor: pointer;
font-size: 0.875rem;
font-weight: 500;
}
.btn-primary { background: #3b82f6; color: white; }
.btn-success { background: #10b981; color: white; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
/* 범례 */
.legend-box {
display: flex;
gap: 1rem;
margin-bottom: 1rem;
padding: 0.5rem 1rem;
background: #f9fafb;
border-radius: 0.5rem;
font-size: 0.8rem;
color: #6b7280;
flex-wrap: wrap;
align-items: center;
}
.legend-item { display: flex; align-items: center; gap: 0.25rem; }
.legend-dot {
width: 12px; height: 12px; border-radius: 2px;
}
.dot-carryover { background: #fef3c7; border: 1px solid #f59e0b; }
.dot-annual { background: #dbeafe; border: 1px solid #3b82f6; }
.dot-longservice { background: #f3e8ff; border: 1px solid #a855f7; }
.dot-special { background: #fce7f3; border: 1px solid #ec4899; }
/* 테이블 */
.data-table {
width: 100%;
border-collapse: collapse;
font-size: 0.85rem;
background: white;
}
.data-table th, .data-table td {
padding: 0.6rem 0.5rem;
text-align: center;
border: 1px solid #e5e7eb;
}
.data-table th {
background: #f9fafb;
font-weight: 600;
font-size: 0.8rem;
}
.data-table th.col-carryover { background: #fef3c7; color: #92400e; }
.data-table th.col-annual { background: #dbeafe; color: #1e40af; }
.data-table th.col-longservice { background: #f3e8ff; color: #7c3aed; }
.data-table th.col-special { background: #fce7f3; color: #be185d; }
.data-table th.col-total { background: #dcfce7; color: #166534; }
.data-table td.worker-name { text-align: left; font-weight: 500; }
.data-table tr:hover { background: #f9fafb; }
/* 입력 필드 */
.num-input {
width: 55px;
padding: 0.25rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
text-align: center;
font-size: 0.8rem;
}
.num-input:focus {
outline: none;
border-color: #3b82f6;
}
.num-input.negative { color: #dc2626; }
/* 경조사 버튼 */
.special-btn {
padding: 0.2rem 0.5rem;
font-size: 0.75rem;
background: #fce7f3;
color: #be185d;
border: 1px solid #f9a8d4;
border-radius: 0.25rem;
cursor: pointer;
}
.special-btn:hover { background: #fbcfe8; }
.special-count {
display: inline-block;
min-width: 20px;
padding: 0.125rem 0.375rem;
background: #be185d;
color: white;
border-radius: 10px;
font-size: 0.7rem;
margin-left: 0.25rem;
}
/* 잔여 */
.remaining { font-weight: 700; }
.remaining.positive { color: #059669; }
.remaining.zero { color: #6b7280; }
.remaining.negative { color: #dc2626; }
/* 저장 바 */
.save-bar {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 1rem;
padding: 0.75rem 1rem;
background: #f9fafb;
border: 1px solid #e5e7eb;
border-radius: 0.5rem;
}
.save-status { font-size: 0.875rem; color: #6b7280; }
/* 경조사 모달 */
.modal-overlay {
display: none;
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.5);
z-index: 1000;
justify-content: center;
align-items: center;
}
.modal-overlay.active { display: flex; }
.modal-content {
background: white;
border-radius: 0.75rem;
width: 90%;
max-width: 500px;
max-height: 80vh;
overflow-y: auto;
padding: 1.5rem;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid #e5e7eb;
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: #6b7280;
}
.special-list { margin-bottom: 1rem; }
.special-item {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem;
border-bottom: 1px solid #f3f4f6;
}
.special-item select {
flex: 1;
padding: 0.375rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
font-size: 0.8rem;
}
.special-item input {
width: 60px;
padding: 0.375rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
text-align: center;
font-size: 0.8rem;
}
.special-item .delete-btn {
padding: 0.25rem 0.5rem;
background: #fee2e2;
color: #dc2626;
border: none;
border-radius: 0.25rem;
cursor: pointer;
font-size: 0.75rem;
}
.add-special-btn {
width: 100%;
padding: 0.5rem;
background: #f3f4f6;
border: 1px dashed #9ca3af;
border-radius: 0.375rem;
cursor: pointer;
font-size: 0.8rem;
color: #6b7280;
}
.add-special-btn:hover { background: #e5e7eb; }
.modal-footer {
display: flex;
justify-content: flex-end;
gap: 0.5rem;
margin-top: 1rem;
padding-top: 0.75rem;
border-top: 1px solid #e5e7eb;
}
.loading { text-align: center; padding: 2rem; color: #6b7280; }
</style>
</head>
<body class="has-sidebar">
<div id="navbar-container"></div>
<div id="sidebar-container"></div>
<main class="main-content">
<div class="page-wrapper">
<div class="page-header">
<div>
<h1 class="page-title">연간 연차 현황</h1>
<p class="page-desc">작업자별 연차 발생 및 사용 현황을 관리합니다</p>
</div>
<div class="controls">
<select id="yearSelect"></select>
<button class="btn btn-primary" onclick="loadData()">조회</button>
</div>
</div>
<!-- 범례 -->
<div class="legend-box">
<span style="font-weight:500;">차감 우선순위:</span>
<div class="legend-item"><div class="legend-dot dot-carryover"></div>1. 이월</div>
<div class="legend-item"><div class="legend-dot dot-annual"></div>2. 정기연차</div>
<div class="legend-item"><div class="legend-dot dot-longservice"></div>3. 장기근속</div>
<div class="legend-item"><div class="legend-dot dot-special"></div>4. 경조사</div>
</div>
<!-- 테이블 -->
<div class="card">
<div class="card-body" style="padding:0;overflow-x:auto;">
<table class="data-table">
<thead>
<tr>
<th style="width:40px">No</th>
<th style="min-width:70px">이름</th>
<th class="col-carryover" style="width:80px">이월</th>
<th class="col-annual" style="width:80px">정기연차</th>
<th class="col-longservice" style="width:80px">장기근속</th>
<th class="col-special" style="width:100px">경조사</th>
<th class="col-total" style="width:70px">총 발생</th>
<th class="col-total" style="width:70px">총 사용</th>
<th class="col-total" style="width:70px">잔여</th>
</tr>
</thead>
<tbody id="tableBody">
<tr><td colspan="9" class="loading">로딩 중...</td></tr>
</tbody>
</table>
</div>
</div>
<!-- 저장 바 -->
<div class="save-bar">
<span class="save-status" id="saveStatus">변경사항이 있으면 저장 버튼을 눌러주세요</span>
<button class="btn btn-success" onclick="saveAll()">저장</button>
</div>
</div>
</main>
<!-- 경조사 모달 -->
<div class="modal-overlay" id="specialModal">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="specialModalTitle">경조사 휴가</h3>
<button class="modal-close" onclick="closeSpecialModal()">&times;</button>
</div>
<div class="modal-body">
<div class="special-list" id="specialList">
<!-- 동적 생성 -->
</div>
<button class="add-special-btn" onclick="addSpecialItem()">+ 경조사 추가</button>
</div>
<div class="modal-footer">
<button class="btn btn-primary" onclick="saveSpecialAndClose()">확인</button>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
// axios 설정
(function() {
const check = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(check);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
}, 50);
})();
// 전역 변수
let workers = [];
let currentYear = new Date().getFullYear();
let vacationData = {}; // { workerId: { carryover, annual, longService, specials: [{type, days}], totalUsed } }
let currentWorkerId = null;
// 경조사 유형
const specialTypes = [
{ code: 'WEDDING', name: '결혼', defaultDays: 5 },
{ code: 'SPOUSE_BIRTH', name: '배우자 출산', defaultDays: 10 },
{ code: 'CHILD_WEDDING', name: '자녀 결혼', defaultDays: 1 },
{ code: 'CONDOLENCE_PARENT', name: '부모 사망', defaultDays: 5 },
{ code: 'CONDOLENCE_SPOUSE_PARENT', name: '배우자 부모 사망', defaultDays: 5 },
{ code: 'CONDOLENCE_GRANDPARENT', name: '조부모 사망', defaultDays: 3 },
{ code: 'CONDOLENCE_SIBLING', name: '형제자매 사망', defaultDays: 3 },
{ code: 'OTHER', name: '기타', defaultDays: 1 }
];
// 초기화
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxios();
initYearSelector();
await loadData();
});
function waitForAxios() {
return new Promise(resolve => {
const check = setInterval(() => {
if (axios.defaults.baseURL) { clearInterval(check); resolve(); }
}, 50);
setTimeout(() => { clearInterval(check); resolve(); }, 5000);
});
}
function initYearSelector() {
const select = document.getElementById('yearSelect');
const now = new Date().getFullYear();
for (let y = now - 2; y <= now + 1; y++) {
const opt = document.createElement('option');
opt.value = y;
opt.textContent = `${y}`;
if (y === now) opt.selected = true;
select.appendChild(opt);
}
}
async function loadData() {
currentYear = parseInt(document.getElementById('yearSelect').value);
document.getElementById('tableBody').innerHTML = '<tr><td colspan="9" class="loading">로딩 중...</td></tr>';
try {
// 작업자 로드
const workersRes = await axios.get('/workers?limit=100');
workers = (workersRes.data.data || [])
.filter(w => w.status === 'active' && w.employment_status === 'employed')
.sort((a, b) => a.worker_name.localeCompare(b.worker_name, 'ko'));
// 휴가 잔액 로드
let balances = [];
try {
const balancesRes = await axios.get(`/vacation-balances/year/${currentYear}`);
balances = balancesRes.data.data || [];
} catch (e) { console.log('휴가 잔액 로드 실패'); }
// 데이터 정리
vacationData = {};
workers.forEach(w => {
vacationData[w.worker_id] = {
carryover: 0,
annual: 0,
longService: 0,
specials: [],
totalUsed: 0
};
});
// 잔액 데이터 매핑
balances.forEach(b => {
if (!vacationData[b.worker_id]) return;
const code = b.type_code || '';
const data = vacationData[b.worker_id];
if (code === 'CARRYOVER' || b.type_name === '이월') {
data.carryover = b.total_days || 0;
data.totalUsed += b.used_days || 0;
} else if (code === 'ANNUAL' || b.type_name === '정기연차' || b.type_name === '연차') {
data.annual = b.total_days || 0;
data.totalUsed += b.used_days || 0;
} else if (code === 'LONG_SERVICE' || b.type_name === '장기근속') {
data.longService = b.total_days || 0;
data.totalUsed += b.used_days || 0;
} else if (code.startsWith('SPECIAL_') || specialTypes.some(st => st.code === code)) {
data.specials.push({
type: code,
typeName: b.type_name,
days: b.total_days || 0,
id: b.id
});
data.totalUsed += b.used_days || 0;
}
});
renderTable();
} catch (error) {
console.error('데이터 로드 오류:', error);
document.getElementById('tableBody').innerHTML = '<tr><td colspan="9" class="loading" style="color:#ef4444;">데이터 로드 실패</td></tr>';
}
}
function renderTable() {
const tbody = document.getElementById('tableBody');
if (workers.length === 0) {
tbody.innerHTML = '<tr><td colspan="9" class="loading">작업자가 없습니다</td></tr>';
return;
}
tbody.innerHTML = workers.map((w, idx) => {
const d = vacationData[w.worker_id] || { carryover: 0, annual: 0, longService: 0, specials: [], totalUsed: 0 };
const carryover = parseFloat(d.carryover) || 0;
const annual = parseFloat(d.annual) || 0;
const longService = parseFloat(d.longService) || 0;
const totalUsed = parseFloat(d.totalUsed) || 0;
const specialTotal = (d.specials || []).reduce((sum, s) => sum + (parseFloat(s.days) || 0), 0);
const totalGenerated = carryover + annual + longService + specialTotal;
const remaining = totalGenerated - totalUsed;
const remainingClass = remaining > 0 ? 'positive' : remaining < 0 ? 'negative' : 'zero';
return `
<tr data-worker-id="${w.worker_id}">
<td>${idx + 1}</td>
<td class="worker-name">${w.worker_name}</td>
<td>
<input type="number" class="num-input ${carryover < 0 ? 'negative' : ''}"
value="${carryover}" step="0.5"
data-field="carryover"
onchange="updateField(${w.worker_id}, 'carryover', this.value)">
</td>
<td>
<input type="number" class="num-input"
value="${annual}" step="0.5"
data-field="annual"
onchange="updateField(${w.worker_id}, 'annual', this.value)">
</td>
<td>
<input type="number" class="num-input"
value="${longService}" step="0.5"
data-field="longService"
onchange="updateField(${w.worker_id}, 'longService', this.value)">
</td>
<td>
<button class="special-btn" onclick="openSpecialModal(${w.worker_id}, '${w.worker_name}')">
${(d.specials || []).length > 0 ? `${specialTotal}` : '추가'}
${(d.specials || []).length > 0 ? `<span class="special-count">${d.specials.length}</span>` : ''}
</button>
</td>
<td style="font-weight:600;color:#059669;">${totalGenerated.toFixed(2)}</td>
<td style="color:#6b7280;">${totalUsed > 0 ? totalUsed.toFixed(2) : '-'}</td>
<td class="remaining ${remainingClass}">${remaining.toFixed(2)}</td>
</tr>
`;
}).join('');
}
function updateField(workerId, field, value) {
const val = parseFloat(value) || 0;
if (!vacationData[workerId]) {
vacationData[workerId] = { carryover: 0, annual: 0, longService: 0, specials: [], totalUsed: 0 };
}
vacationData[workerId][field] = val;
// 입력 스타일 업데이트
const input = document.querySelector(`tr[data-worker-id="${workerId}"] input[data-field="${field}"]`);
if (input) {
input.classList.toggle('negative', val < 0);
}
// 행 합계 업데이트
updateRowTotals(workerId);
markChanged();
}
function updateRowTotals(workerId) {
const row = document.querySelector(`tr[data-worker-id="${workerId}"]`);
if (!row) return;
const d = vacationData[workerId];
if (!d) return;
const carryover = parseFloat(d.carryover) || 0;
const annual = parseFloat(d.annual) || 0;
const longService = parseFloat(d.longService) || 0;
const totalUsed = parseFloat(d.totalUsed) || 0;
const specialTotal = (d.specials || []).reduce((sum, s) => sum + (parseFloat(s.days) || 0), 0);
const totalGenerated = carryover + annual + longService + specialTotal;
const remaining = totalGenerated - totalUsed;
const cells = row.querySelectorAll('td');
cells[6].textContent = totalGenerated.toFixed(2);
cells[7].textContent = totalUsed > 0 ? totalUsed.toFixed(2) : '-';
cells[8].textContent = remaining.toFixed(2);
cells[8].className = `remaining ${remaining > 0 ? 'positive' : remaining < 0 ? 'negative' : 'zero'}`;
}
function markChanged() {
document.getElementById('saveStatus').textContent = '변경사항이 있습니다. 저장 버튼을 눌러주세요.';
document.getElementById('saveStatus').style.color = '#f59e0b';
}
// ===== 경조사 모달 =====
function openSpecialModal(workerId, workerName) {
currentWorkerId = workerId;
document.getElementById('specialModalTitle').textContent = `${workerName} - 경조사 휴가`;
renderSpecialList();
document.getElementById('specialModal').classList.add('active');
}
function closeSpecialModal() {
document.getElementById('specialModal').classList.remove('active');
currentWorkerId = null;
}
function renderSpecialList() {
const container = document.getElementById('specialList');
const specials = vacationData[currentWorkerId]?.specials || [];
if (specials.length === 0) {
container.innerHTML = '<p style="text-align:center;color:#9ca3af;padding:1rem;">경조사 휴가가 없습니다</p>';
return;
}
container.innerHTML = specials.map((s, idx) => `
<div class="special-item" data-idx="${idx}">
<select onchange="updateSpecialType(${idx}, this.value)">
${specialTypes.map(st => `
<option value="${st.code}" ${s.type === st.code ? 'selected' : ''}>${st.name}</option>
`).join('')}
</select>
<input type="number" value="${s.days}" step="0.5" min="0"
onchange="updateSpecialDays(${idx}, this.value)">
<span>일</span>
<button class="delete-btn" onclick="deleteSpecialItem(${idx})">삭제</button>
</div>
`).join('');
}
function addSpecialItem() {
if (!vacationData[currentWorkerId]) return;
vacationData[currentWorkerId].specials.push({
type: 'WEDDING',
typeName: '결혼',
days: 5
});
renderSpecialList();
}
function updateSpecialType(idx, typeCode) {
const specials = vacationData[currentWorkerId]?.specials;
if (!specials || !specials[idx]) return;
const typeInfo = specialTypes.find(st => st.code === typeCode);
specials[idx].type = typeCode;
specials[idx].typeName = typeInfo?.name || typeCode;
specials[idx].days = typeInfo?.defaultDays || specials[idx].days;
renderSpecialList();
}
function updateSpecialDays(idx, value) {
const specials = vacationData[currentWorkerId]?.specials;
if (!specials || !specials[idx]) return;
specials[idx].days = parseFloat(value) || 0;
}
function deleteSpecialItem(idx) {
const specials = vacationData[currentWorkerId]?.specials;
if (!specials) return;
specials.splice(idx, 1);
renderSpecialList();
}
function saveSpecialAndClose() {
updateRowTotals(currentWorkerId);
renderTable(); // 경조사 버튼 텍스트 업데이트
markChanged();
closeSpecialModal();
}
// ESC로 모달 닫기
document.addEventListener('keydown', e => {
if (e.key === 'Escape') closeSpecialModal();
});
document.getElementById('specialModal').addEventListener('click', e => {
if (e.target.id === 'specialModal') closeSpecialModal();
});
// ===== 저장 =====
async function saveAll() {
const balancesToSave = [];
// 휴가 유형 ID 매핑 (서버에서 가져와야 하지만 일단 하드코딩)
// 실제로는 vacation_types 테이블에서 조회해야 함
const typeIdMap = {
'CARRYOVER': null,
'ANNUAL': null,
'LONG_SERVICE': null
};
// 휴가 유형 ID 조회
try {
const typesRes = await axios.get('/vacation-types');
const types = typesRes.data.data || [];
types.forEach(t => {
if (t.type_code === 'CARRYOVER' || t.type_name === '이월') typeIdMap['CARRYOVER'] = t.id;
if (t.type_code === 'ANNUAL' || t.type_name === '정기연차' || t.type_name === '연차') typeIdMap['ANNUAL'] = t.id;
if (t.type_code === 'LONG_SERVICE' || t.type_name === '장기근속') typeIdMap['LONG_SERVICE'] = t.id;
});
} catch (e) {
console.error('휴가 유형 로드 실패:', e);
}
// 필요한 유형이 없으면 생성 (deduct_days 필수)
if (!typeIdMap['CARRYOVER']) {
try {
const res = await axios.post('/vacation-types', { type_code: 'CARRYOVER', type_name: '이월', deduct_days: 1, priority: 1 });
typeIdMap['CARRYOVER'] = res.data.data?.id;
} catch (e) { console.error('이월 유형 생성 실패'); }
}
if (!typeIdMap['ANNUAL']) {
try {
const res = await axios.post('/vacation-types', { type_code: 'ANNUAL', type_name: '정기연차', deduct_days: 1, priority: 2 });
typeIdMap['ANNUAL'] = res.data.data?.id;
} catch (e) { console.error('정기연차 유형 생성 실패'); }
}
if (!typeIdMap['LONG_SERVICE']) {
try {
const res = await axios.post('/vacation-types', { type_code: 'LONG_SERVICE', type_name: '장기근속', deduct_days: 1, priority: 3 });
typeIdMap['LONG_SERVICE'] = res.data.data?.id;
} catch (e) { console.error('장기근속 유형 생성 실패'); }
}
// 데이터 수집
for (const w of workers) {
const d = vacationData[w.worker_id];
if (!d) continue;
if (typeIdMap['CARRYOVER']) {
balancesToSave.push({
worker_id: w.worker_id,
vacation_type_id: typeIdMap['CARRYOVER'],
year: currentYear,
total_days: d.carryover
});
}
if (typeIdMap['ANNUAL']) {
balancesToSave.push({
worker_id: w.worker_id,
vacation_type_id: typeIdMap['ANNUAL'],
year: currentYear,
total_days: d.annual
});
}
if (typeIdMap['LONG_SERVICE']) {
balancesToSave.push({
worker_id: w.worker_id,
vacation_type_id: typeIdMap['LONG_SERVICE'],
year: currentYear,
total_days: d.longService
});
}
// 경조사 데이터 저장
for (const special of d.specials) {
if (special.days > 0) {
// 경조사 유형 ID 조회 또는 생성
let specialTypeId = typeIdMap[special.type];
if (!specialTypeId) {
try {
const typesRes = await axios.get('/vacation-types');
const existingType = (typesRes.data.data || []).find(t => t.type_code === special.type);
if (existingType) {
specialTypeId = existingType.id;
typeIdMap[special.type] = specialTypeId;
}
} catch (e) {}
}
if (!specialTypeId) {
try {
const typeInfo = specialTypes.find(st => st.code === special.type);
const res = await axios.post('/vacation-types', {
type_code: special.type,
type_name: typeInfo?.name || special.type,
deduct_days: typeInfo?.defaultDays || 1,
priority: 4
});
specialTypeId = res.data.data?.id;
typeIdMap[special.type] = specialTypeId;
} catch (e) { console.error(`${special.type} 유형 생성 실패`); }
}
if (specialTypeId) {
balancesToSave.push({
worker_id: w.worker_id,
vacation_type_id: specialTypeId,
year: currentYear,
total_days: special.days,
notes: special.typeName || special.type
});
}
}
}
}
if (balancesToSave.length === 0) {
alert('저장할 데이터가 없습니다.');
return;
}
try {
const res = await axios.post('/vacation-balances/bulk-upsert', { balances: balancesToSave });
if (res.data.success) {
alert(res.data.message);
document.getElementById('saveStatus').textContent = '저장 완료';
document.getElementById('saveStatus').style.color = '#10b981';
await loadData();
} else {
alert('저장 실패: ' + res.data.message);
}
} catch (error) {
console.error('저장 오류:', error);
alert('저장 중 오류: ' + (error.response?.data?.message || error.message));
}
}
</script>
</body>
</html>

View File

@@ -0,0 +1,398 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>출근 체크 | (주)테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<script src="https://instant.page/5.2.0" type="module"></script>
<style>
.page-wrapper {
padding: 1.5rem;
max-width: 1200px;
}
.page-title {
font-size: 1.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
}
.page-desc {
color: #64748b;
margin-bottom: 1.5rem;
}
.controls {
display: flex;
gap: 0.5rem;
margin-bottom: 1.5rem;
flex-wrap: wrap;
align-items: center;
}
.controls input[type="date"] {
padding: 0.5rem;
border: 1px solid #d1d5db;
border-radius: 0.375rem;
}
.btn {
padding: 0.5rem 1rem;
border: none;
border-radius: 0.375rem;
cursor: pointer;
font-size: 0.875rem;
}
.btn-primary { background: #3b82f6; color: white; }
.btn-outline { background: white; border: 1px solid #d1d5db; }
.btn-success { background: #10b981; color: white; }
/* 요약 바 */
.summary-bar {
display: flex;
gap: 1.5rem;
padding: 1rem;
background: white;
border-radius: 0.5rem;
margin-bottom: 1rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.summary-item {
display: flex;
align-items: center;
gap: 0.5rem;
}
.summary-dot {
width: 10px;
height: 10px;
border-radius: 50%;
}
.dot-present { background: #10b981; }
.dot-absent { background: #ef4444; }
.dot-vacation { background: #3b82f6; }
.summary-count { font-weight: 700; }
.summary-label { color: #6b7280; font-size: 0.875rem; }
/* 작업자 목록 */
.worker-list {
background: white;
border-radius: 0.5rem;
padding: 1rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.worker-chip {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.375rem 0.75rem;
margin: 0.25rem;
border: 2px solid #e5e7eb;
border-radius: 2rem;
background: white;
cursor: pointer;
font-size: 0.875rem;
transition: all 0.15s;
}
.worker-chip:hover {
border-color: #9ca3af;
}
.worker-chip.present {
border-color: #10b981;
background: #ecfdf5;
}
.worker-chip.absent {
border-color: #ef4444;
background: #fef2f2;
}
.worker-chip.vacation {
border-color: #3b82f6;
background: #eff6ff;
cursor: default;
}
.chip-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #d1d5db;
}
.worker-chip.present .chip-dot { background: #10b981; }
.worker-chip.absent .chip-dot { background: #ef4444; }
.worker-chip.vacation .chip-dot { background: #3b82f6; }
.save-section {
text-align: center;
margin-top: 1.5rem;
}
.btn-save {
padding: 0.75rem 2rem;
font-size: 1rem;
background: #3b82f6;
color: white;
border: none;
border-radius: 0.5rem;
cursor: pointer;
}
.btn-save:hover {
background: #2563eb;
}
.btn-save:disabled {
background: #9ca3af;
cursor: not-allowed;
}
.btn-save.saved {
background: #10b981;
}
.status-badge {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
font-size: 0.875rem;
font-weight: 500;
}
.status-badge.saved {
background: #dcfce7;
color: #166534;
}
.status-badge.unsaved {
background: #fef3c7;
color: #92400e;
}
</style>
</head>
<body class="has-sidebar">
<div id="navbar-container"></div>
<div id="sidebar-container"></div>
<main class="main-content">
<div class="page-wrapper">
<h1 class="page-title">출근 체크</h1>
<p class="page-desc">클릭하여 출근/결근 상태를 변경하세요</p>
<div class="controls">
<input type="date" id="selectedDate">
<button class="btn btn-primary" onclick="loadCheckinData()">새로고침</button>
<button class="btn btn-outline" onclick="setAllPresent()">전체 출근</button>
<button class="btn btn-outline" onclick="setAllAbsent()">전체 결근</button>
</div>
<div class="summary-bar">
<div class="summary-item">
<span class="summary-dot dot-present"></span>
<span class="summary-count" id="presentCount">0</span>
<span class="summary-label">출근</span>
</div>
<div class="summary-item">
<span class="summary-dot dot-absent"></span>
<span class="summary-count" id="absentCount">0</span>
<span class="summary-label">결근</span>
</div>
<div class="summary-item">
<span class="summary-dot dot-vacation"></span>
<span class="summary-count" id="vacationCount">0</span>
<span class="summary-label">연차</span>
</div>
</div>
<div class="worker-list" id="workerList">
<!-- 작업자 칩이 여기에 렌더링됩니다 -->
</div>
<div class="save-section">
<div id="saveStatus" style="margin-bottom: 1rem;"></div>
<button id="saveBtn" class="btn-save" onclick="saveCheckin()">출근 체크 저장</button>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script type="module">
</script>
<script>
(function() {
const checkApiConfig = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(checkApiConfig);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
}
}, 50);
})();
let workers = [];
let checkinStatus = {};
let isAlreadySaved = false;
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxiosConfig();
document.getElementById('selectedDate').value = new Date().toISOString().split('T')[0];
loadCheckinData();
// 날짜 변경 시 자동 로드
document.getElementById('selectedDate').addEventListener('change', loadCheckinData);
});
function waitForAxiosConfig() {
return new Promise((resolve) => {
const check = setInterval(() => {
if (axios.defaults.baseURL) {
clearInterval(check);
resolve();
}
}, 50);
setTimeout(() => { clearInterval(check); resolve(); }, 5000);
});
}
async function loadCheckinData() {
const selectedDate = document.getElementById('selectedDate').value;
if (!selectedDate) return alert('날짜를 선택해주세요.');
try {
const [workersRes, checkinRes, recordsRes] = await Promise.all([
axios.get('/workers?limit=100'),
axios.get(`/attendance/checkin-list?date=${selectedDate}`).catch(() => ({ data: { data: [] } })),
axios.get(`/attendance/daily-records?date=${selectedDate}`).catch(() => ({ data: { data: [] } }))
]);
const allWorkers = workersRes.data.data || [];
workers = allWorkers.filter(w => w.status === 'active' && (!w.employment_status || w.employment_status === 'employed'));
const checkinList = checkinRes.data.data || [];
const records = recordsRes.data.data || [];
// 이미 저장된 기록이 있는지 확인
isAlreadySaved = records.length > 0;
checkinStatus = {};
workers.forEach(w => {
const checkin = checkinList.find(c => c.worker_id === w.worker_id);
const record = records.find(r => r.worker_id === w.worker_id);
if (checkin?.vacation_status === 'approved' || record?.vacation_type_id) {
checkinStatus[w.worker_id] = { status: 'vacation', vacationType: checkin?.vacation_type_name || record?.vacation_type_name || '연차' };
} else if (record && record.is_present === 0) {
checkinStatus[w.worker_id] = { status: 'absent' };
} else if (record && record.is_present === 1) {
checkinStatus[w.worker_id] = { status: 'present' };
} else {
// 기록이 없으면 기본 출근
checkinStatus[w.worker_id] = { status: 'present' };
}
});
render();
updateSaveStatus();
} catch (e) {
console.error(e);
alert('데이터 로드 실패');
}
}
function render() {
const container = document.getElementById('workerList');
if (workers.length === 0) {
container.innerHTML = '<p style="color:#6b7280;text-align:center;padding:2rem;">작업자가 없습니다</p>';
return;
}
container.innerHTML = workers.map(w => {
const s = checkinStatus[w.worker_id] || { status: 'present' };
const label = s.status === 'present' ? '출근' : s.status === 'absent' ? '결근' : (s.vacationType || '연차');
return `<span class="worker-chip ${s.status}" onclick="toggle(${w.worker_id})"><span class="chip-dot"></span>${w.worker_name} <small style="color:#6b7280">${label}</small></span>`;
}).join('');
updateSummary();
}
function toggle(id) {
const s = checkinStatus[id];
if (s.status === 'vacation') return;
s.status = s.status === 'present' ? 'absent' : 'present';
render();
}
function setAllPresent() {
workers.forEach(w => {
if (checkinStatus[w.worker_id]?.status !== 'vacation') {
checkinStatus[w.worker_id] = { status: 'present' };
}
});
render();
}
function setAllAbsent() {
workers.forEach(w => {
if (checkinStatus[w.worker_id]?.status !== 'vacation') {
checkinStatus[w.worker_id] = { status: 'absent' };
}
});
render();
}
function updateSummary() {
let p = 0, a = 0, v = 0;
Object.values(checkinStatus).forEach(s => {
if (s.status === 'present') p++;
else if (s.status === 'absent') a++;
else v++;
});
document.getElementById('presentCount').textContent = p;
document.getElementById('absentCount').textContent = a;
document.getElementById('vacationCount').textContent = v;
}
function updateSaveStatus() {
const statusEl = document.getElementById('saveStatus');
const saveBtn = document.getElementById('saveBtn');
if (isAlreadySaved) {
statusEl.innerHTML = '<span class="status-badge saved">이 날짜는 이미 출근 체크가 완료되었습니다</span>';
saveBtn.textContent = '수정하여 다시 저장';
saveBtn.classList.add('saved');
} else {
statusEl.innerHTML = '<span class="status-badge unsaved">아직 저장되지 않았습니다</span>';
saveBtn.textContent = '출근 체크 저장';
saveBtn.classList.remove('saved');
}
}
async function saveCheckin() {
const date = document.getElementById('selectedDate').value;
if (!date) return alert('날짜를 선택해주세요.');
// 이미 저장된 경우 확인
if (isAlreadySaved) {
if (!confirm('이미 저장된 데이터가 있습니다.\n수정하시겠습니까?')) {
return;
}
}
// 연차가 아닌 작업자들만 체크인 데이터로 전송
const checkins = workers
.filter(w => checkinStatus[w.worker_id]?.status !== 'vacation')
.map(w => ({
worker_id: w.worker_id,
is_present: checkinStatus[w.worker_id]?.status === 'present'
}));
try {
const res = await axios.post('/attendance/checkins', { date, checkins });
if (res.data.success) {
alert(`${res.data.data.saved_count}명 출근 체크 저장 완료`);
isAlreadySaved = true;
updateSaveStatus();
} else {
alert('저장 실패: ' + (res.data.message || '알 수 없는 오류'));
}
} catch (e) {
console.error(e);
alert('저장 실패: ' + (e.response?.data?.message || e.message));
}
}
</script>
</body>
</html>

View File

@@ -0,0 +1,392 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>일일 출퇴근 입력 | (주)테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<script src="https://instant.page/5.2.0" type="module"></script>
</head>
<body>
<!-- 네비게이션 바 -->
<div id="navbar-container"></div>
<!-- 메인 콘텐츠 -->
<main class="main-content">
<div class="dashboard-main">
<div class="page-header">
<div class="page-title-section">
<h1 class="page-title">일일 출퇴근 입력</h1>
<p class="page-description">오늘 출근한 작업자들의 출퇴근 기록을 입력합니다</p>
</div>
<div class="page-actions">
<input type="date" id="selectedDate" class="form-control" style="width: auto;">
<button class="btn btn-primary" onclick="loadAttendanceRecords()">
새로고침
</button>
</div>
</div>
<!-- 출퇴근 입력 폼 -->
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">작업자 출퇴근 기록</h2>
<p class="text-muted">근태 구분을 선택하면 근무시간이 자동 입력됩니다. 연장근로는 별도로 입력 가능합니다. (조퇴: 2시간, 반반차: 6시간, 반차: 4시간, 정시: 8시간, 주말근무: 0시간)</p>
</div>
<div class="card-body">
<div id="attendanceList" class="data-table-container">
<!-- 출퇴근 기록 목록이 여기에 동적으로 렌더링됩니다 -->
</div>
<div style="text-align: center; margin-top: 2rem;">
<button class="btn btn-primary" onclick="saveAllAttendance()" style="padding: 1rem 3rem; font-size: 1.1rem;">
전체 저장
</button>
</div>
</div>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script type="module">
import '/js/api-config.js?v=3';
</script>
<script>
// axios 기본 설정
(function() {
const checkApiConfig = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(checkApiConfig);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
axios.interceptors.request.use(
config => {
const token = localStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
error => Promise.reject(error)
);
axios.interceptors.response.use(
response => response,
error => {
if (error.response?.status === 401) {
alert('세션이 만료되었습니다. 다시 로그인해주세요.');
window.location.href = '/pages/login.html';
}
return Promise.reject(error);
}
);
}
}, 50);
})();
</script>
<script>
// 전역 변수
let workers = [];
let attendanceRecords = [];
// 근태 구분 옵션 (근무시간 자동 설정, 연장근로는 별도 입력)
const attendanceTypes = [
{ value: 'on_time', label: '정시', hours: 8 },
{ value: 'half_leave', label: '반차', hours: 4 },
{ value: 'quarter_leave', label: '반반차', hours: 6 },
{ value: 'early_leave', label: '조퇴', hours: 2 },
{ value: 'weekend_work', label: '주말근무', hours: 0 },
{ value: 'annual_leave', label: '연차', hours: 0 },
{ value: 'custom', label: '특이사항', hours: 0 }
];
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxiosConfig();
initializePage();
});
function waitForAxiosConfig() {
return new Promise((resolve) => {
const check = setInterval(() => {
if (axios.defaults.baseURL) {
clearInterval(check);
resolve();
}
}, 50);
setTimeout(() => {
clearInterval(check);
resolve();
}, 5000);
});
}
async function initializePage() {
// 오늘 날짜 설정
const today = new Date().toISOString().split('T')[0];
document.getElementById('selectedDate').value = today;
try {
await loadWorkers();
await loadAttendanceRecords();
} catch (error) {
console.error('초기화 오류:', error);
alert('페이지 초기화 중 오류가 발생했습니다.');
}
}
async function loadWorkers() {
try {
const response = await axios.get('/workers?limit=100');
if (response.data.success) {
workers = response.data.data.filter(w => w.employment_status === 'employed');
}
} catch (error) {
console.error('작업자 목록 로드 오류:', error);
}
}
async function loadAttendanceRecords() {
const selectedDate = document.getElementById('selectedDate').value;
if (!selectedDate) {
alert('날짜를 선택해주세요.');
return;
}
try {
// 출퇴근 기록과 체크인 목록(휴가 정보 포함)을 동시에 가져오기
const [recordsResponse, checkinResponse] = await Promise.all([
axios.get(`/attendance/records?date=${selectedDate}`).catch(() => ({ data: { success: false, data: [] } })),
axios.get(`/attendance/checkin-list?date=${selectedDate}`).catch(() => ({ data: { success: false, data: [] } }))
]);
const existingRecords = recordsResponse.data.success ? recordsResponse.data.data : [];
const checkinList = checkinResponse.data.success ? checkinResponse.data.data : [];
// 체크인 목록을 기준으로 출퇴근 기록 생성 (연차 정보 포함)
attendanceRecords = checkinList.map(worker => {
const existingRecord = existingRecords.find(r => r.worker_id === worker.worker_id);
const isOnVacation = worker.vacation_status === 'approved';
// 기존 기록이 있으면 사용, 없으면 초기화
if (existingRecord) {
return existingRecord;
} else {
return {
worker_id: worker.worker_id,
worker_name: worker.worker_name,
attendance_date: selectedDate,
total_hours: isOnVacation ? 0 : 8,
overtime_hours: 0,
attendance_type: isOnVacation ? 'annual_leave' : 'on_time',
is_custom: false,
is_new: true,
is_on_vacation: isOnVacation,
vacation_type_name: worker.vacation_type_name
};
}
});
renderAttendanceList();
} catch (error) {
console.error('출퇴근 기록 로드 오류:', error);
alert('출퇴근 기록 조회 중 오류가 발생했습니다.');
}
}
function initializeAttendanceRecords() {
const selectedDate = document.getElementById('selectedDate').value;
attendanceRecords = workers.map(worker => ({
worker_id: worker.worker_id,
worker_name: worker.worker_name,
attendance_date: selectedDate,
total_hours: 8,
overtime_hours: 0,
attendance_type: 'on_time',
is_custom: false,
is_new: true
}));
renderAttendanceList();
}
function renderAttendanceList() {
const container = document.getElementById('attendanceList');
if (attendanceRecords.length === 0) {
container.innerHTML = `
<div class="empty-state">
<p>등록된 작업자가 없거나 출퇴근 기록이 없습니다.</p>
<button class="btn btn-primary" onclick="initializeAttendanceRecords()">
작업자 목록으로 초기화
</button>
</div>
`;
return;
}
const tableHTML = `
<table class="data-table" style="font-size: 0.95rem;">
<thead style="background-color: #f8f9fa;">
<tr>
<th style="width: 120px;">작업자</th>
<th style="width: 180px;">근태 구분</th>
<th style="width: 100px;">근무시간</th>
<th style="width: 120px;">연장근로</th>
<th style="width: 100px;">특이사항</th>
</tr>
</thead>
<tbody>
${attendanceRecords.map((record, index) => {
const isCustom = record.is_custom || record.attendance_type === 'custom';
const isHoursReadonly = !isCustom; // 특이사항이 아니면 근무시간은 읽기 전용
const isOnVacation = record.is_on_vacation || false;
const vacationLabel = record.vacation_type_name ? ` (${record.vacation_type_name})` : '';
return `
<tr style="border-bottom: 1px solid #e5e7eb; ${isOnVacation ? 'background-color: #f0f9ff;' : ''}">
<td style="padding: 0.75rem; font-weight: 600;">
${record.worker_name}
${isOnVacation ? `<span style="margin-left: 0.5rem; display: inline-block; padding: 0.125rem 0.5rem; background-color: #dbeafe; color: #1e40af; border-radius: 0.25rem; font-size: 0.75rem; font-weight: 500;">연차${vacationLabel}</span>` : ''}
</td>
<td style="padding: 0.75rem;">
<select class="form-control"
onchange="updateAttendanceType(${index}, this.value)"
style="width: 160px; padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 0.375rem;">
${attendanceTypes.map(type => `
<option value="${type.value}" ${record.attendance_type === type.value ? 'selected' : ''}>
${type.label}
</option>
`).join('')}
</select>
</td>
<td style="padding: 0.75rem;">
<input type="number" class="form-control"
id="hours_${index}"
value="${record.total_hours || 0}"
min="0" max="24" step="0.5"
${isHoursReadonly ? 'readonly' : ''}
onchange="updateTotalHours(${index}, this.value)"
style="width: 90px; padding: 0.5rem; border: 1px solid ${isHoursReadonly ? '#e5e7eb' : '#d1d5db'};
border-radius: 0.375rem; background-color: ${isHoursReadonly ? '#f9fafb' : 'white'}; text-align: center;">
</td>
<td style="padding: 0.75rem;">
<input type="number" class="form-control"
id="overtime_${index}"
value="${record.overtime_hours || 0}"
min="0" max="12" step="0.5"
onchange="updateOvertimeHours(${index}, this.value)"
style="width: 90px; padding: 0.5rem; border: 1px solid #d1d5db;
border-radius: 0.375rem; background-color: white; text-align: center;">
</td>
<td style="padding: 0.75rem; text-align: center;">
${isCustom ?
'<span style="color: #dc2626; font-weight: 600;">✓</span>' :
'<span style="color: #9ca3af;">-</span>'}
</td>
</tr>
`;
}).join('')}
</tbody>
</table>
`;
container.innerHTML = tableHTML;
}
function updateTotalHours(index, value) {
attendanceRecords[index].total_hours = parseFloat(value) || 0;
}
function updateOvertimeHours(index, value) {
attendanceRecords[index].overtime_hours = parseFloat(value) || 0;
}
function updateAttendanceType(index, value) {
const record = attendanceRecords[index];
record.attendance_type = value;
// 근태 구분에 따라 자동으로 근무시간 설정
const attendanceType = attendanceTypes.find(t => t.value === value);
if (value === 'custom') {
// 특이사항 선택 시 수동 입력 가능
record.is_custom = true;
// 기존 값 유지, 수동 입력 가능
} else if (attendanceType) {
// 다른 근태 구분 선택 시 근무시간만 자동 설정
record.is_custom = false;
record.total_hours = attendanceType.hours;
// 연장근로는 유지 (별도 입력 가능)
}
// UI 다시 렌더링
renderAttendanceList();
}
async function saveAllAttendance() {
const selectedDate = document.getElementById('selectedDate').value;
if (!selectedDate) {
alert('날짜를 선택해주세요.');
return;
}
if (attendanceRecords.length === 0) {
alert('저장할 출퇴근 기록이 없습니다.');
return;
}
// 모든 기록을 API 형식에 맞게 변환
const recordsToSave = attendanceRecords.map(record => ({
worker_id: record.worker_id,
attendance_date: selectedDate,
total_hours: record.total_hours || 0,
overtime_hours: record.overtime_hours || 0,
attendance_type: record.attendance_type || 'on_time',
is_custom: record.is_custom || false
}));
try {
// 각 기록을 순차적으로 저장
let successCount = 0;
let errorCount = 0;
for (const data of recordsToSave) {
try {
const response = await axios.post('/attendance/records', data);
if (response.data.success) {
successCount++;
}
} catch (error) {
console.error(`작업자 ${data.worker_id} 저장 오류:`, error);
errorCount++;
}
}
if (errorCount === 0) {
alert(`${successCount}건의 출퇴근 기록이 모두 저장되었습니다.`);
await loadAttendanceRecords(); // 저장 후 새로고침
} else {
alert(`${successCount}건 저장 완료, ${errorCount}건 저장 실패\n자세한 내용은 콘솔을 확인해주세요.`);
}
} catch (error) {
console.error('전체 저장 오류:', error);
alert('저장 중 오류가 발생했습니다.');
}
}
</script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,554 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>내 연차 정보 | 테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<style>
.page-wrapper {
padding: 1.5rem;
max-width: 1000px;
}
.page-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
}
.page-title { font-size: 1.5rem; font-weight: 700; margin: 0; }
.page-desc { color: #6b7280; font-size: 0.875rem; margin-top: 0.25rem; }
/* 작업자 선택 (관리자용) */
.admin-controls {
display: none;
gap: 0.5rem;
align-items: center;
margin-bottom: 1rem;
padding: 0.75rem 1rem;
background: #fef3c7;
border: 1px solid #f59e0b;
border-radius: 0.5rem;
}
.admin-controls.visible { display: flex; }
.admin-controls label { font-weight: 500; color: #92400e; }
.admin-controls select {
padding: 0.4rem 0.5rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
font-size: 0.875rem;
min-width: 150px;
}
/* 카드 그리드 */
.info-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1rem;
margin-bottom: 1.5rem;
}
/* 연차 카드 */
.vacation-card {
background: white;
border: 1px solid #e5e7eb;
border-radius: 0.75rem;
padding: 1.25rem;
}
.vacation-card h3 {
font-size: 0.9rem;
font-weight: 600;
margin: 0 0 1rem 0;
padding-bottom: 0.5rem;
border-bottom: 2px solid #3b82f6;
color: #1e40af;
}
.vacation-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 0;
border-bottom: 1px solid #f3f4f6;
}
.vacation-item:last-child { border-bottom: none; }
.vacation-item .label {
display: flex;
align-items: center;
gap: 0.5rem;
color: #374151;
font-size: 0.875rem;
}
.vacation-item .dot {
width: 10px;
height: 10px;
border-radius: 2px;
}
.dot-carryover { background: #fbbf24; }
.dot-annual { background: #3b82f6; }
.dot-longservice { background: #a855f7; }
.dot-special { background: #ec4899; }
.vacation-item .days {
font-weight: 700;
font-size: 1rem;
}
.days.positive { color: #059669; }
.days.zero { color: #9ca3af; }
.days.negative { color: #dc2626; }
/* 총 합계 */
.vacation-total {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 0.75rem;
padding-top: 0.75rem;
border-top: 2px solid #e5e7eb;
font-weight: 600;
}
.vacation-total .label { font-size: 0.9rem; color: #111827; }
.vacation-total .days { font-size: 1.25rem; }
/* 연장근로 카드 */
.overtime-card {
background: white;
border: 1px solid #e5e7eb;
border-radius: 0.75rem;
padding: 1.25rem;
}
.overtime-card h3 {
font-size: 0.9rem;
font-weight: 600;
margin: 0 0 1rem 0;
padding-bottom: 0.5rem;
border-bottom: 2px solid #f97316;
color: #c2410c;
}
.overtime-controls {
display: flex;
gap: 0.5rem;
margin-bottom: 1rem;
}
.overtime-controls select {
padding: 0.4rem 0.5rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
font-size: 0.875rem;
}
.overtime-summary {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 1rem;
margin-bottom: 1rem;
}
.overtime-stat {
text-align: center;
padding: 1rem;
background: #fff7ed;
border-radius: 0.5rem;
}
.overtime-stat .value {
font-size: 1.5rem;
font-weight: 700;
color: #ea580c;
}
.overtime-stat .label {
font-size: 0.75rem;
color: #9a3412;
margin-top: 0.25rem;
}
/* 월별 상세 */
.overtime-detail {
max-height: 200px;
overflow-y: auto;
}
.overtime-day {
display: flex;
justify-content: space-between;
padding: 0.4rem 0;
border-bottom: 1px solid #f3f4f6;
font-size: 0.8rem;
}
.overtime-day:last-child { border-bottom: none; }
.overtime-day .date { color: #6b7280; }
.overtime-day .hours { font-weight: 600; color: #ea580c; }
/* 로딩/에러 */
.loading, .error, .no-data {
text-align: center;
padding: 2rem;
color: #6b7280;
}
.error { color: #dc2626; }
/* 안내 메시지 */
.info-message {
padding: 1rem;
background: #eff6ff;
border: 1px solid #bfdbfe;
border-radius: 0.5rem;
color: #1e40af;
font-size: 0.875rem;
margin-bottom: 1rem;
}
</style>
</head>
<body class="has-sidebar">
<div id="navbar-container"></div>
<div id="sidebar-container"></div>
<main class="main-content">
<div class="page-wrapper">
<div class="page-header">
<div>
<h1 class="page-title">내 연차 정보</h1>
<p class="page-desc" id="workerNameDisplay">연차 잔여 현황 및 월간 연장근로 시간을 확인합니다</p>
</div>
</div>
<!-- 관리자용 작업자 선택 -->
<div class="admin-controls" id="adminControls">
<label>작업자 선택:</label>
<select id="workerSelect" onchange="onWorkerChange()">
<option value="">-- 선택 --</option>
</select>
</div>
<!-- 작업자 미연결 안내 -->
<div class="info-message" id="noWorkerMessage" style="display:none;">
현재 계정에 연결된 작업자 정보가 없습니다. 관리자에게 문의하세요.
</div>
<!-- 정보 그리드 -->
<div class="info-grid" id="infoGrid" style="display:none;">
<!-- 연차 잔여 현황 -->
<div class="vacation-card">
<h3 id="vacationCardTitle">연차 잔여 현황</h3>
<div id="vacationList">
<div class="loading">로딩 중...</div>
</div>
</div>
<!-- 월간 연장근로 -->
<div class="overtime-card">
<h3>월간 연장근로 현황</h3>
<div class="overtime-controls">
<select id="yearSelect" onchange="loadOvertimeData()"></select>
<select id="monthSelect" onchange="loadOvertimeData()"></select>
</div>
<div id="overtimeContent">
<div class="loading">로딩 중...</div>
</div>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
// axios 설정
(function() {
const check = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(check);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
}, 50);
})();
// 전역 변수
let currentUser = null;
let currentWorkerId = null;
let isAdmin = false;
let workers = [];
// 초기화
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxios();
await initPage();
});
function waitForAxios() {
return new Promise(resolve => {
const check = setInterval(() => {
if (axios.defaults.baseURL) { clearInterval(check); resolve(); }
}, 50);
setTimeout(() => { clearInterval(check); resolve(); }, 5000);
});
}
async function initPage() {
// 현재 사용자 정보 가져오기
const userStr = localStorage.getItem('user');
if (userStr) {
try {
currentUser = JSON.parse(userStr);
} catch (e) {
console.error('사용자 정보 파싱 실패');
}
}
// 관리자 여부 확인
const userRole = (currentUser?.role || currentUser?.access_level || '').toLowerCase();
isAdmin = ['admin', 'system admin', 'system', 'system_admin'].includes(userRole);
// 연도/월 선택기 초기화
initDateSelectors();
if (isAdmin) {
// 관리자: 작업자 선택 UI 표시
document.getElementById('adminControls').classList.add('visible');
await loadWorkers();
} else {
// 일반 사용자: 본인 worker_id 사용
if (currentUser?.worker_id) {
currentWorkerId = currentUser.worker_id;
document.getElementById('infoGrid').style.display = 'grid';
await loadAllData();
} else {
// worker_id가 없는 경우
document.getElementById('noWorkerMessage').style.display = 'block';
}
}
}
function initDateSelectors() {
const now = new Date();
const yearSelect = document.getElementById('yearSelect');
const monthSelect = document.getElementById('monthSelect');
// 연도 (올해 ± 1년)
for (let y = now.getFullYear() - 1; y <= now.getFullYear() + 1; y++) {
const opt = document.createElement('option');
opt.value = y;
opt.textContent = `${y}`;
if (y === now.getFullYear()) opt.selected = true;
yearSelect.appendChild(opt);
}
// 월
for (let m = 1; m <= 12; m++) {
const opt = document.createElement('option');
opt.value = m;
opt.textContent = `${m}`;
if (m === now.getMonth() + 1) opt.selected = true;
monthSelect.appendChild(opt);
}
}
async function loadWorkers() {
try {
const res = await axios.get('/workers?limit=100');
workers = (res.data.data || [])
.filter(w => w.status === 'active' && w.employment_status === 'employed')
.sort((a, b) => a.worker_name.localeCompare(b.worker_name, 'ko'));
const select = document.getElementById('workerSelect');
workers.forEach(w => {
const opt = document.createElement('option');
opt.value = w.worker_id;
opt.textContent = w.worker_name;
select.appendChild(opt);
});
} catch (e) {
console.error('작업자 목록 로드 실패:', e);
}
}
async function onWorkerChange() {
const workerId = document.getElementById('workerSelect').value;
if (!workerId) {
document.getElementById('infoGrid').style.display = 'none';
return;
}
currentWorkerId = parseInt(workerId);
const worker = workers.find(w => w.worker_id === currentWorkerId);
document.getElementById('workerNameDisplay').textContent =
`${worker?.worker_name || ''}님의 연차 잔여 현황 및 월간 연장근로 시간`;
document.getElementById('infoGrid').style.display = 'grid';
await loadAllData();
}
async function loadAllData() {
await Promise.all([
loadVacationData(),
loadOvertimeData()
]);
}
// ===== 연차 잔여 현황 =====
async function loadVacationData() {
const container = document.getElementById('vacationList');
container.innerHTML = '<div class="loading">로딩 중...</div>';
const year = new Date().getFullYear();
document.getElementById('vacationCardTitle').textContent = `연차 잔여 현황 (${year}년)`;
try {
const res = await axios.get(`/vacation-balances/worker/${currentWorkerId}/year/${year}`);
const balances = res.data.data || [];
if (balances.length === 0) {
container.innerHTML = '<div class="no-data">등록된 연차 정보가 없습니다</div>';
return;
}
// 유형별 정리
const typeOrder = ['CARRYOVER', 'ANNUAL', 'LONG_SERVICE'];
const typeNames = {
'CARRYOVER': '이월',
'ANNUAL': '정기연차',
'LONG_SERVICE': '장기근속'
};
const dotClasses = {
'CARRYOVER': 'dot-carryover',
'ANNUAL': 'dot-annual',
'LONG_SERVICE': 'dot-longservice'
};
let totalDays = 0;
let usedDays = 0;
let html = '';
// 정렬된 순서로 표시
const sortedBalances = balances.sort((a, b) => {
const aIdx = typeOrder.indexOf(a.type_code);
const bIdx = typeOrder.indexOf(b.type_code);
if (aIdx === -1 && bIdx === -1) return 0;
if (aIdx === -1) return 1;
if (bIdx === -1) return -1;
return aIdx - bIdx;
});
sortedBalances.forEach(b => {
const total = parseFloat(b.total_days) || 0;
const used = parseFloat(b.used_days) || 0;
const remaining = total - used;
totalDays += total;
usedDays += used;
const dotClass = dotClasses[b.type_code] || 'dot-special';
const typeName = typeNames[b.type_code] || b.type_name || b.type_code;
const remainingClass = remaining > 0 ? 'positive' : remaining < 0 ? 'negative' : 'zero';
html += `
<div class="vacation-item">
<span class="label">
<span class="dot ${dotClass}"></span>
${typeName}
</span>
<span class="days ${remainingClass}">
${remaining.toFixed(1)}
<small style="color:#9ca3af;font-weight:normal;">(${total.toFixed(1)} - ${used.toFixed(1)})</small>
</span>
</div>
`;
});
// 총 합계
const totalRemaining = totalDays - usedDays;
const totalClass = totalRemaining > 0 ? 'positive' : totalRemaining < 0 ? 'negative' : 'zero';
html += `
<div class="vacation-total">
<span class="label">총 잔여</span>
<span class="days ${totalClass}">${totalRemaining.toFixed(1)}일</span>
</div>
`;
container.innerHTML = html;
} catch (e) {
console.error('연차 데이터 로드 실패:', e);
container.innerHTML = '<div class="error">데이터를 불러오는데 실패했습니다</div>';
}
}
// ===== 월간 연장근로 =====
async function loadOvertimeData() {
const container = document.getElementById('overtimeContent');
container.innerHTML = '<div class="loading">로딩 중...</div>';
const year = parseInt(document.getElementById('yearSelect').value);
const month = parseInt(document.getElementById('monthSelect').value);
// 해당 월의 시작일/종료일
const startDate = `${year}-${String(month).padStart(2, '0')}-01`;
const lastDay = new Date(year, month, 0).getDate();
const endDate = `${year}-${String(month).padStart(2, '0')}-${lastDay}`;
try {
// 근태 기록에서 연장근로 데이터 조회
const res = await axios.get(`/attendance/records?start_date=${startDate}&end_date=${endDate}&worker_id=${currentWorkerId}`);
const records = res.data.data || [];
// 8시간 초과분 계산
let totalOvertimeHours = 0;
const overtimeDays = [];
records.forEach(r => {
const hours = parseFloat(r.total_work_hours) || 0;
if (hours > 8) {
const overtime = hours - 8;
totalOvertimeHours += overtime;
overtimeDays.push({
date: r.record_date,
hours: overtime
});
}
});
// 총 근무일수
const workDays = records.filter(r => (parseFloat(r.total_work_hours) || 0) > 0).length;
// 렌더링
let html = `
<div class="overtime-summary">
<div class="overtime-stat">
<div class="value">${totalOvertimeHours.toFixed(1)}h</div>
<div class="label">총 연장근로</div>
</div>
<div class="overtime-stat">
<div class="value">${overtimeDays.length}일</div>
<div class="label">연장근로 일수</div>
</div>
</div>
`;
if (overtimeDays.length > 0) {
html += '<div class="overtime-detail">';
overtimeDays.sort((a, b) => a.date.localeCompare(b.date)).forEach(d => {
const dateObj = new Date(d.date);
const dayNames = ['일', '월', '화', '수', '목', '금', '토'];
const dayName = dayNames[dateObj.getDay()];
const displayDate = `${dateObj.getMonth() + 1}/${dateObj.getDate()} (${dayName})`;
html += `
<div class="overtime-day">
<span class="date">${displayDate}</span>
<span class="hours">+${d.hours.toFixed(1)}h</span>
</div>
`;
});
html += '</div>';
} else {
html += '<div class="no-data" style="padding:1rem;">연장근로 기록이 없습니다</div>';
}
container.innerHTML = html;
} catch (e) {
console.error('연장근로 데이터 로드 실패:', e);
container.innerHTML = '<div class="error">데이터를 불러오는데 실패했습니다</div>';
}
}
</script>
</body>
</html>

View File

@@ -0,0 +1,354 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>휴가 발생 입력 | 테크니컬코리아</title>
<!-- 모던 디자인 시스템 적용 -->
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/vacation-allocation.css">
<link rel="icon" type="image/png" href="/img/favicon.png">
<!-- 스크립트 -->
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<script src="https://instant.page/5.2.0" type="module"></script>
<script type="module" src="/js/vacation-allocation.js" defer></script>
</head>
<body>
<!-- 메인 컨테이너 -->
<div class="page-container">
<!-- 네비게이션 헤더 -->
<div id="navbar-container"></div>
<!-- 메인 콘텐츠 -->
<main class="main-content">
<div class="content-wrapper">
<!-- 페이지 헤더 -->
<div class="page-header">
<h1 class="page-title">휴가 발생 입력</h1>
<p class="page-description">작업자별 휴가를 입력하고 특별 휴가를 관리합니다</p>
</div>
<!-- 탭 네비게이션 -->
<div class="tab-navigation">
<button class="tab-button active" data-tab="individual">개별 입력</button>
<button class="tab-button" data-tab="bulk">일괄 입력</button>
<button class="tab-button" data-tab="special">특별 휴가 관리</button>
</div>
<!-- 탭 1: 개별 입력 -->
<section id="tab-individual" class="tab-content active">
<div class="card">
<div class="card-header">
<h2 class="card-title">개별 작업자 휴가 입력</h2>
</div>
<div class="card-body">
<!-- 입력 폼 -->
<div class="form-section">
<div class="form-row">
<div class="form-group">
<label for="individualWorker">작업자 선택 <span class="required">*</span></label>
<select id="individualWorker" class="form-select" required>
<option value="">선택하세요</option>
<!-- JavaScript로 동적 생성 -->
</select>
</div>
<div class="form-group">
<label for="individualYear">연도 <span class="required">*</span></label>
<select id="individualYear" class="form-select" required>
<!-- JavaScript로 동적 생성 -->
</select>
</div>
<div class="form-group">
<label for="individualVacationType">휴가 유형 <span class="required">*</span></label>
<select id="individualVacationType" class="form-select" required>
<option value="">선택하세요</option>
<!-- JavaScript로 동적 생성 -->
</select>
</div>
</div>
<!-- 자동 계산 섹션 -->
<div class="auto-calculate-section">
<div class="section-header">
<h3>자동 계산 (연차만 해당)</h3>
<button id="autoCalculateBtn" class="btn btn-secondary btn-sm">
입사일 기준 자동 계산
</button>
</div>
<div id="autoCalculateResult" class="alert alert-info" style="display: none;">
<!-- 계산 결과 표시 -->
</div>
</div>
<!-- 수동 입력 -->
<div class="form-row">
<div class="form-group">
<label for="individualTotalDays">총 부여 일수 <span class="required">*</span></label>
<input type="number" id="individualTotalDays" class="form-input" min="0" step="0.5" required>
</div>
<div class="form-group">
<label for="individualUsedDays">사용 일수</label>
<input type="number" id="individualUsedDays" class="form-input" min="0" step="0.5" value="0">
</div>
<div class="form-group full-width">
<label for="individualNotes">비고</label>
<input type="text" id="individualNotes" class="form-input" placeholder="예: 2026년 연차">
</div>
</div>
<div class="form-actions">
<button id="individualSubmitBtn" class="btn btn-primary">
저장
</button>
<button id="individualResetBtn" class="btn btn-secondary">
초기화
</button>
</div>
</div>
<!-- 기존 데이터 테이블 -->
<div class="existing-data-section">
<h3>기존 입력 내역</h3>
<div class="table-responsive">
<table class="data-table">
<thead>
<tr>
<th>작업자</th>
<th>연도</th>
<th>휴가 유형</th>
<th>총 일수</th>
<th>사용 일수</th>
<th>잔여 일수</th>
<th>비고</th>
<th>작업</th>
</tr>
</thead>
<tbody id="individualTableBody">
<tr>
<td colspan="8" class="loading-state">
<p>작업자를 선택하세요</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<!-- 탭 2: 일괄 입력 -->
<section id="tab-bulk" class="tab-content">
<div class="card">
<div class="card-header">
<h2 class="card-title">근속년수별 연차 일괄 생성</h2>
</div>
<div class="card-body">
<div class="alert alert-warning">
<strong>주의:</strong> 이 기능은 연차(ANNUAL) 휴가 유형만 생성합니다. 각 작업자의 입사일을 기준으로 근속년수를 계산하여 자동으로 연차를 부여합니다.
</div>
<div class="form-section">
<div class="form-row">
<div class="form-group">
<label for="bulkYear">대상 연도 <span class="required">*</span></label>
<select id="bulkYear" class="form-select" required>
<!-- JavaScript로 동적 생성 -->
</select>
</div>
<div class="form-group">
<label for="bulkEmploymentStatus">재직 상태</label>
<select id="bulkEmploymentStatus" class="form-select">
<option value="employed">재직 중만</option>
<option value="all">전체</option>
</select>
</div>
</div>
<div class="form-actions">
<button id="bulkPreviewBtn" class="btn btn-secondary">
미리보기
</button>
<button id="bulkSubmitBtn" class="btn btn-primary" disabled>
일괄 생성
</button>
</div>
</div>
<!-- 미리보기 테이블 -->
<div id="bulkPreviewSection" class="preview-section" style="display: none;">
<h3>생성 예정 내역</h3>
<div class="table-responsive">
<table class="data-table">
<thead>
<tr>
<th>작업자</th>
<th>입사일</th>
<th>근속년수</th>
<th>부여 연차</th>
<th>계산 근거</th>
<th>상태</th>
</tr>
</thead>
<tbody id="bulkPreviewTableBody">
<!-- JavaScript로 동적 생성 -->
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<!-- 탭 3: 특별 휴가 관리 -->
<section id="tab-special" class="tab-content">
<div class="card">
<div class="card-header">
<h2 class="card-title">특별 휴가 유형 관리</h2>
<button id="addSpecialTypeBtn" class="btn btn-primary btn-sm">
+ 새 휴가 유형 추가
</button>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="data-table">
<thead>
<tr>
<th>유형명</th>
<th>코드</th>
<th>우선순위</th>
<th>특별 휴가</th>
<th>시스템 유형</th>
<th>설명</th>
<th>작업</th>
</tr>
</thead>
<tbody id="specialTypesTableBody">
<tr>
<td colspan="7" class="loading-state">
<div class="spinner"></div>
<p>데이터를 불러오는 중...</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
</div>
</main>
</div>
<!-- 알림 토스트 -->
<div class="toast-container" id="toastContainer"></div>
<!-- 모달: 휴가 유형 추가/수정 -->
<div id="vacationTypeModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h3 id="modalTitle">휴가 유형 추가</h3>
<button class="modal-close">&times;</button>
</div>
<div class="modal-body">
<form id="vacationTypeForm">
<input type="hidden" id="modalTypeId">
<div class="form-group">
<label for="modalTypeName">유형명 <span class="required">*</span></label>
<input type="text" id="modalTypeName" class="form-input" required>
</div>
<div class="form-group">
<label for="modalTypeCode">코드 <span class="required">*</span></label>
<input type="text" id="modalTypeCode" class="form-input" required>
<small>예: ANNUAL, SICK, MATERNITY (영문 대문자)</small>
</div>
<div class="form-row">
<div class="form-group">
<label for="modalPriority">우선순위 <span class="required">*</span></label>
<input type="number" id="modalPriority" class="form-input" min="1" required>
<small>낮을수록 먼저 차감</small>
</div>
<div class="form-group">
<label>
<input type="checkbox" id="modalIsSpecial">
특별 휴가
</label>
</div>
</div>
<div class="form-group">
<label for="modalDescription">설명</label>
<textarea id="modalDescription" class="form-input" rows="3"></textarea>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">저장</button>
<button type="button" class="btn btn-secondary modal-close">취소</button>
</div>
</form>
</div>
</div>
</div>
<!-- 모달: 휴가 수정 -->
<div id="editBalanceModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h3>휴가 수정</h3>
<button class="modal-close">&times;</button>
</div>
<div class="modal-body">
<form id="editBalanceForm">
<input type="hidden" id="editBalanceId">
<div class="form-group">
<label for="editTotalDays">총 일수 <span class="required">*</span></label>
<input type="number" id="editTotalDays" class="form-input" min="0" step="0.5" required>
</div>
<div class="form-group">
<label for="editUsedDays">사용 일수 <span class="required">*</span></label>
<input type="number" id="editUsedDays" class="form-input" min="0" step="0.5" required>
</div>
<div class="form-group">
<label for="editNotes">비고</label>
<input type="text" id="editNotes" class="form-input">
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">저장</button>
<button type="button" class="btn btn-secondary modal-close">취소</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,264 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>휴가 승인 관리 | (주)테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<script src="https://instant.page/5.2.0" type="module"></script>
<style>
.tabs {
display: flex;
gap: 0.5rem;
margin-bottom: 1.5rem;
border-bottom: 2px solid #e5e7eb;
}
.tab {
padding: 0.75rem 1.5rem;
background: none;
border: none;
border-bottom: 2px solid transparent;
cursor: pointer;
font-weight: 500;
color: #6b7280;
transition: all 0.2s;
}
.tab:hover {
color: #111827;
}
.tab.active {
color: #3b82f6;
border-bottom-color: #3b82f6;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
</style>
</head>
<body>
<!-- 네비게이션 바 -->
<div id="navbar-container"></div>
<!-- 메인 콘텐츠 -->
<main class="main-content">
<div class="dashboard-main">
<div class="page-header">
<div class="page-title-section">
<h1 class="page-title">휴가 승인 관리</h1>
<p class="page-description">휴가 신청을 승인하거나 거부합니다</p>
</div>
</div>
<!-- 탭 메뉴 -->
<div class="tabs">
<button class="tab active" onclick="switchTab('pending')">승인 대기 목록</button>
<button class="tab" onclick="switchTab('all')">전체 신청 내역</button>
</div>
<!-- 승인 대기 목록 탭 -->
<div id="pendingTab" class="tab-content active">
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">승인 대기 목록</h2>
<p class="text-muted">대기 중인 휴가 신청을 승인하거나 거부할 수 있습니다</p>
</div>
<div class="card-body">
<div id="pendingRequestsList" class="data-table-container">
<!-- 승인 대기 목록이 여기에 동적으로 렌더링됩니다 -->
</div>
</div>
</div>
</div>
</div>
<!-- 전체 신청 내역 탭 -->
<div id="allTab" class="tab-content">
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">전체 신청 내역</h2>
<div class="page-actions">
<input type="date" id="filterStartDate" class="form-control" style="width: auto;">
<span style="margin: 0 0.5rem;">~</span>
<input type="date" id="filterEndDate" class="form-control" style="width: auto;">
<button class="btn btn-secondary" onclick="filterAllRequests()">
조회
</button>
<button class="btn btn-secondary" onclick="resetFilter()">
전체
</button>
</div>
</div>
<div class="card-body">
<div id="allRequestsList" class="data-table-container">
<!-- 전체 신청 내역이 여기에 동적으로 렌더링됩니다 -->
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/js/vacation-common.js"></script>
<script type="module">
import '/js/api-config.js?v=3';
</script>
<script>
// axios 기본 설정
(function() {
const checkApiConfig = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(checkApiConfig);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
axios.interceptors.request.use(
config => {
const token = localStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
error => Promise.reject(error)
);
axios.interceptors.response.use(
response => response,
error => {
if (error.response?.status === 401) {
alert('세션이 만료되었습니다. 다시 로그인해주세요.');
window.location.href = '/pages/login.html';
}
return Promise.reject(error);
}
);
}
}, 50);
})();
</script>
<script>
let allRequestsData = [];
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxiosConfig();
initializePage();
});
async function initializePage() {
try {
const currentUser = getCurrentUser();
// 관리자 권한 체크
if (currentUser.access_level !== 'system' && currentUser.access_level !== 'admin') {
alert('관리자만 접근할 수 있습니다.');
window.location.href = '/pages/attendance/vacation-request.html';
return;
}
await loadPendingRequests();
await loadAllRequests();
// 휴가 업데이트 이벤트 리스너
window.addEventListener('vacation-updated', () => {
loadPendingRequests();
loadAllRequests();
});
// 날짜 필터 초기화 (최근 3개월)
const today = new Date();
const threeMonthsAgo = new Date();
threeMonthsAgo.setMonth(today.getMonth() - 3);
document.getElementById('filterStartDate').value = threeMonthsAgo.toISOString().split('T')[0];
document.getElementById('filterEndDate').value = today.toISOString().split('T')[0];
} catch (error) {
console.error('초기화 오류:', error);
alert('페이지 초기화 중 오류가 발생했습니다.');
}
}
function switchTab(tabName) {
// 모든 탭과 컨텐츠 비활성화
document.querySelectorAll('.tab').forEach(tab => tab.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
// 선택한 탭 활성화
if (tabName === 'pending') {
document.querySelector('.tab:nth-child(1)').classList.add('active');
document.getElementById('pendingTab').classList.add('active');
} else if (tabName === 'all') {
document.querySelector('.tab:nth-child(2)').classList.add('active');
document.getElementById('allTab').classList.add('active');
}
}
async function loadPendingRequests() {
try {
const response = await axios.get('/vacation-requests/pending');
if (response.data.success) {
renderVacationRequests(response.data.data, 'pendingRequestsList', true, 'approval');
}
} catch (error) {
console.error('승인 대기 목록 로드 오류:', error);
document.getElementById('pendingRequestsList').innerHTML = `
<div class="empty-state">
<p>승인 대기 중인 신청이 없습니다.</p>
</div>
`;
}
}
async function loadAllRequests() {
try {
const response = await axios.get('/vacation-requests');
if (response.data.success) {
allRequestsData = response.data.data;
renderVacationRequests(allRequestsData, 'allRequestsList', false);
}
} catch (error) {
console.error('전체 신청 내역 로드 오류:', error);
document.getElementById('allRequestsList').innerHTML = `
<div class="empty-state">
<p>신청 내역이 없습니다.</p>
</div>
`;
}
}
function filterAllRequests() {
const startDate = document.getElementById('filterStartDate').value;
const endDate = document.getElementById('filterEndDate').value;
if (!startDate || !endDate) {
alert('시작일과 종료일을 모두 선택해주세요.');
return;
}
const filtered = allRequestsData.filter(req => {
return req.start_date >= startDate && req.start_date <= endDate;
});
renderVacationRequests(filtered, 'allRequestsList', false);
}
function resetFilter() {
renderVacationRequests(allRequestsData, 'allRequestsList', false);
}
</script>
</body>
</html>

View File

@@ -0,0 +1,291 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>휴가 직접 입력 | (주)테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<script src="https://instant.page/5.2.0" type="module"></script>
</head>
<body>
<!-- 네비게이션 바 -->
<div id="navbar-container"></div>
<!-- 메인 콘텐츠 -->
<main class="main-content">
<div class="dashboard-main">
<div class="page-header">
<div class="page-title-section">
<h1 class="page-title">휴가 직접 입력</h1>
<p class="page-description">관리자 권한으로 작업자의 휴가 정보를 직접 입력합니다</p>
</div>
</div>
<!-- 휴가 직접 입력 폼 -->
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">휴가 정보 입력</h2>
<p class="text-muted">승인 절차 없이 휴가 정보를 직접 입력합니다. 입력 즉시 승인 상태로 저장됩니다.</p>
</div>
<div class="card-body">
<form id="vacationInputForm" onsubmit="submitVacationInput(event)">
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem;">
<div class="form-group">
<label for="inputWorker">작업자 *</label>
<select id="inputWorker" class="form-control" required onchange="updateVacationBalance()">
<option value="">선택하세요</option>
</select>
</div>
<div class="form-group">
<label for="inputVacationType">휴가 유형 *</label>
<select id="inputVacationType" class="form-control" required>
<option value="">선택하세요</option>
</select>
</div>
<div class="form-group">
<label for="inputStartDate">시작일 *</label>
<input type="date" id="inputStartDate" class="form-control" required>
</div>
<div class="form-group">
<label for="inputEndDate">종료일 *</label>
<input type="date" id="inputEndDate" class="form-control" required>
</div>
<div class="form-group">
<label for="inputDaysUsed">사용 일수 *</label>
<input type="number" id="inputDaysUsed" class="form-control" min="0.5" step="0.5" value="1.0" required>
</div>
<div class="form-group">
<label>작업자 휴가 잔여</label>
<div id="workerVacationBalance" style="padding: 0.75rem; background-color: #f9fafb; border-radius: 0.375rem; border: 1px solid #e5e7eb;">
<span class="text-muted">작업자를 선택하세요</span>
</div>
</div>
<div class="form-group" style="grid-column: 1 / -1;">
<label for="inputReason">사유</label>
<textarea id="inputReason" class="form-control" rows="3" placeholder="휴가 사유를 입력하세요 (선택)"></textarea>
</div>
</div>
<div style="text-align: center; margin-top: 2rem;">
<button type="submit" class="btn btn-primary" style="padding: 1rem 3rem;">
즉시 입력 (자동 승인)
</button>
</div>
</form>
</div>
</div>
</div>
<!-- 최근 입력 내역 -->
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">최근 입력 내역</h2>
<div class="page-actions">
<button class="btn btn-secondary" onclick="loadRecentInputs()">
새로고침
</button>
</div>
</div>
<div class="card-body">
<div id="recentInputsList" class="data-table-container">
<!-- 최근 입력 내역이 여기에 동적으로 렌더링됩니다 -->
</div>
</div>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/js/vacation-common.js"></script>
<script type="module">
import '/js/api-config.js?v=3';
</script>
<script>
// axios 기본 설정
(function() {
const checkApiConfig = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(checkApiConfig);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
axios.interceptors.request.use(
config => {
const token = localStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
error => Promise.reject(error)
);
axios.interceptors.response.use(
response => response,
error => {
if (error.response?.status === 401) {
alert('세션이 만료되었습니다. 다시 로그인해주세요.');
window.location.href = '/pages/login.html';
}
return Promise.reject(error);
}
);
}
}, 50);
})();
</script>
<script>
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxiosConfig();
initializePage();
});
async function initializePage() {
try {
const currentUser = getCurrentUser();
// 관리자 권한 체크
if (currentUser.access_level !== 'system' && currentUser.access_level !== 'admin') {
alert('관리자만 접근할 수 있습니다.');
window.location.href = '/pages/attendance/vacation-request.html';
return;
}
await loadWorkers();
await loadVacationTypes();
await loadRecentInputs();
// 휴가 업데이트 이벤트 리스너
window.addEventListener('vacation-updated', loadRecentInputs);
} catch (error) {
console.error('초기화 오류:', error);
alert('페이지 초기화 중 오류가 발생했습니다.');
}
}
async function updateVacationBalance() {
const workerId = document.getElementById('inputWorker').value;
const balanceDiv = document.getElementById('workerVacationBalance');
if (!workerId) {
balanceDiv.innerHTML = '<span class="text-muted">작업자를 선택하세요</span>';
return;
}
try {
const response = await axios.get(`/attendance/vacation-balance/${workerId}`);
if (response.data.success) {
const balance = response.data.data;
if (!balance || Object.keys(balance).length === 0) {
balanceDiv.innerHTML = '<span class="text-muted">휴가 잔여 정보가 없습니다</span>';
return;
}
const balanceHTML = Object.keys(balance).map(key => {
const info = balance[key];
return `
<div style="display: inline-block; margin-right: 1rem;">
<span style="color: #6b7280; font-size: 0.875rem;">${key}:</span>
<strong style="color: #111827; font-size: 1rem; margin-left: 0.25rem;">${info.remaining || 0}일</strong>
<span style="color: #9ca3af; font-size: 0.75rem; margin-left: 0.25rem;">(전체: ${info.total || 0}일)</span>
</div>
`;
}).join('');
balanceDiv.innerHTML = balanceHTML;
}
} catch (error) {
console.error('휴가 잔여 조회 오류:', error);
balanceDiv.innerHTML = '<span class="text-muted" style="color: #dc2626;">조회 실패</span>';
}
}
async function submitVacationInput(event) {
event.preventDefault();
const data = {
worker_id: parseInt(document.getElementById('inputWorker').value),
vacation_type_id: parseInt(document.getElementById('inputVacationType').value),
start_date: document.getElementById('inputStartDate').value,
end_date: document.getElementById('inputEndDate').value,
days_used: parseFloat(document.getElementById('inputDaysUsed').value),
reason: document.getElementById('inputReason').value || null,
auto_approve: true // 자동 승인 플래그
};
if (!confirm(`${document.getElementById('inputWorker').selectedOptions[0].text}의 휴가를 즉시 입력하시겠습니까?\n\n입력 즉시 승인 상태로 저장됩니다.`)) {
return;
}
try {
// 휴가 신청 생성
const response = await axios.post('/vacation-requests', data);
if (response.data.success) {
const requestId = response.data.data.request_id;
// 즉시 승인 처리
try {
const approveResponse = await axios.patch(`/vacation-requests/${requestId}/approve`);
if (approveResponse.data.success) {
alert('휴가 정보가 입력되고 자동 승인되었습니다.');
document.getElementById('vacationInputForm').reset();
document.getElementById('workerVacationBalance').innerHTML = '<span class="text-muted">작업자를 선택하세요</span>';
window.dispatchEvent(new Event('vacation-updated'));
}
} catch (approveError) {
console.error('자동 승인 오류:', approveError);
alert('휴가 정보는 입력되었으나 자동 승인에 실패했습니다. 승인 관리 페이지에서 수동으로 승인해주세요.');
}
}
} catch (error) {
console.error('휴가 입력 오류:', error);
alert(error.response?.data?.message || '휴가 입력 중 오류가 발생했습니다.');
}
}
async function loadRecentInputs() {
try {
const response = await axios.get('/vacation-requests');
if (response.data.success) {
// 최근 30일 이내 승인된 항목만 표시
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
const thirtyDaysAgoStr = thirtyDaysAgo.toISOString().split('T')[0];
const recentApproved = response.data.data.filter(req =>
req.status === 'approved' &&
req.created_at >= thirtyDaysAgoStr
).slice(0, 20); // 최근 20개만
renderVacationRequests(recentApproved, 'recentInputsList', false);
}
} catch (error) {
console.error('최근 입력 내역 로드 오류:', error);
document.getElementById('recentInputsList').innerHTML = `
<div class="empty-state">
<p>최근 입력 내역이 없습니다.</p>
</div>
`;
}
}
</script>
</body>
</html>

View File

@@ -0,0 +1,458 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>휴가 관리 | (주)테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<script src="https://instant.page/5.2.0" type="module"></script>
<style>
.tabs {
display: flex;
gap: 0.5rem;
margin-bottom: 1.5rem;
border-bottom: 2px solid #e5e7eb;
}
.tab {
padding: 0.75rem 1.5rem;
background: none;
border: none;
border-bottom: 2px solid transparent;
cursor: pointer;
font-weight: 500;
color: #6b7280;
transition: all 0.2s;
}
.tab:hover {
color: #111827;
}
.tab.active {
color: #3b82f6;
border-bottom-color: #3b82f6;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
</style>
</head>
<body>
<!-- 네비게이션 바 -->
<div id="navbar-container"></div>
<!-- 메인 콘텐츠 -->
<main class="main-content">
<div class="dashboard-main">
<div class="page-header">
<div class="page-title-section">
<h1 class="page-title">휴가 관리</h1>
<p class="page-description">휴가 신청을 승인하고 작업자 휴가 정보를 관리합니다</p>
</div>
</div>
<!-- 탭 메뉴 -->
<div class="tabs">
<button class="tab active" onclick="switchTab('approval')">승인 대기 목록</button>
<button class="tab" onclick="switchTab('input')">직접 입력</button>
<button class="tab" onclick="switchTab('all')">전체 신청 내역</button>
</div>
<!-- 승인 대기 목록 탭 -->
<div id="approvalTab" class="tab-content active">
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">승인 대기 목록</h2>
<p class="text-muted">대기 중인 휴가 신청을 승인하거나 거부할 수 있습니다</p>
</div>
<div class="card-body">
<div id="pendingRequestsList" class="data-table-container">
<!-- 승인 대기 목록이 여기에 동적으로 렌더링됩니다 -->
</div>
</div>
</div>
</div>
</div>
<!-- 직접 입력 탭 -->
<div id="inputTab" class="tab-content">
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">휴가 정보 직접 입력</h2>
<p class="text-muted">승인 절차 없이 휴가 정보를 직접 입력합니다. 입력 즉시 승인 상태로 저장됩니다.</p>
</div>
<div class="card-body">
<form id="vacationInputForm" onsubmit="submitVacationInput(event)">
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem;">
<div class="form-group">
<label for="inputWorker">작업자 *</label>
<select id="inputWorker" class="form-control" required onchange="updateVacationBalance()">
<option value="">선택하세요</option>
</select>
</div>
<div class="form-group">
<label for="inputVacationType">휴가 유형 *</label>
<select id="inputVacationType" class="form-control" required>
<option value="">선택하세요</option>
</select>
</div>
<div class="form-group">
<label for="inputStartDate">시작일 *</label>
<input type="date" id="inputStartDate" class="form-control" required>
</div>
<div class="form-group">
<label for="inputEndDate">종료일 *</label>
<input type="date" id="inputEndDate" class="form-control" required>
</div>
<div class="form-group">
<label for="inputDaysUsed">사용 일수 *</label>
<input type="number" id="inputDaysUsed" class="form-control" min="0.5" step="0.5" value="1.0" required>
</div>
<div class="form-group">
<label>작업자 휴가 잔여</label>
<div id="workerVacationBalance" style="padding: 0.75rem; background-color: #f9fafb; border-radius: 0.375rem; border: 1px solid #e5e7eb;">
<span class="text-muted">작업자를 선택하세요</span>
</div>
</div>
<div class="form-group" style="grid-column: 1 / -1;">
<label for="inputReason">사유</label>
<textarea id="inputReason" class="form-control" rows="3" placeholder="휴가 사유를 입력하세요 (선택)"></textarea>
</div>
</div>
<div style="text-align: center; margin-top: 2rem;">
<button type="submit" class="btn btn-primary" style="padding: 1rem 3rem;">
즉시 입력 (자동 승인)
</button>
</div>
</form>
</div>
</div>
<!-- 최근 입력 내역 -->
<div class="card" style="margin-top: 2rem;">
<div class="card-header">
<h2 class="card-title">최근 입력 내역</h2>
<div class="page-actions">
<button class="btn btn-secondary" onclick="loadRecentInputs()">
새로고침
</button>
</div>
</div>
<div class="card-body">
<div id="recentInputsList" class="data-table-container">
<!-- 최근 입력 내역이 여기에 동적으로 렌더링됩니다 -->
</div>
</div>
</div>
</div>
</div>
<!-- 전체 신청 내역 탭 -->
<div id="allTab" class="tab-content">
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">전체 신청 내역</h2>
<div class="page-actions">
<input type="date" id="filterStartDate" class="form-control" style="width: auto;">
<span style="margin: 0 0.5rem;">~</span>
<input type="date" id="filterEndDate" class="form-control" style="width: auto;">
<button class="btn btn-secondary" onclick="filterAllRequests()">
조회
</button>
<button class="btn btn-secondary" onclick="resetFilter()">
전체
</button>
</div>
</div>
<div class="card-body">
<div id="allRequestsList" class="data-table-container">
<!-- 전체 신청 내역이 여기에 동적으로 렌더링됩니다 -->
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/js/vacation-common.js"></script>
<script type="module">
import '/js/api-config.js?v=3';
</script>
<script>
// axios 기본 설정
(function() {
const checkApiConfig = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(checkApiConfig);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
axios.interceptors.request.use(
config => {
const token = localStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
error => Promise.reject(error)
);
axios.interceptors.response.use(
response => response,
error => {
if (error.response?.status === 401) {
alert('세션이 만료되었습니다. 다시 로그인해주세요.');
window.location.href = '/pages/login.html';
}
return Promise.reject(error);
}
);
}
}, 50);
})();
</script>
<script>
let allRequestsData = [];
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxiosConfig();
initializePage();
});
async function initializePage() {
try {
const currentUser = getCurrentUser();
// 관리자 권한 체크
if (currentUser.access_level !== 'system' && currentUser.access_level !== 'admin') {
alert('관리자만 접근할 수 있습니다.');
window.location.href = '/pages/attendance/vacation-request.html';
return;
}
await loadWorkers();
await loadVacationTypes();
await loadPendingRequests();
await loadAllRequests();
// 휴가 업데이트 이벤트 리스너
window.addEventListener('vacation-updated', () => {
loadPendingRequests();
loadAllRequests();
});
// 날짜 필터 초기화 (최근 3개월)
const today = new Date();
const threeMonthsAgo = new Date();
threeMonthsAgo.setMonth(today.getMonth() - 3);
document.getElementById('filterStartDate').value = threeMonthsAgo.toISOString().split('T')[0];
document.getElementById('filterEndDate').value = today.toISOString().split('T')[0];
} catch (error) {
console.error('초기화 오류:', error);
alert('페이지 초기화 중 오류가 발생했습니다.');
}
}
function switchTab(tabName) {
// 모든 탭과 컨텐츠 비활성화
document.querySelectorAll('.tab').forEach(tab => tab.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
// 선택한 탭 활성화
if (tabName === 'approval') {
document.querySelector('.tab:nth-child(1)').classList.add('active');
document.getElementById('approvalTab').classList.add('active');
} else if (tabName === 'input') {
document.querySelector('.tab:nth-child(2)').classList.add('active');
document.getElementById('inputTab').classList.add('active');
} else if (tabName === 'all') {
document.querySelector('.tab:nth-child(3)').classList.add('active');
document.getElementById('allTab').classList.add('active');
}
}
async function loadPendingRequests() {
try {
const response = await axios.get('/vacation-requests/pending');
if (response.data.success) {
renderVacationRequests(response.data.data, 'pendingRequestsList', true, 'approval');
}
} catch (error) {
console.error('승인 대기 목록 로드 오류:', error);
document.getElementById('pendingRequestsList').innerHTML = `
<div class="empty-state">
<p>승인 대기 중인 신청이 없습니다.</p>
</div>
`;
}
}
async function loadAllRequests() {
try {
const response = await axios.get('/vacation-requests');
if (response.data.success) {
allRequestsData = response.data.data;
renderVacationRequests(allRequestsData, 'allRequestsList', false);
}
} catch (error) {
console.error('전체 신청 내역 로드 오류:', error);
document.getElementById('allRequestsList').innerHTML = `
<div class="empty-state">
<p>신청 내역이 없습니다.</p>
</div>
`;
}
}
async function updateVacationBalance() {
const workerId = document.getElementById('inputWorker').value;
const balanceDiv = document.getElementById('workerVacationBalance');
if (!workerId) {
balanceDiv.innerHTML = '<span class="text-muted">작업자를 선택하세요</span>';
return;
}
try {
const response = await axios.get(`/attendance/vacation-balance/${workerId}`);
if (response.data.success) {
const balance = response.data.data;
if (!balance || Object.keys(balance).length === 0) {
balanceDiv.innerHTML = '<span class="text-muted">휴가 잔여 정보가 없습니다</span>';
return;
}
const balanceHTML = Object.keys(balance).map(key => {
const info = balance[key];
return `
<div style="display: inline-block; margin-right: 1rem;">
<span style="color: #6b7280; font-size: 0.875rem;">${key}:</span>
<strong style="color: #111827; font-size: 1rem; margin-left: 0.25rem;">${info.remaining || 0}일</strong>
<span style="color: #9ca3af; font-size: 0.75rem; margin-left: 0.25rem;">(전체: ${info.total || 0}일)</span>
</div>
`;
}).join('');
balanceDiv.innerHTML = balanceHTML;
}
} catch (error) {
console.error('휴가 잔여 조회 오류:', error);
balanceDiv.innerHTML = '<span class="text-muted" style="color: #dc2626;">조회 실패</span>';
}
}
async function submitVacationInput(event) {
event.preventDefault();
const data = {
worker_id: parseInt(document.getElementById('inputWorker').value),
vacation_type_id: parseInt(document.getElementById('inputVacationType').value),
start_date: document.getElementById('inputStartDate').value,
end_date: document.getElementById('inputEndDate').value,
days_used: parseFloat(document.getElementById('inputDaysUsed').value),
reason: document.getElementById('inputReason').value || null
};
if (!confirm(`${document.getElementById('inputWorker').selectedOptions[0].text}의 휴가를 즉시 입력하시겠습니까?\n\n입력 즉시 승인 상태로 저장됩니다.`)) {
return;
}
try {
// 휴가 신청 생성
const response = await axios.post('/vacation-requests', data);
if (response.data.success) {
const requestId = response.data.data.request_id;
// 즉시 승인 처리
try {
const approveResponse = await axios.patch(`/vacation-requests/${requestId}/approve`);
if (approveResponse.data.success) {
alert('휴가 정보가 입력되고 자동 승인되었습니다.');
document.getElementById('vacationInputForm').reset();
document.getElementById('workerVacationBalance').innerHTML = '<span class="text-muted">작업자를 선택하세요</span>';
window.dispatchEvent(new Event('vacation-updated'));
loadRecentInputs();
}
} catch (approveError) {
console.error('자동 승인 오류:', approveError);
alert('휴가 정보는 입력되었으나 자동 승인에 실패했습니다. 승인 관리 탭에서 수동으로 승인해주세요.');
}
}
} catch (error) {
console.error('휴가 입력 오류:', error);
alert(error.response?.data?.message || '휴가 입력 중 오류가 발생했습니다.');
}
}
async function loadRecentInputs() {
try {
const response = await axios.get('/vacation-requests');
if (response.data.success) {
// 최근 30일 이내 승인된 항목만 표시
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
const thirtyDaysAgoStr = thirtyDaysAgo.toISOString().split('T')[0];
const recentApproved = response.data.data.filter(req =>
req.status === 'approved' &&
req.created_at >= thirtyDaysAgoStr
).slice(0, 20); // 최근 20개만
renderVacationRequests(recentApproved, 'recentInputsList', false);
}
} catch (error) {
console.error('최근 입력 내역 로드 오류:', error);
document.getElementById('recentInputsList').innerHTML = `
<div class="empty-state">
<p>최근 입력 내역이 없습니다.</p>
</div>
`;
}
}
function filterAllRequests() {
const startDate = document.getElementById('filterStartDate').value;
const endDate = document.getElementById('filterEndDate').value;
if (!startDate || !endDate) {
alert('시작일과 종료일을 모두 선택해주세요.');
return;
}
const filtered = allRequestsData.filter(req => {
return req.start_date >= startDate && req.start_date <= endDate;
});
renderVacationRequests(filtered, 'allRequestsList', false);
}
function resetFilter() {
renderVacationRequests(allRequestsData, 'allRequestsList', false);
}
</script>
</body>
</html>

View File

@@ -0,0 +1,269 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>휴가 신청 | (주)테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<script src="https://instant.page/5.2.0" type="module"></script>
</head>
<body>
<!-- 네비게이션 바 -->
<div id="navbar-container"></div>
<!-- 메인 콘텐츠 -->
<main class="main-content">
<div class="dashboard-main">
<div class="page-header">
<div class="page-title-section">
<h1 class="page-title">휴가 신청</h1>
<p class="page-description">휴가를 신청하고 신청 내역을 확인합니다</p>
</div>
</div>
<!-- 휴가 잔여 현황 -->
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">휴가 잔여 현황</h2>
</div>
<div class="card-body">
<div id="vacationBalance" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem;">
<!-- 휴가 잔여 정보가 여기에 표시됩니다 -->
</div>
</div>
</div>
</div>
<!-- 휴가 신청 -->
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">휴가 신청</h2>
</div>
<div class="card-body">
<form id="vacationRequestForm" onsubmit="submitVacationRequest(event)">
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem;">
<div class="form-group">
<label for="vacationType">휴가 유형 *</label>
<select id="vacationType" class="form-control" required>
<option value="">선택하세요</option>
</select>
</div>
<div class="form-group">
<label for="daysUsed">사용 일수 *</label>
<input type="number" id="daysUsed" class="form-control" min="0.5" step="0.5" value="1.0" required>
</div>
<div class="form-group">
<label for="startDate">시작일 *</label>
<input type="date" id="startDate" class="form-control" required>
</div>
<div class="form-group">
<label for="endDate">종료일 *</label>
<input type="date" id="endDate" class="form-control" required>
</div>
<div class="form-group" style="grid-column: 1 / -1;">
<label for="reason">사유</label>
<textarea id="reason" class="form-control" rows="3" placeholder="휴가 사유를 입력하세요 (선택)"></textarea>
</div>
</div>
<div style="text-align: center; margin-top: 2rem;">
<button type="submit" class="btn btn-primary" style="padding: 1rem 3rem;">
신청하기
</button>
</div>
</form>
</div>
</div>
</div>
<!-- 내 신청 내역 -->
<div class="content-section">
<div class="card">
<div class="card-header">
<h2 class="card-title">내 신청 내역</h2>
</div>
<div class="card-body">
<div id="myRequestsList" class="data-table-container">
<!-- 내 신청 내역이 여기에 동적으로 렌더링됩니다 -->
</div>
</div>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="/js/vacation-common.js"></script>
<script type="module">
import '/js/api-config.js?v=3';
</script>
<script>
// axios 기본 설정
(function() {
const checkApiConfig = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(checkApiConfig);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
axios.interceptors.request.use(
config => {
const token = localStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
},
error => Promise.reject(error)
);
axios.interceptors.response.use(
response => response,
error => {
if (error.response?.status === 401) {
alert('세션이 만료되었습니다. 다시 로그인해주세요.');
window.location.href = '/pages/login.html';
}
return Promise.reject(error);
}
);
}
}, 50);
})();
</script>
<script>
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxiosConfig();
initializePage();
});
async function initializePage() {
try {
const currentUser = getCurrentUser();
if (!currentUser || !currentUser.worker_id) {
alert('작업자 정보가 없습니다. 관리자에게 문의하세요.');
return;
}
await loadVacationTypes();
await loadVacationBalance();
await loadMyRequests();
// 휴가 업데이트 이벤트 리스너
window.addEventListener('vacation-updated', () => {
loadVacationBalance();
loadMyRequests();
});
} catch (error) {
console.error('초기화 오류:', error);
alert('페이지 초기화 중 오류가 발생했습니다.');
}
}
async function loadVacationBalance() {
const currentUser = getCurrentUser();
try {
const response = await axios.get(`/attendance/vacation-balance/${currentUser.worker_id}`);
if (response.data.success) {
renderVacationBalance(response.data.data);
}
} catch (error) {
console.error('휴가 잔여 조회 오류:', error);
document.getElementById('vacationBalance').innerHTML = `
<p class="text-muted">휴가 잔여 정보를 불러올 수 없습니다.</p>
`;
}
}
function renderVacationBalance(balance) {
const container = document.getElementById('vacationBalance');
if (!balance || Object.keys(balance).length === 0) {
container.innerHTML = '<p class="text-muted">휴가 잔여 정보가 없습니다.</p>';
return;
}
const balanceHTML = Object.keys(balance).map(key => {
const info = balance[key];
return `
<div style="padding: 1.5rem; background-color: #f9fafb; border-radius: 0.5rem; border: 1px solid #e5e7eb;">
<div style="font-size: 0.875rem; color: #6b7280; margin-bottom: 0.5rem;">${key}</div>
<div style="font-size: 1.5rem; font-weight: 700; color: #111827;">
${info.remaining || 0}
</div>
<div style="font-size: 0.75rem; color: #9ca3af; margin-top: 0.25rem;">
사용: ${info.used || 0}일 / 전체: ${info.total || 0}
</div>
</div>
`;
}).join('');
container.innerHTML = balanceHTML;
}
async function submitVacationRequest(event) {
event.preventDefault();
const currentUser = getCurrentUser();
const data = {
worker_id: currentUser.worker_id,
vacation_type_id: parseInt(document.getElementById('vacationType').value),
start_date: document.getElementById('startDate').value,
end_date: document.getElementById('endDate').value,
days_used: parseFloat(document.getElementById('daysUsed').value),
reason: document.getElementById('reason').value || null
};
try {
const response = await axios.post('/vacation-requests', data);
if (response.data.success) {
alert('휴가 신청이 완료되었습니다.');
document.getElementById('vacationRequestForm').reset();
window.dispatchEvent(new Event('vacation-updated'));
}
} catch (error) {
console.error('휴가 신청 오류:', error);
alert(error.response?.data?.message || '휴가 신청 중 오류가 발생했습니다.');
}
}
async function loadMyRequests() {
const currentUser = getCurrentUser();
try {
const response = await axios.get('/vacation-requests');
if (response.data.success) {
// 내 신청만 필터링
const myRequests = response.data.data.filter(req =>
req.requested_by === currentUser.user_id || req.worker_id === currentUser.worker_id
);
renderVacationRequests(myRequests, 'myRequestsList', true, 'delete');
}
} catch (error) {
console.error('내 신청 내역 로드 오류:', error);
document.getElementById('myRequestsList').innerHTML = `
<div class="empty-state">
<p>신청 내역이 없습니다.</p>
</div>
`;
}
}
</script>
</body>
</html>

View File

@@ -0,0 +1,700 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>근무 현황 | (주)테크니컬코리아</title>
<link rel="stylesheet" href="/css/design-system.css">
<link rel="stylesheet" href="/css/admin-pages.css?v=7">
<link rel="icon" type="image/png" href="/img/favicon.png">
<script src="/js/api-base.js"></script>
<script src="/js/app-init.js?v=2" defer></script>
<style>
.page-wrapper {
padding: 1.5rem;
max-width: 1400px;
}
.page-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.page-title {
font-size: 1.25rem;
font-weight: 600;
margin: 0;
}
.controls {
display: flex;
gap: 0.5rem;
align-items: center;
}
.controls input[type="date"] {
padding: 0.4rem 0.5rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
font-size: 0.875rem;
}
.btn {
padding: 0.4rem 0.75rem;
border: none;
border-radius: 0.25rem;
cursor: pointer;
font-size: 0.8rem;
}
.btn-primary { background: #3b82f6; color: white; }
.btn-outline { background: white; border: 1px solid #d1d5db; }
.btn-success { background: #10b981; color: white; }
/* 요약 */
.summary-row {
display: flex;
gap: 1rem;
padding: 0.5rem 0;
margin-bottom: 0.5rem;
font-size: 0.8rem;
color: #6b7280;
border-bottom: 1px solid #e5e7eb;
}
.summary-row span { display: flex; align-items: center; gap: 0.25rem; }
.summary-row .dot {
width: 8px; height: 8px; border-radius: 50%;
}
.dot-normal { background: #10b981; }
.dot-annual { background: #3b82f6; }
.dot-half { background: #22c55e; }
.dot-quarter { background: #eab308; }
.dot-early { background: #ef4444; }
.dot-overtime { background: #f97316; }
/* 테이블 */
.data-table {
width: 100%;
border-collapse: collapse;
font-size: 0.85rem;
background: white;
border: 1px solid #e5e7eb;
}
.data-table th, .data-table td {
padding: 0.5rem 0.75rem;
text-align: left;
border-bottom: 1px solid #e5e7eb;
}
.data-table th {
background: #f9fafb;
font-weight: 500;
color: #374151;
font-size: 0.8rem;
}
.data-table tr:hover {
background: #f9fafb;
}
.data-table tr.saved {
background: #f0fdf4;
}
.data-table tr.leave {
background: #fefce8; /* 연한 노랑 - 연차/반차/반반차 */
}
.data-table tr.absent {
background: #fef2f2; /* 연한 빨강 - 결근 (연차정보 없음) */
}
.data-table tr.absent-no-leave {
background: #fee2e2; /* 더 진한 빨강 - 출근체크 안하고 연차정보도 없음 */
}
.leave-tag {
font-size: 0.65rem;
color: #a16207;
background: #fef3c7;
padding: 0.125rem 0.375rem;
border-radius: 0.25rem;
margin-left: 0.5rem;
}
.status-leave { color: #a16207; }
.status-absent-warning { color: #dc2626; font-weight: 600; }
.worker-name {
font-weight: 500;
}
.saved-tag {
font-size: 0.65rem;
color: #10b981;
background: #dcfce7;
padding: 0.125rem 0.375rem;
border-radius: 0.25rem;
margin-left: 0.5rem;
}
.type-select {
padding: 0.25rem 0.5rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
font-size: 0.8rem;
min-width: 100px;
}
.overtime-input {
width: 50px;
padding: 0.25rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
text-align: center;
font-size: 0.8rem;
}
.hours-cell {
text-align: center;
min-width: 60px;
}
.status-present { color: #10b981; }
.status-absent { color: #ef4444; }
.status-not-hired { color: #9ca3af; font-style: italic; }
.data-table tr.not-hired {
background: #f3f4f6;
color: #9ca3af;
}
.data-table tr.not-hired .type-select,
.data-table tr.not-hired .overtime-input {
display: none;
}
.not-hired-tag {
font-size: 0.65rem;
color: #6b7280;
background: #e5e7eb;
padding: 0.125rem 0.375rem;
border-radius: 0.25rem;
margin-left: 0.5rem;
}
/* 저장 영역 */
.save-bar {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 1rem;
padding: 0.75rem 1rem;
background: #f9fafb;
border: 1px solid #e5e7eb;
border-radius: 0.25rem;
}
.save-status {
font-size: 0.8rem;
color: #6b7280;
}
.save-status.saved { color: #10b981; }
.save-status.unsaved { color: #f59e0b; }
.btn-save {
padding: 0.5rem 1.5rem;
font-size: 0.875rem;
background: #3b82f6;
color: white;
border: none;
border-radius: 0.25rem;
cursor: pointer;
}
.btn-save:hover { background: #2563eb; }
.btn-save:disabled { background: #9ca3af; cursor: not-allowed; }
.warning-box {
background: #fef3c7;
border: 1px solid #fcd34d;
color: #92400e;
padding: 0.5rem 0.75rem;
border-radius: 0.25rem;
margin-bottom: 0.75rem;
font-size: 0.8rem;
}
.warning-box a { color: #92400e; font-weight: 500; }
</style>
</head>
<body class="has-sidebar">
<div id="navbar-container"></div>
<div id="sidebar-container"></div>
<main class="main-content">
<div class="page-wrapper">
<div class="page-header">
<h1 class="page-title">근무 현황</h1>
<div class="controls">
<input type="date" id="selectedDate">
<button class="btn btn-primary" onclick="loadWorkStatus()">조회</button>
<button class="btn btn-outline" onclick="setAllNormal()">전체 정시근무</button>
</div>
</div>
<div id="noCheckinWarning" class="warning-box" style="display:none;">
출근 체크가 완료되지 않았습니다. 먼저 <a href="/pages/attendance/checkin.html">출근 체크</a>를 진행해주세요.
</div>
<div class="summary-row">
<span><span class="dot dot-normal"></span> 정시 <strong id="normalCount">0</strong></span>
<span><span class="dot dot-annual"></span> 연차 <strong id="annualCount">0</strong></span>
<span><span class="dot dot-half"></span> 반차 <strong id="halfCount">0</strong></span>
<span><span class="dot dot-quarter"></span> 반반차 <strong id="quarterCount">0</strong></span>
<span><span class="dot dot-early"></span> 조퇴 <strong id="earlyCount">0</strong></span>
<span><span class="dot dot-overtime"></span> 연장 <strong id="overtimeCount">0</strong></span>
<span><span class="dot" style="background:#dc2626;"></span> 결근 <strong id="absentCount">0</strong></span>
</div>
<table class="data-table">
<thead>
<tr>
<th style="width:30px">#</th>
<th>이름</th>
<th>출근</th>
<th>근태구분</th>
<th class="hours-cell">기본</th>
<th class="hours-cell">연장</th>
<th class="hours-cell">합계</th>
</tr>
</thead>
<tbody id="workerTableBody">
</tbody>
</table>
<div class="save-bar">
<span id="saveStatus" class="save-status"></span>
<button id="saveBtn" class="btn-save" onclick="saveWorkStatus()">저장</button>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
(function() {
const checkApiConfig = setInterval(() => {
if (window.API_BASE_URL) {
clearInterval(checkApiConfig);
axios.defaults.baseURL = window.API_BASE_URL;
const token = localStorage.getItem('token');
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
}
}
}, 50);
})();
let workers = [];
let workStatus = {};
let hasCheckinData = false;
let isAlreadySaved = false;
let isSaving = false;
const attendanceTypes = [
{ value: 'normal', label: '정시근무', hours: 8, isLeave: false },
{ value: 'annual', label: '연차', hours: 0, isLeave: true },
{ value: 'half', label: '반차', hours: 4, isLeave: true },
{ value: 'quarter', label: '반반차', hours: 2, isLeave: true },
{ value: 'early', label: '조퇴', hours: 0, isLeave: false },
{ value: 'overtime', label: '연장근로', hours: 8, isLeave: false }
];
document.addEventListener('DOMContentLoaded', async () => {
await waitForAxiosConfig();
document.getElementById('selectedDate').value = new Date().toISOString().split('T')[0];
loadWorkStatus();
});
function waitForAxiosConfig() {
return new Promise((resolve) => {
const check = setInterval(() => {
if (axios.defaults.baseURL) {
clearInterval(check);
resolve();
}
}, 50);
setTimeout(() => { clearInterval(check); resolve(); }, 5000);
});
}
function formatDisplayDate(dateStr) {
if (!dateStr) return '-';
const [year, month, day] = dateStr.split('-');
return `${year}.${month}.${day}`;
}
async function loadWorkStatus() {
const selectedDate = document.getElementById('selectedDate').value;
if (!selectedDate) return alert('날짜를 선택해주세요.');
try {
const [workersRes, recordsRes] = await Promise.all([
axios.get('/workers?limit=100'),
axios.get(`/attendance/daily-records?date=${selectedDate}`).catch(() => ({ data: { data: [] } }))
]);
workers = (workersRes.data.data || []).filter(w => w.status === 'active' && (!w.employment_status || w.employment_status === 'employed'));
const records = recordsRes.data.data || [];
hasCheckinData = records.length > 0;
isAlreadySaved = records.some(r => r.attendance_type_id || r.total_work_hours > 0);
document.getElementById('noCheckinWarning').style.display = hasCheckinData ? 'none' : 'block';
const selectedDate = document.getElementById('selectedDate').value;
workStatus = {};
workers.forEach(w => {
const record = records.find(r => r.worker_id === w.worker_id);
// 입사일 이전인지 확인
const joinDate = w.join_date ? w.join_date.split('T')[0] : null;
const isBeforeJoin = joinDate && selectedDate < joinDate;
if (isBeforeJoin) {
// 입사 전 날짜
workStatus[w.worker_id] = {
isPresent: false,
type: 'not_hired',
hours: 0,
overtimeHours: 0,
isSaved: false,
hasLeaveInfo: false,
isNotHired: true,
joinDate: joinDate
};
return;
}
if (record) {
let type = 'normal';
let overtimeHours = 0;
// 1. 휴가 유형 확인 (vacation_type_id 또는 vacation_type_code)
if (record.vacation_type_id || record.vacation_type_code) {
const vacationCodeMap = {
'ANNUAL_FULL': 'annual',
'ANNUAL_HALF': 'half',
'ANNUAL_QUARTER': 'quarter',
1: 'annual',
2: 'half',
3: 'quarter'
};
type = vacationCodeMap[record.vacation_type_code] || vacationCodeMap[record.vacation_type_id] || 'annual';
}
// 2. 근태 유형 확인
// work_attendance_types: 1=NORMAL, 2=LATE, 3=EARLY_LEAVE, 4=ABSENT, 5=VACATION
else if (record.attendance_type_code || record.attendance_type_id) {
const codeMap = {
'NORMAL': 'normal',
'REGULAR': 'normal',
'VACATION': 'annual',
'EARLY_LEAVE': 'early',
'ABSENT': 'normal', // 결근은 화면에서 따로 처리
1: 'normal', // NORMAL
2: 'normal', // LATE (지각도 출근으로 처리)
3: 'early', // EARLY_LEAVE
4: 'normal', // ABSENT (결근은 화면에서 따로 처리)
5: 'annual' // VACATION
};
type = codeMap[record.attendance_type_code] || codeMap[record.attendance_type_id] || 'normal';
}
// 3. 출근 안 한 경우 (is_present가 0이고 휴가 정보 없으면 결근 상태로 표시)
else if (record.is_present === 0) {
type = 'normal'; // 기본값, 사용자가 수정해야 함
}
// 연장근로 확인
if (record.total_work_hours > 8 && type === 'normal') {
type = 'overtime';
overtimeHours = record.total_work_hours - 8;
}
const typeInfo = attendanceTypes.find(t => t.value === type);
workStatus[w.worker_id] = {
isPresent: record.is_present === 1 || typeInfo?.isLeave,
type: type,
hours: typeInfo !== undefined ? typeInfo.hours : 8,
overtimeHours: overtimeHours,
isSaved: record.attendance_type_id != null || record.total_work_hours > 0 || record.vacation_type_id != null,
hasLeaveInfo: typeInfo?.isLeave || false
};
} else {
// 출근 체크 기록이 없는 경우 - 결근 상태
workStatus[w.worker_id] = {
isPresent: false,
type: 'normal',
hours: 8,
overtimeHours: 0,
isSaved: false,
hasLeaveInfo: false
};
}
});
render();
updateSummary();
updateSaveStatus();
} catch (e) {
console.error(e);
alert('데이터 로드 실패');
}
}
function render() {
const tbody = document.getElementById('workerTableBody');
if (workers.length === 0) {
tbody.innerHTML = '<tr><td colspan="7" style="text-align:center;color:#6b7280;padding:2rem;">작업자가 없습니다</td></tr>';
return;
}
tbody.innerHTML = workers.map((w, idx) => {
const s = workStatus[w.worker_id];
// 미입사 상태 처리
if (s.isNotHired) {
return `
<tr class="not-hired">
<td>${idx + 1}</td>
<td>
<span class="worker-name">${w.worker_name}</span>
<span class="not-hired-tag">미입사</span>
</td>
<td class="status-not-hired">-</td>
<td><span style="color:#9ca3af;font-size:0.8rem;">입사일: ${formatDisplayDate(s.joinDate)}</span></td>
<td class="hours-cell">-</td>
<td class="hours-cell">-</td>
<td class="hours-cell">-</td>
</tr>
`;
}
const typeInfo = attendanceTypes.find(t => t.value === s.type);
const isLeaveType = typeInfo?.isLeave || false;
const showOvertimeInput = s.type === 'overtime';
const baseHours = s.hours;
const totalHours = s.type === 'overtime' ? baseHours + s.overtimeHours : baseHours;
// 행 클래스 결정
let rowClass = '';
if (s.isSaved) {
rowClass = isLeaveType ? 'leave' : 'saved';
} else if (!s.isPresent) {
// 출근 안 했는데 연차 정보도 없으면 경고
rowClass = isLeaveType ? 'leave' : 'absent-no-leave';
}
// 출근 상태 텍스트 및 클래스 결정
let statusText = '';
let statusClass = '';
if (isLeaveType) {
statusText = typeInfo.label;
statusClass = 'status-leave';
} else if (s.isPresent) {
statusText = '출근';
statusClass = 'status-present';
} else {
statusText = '⚠️ 결근';
statusClass = 'status-absent-warning';
}
// 태그 표시
let tag = '';
if (s.isSaved) {
tag = '<span class="saved-tag">저장됨</span>';
} else if (isLeaveType) {
tag = '<span class="leave-tag">연차</span>';
}
return `
<tr class="${rowClass}">
<td>${idx + 1}</td>
<td>
<span class="worker-name">${w.worker_name}</span>
${tag}
</td>
<td class="${statusClass}">
${statusText}
</td>
<td>
<select class="type-select" onchange="updateType(${w.worker_id}, this.value)">
${attendanceTypes.map(t => `
<option value="${t.value}" ${s.type === t.value ? 'selected' : ''}>${t.label}</option>
`).join('')}
</select>
</td>
<td class="hours-cell">${baseHours}h</td>
<td class="hours-cell">
${showOvertimeInput ? `
<input type="number" class="overtime-input" value="${s.overtimeHours}" min="0" max="8" step="0.5"
onchange="updateOvertime(${w.worker_id}, this.value)">
` : '-'}
</td>
<td class="hours-cell"><strong>${totalHours}h</strong></td>
</tr>
`;
}).join('');
}
function updateType(workerId, value) {
const typeInfo = attendanceTypes.find(t => t.value === value);
workStatus[workerId].type = value;
workStatus[workerId].hours = typeInfo !== undefined ? typeInfo.hours : 8;
workStatus[workerId].hasLeaveInfo = typeInfo?.isLeave || false;
// 연차 유형 선택 시 출근 상태로 간주 (결근 아님)
if (typeInfo?.isLeave) {
workStatus[workerId].isPresent = true;
}
if (value === 'overtime') {
workStatus[workerId].overtimeHours = workStatus[workerId].overtimeHours || 2;
} else {
workStatus[workerId].overtimeHours = 0;
}
render();
updateSummary();
}
function updateOvertime(workerId, value) {
workStatus[workerId].overtimeHours = parseFloat(value) || 0;
render();
updateSummary();
}
function setAllNormal() {
workers.forEach(w => {
workStatus[w.worker_id].type = 'normal';
workStatus[w.worker_id].hours = 8;
workStatus[w.worker_id].overtimeHours = 0;
});
render();
updateSummary();
}
function updateSummary() {
let normal = 0, annual = 0, half = 0, quarter = 0, early = 0, overtime = 0, absent = 0, notHired = 0;
Object.values(workStatus).forEach(s => {
// 미입사자 제외
if (s.isNotHired) {
notHired++;
return;
}
const typeInfo = attendanceTypes.find(t => t.value === s.type);
const isLeaveType = typeInfo?.isLeave || false;
// 출근 안 했고 연차 정보도 없으면 결근
if (!s.isPresent && !isLeaveType) {
absent++;
}
switch (s.type) {
case 'normal': if (s.isPresent) normal++; break;
case 'annual': annual++; break;
case 'half': half++; break;
case 'quarter': quarter++; break;
case 'early': early++; break;
case 'overtime': overtime++; break;
}
});
document.getElementById('normalCount').textContent = normal;
document.getElementById('annualCount').textContent = annual;
document.getElementById('halfCount').textContent = half;
document.getElementById('quarterCount').textContent = quarter;
document.getElementById('earlyCount').textContent = early;
document.getElementById('overtimeCount').textContent = overtime;
document.getElementById('absentCount').textContent = absent;
}
function updateSaveStatus() {
const statusEl = document.getElementById('saveStatus');
const saveBtn = document.getElementById('saveBtn');
if (isAlreadySaved) {
statusEl.innerHTML = '이 날짜의 근무 현황이 저장되어 있습니다';
statusEl.className = 'save-status saved';
saveBtn.textContent = '수정 저장';
} else {
statusEl.innerHTML = '아직 저장되지 않았습니다';
statusEl.className = 'save-status unsaved';
saveBtn.textContent = '저장';
}
}
async function saveWorkStatus() {
const date = document.getElementById('selectedDate').value;
if (!date) return alert('날짜를 선택해주세요.');
if (isSaving) return;
const saveBtn = document.getElementById('saveBtn');
// work_attendance_types: 1=NORMAL, 2=LATE, 3=EARLY_LEAVE, 4=ABSENT, 5=VACATION
const typeIdMap = {
'normal': 1, // NORMAL
'annual': 5, // VACATION
'half': 5, // VACATION
'quarter': 5, // VACATION
'early': 3, // EARLY_LEAVE
'overtime': 1 // NORMAL (시간으로 구분)
};
// vacation_types: 1=ANNUAL_FULL, 2=ANNUAL_HALF, 3=ANNUAL_QUARTER
const vacationTypeIdMap = {
'annual': 1,
'half': 2,
'quarter': 3,
};
// 미입사자 제외하고 저장할 데이터 생성
const recordsToSave = workers
.filter(w => !workStatus[w.worker_id]?.isNotHired)
.map(w => {
const s = workStatus[w.worker_id];
const totalHours = s.type === 'overtime' ? s.hours + s.overtimeHours : s.hours;
return {
record_date: date,
worker_id: w.worker_id,
attendance_type_id: typeIdMap[s.type] || 1,
vacation_type_id: vacationTypeIdMap[s.type] || null,
total_work_hours: totalHours,
overtime_approved: s.type === 'overtime',
notes: s.type === 'overtime' ? `연장근로 ${s.overtimeHours}시간` : null
};
});
isSaving = true;
saveBtn.disabled = true;
saveBtn.textContent = '저장 중...';
try {
let ok = 0, fail = 0;
for (const r of recordsToSave) {
try {
await axios.post('/attendance/records', r);
ok++;
} catch (e) {
console.error('저장 실패:', e);
fail++;
}
}
if (fail === 0) {
alert(`${ok}명 저장 완료`);
isAlreadySaved = true;
workers.forEach(w => {
if (workStatus[w.worker_id]) {
workStatus[w.worker_id].isSaved = true;
}
});
render();
updateSaveStatus();
} else if (ok > 0) {
alert(`${ok}명 성공, ${fail}명 실패`);
} else {
alert('저장에 실패했습니다');
}
} catch (e) {
console.error(e);
alert('저장 중 오류가 발생했습니다');
} finally {
isSaving = false;
saveBtn.disabled = false;
updateSaveStatus();
}
}
</script>
</body>
</html>