<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';
include '../../inc/fungsi_tanggal.php';

session_start();

$cari	= $_GET['cari'];
$kodegr	= $_GET['kodegr'];
$kodecab= $_SESSION['kodecab'];
$tgllap	= date('Y-m-d');

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Kode</th>
			<th>Nama Barang</th>
			<th>Barcode</th>
			<th>Supplier</th>
			<th>Satuan</th>
			<th>HJ. Umum</th>
			<th>HJ. Resep</th>
			<th>HJ. Grosir</th>
			<th>Stok Toko</th>
			<th>Stok Gudang</th>
		</tr>";

		if(!empty($cari))
			$sql= "SELECT * FROM stock WHERE (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%' OR barcode LIKE '%$cari%') AND kode_cab='$kodecab' ORDER BY kode_st";
		else{
		    if(!empty($kodegr))
			    $sql="SELECT * FROM stock WHERE kode_gr='$kodegr' AND kode_cab='$kodecab' ORDER BY kode_st";
		    else
		        $sql= "SELECT * FROM stock WHERE kode_cab='$kodecab' ORDER BY kode_st";
		}
		$query=mysql_query($sql);
			
		$no=1;
		while($r=mysql_fetch_array($query)){
		    $kodest=$r['kode_st'];
		    
		    if($kodecab=='01') $jmlstokb=$r['jml_stokb'];
		    else{
		        $sql1=mysql_query("SELECT * FROM stock WHERE kode_st='$kodest' AND kode_cab='01'");
		        $r1=mysql_fetch_assoc($sql1);
		        $jmlstokb=$r1['jml_stokb'];
		    }
		    
			echo "<tr>
				<td>$no</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[barcode]</td>
				<td>$r[nama_sp]</td>
				<td>$r[satuan]</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['jml_stok'],0)."</td>
				<td align='right'>".number_format($jmlstokb,0)."</td>
			</tr>";
			$no++;
		}
	echo "</table>";

echo "</div>";
?>