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

        $("#theList.detail tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function edit_data(ID){
		var kode = ID;
		var sisabon = $("#txt_sisabon").val();
						
		$.ajax({
			type	: "POST",
			url		: "modul/setor_bbm/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_idbon").val(data.idbon);
				$("#txt_kodepl").val(data.kodepl);
				$("#txt_namapl").val(data.namapl);
				$("#txt_nopol").val(data.nopol);
				$("#txt_jmlnopol").val(data.jmlnopol);
				$("#txt_nilainopol").val(data.nilainopol);
				$("#txt_tanggaljt").val(data.tanggaljt);
				
				var jmlnopol = $("#txt_jmlnopol").val();
				var sisbon=parseFloat(sisabon)+parseFloat(jmlnopol);
				var sisbon=sisbon.toFixed(2);
				$("#txt_sisabon").val(sisbon);
				$("#txt_sibon").val(sisbon);
				$("#txt_jmlnopol").focus();
			}
		});		
	}

	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
			var kode = ID;
			var sisabon = $("#txt_sisabon").val();
			var jmlnopol = $("#txt_jmlnopol").val();
			
			$.ajax({
				type	: "POST",
				url		: "modul/setor_bbm/hapus.php",
				data	: "kode="+kode,
				dataType: "json",
				success	: function(data){
					$("#info").html(data);
					$("#txt_sisabon").val(sisbon);
					$("#txt_sibon").val(sisbon);
					$("#txt_namapl").focus();
					$("#txt_jmlnopol").val(data.jmlnopol);
					
					var jmlnopol = $("#txt_jmlnopol").val();
					var sisbon=parseFloat(sisabon)+parseFloat(jmlnopol);
					var sisbon=sisbon.toFixed(2);
					$("#txt_sisabon").val(sisbon);
					$("#txt_sibon").val(sisbon);
					$("#txt_jmlnopol").val('');
					tampil_data_detail();
				}
			});
		}
	}
	
	function tampil_data_detail(){
		var	kode=$("#txt_kode").val();
		$("#tampil_data_bon").load("modul/setor_bbm/tampil_data_detail.php?kode="+kode);
	}
</script>

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

$kode	= $_GET[kode];
echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Pelanggan</th>
			<th>Nomor Polisi</th>
			<th>Jumlah Liter</th>
			<th>Nilai Bon</th>			
			<th>Aksi</th>
		</tr>";
		$sql = "SELECT * FROM setor_bbm WHERE kode_sb='$kode' AND batal='' ORDER BY kode_sb";
						
		$query = mysql_query($sql);
		$no=1;
		$total=0;
		while($r_data=mysql_fetch_array($query)){
			$kode = $r_data[kode_sb].'-'.$r_data[id_bon];
			$total	= $total+$r_data[nilai_nopol];
			echo "<tr>
					<td align='center'>$no</td>
					<td>$r_data[kode_pl]</td>
					<td>$r_data[nama_pl]</td>
					<td>$r_data[nopol]</td>
					<td align='center'>".number_format($r_data[jml_nopol],2)."</td>
					<td align='right'>".number_format($r_data[nilai_nopol],0)."</td>					
					<td align='center'>
						<a href='javascript:void(0)' onClick=\"edit_data('$kode')\">
						<img src='icon/thumb_up.png' border='0' id='edit' title='Edit' width='12' height='12' ></a>					
						<a href='javascript:void(0)' onClick=\"hapus_data('$kode')\">
						<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' ></a>					
					</td>
				</tr>";
			$no++;			
		}
		echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Total </td>
				<td align='right'>".number_format($total,0)."</td>
			</tr>";
			
	echo "</table>";	
?>