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

// Admin boleh lihat semua, selain admin hanya customer_id sendiri
 if (in_array($_SESSION['role'], ['admin', 'finance', 'cashier'])) {
    $sql = "SELECT COUNT(*) as total FROM invoice WHERE invoice_status != 'Completed'";
    $stmt = $con->prepare($sql);
} else {
    $sql = "SELECT COUNT(*) as total FROM invoice WHERE invoice_status != 'Completed' 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]);
