<?php
include('class/mysql_crud.php');
$db_finger=new Database();
$db_finger->connect();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="">
<input type="hidden" name="proses" />
Bulan : 
<select name="bulan">
<?php
$bln_tampil=array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Obtober","November","Desember");
$bln_angka=array("01","02","03","04","05","06","07","08","09","10","11","12");
for($i=0;$i<=11;$i++){
echo"<option value='$bln_angka[$i]'>$bln_tampil[$i]</option>";	
}
?>
</select> <input type="text" name="tahun" />
<input type="submit" value="PROSES" />
</form>

<?php
if(isset($_POST['proses'])){

$blnsekarang="$_POST[tahun]-$_POST[bulan]";
$db_finger->select('libur','*','','left(tanggal_awal,7)="'.$blnsekarang.'"','','');
$cek_libur = $db_finger->numRows();
$indexlibur=$cek_libur-1;
$data_libur = $db_finger->getResult();
$cd=0;

//print_r($data_libur);	
$jml_hari=@cal_days_in_month(CAL_GREGORIAN, $_POST['bulan'], $_POST['tahun']);	
?>
<a href="laporan_cetak.php?proses=&bulan=<?php echo $_POST['bulan']; ?>&tahun=<?php echo $_POST['tahun']; ?>"><button>CETAK LAPORAN</button></a>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<th rowspan="2">No.</th>
<th rowspan="2">PIN</th>
<th rowspan="2">Nama</th>
<th rowspan="2">Scan</th>
<th colspan="<?php echo $jml_hari;?>">TANGGAL</th>
<th colspan="4">REKAP</th>
</tr>
<tr>
<?php
for($x=1;$x<=$jml_hari;$x++){
if($x<10){
$tanggal="0".$x;
}else{
$tanggal=$x;	
}	
$d = date("l", mktime(0, 0, 0, $_POST['bulan'], $tanggal, $_POST['tahun']));
$tgl="$_POST[tahun]-$_POST[bulan]-$tanggal";
?>
<th width="20" <?php if($d=="Sunday"){echo"bgcolor=red";}elseif($cek_libur>0 and($tgl>=$data_libur[$cd]['tanggal_awal'] and $tgl<=$data_libur[$cd]['tanggal_akhir'])){echo"bgcolor=red";  }?>><?php echo $tanggal; if($cd<$indexlibur){$cd++;}?></th>
<?php	
}
?>
<th>Efektif</th>
<th>scan</th>
<th>Tidak Scan</th>
<th>Persentase</th>
</tr>
<?php
$db_finger->select('ptk','*','','','pin asc','');
$data_ptk = $db_finger->getResult();
$no=1;
foreach($data_ptk as $d_data_ptk){
$cdin=0;	
$cdout=0;	
?>
<tr>
<td rowspan="2"><?php echo $no; ?></td>
<td rowspan="2"><?php echo $d_data_ptk['pin'];?></td>
<td rowspan="2"><?php echo $d_data_ptk['nama'];?></td>
<td>IN</td>
<?php
for($x=1;$x<=$jml_hari;$x++){
if($x<10){
$tanggal="0".$x;
}else{
$tanggal=$x;	
}
$d = date("l", mktime(0, 0, 0, $_POST['bulan'], $tanggal, $_POST['tahun']));
$tgl="$_POST[tahun]-$_POST[bulan]-$tanggal";
$cektanggal="$_POST[tahun]-$_POST[bulan]-$tanggal";
$db_finger->select('absensi_log','*',NULL,'pin="'.$d_data_ptk['pin'].'"'.'and left(scan_date,10)="'.$cektanggal.'"','scan_date asc','0,1');
$data_log=$db_finger->getResult();
$res = $db_finger->getResult(); 
$log="";
?>
<td align="center" <?php if($d=="Sunday"){echo"bgcolor=red";}elseif($cek_libur>0 and $tgl>=$data_libur[$cdin]['tanggal_awal'] and $tgl<=$data_libur[$cdin]['tanggal_akhir']){echo"bgcolor=red"; }else{
if(@$data_log[0]['scan_date']==0){
$log="-";
$efektif[$tanggal]=1;	
$tidak[$tanggal]=1;
$scan[$tanggal]=0;
}else{
$efektif[$tanggal]=1;
$scan[$tanggal]=1;
$tidak[$tanggal]=0;
$log=substr($data_log[0]['scan_date'],11,5);
}	
}
?>><?php echo $log; if($cdin<$indexlibur){$cdin++;}?></td>
<?php	
}
?>
<td><?php $jml_efektif=array_sum($efektif); echo "$jml_efektif"; ?></td>
<td><?php $jml_scan=array_sum($scan); echo "$jml_scan"; ?></td>
<td><?php $jml_tidak=array_sum($tidak); echo "$jml_tidak"; ?></td>
<td><?php $jml_persen=ceil($jml_scan/$jml_efektif*100); echo "$jml_persen %"; ?></td>
</tr>






<tr bgcolor="#E5E5E5">
<td>OUT</td>
<?php
for($x=1;$x<=$jml_hari;$x++){
if($x<10){
$tanggal="0".$x;
}else{
$tanggal=$x;	
}
$d = date("l", mktime(0, 0, 0, $_POST['bulan'], $tanggal, $_POST['tahun']));
$tgl="$_POST[tahun]-$_POST[bulan]-$tanggal";
$cektanggal="$_POST[tahun]-$_POST[bulan]-$tanggal";
$db_finger->select('absensi_log','*',NULL,'pin="'.$d_data_ptk['pin'].'"'.'and left(scan_date,10)="'.$cektanggal.'"','scan_date desc','');
$data_log=$db_finger->getResult();
$jm_log=$db_finger->numRows();
$res = $db_finger->getResult(); 
$log="";
?>
<td align="center" <?php if($d=="Sunday"){echo"bgcolor=red";}elseif($cek_libur>0 and $tgl>=$data_libur[$cdout]['tanggal_awal'] and $tgl<=$data_libur[$cdout]['tanggal_akhir']){echo"bgcolor=red"; if($cd<$cek_libur-1){$cd++;}}else{
if(@$data_log[0]['scan_date']==0 or $jm_log<=1){
$log="-";
$efektif[$tanggal]=1;	
$tidak[$tanggal]=1;
$scan[$tanggal]=0;
}else{
$efektif[$tanggal]=1;
$scan[$tanggal]=1;
$tidak[$tanggal]=0;
$log=substr($data_log[0]['scan_date'],11,5);
}	
}
?>><?php echo $log; if($cdout<$indexlibur){$cdout++;}?></td>
<?php	
}
?>
<td><?php $jml_efektif=array_sum($efektif); echo "$jml_efektif"; ?></td>
<td><?php $jml_scan=array_sum($scan); echo "$jml_scan"; ?></td>
<td><?php $jml_tidak=array_sum($tidak); echo "$jml_tidak"; ?></td>
<td><?php $jml_persen=ceil($jml_scan/$jml_efektif*100); echo "$jml_persen %"; ?></td>
</tr>



















<?php
$no++;}
}
?>
</table>
</body>
</html>
