feat(tkpurchase): 협력업체 작업 신청 기능 추가
협력업체 포탈에서 오늘 일정이 없을 때 직접 작업을 신청할 수 있는 기능. 구매팀이 승인하면 일정이 생성되고, 반려 시 재신청 가능. - DB: status ENUM에 requested/rejected 추가, requested_by 컬럼 추가 - API: POST /schedules/request, PUT /:id/approve, PUT /:id/reject - 포탈: 신청 폼 + 승인 대기/반려 상태 카드 - 관리자: 신청 배지 + 승인 모달 (프로젝트 배정, 작업장 보정) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,10 +48,36 @@
|
||||
<p class="text-gray-400 text-center py-8 text-sm">로딩 중...</p>
|
||||
</div>
|
||||
|
||||
<!-- 일정 없을 때 -->
|
||||
<div id="noScheduleMessage" class="hidden bg-white rounded-xl shadow-sm p-8 text-center">
|
||||
<i class="fas fa-calendar-times text-gray-300 text-4xl mb-3"></i>
|
||||
<p class="text-gray-500">오늘 예정된 작업 일정이 없습니다.</p>
|
||||
<!-- 신청 대기 / 반려 카드 영역 -->
|
||||
<div id="requestCards" class="hidden space-y-4"></div>
|
||||
|
||||
<!-- 작업 신청 폼 -->
|
||||
<div id="workRequestForm" class="hidden bg-white rounded-xl shadow-sm p-6">
|
||||
<h3 class="text-base font-semibold text-gray-800 mb-4">
|
||||
<i class="fas fa-paper-plane text-emerald-500 mr-2"></i>작업 신청
|
||||
</h3>
|
||||
<p class="text-sm text-gray-500 mb-4">오늘 예정된 작업 일정이 없습니다. 작업이 필요하시면 아래에서 신청해주세요.</p>
|
||||
<div class="space-y-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="reqStartDate" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">예상 인원</label>
|
||||
<input type="number" id="reqExpectedWorkers" min="1" value="1" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">작업 내용 <span class="text-red-400">*</span></label>
|
||||
<textarea id="reqWorkDescription" rows="3" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="작업 내용을 입력하세요"></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">작업장</label>
|
||||
<input type="text" id="reqWorkplaceName" class="input-field w-full px-3 py-2 rounded-lg text-sm" placeholder="작업 장소">
|
||||
</div>
|
||||
<button onclick="doWorkRequest()" class="w-full px-4 py-3 bg-emerald-600 text-white rounded-lg text-sm hover:bg-emerald-700 font-medium">
|
||||
<i class="fas fa-paper-plane mr-1"></i>작업 신청
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -52,10 +52,12 @@
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">상태</label>
|
||||
<select id="filterStatus" class="input-field px-3 py-2 rounded-lg text-sm">
|
||||
<option value="">전체</option>
|
||||
<option value="requested">신청</option>
|
||||
<option value="scheduled">예정</option>
|
||||
<option value="in_progress">진행중</option>
|
||||
<option value="completed">완료</option>
|
||||
<option value="cancelled">취소</option>
|
||||
<option value="rejected">반려</option>
|
||||
</select>
|
||||
</div>
|
||||
<button onclick="loadSchedules()" class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg text-sm hover:bg-gray-200">
|
||||
@@ -224,6 +226,51 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 승인 모달 -->
|
||||
<div id="approveModal" class="hidden modal-overlay" onclick="if(event.target===this)closeApproveModal()">
|
||||
<div class="modal-content p-6">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<h3 class="text-lg font-semibold">작업 신청 승인</h3>
|
||||
<button onclick="closeApproveModal()" class="text-gray-400 hover:text-gray-600"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
<input type="hidden" id="approveScheduleId">
|
||||
<div class="space-y-3">
|
||||
<div class="bg-amber-50 rounded-lg p-4 text-sm">
|
||||
<div class="font-medium text-amber-800 mb-2"><i class="fas fa-info-circle mr-1"></i>신청 정보</div>
|
||||
<div id="approveInfo" class="space-y-1 text-gray-700"></div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">프로젝트 배정</label>
|
||||
<select id="approveProject" 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>
|
||||
<input type="text" id="approveWorkplace" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">작업일</label>
|
||||
<input type="date" id="approveStartDate" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-600 mb-1">종료일</label>
|
||||
<input type="date" id="approveEndDate" class="input-field w-full px-3 py-2 rounded-lg text-sm">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end mt-4 gap-2">
|
||||
<button onclick="doReject()" class="px-4 py-2 bg-red-500 text-white rounded-lg text-sm hover:bg-red-600">
|
||||
<i class="fas fa-times mr-1"></i>반려
|
||||
</button>
|
||||
<button onclick="doApprove()" class="px-4 py-2 bg-emerald-600 text-white rounded-lg text-sm hover:bg-emerald-700">
|
||||
<i class="fas fa-check mr-1"></i>승인
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=20260313"></script>
|
||||
<script src="/static/js/tkpurchase-schedule.js?v=20260313"></script>
|
||||
<script>initSchedulePage();</script>
|
||||
|
||||
@@ -30,6 +30,7 @@ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; b
|
||||
.badge-blue { background: #eff6ff; color: #2563eb; }
|
||||
.badge-amber { background: #fffbeb; color: #d97706; }
|
||||
.badge-red { background: #fef2f2; color: #dc2626; }
|
||||
.badge-orange { background: #fff7ed; color: #ea580c; }
|
||||
.badge-gray { background: #f3f4f6; color: #6b7280; }
|
||||
|
||||
/* Purpose badges */
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* tkpurchase-partner-portal.js - Partner portal logic (2-step flow) */
|
||||
|
||||
let portalSchedules = [];
|
||||
let portalRequests = [];
|
||||
let portalCheckins = {};
|
||||
let partnerCompanyId = null;
|
||||
let companyWorkersCache = null;
|
||||
@@ -8,10 +9,13 @@ let companyWorkersCache = null;
|
||||
async function loadMySchedules() {
|
||||
try {
|
||||
const r = await api('/schedules/my');
|
||||
portalSchedules = r.data || [];
|
||||
const data = r.data || {};
|
||||
portalSchedules = data.schedules || [];
|
||||
portalRequests = data.requests || [];
|
||||
} catch(e) {
|
||||
console.warn('Load schedules error:', e);
|
||||
portalSchedules = [];
|
||||
portalRequests = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,15 +50,59 @@ async function renderScheduleCards() {
|
||||
await Promise.all([loadMySchedules(), loadMyCheckins()]);
|
||||
|
||||
const container = document.getElementById('scheduleCards');
|
||||
const noMsg = document.getElementById('noScheduleMessage');
|
||||
const requestCardsEl = document.getElementById('requestCards');
|
||||
const workRequestFormEl = document.getElementById('workRequestForm');
|
||||
|
||||
if (!portalSchedules.length) {
|
||||
container.innerHTML = '';
|
||||
noMsg.classList.remove('hidden');
|
||||
// 신청 건 표시
|
||||
if (portalRequests.length) {
|
||||
requestCardsEl.classList.remove('hidden');
|
||||
requestCardsEl.innerHTML = portalRequests.map(r => {
|
||||
const isRejected = r.status === 'rejected';
|
||||
const statusBg = isRejected ? 'bg-red-50 border-red-200' : 'bg-amber-50 border-amber-200';
|
||||
const statusIcon = isRejected ? 'fa-times-circle text-red-400' : 'fa-clock text-amber-400';
|
||||
const statusText = isRejected ? '반려됨' : '승인 대기 중';
|
||||
const statusTextClass = isRejected ? 'text-red-600' : 'text-amber-600';
|
||||
return `<div class="bg-white rounded-xl shadow-sm overflow-hidden border ${isRejected ? 'border-red-100' : 'border-amber-100'}">
|
||||
<div class="p-5">
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<h3 class="text-base font-semibold text-gray-800">${escapeHtml(r.workplace_name || '작업장 미지정')}</h3>
|
||||
<span class="text-xs ${statusTextClass} font-medium px-2 py-1 rounded-full ${statusBg}">
|
||||
<i class="fas ${statusIcon} mr-1"></i>${statusText}
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-sm text-gray-600 mb-2">${escapeHtml(r.work_description || '')}</div>
|
||||
<div class="flex gap-4 text-xs text-gray-500">
|
||||
<span><i class="fas fa-calendar mr-1"></i>${formatDate(r.start_date)}</span>
|
||||
<span><i class="fas fa-users mr-1"></i>예상 ${r.expected_workers || 0}명</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
// 반려 건만 있으면 재신청 폼도 표시
|
||||
const hasOnlyRejected = portalRequests.every(r => r.status === 'rejected');
|
||||
if (hasOnlyRejected) {
|
||||
workRequestFormEl.classList.remove('hidden');
|
||||
workRequestFormEl.querySelector('p').textContent = '반려된 신청 건이 있습니다. 필요시 재신청해주세요.';
|
||||
} else {
|
||||
workRequestFormEl.classList.add('hidden');
|
||||
}
|
||||
} else {
|
||||
requestCardsEl.classList.add('hidden');
|
||||
workRequestFormEl.classList.remove('hidden');
|
||||
workRequestFormEl.querySelector('p').textContent = '오늘 예정된 작업 일정이 없습니다. 작업이 필요하시면 아래에서 신청해주세요.';
|
||||
}
|
||||
// 기본 날짜 설정
|
||||
const today = new Date().toISOString().substring(0, 10);
|
||||
const reqDate = document.getElementById('reqStartDate');
|
||||
if (reqDate && !reqDate.value) reqDate.value = today;
|
||||
return;
|
||||
}
|
||||
|
||||
noMsg.classList.add('hidden');
|
||||
// 오늘 일정 있으면 기존 카드 렌더
|
||||
requestCardsEl.classList.add('hidden');
|
||||
workRequestFormEl.classList.add('hidden');
|
||||
|
||||
container.innerHTML = portalSchedules.map(s => {
|
||||
const checkin = portalCheckins[s.id];
|
||||
@@ -303,6 +351,32 @@ async function doCheckIn(scheduleId) {
|
||||
}
|
||||
}
|
||||
|
||||
async function doWorkRequest() {
|
||||
const startDate = document.getElementById('reqStartDate').value;
|
||||
if (!startDate) { showToast('작업일을 선택하세요', 'error'); return; }
|
||||
const workDescription = document.getElementById('reqWorkDescription').value.trim();
|
||||
if (!workDescription) { showToast('작업 내용을 입력하세요', 'error'); return; }
|
||||
|
||||
const body = {
|
||||
start_date: startDate,
|
||||
expected_workers: parseInt(document.getElementById('reqExpectedWorkers').value) || 1,
|
||||
work_description: workDescription,
|
||||
workplace_name: document.getElementById('reqWorkplaceName').value.trim() || null
|
||||
};
|
||||
|
||||
try {
|
||||
await api('/schedules/request', { method: 'POST', body: JSON.stringify(body) });
|
||||
showToast('작업 신청이 완료되었습니다');
|
||||
// 폼 초기화
|
||||
document.getElementById('reqWorkDescription').value = '';
|
||||
document.getElementById('reqWorkplaceName').value = '';
|
||||
document.getElementById('reqExpectedWorkers').value = '1';
|
||||
renderScheduleCards();
|
||||
} catch(e) {
|
||||
showToast(e.message || '작업 신청 실패', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function initPartnerPortal() {
|
||||
if (!initAuth()) return;
|
||||
|
||||
|
||||
@@ -67,17 +67,20 @@ function renderScheduleTable(list, total) {
|
||||
}
|
||||
|
||||
const statusMap = {
|
||||
requested: ['badge-orange', '신청'],
|
||||
scheduled: ['badge-amber', '예정'],
|
||||
in_progress: ['badge-green', '진행중'],
|
||||
completed: ['badge-blue', '완료'],
|
||||
cancelled: ['badge-gray', '취소']
|
||||
cancelled: ['badge-gray', '취소'],
|
||||
rejected: ['badge-red', '반려']
|
||||
};
|
||||
|
||||
tbody.innerHTML = list.map(s => {
|
||||
const [cls, label] = statusMap[s.status] || ['badge-gray', s.status];
|
||||
const canEdit = s.status === 'scheduled';
|
||||
const isRequest = s.status === 'requested';
|
||||
const projectLabel = s.project_name ? (s.job_no ? `[${s.job_no}] ${s.project_name}` : s.project_name) : '';
|
||||
return `<tr>
|
||||
return `<tr${isRequest ? ' class="bg-amber-50"' : ''}>
|
||||
<td class="font-medium">${escapeHtml(s.company_name || '')}</td>
|
||||
<td class="whitespace-nowrap">${formatDateRange(s.start_date, s.end_date)}</td>
|
||||
<td class="text-xs text-gray-500">${escapeHtml(projectLabel)}</td>
|
||||
@@ -86,6 +89,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">
|
||||
${isRequest ? `<button onclick="openApproveModal(${s.id})" class="text-amber-600 hover:text-amber-800 text-xs mr-1 font-medium" title="승인/반려"><i class="fas fa-check-circle mr-1"></i>처리</button>` : ''}
|
||||
${(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>` : ''}
|
||||
@@ -368,6 +372,72 @@ async function editCheckinWorkers(checkinId) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== Approve/Reject Request ===== */
|
||||
async function openApproveModal(id) {
|
||||
try {
|
||||
const r = await api('/schedules/' + id);
|
||||
const s = r.data || r;
|
||||
scheduleCache[id] = s;
|
||||
|
||||
document.getElementById('approveScheduleId').value = id;
|
||||
document.getElementById('approveInfo').innerHTML = `
|
||||
<div><strong>업체:</strong> ${escapeHtml(s.company_name || '')}</div>
|
||||
<div><strong>작업일:</strong> ${formatDate(s.start_date)}</div>
|
||||
<div><strong>예상 인원:</strong> ${s.expected_workers || 0}명</div>
|
||||
<div><strong>작업 내용:</strong> ${escapeHtml(s.work_description || '-')}</div>
|
||||
<div><strong>작업장:</strong> ${escapeHtml(s.workplace_name || '-')}</div>
|
||||
`;
|
||||
document.getElementById('approveWorkplace').value = s.workplace_name || '';
|
||||
document.getElementById('approveStartDate').value = formatDate(s.start_date);
|
||||
document.getElementById('approveEndDate').value = formatDate(s.end_date);
|
||||
await loadProjects();
|
||||
populateProjectDropdown('approveProject', '');
|
||||
document.getElementById('approveModal').classList.remove('hidden');
|
||||
} catch(e) {
|
||||
showToast('신청 정보를 불러올 수 없습니다', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function closeApproveModal() {
|
||||
document.getElementById('approveModal').classList.add('hidden');
|
||||
}
|
||||
|
||||
async function doApprove() {
|
||||
const id = document.getElementById('approveScheduleId').value;
|
||||
if (!confirm('이 작업 신청을 승인하시겠습니까?')) return;
|
||||
|
||||
const projectId = document.getElementById('approveProject').value;
|
||||
const body = {
|
||||
project_id: projectId ? parseInt(projectId) : null,
|
||||
workplace_name: document.getElementById('approveWorkplace').value.trim(),
|
||||
start_date: document.getElementById('approveStartDate').value,
|
||||
end_date: document.getElementById('approveEndDate').value
|
||||
};
|
||||
|
||||
try {
|
||||
await api('/schedules/' + id + '/approve', { method: 'PUT', body: JSON.stringify(body) });
|
||||
showToast('승인 완료');
|
||||
closeApproveModal();
|
||||
loadSchedules();
|
||||
} catch(e) {
|
||||
showToast(e.message || '승인 실패', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function doReject() {
|
||||
const id = document.getElementById('approveScheduleId').value;
|
||||
if (!confirm('이 작업 신청을 반려하시겠습니까?')) return;
|
||||
|
||||
try {
|
||||
await api('/schedules/' + id + '/reject', { method: 'PUT' });
|
||||
showToast('반려 완료');
|
||||
closeApproveModal();
|
||||
loadSchedules();
|
||||
} catch(e) {
|
||||
showToast(e.message || '반려 실패', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== Init ===== */
|
||||
function initSchedulePage() {
|
||||
if (!initAuth()) return;
|
||||
|
||||
Reference in New Issue
Block a user