<?php if (auth()->user()->role == 'customer'): ?>
    <?= $this->extend('layouts/topbar') ?>
<?php else: ?>
    <?= $this->extend('layouts/sidebar') ?>
<?php endif; ?>

<?= $this->section('content') ?>
<section class="content">
    <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
        <div class="card mb-3">
            <div class="card-body">
                <table id="example1" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>No Order</th>
                            <th>Customer</th>
                            <th>Tanggal Order</th>
                            <th>Tanggal Pengembalian</th>
                            <th>Nominal Pelunasan</th>
                            <th>Status Pelunasan</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $i = 1 ?>
                        <?php foreach ($data as $data) : ?>
                            <tr>
                                <td style="width: 30px;"><?= $i++ ?></td>
                                <td><?= $data->no_order_custom  ?></td>
                                <td><?= $data->nama  ?></td>
                                <td><?= $data->tanggal_order  ?></td>
                                <td><?= $data->tanggal_pengambilan ?></td>
                                <td>Rp. <?= number_format($data->nominal_pelunasan, 0, ",", ".") ?></td>
                                <td>
                                    <?php if ($data->status_pelunasan == 2): ?>
                                        <span class="badge badge-success">Sudah Dibayar</span>
                                    <?php elseif ($data->status_pelunasan == 1): ?>
                                        <span class="badge badge-warning">DP</span>
                                    <?php else: ?>
                                        <span class="badge badge-danger">Belum dibayar</span>
                                    <?php endif; ?>
                                </td>
                                <td style="width: 200px;">
                                    <?php if (auth()->user()->role != 'pemilik_toko'): ?>
                                        <?php if ($data->status_pelunasan == 1): ?>
                                            <a class="btn btn-primary btn-sm mt-1" onclick="show_lg('<?= base_url('permintaan_custom/detail/' . $data->kode_permintaan_custom) ?>')"><i class="fas fa-eye"></i>&nbsp;&nbsp;Detail</a>
                                            <a class="btn btn-warning btn-sm mt-1" onclick="show_lg('<?= base_url('transactions/pay_dp/' . $data->kode_permintaan_custom) ?>')"><i class="fas fa-money-check"></i>&nbsp;&nbsp;Bayar</a>
                                        <?php else: ?>
                                            <a class="btn btn-primary btn-sm mt-1" onclick="show_lg('<?= base_url('permintaan_custom/detail/' . $data->kode_permintaan_custom) ?>')"><i class="fas fa-eye"></i>&nbsp;&nbsp;Detail</a>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                    <a class="btn btn-danger btn-sm mt-1" target="_blank" href="<?= base_url('transactions/invoice/' . $data->kode_permintaan_custom) ?>"><i class="fas fa-file-pdf"></i>&nbsp;&nbsp; Cetak Laporan</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div><!-- /.container-fluid -->
</section>
<?= $this->endSection() ?>