<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");
            }
        );
    });
});

	function batal_bbm(ID){
		var kode = ID;	
		$.ajax({
			type	: "POST",
			url		: "modul/setor_bbm/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#t_kodesbbt").val(kode);
				$("#t_tanggalbt").val(data.tgl);
				$("#t_shiftbt").val(data.shift);
				$("#t_kodetlbt").val(data.kodetl);
				$("#t_jenisbt").val(data.jenis);
				$("#t_tankibt").val(data.tanki);
				$("#t_petugasbt").val(data.petugas);
				$("#t_tellerawbt").val(data.telleraw);
				$("#t_tellerakbt").val(data.tellerak);
				$("#t_jmlkeluarbt").val(data.jmlkeluar);
				$("#t_jmlterabt").val(data.jmltera);
				$("#t_jmlbonbt").val(data.jmlbon);
				$("#t_jmltunaibt").val(data.jmltunai);
				$("#t_niltunaibt").val(data.niltunai);
				$("#t_hpptunaibt").val(data.hpptunai);
				$("#pencarian_bt").hide();
				$("#tampil_data_bt").hide();
				$("#info_batal").show();
				$("#tampil_detail_bt").show();
				$("#tampil_detail_bt").load('modul/setor_bbm/tampil_data_bon.php?kode='+kode);
			}
		});		
	}
</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 Setoran</th>
			<th>Tanggal</th>
			<th>Shift</th>
			<th>No. Teller</th>
			<th>Jenis BBM</th>
			<th>Petugas</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>Setor Tunai</th>
			<th>Batal</th>
		</tr>";
		
		if(!empty($cari))
			$sql = "SELECT kode_sb,tanggal,shift,kode_tl,jenis,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 BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' AND (jenis LIKE '%$cari%') GROUP BY kode_sb ";
		else
			$sql = "SELECT kode_sb,tanggal,shift,kode_tl,jenis,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 BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_sb ";
		$query = mysql_query($sql);
		
		$no=1;
		$ttunai=0;		
		while($r=mysql_fetch_array($query)){
			$ttunai = $ttunai+$r[niltun];
			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_sb]</td>
				<td>".jin_date_str($r[tanggal])."</td>
				<td align='center'>$r[shift]</td>
				<td align='center'>$r[kode_tl]</td>
				<td>$r[jenis]</td>
				<td>$r[petugas]</td>
				<td align='right'>$r[teller_aw]</td>
				<td align='right'>$r[teller_ak]</td>
				<td align='right'>".number_format($r[keluar],2)."</td>
				<td align='right'>".number_format($r[tera],2)."</td>
				<td align='right'>".number_format($r[bon],2)."</td>
				<td align='right'>".number_format($r[tunai],2)."</td>				
				<td align='right'>".number_format($r[niltun])."</td>
				<td align='center'>
				<a href='javascript:void(0)' onClick=\"batal_bbm('$r[kode_sb]')\">
					<img src='icon/thumb_down.png' border='0' id='batal' title='Batal' width='12' height='12' >
				</a>
				</td>
			</tr>";
			$no++;
		}
		echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<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($ttunai)."</td>
			</tr>";
	echo "</table>";
?>