<div class="row">
    <div class="col-md-12">
        <button id="btn_download_pdf" class="btn btn-primary"> DOWNLOAD PDF</button>
    </div>
</div>
<style type="text/css">
	#list {
		overflow: scroll;
		max-height: 800px;
	}
    .table th, .table td {
        border-bottom: 1px solid #e3ebf3 !important;
    }
    .table th, .table td {
        padding: 0.75rem !important;
    }
</style>

<div class="row mt-2">
    <div id="list" class="col-md-12">
        <table class="table table-bordered">
            <thead>
                <tr style="background-color:#1c77d4; color:#FFFFFF">
                    <th class="text-center" width="50px">NO</th>
                    <th class="text-center" width="150px">TGL PENGAJUAN</th>
                    <th class="text-center">NO PENGAJUAN</th>
                    <th class="text-center">CABANG<br>DEPARTEMEN</th>
                    <th class="text-center">KARYAWAN</th>
                    <th class="text-center">PLAFON</th>
                    <th class="text-center">KETERANGAN</th>
                    <th class="text-center">MAX PLAFON</th>
                    <th class="text-center">DIAJUKAN</th>
                    <th class="text-center">DISETUJUI</th>
                </tr>
            </thead>
            <tbody>
                <?php
                    $no = 0;
                    $ttl_nominal_pengajuan = 0;
                    $ttl_nominal_disetujui = 0;
                    foreach ($list_data as $val) {
                        $no++;
                        $data_reimburse = $this->fungsi->data_reimburse($val->id_pengajuan);

                        $jumlah_row = $data_reimburse->num_rows()+1;
            ?>
                        <tr>
                            <td rowspan="<?= $jumlah_row ?>" class="text-center"><?= $no ?></td>
                            <td rowspan="<?= $jumlah_row ?>" class="text-center"><?= date('d-m-Y', strtotime($val->tgl_pengajuan));?></td>
                            <td rowspan="<?= $jumlah_row ?>" class="text-center"><?= "<b>".$val->no_pengajuan."</b><br>".$val->keterangan ?></td>
                            <td rowspan="<?= $jumlah_row ?>"><?= "<b>".$val->kode_cabang."</b> - ".$val->nama_cabang."<br><b>".$val->kode_departemen."</b> - ".$val->nama_departemen ?></td>
                            <td rowspan="<?= $jumlah_row ?>"><?= $val->nama_karyawan."<br><b>".$val->nik."</b>" ?></td>
                            <?php
                                $nominal_pengajuan = 0;
                                $nominal_disetujui = 0;
                                foreach ($data_reimburse->result() as $dat) {
                                    $nominal_pengajuan = $nominal_pengajuan + $dat->nominal;
                                    $nominal_disetujui = $nominal_disetujui + $dat->nominal_disetujui;

                                    $ttl_nominal_pengajuan = $ttl_nominal_pengajuan + $dat->nominal;
                                    $ttl_nominal_disetujui = $ttl_nominal_disetujui + $dat->nominal_disetujui;
                            ?>
                                <td><?= $dat->jenis_plafon; ?></td>
                                <td><?= $dat->keterangan; ?></td>
                                <td class="text-right"><?= number_format($dat->max_plafon,0,",","."); ?></td>
                                <td class="text-right"><?= number_format($dat->nominal,0,",","."); ?></td>
                                <td class="text-right"><?= number_format($dat->nominal_disetujui,0,",","."); ?></td>
                        </tr>
                        <?php
                                }
                        ?>
                        <tr>
                            <td style="font-weight: bold; text-align: center;" colspan="3">SUB TOTAL</td>
                            <td class="text-right" style="font-weight: bold;"><?= number_format($nominal_pengajuan,0,",","."); ?></td>
                            <td class="text-right" style="font-weight: bold;"><?= number_format($nominal_disetujui,0,",","."); ?></td>
                        </tr>
                <?php
                        }
                ?>

                <tr style="font-weight: bold;">
                    <td class="text-center" colspan="8">TOTAL</td>
                    <td class="text-right"><?= number_format($ttl_nominal_pengajuan,0,",","."); ?> </td>
                    <td class="text-right"><?= number_format($ttl_nominal_disetujui,0,",","."); ?> </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>