<?php
if ($data != null) {
    $jml_data = count($data);
    $nomor = 0;
    foreach ($data as $key => $value) {
        $nomor++;
        $karyawan = $value['data_karyawan'];
        $lembur      = $value['data_lembur'];

        $lembur_mulai   = strtotime($field->jam_absen);
        $lembur_selesai = strtotime($field->jam_lembur_selesai);
        $selisih_detik  = $lembur_selesai - $lembur_mulai;
        $lama_lembur    = floor($selisih_detik/60);
?>
        <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%" border="1">
            <tr>
                <td style="border:1px solid #fff; text-align:left" colspan="2">NIK</td>
                <td style="border:1px solid #fff; text-align:left" colspan="4">: <?php echo $karyawan['nik']; ?></td>
                <td style="border:1px solid #fff; text-align:left" colspan="4"></td>
                <td style="border:1px solid #fff; text-align:left" colspan="2">CABANG</td>
                <td style="border:1px solid #fff; text-align:left" colspan="4">: <?php echo $karyawan['nama_cabang']; ?></td>
            </tr>
            <tr>
                <td style="border:1px solid #fff; text-align:left" colspan="2">NAMA</td>
                <td style="border:1px solid #fff; text-align:left" colspan="4">: <?php echo $karyawan['nama_karyawan']; ?></td>
                <td style="border:1px solid #fff; text-align:left" colspan="4"></td>
                <td style="border:1px solid #fff; text-align:left" colspan="2">DEPARTEMEN</td>
                <td style="border:1px solid #fff; text-align:left" colspan="4">: <?php echo $karyawan['nama_departemen']; ?></td>
            </tr>
            <tr>
                <td style="border:1px solid #fff; text-align:left" colspan="2"></td>
                <td style="border:1px solid #fff; text-align:left" colspan="4"></td>
                <td style="border:1px solid #fff; text-align:left" colspan="4"></td>
                <td style="border:1px solid #fff; text-align:left" colspan="2">JABATAN</td>
                <td style="border:1px solid #fff; text-align:left" colspan="4">: <?php echo $karyawan['nama_jabatan']; ?></td>
            </tr>
            <tr>
                <td style="border:1px solid #fff; border-bottom:1px solid #000" colspan="16"></td>
            </tr>
            <tr>
                <th rowspan="2">NO</th>
                <th rowspan="2">TANGGAL PENGAJUAN</th>
                <th colspan="2">JAM</th>
                <th rowspan="2">LAMA <br>LEMBUR (M)</th>
                <th colspan="4">KETERANGAN</th>
                <th colspan="2">LOKASI</th>
                <th colspan="5">APPROVAL</th>
                <th rowspan="2">STATUS</th>
            </tr>
            <tr>
                <th>MULAI</th>
                <th>SELESAI</th>
                <th colspan="2">MULAI</th>
                <th colspan="2">SELESAI</th>
                <th>MULAI</th>
                <th>SELESAI</th>
                <th>SUPERVISI</th>
                <th>KEP. DEP</th>
                <th>KEP. CAB</th>
                <th>DIREKSI</th>
                <th>HRD</th>
            </tr>
            <?php
            if (count($lembur) > 0) {
                $no = 1;

                $data_lembur = array();
                foreach ($lembur as $k => $v) {
                    $lembur_mulai   = strtotime($v['lm_jam']);
                    $lembur_selesai = strtotime($v['ls_jam']);
                    $selisih_detik  = $lembur_selesai - $lembur_mulai;
                    $lama_lembur    = floor($selisih_detik/60);

                ?>
                        <tr <?= $css ?>>
                            <td><?php echo $no ?></td>
                            <td><?php echo $v['tgl_absen'] ?></td>
                            <td><?php echo $v['lm_jam'] ?></td>
                            <td><?php echo $v['ls_jam'] ?></td>
                            <td><?php echo $lama_lembur ?></td>
                            <td colspan="2"><?php echo $v['lm_keterangan'] ?></td>
                            <td colspan="2"><?php echo $v['ls_keterangan'] ?></td>
                            <td><?php echo $v['lm_lokasi'] ?></td>
                            <td><?php echo $v['ls_lokasi'] ?></td>
                            <td><?php echo $v['apv_spv'] ?></td>
                            <td><?php echo $v['apv_kedep'] ?></td>
                            <td><?php echo $v['apv_kacab'] ?></td>
                            <td><?php echo $v['apv_direksi'] ?></td>
                            <td><?php echo $v['apv_hrd'] ?></td>
                            <td><?php echo $v['status'] ?></td>
                        </tr>
                <?php
                    $no++;
                }
            }
            ?>
        </table>
        <?php
        if ($is_excel === true) {
            echo '<h5>--PAGEBREAK--</h5>';
        } else {
            if ($nomor >= 1 && $nomor != $jml_data) {
                echo '<pagebreak>';
            }
        }
        ?>
<?php
    }
}
?>