<?php
include 'shikanisha.kts.php';

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT DISTINCT YEARWEEK(seller_date) AS week, 
        CONCAT(DATE_FORMAT(MIN(seller_date), '%b %d'), ' - ', DATE_FORMAT(MAX(seller_date), '%b %d')) AS week_range 
        FROM transaction_receipts 
        GROUP BY YEARWEEK(seller_date) 
        ORDER BY YEARWEEK(seller_date) DESC";
$result = $conn->query($sql);

$weeks = [];
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $weeks[] = [
            'value' => $row['week'],
            'text' => $row['week_range']
        ];
    }
}

echo json_encode($weeks);

$conn->close();
?>
