<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);
				$("#txt_barcode").val(data.barcode);
				$("#txt_satuan").val(data.satuan);
				$("#txt_hgresep").val(data.hgresep);
				$("#txt_hgparam").val(data.hgparam);
				$("#txt_hgbeli").val(data.hgbeli);
				$("#txt_hgjual").val(data.hgjual);
				$("#txt_minstok").val(data.minstok);
				$("#txt_kodesp").val(data.kodesp);
				$("#txt_namasp").val(data.namasp);
				$("#txt_kodesp1").val(data.kodesp1);
				$("#txt_namasp1").val(data.namasp1);
				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';

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

echo "<table id='theList' class='detail' width='100%'>
		<tr>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Barcode</th>
			<th>Satuan</th>
			<th>Harga Beli</th>
			<th>Jml. Stok</th>
			<th>HJ. Umum</th>
			<th>HJ. Resep</th>
			<th>HJ. Grosir</th>
			<th>Stok Min.Gd.</th>
			<th>Supplier 1</th>
			<th>Supplier 2</th>
			<th>Edit</th>
		</tr>";
		if (!empty($cari))
			$sql = "SELECT kode_st,nama_st,barcode,satuan,hg_beli,sum(jml_stok) as jstok,sum(jml_stokb) as jstokb,hg_jual,hg_resep,hg_param,min_stokb,nama_sp,nama_sp1 FROM stock WHERE (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%' OR barcode LIKE '%$cari%') AND kode_gr='$kode' GROUP BY kode_st";
		else
			$sql = "SELECT kode_st,nama_st,barcode,satuan,hg_beli,sum(jml_stok) as jstok,sum(jml_stokb) as jstokb,hg_jual,hg_resep,hg_param,min_stokb,nama_sp,nama_sp1 FROM stock WHERE kode_gr='$kode' GROUP BY kode_st";
		$query = mysql_query($sql);
		$jml_data=0;
		while($r=mysql_fetch_array($query)){
			$jmlstok=$r['jstok']+$r['jstokb'];
			
			echo "<tr>
				<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'],2)."</td>
				<td align='right'>".number_format($jmlstok,2)."</td>
				<td align='right'>".number_format($r['hg_jual'],0)."</td>
				<td align='right'>".number_format($r['hg_resep'],0)."</td>
				<td align='right'>".number_format($r['hg_param'],0)."</td>
				<td align='right'>".number_format($r['min_stokb'],0)."</td>
				<td>$r[kode_sp] - $r[nama_sp]</td>
				<td>$r[kode_sp1] - $r[nama_sp1]</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>";
			$jml_data++;
		}
	echo "</table>
	<table width='100%'>
		<tr>
			<td>Jumlah data : $jml_data</td>			
		</tr>
	</table>";
?>