<?php
session_start(); 
$u_uname = '';
if (isset($_COOKIE['auth_token'])) {
    $u_uname = $_COOKIE['auth_token'];
} else {
    header("location:login.php");
    exit; 
}
?>

<?php include 'include/header.php'; ?>
<?php include 'include/aside.php'; ?>
<?php include 'include/connection.php'; ?>

<!--start page wrapper -->
<div class="page-wrapper">
    <div class="page-content">
        <h6 class="mb-0 text-uppercase">Invoice History</h6>
        <hr/>

        <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <table id="example2" class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>SR. No</th>
                                <th>Invoice No</th>
                                <th>Invoice Name</th>
                                <th>User ID</th>
                                <th>Invoice Status</th>
                                <th>Invoice Amount</th>
                                <th>Date</th>
                                <th>Order Id</th>
                                
                              
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $sql = "SELECT * FROM  invoice order by id desc";
                            $result = $link->query($sql);
                            $sr = 1; // Initialize serial number
                            
                            if ($result->num_rows > 0) {
                                // Output data of each row
                                while($row = $result->fetch_assoc()) {
                                    ?>
                                    
                                    <tr>
                                    <td><?php echo  $sr ?></td>
                                    <td><?php echo$row['invoice_no'] ?></td>
                                    <td><?php echo $row['invoice_name'] ?></td>
                                    
                                    <td><?php echo $row['user_id'] ?></td>
                                    <td>
    <?php  
    if($row['invoice_status'] == '0'){
        ?>
        <span class="badge bg-warning text-white rounded-pill">Unpaid</span>
        <?php
     } else
    if ($row['invoice_status'] == '1') {
        ?>
        <span class="badge bg-success text-white rounded-pill">Paid</span>
        <?php
    } 
    
    ?>
</td>
                                    <td><?php echo  $row['invoice_amount'] ?></td>
                                    <td><?php echo$row['date'] ?></td>
                                    <td><?php echo $row['order_id'] ?></td>
                                    

                                    </tr>
                                    <?php
                                    $sr++; 
                                }
                            } else {
                                echo "<tr><td colspan='8'>No data available</td></tr>";
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--end page wrapper -->

<?php include 'include/footer.php'; ?>
