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

$cari	= $_GET['cari'];
$kodegr	= $_GET['kodegr'];
$kodecab= $_GET['kodecab'];
$status	= $_GET['status'];
$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>Satuan</th>
			<th>Min. Stok</th>
			<th>Jumlah Stok</th>
		</tr>";

		if(!empty($cari))
			$sql= "SELECT * FROM stock WHERE kode_cab='$kodecab' AND (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%' OR barcode LIKE '%$cari%') GROUP BY kode_st";
		else{
		    if(!($kodegr=='')){
			    if($status=='seluruh') $sql="SELECT * FROM stock WHERE kode_cab='$kodecab' AND kode_gr='$kodegr' GROUP BY kode_st";
			    else if($status=='ada') $sql="SELECT * FROM stock WHERE kode_cab='$kodecab' AND kode_gr='$kodegr' AND !(jml_stok=0) GROUP BY kode_st";
			    else if($status=='minimal') $sql= "SELECT * FROM stock WHERE kode_cab='$kodecab' AND kode_gr='$kodegr' AND jml_stok<=min_stok GROUP BY kode_st";
			    else if($status=='expired') $sql= "SELECT * FROM stock WHERE kode_cab='$kodecab' AND kode_gr='$kodegr' AND expired<='$tgllap' GROUP BY kode_st";
		    }
		    else{
		        if($status=='seluruh') $sql= "SELECT * FROM stock WHERE kode_cab='$kodecab' GROUP BY kode_st";
			    else if($status=='ada') $sql= "SELECT * FROM stock WHERE kode_cab='$kodecab' AND !(jml_stok=0) GROUP BY kode_st";
			    else if($status=='minimal') $sql= "SELECT * FROM stock WHERE kode_cab='$kodecab' AND jml_stok<=min_stok GROUP BY kode_st";
			    else if($status=='expired') $sql= "SELECT * FROM stock WHERE kode_cab='$kodecab' AND expired<='$tgllap' GROUP BY kode_st";
		    }
		}
		$query=mysql_query($sql);
			
		$no=1;
		while($r=mysql_fetch_array($query)){
			$nilai=$r['jml_stok']*$r['hg_beli'];
			
			echo "<tr>
				<td>$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['min_stok'],0)."</td>
				<td align='right'>".number_format($r['jml_stok'],0)."</td>
			</tr>";
			$no++;
		}
		echo "<tr></tr>
	</table>";

echo "</div>";
?>