<?php include 'header.php'; ?>

<?php 
		$laporan_harian = "11";
		$laporan_penanggungjawab = "12";
		$laporan_pengawas = "13";	

									
		If(isset($_POST['tanggal'])){
			$date=$_POST['tanggal'];
			$tahun = date("Y", strtotime($date)); //Mengambil tahun dari form
			$bulan = date("m", strtotime($date)); //Mengambil tbulan dari form
		} else {
			$tahun = date('Y'); //Mengambil tahun saat ini
			$bulan = date('m'); //Mengambil bulan saat ini
		}
	
		$tanggal = cal_days_in_month(CAL_GREGORIAN, $bulan, $tahun);
		
		//membuat bulan dalam indonesia
		
		if ($bulan == '01' ) {
			$blnindonesia ='Januari';
			} else if ($bulan == '02' )  {
				$blnindonesia ='Februari';
			} else if ($bulan == '03' )  {
				$blnindonesia ='Maret';
			} else if ($bulan == '04' )  {
				$blnindonesia ='April';
			} else if ($bulan == '05' )  {
				$blnindonesia ='Mei';
			} else if ($bulan == '06' )  {
				$blnindonesia ='Juni';
			} else if($bulan == '07' )  {
				$blnindonesia ='Juli';
			} else if ($bulan == '08' )  {
				$blnindonesia ='Agustus';
			} else if ($bulan == '09' )  {
				$blnindonesia ='September';
			} else if ($bulan == '10' )  {
				$blnindonesia ='Oktober';
			} else if ($bulan == '11' )  {
				$blnindonesia ='November';
			} else {
				$blnindonesia ='Desember';
		}
	
		//laporan pengawas		
		$lap_pengawas = mysqli_query($koneksi,"SELECT arsip_petugas FROM arsip WHERE arsip_kategori='13' and month(arsip_tgl)='$bulan' and year(arsip_tgl)='$tahun'");
		$pengawas = mysqli_fetch_array($lap_pengawas);
		$pengawas_jumlah = mysqli_num_rows($lap_pengawas);
		
		//laporan bulanan		
		$lap_bulanan = mysqli_query($koneksi,"SELECT arsip_petugas FROM arsip WHERE arsip_kategori='12' and month(arsip_tgl)='$bulan' and year(arsip_tgl)='$tahun'");
		$bulanan_jumlah = mysqli_num_rows($lap_bulanan);
	
	
		//menghitung jumlah hari kerja
		
					$awal_cuti = "1-$bulan-$tahun";
					$akhir_cuti = "$tanggal-$bulan-$tahun";
					 
		// tanggalnya diubah formatnya ke Y-m-d 
					$awal_cuti = date_create_from_format('d-m-Y', $awal_cuti);
					$awal_cuti = date_format($awal_cuti, 'Y-m-d');
					$awal_cuti = strtotime($awal_cuti);
					 
					$akhir_cuti = date_create_from_format('d-m-Y', $akhir_cuti);
					$akhir_cuti = date_format($akhir_cuti, 'Y-m-d');
					$akhir_cuti = strtotime($akhir_cuti);
					 
					$haricuti = array();
					$sabtuminggu = array();
					 
					for ($i=$awal_cuti; $i <= $akhir_cuti; $i += (60 * 60 * 24)) {
						if (date('w', $i) !== '0' && date('w', $i) !== '6') {
							$haricuti[] = $i;
						} else {
							$sabtuminggu[] = $i;
						}
					 
					}
					$jumlah_cuti = count($haricuti);
					$jumlah_sabtuminggu = count($sabtuminggu);
					$abtotal = $jumlah_cuti + $jumlah_sabtuminggu;
					
					


					
		//laporan harian		
		$lap_harian = mysqli_query($koneksi,"SELECT arsip_petugas FROM arsip WHERE arsip_kategori='11' and month(arsip_tgl)='$bulan' and year(arsip_tgl)='$tahun'");
		$harian_jumlah = mysqli_num_rows($lap_harian);
	
		//membuat bulan dalam indonesia
		$kd_pegawai = $_SESSION['id'];
?>


<div class="breadcome-area">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="breadcome-list">
                    <div class="row">
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="breadcome-heading">
							
							<form method="POST" class="form-inline">
								  <div class="box-body">
									<div class="form-group">
									  <label>  Pilih Bulan/Tahun   </label>&emsp;
									  <input type="date" id="tanggal" class="form-control" name="tanggal" required>
									</div>
								
									<div class="form-group">&emsp;
									  <input type='submit' name="tampilkan" value="Tampilkan" class='btn btn-success'>
									</div>
								  </div>
							</form>
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <ul class="breadcome-menu" style="padding-top: 0px">
                                <li><a href="#">Home</a> <span class="bread-slash">/</span></li>
                                <li><span class="bread-blod">Dashboard</span></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--

  <div class="traffice-source-area mg-b-30">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
                <div class="white-box analytics-info-cs">
                    <h3 class="box-title">Laporan Harian</h3>
					<?php
					if (empty ($harian_jumlah)) {
							$hj =$jumlah_cuti;
						} else {
							$hj = $jumlah_cuti-$harian_jumlah;
						}
					?>
					
					<button type="button" class="btn btn-primary">
						Belum Upload <span class="badge badge-light"><?php echo $hj ;?></span>
					</button> 
                </div>
            </div>
            <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
                <div class="white-box analytics-info-cs res-mg-t-30 table-mg-t-pro-n">
					<h3 class="box-title">Laporan Bulanan</h3>
					<?php 
					if (empty ($bulanan_jumlah)) {
							$bj ='4';
						} else {
							$bj = 4-$bulanan_jumlah;
						}
					?>
					
					<button type="button" class="btn btn-primary">
						Belum Upload <span class="badge badge-light"><?php echo $bj ;?></span>
					</button>                
				</div>
            </div>
			<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
                <div class="white-box analytics-info-cs res-mg-t-30 table-mg-t-pro-n">
					<h3 class="box-title">Laporan Pengawas</h3>
					
					<?php 
					if (empty ($pengawas)) {
							$pj ='1';
													} else {
														$pj = '0';
													}
					?>
					<button type="button" class="btn btn-primary">
						Belum Upload <span class="badge badge-light"><?php echo $pj ;?></span>
					</button>                
				</div>
            </div>
            
        </div>
    </div>
</div>

-->

<div class="product-sales-area mg-tb-30">
    <div class="container-fluid">
        <div class="row">
			<div class="col-md-4 col-xs-12">
                <div class="white-box analytics-info-cs">
					<div class="panel">
						<h3 class="panel-title">Laporan Harian</h3>
						
						<div class="panel-body">
							<div class="table-responsive-xl">
							  <table class="table">
								<thead>
									<tr>
										<th>No</th>
										<th>Tanggal</th>
										<th>Jam Masuk</th>
										<th>Jam Pulang</th>
										<th>Keterangan</th>
									</tr>
								</thead>
								
								<tbody>
								
									<?php 
									function tglind($x){
										$ref=array('','Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
										$aref=array('Minggu','Senin','Selasa','Rabu','Kamis','Jumat','Sabtu','Minggu');
										$bongkar=explode("-",$x);
										$angka=intval($bongkar[1]);
										$bulanind=$ref[$angka];
										$hari=date_format(date_create($x),"w");
										return "$aref[$hari], $bongkar[2] $bulanind $bongkar[0]";
									}
									
									$a = date("$tahun-$bulan-01") ;
									
									for ($i=1; $i < $tanggal+1; $i++) {
										if($i<10){
										$tgl="0".$i;
										}else{
										$tgl=$i;
									}
									
									?>
								
									<tr>
										<th><?php echo $i;?> </th>
										<th><?php echo tglind($a++);?></th>
										<th><?php 
											$absen = mysqli_query($koneksi,"SELECT * FROM absensi WHERE kd_pegawai ='$kd_pegawai' and tanggal='$tahun-$bulan-$tgl'");
											$lap_absen = mysqli_num_rows($absen);
											$lap_absen_isi = mysqli_fetch_array ($absen);
												
											if (empty ($lap_absen)) {
													echo '-';
												} else {
													echo $lap_absen_isi['masuk'];
												}
												
											
											
											?>
										</th>
										<th ><?php 
											$absen = mysqli_query($koneksi,"SELECT * FROM absensi WHERE kd_pegawai ='$kd_pegawai' and tanggal='$tahun-$bulan-$tgl'");
											$lap_absen = mysqli_num_rows($absen);
											$lap_absen_isi = mysqli_fetch_array ($absen);
												
											if (empty ($lap_absen)) {
													echo '-';
												} else {
													echo $lap_absen_isi['pulang'];
												}
										?>
										</th>
										<th>
										
										</th>
									</tr>
									
									<?php }?>
									
								</tbody>
							  </table>
							</div>
							
						</div>

				</div>
                 
                </div>
            </div>
		
			
        </div>
    </div>
</div>


<?php include 'footer.php'; ?>