diff --git a/system1-factory/api/controllers/monthlyComparisonController.js b/system1-factory/api/controllers/monthlyComparisonController.js index 49a7ec8..eac22f5 100644 --- a/system1-factory/api/controllers/monthlyComparisonController.js +++ b/system1-factory/api/controllers/monthlyComparisonController.js @@ -121,8 +121,10 @@ async function buildComparisonData(userId, year, month) { status: confirmation.status, confirmed_at: confirmation.confirmed_at, rejected_at: confirmation.rejected_at, - reject_reason: confirmation.reject_reason - } : { status: 'pending', confirmed_at: null, reject_reason: null }, + reject_reason: confirmation.reject_reason, + change_details: confirmation.change_details || null, + admin_checked: confirmation.admin_checked || 0 + } : { status: 'pending', confirmed_at: null, reject_reason: null, change_details: null, admin_checked: 0 }, daily_records: dailyRecords }; } diff --git a/system1-factory/web/css/monthly-comparison.css b/system1-factory/web/css/monthly-comparison.css index 9426e07..487e22a 100644 --- a/system1-factory/web/css/monthly-comparison.css +++ b/system1-factory/web/css/monthly-comparison.css @@ -54,6 +54,9 @@ .mc-status-badge.pending { background: #fef3c7; color: #92400e; } .mc-status-badge.confirmed { background: #dcfce7; color: #166534; } .mc-status-badge.rejected { background: #fef2f2; color: #991b1b; } +.mc-status-badge.change_request { background: #fff7ed; color: #c2410c; } +.mc-status-badge.review_sent { background: #dbeafe; color: #1e40af; } +.mc-status-badge.admin_checked { background: #dcfce7; color: #166534; } /* Summary Cards */ .mc-summary-cards { @@ -305,6 +308,61 @@ .ds-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 16px; color: #9ca3af; font-size: 0.875rem; } .ds-link { color: #2563eb; font-size: 0.8rem; text-decoration: underline; } +/* Change Request Panel (detail mode) */ +.mc-change-panel { + background: #fff7ed; + border: 1px solid #fed7aa; + border-radius: 10px; + padding: 14px; + margin-bottom: 12px; +} +.mc-change-header { + font-size: 0.85rem; font-weight: 700; color: #c2410c; + margin-bottom: 8px; + display: flex; align-items: center; gap: 6px; +} +.mc-change-list { margin-bottom: 10px; } +.mc-change-item { + font-size: 0.8rem; color: #374151; + padding: 4px 0; + border-bottom: 1px solid #fde6d0; +} +.mc-change-item:last-child { border-bottom: none; } +.mc-change-from { color: #9ca3af; text-decoration: line-through; } +.mc-change-to { color: #c2410c; font-weight: 600; } +.mc-change-desc { + font-size: 0.8rem; color: #374151; + margin-bottom: 10px; + white-space: pre-wrap; +} +.mc-change-actions { + display: flex; gap: 8px; +} +.mc-change-approve { + flex: 1; padding: 10px; + background: #2563eb; color: white; + font-size: 0.8rem; font-weight: 600; + border: none; border-radius: 8px; cursor: pointer; +} +.mc-change-approve:hover { background: #1d4ed8; } +.mc-change-reject { + flex: 1; padding: 10px; + background: white; color: #ef4444; + font-size: 0.8rem; font-weight: 600; + border: 2px solid #fecaca; border-radius: 8px; cursor: pointer; +} +.mc-change-reject:hover { background: #fef2f2; } + +/* Worker card change summary */ +.mc-worker-change-summary { + font-size: 0.7rem; color: #c2410c; + margin-top: 4px; padding-left: 8px; + border-left: 2px solid #fed7aa; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + @media (max-width: 480px) { body { max-width: 480px; margin: 0 auto; } } /* Inline Edit */ diff --git a/system1-factory/web/js/monthly-comparison.js b/system1-factory/web/js/monthly-comparison.js index 88e718f..9c8b150 100644 --- a/system1-factory/web/js/monthly-comparison.js +++ b/system1-factory/web/js/monthly-comparison.js @@ -323,7 +323,11 @@ function renderConfirmationStatus(conf) { document.getElementById('confirmedText').textContent = '반려: ' + (conf.reject_reason || '-'); } else if (conf.status === 'change_request') { statusEl.classList.remove('hidden'); - document.getElementById('confirmedText').textContent = '수정요청 접수됨'; + document.getElementById('confirmedText').innerHTML = '수정요청 접수됨'; + // detail 모드: 수정 내역 + 승인/거부 버튼 표시 + if (currentMode === 'detail') { + renderChangeRequestPanel(conf); + } } else { statusEl.classList.add('hidden'); } @@ -384,6 +388,8 @@ function renderWorkerList(workers) { ? `⚠️ 불일치${w.mismatch_count}` : ''; const rejectReason = w.status === 'rejected' && w.reject_reason ? `
사유: ${escHtml(w.reject_reason)}
` : ''; + const changeSummary = w.status === 'change_request' && w.change_details + ? `
${escHtml(formatChangeDetailsSummary(w.change_details))}
` : ''; const confirmedAt = w.confirmed_at ? `(${new Date(w.confirmed_at).toLocaleDateString('ko')})` : ''; return ` @@ -399,7 +405,7 @@ function renderWorkerList(workers) {
${statusBadge} ${confirmedAt}
- ${rejectReason} + ${rejectReason}${changeSummary} `; }).join(''); } @@ -511,9 +517,14 @@ async function downloadExcel() { return; } const token = (window.getSSOToken && window.getSSOToken()) || ''; - const response = await fetch(`${window.API_BASE_URL}/monthly-comparison/export?year=${currentYear}&month=${currentMonth}`, { + const response = await fetch(`/api/monthly-comparison/export?year=${currentYear}&month=${currentMonth}`, { headers: { 'Authorization': `Bearer ${token}` } }); + if (response.status === 401) { + if (typeof _safeRedirect === 'function') _safeRedirect(); + else location.href = '/pages/login.html'; + return; + } if (!response.ok) throw new Error('다운로드 실패'); const blob = await response.blob(); const url = window.URL.createObjectURL(blob); @@ -696,7 +707,127 @@ async function saveAttendance(date) { } } +// ===== Change Request Panel (detail mode) ===== +function renderChangeRequestPanel(conf) { + var panel = document.getElementById('changeRequestPanel'); + if (!panel) { + // 동적 생성: mismatchAlert 뒤에 삽입 + panel = document.createElement('div'); + panel.id = 'changeRequestPanel'; + var anchor = document.getElementById('mismatchAlert'); + anchor.parentNode.insertBefore(panel, anchor.nextSibling); + } + + var details = null; + if (conf.change_details) { + try { details = typeof conf.change_details === 'string' ? JSON.parse(conf.change_details) : conf.change_details; } + catch (e) { details = null; } + } + + var html = '
'; + html += '
수정요청 내역
'; + + if (details && details.changes && details.changes.length) { + html += '
'; + details.changes.forEach(function(c) { + var dateLabel = c.date ? c.date.substring(5).replace('-', '/') : ''; + html += '
' + escHtml(dateLabel) + ': ' + + '' + escHtml(c.from) + '' + + ' ' + + '' + escHtml(c.to) + '
'; + }); + html += '
'; + } else if (details && details.description) { + html += '
' + escHtml(details.description) + '
'; + } else { + html += '
상세 내역 없음
'; + } + + html += '
'; + html += ''; + html += ''; + html += '
'; + html += '
'; + + panel.innerHTML = html; +} + +async function approveChangeRequest() { + if (!currentUserId || isProcessing) return; + if (!confirm('수정요청을 승인하시겠습니까? 작업자에게 재확인 요청이 발송됩니다.')) return; + isProcessing = true; + try { + var res = await window.apiCall('/monthly-comparison/review-respond', 'POST', { + user_id: currentUserId, year: currentYear, month: currentMonth, action: 'approve' + }); + if (res && res.success) { + showToast(res.message || '승인 완료', 'success'); + loadData(); + } else { + showToast(res?.message || '처리 실패', 'error'); + } + } catch (e) { showToast('네트워크 오류', 'error'); } + finally { isProcessing = false; } +} + +function openRejectChangeModal() { + document.getElementById('rejectReason').value = ''; + // 모달 텍스트를 수정요청 거부용으로 변경 + var headerSpan = document.querySelector('#rejectModal .mc-modal-header span'); + if (headerSpan) headerSpan.innerHTML = '수정요청 거부'; + var desc = document.querySelector('#rejectModal .mc-modal-desc'); + if (desc) desc.textContent = '거부 사유를 입력해주세요:'; + var submitBtn = document.getElementById('rejectSubmitBtn'); + if (submitBtn) { + submitBtn.textContent = '거부 제출'; + submitBtn.onclick = submitRejectChange; + } + document.getElementById('rejectModal').classList.remove('hidden'); +} + +async function submitRejectChange() { + if (!currentUserId || isProcessing) return; + var reason = document.getElementById('rejectReason').value.trim(); + if (!reason) { showToast('거부 사유를 입력해주세요', 'error'); return; } + isProcessing = true; + try { + var res = await window.apiCall('/monthly-comparison/review-respond', 'POST', { + user_id: currentUserId, year: currentYear, month: currentMonth, + action: 'reject', reject_reason: reason + }); + if (res && res.success) { + showToast(res.message || '거부 완료', 'success'); + closeRejectModal(); + loadData(); + } else { + showToast(res?.message || '처리 실패', 'error'); + } + } catch (e) { showToast('네트워크 오류', 'error'); } + finally { isProcessing = false; } +} + +function formatChangeDetailsSummary(changeDetails) { + var details = null; + if (!changeDetails) return ''; + try { details = typeof changeDetails === 'string' ? JSON.parse(changeDetails) : changeDetails; } + catch (e) { return ''; } + + if (details.changes && details.changes.length) { + var items = details.changes.map(function(c) { + var d = c.date ? c.date.substring(5).replace('-', '/') : ''; + return d + ' ' + (c.from || '') + '\u2192' + (c.to || ''); + }); + return items.join(', '); + } + if (details.description) return details.description; + return ''; +} + // ESC로 모달 닫기 -document.addEventListener('keydown', e => { +function handleEscKey(e) { if (e.key === 'Escape') closeRejectModal(); +} +document.addEventListener('keydown', handleEscKey); +window.addEventListener('beforeunload', function() { + document.removeEventListener('keydown', handleEscKey); }); diff --git a/system1-factory/web/pages/attendance/monthly-comparison.html b/system1-factory/web/pages/attendance/monthly-comparison.html index 4cd3e81..d0f3059 100644 --- a/system1-factory/web/pages/attendance/monthly-comparison.html +++ b/system1-factory/web/pages/attendance/monthly-comparison.html @@ -8,7 +8,7 @@ - +
@@ -164,7 +164,7 @@ - +