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

<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';
	include '../../inc/fungsi_indotgl.php';
	
	$tanggal= $_GET['tanggal'];

	$sql=mysql_query("SELECT * FROM company");
	$r	=mysql_fetch_assoc($sql);	
	$kop1 = $r[nama1];
	$kop2 = $r[nama2];
	$kop3 = $r[alamat];
	
	echo "<table width='100%' style='font:11px arial><b>
		<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 HARIAN KAS</b></td>
		</tr>
		<tr>
			<td align='center' style='font:14px arial'><b>TANGGAL : ".tgl_indo($tanggal)."</b></td>
		</tr>
	</table>
	<br>";

	$data	= mysql_query("SELECT * FROM setor_bbm WHERE tanggal='$tanggal' AND batal='' GROUP BY jenis");
	$setor=0;	
	while($r_data=mysql_fetch_array($data)){
		$jenis=$r_data[jenis];
			
		echo "<table>
			<tr>
				<td style='font:11px arial'><b>$jenis</b></td>
			</tr>
		</table>
		
		<table width='700' border='1' style='font:11px arial;border-collapse:collapse'>
			<tr>
				<th>No.</th>
				<th>No. Teller</th>
				<th>Teller Awal</th>
				<th>Teller Akhir</th>
				<th>Liter Keluar</th>
				<th>Liter Tera</th>
				<th>Liter Bon</th>
				<th>Liter Tunai</th>
				<th>Rupiah Tunai</th>
			</tr>";
		
			$sql1 = mysql_query("SELECT kode_tl,teller_aw,teller_ak,sum(jml_keluar) as keluar,sum(jml_tera) as tera,sum(jml_bon) as bon,sum(jml_tunai) as tunai,sum(nilai_tunai) as niltun FROM setor_bbm WHERE tanggal='$tanggal' AND jenis='$jenis' AND batal='' GROUP BY kode_tl");
		
			$no=1;
			$tkeluar=0;
			$ttera=0;
			$tbon=0;
			$ttunai=0;
			$tniltun=0;
		
			while($r1=mysql_fetch_array($sql1)){
				$kodetl=$r1[kode_tl];
				$tellaw=$r1[teller_aw];
			
				$sql = mysql_query("SELECT kode_tl,teller_aw,teller_ak FROM setor_bbm WHERE tanggal='$tanggal' AND jenis='$jenis' AND kode_tl='$kodetl' AND batal='' ORDER BY kode_tl");
			
				$keluar=$r1[keluar];
				$tera  =$r1[tera];
				$bon   =$r1[bon];
				$tunai =$r1[tunai];
				$niltun=$r1[niltun];
			
				while($r=mysql_fetch_array($sql)){
					$tellak=$r[teller_ak];
				}
				echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$kodetl</td>
					<td align='right'>".number_format($tellaw,2)."</td>
					<td align='right'>".number_format($tellak,2)."</td>
					<td align='right'>".number_format($keluar,2)."</td>
					<td align='right'>".number_format($tera,2)."</td>
					<td align='right'>".number_format($bon,2)."</td>
					<td align='right'>".number_format($tunai,2)."</td>
					<td align='right'>".number_format($niltun,2)."</td>
				</tr>";
				$no++;
				$tkeluar=$tkeluar+$keluar;
				$ttera=$ttera+$tera;
				$tbon=$tbon+$bon;
				$ttunai=$ttunai+$tunai;
				$tniltun=$tniltun+$niltun;
			}
	
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tkeluar,2)."</td>
			<td align='right'>".number_format($ttera,2)."</td>
			<td align='right'>".number_format($tbon,2)."</td>
			<td align='right'>".number_format($ttunai,2)."</td>
			<td align='right'>".number_format($tniltun,2)."</td>
		</tr>
		</table>
		<br>";
		$setor=$setor+$tniltun;
		
		if($tbon>0){
			echo "<table>
				<tr>
					<td style='font:11px arial'><b>BON $jenis</b></td>
				</tr>
			</table>
			
			<table width='600' border='1' style='font:11px arial;border-collapse:collapse'>
				<tr>
					<th>No.</th>
					<th>Kode Plg</th>
					<th>Nama Pelanggan</th>
					<th>No.Polisi</th>
					<th>Jumlah Liter</th>
					<th>Jumlah Rupiah</th>				
				</tr>";
			
			$sql = mysql_query("SELECT kode_pl,nama_pl,nopol,jml_nopol,nilai_nopol FROM setor_bbm WHERE tanggal='$tanggal' AND jenis='$jenis' AND !(jml_nopol='0') AND batal='' ORDER BY kode_sb");
		
			$no=1;
			$tpol=0;			
			$tnilpol=0;
			while($r=mysql_fetch_array($sql)){
				echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r[kode_pl]</td>
					<td>$r[nama_pl]</td>
					<td>$r[nopol]</td>					
					<td align='right'>".number_format($r[jml_nopol],2)."</td>
					<td align='right'>".number_format($r[nilai_nopol],2)."</td>
				</tr>";
				$no++;
				$tpol=$tpol+$r[jml_nopol];
				$tnilpol=$tnilpol+$r[nilai_nopol];
			}
			echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total</td>
				<td align='right'>".number_format($tpol,2)."</td>			
				<td align='right'>".number_format($tnilpol,2)."</td>
			</tr>
			</table>
			<br>";
		}
	}
		
	echo "<table width='700' style='font:11px arial'>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'><b>Total Penjualan :</td>
			<td align='right'>".number_format($setor,2)."</b></td>
		</tr>
		</table>
		<br>";
		
	echo "<table>
			<tr>
				<td style='font:11px arial'><b>PENGELUARAN</b></td>
			</tr>
		</table>
		
		<table width='400' border='1' style='font:11px arial;border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Keterangan</th>			
			<th>Jumlah</th>				
		</tr>";
		
		$sql = mysql_query("SELECT * FROM jurkk WHERE tanggal='$tanggal' ORDER BY no_urut");
		
		$no=1;
		$tjumlah=0;
		while($r=mysql_fetch_array($sql)){
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[keterangan]</td>					
				<td align='right'>".number_format($r[jumlah],2)."</td>					
			</tr>";
			$no++;			
			$tjumlah=$tjumlah+$r[jumlah];
		}
		$setor=$setor-$tjumlah;
		
	echo "<tr>
			<td></td>			
			<td align='right'>Total</td>				
			<td align='right'>".number_format($tjumlah,2)."</td>
		</tr>
	</table>
	<br>
	
	<table width='700' style='font:11px arial'>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td><b>Jumlah Uang Disetor :</td>
			<td align='right'>".number_format($setor,2)."</b></td>
		</tr>
	</table>";
?>