<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';

	$cari= $_GET['cari'];
	
	if($cari=='')
		$jenis='Keseluruhan';
	else
		$jenis='$cari';

	$content = "<b><li>DAFTAR PENEBUSAN DO BBM</li>
	    <li>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</li>
		<li>JENIS BBM : $jenis</b>
		<br>
	
	<table width='100%' border='1' style='border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Kode Tebusan</th>
			<th>Tanggal</th>
			<th>Nomor Bukti</th>
			<th>Rekening Bank</th>
			<th>Jenis BBM</th>
			<th>Jumlah Liter</th>
			<th>Harga Beli</th>
			<th>Jumlah Harga</th>
			<th>PPh Pasal 22</th>
			<th>Jumlah Disetor</th>
		</tr>";
		
		if(!empty($cari))
			$sql = "SELECT * FROM tebus_do WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND cari LIKE '%$cari%' AND batal='' GROUP BY kode_do ";
		else
			$sql = "SELECT * FROM tebus_do WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_do ";
		$query = mysql_query($sql);
		
		$no=1;
		$tliter=0;
		$tjumlah=0;
		$tpph=0;
		$tsetor=0;
		
		while($r_data=mysql_fetch_array($query)){
			$tliter = $tliter+$r_data[jml_liter];
			$tjumlah= $tjumlah+$r_data[jml_harga];
			$tpph= $tpph+$r_data[jml_pph];
			$tsetor= $tsetor+$r_data[jml_setor];

			$content .= "<tr>	
				<td align='center'>$no</td>
					<td align='center'>$r_data[kode_do]</td>
					<td align='center'>".jin_date_str($r_data[tanggal])."</td>
					<td align='center'>$r_data[nobukti]</td>
					<td align='center'>$r_data[namabank]</td>
					<td>$r_data[jenis]</td>
					<td align='right'>$r_data[jml_liter]</td>
					<td align='right'>$r_data[hg_beli]</td>
					<td align='right'>".number_format($r_data[jml_harga])."</td>
					<td align='right'>$r_data[jml_pph]</td>
					<td align='right'>".number_format($r_data[jml_setor])."</td>
				</tr>";
			$no++;
		}
		
		$content .= "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total</td>
				<td align='right'>$tliter</td>
				<td></td>
				<td align='right'>".number_format($tjumlah)."</td>
				<td align='right'>$tpph</td>
				<td align='right'>".number_format($tsetor)."</td>
			</tr>";
			
		$content .= "</table>";
				
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=daftar_tbdo.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>
