<!----------------------------------Login------------------------------------>
<?php

include 'php/db_connection.php';

// শুধুমাত্র লগইন করা ইউজার পেজ দেখতে পারবে
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

$userName = $_SESSION['user_name'];
$role = $_SESSION['role']; // ✅ এখানে role সেভ করা হচ্ছে
$userId = $_SESSION['user_id'];


$isAdmin = ($_SESSION['role'] == 'admin');

?>

<?php

// Query to fetch total_purchase for the last 30 days
$thirty_days_query = "SELECT total_purchase, total FROM sales_items WHERE created_at >= NOW() - INTERVAL 1000 DAY";
$thirty_days_result = $con->query($thirty_days_query);

// Initialize the total to 0
$thirty_days_total = 0;
$total = 0;

// Check if there are results and sum up the total_purchase values
if ($thirty_days_result->num_rows > 0) {
    while ($row = $thirty_days_result->fetch_assoc()) {
        // Add each total_purchase to the running total
        $thirty_days_total += $row['total_purchase'];
        $total += $row['total'];
    }
}
// Output the total Defarence
$defarence = $total - $thirty_days_total;

// Output the total for the last 30 days
/*echo "Total purchase for the last 30 days: " . $thirty_days_total;----*/

?>



<?php
// Close the database connection
$con->close();
?>
