<script type="text/javascript">
$(document).ready(function() {
    $(function() {
        $("#theList.barang tr:even").addClass("stripe1");
        $("#theList.barang tr:odd").addClass("stripe2");

        $("#theList.barang tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });	
});

	function pilih(ID){
		var kode = ID;
        var tgljualaw = $("#op_tgljualaw").val();
        var tgljualak = $("#op_tgljualak").val();
		$.ajax({
			type	: "POST",
			url		: "spv/order_pb/cari_barang.php",
			data	: "kode="+kode+
			        "&tgljualaw="+tgljualaw+
			        "&tgljualak="+tgljualak,
			dataType: "json",
			success	: function(data){
				$("#op_kodest").val(kode);
				$("#op_namast").val(data.namast);
				$("#op_jmljual").val(data.jmljual);
				$("#op_jmlstok").val(data.jmlstok);
				$("#op_satuan").val(data.satuan);
				$("#op_harga").val(data.harga);
				$("#form_cari_brg").dialog('close');
				$("#op_zataktif").focus();
			}
		});
	}
</script>
<?php
include '../../inc/inc.koneksi.php';

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

echo "<table id='theList' class='barang' width='100%'>
	<tr>
		<th>No.</th>
		<th>Kode Barang</th>
		<th>Nama Barang</th>
		<th>Barcode</th>
		<th>Satuan</th>		
		<th>HB. Terakhir</th>
		<th>Total Stok</th>
		<th>Ambil</th>
	</tr>";
	if(!empty($cari))
		$sql = "SELECT kode_st,nama_st,barcode,satuan,hb_akhir,sum(jml_stok) as jstok,sum(jml_stokb) as jstokb FROM stock WHERE (kode_st LIKE '%$cari%' OR nama_st LIKE '%$cari%') GROUP BY kode_st";
	else
		$sql = "SELECT kode_st,nama_st,barcode,satuan,hb_akhir,sum(jml_stok) as jstok,sum(jml_stokb) as jstokb FROM stock WHERE 1 GROUP BY kode_st";
	$query = mysql_query($sql);
	
	$no=1;
	while($r=mysql_fetch_array($query)){
		$stok=$r['jstok']+$r['jstokb'];
		
		echo "<tr>
			<td align='center'>$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['hb_akhir'],0)."</td>
			<td align='right'>$stok</td>
			<td align='center'>
				<a href='javascript:void(0)' onClick=\"pilih('$r[kode_st]')\">
					<img src='icon/download.gif' border='0' id='tambah_data' title='Tambah' width='12' height='12'>
				</a>
			</td>
		</tr>";
		$no++;			
	}
echo "</table>";
?>