<html lang="en">
	<script type="text/javascript" charset="utf-8" id="zm-extension" src="<?php echo base_url('assets/cetak/jquery/webrtc-patch.js'); ?>"></script>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <title>Daftar Hadir</title>
    <link rel="stylesheet" href="<?php echo base_url('assets/cetak/cetak.css'); ?>">
	<script src="<?php echo base_url('assets/cetak/jquery/jquery-3.js'); ?>"></script>
	<script src="<?php echo base_url('assets/cetak/jquery/jquery-migrate-1.js'); ?>"></script>
	<script src="<?php echo base_url('assets/cetak/jquery/qrcode.js'); ?>"></script>
</head>
<body onload="window.print();" style="font-family: arial;width:100%; margin:0 auto;margin-top:0px; ">
<style>
	.page {
		padding: 1cm;
	}

	td {
		padding: 5px;
	}

	.upper {
		text-transform: uppercase;
	}
</style>
<?php
$tiga=$this->db->query("SELECT * from web_setting where id='1'");
foreach ($tiga->result() as $rt) {
$nama_sekolah=$rt->nama;
$namsek=$rt->nama;
$logo=$rt->logo;
$back=$rt->back;
$tapel=$rt->tapel;
$kop=$rt->kop;
$kepsek = balikin($rt->namakepsek);
$nipkepsek = $rt->nipkepsek;
$kabupaten = $rt->kabupaten;
}

$dd=$this->input->get('dd');
$mm=$this->input->get('mm');
$yy=$this->input->get('yy');
$harike3=substr(hari($dd,$mm,$yy),0,3);
$carikelas="SELECT * FROM web_kelas ORDER BY urut ASC";
$kelas = $this->db->query($carikelas);
foreach ($kelas->result() as $rs) {
	$namakelas=$rs->nama;
	$kodekelas=$rs->kode;
	$halaman=0;
	$ceksiswa = $this->db->query("SELECT * FROM web_siswa WHERE KD_JENIS_KETENAGAAN='$kodekelas' ORDER BY NM_PEGAWAI asc");
	$jumlahsiswa=$ceksiswa->num_rows();
	$jmlperhal=25;
	$mulai=0;
	$nomer=0;
	if ($jumlahsiswa >=$jmlperhal) {
	//$halaman=round($jumlahsiswa/$jmlperhal,0,PHP_ROUND_HALF_EVEN);
	$halaman=ceil($jumlahsiswa/$jmlperhal);
	//echo "iki halaman = ".$halaman;
	for ($hal=1;$hal<=$halaman;$hal++) {
	?>
	<div class="page">
	<center>
	 <table border="0" width="100%">
     <tr>
    <td rowspan="1" width="100" align="left"><img src="<?php echo base_url('assets/back/'.$logo.'');?>" width="80"></td>
    <td>
	<center>
	<strong class="f12">
	DAFTAR ABSENSI<br>
	<?php echo $nama_sekolah;?><br>
	TAHUN : <?php echo $yy;?>
	</strong>
	</center>
	<br>
 </td>
  <tr>
    <td></td>
  </tr>
  <tr>
    <td></td>
  </tr>
  </table><br>
  <font size="3">
    <table border="0" width="100%" style="font-size: small;margin-left:0px">
	<tr height="30">
  <td height="30" width="20%">Nama Sekolah</td>
  <td height="30" width="2%">:</td>
  <td height="30" width="45%" ><?php echo $namsek; ?> </td>
  <td height="30" width="1%"></td>

  <td height="30" width="15%" style="margin-left:10px"> Grup</td>
    <td height="30" width="2%"> : </td>
  <td height="30" width="15%"><?php echo $namakelas; ?></td>
  </tr>

  <tr height="30">
  <td height="30" width="20%">Hari/Tanggal</td>
  <td height="30" width="2%">:</td>
  <td height="30" width="45%" ><?php echo hari($dd,$mm,$yy);?> /<?php echo $dd; ?> <?php echo bulan($mm); ?> <?php echo $yy; ?> </td>
  <td height="30" width="1%"></td>

  <td height="30" width="15%" style="margin-left:10px"> Pukul</td>
    <td height="30" width="2%"> : </td>
  <td height="30" width="15%"><?php echo date("H:m:s"); ?></td>
  </tr>
  </table>
  </font>

  <table style="border:1px solid black;border-collapse: collapse" width="100%">
  <tr bgcolor="#CCCCCC" height="40">
  <th width="5%" style="font-size: small;text-align: center;border:1px solid black">No.</th>
  <th width="35%" style="font-size: small;text-align: center;border:1px solid black">NAMA</th>
  <th width="11%" style="font-size: small;text-align: center;border:1px solid black">STATUS</th>
  <th width="11%"style="font-size: small;text-align: center;border:1px solid black">DATANG</th>
  <th width="11%" style="font-size: small;text-align: center;border:1px solid black">PULANG</th>
  <th width="35%" style="font-size: small;text-align: center;border:1px solid black">PULANG</th>
  </tr>

	<?php
	//$nomer=0;
	$lim=$hal*$jmlperhal;
	$siswa = $this->db->query("SELECT * FROM web_siswa WHERE KD_JENIS_KETENAGAAN='$kodekelas' ORDER BY NM_PEGAWAI asc LIMIT ".$mulai.",".$jmlperhal."");
	foreach ($siswa->result() as $rssis) {
		$nomer++;
		$namasiswa=$rssis->NM_PEGAWAI;
		$kodeabsen=$rssis->absen;
		$cekhari=$rssis->$harike3;
		//echo 'iki cek '.$cekhari;
		$skrg="$yy-$mm-$dd";
		$cek1=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status=1");
		$hasilcek1=$cek1->num_rows();
		$jamcek1='';
		$jamcek2='';
		$ketcek1='';
		//cekliburan
		$cekijin=$this->db->query("SELECT * FROM web_ijin WHERE tgl='$skrg' AND absen='$kodeabsen'");
		$hasilijin=$cekijin->num_rows();
		$ceklibur=$this->db->query("SELECT * FROM web_libur WHERE tgl='$skrg'");
		$hasillibur=$ceklibur->num_rows();
		if ($hasillibur ==0) {
			if ($cekhari==6){
				$kehadiran='LIBUR SEKOLAH';
			} elseif ($hasilijin != 0){
				foreach ($cekijin->result() as $rsijin) {
					$hijin=$rsijin->status;
					$ketcek1=$rsijin->ket;
					$cekst=$this->db->query("SELECT * FROM web_status WHERE kd_jenis='".$hijin."'");
					foreach ($cekst->result() as $rsst) {
						$kehadiran=$rsst->status;
					}
				}
			} else {
				if ($hasilcek1 !=0) {

					$kehadiran='<b>HADIR</b>';
					$cek2=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status=2");
					foreach ($cek2->result() as $rscek2) {
						$jamcek2=$rscek2->jam;
					}
					foreach ($cek1->result() as $rscek1) {
						$jamcek1=$rscek1->jam;
						$ketcek1=$rscek1->ket;
					}
				} else {
					$cek3=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status>=3");
					$hasilcek3=$cek3->num_rows();
					//echo "SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status>=3"."<br>";
					if ($hasilcek3 !=0) {
						foreach ($cek3->result() as $rscek3) {
						$status3=$rscek3->status;
						$ketcek1=$rscek3->ket;
						}
						$cekst=$this->db->query("SELECT * FROM web_status WHERE kd_jenis='".$status3."'");
						foreach ($cekst->result() as $rsst) {
							$statusku=$rsst->status;
						}
						$kehadiran='<b>'.strtoupper($statusku).'</b>';
					} else {
						$kehadiran='TIDAK HADIR';
					}
				}
			}
		} else {
			$kehadiran='LIBUR NASIONAL';
			foreach ($ceklibur->result() as $rslibur) {
				$ketcek1=$rslibur->ket;
			}
		}

		?>
		<tr height=30px>
		<td style='font-size: small; border:1px solid black' align='center'>&nbsp;<?php echo $nomer;?>.</td>
		<td style='font-size: small;border:1px solid black'><?php echo balikin($namasiswa);?></td>
		<td style='font-size: small;border:1px solid black'>&nbsp;<?php echo $kehadiran;?></td>
		<td style='font-size: small;border:1px solid black' align='center'>&nbsp;<?php echo $jamcek1;?></td>
		<td style='border:1px solid black' align='center'>&nbsp;<?php echo $jamcek2;?></td>
		<td style='border:1px solid black'>&nbsp;<?php echo $ketcek1;?></td>
		</tr>

	<?php }?>
	</table>
	</center>
</div>

	<?php
	$mulai=$mulai+$jmlperhal;
	}} else {?>
	<div class="page">
	<center>
	 <table border="0" width="100%">
     <tr>
    <td rowspan="1" width="100" align="left"><img src="<?php echo base_url('assets/back/'.$logo.'');?>" width="80"></td>
    <td>
	<center>
	<strong class="f12">
	DAFTAR ABSENSI<br>
	<?php echo $nama_sekolah;?><br>
	TAHUN : <?php echo $yy;?>
	</strong>
	</center>
	<br>
 </td>
  <tr>
    <td></td>
  </tr>
  <tr>
    <td></td>
  </tr>
  </table><br>
  <font size="3">
    <table border="0" width="100%" style="font-size: small;margin-left:0px">
	<tr height="30">
  <td height="30" width="20%">Nama Sekolah</td>
  <td height="30" width="2%">:</td>
  <td height="30" width="45%" ><?php echo $namsek; ?> </td>
  <td height="30" width="1%"></td>

  <td height="30" width="15%" style="margin-left:10px"> Grup</td>
    <td height="30" width="2%"> : </td>
  <td height="30" width="15%"><?php echo $namakelas; ?></td>
  </tr>

  <tr height="30">
  <td height="30" width="20%">Hari/Tanggal</td>
  <td height="30" width="2%">:</td>
  <td height="30" width="45%" ><?php echo hari($dd,$mm,$yy);?> /<?php echo $dd; ?> <?php echo bulan($mm); ?> <?php echo $yy; ?> </td>
  <td height="30" width="1%"></td>

  <td height="30" width="15%" style="margin-left:10px"> Pukul</td>
    <td height="30" width="2%"> : </td>
  <td height="30" width="15%"><?php echo date("H:m:s"); ?></td>
  </tr>
  </table>
  </font>

  <table style="border:1px solid black;border-collapse: collapse" width="100%">
  <tr bgcolor="#CCCCCC" height="40">
  <th width="5%" style="font-size: small;text-align: center;border:1px solid black">No.</th>
  <th width="35%" style="font-size: small;text-align: center;border:1px solid black">NAMA</th>
  <th width="11%" style="font-size: small;text-align: center;border:1px solid black">STATUS</th>
  <th width="11%"style="font-size: small;text-align: center;border:1px solid black">DATANG</th>
  <th width="11%" style="font-size: small;text-align: center;border:1px solid black">PULANG</th>
  <th width="35%" style="font-size: small;text-align: center;border:1px solid black">PULANG</th>
  </tr>

	<?php
	$i=0;
	$siswa = $this->db->query("SELECT * FROM web_siswa WHERE KD_JENIS_KETENAGAAN='$kodekelas' ORDER BY NM_PEGAWAI asc");
	foreach ($siswa->result() as $rssis) {
		$i++;
		$namasiswa=$rssis->NM_PEGAWAI;
		$kodeabsen=$rssis->absen;
		$cekhari=$rssis->$harike3;
		//echo 'iki cek '.$cekhari;
		$skrg="$yy-$mm-$dd";
		$cek1=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status=1");
		$hasilcek1=$cek1->num_rows();
		$jamcek1='';
		$jamcek2='';
		$ketcek1='';
		//cekliburan
		$cekijin=$this->db->query("SELECT * FROM web_ijin WHERE tgl='$skrg' AND absen='$kodeabsen'");
		$hasilijin=$cekijin->num_rows();
		$ceklibur=$this->db->query("SELECT * FROM web_libur WHERE tgl='$skrg'");
		$hasillibur=$ceklibur->num_rows();
		if ($hasillibur ==0) {
			if ($cekhari==6){
				$kehadiran='TIDAK ADA JADWAL';
			} elseif ($hasilijin != 0){
				foreach ($cekijin->result() as $rsijin) {
					$hijin=$rsijin->status;
					$ketcek1=$rsijin->ket;
					$cekst=$this->db->query("SELECT * FROM web_status WHERE kd_jenis='".$hijin."'");
					foreach ($cekst->result() as $rsst) {
						$kehadiran=$rsst->status;
					}
				}
			} else {
				if ($hasilcek1 !=0) {

					$kehadiran='<b>HADIR</b>';
					$cek2=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status=2");
					foreach ($cek2->result() as $rscek2) {
						$jamcek2=$rscek2->jam;
					}
					foreach ($cek1->result() as $rscek1) {
						$jamcek1=$rscek1->jam;
						$ketcek1=$rscek1->ket;
					}
				} else {
					$cek3=$this->db->query("SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status>=3");
					$hasilcek3=$cek3->num_rows();
					//echo "SELECT status,jam,ket FROM web_absen WHERE tgl='$skrg' AND nip='$kodeabsen' AND status>=3"."<br>";
					if ($hasilcek3 !=0) {
						foreach ($cek3->result() as $rscek3) {
						$status3=$rscek3->status;
						$ketcek1=$rscek3->ket;
						}
						$cekst=$this->db->query("SELECT * FROM web_status WHERE kd_jenis='".$status3."'");
						foreach ($cekst->result() as $rsst) {
							$statusku=$rsst->status;
						}
						$kehadiran='<b>'.strtoupper($statusku).'</b>';
					} else {
						$kehadiran='TIDAK HADIR';
					}
				}
			}
		} else {
			$kehadiran='LIBUR';
			foreach ($ceklibur->result() as $rslibur) {
				$ketcek1=$rslibur->ket;
			}
		}

		?>
		<tr height=30px>
		<td style='font-size: small; border:1px solid black' align='center'>&nbsp;<?php echo $i;?>.</td>
		<td style='font-size: small;border:1px solid black'><?php echo $namasiswa;?></td>
		<td style='font-size: small;border:1px solid black'>&nbsp;<?php echo $kehadiran;?></td>
		<td style='font-size: small;border:1px solid black' align='center'>&nbsp;<?php echo $jamcek1;?></td>
		<td style='border:1px solid black' align='center'>&nbsp;<?php echo $jamcek2;?></td>
		<td style='border:1px solid black'>&nbsp;<?php echo $ketcek1;?></td>
		</tr>

	<?php }?>
	</table>
	</center>
</div>
	<?php }}?>
</body>
</html>
