
<style>
    .table th, .table td {
        padding: 0.75rem !important;
    }
</style>
<div class="row">
    <div class="col-md-12">
        <button id="btn_download_pdf" class="btn btn-primary"> DOWNLOAD PDF</button>
    </div>
</div>

<div class="row mt-2">
    <div id="list" class="col-md-12">
        <div class="table-responsive">
            <table class="table table-striped table-bordered" style="width:100%">
                <thead>
                    <tr style="background-color:#1c77d4; color:#FFFFFF">
                        <th class="text-center" style="width:50px">NO</th>
                        <th class="text-center" style="width:100px">TANGGAL</th>
                        <th class="text-center">NO PENEGAJUAN</th>
                        <th class="text-center">CABANG<hr>DEPARTEMEN</th>
                        <th class="text-center">KARYAWAN</th>
                        <th class="text-center">PLAFON</th>
                        <th class="text-center">KETERANGAN</th>
                        <th class="text-center">PLAFON MAX</th>
                        <th class="text-center">DIAJUKAN</th>
                        <th class="text-center">DISETUJUI</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        if (isset($list_data)) {

                            $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  ?>"><?= "<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;
                                    ?>
                                        <tr>
                                            <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>
                                <tr>
                                    <td style="font-weight: bold; text-align: right;" colspan="8">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>
                                <tr>
                                    <td colspan="10">&nbsp;</td>
                                </tr>
                    <?php
                            }
                    ?>

                            <tr style="font-weight: bold;">
                                <td class="text-right" 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>
                    <?php
                        }else{
                            echo "<tr><td><center>Tidak ada data</center></td></tr>";
                        }
                    ?>
                </tbody>
            </table>
        </div>
    </div>
</div>