diff --git a/tkpurchase/api/controllers/scheduleController.js b/tkpurchase/api/controllers/scheduleController.js index 7a75eda..b226a62 100644 --- a/tkpurchase/api/controllers/scheduleController.js +++ b/tkpurchase/api/controllers/scheduleController.js @@ -4,7 +4,7 @@ const scheduleModel = require('../models/scheduleModel'); async function list(req, res) { try { const { company, company_id, date_from, date_to, status, project_id, page, limit } = req.query; - const rows = await scheduleModel.findAll({ + const { rows, total } = await scheduleModel.findAll({ company: company || undefined, company_id: company_id ? parseInt(company_id) : undefined, date_from, @@ -14,7 +14,7 @@ async function list(req, res) { page: page ? parseInt(page) : 1, limit: limit ? parseInt(limit) : 50 }); - res.json({ success: true, data: rows }); + res.json({ success: true, data: rows, total }); } catch (err) { console.error('Schedule list error:', err); res.status(500).json({ success: false, error: err.message }); diff --git a/tkpurchase/api/index.js b/tkpurchase/api/index.js index bb77b50..973036e 100644 --- a/tkpurchase/api/index.js +++ b/tkpurchase/api/index.js @@ -37,6 +37,12 @@ app.get('/health', (req, res) => { res.json({ status: 'ok', service: 'tkpurchase-api', timestamp: new Date().toISOString() }); }); +// API 캐시 비활성화 +app.use('/api', (req, res, next) => { + res.set('Cache-Control', 'no-store'); + next(); +}); + // Routes app.use('/api/partners', partnerRoutes); app.use('/api/day-labor', dayLaborRoutes); diff --git a/tkpurchase/api/models/scheduleModel.js b/tkpurchase/api/models/scheduleModel.js index 9e360c5..0e64fc1 100644 --- a/tkpurchase/api/models/scheduleModel.js +++ b/tkpurchase/api/models/scheduleModel.js @@ -1,27 +1,35 @@ const { getPool } = require('./partnerModel'); +function buildWhereClause({ company, company_id, date_from, date_to, status, project_id }) { + let where = ' WHERE 1=1'; + const params = []; + if (company) { where += ' AND pc.company_name LIKE ?'; params.push('%' + company + '%'); } + if (company_id) { where += ' AND ps.company_id = ?'; params.push(company_id); } + if (date_from) { where += ' AND ps.end_date >= ?'; params.push(date_from); } + if (date_to) { where += ' AND ps.start_date <= ?'; params.push(date_to); } + if (status) { where += ' AND ps.status = ?'; params.push(status); } + if (project_id) { where += ' AND ps.project_id = ?'; params.push(project_id); } + return { where, params }; +} + async function findAll({ company, company_id, date_from, date_to, status, project_id, page = 1, limit = 50 } = {}) { const db = getPool(); - let sql = `SELECT ps.*, pc.company_name, su.name AS registered_by_name, - p.project_name, p.job_no - FROM partner_schedules ps + const { where, params } = buildWhereClause({ company, company_id, date_from, date_to, status, project_id }); + + const fromClause = ` FROM partner_schedules ps LEFT JOIN partner_companies pc ON ps.company_id = pc.id LEFT JOIN sso_users su ON ps.registered_by = su.user_id - LEFT JOIN projects p ON ps.project_id = p.project_id - WHERE 1=1`; - const params = []; - if (company) { sql += ' AND pc.company_name LIKE ?'; params.push('%' + company + '%'); } - if (company_id) { sql += ' AND ps.company_id = ?'; params.push(company_id); } - if (date_from) { sql += ' AND ps.end_date >= ?'; params.push(date_from); } - if (date_to) { sql += ' AND ps.start_date <= ?'; params.push(date_to); } - if (status) { sql += ' AND ps.status = ?'; params.push(status); } - if (project_id) { sql += ' AND ps.project_id = ?'; params.push(project_id); } + LEFT JOIN projects p ON ps.project_id = p.project_id`; + + const [countResult] = await db.query('SELECT COUNT(*) AS cnt' + fromClause + where, params); + + let sql = `SELECT ps.*, pc.company_name, su.name AS registered_by_name, + p.project_name, p.job_no` + fromClause + where; sql += ' ORDER BY ps.start_date DESC, ps.created_at DESC'; const offset = (page - 1) * limit; sql += ' LIMIT ? OFFSET ?'; - params.push(limit, offset); - const [rows] = await db.query(sql, params); - return rows; + const [rows] = await db.query(sql, [...params, limit, offset]); + return { rows, total: countResult[0].cnt }; } async function findById(id) { diff --git a/tkpurchase/web/accounts.html b/tkpurchase/web/accounts.html index 90a7e8d..9e630b3 100644 --- a/tkpurchase/web/accounts.html +++ b/tkpurchase/web/accounts.html @@ -6,7 +6,7 @@ 계정 관리 - TK 구매관리 - + @@ -133,8 +133,8 @@ - - + + diff --git a/tkpurchase/web/daylabor.html b/tkpurchase/web/daylabor.html index d292b0d..b36ace8 100644 --- a/tkpurchase/web/daylabor.html +++ b/tkpurchase/web/daylabor.html @@ -6,7 +6,7 @@ 일용공 신청 - TK 구매관리 - + @@ -148,8 +148,8 @@ - - + + diff --git a/tkpurchase/web/index.html b/tkpurchase/web/index.html index 734b79a..4a985bd 100644 --- a/tkpurchase/web/index.html +++ b/tkpurchase/web/index.html @@ -6,7 +6,7 @@ 대시보드 - TK 구매관리 - + @@ -88,8 +88,8 @@ - - + + diff --git a/tkpurchase/web/partner-history.html b/tkpurchase/web/partner-history.html index f777f58..680b7c3 100644 --- a/tkpurchase/web/partner-history.html +++ b/tkpurchase/web/partner-history.html @@ -6,7 +6,7 @@ 작업 이력 - TK 구매관리 - + @@ -61,8 +61,8 @@
- - + + diff --git a/tkpurchase/web/partner-portal.html b/tkpurchase/web/partner-portal.html index e8d9eb9..209c7c2 100644 --- a/tkpurchase/web/partner-portal.html +++ b/tkpurchase/web/partner-portal.html @@ -6,7 +6,7 @@ 협력업체 포털 - TK 구매관리 - + @@ -81,8 +81,8 @@ - - + + diff --git a/tkpurchase/web/partner.html b/tkpurchase/web/partner.html index a6ba1b1..cb2fb3b 100644 --- a/tkpurchase/web/partner.html +++ b/tkpurchase/web/partner.html @@ -6,7 +6,7 @@ 협력업체 관리 - TK 구매관리 - + @@ -294,8 +294,8 @@ - - + + diff --git a/tkpurchase/web/schedule.html b/tkpurchase/web/schedule.html index 3e61741..5a354ee 100644 --- a/tkpurchase/web/schedule.html +++ b/tkpurchase/web/schedule.html @@ -6,7 +6,7 @@ 작업일정 - TK 구매관리 - + @@ -275,8 +275,8 @@ - - + + diff --git a/tkpurchase/web/static/js/tkpurchase-accounts.js b/tkpurchase/web/static/js/tkpurchase-accounts.js index 15f1ceb..94d883b 100644 --- a/tkpurchase/web/static/js/tkpurchase-accounts.js +++ b/tkpurchase/web/static/js/tkpurchase-accounts.js @@ -104,7 +104,7 @@ function openAddAccount() { // Default expiration: 1 year from now const oneYear = new Date(); oneYear.setFullYear(oneYear.getFullYear() + 1); - document.getElementById('addExpiresAt').value = oneYear.toISOString().substring(0, 10); + document.getElementById('addExpiresAt').value = toLocalDate(oneYear); document.getElementById('addAccountModal').classList.remove('hidden'); } diff --git a/tkpurchase/web/static/js/tkpurchase-core.js b/tkpurchase/web/static/js/tkpurchase-core.js index 95b199c..3b70409 100644 --- a/tkpurchase/web/static/js/tkpurchase-core.js +++ b/tkpurchase/web/static/js/tkpurchase-core.js @@ -61,6 +61,12 @@ function showToast(msg, type = 'success') { /* ===== Escape ===== */ function escapeHtml(str) { if (!str) return ''; const d = document.createElement('div'); d.textContent = str; return d.innerHTML; } +/* ===== Local Date (timezone-safe) ===== */ +function toLocalDate(d) { + if (!(d instanceof Date) || isNaN(d)) return ''; + return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`; +} + /* ===== Helpers ===== */ function formatDate(d) { if (!d) return ''; return String(d).substring(0, 10); } function formatTime(d) { if (!d) return ''; return String(d).substring(11, 16); } diff --git a/tkpurchase/web/static/js/tkpurchase-dashboard.js b/tkpurchase/web/static/js/tkpurchase-dashboard.js index 9f3a3d9..6fdd19e 100644 --- a/tkpurchase/web/static/js/tkpurchase-dashboard.js +++ b/tkpurchase/web/static/js/tkpurchase-dashboard.js @@ -65,7 +65,7 @@ async function loadTodaySchedules() { } catch(e) { console.warn(e); } } -function todayStr() { return new Date().toISOString().substring(0, 10); } +function todayStr() { return toLocalDate(new Date()); } function initDashboard() { if (!initAuth()) return; diff --git a/tkpurchase/web/static/js/tkpurchase-daylabor.js b/tkpurchase/web/static/js/tkpurchase-daylabor.js index b6ca460..f118a05 100644 --- a/tkpurchase/web/static/js/tkpurchase-daylabor.js +++ b/tkpurchase/web/static/js/tkpurchase-daylabor.js @@ -99,7 +99,7 @@ function openAddDayLabor() { // Default to tomorrow const tomorrow = new Date(); tomorrow.setDate(tomorrow.getDate() + 1); - document.getElementById('addWorkDate').value = tomorrow.toISOString().substring(0, 10); + document.getElementById('addWorkDate').value = toLocalDate(tomorrow); document.getElementById('addDayLaborModal').classList.remove('hidden'); } @@ -167,7 +167,7 @@ function initDayLaborPage() { // Set default date range to this month const now = new Date(); const firstDay = new Date(now.getFullYear(), now.getMonth(), 1); - document.getElementById('filterDateFrom').value = firstDay.toISOString().substring(0, 10); - document.getElementById('filterDateTo').value = now.toISOString().substring(0, 10); + document.getElementById('filterDateFrom').value = toLocalDate(firstDay); + document.getElementById('filterDateTo').value = toLocalDate(now); loadDayLabor(); } diff --git a/tkpurchase/web/static/js/tkpurchase-partner-history.js b/tkpurchase/web/static/js/tkpurchase-partner-history.js index acab6fa..89477cb 100644 --- a/tkpurchase/web/static/js/tkpurchase-partner-history.js +++ b/tkpurchase/web/static/js/tkpurchase-partner-history.js @@ -17,8 +17,8 @@ function initPartnerHistory() { const today = new Date(); const thirtyDaysAgo = new Date(today); thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30); - document.getElementById('filterDateTo').value = today.toISOString().substring(0, 10); - document.getElementById('filterDateFrom').value = thirtyDaysAgo.toISOString().substring(0, 10); + document.getElementById('filterDateTo').value = toLocalDate(today); + document.getElementById('filterDateFrom').value = toLocalDate(thirtyDaysAgo); loadHistory(); } diff --git a/tkpurchase/web/static/js/tkpurchase-partner-portal.js b/tkpurchase/web/static/js/tkpurchase-partner-portal.js index 08c5258..d5e6343 100644 --- a/tkpurchase/web/static/js/tkpurchase-partner-portal.js +++ b/tkpurchase/web/static/js/tkpurchase-partner-portal.js @@ -53,7 +53,7 @@ async function renderScheduleCards() { const requestCardsEl = document.getElementById('requestCards'); const workRequestFormEl = document.getElementById('workRequestForm'); - const today = new Date().toISOString().substring(0, 10); + const today = toLocalDate(new Date()); if (!portalSchedules.length) { container.innerHTML = ''; diff --git a/tkpurchase/web/static/js/tkpurchase-schedule.js b/tkpurchase/web/static/js/tkpurchase-schedule.js index bc6029d..dd8661e 100644 --- a/tkpurchase/web/static/js/tkpurchase-schedule.js +++ b/tkpurchase/web/static/js/tkpurchase-schedule.js @@ -177,7 +177,7 @@ async function openAddSchedule() { document.getElementById('addCompanyId').value = ''; const tomorrow = new Date(); tomorrow.setDate(tomorrow.getDate() + 1); - const tomorrowStr = tomorrow.toISOString().substring(0, 10); + const tomorrowStr = toLocalDate(tomorrow); document.getElementById('addStartDate').value = tomorrowStr; document.getElementById('addEndDate').value = tomorrowStr; await loadProjects(); @@ -446,8 +446,8 @@ function initSchedulePage() { const now = new Date(); const firstDay = new Date(now.getFullYear(), now.getMonth(), 1); const lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0); - document.getElementById('filterDateFrom').value = firstDay.toISOString().substring(0, 10); - document.getElementById('filterDateTo').value = lastDay.toISOString().substring(0, 10); + document.getElementById('filterDateFrom').value = toLocalDate(firstDay); + document.getElementById('filterDateTo').value = toLocalDate(lastDay); // Setup autocomplete for both modals setupCompanyAutocomplete('addCompanySearch', 'addCompanyDropdown', 'addCompanyId'); diff --git a/tkpurchase/web/static/js/tkpurchase-workreport-summary.js b/tkpurchase/web/static/js/tkpurchase-workreport-summary.js index b492c48..4ae731c 100644 --- a/tkpurchase/web/static/js/tkpurchase-workreport-summary.js +++ b/tkpurchase/web/static/js/tkpurchase-workreport-summary.js @@ -140,8 +140,8 @@ function initSummaryPage() { // 기본 기간: 이번 달 const now = new Date(); const firstDay = new Date(now.getFullYear(), now.getMonth(), 1); - document.getElementById('filterDateFrom').value = firstDay.toISOString().substring(0, 10); - document.getElementById('filterDateTo').value = now.toISOString().substring(0, 10); + document.getElementById('filterDateFrom').value = toLocalDate(firstDay); + document.getElementById('filterDateTo').value = toLocalDate(now); loadCompaniesForFilter(); loadSchedulesForFilter(); diff --git a/tkpurchase/web/static/js/tkpurchase-workreport.js b/tkpurchase/web/static/js/tkpurchase-workreport.js index 03aeb1b..0f6bd84 100644 --- a/tkpurchase/web/static/js/tkpurchase-workreport.js +++ b/tkpurchase/web/static/js/tkpurchase-workreport.js @@ -404,8 +404,8 @@ function initWorkReportPage() { // Set default date range to this month const now = new Date(); const firstDay = new Date(now.getFullYear(), now.getMonth(), 1); - document.getElementById('filterDateFrom').value = firstDay.toISOString().substring(0, 10); - document.getElementById('filterDateTo').value = now.toISOString().substring(0, 10); + document.getElementById('filterDateFrom').value = toLocalDate(firstDay); + document.getElementById('filterDateTo').value = toLocalDate(now); loadCompaniesForFilter(); loadReports(); diff --git a/tkpurchase/web/workreport-summary.html b/tkpurchase/web/workreport-summary.html index aecb57c..0ade11a 100644 --- a/tkpurchase/web/workreport-summary.html +++ b/tkpurchase/web/workreport-summary.html @@ -6,7 +6,7 @@ 업무현황 종합 - TK 구매관리 - + @@ -100,8 +100,8 @@ - - + + diff --git a/tkpurchase/web/workreport.html b/tkpurchase/web/workreport.html index a223003..3c0b54d 100644 --- a/tkpurchase/web/workreport.html +++ b/tkpurchase/web/workreport.html @@ -6,7 +6,7 @@ 업무현황 - TK 구매관리 - + @@ -114,8 +114,8 @@ - - + +