<?php
    if ($is_excel === false) {
?>
        <style type="text/css">
            body {
                font-family: sans-serif;
            }
            table {
                border-spacing: 0;
                border-collapse: collapse;
                width: 100%;
                max-width: 100%;
                margin-bottom: 20px;
                font-size:11px;
                vertical-align: middle;
                padding: 0;
                padding: 1px;
                vertical-align: top;
                text-align:center;
                font-family: sans-serif;
            }
        </style>
<?php
    }
?>

<?php
if ($data != null) {
    $jml_data = count($data);
    $nomor = 0;
    foreach ($data as $key => $value) {
        $nomor++;
        $karyawan = $value['data_karyawan'];
        $absen      = $value['data_absen'];
?>
        <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="<?php echo ($is_excel) ? '4' : '3' ?>"></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="<?php echo ($is_excel) ? '4' : '3' ?>"></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="<?php echo ($is_excel) ? '4' : '3' ?>"></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="<?php echo ($is_excel) ? '16' : '15' ?>"></td>
            </tr>
            <tr>
                <td style="text-align:center;" width="40" rowspan="2">NO.</td>
                <td style="text-align:center;" width="90" rowspan="2">TANGGAL</td>
                <td style="text-align:center;" width="100" rowspan="2">KODE ABSEN</td>
                <td style="text-align:center;" colspan="3">MASUK</td>
                <td style="text-align:center;" colspan="3">ISTIRAHAT MULAI</td>
                <td style="text-align:center;" colspan="3">ISTIRAHAT SELESAI</td>
                <td style="text-align:center;" colspan="3">PULANG</td>
                <?php if ($is_excel) { ?>
                    <td style="text-align:center; display:none;" rowspan="2">JENIS ABSEN</td>
                <?php } ?>
            </tr>
            <tr>
                <td style="text-align:center;" width="70">WAKTU</td>
                <td style="text-align:center;">LOKASI</td>
                <td style="text-align:center;" width="70">KET</td>
                <td style="text-align:center;" width="70">WAKTU</td>
                <td style="text-align:center;">LOKASI</td>
                <td style="text-align:center;" width="70">KET</td>
                <td style="text-align:center;" width="70">WAKTU</td>
                <td style="text-align:center;">LOKASI</td>
                <td style="text-align:center;" width="70">KET</td>
                <td style="text-align:center;" width="70">WAKTU</td>
                <td style="text-align:center;">LOKASI</td>
                <td style="text-align:center;" width="70">KET</td>
            </tr>
            <?php
            if (count($absen) > 0) {
                $no = 1;
                $data_absensi = array();
                foreach ($absen as $k => $v) {
                    $data_absensi[$v['tgl_absen']] = ["tgl_absensi"           =>$v['tgl_absen'],
                                                        "kode_absensi"          =>$v['kode_absensi'],
                                                        "absen_masuk"           =>$v['absen_masuk'],
                                                        "lokasi_masuk"          =>$v['lokasi_masuk'],
                                                        "ket_absen_masuk"       =>$v['ket_absen_masuk'],
                                                        "absen_ist_mulai"       =>$v['absen_ist_mulai'],
                                                        "lokasi_ist_mulai"      =>$v['lokasi_ist_mulai'],
                                                        "ket_absen_ist_mulai"   =>$v['ket_absen_ist_mulai'],
                                                        "absen_ist_selesai"     =>$v['absen_ist_selesai'],
                                                        "lokasi_ist_selesai"    =>$v['lokasi_ist_selesai'],
                                                        "ket_absen_ist_selesai" =>$v['ket_absen_ist_selesai'],
                                                        "absen_pulang"          =>$v['absen_pulang'],
                                                        "lokasi_pulang"         =>$v['lokasi_pulang'],
                                                        "ket_absen_pulang"      =>$v['ket_absen_pulang'],
                                                        "jenis_absen"           =>$v['jenis_absen']];
                                                
                }
                // print_r($data_arr);
                // echo '<pre>',print_r($data_absensi),'</pre>';
                foreach ($periode as $dt) {
                    $tanggal = $dt->format("d-m-Y");
                    if(array_key_exists($tanggal,$data_absensi)){
                        if($is_excel === false){
                            if($data_absensi[$tanggal]['jenis_absen'] == "libur"){
                                $css = "style='background-color:#e44358 '";
                            }else{
                                $css = "";
                            }
                            
                        }else{
                            $css = "";
                        }
                ?>
                        <tr <?= $css ?>>
                            <td><?php echo $no ?></td>
                            <td><?php echo $data_absensi[$tanggal]['tgl_absensi'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['kode_absensi'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['absen_masuk'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['lokasi_masuk'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['ket_absen_masuk'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['absen_ist_mulai'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['lokasi_ist_mulai'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['ket_absen_ist_mulai'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['absen_ist_selesai'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['lokasi_ist_selesai'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['ket_absen_ist_selesai'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['absen_pulang'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['lokasi_pulang'] ?></td>
                            <td><?php echo $data_absensi[$tanggal]['ket_absen_pulang'] ?></td>
                            <?php if ($is_excel) { ?>
                                <td style="display:none;"><?php echo $data_absensi[$tanggal]['jenis_absen'] ?></td>
                            <?php } ?>
                        </tr>
                <?php
                    }else{
                ?>
                    <tr>
                        <td><?php echo $no ?></td>
                        <td><?php echo $tanggal ?></td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <td>-</td>
                        <?php if ($is_excel) { ?>
                            <td style="display:none;"></td>
                        <?php } ?>
                    </tr>
                <?php
                    }
                    $no++;
                }
            }
            ?>
        </table>
        <?php
        if ($is_excel === true) {
            echo '<h5>--PAGEBREAK--</h5>';
        } else {
            if ($nomor >= 1 && $nomor != $jml_data) {
                echo '<pagebreak>';
            }
        }
        ?>
<?php
    }
}
?>