<script type="text/javascript">
    $(function() {
        $("#theList tr:even").addClass("stripe1");
        $("#theList tr:odd").addClass("stripe2");

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });
</script>

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

	$tanggal= $_GET['tanggal'];
	$shift	= $_GET['shift'];

	$data	= mysql_query("SELECT * FROM setor_bbm WHERE tanggal='$tanggal' AND shift='$shift' AND batal='' GROUP BY jenis");
	$setor=0;	
	while($r_data=mysql_fetch_array($data)){
		$jenis=$r_data[jenis];
		
		echo "<li align='left'><b>$jenis</b></li>
			<table id='theList' width='100%'>
			<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>";
		
		$sql = mysql_query("SELECT kode_tl,teller_aw,teller_ak,sum(jml_keluar) as jkel,sum(jml_tera) as jtera,sum(jml_bon) as jbon,sum(jml_tunai) as jtunai,sum(nilai_tunai) as niltun FROM setor_bbm WHERE tanggal='$tanggal' AND shift='$shift' AND jenis='$jenis' AND batal='' GROUP BY kode_sb");
		
		$no=1;
		$tkeluar=0;
		$ttera=0;
		$tbon=0;
		$ttunai=0;
		$tniltun=0;
		
		while($r=mysql_fetch_array($sql)){
					
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_tl]</td>
				<td align='right'>".number_format($r[teller_aw],2)."</td>
				<td align='right'>".number_format($r[teller_ak],2)."</td>
				<td align='right'>".number_format($r[jkel],2)."</td>
				<td align='right'>".number_format($r[jtera],2)."</td>
				<td align='right'>".number_format($r[jbon],2)."</td>
				<td align='right'>".number_format($r[jtunai],2)."</td>
				<td align='right'>".number_format($r[niltun],2)."</td>
			</tr>";
			$no++;
			$tkeluar=$tkeluar+$r[jkel];
			$ttera=$ttera+$r[jtera];
			$tbon=$tbon+$r[jbon];
			$ttunai=$ttunai+$r[jtunai];
			$tniltun=$tniltun+$r[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 "<li align='left'><b>BON $jenis</b></li>
			<table id='theList' width='100%'>
			<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 shift='$shift' 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 align='right'>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td><b>Total Penjualan :</td>
			<td align='right'>".number_format($setor,2)."</b></td>
		</tr>
	</table>
	<br>";
		
	echo "<li align='left'><b>PENGELUARAN :</b></li>
		<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Keterangan</th>			
			<th>Jumlah</th>
		</tr>";
		
		$sql = mysql_query("SELECT * FROM jurkk WHERE tanggal='$tanggal' AND shift='$shift' 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>";
		
		echo "<table align='right'>
		<tr>
			<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>";

?>
