<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 pilih(ID){
		var kode = ID;
						
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){				
				$("#i_kodest").val(kode);
				$("#i_kodegr").val(data.kodegr);
				$("#i_namast").val(data.namast);
				$("#t_namast").val(data.namast);
				$("#i_barcode").val(data.barcode);
				$("#i_satuan").val(data.satuan);
				$("#i_ungros").val(data.ungros);
				$("#t_ungros").val(data.tungros);
				$("#i_ungros1").val(data.ungros1);
				$("#t_ungros1").val(data.tungros1);
				$("#i_ungros2").val(data.ungros2);
				$("#t_ungros2").val(data.ungros2);
				$("#i_hggros1").val(data.hggros1);
				$("#t_hggros1").val(data.hggros1);
				$("#i_hggros2").val(data.hggros2);
				$("#i_hggros3").val(data.hggros3);
				$("#i_hgbeli").val(data.hgbeli);
				$("#i_hgjual").val(data.hgjual);
				$("#t_hgjual").val(data.hgjual);
				$("#form_i_cari_barang").dialog('close');
				cari_grup();
			}			
		});
	}
	
	function cari_grup(){
		var kode 	= $("#txt_kodegr").val();
				
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/cari_grup.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){				
				$("#txt_namagr").val(data.namagr);
				$("#txt_hgjual").focus();
			}
		});
	}
</script>

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

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

echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Barcode</th>
			<th>Satuan</th>
			<th>Harga Beli</th>
			<th>Harga Jual</th>
			<th>Jml. Stok</th>
			<th>Aksi</th>
		</tr>";
		
		if(!$cari=='')
			$query = mysql_query("SELECT * FROM stock WHERE kode_gr='$kodegr' AND (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%' OR barcode like '$cari') ORDER by kode_st");
		else
			$query = mysql_query("SELECT * FROM stock WHERE kode_gr='$kodegr' ORDER by kode_st");
		$no=1;
		
		while($r=mysql_fetch_array($query)){
			$jmlstok=$r['jmi_stok']+$r['jmi_stokb']+$r['jmi_stokc']+$r['jmi_stokd']+$r['jmi_stoke'];
			
			echo "<tr>
				<td>$no</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[barcode]</td>
				<td>$r[satuan]</td>
				<td align='right'>".number_format($r['hg_beli'],0)."</td>
				<td align='right'>".number_format($r['hg_jual'],0)."</td>
				<td align='right'>".number_format($jmlstok,2)."</td>
				<td align='center'>						
					<a href='javascript:void(0)' onClick=\"pilih('$r[kode_st]')\">
						<img src='icon/thumb_up.png' border='0' id='edit' title='Edit' width='12' height='12' >
					</a>
				</td>					
			</tr>";
			$no++;
		}
	echo "</table>";	
?>