<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;
						
		$.ajax({
			type	: "POST",
			url		: "modul/returbeli/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_nourut").val(data.nourut);
				$("#txt_kodest").val(data.kodest);
				$("#txt_namast").val(data.namast);
				$("#txt_satuan").val(data.satuan);
				$("#txt_jmlkirim").val(data.jmlkirim);
				$("#txt_jmlretur").val(data.jmlretur);
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_jumlah").val(data.jumlah);
				$("#txt_ket").val(data.ket);
			}
		});
	}

	function hapus_data(ID){
		var pilih = confirm('Data yang akan dihapus kode = '+ID+ '?');
		if (pilih==true) {
		var kode = ID;
		$.ajax({
			type	: "POST",
			url		: "modul/returbeli/hapus.php",
			data	: "kode="+kode,
			success	: function(data){
				$("#info").html(data);
				cari_nourut();
				tampil_data_detail();
			}
		});
		}
	}
	
	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 tampil_data_detail(){
		var kode = $("#txt_kode").val();
		$("#data_detail").show();
		$("#data_detail").load("modul/returbeli/tampil_data_detail.php?kode="+kode);
	}
	
</script>
<?php
include '../../inc/inc.koneksi.php';
$kode	= $_GET['kode'];
echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Jml.Retur</th>
			<th>HB. Asal</th>
			<th>HB. Retur</th>
			<th>Nilai Retur</th>
			<th>Nilai Asal</th>
			<th>Rugi Retur</th>
			<th>Keterangan</th>
			<th>Aksi</th>
		</tr>";						
		$query = mysql_query("SELECT * FROM retur_pb WHERE kode_rb='$kode' ORDER BY no_urut");		
		
		$no=1;
		$total=0;$tasal=0;$trugiret=0;
		while($r=mysql_fetch_array($query)){
			$kode 	= $r['kode_rb'].';'.$r['no_urut'];
			$rugiret= $r['jumlah_asal']-$r['jumlah'];
			$total	= $total+$r['jumlah'];
			$tasal  = $tasal+$r['jumlah_asal'];
			$trugiret= $trugiret+$rugiret;
			
			echo "<tr>
				<td align='center'>$no</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[satuan]</td>
				<td align='center'>".number_format($r['jml_retur'],2)."</td>
				<td align='right'>".number_format($r['hb_asal'],2)."</td>
				<td align='right'>".number_format($r['hg_beli'],2)."</td>
				<td align='right'>".number_format($r['jumlah'],2)."</td>
				<td align='right'>".number_format($r['jumlah_asal'],2)."</td>
				<td align='right'>".number_format($rugiret,2)."</td>
				<td>$r[keterangan]</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></td>
		<td></td>
		<td align='right'>Total</td>
		<td align='right'>".number_format($total,2)."</td>			
		<td align='right'>".number_format($tasal,2)."</td>			
		<td align='right'>".number_format($trugiret,2)."</td>			
	</tr>
</table>";
?>