<?php
	include '../../inc/inc.koneksi.php';
	include '../../inc/fungsi_tanggal.php';
	
	$kode = $_GET[kode];
	$tgllap =date('d-m-Y');
	
	$sql = "SELECT * FROM departemen WHERE kode_dep='$kode' ORDER BY kode_dep";
	$query = mysql_query($sql);
	$r=mysql_fetch_array($query);
	$nadep = $r[nama_dep];
	
	$sql1 = "SELECT * FROM tambah_fas WHERE kode_dep='$kode' AND jumlah_amb<jumlah ORDER BY kode_tf";
	$query1 = mysql_query($sql1);
	
	$content = "<b><li>DAFTAR FASILITAS YANG BELUM DIAMBIL</li>
		<li>DEPARTEMEN $nadep</li>
		<li>PER TANGGAL $tgllap</li></b>
		<br>
	
		<table width='390' border='1' style='border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>NIK</th>
			<th>Nama Karyawan</th>
			<th>Kode Fas.</th>
			<th>Nama Fasilitas</th>
			<th>Tanggal</th>
			<th>Penambahan</th>
			<th>Diambil</th>
			<th>Sisa</th>
		</tr>";
		
		$no=1;	
		while($r_data=mysql_fetch_array($query1)){
			$sisa=$r_data[jumlah]-$r_data[jumlah_amb];
			
		$content .="<tr>
			<td align='center'>$no</td>
			<td align='center'>$r_data[kode_kar]</td>
			<td>$r_data[nama_kar]</td>
			<td align='center'>$r_data[kode_fas]</td>
			<td>$r_data[nama_fas]</td>
			<td align='center'>".jin_date_str($r_data[tanggal])."</td>			
			<td align='center'>$r_data[jumlah]</td>
			<td align='center'>$r_data[jumlah_amb]</td>
			<td align='center'>$sisa</td>	
			</tr>";					
			$no++;
		}
		
		$content .= "</table>";
				
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=daftar_of.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>
