<?php
session_start();
include "conn.php";

// Admin boleh lihat semua, selain admin hanya customer_id sendiri
if (in_array($_SESSION['role'], ['packaging', 'admin', 'cashier'])) { 
    $sql = "SELECT COUNT(*) as total FROM invoice WHERE packaging_status != 'Packed'"; 
    $stmt = $con->prepare($sql);
} else {
    $sql = "SELECT COUNT(*) as total FROM invoice WHERE packaging_status != 'Packed' AND customer_id=?"; 
    $stmt = $con->prepare($sql);
    $stmt->bind_param("i", $_SESSION['aidi']);
}

$stmt->execute();
$res = $stmt->get_result()->fetch_assoc();
echo json_encode(['count' => $res['total'] ?? 0]);

