<?php

include('includes/header.php');



 include('../middleware/adminMiddleware.php');

 include('../functions/myfunctions.php');

 



?>



<div class="container">

    <div class="row">

        <div class="col-md-12">

            <h2>Admin Panel</h2>

        </div>

        <div class="col-md-12">

            <div class="card">

                <div class="card-header">

                    <h4>Order History

                        <a href="index.php" class="btn btn-warning float-end"><i class="fa fa-reply"></i> Back </a>

                    </h4>

                </div>

                <div class="card-body">

                    <div class="row">

                        <div class="col-md-12">

                            <table class="table table-bordered table-striped">

                                <thead>

                                    <tr>

                                    <th>ID</th>

                                    <th>User</th>

                                    <th>Tracking NO</th>

                                    <th>Price</th>

                                    <th>Date</th>

                                    <th>Details</th>

                                    </tr>

                                </thead>

                                <tbody>

                                    <?php

                                    $orders = getOrderHistory();

                                    if(mysqli_num_rows($orders)>0){

                                        foreach($orders as $item){

                                        ?>

                                            <tr>

                                                <td> <?= $item['id']; ?> </td>

                                                <td> <?= $item['name']; ?> </td>

                                                <td> <?= $item['tracking_no']; ?> </td>

                                                <td> <?= $item['total_price']; ?> </td>

                                                 <td> 
                                                    <?= date('Y-m-d H:i:s', strtotime($item['created_at']) + 3 * 3600); ?>
                                                </td>

                                                <td> <a href="view-order.php?t=<?= $item['tracking_no']; ?>" class="btn btn-primary">View Details</a> </td>

                                            </tr>

                                        <?php

                                        }

                                    }else{

                                        ?>

                                            <tr>

                                                <td colspan="5"> No Orders Found </td>

                                            </tr>

                                        <?php

                                    }

                                    ?>

                                

                                </tbody>

                            </table>

                        </div>

                    </div>

                </div>

            </div>

        </div>

    </div>

</div>



<?php include('includes/footer.php'); ?>