<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList.barang tr:even").addClass("stripe2");
        $("#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();
		var tjumlah1	= $("#txt_tjumlah1").val();
				
		$.ajax({
			type	: "POST",
			url	    : "modul/ubah_status/cari_barang.php",
			data	: "kode="+kode+
					"&gudang="+gudang,
			dataType: "json",
			success	: function(data){
				$("#txt_kodest2").val(kode);
				$("#txt_namast2").val(data.namast);
				$("#txt_satuan2").val(data.satuan);
				$("#txt_hgbeli2").val(data.hgbeli);				
				var hgbeli2=$("#txt_hgbeli2").val();
				
				if(hgbeli2=='') $("#txt_jumlah2").val(tjumlah1);
				$("#form_cari_barang2").dialog('close');
				$("#txt_caribr2").val('');
				$("#txt_jmlunit2").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</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>HB. Rata-rata</th>
			<th>Jumlah Stok</th>
			<th>Ambil</th>
		</tr>";
		if(!empty($cari)){
		    if($gudang=='Gudang')
			    $sql = "SELECT * FROM stock WHERE (kode_st LIKE '%$cari%' OR nama_st LIKE '%$cari%') AND kode_cab='01' ORDER BY kode_st";
		    else
		        $sql = "SELECT * FROM stock WHERE (kode_st LIKE '%$cari%' OR nama_st LIKE '%$cari%') AND kode_cab='$gudang' ORDER BY kode_st";
		}
		else{
		    if($gudang=='Gudang')
		        $sql = "SELECT * FROM stock WHERE kode_cab='01' ORDER BY kode_st";
		    else
		        $sql = "SELECT * FROM stock WHERE kode_cab='$gudang' ORDER BY kode_st";
		}
		$query = mysql_query($sql);
		
		$no=1;
		while($r=mysql_fetch_array($query)){
			if($gudang=='Gudang') $jstok=$r['jml_stokb'];
			else $jstok=$r['jml_stok'];
			
			echo "<tr>
				<td>$no</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[satuan]</td>
				<td align='right'>".number_format($r['hg_beli'],2)."</td>
				<td align='right'>".number_format($jstok,0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r[kode_st]')\">
					<img src='icon/download.gif' border='0' id='tambah_data' title='Tambah' width='12' height='12'>
					</a>
				</td>
			</tr>";
			$no++;
		}
	echo "</table>";
?>