diff --git a/tkpurchase/api/controllers/checkinController.js b/tkpurchase/api/controllers/checkinController.js index 2c7c3d4..c1e370e 100644 --- a/tkpurchase/api/controllers/checkinController.js +++ b/tkpurchase/api/controllers/checkinController.js @@ -20,7 +20,7 @@ async function myCheckins(req, res) { if (!companyId) { return res.status(403).json({ success: false, error: '협력업체 계정이 아닙니다' }); } - const rows = await checkinModel.findTodayByCompany(companyId); + const rows = await checkinModel.findActiveByCompany(companyId); res.json({ success: true, data: rows }); } catch (err) { console.error('Checkin myCheckins error:', err); @@ -39,19 +39,13 @@ async function checkIn(req, res) { if (!resolvedCompanyId) { return res.status(400).json({ success: false, error: '업체 정보가 필요합니다' }); } - // 일정 기간 내 체크인 검증 + // 일정 유효성 검증 const schedule = await scheduleModel.findById(schedule_id); if (!schedule) { return res.status(404).json({ success: false, error: '일정을 찾을 수 없습니다' }); } - const today = new Date(); - today.setHours(0, 0, 0, 0); - const startDate = new Date(schedule.start_date); - startDate.setHours(0, 0, 0, 0); - const endDate = new Date(schedule.end_date); - endDate.setHours(0, 0, 0, 0); - if (today < startDate || today > endDate) { - return res.status(400).json({ success: false, error: '오늘은 해당 일정의 작업 기간이 아닙니다' }); + if (['cancelled', 'rejected', 'completed'].includes(schedule.status)) { + return res.status(400).json({ success: false, error: '마감되었거나 취소된 일정입니다' }); } const data = { schedule_id, diff --git a/tkpurchase/api/controllers/scheduleController.js b/tkpurchase/api/controllers/scheduleController.js index 7502f5a..7480aaf 100644 --- a/tkpurchase/api/controllers/scheduleController.js +++ b/tkpurchase/api/controllers/scheduleController.js @@ -41,7 +41,7 @@ async function mySchedules(req, res) { return res.status(403).json({ success: false, error: '협력업체 계정이 아닙니다' }); } const [schedules, requests] = await Promise.all([ - scheduleModel.findByCompanyToday(companyId), + scheduleModel.findActiveByCompany(companyId), scheduleModel.findRequestsByCompany(companyId) ]); res.json({ success: true, data: { schedules, requests } }); diff --git a/tkpurchase/api/models/checkinModel.js b/tkpurchase/api/models/checkinModel.js index 75acaef..7f1baaa 100644 --- a/tkpurchase/api/models/checkinModel.js +++ b/tkpurchase/api/models/checkinModel.js @@ -216,4 +216,17 @@ async function findHistoryByCompany(companyId, { dateFrom, dateTo, page = 1, lim return { data: checkins, total, page, limit }; } -module.exports = { findBySchedule, findById, findTodayByCompany, checkIn, checkOut, update, resetCheckout, countActive, deleteCheckin, checkOutWithReport, findHistoryByCompany }; +async function findActiveByCompany(companyId) { + const db = getPool(); + const [rows] = await db.query( + `SELECT pc.*, ps.work_description, ps.workplace_name, + (SELECT COUNT(*) FROM partner_work_reports WHERE checkin_id = pc.id) AS work_report_count + FROM partner_work_checkins pc + LEFT JOIN partner_schedules ps ON pc.schedule_id = ps.id + WHERE pc.company_id = ? + AND (pc.check_out_time IS NULL OR DATE(pc.check_in_time) = CURDATE()) + ORDER BY pc.check_in_time DESC`, [companyId]); + return rows; +} + +module.exports = { findBySchedule, findById, findTodayByCompany, findActiveByCompany, checkIn, checkOut, update, resetCheckout, countActive, deleteCheckin, checkOutWithReport, findHistoryByCompany }; diff --git a/tkpurchase/api/models/scheduleModel.js b/tkpurchase/api/models/scheduleModel.js index b271873..fc01e0c 100644 --- a/tkpurchase/api/models/scheduleModel.js +++ b/tkpurchase/api/models/scheduleModel.js @@ -117,4 +117,17 @@ async function deleteSchedule(id) { await db.query('DELETE FROM partner_schedules WHERE id = ?', [id]); } -module.exports = { findAll, findById, findByCompanyToday, findRequestsByCompany, findByProject, create, update, updateStatus, deleteSchedule }; +async function findActiveByCompany(companyId) { + const db = getPool(); + const [rows] = await db.query( + `SELECT ps.*, pc.company_name, p.project_name, p.job_no + FROM partner_schedules ps + LEFT JOIN partner_companies pc ON ps.company_id = pc.id + LEFT JOIN projects p ON ps.project_id = p.project_id + WHERE ps.company_id = ? + AND ps.status NOT IN ('cancelled','rejected','requested','completed') + ORDER BY ps.start_date ASC, ps.created_at DESC`, [companyId]); + return rows; +} + +module.exports = { findAll, findById, findByCompanyToday, findActiveByCompany, findRequestsByCompany, findByProject, create, update, updateStatus, deleteSchedule }; diff --git a/tkpurchase/web/partner-portal.html b/tkpurchase/web/partner-portal.html index 3cf1da9..a63ec9f 100644 --- a/tkpurchase/web/partner-portal.html +++ b/tkpurchase/web/partner-portal.html @@ -35,7 +35,7 @@
오늘의 작업 일정을 확인하세요.
+작업 일정을 확인하세요.