<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 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,
			dataType: "json",
			success	: function(data){
				$("#t_kodest").val(kode);
				$("#t_namast").val(data.namast);
				$("#t_jmlstok").val(data.jmlstok);
				$("#t_satuan").val(data.tsatuan);
				$("#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+'&tglawal='+tglawal+'&tglakhir='+tglakhir);				
			}
		});		
	}
</script>

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

$cari= $_GET[cari];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Jumlah Stok</th>
			<th>Satuan</th>
			<th>Pilih</th>
		</tr>";
		
		if (!empty($cari)){
			$sql = "SELECT * FROM stock WHERE nama_st LIKE '%$cari%' or kode_st LIKE '%$cari%' ORDER BY kode_st";
		}
		else{
			$sql = "SELECT * FROM stock ORDER BY kode_st";
		}
		$query = mysql_query($sql);
			
		$no=1;
		while($r_data=mysql_fetch_array($query)){			
			echo "<tr>
				<td>$no</td>
				<td>$r_data[kode_st]</td>
				<td>$r_data[nama_st]</td>
				<td align='right'>".number_format($r_data[jml_stok],2)."</td>
				<td>$r_data[satuan]</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"pilih('$r_data[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>";
?>
