<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 tampil_pb(ID){
		var kode = ID;	
		$.ajax({
			type	: "POST",
			url		: "modul/returbeli/cari_kode.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kode").val(kode);
				$("#txt_nomorfk").val(data.nomorfk);
				$("#txt_tanggal").val(data.tgl);
				$("#txt_kodesup").val(data.kodesup);
				$("#txt_namasup").val(data.namasup);
				$("#txt_tanggalfk").val(data.tanggalfk);
				$('#form_cari_koderb').dialog('close');
				$("#info_rpb").hide();
				$("#data_detail").show();
				$("#data_detail").load('modul/returbeli/tampil_data_detail.php?kode='+kode);
				$("#txt_caraby").focus();
				cari_nourut();
				hitung_total();
			}
		});		
	}
	
	function cari_nourut(){
		var kode = $("#txt_kode").val();
				
		$.ajax({
			type	: "POST",
			url		: "modul/returbeli/cari_nourut.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){				
				$("#txt_nourut").val(data.nourut);		
			}
		});
	}
	
	function hitung_total(){
		var kode= $("#txt_kode").val();
		
		$.ajax({
			type	: "POST",
			url		: "modul/returbeli/cari_total.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_total").val(data.total);				
			}
		});
	}
</script>

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

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode Retur</th>
			<th>Tanggal</th>
			<th>Nomor Faktur</th>
			<th>Supplier</th>
			<th>Total Item</th>
			<th>Total Unit</th>
			<th>Total Harga</th>
			<th>Lihat</th>
		</tr>";
		$query = mysql_query("SELECT kode_rb,tanggal,nama_sup,nomor_fk,count(kode_st) as titem,sum(jml_retur) as tretur,sum(jumlah) as tjumlah FROM retur_pb WHERE posting='' AND batal='' GROUP BY kode_rb");
		
		$no=1;
		while($r=mysql_fetch_array($query)){
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_rb]</td>
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td>$r[nomor_fk]</td>
				<td>$r[nama_sup]</td>
				<td align='center'>$r[titem]</td>
				<td align='right'>$r[tretur]</td>
				<td align='right'>$r[tjumlah]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"tampil_pb('$r[kode_rb]')\">
						<img src='images/view.png' border='0' id='edit' title='Lihat detail' width='12' height='12' >
					</a>
				</td>
			</tr>";
			$no++;			
		}
	echo "</table>";
?>