<?php
session_start();
require '../config.php';
require '../layouts/header.php';
?>
        <div class="row">
            <div class="col-lg-6 mx-auto mb-5">
                <div class="card bg-dark shadow">
                    <div class="card-header">
                        <h5>Cek invoice</h5>
                    </div>
                    <div class="card-body">Invoice Number:
                        <div class="input-group">
                            <span class="input-group-text"><i class="fas fa-receipt"></i></span>
                            <input type="text" name="invnum" id="invnum" class="form-control" placeholder="ZPxxxxxxxxx">
                        </div>
                        <button class="btn btn-primary mt-3 float-end" onclick="checkk();">Check</button>
                    </div>
                </div>
            </div>
        </div>
        
    <div class="row justify-content-center">
    <div class="col-md-9 col-12 mb-5">
    <div class="card bg-dark shadow">
    <div class="card-body">
    <h4 class="card-title mb-4" id="headInv">10 Riwayat Transaksi Terakhir</h4>
    <div class="table-responsive" id="setTableNew">
    <table class="table" id="tbb">
    <thead class="table">
    <tr>
    <th class="align-middle">Tanggal</th>
    <th class="align-middle">Produk</th>
    <th class="align-middle">UserID</th>
    <th class="align-middle">Status</th>
    </tr>
    </thead>
    <tbody>
   
                  <?php
                  $query = mysqli_query($db, "SELECT * FROM pembelian_guest ORDER BY id DESC LIMIT 10");
                   while($data    =mysqli_fetch_array($query)){
                            if ($data['status'] == 'Pending') {
                                $badge_bg = 'fas fa-circle-notch fa-spin text-warning';
                                $badge_bg1 = 'warning';
                            } else if ($data['status'] == 'Success') {
                                $badge_bg = 'far fa-check-circle text-success';
                                $badge_bg1 = 'success';
                            } else if ($data['status'] == 'Processing') {
                                $badge_bg = 'fas fa-circle-notch fa-spin text-info';
                                $badge_bg1 = 'primary';
                            } else if ($data['status'] == 'Canceled') {
                                $badge_bg = 'far fa-times-circle text-danger';
                                $badge_bg1 = 'danger';
                            } else {
                                $badge_bg = 'far fa-dot-circle text-danger';
                                $badge_bg1 = 'secondary';
                            }
                            ?>
            <tr>
            	<td><?= format_date('id',$data['date_create']); ?></td>
                <td><?= $data['games']; ?> - <?= $data['layanan']; ?></td>
                <td><?= substr($data['phone'],0,-8); ?>xxxxxx<br>(<?= substr($data['target'],0,-6); ?>xxxxxx)<br>Rp.<?= number_format($data['harga'],0,',','.'); ?></td>
                <td><span class="<?= $badge_bg; ?>"> </span> <?= $data['status']; ?></td>
            </tr>
            <?php
               }
             ?>
        </tbody>
        </table>
        </div>
        </div>
        </div>
        </div>
<script type="text/javascript">
        function checkk() {
            var value = $("#invnum").val();
            window.location.href = `<?= base_url('id/invoice?no=:id');?>`.replace(':id', value)
        }
</script>
<?php require '../layouts/footer.php';?>