<?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;"><?= strtoupper($this->lang->line('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"><?= strtoupper($this->lang->line('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) ? '6' : '5' ?>"></td>
                <td style="border:1px solid #fff; text-align:left" colspan="2"><?= strtoupper($this->lang->line('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"><?= strtoupper($this->lang->line('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) ? '6' : '5' ?>"></td>
                <td style="border:1px solid #fff; text-align:left" colspan="2"><?= strtoupper($this->lang->line('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) ? '6' : '5' ?>"></td>
                <td style="border:1px solid #fff; text-align:left" colspan="2"><?= strtoupper($this->lang->line('menu_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) ? '18' : '17' ?>"></td>
            </tr>
            <tr>
                <td style="text-align:center;" width="40" rowspan="2">NO.</td>
                <td style="text-align:center;" width="70" rowspan="2"><?= strtoupper($this->lang->line('tgl')); ?></td>
                <td style="text-align:center;" width="70" rowspan="2"><?= strtoupper($this->lang->line('kode_absensi')); ?></td>
                <td style="text-align:center;" colspan="4"><?= strtoupper($this->lang->line('masuk')); ?></td>
                <td style="text-align:center;" colspan="3"><?= strtoupper($this->lang->line('istirahat_mulai')); ?></td>
                <td style="text-align:center;" colspan="3"><?= strtoupper($this->lang->line('istirahat_selesai')); ?></td>
                <td style="text-align:center;" colspan="4"><?= strtoupper($this->lang->line('pulang')); ?></td>
                <?php if ($is_excel) { ?>
                    <td style="text-align:center; display:none;" rowspan="2"><?= strtoupper($this->lang->line('jenis_absen')); ?></td>
                <?php } ?>
            </tr>
            <tr>
                <td style="text-align:center;" width="60"><?= strtoupper($this->lang->line('waktu')); ?></td>
                <td style="text-align:center;" width="30">T</td>
                <td style="text-align:center;"><?= strtoupper($this->lang->line('lokasi')); ?></td></td>
                <td style="text-align:center;" width="70"><?= strtoupper($this->lang->line('ket')); ?></td>
                <td style="text-align:center;" width="60"><?= strtoupper($this->lang->line('waktu')); ?></td>
                <td style="text-align:center;"><?= strtoupper($this->lang->line('lokasi')); ?></td></td>
                <td style="text-align:center;" width="70"><?= strtoupper($this->lang->line('ket')); ?></td>
                <td style="text-align:center;" width="60"><?= strtoupper($this->lang->line('waktu')); ?></td>
                <td style="text-align:center;"><?= strtoupper($this->lang->line('lokasi')); ?></td></td>
                <td style="text-align:center;" width="70"><?= strtoupper($this->lang->line('ket')); ?></td>
                <td style="text-align:center;" width="60"><?= strtoupper($this->lang->line('waktu')); ?></td>
                <td style="text-align:center;" width="30">PC</td>
                <td style="text-align:center;"><?= strtoupper($this->lang->line('lokasi')); ?></td></td>
                <td style="text-align:center;" width="70"><?= strtoupper($this->lang->line('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'],
                                                        "terlambat"             =>$v['terlambat'],
                                                        "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'],
                                                        "pulang_cepat"          =>$v['pulang_cepat'],
                                                        "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");
                    $Y_m_d       = $dt->format("Y-m-d");
                    $week_of_day = $dt->format("N");
                    $hari        = indo_date($Y_m_d, "l");
                    if(array_key_exists($tanggal,$data_absensi)){
                        if($is_excel === false){
                            if($data_absensi[$tanggal]['jenis_absen'] == "libur" || $data_absensi[$tanggal]['jenis_absen'] == "alpha"){
                                $css = "style='background-color:#e44358 '";
                            }elseif(in_array($week_of_day, $m_jam_kerja_libur) or in_array($Y_m_d, $m_libur_nasional)) {
                                $css = "style='background-color:".$this->config->item('warna_background_libur')."'";
                            }else{
                                $css = "";
                            }
                            
                        }else{
                            $css = "";
                        }
                ?>
                        <tr <?= $css ?>>
                            <td><?php echo $no ?></td>
                            <td><?php echo $hari."<br>".$tanggal ?></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]['terlambat'] ?></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]['pulang_cepat'] ?></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 $hari."<br>".$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>
                        <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
    }
}
?>