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

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });
});
</script>

<?php
include '../../inc/inc.koneksi.php';
$cari	= $_GET[cari];
$pilih  = $_GET[pilih];
$kodesp = $_GET[kodesp];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>HB Rata-2</th>
			<th>HB Terakhir</th>
			<th>Supplier</th>
			<th>Nama Supplier</th>
			<th>Harga Jual</th>
			<th>Stok Min.</th>
			<th>Jumlah Stok</th>
			<th>Nilai Stok</th>
		</tr>";
			
		if (!empty($cari)){
			if(!($kodesp=='')){
				if($pilih=='STOK MINIMAL')
					$sql	= "SELECT * FROM stock WHERE (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') AND kode_sp='$kodesp' AND jml_stok<(min_stok+1) ORDER BY kode_st";
				else
					$sql	= "SELECT * FROM stock WHERE (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') AND kode_sp='$kodesp' ORDER BY kode_st";
			}else{
				if($pilih=='STOK MINIMAL')
					$sql	= "SELECT * FROM stock WHERE (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') AND jml_stok<(min_stok+1) ORDER BY kode_st";
				else
					$sql	= "SELECT * FROM stock WHERE (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') ORDER BY kode_st";
			}
		}else{
			if(!($kodesp=='')){
				if($pilih=='STOK MINIMAL')
					$sql	= "SELECT * FROM stock WHERE kode_sp='$kodesp' AND jml_stok<(min_stok+1) ORDER BY kode_st";
				else
					$sql	= "SELECT * FROM stock WHERE kode_sp='$kodesp' ORDER BY kode_st";
			}else{
				if($pilih=='STOK MINIMAL')
					$sql	= "SELECT * FROM stock WHERE jml_stok<(min_stok+1) ORDER BY kode_st";
				else
					$sql	= "SELECT * FROM stock ORDER BY kode_st";
			}
		}
		$query = mysql_query($sql);
		
		$no=1;
		$tnilai=0;
		while($r_data=mysql_fetch_array($query)){
			$nilai = $r_data[jml_stok]*$r_data[hg_beli];
			
			echo "<tr>
				<td>$no</td>
				<td>$r_data[kode_st]</td>
				<td>$r_data[nama_st]</td>
				<td>$r_data[satuan]</td>
				<td align='right'>".number_format($r_data[hg_beli],2)."</td>
				<td align='right'>".number_format($r_data[hb_akhir],2)."</td>
				<td align='center'>$r_data[kode_sp]</td>
				<td>$r_data[nama_sp]</td>
				<td align='right'>".number_format($r_data[hg_jual],0)."</td>
				<td align='right'>$r_data[min_stok]</td>
				<td align='right'>".number_format($r_data[jml_stok],2)."</td>
				<td align='right'>".number_format($nilai,2)."</td>
			</tr>";
			$tnilai=$tnilai+$nilai;
			$no++;			
		}
		
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tnilai,0)."</td>
		</tr>";

	echo "</table>";
echo "</div>";
?>