<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/inventory/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){
				$("#txt_kodegr").val(data.kodegr);
				$("#txt_kodest").val(kode);
				$("#txt_namast").val(data.namast);
				$("#txt_satuan").val(data.satuan);
				$("#txt_kodesp").val(data.kodesp);
				$("#txt_namasp").val(data.namasp);
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_hgjual").val(data.hgjual);
				$("#txt_minstok").val(data.minstok);
				$('#form_cari_br').dialog('close');
			}
		});		
	}
	
	function hapus_data(ID){
		var pilih = confirm('Hapus data fasilitas kerja kode = '+ID+ '?');
		
		if (pilih==true) {
		var kode = ID;
		
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/hapus.php",
			data	: "kode="+kode,
			success	: function(data){				
				$("#info").html(data);
				tampil_data_detail();				
			}			
		});
		}
	}
	
	function tampil_data_detail(kode){
		var kode = $("#txt_kodegr").val();
		$("#data_detail").load('modul/inventory/tampil_data_detail.php?kode='+kode);
		
	}	
</script>

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

$kode	= $_GET[kode];
$cari	= $_GET[cari];

echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Beli</th>
			<th>Harga Jual</th>			
			<th>Aksi</th>
		</tr>";
		
		if (!empty($cari))
			$sql = "SELECT * FROM stock WHERE (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') ORDER BY kode_st";
		else{
			if (!empty($kode))
				$sql = "SELECT * FROM stock WHERE kode_gr='$kode' ORDER BY kode_st";
			else
				$sql = "SELECT * FROM stock ORDER BY kode_st";
		}
		$query 	  = mysql_query($sql);
		$jml_data = mysql_num_rows($query);
		
		while($r_data=mysql_fetch_array($query)){
			
			echo "<tr>
					<td>$r_data[kode_st]</td>
					<td>$r_data[nama_st]</td>
					<td>$r_data[satuan]</td>
					<td align='right'>".number_format($r_data[hg_beli],2)."</td>
					<td align='right'>".number_format($r_data[hg_jual],0)."</td>
					<td align='center'>
						<a href='javascript:void(0)' onClick=\"edit_data('$r_data[kode_st]')\">
							<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('$r_data[kode_st]')\">
							<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' >
						</a>
					</td>
				</tr>";
		}
		
	echo "</table>";
?>