
<!----------------------------------Login------------------------------------>
<?php
include 'db_connection.php';

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

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


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

?>

<!---------------------------------কন্টেন------------------------------------>
<?php

// Fetch total quantity and purchase price for each product
function getTotalQuantityAndPriceReport() {
    global $con;
    $query = "
        SELECT pc.Product_name, pc.Product_id, SUM(p.quantity) AS total_quantity, pc.purchase_price
        FROM product_cat pc
        LEFT JOIN product p ON pc.Product_id = p.product_id
        GROUP BY pc.Product_name, pc.Product_id, pc.purchase_price
        ORDER BY pc.Product_name";
    
    $result = $con->query($query);
    return $result;
}

// Calculate the total quantity and purchase price of all products
function getTotalQuantityAndPrice() {
    global $con;
    $query = "
        SELECT SUM(p.quantity) AS total_quantity, SUM(p.purchase_price * p.quantity) AS total_purchase_price
        FROM product p";
    
    $result = $con->query($query);
    $row = $result->fetch_assoc();
    return $row;
}
?>

<!---------------------------echo------------------->
<?php
$result = getTotalQuantityAndPriceReport();
$totalQuantity = 0; // Variable to store overall total quantity
$totalPurchasePrice = 0; // Variable to store total purchase price

while ($row = $result->fetch_assoc()) {
    $totalQuantity += $row['total_quantity']; // Adding each product's quantity to the total
    $totalPurchasePrice += $row['purchase_price'] * $row['total_quantity']; // Adding purchase price * quantity to total
}
?>
