<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];

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Harga Jual</th>
			<th>HB Rata-2</th>
			<th>HB Terakhir</th>
			<th>Jumlah Gd 1</th>
			<th>Jumlah Gd 2</th>
			<th>Jumlah Gd 3</th>			
			<th>Jumlah Stok</th>
			<th>Nilai Stok</th>
		</tr>";
			
		if (!empty($cari)){
			$sql	= "SELECT * FROM stock WHERE nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%' ORDER BY kode_st";
		}
		else{
			$sql	= "SELECT * FROM stock ORDER BY kode_st ";
		}
		$query = mysql_query($sql);
		
		$no=1;
		$tnilai=0;
		$tgd1=0;
		$tgd2=0;
		$tgd3=0;		
		$tstok=0;
		while($r_data=mysql_fetch_array($query)){
			$jmlstok=$r_data[jml_gd1]+$r_data[jml_gd2]+$r_data[jml_gd3];
			$nilai = $jmlstok*$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_jual],0)."</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='right'>".number_format($r_data[jml_gd1],2)."</td>
				<td align='right'>".number_format($r_data[jml_gd2],2)."</td>
				<td align='right'>".number_format($r_data[jml_gd3],2)."</td>				
				<td align='right'>".number_format($jmlstok,2)."</td>
				<td align='right'>".number_format($nilai,2)."</td>
			</tr>";
			$tgd1=$tgd1+$r_data[jml_gd1];
			$tgd2=$tgd2+$r_data[jml_gd2];
			$tgd3=$tgd3+$r_data[jml_gd3];			
			$tstok=$tstok+$jmlstok;
			$tnilai=$tnilai+$nilai;
			$no++;			
		}
		
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tgd1,2)."</td>
			<td align='right'>".number_format($tgd2,2)."</td>
			<td align='right'>".number_format($tgd3,2)."</td>			
			<td align='right'>".number_format($tstok,2)."</td>
			<td align='right'>".number_format($tnilai,2)."</td>
		</tr>
	</table>";
echo "</div>";
?>
