<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() {ale
                $(this).toggleClass("highlight");
            }
        );
    });	
});
		
	function hapus_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_jmlstok").val(data.jmlstok);
				var jmlstok = $("#txt_jmlstok").val();
			
				if(jmlstok=='') var jmlstok=0;
				else var jmlstok=parseFloat(jmlstok);
			
				if(!(jmlstok==0)){
					alert('Maaf, jumlah stok masih '+jmlstok+', data barang tidak dapat dihapus.');
					return(false);
				}else hapus_databr();
			}
		});
	}

	function hapus_databr(){
		var kode = $("#txt_kodest").val();
		
		var pilih = confirm('Hapus data barang kode '+kode+' ?');
		
		if (pilih==true) {
		$.ajax({
			type	: "POST",
			url	    : "modul/inventory/hapus.php",
			data	: "kode="+kode,
			success	: function(data){				
				$("#info").html(data);
				$("#form_cari_br").dialog('close');
				tampil_data_detail();
			}			
		});
		}
	}
	
	function tampil_data_detail(kode){
		var kode = $("#txt_kodegr").val();
		var cari = $("#txt_caribr").val();
		$("#data_detail").load('modul/inventory/tampil_data_detail.php?kode='+kode+'&cari='+cari);
	}
</script>

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

$cari= $_GET['cari'];

echo "cari $cari
<table id='theList' class='detail' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Beli</th>
			<th>Harga Jual</th>
			<th>Jumlah Stok</th>
			<th>Hapus</th>
		</tr>";
		if(!empty($cari))
			$sql= "SELECT * FROM stock WHERE (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') group by kode_st";
		else
			$sql= "SELECT * FROM stock WHERE 1 GROUP BY kode_st";
		$query = mysql_query($sql);
		$no=1;
		
		while($r=mysql_fetch_array($query)){
			echo "<tr>
				<td>$no</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[satuan]</td>
				<td align='right'>".number_format($r['hg_beli'],2)."</td>
				<td align='right'>".number_format($r['hg_jual'],0)."</td>
				<td align='right'>".number_format($r['jml_stokb'],0)."</td>
				<td align='center'>
					<a href='javascript:void(0)' onClick=\"hapus_data('$r[kode_st]')\">
						<img src='icon/thumb_down.png' border='0' id='hapus' title='Hapus' width='12' height='12' >
					</a>
				</td>					
			</tr>";
			$no++;
		}
	echo "</table>";	
?>