<?php
include('../includes/session.php');
include('../includes/config.php');
include('../template/ahkweb/header.php');

$appliedby = $udata['phone'];

if ($udata['type'] == 'admin') {
    $res = mysqli_query($ahk_conn, "SELECT * FROM recharge_history ORDER BY id DESC");
} else {
    $res = mysqli_query($ahk_conn, "SELECT * FROM recharge_history WHERE userid='$appliedby' ORDER BY id DESC");
}
?>
<div class="page-wrapper">
<div class="page-content">
    <div class="card radius-10">
        <div class="card-body">
            <h5 class="mb-0">Recharge History</h5>
            <hr>
         <div class="table-responsive">
                <table id="example2" class="table align-middle mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>#</th>
                            <th>Mobile/ID</th>
                            <th>Operator</th>
                            <th>Amount</th>
                            <th>Status</th>
                            <th>Commission</th>
                            <th>Message</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $x = 0;
                        while($data = mysqli_fetch_assoc($res)){
                            $x++;
                            $statusBtn = '';

                            if (stripos($data['status'], 'Pending') !== false) {
                                $statusBtn = '<a href="check_status.php?txn_id='.$data['agentid'].'" class="btn btn-sm btn-warning">Check Status</a>';
                            } elseif (stripos($data['status'], 'Success') !== false) {
                                $statusBtn = '<a href="receipt.php?txn_id='.$data['agentid'].'" target="_blank" class="btn btn-sm btn-success">Print Receipt</a>';
                            } elseif (stripos($data['status'], 'Refunded') !== false) {
                                $statusBtn = '<span class="badge bg-info">Refunded</span>';
                            } elseif (stripos($data['status'], 'Failed') !== false) {
                                $statusBtn = '<span class="badge bg-danger">Failed</span>';
                            } else {
                                $statusBtn = '<span class="badge bg-secondary">'.$data['status'].'</span>';
                            }

                            echo "<tr>
                                <td>{$x}</td>
                                <td>{$data['mobile']}</td>
                                <td>{$data['operator']}</td>
                                <td>₹{$data['amount']}</td>
                                <td>{$statusBtn}</td>
                                <td>₹{$data['commission']}</td>
                                <td>{$data['msg']}</td>
                                <td>{$data['date']}</td>
                            </tr>";
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
</div>

<!--end page wrapper -->
<?php 
include('../template/ahkweb/footer.php');
?>

<!-- Bootstrap & Plugins JS -->
<script src="../template/ahkweb/assets/js/bootstrap.bundle.min.js"></script>
<script src="../template/ahkweb/assets/js/jquery.min.js"></script>
<script src="../template/ahkweb/assets/plugins/simplebar/js/simplebar.min.js"></script>
<script src="../template/ahkweb/assets/plugins/metismenu/js/metisMenu.min.js"></script>
<script src="../template/ahkweb/assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
<script src="../template/ahkweb/assets/js/index.js"></script>
<script src="../template/ahkweb/assets/js/app.js"></script>

<!-- Datatables -->
<script src="../template/ahkweb/assets/plugins/datatable/js/jquery.dataTables.min.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/dataTables.bootstrap5.min.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/dataTables.buttons.min.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/buttons.bootstrap5.min.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/jszip.min.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/pdfmake.min.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/vfs_fonts.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/buttons.html5.min.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/buttons.print.min.js"></script>
<script src="../template/ahkweb/assets/plugins/datatable/js/buttons.colVis.min.js"></script>

<script>
$(document).ready(function() {
    var table = $('#example2').DataTable({
        lengthChange: false,
        buttons: [ 'copy', 'excel', 'pdf', 'print', 'colvis' ]
    });

    table.buttons().container()
        .appendTo('#example2_wrapper .col-md-6:eq(0)');
});
</script>
