feat(tkpurchase): 체크인 worker_names 배열 저장 + 구매팀 체크인 관리 기능
- doCheckIn()에서 worker_names를 콤마 split 배열로 전송 (DB에 JSON 배열로 저장) - 구매팀 일정 페이지에 체크인 조회/수정/삭제 모달 추가 - DELETE /checkins/:id endpoint + 트랜잭션 삭제 (reports cascade) - PUT /checkins/:id에 requirePage 권한 guard 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -421,12 +421,15 @@ async function openEditReport(reportId, checkinId, scheduleId) {
|
||||
|
||||
async function doCheckIn(scheduleId) {
|
||||
const workerCount = parseInt(document.getElementById('checkinWorkers_' + scheduleId).value) || 1;
|
||||
const workerNames = document.getElementById('checkinNames_' + scheduleId).value.trim();
|
||||
const rawNames = document.getElementById('checkinNames_' + scheduleId).value.trim();
|
||||
const workerNames = rawNames
|
||||
? rawNames.split(/[,,]\s*/).map(n => n.trim()).filter(Boolean)
|
||||
: null;
|
||||
|
||||
const body = {
|
||||
schedule_id: scheduleId,
|
||||
actual_worker_count: workerCount,
|
||||
worker_names: workerNames || null
|
||||
worker_names: workerNames
|
||||
};
|
||||
|
||||
try {
|
||||
|
||||
@@ -86,6 +86,7 @@ function renderScheduleTable(list, total) {
|
||||
<td class="text-center">${s.expected_workers || 0}명</td>
|
||||
<td><span class="badge ${cls}">${label}</span></td>
|
||||
<td class="text-right">
|
||||
${(s.status === 'in_progress' || s.status === 'completed') ? `<button onclick="viewCheckins(${s.id})" class="text-emerald-600 hover:text-emerald-800 text-xs mr-1" title="체크인 현황"><i class="fas fa-clipboard-check"></i></button>` : ''}
|
||||
${canEdit ? `<button onclick="openEditSchedule(${s.id})" class="text-blue-600 hover:text-blue-800 text-xs mr-1" title="수정"><i class="fas fa-edit"></i></button>
|
||||
<button onclick="deleteSchedule(${s.id})" class="text-red-500 hover:text-red-700 text-xs" title="삭제"><i class="fas fa-trash"></i></button>` : ''}
|
||||
</td>
|
||||
@@ -290,6 +291,83 @@ async function deleteSchedule(id) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== Checkin Management ===== */
|
||||
async function viewCheckins(scheduleId) {
|
||||
document.getElementById('checkinModal').classList.remove('hidden');
|
||||
const body = document.getElementById('checkinModalBody');
|
||||
body.innerHTML = '<p class="text-gray-400 text-center py-4">로딩 중...</p>';
|
||||
|
||||
try {
|
||||
const r = await api('/checkins/schedule/' + scheduleId);
|
||||
const list = r.data || [];
|
||||
if (!list.length) {
|
||||
body.innerHTML = '<p class="text-gray-400 text-center py-4">체크인 기록이 없습니다</p>';
|
||||
return;
|
||||
}
|
||||
body.innerHTML = list.map(c => {
|
||||
let names = '';
|
||||
if (c.worker_names) {
|
||||
try {
|
||||
const parsed = JSON.parse(c.worker_names);
|
||||
names = Array.isArray(parsed) ? parsed.join(', ') : parsed;
|
||||
} catch { names = c.worker_names; }
|
||||
}
|
||||
const checkinTime = c.check_in_time ? new Date(c.check_in_time).toLocaleString('ko-KR', { month:'numeric', day:'numeric', hour:'2-digit', minute:'2-digit' }) : '-';
|
||||
const checkoutTime = c.check_out_time ? new Date(c.check_out_time).toLocaleString('ko-KR', { hour:'2-digit', minute:'2-digit' }) : '작업중';
|
||||
return `<div class="border rounded-lg p-3" data-checkin-id="${c.id}">
|
||||
<div class="flex justify-between items-start">
|
||||
<div class="flex-1">
|
||||
<div class="text-sm font-medium">${escapeHtml(c.company_name || '')} <span class="text-gray-400 text-xs">${checkinTime} ~ ${checkoutTime}</span></div>
|
||||
<div class="text-xs text-gray-500 mt-1">인원: ${c.actual_worker_count || 0}명</div>
|
||||
<div class="text-xs text-gray-600 mt-1" id="checkinNames_${c.id}">작업자: ${escapeHtml(names) || '-'}</div>
|
||||
</div>
|
||||
<div class="flex gap-1 ml-2">
|
||||
<button onclick="editCheckinWorkers(${c.id})" class="text-blue-500 hover:text-blue-700 text-xs px-1" title="수정"><i class="fas fa-edit"></i></button>
|
||||
<button onclick="deleteCheckin(${c.id},${scheduleId})" class="text-red-500 hover:text-red-700 text-xs px-1" title="삭제"><i class="fas fa-trash"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
} catch(e) {
|
||||
body.innerHTML = '<p class="text-red-400 text-center py-4">로딩 실패</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function closeCheckinModal() {
|
||||
document.getElementById('checkinModal').classList.add('hidden');
|
||||
}
|
||||
|
||||
async function deleteCheckin(checkinId, scheduleId) {
|
||||
if (!confirm('이 체크인을 삭제하시겠습니까?\n관련 업무현황도 함께 삭제됩니다.')) return;
|
||||
try {
|
||||
await api('/checkins/' + checkinId, { method: 'DELETE' });
|
||||
showToast('체크인이 삭제되었습니다');
|
||||
viewCheckins(scheduleId);
|
||||
loadSchedules();
|
||||
} catch(e) {
|
||||
showToast(e.message || '삭제 실패', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function editCheckinWorkers(checkinId) {
|
||||
const el = document.getElementById('checkinNames_' + checkinId);
|
||||
const current = el.textContent.replace('작업자: ', '').trim();
|
||||
const input = prompt('작업자 명단 (콤마로 구분)', current === '-' ? '' : current);
|
||||
if (input === null) return;
|
||||
|
||||
const names = input.split(/[,,]\s*/).map(n => n.trim()).filter(Boolean);
|
||||
try {
|
||||
await api('/checkins/' + checkinId, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ worker_names: names.length ? names : null })
|
||||
});
|
||||
el.textContent = '작업자: ' + (names.length ? names.join(', ') : '-');
|
||||
showToast('작업자 명단이 수정되었습니다');
|
||||
} catch(e) {
|
||||
showToast(e.message || '수정 실패', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== Init ===== */
|
||||
function initSchedulePage() {
|
||||
if (!initAuth()) return;
|
||||
|
||||
Reference in New Issue
Block a user