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();
?>