171 lines
5.7 KiB
PHP
171 lines
5.7 KiB
PHP
<?php
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL);
|
|
?>
|
|
<!doctype html>
|
|
<html lang="ko">
|
|
<head>
|
|
<?php include __DIR__ . '/html/_include/_head.php'; ?>
|
|
</head>
|
|
<body>
|
|
<div class="wrap">
|
|
<?php include __DIR__ . '/html/_include/_header.php'; ?>
|
|
<!-- container -->
|
|
<div class="container">
|
|
<div class="main-contents">
|
|
<div class="main-grid">
|
|
<!-- 연간 총 판매 실적 -->
|
|
<?php include __DIR__ . '/html/main_sub/yearly_chart.php'; ?>
|
|
<!-- //연간 총 판매 실적 -->
|
|
|
|
<!-- 연간 개별 판매 실적 -->
|
|
<?php include __DIR__ . '/html/main_sub/individual_chart.php'; ?>
|
|
<!-- //연간 개별 판매 실적 -->
|
|
|
|
<!-- 연간 영업 판매 실적 -->
|
|
<?php include __DIR__ . '/html/main_sub/sales_chart.php'; ?>
|
|
<!-- //연간 영업 판매 실적 -->
|
|
|
|
<!-- 월 판매 실적 -->
|
|
<?php include __DIR__ . '/html/main_sub/month_chart.php'; ?>
|
|
<!-- //월 판매 실적 -->
|
|
</div>
|
|
|
|
<!-- 주간 영업 계획 -->
|
|
<?php include __DIR__ . '/html/main_sub/weekly_plan.php'; ?>
|
|
<!-- //주간 영업 계획 -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
(() => {
|
|
// 리사이즈 이벤트 리스너 (디바운스 적용)
|
|
let resizeTimer;
|
|
window.addEventListener("resize", () => {
|
|
clearTimeout(resizeTimer);
|
|
resizeTimer = setTimeout(() => {
|
|
createYearlyChart();
|
|
createIndividualChart();
|
|
createMonthChart();
|
|
createIndustryChart();
|
|
}, 250); // 250ms 디바운스
|
|
});
|
|
})();
|
|
|
|
/* =========================================================
|
|
공통: 헤더 업데이트 시간
|
|
========================================================= */
|
|
function updateHeaderDate() {
|
|
const now = new Date();
|
|
|
|
const y = now.getFullYear();
|
|
const m = String(now.getMonth() + 1).padStart(2, "0");
|
|
const d = String(now.getDate()).padStart(2, "0");
|
|
const hh = String(now.getHours()).padStart(2, "0");
|
|
const mm = String(now.getMinutes()).padStart(2, "0");
|
|
const weekday = ["일","월","화","수","목","금","토"][now.getDay()];
|
|
|
|
const dateEl = document.querySelector(".header .date");
|
|
if (dateEl) {
|
|
dateEl.textContent = `업데이트 : ${y}.${m}.${d}(${weekday}) ${hh}:${mm}`;
|
|
}
|
|
}
|
|
|
|
/* =========================================================
|
|
공통: 증감 표시 UI
|
|
========================================================= */
|
|
function updateDiff(id, value) {
|
|
const el = document.getElementById(id);
|
|
if (!el) return;
|
|
|
|
const wrap = el.parentElement;
|
|
|
|
wrap.classList.remove("change", "change-up", "change-down");
|
|
|
|
if (value > 0) {
|
|
wrap.classList.add("change-up");
|
|
} else if (value < 0) {
|
|
wrap.classList.add("change-down");
|
|
} else {
|
|
wrap.classList.add("change");
|
|
}
|
|
|
|
el.textContent = Math.abs(value);
|
|
}
|
|
|
|
/* =========================================================
|
|
🔥 대시보드 전체 갱신 컨트롤 타워
|
|
========================================================= */
|
|
function refreshDashboard() {
|
|
Promise.all([
|
|
// 연간 영업 판매 현황
|
|
typeof loadSalesDashboardData === "function"
|
|
? loadSalesDashboardData()
|
|
: Promise.resolve(),
|
|
|
|
// 연간 총 판매 실적
|
|
typeof loadYearlyDashboardData === "function"
|
|
? loadYearlyDashboardData()
|
|
: Promise.resolve(),
|
|
|
|
// 월 판매 실적
|
|
typeof loadMonthDashboardData === "function"
|
|
? loadMonthDashboardData()
|
|
: Promise.resolve(),
|
|
|
|
// 개인별 연간 실적
|
|
typeof loadIndividualDashboardData === "function"
|
|
? loadIndividualDashboardData()
|
|
: Promise.resolve(),
|
|
|
|
// 주간 영업계획 (있을 때만)
|
|
typeof loadWeeklyPlanData === "function"
|
|
? loadWeeklyPlanData()
|
|
: Promise.resolve(),
|
|
]).then(() => {
|
|
updateHeaderDate();
|
|
});
|
|
}
|
|
|
|
/* =========================================================
|
|
🔄 자동 갱신 제어
|
|
========================================================= */
|
|
let autoRefreshTimer = null;
|
|
|
|
function startAutoRefresh() {
|
|
if (autoRefreshTimer) return;
|
|
|
|
// 5분(300초)
|
|
autoRefreshTimer = setInterval(refreshDashboard, 60000);
|
|
}
|
|
|
|
function stopAutoRefresh() {
|
|
if (autoRefreshTimer) {
|
|
clearInterval(autoRefreshTimer);
|
|
autoRefreshTimer = null;
|
|
}
|
|
}
|
|
|
|
/* =========================================================
|
|
탭 비활성화 시 갱신 중단
|
|
========================================================= */
|
|
document.addEventListener("visibilitychange", () => {
|
|
if (document.hidden) {
|
|
stopAutoRefresh();
|
|
} else {
|
|
refreshDashboard();
|
|
startAutoRefresh();
|
|
}
|
|
});
|
|
|
|
/* =========================================================
|
|
초기 실행
|
|
========================================================= */
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
refreshDashboard(); // 최초 1회
|
|
startAutoRefresh(); // 이후 자동 갱신
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|