<div class="modal-header">
    <h4 class="modal-title">Transaksi Pembayaran</h4>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">×</span>
    </button>
</div>
<div class="modal-body">
    <form method="POST" action="<?= base_url('transactions/pay_dp/' . $data->kode_permintaan_custom) ?>" enctype="multipart/form-data">
        <?= csrf_field() ?>

        <div class="row">
            <div class="col-12">
                <table class="w-100 mb-3">
                    <tr>
                        <td>
                            <b>Transfer Ke</b>
                        </td>
                        <td style="width: 20px; text-align: center; height: 50px;">
                            :
                        </td>
                        <td>Bca 8945242589 a.n Annisa Syar'i (naning indras)</td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <div class="form-group">
                                <label class="form-label">Metode Pembayaran</label>
                                <div class="row">
                                    <div class="col-4">
                                        <div class="custom-control custom-radio">
                                            <input type="radio" class="custom-control-input" id="metode_transfer" name="metode_pembayaran" value="transfer" required checked>
                                            <label class="custom-control-label" for="metode_transfer">
                                                <i class="fas fa-university"></i> Transfer Bank
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-4">
                                        <div class="custom-control custom-radio">
                                            <input type="radio" class="custom-control-input" id="metode_tunai" name="metode_pembayaran" value="tunai" required>
                                            <label class="custom-control-label" for="metode_tunai">
                                                <i class="fas fa-money-bill"></i> Tunai
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <div class="form-group">
                                <label class="form-label" for="exampleInputJumlahPembayaran">Jumlah Pembayaran</label>
                                <input type="number" class="form-control" id="exampleInputJumlahPembayaran" name="jumlah_bayar" placeholder="Input Jumlah Pembayaran" required max="<?= $data->status_pelunasan == 1 ? $data->sisa_pembayaran : $data->nominal_pelunasan ?>">
                                <small class="form-text text-muted">Maksimal: Rp. <?= number_format(($data->status_pelunasan == 1 ? $data->sisa_pembayaran : $data->nominal_pelunasan), 0, ",", ".") ?></small>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <div class="form-group">
                                <label class="form-label">Status Pembayaran</label>
                                <input type="text" class="form-control" id="status_display" value="Akan ditentukan otomatis berdasarkan jumlah pembayaran" readonly>
                                <small class="form-text text-muted">Jika sisa = 0, maka status = Lunas. Jika sisa > 0, maka status = DP</small>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <label class="form-label" for="exampleTanggalPelunasan">Tanggal Pelunasan</label>
                            <input type="datetime-local" class="form-control" id="exampleTanggalPelunasan" name="tanggal_pelunasan" value="<?= date('Y-m-d\TH:i') ?>" required>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <label class="form-label mt-3" for="status_pengiriman">Status Pengiriman</label>
                            <br>
                            <?php if ($data->status_pengiriman == 2): ?>
                                <span class="badge badge-success">Dikirim ke Alamat</span>
                            <?php else: ?>
                                <span class="badge badge-info">Ambil Ditoko</span>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php if (!empty($data->bukti_pembayaran_dp)): ?>
                        <tr>
                            <td colspan="3">
                                <label class="form-label mt-3">Bukti Pembayaran DP</label>
                                <br>
                                <a href="<?= base_url($data->bukti_pembayaran_dp) ?>" target="_blank"><img src="<?= base_url($data->bukti_pembayaran_dp) ?>" alt="Bukti DP" width="150" class="img-fluid" /></a>
                            </td>
                        </tr>
                    <?php endif; ?>
                    <tr>
                        <td colspan="3">
                            <div class="form-group">
                                <label class="form-label mt-3" for="exampleInputFile">Input Bukti Pembayaran</label>
                                <div class="input-group">
                                    <div class="custom-file">
                                        <input type="file" class="custom-file-input" name="bukti_pembayaran" required id="exampleInputFile">
                                        <label class="custom-file-label" for="exampleInputFile">Choose file</label>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <h4 class="mb-2 mt-2 mb-2">Detail</h4>
        <div class="row">
            <div class="col-sm-6">
                <table cellpadding="5">
                    <tr>
                        <td><b>No Order</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td><?= $data->no_order_custom  ?></td>
                    </tr>
                    <tr>
                        <td><b>Customer</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td><?= $data->nama ?></td>
                    </tr>
                    <tr>
                        <td><b>Tanggal Order</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td><?= $data->tanggal_order  ?></td>
                    </tr>
                    <tr>
                        <td><b>Tanggal Pengambilan</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td><?= $data->tanggal_pengambilan ?? '-' ?></td>
                    </tr>
                    <tr>
                        <td><b>Tanggal Pelunasan</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td><?= $data->tanggal_pelunasan ?? '-' ?></td>
                    </tr>
                </table>
            </div>
            <div class="col-sm-6">
                <table cellpadding="5">
                    <tr>
                        <td><b>Total Order</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td><?= $data->total_order  ?></td>
                    </tr>
                    <tr>
                        <td><b>DP Pembayaran</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td>Rp. <?= number_format($data->dp_pembayaran, 0, ",", ".") ?></td>
                    </tr>
                    <tr>
                        <td><b>Sisa Pembayaran</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td>Rp. <?= number_format($data->sisa_pembayaran, 0, ",", ".") ?></td>
                    </tr>
                    <tr>
                        <td><b>Nominal Pelunasan</b></td>
                        <td style="width: 20px; text-align: center;">:</td>
                        <td>Rp. <?= number_format($data->nominal_pelunasan, 0, ",", ".") ?></td>
                    </tr>
                    <tr>
                        <td><b>Status Pelunasan</b></td>
                        <td style="width: 20px; text-align: center;">:</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>
                    </tr>
                </table>
            </div>
            <div class="col-sm-12 mt-5">
                <table id="example1" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th style="width: 33.33%;">Model</th>
                            <th style="width: 33.33%;">Jenis Kain</th>
                            <th style="width: 33.33%;">Keterangan (Revisi)</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ($detail_model as $detail):
                            $riwayat = $riwayatPerubahanModel
                                ->where('id_detail_order', $detail->id_detail_order)
                                ->where('status', 1)
                                ->orderBy('created_at', 'DESC')
                                ->first();

                            $message = $riwayat
                                ? $riwayat->keterangan_permintaan_revisi
                                : 'Tidak ada revisi';
                        ?>
                            <tr>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-3">
                                        </div>
                                        <div class="col-sm-9">
                                            <ul>
                                                <li>Model : <?= $detail->nama_model ?></li>
                                                <li>Size : <?= $detail->ukuran_gamis ?></li>
                                                <li>Jumlah(Pcs) : <?= $detail->jumlah_pcs ?></li>
                                                <li>Ongkos Pengerjaan: Rp. <?= number_format($detail->subtotal_detail_order, 0, ",", ".") ?></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-3">
                                        </div>
                                        <div class="col-sm-9">
                                            <ul>
                                                <li>Jenis Kain : <?= $detail->nama_jenis_kain ?></li>
                                                <li>Warna : <?= $detail->warna ?></li>
                                                <li>Jumlah(Meter) : <?= $detail->meter_pemakaian ?></li>
                                                <li>Total Harga: Rp. <?= number_format($detail->subtotal_detail_kain, 0, ",", ".") ?></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                                <td>
                                    <?= $message ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
            <button type="submit" class="btn btn-outline-primary">Bayar</button>
        </div>
    </form>
</div>