feat: 작업일정 기간 기반 + 프로젝트 연결

- partner_schedules: work_date → start_date/end_date 기간 기반으로 변경
- project_id 컬럼 추가 (projects 테이블 연결, 선택사항)
- 프로젝트 조회 API 추가 (GET /projects/active)
- 일정 조회 시 기간 겹침 조건으로 필터링
- 체크인 시 기간 내 검증 추가
- 프론트엔드: 시작일/종료일 입력 + 프로젝트 선택 드롭다운
- 마이그레이션 SQL 포함 (scripts/migration-schedule-daterange.sql)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-13 08:18:53 +09:00
parent fa4c899d95
commit b5b0fa1728
12 changed files with 228 additions and 36 deletions

View File

@@ -78,7 +78,8 @@
<thead>
<tr>
<th>업체</th>
<th>작업일</th>
<th>기간</th>
<th>프로젝트</th>
<th>작업내용</th>
<th class="hide-mobile">작업장</th>
<th class="text-center">예상인원</th>
@@ -87,7 +88,7 @@
</tr>
</thead>
<tbody id="scheduleTableBody">
<tr><td colspan="7" class="text-center text-gray-400 py-8">로딩 중...</td></tr>
<tr><td colspan="8" class="text-center text-gray-400 py-8">로딩 중...</td></tr>
</tbody>
</table>
</div>
@@ -112,9 +113,21 @@
<input type="hidden" id="addCompanyId">
<div id="addCompanyDropdown" class="hidden absolute z-10 w-full mt-1 bg-white border rounded-lg shadow-lg max-h-48 overflow-y-auto"></div>
</div>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">시작일 <span class="text-red-400">*</span></label>
<input type="date" id="addStartDate" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">종료일 <span class="text-red-400">*</span></label>
<input type="date" id="addEndDate" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
</div>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">작업일 <span class="text-red-400">*</span></label>
<input type="date" id="addWorkDate" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
<label class="block text-xs font-medium text-gray-600 mb-1">프로젝트</label>
<select id="addProject" class="input-field w-full px-3 py-2 rounded-lg text-sm">
<option value="">선택 안함</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">작업내용</label>
@@ -157,9 +170,21 @@
<input type="hidden" id="editCompanyId">
<div id="editCompanyDropdown" class="hidden absolute z-10 w-full mt-1 bg-white border rounded-lg shadow-lg max-h-48 overflow-y-auto"></div>
</div>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">시작일 <span class="text-red-400">*</span></label>
<input type="date" id="editStartDate" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">종료일 <span class="text-red-400">*</span></label>
<input type="date" id="editEndDate" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
</div>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">작업일 <span class="text-red-400">*</span></label>
<input type="date" id="editWorkDate" class="input-field w-full px-3 py-2 rounded-lg text-sm" required>
<label class="block text-xs font-medium text-gray-600 mb-1">프로젝트</label>
<select id="editProject" class="input-field w-full px-3 py-2 rounded-lg text-sm">
<option value="">선택 안함</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">작업내용</label>

View File

@@ -52,12 +52,13 @@ async function loadTodaySchedules() {
const statusMap = { scheduled: ['badge-amber', '예정'], in_progress: ['badge-green', '진행중'], completed: ['badge-blue', '완료'], cancelled: ['badge-gray', '취소'] };
c.innerHTML = list.map(s => {
const [cls, label] = statusMap[s.status] || ['badge-gray', s.status];
const dateDisplay = formatDate(s.start_date) === formatDate(s.end_date) ? formatDate(s.start_date) : formatDate(s.start_date) + ' ~ ' + formatDate(s.end_date);
return `<div class="p-3 bg-gray-50 rounded-lg">
<div class="flex items-center justify-between">
<span class="text-sm font-medium">${escapeHtml(s.company_name || '')}</span>
<span class="badge ${cls}">${label}</span>
</div>
<div class="text-xs text-gray-500 mt-1">${escapeHtml(s.workplace_name || '')} · ${s.expected_workers || 0}명</div>
<div class="text-xs text-gray-500 mt-1">${dateDisplay} · ${escapeHtml(s.workplace_name || '')} · ${s.expected_workers || 0}명</div>
${s.work_description ? `<div class="text-xs text-gray-400 mt-0.5 truncate">${escapeHtml(s.work_description)}</div>` : ''}
</div>`;
}).join('');

View File

@@ -58,7 +58,7 @@ async function renderScheduleCards() {
<div class="p-5 border-b">
<div class="flex items-center justify-between mb-2">
<h3 class="text-base font-semibold text-gray-800">${escapeHtml(s.workplace_name || '작업장 미지정')}</h3>
<span class="text-xs text-gray-500">${formatDate(s.work_date)}</span>
<span class="text-xs text-gray-500">${formatDate(s.start_date) === formatDate(s.end_date) ? formatDate(s.start_date) : formatDate(s.start_date) + ' ~ ' + formatDate(s.end_date)}</span>
</div>
${s.work_description ? `<p class="text-sm text-gray-600 mb-2">${escapeHtml(s.work_description)}</p>` : ''}
<div class="flex gap-4 text-xs text-gray-500">

View File

@@ -3,6 +3,39 @@
let schedulePage = 1;
const scheduleLimit = 20;
let companySearchTimer = null;
let projectList = [];
async function loadProjects() {
try {
const r = await api('/projects/active');
projectList = r.data || [];
} catch(e) {
console.warn('Load projects error:', e);
projectList = [];
}
}
function populateProjectDropdown(selectId, selectedId) {
const select = document.getElementById(selectId);
select.innerHTML = '<option value="">선택 안함</option>';
projectList.forEach(p => {
const label = p.job_no ? `[${p.job_no}] ${p.project_name}` : p.project_name;
select.innerHTML += `<option value="${p.project_id}" ${p.project_id == selectedId ? 'selected' : ''}>${escapeHtml(label)}</option>`;
});
}
function formatDateRange(startDate, endDate) {
const s = formatDate(startDate);
const e = formatDate(endDate);
if (s === e) return s;
// 같은 연도이면 월/일만 표시
const sd = new Date(startDate);
const ed = new Date(endDate);
if (sd.getFullYear() === ed.getFullYear()) {
return `${sd.getMonth()+1}/${sd.getDate()} ~ ${ed.getMonth()+1}/${ed.getDate()}`;
}
return `${s} ~ ${e}`;
}
async function loadSchedules() {
const company = document.getElementById('filterCompany').value.trim();
@@ -21,14 +54,14 @@ async function loadSchedules() {
renderScheduleTable(r.data || [], r.total || 0);
} catch(e) {
console.warn('Schedule load error:', e);
document.getElementById('scheduleTableBody').innerHTML = '<tr><td colspan="7" class="text-center text-red-400 py-8">로딩 실패</td></tr>';
document.getElementById('scheduleTableBody').innerHTML = '<tr><td colspan="8" class="text-center text-red-400 py-8">로딩 실패</td></tr>';
}
}
function renderScheduleTable(list, total) {
const tbody = document.getElementById('scheduleTableBody');
if (!list.length) {
tbody.innerHTML = '<tr><td colspan="7" class="text-center text-gray-400 py-8">일정이 없습니다</td></tr>';
tbody.innerHTML = '<tr><td colspan="8" class="text-center text-gray-400 py-8">일정이 없습니다</td></tr>';
document.getElementById('schedulePagination').innerHTML = '';
return;
}
@@ -43,9 +76,11 @@ function renderScheduleTable(list, total) {
tbody.innerHTML = list.map(s => {
const [cls, label] = statusMap[s.status] || ['badge-gray', s.status];
const canEdit = s.status === 'scheduled';
const projectLabel = s.project_name ? (s.job_no ? `[${s.job_no}] ${s.project_name}` : s.project_name) : '';
return `<tr>
<td class="font-medium">${escapeHtml(s.company_name || '')}</td>
<td>${formatDate(s.work_date)}</td>
<td class="whitespace-nowrap">${formatDateRange(s.start_date, s.end_date)}</td>
<td class="text-xs text-gray-500">${escapeHtml(projectLabel)}</td>
<td class="max-w-xs truncate">${escapeHtml(s.work_description || '')}</td>
<td class="hide-mobile">${escapeHtml(s.workplace_name || '')}</td>
<td class="text-center">${s.expected_workers || 0}명</td>
@@ -131,12 +166,16 @@ function selectCompany(inputId, hiddenId, dropdownId, id, name) {
}
/* ===== Add Schedule ===== */
function openAddSchedule() {
async function openAddSchedule() {
document.getElementById('addScheduleForm').reset();
document.getElementById('addCompanyId').value = '';
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
document.getElementById('addWorkDate').value = tomorrow.toISOString().substring(0, 10);
const tomorrowStr = tomorrow.toISOString().substring(0, 10);
document.getElementById('addStartDate').value = tomorrowStr;
document.getElementById('addEndDate').value = tomorrowStr;
await loadProjects();
populateProjectDropdown('addProject', '');
document.getElementById('addScheduleModal').classList.remove('hidden');
}
@@ -149,9 +188,17 @@ async function submitAddSchedule(e) {
const companyId = document.getElementById('addCompanyId').value;
if (!companyId) { showToast('업체를 선택하세요', 'error'); return; }
const startDate = document.getElementById('addStartDate').value;
const endDate = document.getElementById('addEndDate').value;
if (endDate < startDate) { showToast('종료일은 시작일 이후여야 합니다', 'error'); return; }
const projectId = document.getElementById('addProject').value;
const body = {
partner_company_id: parseInt(companyId),
work_date: document.getElementById('addWorkDate').value,
company_id: parseInt(companyId),
start_date: startDate,
end_date: endDate,
project_id: projectId ? parseInt(projectId) : null,
work_description: document.getElementById('addWorkDescription').value.trim(),
workplace_name: document.getElementById('addWorkplaceName').value.trim(),
expected_workers: parseInt(document.getElementById('addExpectedWorkers').value) || 0,
@@ -179,12 +226,15 @@ async function openEditSchedule(id) {
document.getElementById('editScheduleId').value = id;
document.getElementById('editCompanySearch').value = s.company_name || '';
document.getElementById('editCompanyId').value = s.partner_company_id || '';
document.getElementById('editWorkDate').value = formatDate(s.work_date);
document.getElementById('editCompanyId').value = s.company_id || '';
document.getElementById('editStartDate').value = formatDate(s.start_date);
document.getElementById('editEndDate').value = formatDate(s.end_date);
document.getElementById('editWorkDescription').value = s.work_description || '';
document.getElementById('editWorkplaceName').value = s.workplace_name || '';
document.getElementById('editExpectedWorkers').value = s.expected_workers || 0;
document.getElementById('editNotes').value = s.notes || '';
await loadProjects();
populateProjectDropdown('editProject', s.project_id || '');
document.getElementById('editScheduleModal').classList.remove('hidden');
} catch(e) {
showToast('일정 정보를 불러올 수 없습니다', 'error');
@@ -201,9 +251,17 @@ async function submitEditSchedule(e) {
const companyId = document.getElementById('editCompanyId').value;
if (!companyId) { showToast('업체를 선택하세요', 'error'); return; }
const startDate = document.getElementById('editStartDate').value;
const endDate = document.getElementById('editEndDate').value;
if (endDate < startDate) { showToast('종료일은 시작일 이후여야 합니다', 'error'); return; }
const projectId = document.getElementById('editProject').value;
const body = {
partner_company_id: parseInt(companyId),
work_date: document.getElementById('editWorkDate').value,
company_id: parseInt(companyId),
start_date: startDate,
end_date: endDate,
project_id: projectId ? parseInt(projectId) : null,
work_description: document.getElementById('editWorkDescription').value.trim(),
workplace_name: document.getElementById('editWorkplaceName').value.trim(),
expected_workers: parseInt(document.getElementById('editExpectedWorkers').value) || 0,