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:
@@ -108,4 +108,16 @@ async function stats(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { list, myCheckins, checkIn, checkOut, update, stats };
|
||||
// 체크인 삭제
|
||||
async function deleteCheckin(req, res) {
|
||||
try {
|
||||
const result = await checkinModel.deleteCheckin(req.params.id);
|
||||
if (!result) return res.status(404).json({ success: false, error: '체크인 기록을 찾을 수 없습니다' });
|
||||
res.json({ success: true });
|
||||
} catch (err) {
|
||||
console.error('Checkin delete error:', err);
|
||||
res.status(500).json({ success: false, error: err.message });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { list, myCheckins, checkIn, checkOut, update, stats, deleteCheckin };
|
||||
|
||||
@@ -78,4 +78,32 @@ async function countActive() {
|
||||
return rows[0].cnt;
|
||||
}
|
||||
|
||||
module.exports = { findBySchedule, findById, findTodayByCompany, checkIn, checkOut, update, resetCheckout, countActive };
|
||||
async function deleteCheckin(id) {
|
||||
const checkin = await findById(id);
|
||||
if (!checkin) return false;
|
||||
|
||||
const db = getPool();
|
||||
const conn = await db.getConnection();
|
||||
try {
|
||||
await conn.beginTransaction();
|
||||
await conn.query('DELETE FROM partner_work_reports WHERE checkin_id = ?', [id]);
|
||||
await conn.query('DELETE FROM partner_work_checkins WHERE id = ?', [id]);
|
||||
const [remaining] = await conn.query(
|
||||
'SELECT COUNT(*) AS cnt FROM partner_work_checkins WHERE schedule_id = ?',
|
||||
[checkin.schedule_id]);
|
||||
if (remaining[0].cnt === 0) {
|
||||
await conn.query(
|
||||
"UPDATE partner_schedules SET status = 'scheduled' WHERE id = ? AND status = 'in_progress'",
|
||||
[checkin.schedule_id]);
|
||||
}
|
||||
await conn.commit();
|
||||
return true;
|
||||
} catch (err) {
|
||||
await conn.rollback();
|
||||
throw err;
|
||||
} finally {
|
||||
conn.release();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { findBySchedule, findById, findTodayByCompany, checkIn, checkOut, update, resetCheckout, countActive, deleteCheckin };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { requireAuth } = require('../middleware/auth');
|
||||
const { requireAuth, requirePage } = require('../middleware/auth');
|
||||
const ctrl = require('../controllers/checkinController');
|
||||
|
||||
router.use(requireAuth);
|
||||
@@ -10,6 +10,7 @@ router.get('/schedule/:scheduleId', ctrl.list);
|
||||
router.get('/my', ctrl.myCheckins); // partner portal
|
||||
router.post('/', ctrl.checkIn); // partner can do this
|
||||
router.put('/:id/checkout', ctrl.checkOut);
|
||||
router.put('/:id', ctrl.update);
|
||||
router.put('/:id', requirePage('purchasing_schedule'), ctrl.update);
|
||||
router.delete('/:id', requirePage('purchasing_schedule'), ctrl.deleteCheckin);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -211,8 +211,21 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/tkpurchase-core.js?v=20260312"></script>
|
||||
<script src="/static/js/tkpurchase-schedule.js?v=20260312"></script>
|
||||
<!-- 체크인 상세 모달 -->
|
||||
<div id="checkinModal" class="hidden modal-overlay" onclick="if(event.target===this)closeCheckinModal()">
|
||||
<div class="modal-content p-6" style="max-width:600px">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<h3 class="text-lg font-semibold">체크인 현황</h3>
|
||||
<button onclick="closeCheckinModal()" class="text-gray-400 hover:text-gray-600"><i class="fas fa-times"></i></button>
|
||||
</div>
|
||||
<div id="checkinModalBody" class="space-y-3">
|
||||
<p class="text-gray-400 text-center py-4">로딩 중...</p>
|
||||
</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>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -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