<?php
    include('config.php');

	$limit = 10;	
	$targetpage = "record.php"; 	//your file name  (the name of this file)
	$page = $_POST['page'];
	if($page) 
		$start = ($page - 1) * $limit; 			//first item to display on this page
	else
		$start = 0;								//if no page var is given, set start to 0

	if($f1=="X"){$f1_filter = " AND a.outlet_id = '0'";}
	else{
		$f1_filter = " AND a.outlet_id = '$f1'";
		}

	if($f2){$f2_filter = " AND b.pc_autoid = '$f2'";}

	$q_filter = " WHERE a.pm_autoid = b.pm_autoid AND (a.pm_name LIKE '%$q%' or a.pm_code LIKE '%$q%')  $f1_filter $f2_filter";
   

   $total_pages = 0;
   	$sum_sql = "SELECT COUNT(*) as num FROM invlog a, mst_product b  $q_filter  GROUP BY a.pm_name, a.outlet_id ";				
	$conn_sum_sql = $conn->query($sum_sql) or die($sum_sql);
	while($pagenum = $conn_sum_sql->fetch_assoc()){
	$total_pages = $total_pages + 1;
	}


   


   	$sql = "SELECT * FROM invlog a , mst_product b $q_filter 
			GROUP BY a.pm_autoid,  a.outlet_id 
			ORDER BY a.pm_name LIMIT $start,$limit";
	$sql_con = $conn->query($sql) or die($sql);

   	include ("../../sys/paging.php");

?>

<div class="rec_wrapper">
    <table class="table-striped table-hover table-bordered table table-condensed">
    <thead>
    	<tr class="bold">
            <td style="width:320px;">Nama Produk</td>
            <td class="tc" style="width:100px;">Stok Qty</td>
            <td class="tc" style="width:100px">Outlet</td>
            <td class="tc" style="width:70px;">Action</td>
        </tr>
        </thead>

		<tbody>
        <?php
		$i = 0;
			while($rs = $sql_con->fetch_assoc()){

			$id = $rs['pm_autoid']	;
			$pm_autoid = $rs['pm_autoid'];
			$stok_qty = get_stok_info($pm_autoid,$rs['outlet_id'],$conn);
			$whs = $rs['outlet_id'];
			
			
		?>
        <tr class="rec_body">
            <td><?php echo $rs['pm_name']?></td>
            <td class="tr">
				<?php echo number_format($stok_qty,2)?> Kg
                </td>
                <td class="tc"><?php echo $_outlet_name[$whs]?></td>
            <td class="tc">
            	<a href="view?id=<?php echo $id?>&outlet_id=<?php echo $rs['outlet_id']?>"  data-toggle="tooltip">
                <img src="../../image/view.png" title="Lihat Stok Produk" class="icon"/></a>

            </td>         
        </tr>
	<?php 
	$i = $i + 1;
	} 
	if($i==0){
		?>
        <tr class="rec_body">
        	<td colspan="10" style="height:400px;" class="tc"><h4>Belum Ada Data Stok</h4></td>       
        </tr>
	<?php	} ?>
	</tbody>
    </table>
    </div>
    <div class="record_footer">
            <table class="tbl">
        	<tr class="pad5">
            	<td colspan="5" class="tl pad5" style="border:none"><?php echo $pagination?></td>
                <td colspan="4" class="tr pad5 bold" style="border:none;color:#333">Jumlah <?php echo $total_pages?> Item</td>
            </tr>
        </table>
    </div>
