<?php 
//usleep(500000);
date_default_timezone_set('Asia/Jakarta');
$tgl=date('d-m-Y H:i:s');

require '../functions.php';


session_start();




if(!isset($_SESSION["login"]) ) {
	header("Location: ../login.php");
	exit;
}


$logkanwil=$_SESSION["logkanwil"]; 

$keyword = $_GET["keyword"];



	if($logkanwil=="KP")

	
				{
				    
	$query = "SELECT * FROM spbc
            WHERE
          (nama LIKE '%$keyword%' OR
          
          norange LIKE '%$keyword%' OR
          kanwil LIKE '%$keyword%' OR
          jumlah LIKE '%$keyword%' OR
          tgl_input LIKE '%$keyword%' OR
          flag LIKE '%$keyword%' OR
          jml_ok LIKE '%$keyword%' OR
          rp LIKE '%$keyword%' OR
          rp_ok LIKE '%$keyword%' OR
          tgl_ok LIKE '%$keyword%' OR
          alasan LIKE '%$keyword%' OR
          budget LIKE '%$keyword%'OR
          kcu LIKE '%$keyword%' ) order by kanwil,kcu";}
		    
				else
				    
		{$query = "SELECT * FROM spbc		    
		    WHERE kanwil='$logkanwil' and
		    
		  (nama LIKE '%$keyword%' OR
          
          norange LIKE '%$keyword%' OR
          kanwil LIKE '%$keyword%' OR
          jumlah LIKE '%$keyword%' OR
          tgl_input LIKE '%$keyword%' OR
          flag LIKE '%$keyword%' OR
          jml_ok LIKE '%$keyword%' OR
          rp LIKE '%$keyword%' OR
          rp_ok LIKE '%$keyword%' OR
          tgl_ok LIKE '%$keyword%' OR
          alasan LIKE '%$keyword%' OR
          budget LIKE '%$keyword%'OR
          kcu LIKE '%$keyword%' ) order by kanwil,kcu";}
		  
				

$mahasiswa = query($query);


echo "$tgl, Login KANWIL :$logkanwil ";
//echo "  Login KANWIL :$logkanwil";
?>

<a href="tambah.php"> |Tambah Permohonan|</a>
<a href="quota.php"> |Lihat Quota|</a>
<a href="print.php">|Print Permohonan|</a>
<a href="grafik.php">|Grafik Persetujuan|</a>
<a href="export_ke_excel/index.php">|Export Excel|</a>
<a href="import.php">|Import CSV|</a>
<a href="registrasi.php">|Registrasi|</a>
<a href="logout.php"> |Logout|</a> 



<br><br>

<table border="1" cellpadding="10" cellspacing="0">

        <th>No.</th>
		<th>Action</th>
		<th>Nama PIC</th>
		<th>No.BKAD Orange</th>
		<th>Kanwil/KP</th>
		<th>Cabang/Unit</th>
		<th>Jn. Pekerjaan</th>
		<th>Jml Diajukan</th>
		<th>Rp. Diajukan</th>
		<th>Tgl Diajukan</th>
		<th>Alasan Diajukan</th>
		<th>Budget</th>
		
		<th>Processed</th>
		<th>Jml Disetujui</th>
		<th>Rp. Disetujui</th>
		<th>Tgl Disetujui</th>
	
	
    <?php $i = 1; ?>
    <?php foreach( $mahasiswa as $row ) : ?>
    
    <tr>
		<td><?= $i; ?></td>
		<td>
			<?php
				if($row['flag']=="Y")
				{
					echo "";
				}
				else{
			?>
				<a href="proses.php?id=<?php echo $row["id"]; ?>"                  >Proses</a>      |<a href="ubah.php?id=<?php echo $row["id"]; ?>">Ubah</a>|
		
		
		<?php } ?>
		
		
    		  <a href="hapus.php?id=<?php echo $row["id"]; ?>" onclick="return confirm('Anda yakin ...?')">Hapus</a></td>
<!--              <a href="cetak.php?id=<?php echo $row["id"]; ?>" onclick="return confirm('Anda yakin...?')">Cetak</a></td> -->

    

    
		<td><?= $row["nama"]; ?></td>
		<td><?= $row["norange"]; ?></td>
		<td><?= $row["kanwil"]; ?></td>
		<td><?= $row["kcu"]; ?></td>
		<td><?= $row["jn_pek"]; ?></td>
		<td><?php echo number_format($row['jumlah'],0,",","."); ?></td>
    	<td><?php echo number_format($row['rp'],0,",","."); ?></td>
		<td><?php echo date("d-m-Y", strtotime($row['tgl_input']));?></td>
		
		
		
		<td><?= $row["alasan"]; ?></td>
		<td><?= $row["budget"]; ?></td>
		
		<td><?= $row["flag"]; ?></td>
	    <td><?php echo number_format($row['jml_ok'],0,",","."); ?></td>
		<td><?php echo number_format($row['rp_ok'],0,",","."); ?></td>
		<td><?php echo date("d-m-Y", strtotime($row['tgl_ok']));?></td>
			
		
        
    </tr>
    <?php 
    $i++;
    $aaa=$aaa+$row["jumlah"];
	$bbb=$bbb+$row["jml_ok"];
    $ccc=$ccc+$row["rp"];
	$ddd=$ddd+$row["rp_ok"];

   ?>
    <?php endforeach; ?>
    
</table>

<br>
<table border="2" cellspacing="3" cellpadding="3">
<tr>
		
		<th>Jml Diajukan:</th>
	    <td><?= number_format($aaa,0,",","."); ?></td>
	    
	    	<th>Jml Disetujui :</th>
	    <td><?= number_format($bbb,0,",","."); ?></td>
	
	   
		<th>Persentase:</th>
	    <td><?= number_format($bbb/$aaa*100,0,",","."); ?></td>
	
	
	    
</tr>
</table>


<br>
<table border="2" cellspacing="3" cellpadding="3">
<tr>
		
		<th>Rp. Diajukan:</th>
	    <td><?= number_format($ccc,0,",","."); ?></td>
		<th>Rp. Disetujui :</th>
	    <td><?= number_format($ddd,0,",","."); ?></td>
	    
	   	<th>Persentase:</th>
	    <td><?= number_format($ddd/$ccc*100,0,",","."); ?></td>
	
	    
	    

</tr>
</table>











