<?php 
include 'connect.php';
session_start();

	
	$sql1 = "select * from `user` where kad_pengenalan = '".$_SESSION['kadPengenalan']."' ";
	$result1 = mysqli_query($conn,$sql1);
	$row1 = mysqli_fetch_array($result1);
	
	$peranan= $row1['peranan_user'];

	if(isset($_POST['pdf'])) {
		pdf();
	}
	else {
	}

?>

<style type="text/css" media="print">
    @page { 
        size: portrait;
    }
</style>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Sistem Pendaftaran Surat</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="assets/img/logo_tab.png" rel="icon">

  <!-- Google Fonts -->
  <link href="https://fonts.gstatic.com" rel="preconnect">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
  <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>  
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>   
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script> 
  
  <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">  
   

  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">
  
  <!-- Script logout -->
  <script type="text/javascript" src="internalPage/logoutConfirmation.js"></script>

  <!-- =======================================================
  * Template Name: NiceAdmin - v2.2.0
  * Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
  * Author: BootstrapMade.com
  * License: https://bootstrapmade.com/license/
  ======================================================== -->
</head>

<body>

<?php 
 if($peranan=="USER")
 {
  include 'headerUser.php';
 }
else
 {
	 include 'header.php';
 }
 ?>

  <main id="main" class="main">
	<form class="row g-3" action="printEksekutifBulanan.php" method="post">	
    <div class="pagetitle">
      <h1>Laporan Eksekutif Surat Masuk Bulanan </h1>
		
		<div class="row mb-3">
		  <label class="col-sm-2 col-form-label">Bulan:</label>
		  <div class="col-sm-3">
			<select class="form-select" aria-label="Default select example" name="bulan" id="bulan">
			  <option selected></option>
			  <option value="01">01</option>
			  <option value="02">02</option>
			  <option value="03">03</option>
			  <option value="04">04</option>
			  <option value="05">05</option>
			  <option value="06">06</option>
			  <option value="07">07</option>
			  <option value="08">08</option>
			  <option value="09">09</option>
			  <option value="10">10</option>
			  <option value="11">11</option>
			  <option value="12">12</option>

			  
			</select>
		  </div>
		</div>
		<div class="row mb-3">
		  <label for="inputDate" class="col-sm-2 col-form-label">Tahun</label>
		  <div class="col-sm-3">
			<input type="number" min="2021" class="date form-control" name="tahun" id="tahun" data-date-format="dd-mm-yy">
		  </div>
		</div>
		<button type="submit" class="btn btn-primary">Cari</button>
		<button type="reset" class="btn btn-secondary">Reset</button>
		<form id="form1" runat='server' method="post">		 
		<button type="submit" name="pdf" id="pdf" style="margin-left:2%" class="btn btn-primary" media="print" onclick="javascript:printDiv('sample')"><i class="bi bi-file-earmark-pdf-fill"></i></button>
		</form>
	</form>
    </div><!-- End Page Title -->
	
      <div class="row">
        <div class="col-lg-12">
		
          <div class="card" style="overflow:scroll">
			<div id="sample" name="sample">
			  
				
				<?php
						if(count($_POST)>0)
						{
							$bulan=$_POST['bulan'];						 
							$tahun=$_POST['tahun'];												

				?>
				
					 <h5 class="card-title" style="font-size:12px;color:black;text-align: center;">
					 <b>MAJLIS AGAMA ISLAM NEGERI PULAU PINANG
					 <br>
					 <b>LAPORAN EKSEKUTIF SURAT MASUK BULANAN
					 <br>
					 BULAN: <?php echo $bulan?>	TAHUN: 	<?php echo $tahun?>		 
					 </b></h5>
		
				  <!-- Table with stripped rows -->
				  <table class="table table-bordered">
					<thead>
					 <tr style="font-size:14px;color:black">
						<th scope="col">BIL</th>
						<th scope="col">BAHAGIAN</th>
						<th scope="col">JUMLAH SURAT</th>
						
					  </tr>
					</thead>
					<tbody style="font-size:12px;color:black">
					<?php
						$query ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='YANG DI PERTUA' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result = mysqli_query($conn,$query);
						$row = mysqli_num_rows($result);
						
						$query2 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='SETIAUSAHA' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result2 = mysqli_query($conn,$query2);
						$row2 = mysqli_num_rows($result2);
						
						$query3 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='PENGURUS BAITULMAL' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result3 = mysqli_query($conn,$query3);
						$row3 = mysqli_num_rows($result3);
						
						$query4 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='PEJABAT SETIAUSAHA' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result4 = mysqli_query($conn,$query4);
						$row4 = mysqli_num_rows($result4);
						
						$query5 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='BAHAGIAN PENTADBIRAN DAN SUMBER MANUSIA' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result5 = mysqli_query($conn,$query5);
						$row5 = mysqli_num_rows($result5);
						
						$query6 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='UNIT PEMBANGUNAN HARTANAH DAN HARTA WAKAF' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result6 = mysqli_query($conn,$query6);
						$row6 = mysqli_num_rows($result6);
						
						$query7 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='UNIT PENGURUSAN DANA WAKAF' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result7 = mysqli_query($conn,$query7);
						$row7 = mysqli_num_rows($result7);
						
						$query8 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='UNIT PENGURUSAN DAN PENYELENGGARAAN PREMIS' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result8 = mysqli_query($conn,$query8);
						$row8 = mysqli_num_rows($result8);
						
						$query9 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='BAHAGIAN UNDANG-UNDANG' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result9 = mysqli_query($conn,$query9);
						$row9 = mysqli_num_rows($result9);
						
						$query10 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='BAHAGIAN KEWANGAN DAN AKAUN' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result10 = mysqli_query($conn,$query10);
						$row10 = mysqli_num_rows($result10);
						
						$query11 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='UNIT AUDIT DALAM' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result11 = mysqli_query($conn,$query11);
						$row11 = mysqli_num_rows($result11);
						
						$query12 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='PENGURUSAN' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result12 = mysqli_query($conn,$query12);
						$row12 = mysqli_num_rows($result12);
						
						$query13 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='UNIT PENTADBIRAN TANAH' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result13 = mysqli_query($conn,$query13);
						$row13 = mysqli_num_rows($result13);
						
						$query14 ="SELECT id_surat_masuk FROM `surat_masuk`  WHERE bahagian='UNIT PEMBANGUNAN' AND SUBSTRING(`tarikh_terima_surat`,1,4)='".$tahun."' AND SUBSTRING(`tarikh_terima_surat`,6,2)='".$bulan."';";
						$result14 = mysqli_query($conn,$query14);
						$row14 = mysqli_num_rows($result14);
						

					?>
					<tr >
						<th scope="row" style="width:10%">1</th>
						<td style="width:60%">YANG DI PERTUA</td>
						<td style="width:40%"><?php echo $row; ?></td>	
                  </tr>
				  <tr >
						<th scope="row" style="width:10%">2</th>
						<td style="width:60%">SETIAUSAHA</td>
						<td style="width:40%"><?php echo $row2; ?></td>	
                  </tr>
				  <tr>
						<th scope="row" style="width:10%">3</th>
						<td style="width:60%">PENGURUS BAITULMAL</td>
						<td style="width:40%"><?php echo $row3; ?></td>
				  </tr>
				   <tr>
						<th scope="row" style="width:10%">4</th>
						<td style="width:60%">PEJABAT SETIAUSAHA</td>
						<td style="width:40%"><?php echo $row4; ?></td>
				 </tr>
				 <tr>
						<th scope="row" style="width:10%">5</th>
						<td style="width:60%">BAHAGIAN PENTADBIRAN DAN SUMBER MANUSIA</td>
						<td style="width:40%"><?php echo $row5; ?></td>	
				  </tr>		
				  <tr>
						<th scope="row" style="width:10%">6</th>
						<td style="width:60%">UNIT PEMBANGUNAN HARTANAH DAN HARTA WAKAF</td>
						<td style="width:40%"><?php echo $row6; ?></td>
				  </tr>
				   <tr>
						<th scope="row" style="width:10%">6</th>
						<td style="width:60%">UNIT PENTADBIRAN TANAH</td>
						<td style="width:40%"><?php echo $row13; ?></td>
				  </tr>
				   <tr>
						<th scope="row" style="width:10%">6</th>
						<td style="width:60%">UNIT PEMBANGUNAN</td>
						<td style="width:40%"><?php echo $row14; ?></td>
				  </tr>
						<th scope="row" style="width:10%">7</th>
						<td style="width:60%">UNIT PENGURUSAN DANA WAKAF</td>
						<td style="width:40%"><?php echo $row7; ?></td>
				  <tr>
						<th scope="row" style="width:10%">8</th>
						<td style="width:60%">UNIT PENGURUSAN DAN PENYELENGGARAAN PREMIS</td>
						<td style="width:40%"><?php echo $row8; ?></td>
				  </tr>
				  <tr>
						<th scope="row" style="width:10%">9</th>
						<td style="width:60%">BAHAGIAN UNDANG-UNDANG</td>
						<td style="width:40%"><?php echo $row9; ?></td>
				  </tr>
				  <tr>
						<th scope="row" style="width:10%">10</th>
						<td style="width:60%">BAHAGIAN KEWANGAN DAN AKAUN</td>
						<td style="width:40%"><?php echo $row10; ?></td>
				  </tr>
				  <tr>
						<th scope="row" style="width:10%">11</th>
						<td style="width:60%">UNIT AUDIT DALAM</td>
						<td style="width:40%"><?php echo $row11; ?></td>
				  </tr>
				  <tr>
						<th scope="row" style="width:10%">12</th>
						<td style="width:60%">PENGURUSAN</td>
						<td style="width:40%"><?php echo $row12; ?></td>
				  </tr>
					
					</tbody>
					
				  </table>
				  <!-- End Table with stripped rows -->

				
				</div>
				<?php 
						}

						else
						{}				
					?>
				
			</div>	
          </div>

        </div>
      </div>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <footer id="footer" class="footer">
    <div class="copyright">
      &copy; Copyright <strong><span>Majlis Agama Islam Negeri Pulau Pinang @ 2022</span></strong>.
    </div>
  </footer><!-- End Footer -->

  <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

  <!-- Vendor JS Files -->
  <script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/chart.js/chart.min.js"></script>
  <script src="assets/vendor/echarts/echarts.min.js"></script>
  <script src="assets/vendor/quill/quill.min.js"></script>
  <script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
  <script src="assets/vendor/tinymce/tinymce.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>
  

  <!-- Template Main JS File -->
  <script src="assets/js/main.js"></script>
  
  <!--Javascript function to save data inside 'sample' div --> 
 
    <script language="javascript" type="text/javascript"> 
        function printDiv(divID)  
		{ 
            var divElements = document.getElementById(divID).innerHTML; 
            var oldPage = document.body.innerHTML; 
 
           document.body.innerHTML =  
              "<html><head><title></title></head><body class='d-flex flex-column min-vh-100'>"+  
              divElements+"</body>"; 
			  
            window.print(); 
 
            document.body.innerHTML = oldPage; 
        } 
    </script> 

</body>

</html>