179 lines
5.2 KiB
PHP
179 lines
5.2 KiB
PHP
<!-- header -->
|
|
<!-- <header class="header">
|
|
<button class="logo" onclick="fullScreen();" title="">EG-BIM</button>
|
|
<h1 class="title" data-text="2025년 판매 상세 현황">2025년 판매 상세 현황</h1>
|
|
<div class="date">업데이트 : 2025.11.21(금) 18:00</div>
|
|
</header> -->
|
|
<?php
|
|
$DB_HOST = "localhost";
|
|
$DB_NAME = "egbim";
|
|
$DB_USER = "egbim";
|
|
$DB_PASS = "baron3840!!";
|
|
|
|
try {
|
|
$pdo = new PDO(
|
|
"mysql:host={$DB_HOST};dbname={$DB_NAME};charset=utf8mb4",
|
|
$DB_USER,
|
|
$DB_PASS,
|
|
[
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
]
|
|
);
|
|
} catch (Exception $e) {
|
|
echo json_encode([
|
|
"status" => "fail",
|
|
"message" => "DB 연결 실패: " . $e->getMessage()
|
|
]);
|
|
exit;
|
|
}
|
|
// 기준 연도
|
|
$START_YEAR = 2025;
|
|
|
|
// 현재 연도 (URL 우선)
|
|
$year = isset($_GET['year']) ? (int)$_GET['year'] : date('Y');
|
|
if ($year < $START_YEAR) $year = $START_YEAR;
|
|
|
|
// 누적 기간
|
|
$startDate = $START_YEAR . '-01-01';
|
|
$endDate = $year . '-12-31';
|
|
|
|
// 누적 판매 copy 계산
|
|
$stmt = $pdo->prepare("
|
|
SELECT COALESCE(SUM(quantity), 0) AS total
|
|
FROM sales_results
|
|
WHERE sales_date BETWEEN ? AND ?
|
|
");
|
|
$stmt->execute([$startDate, $endDate]);
|
|
$cumulativeCopy = (int)$stmt->fetchColumn();
|
|
?>
|
|
|
|
<header class="header">
|
|
<div class="header-left">
|
|
<button class="logo" onclick="fullScreen()">EG-BIM</button>
|
|
|
|
<div class="cumulative-copy">
|
|
<span class="label">[총 판매 실적 :</span>
|
|
<span><?= number_format($cumulativeCopy) ?></span>
|
|
<span>copy]</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 연도 이동 영역 -->
|
|
<div class="title-wrap yearly_button" id="yearly_button">
|
|
<button class="year-nav-btn" id="btn-prev-year" title="작년">
|
|
<svg
|
|
width="20"
|
|
height="20"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="#424242"
|
|
stroke-width="2"
|
|
>
|
|
<path d="M15 18l-6-6 6-6" />
|
|
</svg>
|
|
</button>
|
|
|
|
<h1 class="title" data-text="">
|
|
<span id="current-year"></span>년 판매 상세 현황
|
|
</h1>
|
|
|
|
<button class="year-nav-btn" id="btn-next-year" title="내년">
|
|
<svg
|
|
width="20"
|
|
height="20"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="#424242"
|
|
stroke-width="2"
|
|
>
|
|
<path d="M9 18l6-6-6-6" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
|
|
<div class="date"></div>
|
|
</header>
|
|
<!--// header -->
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
/* -------------------------------
|
|
1) 연도 처리 (URL 우선)
|
|
-------------------------------- */
|
|
const params = new URLSearchParams(location.search);
|
|
// let currentYear = Number(params.get("year")) || new Date().getFullYear();
|
|
const START_YEAR = 2025;
|
|
const CURRENT_YEAR = new Date().getFullYear();
|
|
|
|
let currentYear = Number(params.get("year")) || CURRENT_YEAR;
|
|
if (currentYear < START_YEAR) currentYear = START_YEAR;
|
|
|
|
const yearSpan = document.getElementById("current-year");
|
|
const titleEl = document.querySelector(".header .title");
|
|
|
|
function updateTitle() {
|
|
const text = `${currentYear}년 판매 상세 현황`;
|
|
yearSpan.textContent = currentYear;
|
|
titleEl.dataset.text = text;
|
|
}
|
|
|
|
updateTitle();
|
|
|
|
document.getElementById("btn-prev-year")?.addEventListener("click", () => {
|
|
if (currentYear <= START_YEAR) return; // 🔒 2025 이하 차단
|
|
currentYear--;
|
|
moveYear();
|
|
});
|
|
|
|
document.getElementById("btn-next-year")?.addEventListener("click", () => {
|
|
currentYear++;
|
|
moveYear();
|
|
});
|
|
|
|
function moveYear() {
|
|
location.href = `?year=${currentYear}`;
|
|
}
|
|
|
|
/* -------------------------------
|
|
2) 업데이트 날짜 자동 반영
|
|
-------------------------------- */
|
|
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 dateText = `업데이트 : ${y}.${m}.${d}(${weekday}) ${hh}:${mm}`;
|
|
|
|
const dateEl = document.querySelector(".header .date");
|
|
if (dateEl) dateEl.textContent = dateText;
|
|
});
|
|
|
|
function updateTitle() {
|
|
const text = `${currentYear}년 판매 상세 현황`;
|
|
yearSpan.textContent = currentYear;
|
|
titleEl.dataset.text = text;
|
|
|
|
const prevBtn = document.getElementById("btn-prev-year");
|
|
if (prevBtn) {
|
|
prevBtn.classList.toggle("disabled", currentYear <= START_YEAR);
|
|
}
|
|
}
|
|
|
|
// 전역 연도 (모든 include에서 사용)
|
|
window.APP_YEAR = (() => {
|
|
const params = new URLSearchParams(location.search);
|
|
const y = parseInt(params.get("year"), 10);
|
|
const nowY = new Date().getFullYear();
|
|
|
|
if (!isNaN(y) && y >= 2025) return y;
|
|
return nowY;
|
|
})();
|
|
</script>
|
|
|
|
|