<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;
		var gudang = $("#txt_gudang").val();
		
		$.ajax({
			type	: "POST",
			url		: "spv/st_opname/cari_barang.php",
			data	: "kode="+kode+
				"&gudang="+gudang,
			dataType: "json",
			success	: function(data){
				$("#txt_kodest").val(kode);
				$("#txt_namast").val(data.namast);
				$("#txt_satuan").val(data.tsatuan);				
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_jmlstok").val(data.jmlstok);
				$("#form_cari_barang").dialog('close');
				$("#txt_jmlopn").focus();
			}
		});
	}

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

$cari= $_GET['cari'];
$gudang=$_GET['gudang'];

echo "<table id='theList' class='barang' width='100%'>
	<tr>
		<th>No.</th>
		<th>Kode Barang</th>
		<th>Nama Barang</th>
		<th>Satuan</th>
		<th>Harga Pokok</th>
		<th>Jml. Stok</th>
		<th>Ambil</th>
	</tr>";
	if (!empty($cari))
		$sql = "SELECT * FROM stock WHERE kode_st LIKE '%$cari%' OR nama_st LIKE '%$cari%' ORDER BY kode_st";
	else
		$sql = "SELECT * FROM stock ORDER BY kode_st";
		
	$query = mysql_query($sql);
	$jml_data = mysql_num_rows($query);
	$no=1;
	while($r_data=mysql_fetch_array($query)){
		if($gudang=='1')
			$jmlstok=$r_data[jml_gd1];
		else if($gudang=='2')
			$jmlstok=$r_data[jml_gd2];
		else
			$jmlstok=$r_data[jml_gd3];
		
		echo "<tr>
				<td align='center'>$no</td>
				<td>$r_data[kode_st]</td>
				<td>$r_data[nama_st]</td>
				<td>$r_data[satuan]</td>
				<td>$r_data[hg_beli]</td>
				<td align='right'>$jmlstok</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r_data[kode_st]')\">
					<img src='icon/download.gif' border='0' id='tambah_data' title='Tambah' width='12' height='12' >
				</a>					
				</td>
				</tr>";
		$no++;			
	}
		
echo "</table>";
?>