fix(tkpurchase): 협력업체 포탈 보고 폼 자동 표시 + 체크인 작업자 pre-populate
- 보고 0건일 때 입력 폼 자동 표시 (버튼 클릭 불필요) - 체크인 시 입력한 작업자 명단으로 보고 폼 작업자 행 자동 생성 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -165,11 +165,15 @@ async function renderScheduleCards() {
|
||||
</div>`;
|
||||
}).join('');
|
||||
|
||||
// 체크인된 카드의 보고 목록 로드
|
||||
// 체크인된 카드의 보고 목록 로드 + 보고 0건이면 폼 자동 표시
|
||||
for (const s of portalSchedules) {
|
||||
const checkin = portalCheckins[s.id];
|
||||
if (checkin && !checkin.check_out_time) {
|
||||
const reportCount = parseInt(checkin.work_report_count) || 0;
|
||||
loadReportsList(checkin.id, s.id);
|
||||
if (reportCount === 0) {
|
||||
showReportForm(checkin.id, s.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,17 +204,25 @@ function renderReportsList(checkinId, scheduleId, reports) {
|
||||
const workerCount = r.workers ? r.workers.length : 0;
|
||||
const totalHours = r.workers ? r.workers.reduce((sum, w) => sum + Number(w.hours_worked || 0), 0) : 0;
|
||||
const isConfirmed = !!r.confirmed_by;
|
||||
const isRejected = !!r.rejected_by;
|
||||
const statusBadge = isConfirmed
|
||||
? '<span class="text-xs text-emerald-600"><i class="fas fa-check-circle"></i> 확인완료</span>'
|
||||
: isRejected
|
||||
? '<span class="text-xs text-red-600"><i class="fas fa-times-circle"></i> 반려</span>'
|
||||
: '<span class="text-xs text-amber-500">미확인</span>';
|
||||
const canEdit = !isConfirmed;
|
||||
return `<div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg mb-2 text-sm">
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<span class="font-medium text-gray-700">보고 #${r.report_seq || 1}</span>
|
||||
${isConfirmed ? '<span class="text-xs text-emerald-600"><i class="fas fa-check-circle"></i> 확인완료</span>' : '<span class="text-xs text-amber-500">미확인</span>'}
|
||||
${statusBadge}
|
||||
</div>
|
||||
<div class="text-xs text-gray-500 truncate">${escapeHtml((r.work_content || '').substring(0, 50))}${(r.work_content || '').length > 50 ? '...' : ''}</div>
|
||||
<div class="text-xs text-gray-400 mt-1">${workerCount}명 · ${totalHours}h · 진행률 ${r.progress_rate || 0}%</div>
|
||||
${isRejected && r.rejection_reason ? `<div class="text-xs text-red-600 mt-1"><i class="fas fa-exclamation-circle mr-1"></i>${escapeHtml(r.rejection_reason)}</div>` : ''}
|
||||
</div>
|
||||
${!isConfirmed ? `<button onclick="openEditReport(${r.id}, ${checkinId}, ${scheduleId})" class="ml-2 px-3 py-1 text-xs bg-white border border-gray-300 text-gray-600 rounded hover:bg-gray-100 flex-shrink-0">
|
||||
<i class="fas fa-edit mr-1"></i>수정
|
||||
${canEdit ? `<button onclick="openEditReport(${r.id}, ${checkinId}, ${scheduleId})" class="ml-2 px-3 py-1 text-xs bg-white border border-gray-300 text-gray-600 rounded hover:bg-gray-100 flex-shrink-0">
|
||||
<i class="fas fa-edit mr-1"></i>${isRejected ? '수정 재제출' : '수정'}
|
||||
</button>` : ''}
|
||||
</div>`;
|
||||
}).join('');
|
||||
@@ -230,12 +242,26 @@ async function showReportForm(checkinId, scheduleId, editReport) {
|
||||
const checkin = Object.values(portalCheckins).find(c => c.id === checkinId);
|
||||
const isFirstReport = !editReport && checkin && parseInt(checkin.work_report_count) === 0;
|
||||
|
||||
// 기본 작업자 행
|
||||
// 기본 작업자 행: 체크인 시 입력한 작업자 명단으로 pre-populate
|
||||
let existingWorkers = [];
|
||||
if (editReport && editReport.workers) {
|
||||
existingWorkers = editReport.workers;
|
||||
} else if (isFirstReport && currentUser) {
|
||||
existingWorkers = [{ worker_name: currentUser.name || '', hours_worked: 8.0 }];
|
||||
} else if (isFirstReport && checkin) {
|
||||
let workerNames = [];
|
||||
if (checkin.worker_names) {
|
||||
let parsed = checkin.worker_names;
|
||||
try { parsed = JSON.parse(parsed); } catch(e) { /* 그대로 사용 */ }
|
||||
if (Array.isArray(parsed)) {
|
||||
workerNames = parsed.map(n => String(n).trim()).filter(Boolean);
|
||||
} else {
|
||||
workerNames = String(parsed).split(/[,,]\s*/).map(n => n.trim()).filter(Boolean);
|
||||
}
|
||||
}
|
||||
if (workerNames.length > 0) {
|
||||
existingWorkers = workerNames.map(name => ({ worker_name: name, hours_worked: 8.0 }));
|
||||
} else if (currentUser) {
|
||||
existingWorkers = [{ worker_name: currentUser.name || '', hours_worked: 8.0 }];
|
||||
}
|
||||
}
|
||||
|
||||
formContainer.innerHTML = `
|
||||
|
||||
Reference in New Issue
Block a user