<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 pilih(ID){
		var kode = ID;
		var gudang  = $("#t_gudang").val();
		var tglawal = $("#ks_tglawal").val();
		var tglakhir= $("#ks_tglakhir").val();
				
		if(tglawal.length == 0){			
			alert("Maaf, Tanggal awal pencarian belum ditentukan.");
			$("#ks_tglawal").focus();
			return (false);
        }
		if(tglakhir.length == 0){
			alert("Maaf, Tanggal akhir pencarian belum ditentukan.");
			$("#ks_tglakhir").focus();
		    return (false);
        }
		 
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/cari_st.php",
			data	: "kode="+kode+
					"&gudang="+gudang,
			dataType: "json",
			success	: function(data){
				$("#t_kodest").val(kode);
				$("#t_namast").val(data.namast);
				$("#t_satuan").val(data.satuan);
				$("#pencarian_ks").hide();
				$("#tampil_data_ks").hide();
				$("#info_ks").show();
				$("#tampil_detail_ks").show();
				$("#tampil_detail_ks").load("modul/inventory/tampil_detail_ks.php?kode="+kode+'&gudang='+gudang+'&tglawal='+tglawal+'&tglakhir='+tglakhir);
			}
		});		
	}
</script>

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

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

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Barcode</th>
			<th>Jumlah Stok</th>
			<th>Satuan</th>
			<th>Pilih</th>
		</tr>";
		if(!empty($cari)){
		    if($gudang=='Gudang')
			    $sql= "SELECT * FROM stock WHERE kode_cab='01' AND (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') ORDER BY kode_st";
			else
			    $sql= "SELECT * FROM stock WHERE kode_cab='$gudang' AND (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') 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')
				$jmlstok=$r['jml_stokb'];
			else
				$jmlstok=$r['jml_stok'];
			
			echo "<tr>
				<td>$no</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[barcode]</td>
				<td align='right'>".number_format($jmlstok,0)."</td>
				<td>$r[satuan]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r[kode_st]')\">
					<img src='images/view.png' border='0' id='edit' title='Lihat Kartu Stok' width='18' height='18'></a>						
				</td>
			</tr>";
			$no++;
		}
	
	echo "</table>";
echo "</div>";
?>