<h3 style="text-align: center;"><?= strtoupper(strtolower($title)) ?></h3>
<h4 style="text-align: center;">PERIODE : <?php echo $tanggal_mulai . ' s/d ' . $tanggal_selesai ?></h4>
<h4> </h4>

<table width="100%" style="border-collapse:collapse;" border="1">
    <tr>
        <td rowspan="2">NO</td>
        <td rowspan="2"><?= strtoupper($this->lang->line('nik')); ?></td>
        <td rowspan="2"><?= strtoupper($this->lang->line('nama')); ?></td>
        <td rowspan="2"><?= strtoupper($this->lang->line('jenis')); ?></td>
        <td rowspan="2"><?= strtoupper($this->lang->line('tgl_pengajuan_tabel')); ?></td>
        <td rowspan="2"><?= strtoupper($this->lang->line('periode')); ?></td>
        <td rowspan="2"><?= strtoupper($this->lang->line('jml_hari_tabel')); ?></td>
        <td rowspan="2"><?= strtoupper($this->lang->line('keterangan')); ?></td>
        <td colspan="5">APPROVAL</td>
    </tr>
    <tr>
        <th><?= $this->lang->line('supervisi'); ?></th>
        <th><?= $this->lang->line('menu_kepala_departemen'); ?></th>
        <th><?= $this->lang->line('menu_kepala_cabang'); ?></th>
        <th><?= $this->lang->line('direksi'); ?></th>
        <th>HRD</th>
    </tr>
    <?php
    $no = 1;
    foreach ($data as $row) {

        $level_approval = $row->level_approval;
        $get_lev = explode(',', $level_approval);

        if($row->approval_kedep){
            $key = array_search(2, $get_lev);
            $approv = $get_lev[$key - 1];

            if ($approv == '7') {
                $approv_col = $row->approval_spv;
            }

            if ($approv_col == '3') {
                $kedep = $this->fungsi->get_approval('');
            } else {
                $kedep = $this->fungsi->get_approval($row->approval_kedep);
            }
        }

        if($row->approval_kacab){
            $key = array_search(5, $get_lev);
            $approv = $get_lev[$key - 1];
            $approv_2 = $get_lev[$key - 2];

            if ($approv == '7') {
                $approv_col = $row->approval_spv;
            } else if ($approv == '2') {
                $approv_col = $row->approval_kedep;
            }

            if ($approv_2 == '7') {
                $approv_col_2 = $row->approval_spv;
            }

            if ($approv_col == '3' || $approv_col_2 == '3') {
                $kacab = $this->fungsi->get_approval('');
            } else {
                $kacab = $this->fungsi->get_approval($row->approval_kacab);
            }
        }

        if ($row->approval_direksi) {
            $key = array_search(4, $get_lev);
            $approv = $get_lev[$key - 1];
            $approv_2 = $get_lev[$key - 2];
            $approv_3 = $get_lev[$key - 3];

            if ($approv == '7') {
                $approv_col = $row->approval_spv;
            } elseif ($approv == '2') {
                $approv_col = $row->approval_kedep;
            } elseif ($approv == '5') {
                $approv_col = $row->approval_kacab;
            }

            if ($approv_2 == '2') {
                $approv_col_2 = $row->approval_kedep;
            }

            if ($approv_3 == '7') {
                $approv_col_3 = $row->approval_spv;
            }

            if ($approv_col == '3' || $approv_col_3 == '3' || $approv_col_2 == '3') {
                $direksi = $this->fungsi->get_approval('');
            } else {
                $direksi = $this->fungsi->get_approval($row->approval_direksi);
            }
        }

        if ($row->approval_hrd) {
            $key = array_search(1, $get_lev);
            $approv = $get_lev[$key - 1];
            $approv_2 = $get_lev[$key - 2];
            $approv_3 = $get_lev[$key - 3];
            $approv_4 = $get_lev[$key - 4];

            if ($approv == '7') {
                $approv_col = $row->approval_spv;
            } elseif ($approv == '2') {
                $approv_col = $row->approval_kedep;
            } elseif ($approv == '5') {
                $approv_col = $row->approval_kacab;
            } elseif ($approv == '4') {
                $approv_col = $row->approval_direksi;
            }

            if ($approv_2 == '5') {
                $approv_col_2 = $row->approval_kacab;
            }

            if ($approv_3 == '2') {
                $approv_col_3 = $row->approval_kedep;
            }

            if ($approv_4 == '7') {
                $approv_col_4 = $row->approval_spv;
            }

            if ($approv_col == '3' || $approv_col_4 == '3' || $approv_col_3 == '3' || $approv_col_2 == '3') {
                $hrd = $this->fungsi->get_approval('');
            } else {
                $hrd = $this->fungsi->get_approval($row->approval_hrd);
            }
        }

    ?>
        <tr>
            <td><?= $no; ?></td>
            <td>#<?= $row->nik; ?>#</td>
            <td><?= $row->nama_lengkap; ?></td>
            <td><?= $row->nama_izin; ?></td>
            <td><?= date('d-m-Y', strtotime($row->tgl_pengajuan)) ?></td>
            <td><?= date('d-m-Y', strtotime($row->tgl_mulai_izin))." " .$this->lang->line('s/d')." ". date('d-m-Y', strtotime($row->tgl_selesai_izin)); ?></td>
            <td><?= $row->jml_izin; ?></td>
            <td><?= $row->ket_izin; ?></td>
            <td><?= $this->fungsi->get_approval($row->approval_spv); ?></td>
            <td><?= $kedep; ?></td>
            <td><?= $kacab; ?></td>
            <td><?= $direksi; ?></td>
            <td><?= $hrd; ?></td>
        </tr>
    <?php
        $no++;
    }
    ?>
</table>