<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 edit_data(ID){
		var kode = ID;
						
		$.ajax({
			type	: "POST",
			url		: "modul/inventory/edit.php",
			data	: "kode="+kode,
			dataType: "json",
			success	: function(data){				
				$("#txt_kodest").val(kode);
				$("#txt_kodegr").val(data.kodegr);
				$("#txt_namast").val(data.namast);
				$("#t_namast").val(data.namast);
				$("#txt_barcode").val(data.barcode);
				$("#txt_satuan").val(data.satuan);
				$("#txt_ungros").val(data.ungros);
				$("#t_ungros").val(data.tungros);
				$("#txt_ungros1").val(data.ungros1);
				$("#t_ungros1").val(data.tungros1);
				$("#txt_ungros2").val(data.ungros2);
				$("#t_ungros2").val(data.ungros2);
				$("#txt_hggros1").val(data.hggros1);
				$("#t_hggros1").val(data.hggros1);
				$("#txt_hggros2").val(data.hggros2);
				$("#txt_hggros3").val(data.hggros3);
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_hgjual").val(data.hgjual);
				$("#t_hgjual").val(data.hgjual);
				$("#txt_discmom").val(data.discmom);
				$("#txt_tgldisc1").val(data.tgldisc1);
				$("#txt_tgldisc2").val(data.tgldisc2);
				$("#form_cari_br").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['jml_stok']+$r['jml_stokb']+$r['jml_stokc']+$r['jml_stokd']+$r['jml_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=\"edit_data('$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>";	
?>