<?php
include "auth.php";
checkPermission(['admin','manager','staff']);
require_once "db.php";

// Fetch customers
$sql = "SELECT * FROM suppliers ORDER BY supplier_name ASC";
$customers = $conn->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
    <title>Print Customers List</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 0;
        }
        h2 {
            text-align: center;
            margin-bottom: 10px;
        }
        .print-info {
            text-align: center;
            margin-bottom: 20px;
            font-size: 14px;
            color: #333;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        table th, table td {
            border: 1px solid #ddd;
            padding: 8px;
            font-size: 14px;
        }
        table th {
            background: #f3f3f3;
        }

        @media print {
            body { margin: 0; }
        }
    </style>
</head>
<body onload="window.print();" class="global-print">

<?php
    include("global/global-print-heading.php");
?>
<h2>Customer List</h2>

<main class="print-body-content">
<table>
    <thead>
        <tr>
            <th>SL</th>
            <th>Name</th>
            <th>Phone</th>
            <th>Address</th>
        </tr>
    </thead>
    <tbody>
        <?php 
        if ($customers->num_rows > 0):
            $sl = 1;
            while ($c = $customers->fetch_assoc()): 
        ?>
                <tr>
                    <td><?php echo $sl++; ?></td>
                    <td><?php echo htmlspecialchars($c['supplier_name']); ?></td>
                    <td><?php echo htmlspecialchars($c['phone']); ?></td>
                    <td><?php echo htmlspecialchars($c['address']); ?></td>
                </tr>
        <?php 
            endwhile;
        else: 
        ?>
            <tr>
                <td colspan="5" style="text-align:center;">No customer found</td>
            </tr>
        <?php endif; ?>
    </tbody>
</table>
        </main>

</body>
</html>
