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

	$tanggal= date('Y-m-d'];
	$ctanggal=.to_indonesian_date($tanggal).;	
	
	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='390' 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 jenis LIKE '%$cari%' AND batal='' GROUP BY tanggal,kode_do ";
		else
			$sql = "SELECT * FROM tebus_do WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY tanggal,kode_do ";
		$query = mysql_query($sql);
		
		$no=1;
		$tliter=0;
		$tjumlah=0;
		$tpph=0;
		$tsetor=0;
		
		while($r=mysql_fetch_array($query)){
			$tliter = $tliter+$r[jml_liter];
			$tjumlah= $tjumlah+$r[jml_harga];
			$tpph= $tpph+$r[jml_pph];
			$tsetor= $tsetor+$r[jml_setor];

			$content .= "<tr>	
				<td align='center'>$no</td>
					<td align='center'>$r[kode_do]</td>
					<td align='center'>".jin_date_str($r[tanggal])."</td>
					<td align='center'>$r[nobukti]</td>
					<td align='center'>$r[namabank]</td>
					<td>$r[jenis]</td>
					<td align='right'>$r[jml_liter]</td>
					<td align='right'>$r[hg_beli]</td>
					<td align='right'>".number_format($r[jml_harga])."</td>
					<td align='right'>$r[jml_pph]</td>
					<td align='right'>".number_format($r[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;
?>
