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

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

	function pilih(ID){
		var kode = ID;
		
		$.ajax({
			type	: "POST",
			url		: "modul/brg_rusak/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);
				$("#txt_tanggal").val(data.tgl);
				$("#form_cari_kode").dialog('close');				
			}
		});
	}
</script>

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

echo "<table id='theList' class='barang' width='100%'>
	<tr>
		<th>Kode KB</th>
		<th>Tanggal</th>
		<th>Jumlah Item</th>
		<th>Jumlah Rusak</th>
		<th>Nilai Kerusakan</th>
		<th>Ambil</th>
	</tr>";
	
	$sql = "SELECT kode_kb,tanggal,count(kode_st) as item,sum(jml_unit) as tunit,sum(nilai_kr) as tnilai
			FROM jurkrsb WHERE posting='' GROUP BY kode_kb";
				
	$query = mysql_query($sql);
	$jml_data = mysql_num_rows($query);
	$no=1;
	while($r=mysql_fetch_array($query)){
		
		echo "<tr>
			<td>$r[kode_kb]</td>
			<td>$r[tanggal]</td>
			<td align='right'>".number_format($r['item'],0)."</td>
			<td align='right'>".number_format($r['tunit'],2)."</td>
			<td align='right'>".number_format($r['tnilai'],2)."</td>			
			<td align='center'>
				<a href='javascript:void(0)' onClick=\"pilih('$r[kode_kb]')\">
				<img src='icon/download.gif' border='0' id='tambah_data' title='Tambah' width='12' height='12' >
				</a>					
			</td>
		</tr>";
		$no++;			
	}
	echo "</table>";
?>