<script type="text/javascript">
$(document).ready(function() {
    $(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';

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

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode Plg</th>
			<th>Nama Pelanggan</th>
			<th>No.Polisi</th>
			<th>Jenis BBM</th>			
			<th>Jumlah Liter</th>
			<th>Nominal</th>
		</tr>";
		
		if(!empty($cari))
			$sql1 = "SELECT kode_sb,tanggal,shift,kode_pl,nama_pl FROM setor_bbm WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND !(kode_pl='') AND batal='' AND (kode_pl LIKE '%$cari%' OR nama_pl LIKE '%$cari%') GROUP BY kode_sb ";
		else
			$sql1 = "SELECT kode_sb,tanggal,shift,kode_pl,nama_pl FROM setor_bbm WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND !(kode_pl='') AND batal='' GROUP BY kode_sb ";
		$query1 = mysql_query($sql1);
		
		$jml=0;
		$tbon=0;
		$tliter=0;
		while($r1=mysql_fetch_array($query1)){
			$kodesb=$r1[kode_sb];
			
			echo "<tr>
				<td></td>
				<td><b>Tanggal :</b></td>
				<td><b>".jin_date_str($r1[tanggal])."</b></td>
				<td><b>No.Bukti :</b></td>
				<td><b>$r1[kode_sb]</b></td>
				<td align='center'><b>Shift : $r1[shift]</b></td>
			</tr>";
			
			if(!empty($cari))
				$sql = "SELECT * FROM setor_bbm WHERE kode_sb='$kodesb' AND batal='' AND (kode_pl LIKE '%$cari%' OR nama_pl LIKE '%$cari%') ORDER BY id_bon ";
			else
				$sql = "SELECT * FROM setor_bbm WHERE kode_sb='$kodesb' AND batal='' ORDER BY id_bon ";
			$query = mysql_query($sql);
			
			$no=1;
			$sbon=0;
			$sliter=0;
			while($r_data=mysql_fetch_array($query)){
				$sbon = $sbon+$r_data[nilai_nopol];
				$sliter = $sliter+$r_data[jml_nopol];
				
				echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r_data[kode_pl]</td>
					<td>$r_data[nama_pl]</td>
					<td>$r_data[nopol]</td>
					<td>$r_data[jenis]</td>																				
					<td align='right'>$r_data[jml_nopol]</td>
					<td align='right'>".number_format($r_data[nilai_nopol])."</td>
				</tr>";
				$no++;
			}
			$tbon = $tbon+$sbon;
			$tliter= $tliter+$sliter;
			
			echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($sliter,2)."</td>
				<td align='right'>".number_format($sbon)."</td>
			</tr>";
		}
		
		echo "<tr>																
			<td></td>
			<td></td>
			<td></td>
			<td></td>			
			<td align='right'>Total</td>
			<td align='right'>".number_format($sliter,2)."</td>
			<td align='right'>".number_format($tbon)."</td>	
		</tr>";
	echo "</table>";
?>