<script type="text/javascript">	
	window.print();
</script>

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

	$tgl_awal = $_GET['tgl_awal'];
	$tgl_akhir= $_GET['tgl_akhir'];
	$kodepl   = $_GET['kodepl'];
	$namapl   = $_GET['namapl'];
	
	$sql=mysql_query("SELECT * FROM company");
	$r	=mysql_fetch_assoc($sql);	
	$kop1 = $r[nama1];
	$kop2 = $r[nama2];
	$kop3 = $r[alamat];
	
	echo "<table style='font:11px arial'>
		<tr>
			<td>$kop1</td>
		</tr>
		<tr>
			<td>$kop2</td>
		</tr>
		<tr>
			<td>$kop3</td>
		</tr>
	</table>
		
	<table width='100%'>
		<tr>
			<td align='center' style='font:14px arial'><b>LAPORAN PELANGGAN $namapl</b></td>
		</tr>
		<tr>
			<td align='center' style='font:14px arial'><b>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</b></td>
		</tr>
	</table>
	<br>
	
	<table width='100%' border='1' style='font:11px arial;border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>No.Polisi</th>
			<th>Premium</th>
			<th>Bio Solar</th>
			<th>Pertamax</th>
			<th>Pertamax Turbo</th>
			<th>Pertalite</th>
			<th>Pertamina Dex</th>
			<th>Dexlite</th>
			<th>Jml.Liter</th>
			<th>Jumlah Rupiah</th>
		</tr>";
		
		$data = mysql_query("SELECT * FROM setor_bbm WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kode_pl='$kodepl' AND batal='' GROUP BY nopol");
	
		$no=1;
		$tpremium=0;
		$tsolar=0;
		$tpertamax=0;
		$tptmplus=0;
		$tptlite=0;
		$tdex=0;
		$tdexlite=0;
		$tjual=0;
		$tnilai=0;
	
		while($r_data=mysql_fetch_array($data)){
			$nopol=$r_data[nopol];
		
			$sql = mysql_query("SELECT jenis,jml_nopol,nilai_nopol FROM setor_bbm WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND kode_pl='$kodepl' AND nopol='$nopol' AND batal=''");
			$premium=0;
			$solar=0;
			$pertamax=0;
			$ptmplus=0;
			$ptlite=0;
			$dex=0;
			$dexlite=0;
			$jual=0;
			$nilai=0;
		
			while($r=mysql_fetch_array($sql)){
				$jenis=$r[jenis];
				if($jenis=='Premium')
					$premium=$premium+$r[jml_nopol];
				else if($jenis=='Bio Solar')
					$solar=$solar+$r[jml_nopol];
				else if($jenis=='Pertamax')
					$pertamax=$pertamax+$r[jml_nopol];
				else if($jenis=='Pertamax Turbo')
					$ptmplus=$ptmplus+$r[jml_nopol];
				else if($jenis=='Pertalite')
					$ptlite=$ptlite+$r[jml_nopol];
				else if($jenis=='Pertamina Dex')
					$dex=$dex+$r[jml_nopol];
				else if($jenis=='Dexlite')
					$dexlite=$dexlite+$r[jml_nopol];
				$nilai=$nilai+$r[nilai_nopol];
			}
			$jual=$premium+$solar+$pertamax+$ptmplus+$ptlite+$dex+$dexlite;
		
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$nopol</td>
				<td align='right'>".number_format($premium,2)."</td>
				<td align='right'>".number_format($solar,2)."</td>
				<td align='right'>".number_format($pertamax,2)."</td>			
				<td align='right'>".number_format($ptmplus,2)."</td>
				<td align='right'>".number_format($ptlite,2)."</td>
				<td align='right'>".number_format($dex,2)."</td>
				<td align='right'>".number_format($dexlite,2)."</td>
				<td align='right'>".number_format($jual,2)."</td>
				<td align='right'>".number_format($nilai,0)."</td>
			</tr>";
			$tpremium=$tpremium+$premium;
			$tsolar=$tsolar+$solar;
			$tpertamax=$tpertamax+$pertamax;
			$tptmplus=$ptmplus+$ptmplus;
			$tptlite=$tptlite+$ptlite;
			$tdex=$tdex+$dex;
			$tdexlite=$tdexlite+$dexlite;
			$tjual=$tjual+$jual;
			$tnilai=$tnilai+$nilai;
			$no++;
		}
	
		echo "<tr></tr>
		<tr>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tpremium,2)."</td>
			<td align='right'>".number_format($tsolar,2)."</td>
			<td align='right'>".number_format($tpertamax,2)."</td>			
			<td align='right'>".number_format($tptmplus,2)."</td>
			<td align='right'>".number_format($tptlite,2)."</td>
			<td align='right'>".number_format($tdex,2)."</td>
			<td align='right'>".number_format($tdexlite,2)."</td>
			<td align='right'>".number_format($tjual,2)."</td>
			<td align='right'>".number_format($tnilai,0)."</td>
		</tr>
	</table>";
?>
<script type="text/javascript">
	history.back();
</script>