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

	$tgl_awal= $_GET['tgl_awal'];
	$tgl_akhir= $_GET['tgl_akhir'];
	$jenis= $_GET['jenis'];

	if($jenis=='')
		$ljenis='Keseluruhan';
	else
		$ljenis='$jenis';
	
	$content = "<b><li>DAFTAR PERUBAHAN HARGA BBM</li>
		<li>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</li>
		<li>JENIS BBM : $ljenis</li></b>
		<br>
	
		<table width='390' border='1' style='border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Kode Transaksi</th>
			<th>Tanggal</th>
			<th>Jenis BBM</th>
			<th>Jumlah Stok</th>
			<th>Hg.Jual Sebelumnya</th>
			<th>Hg.Jual Sekarang</th>
			<th>Hg.Beli Sebelumnya</th>
			<th>Hg.Beli Sekarang</th>
			<th>Total Selisih</th>
		</tr>";
		
		if(!empty($jenis))
			$sql = "SELECT * FROM ubah_hg WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND jenis='$jenis' AND batal='' GROUP BY kode_uh ";
		else
			$sql = "SELECT * FROM ubah_hg WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_uh ";
		$query = mysql_query($sql);
		
		$query = mysql_query($sql);
		$no=1;
		$tsls=0;

		while($r=mysql_fetch_array($query)){
			$tsls= $tsls+$r[selisih];
		
			$content .= "<tr>	
				<td align='center'>$no</td>
				<td align='center'>$r[kode_uh]</td>
				<td align='center'>".jin_date_str($r[tanggal])."</td>
				<td>$r[jenis]</td>
				<td align='right'>$r[jml_stok]</td>					
				<td align='right'>".number_format($r[hj_lama])."</td>
				<td align='right'>".number_format($r[hj_baru])."</td>
				<td align='right'>".number_format($r[hb_lama],2)."</td>
				<td align='right'>".number_format($r[hb_baru],2)."</td>
				<td align='right'>".number_format($r[selisih])."</td>
			</tr>";
		}
		
		$content .= "<tr>				
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total </td>
		    <td align='right'>".number_format($tsls)."</td>
		</tr>
	</table>";
				
	header("Content-type: application/x-msdownload");
	header("Content-Disposition: attachment; filename=daftar_uhbbm.xls");
	header("Pragma: no-cache");
	header("Expires: 0");
	echo $content;
?>