<?php
    include('config.php');
	$limit = 10;	
	$targetpage = "record_his.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



   
   
   
   	$query_string = " FROM poheader_outlet a, mst_outlet b WHERE 
					a.outlet_autoid = b.outlet_autoid AND (a.po_transno LIKE '%$q%' or b.outlet_name LIKE '%$q%') AND a.po_status <> 0";


   	$sum_sql = "SELECT COUNT(*) as num $query_string";
	$conn_sum_sql = $conn->query($sum_sql);
	$pagenum = $conn_sum_sql->fetch_assoc();
	$total_pages = $pagenum["num"];
   
  	include ("../../sys/paging.php");
 
   	$sql = "SELECT * $query_string ORDER BY po_transno DESC LIMIT $start,$limit";
	$sql_con = $conn->query($sql) or die($sql);

?>

<div class="rec_wrapper">
    <table class="table-striped table-hover table-bordered table table-condensed">
    <thead>
    	<tr class="bold">
     	<td style="width:130px">No Transaksi</td>
        <td style="width:100px;">Tanggal</td>
        <td class="tl" style="width:250px">Outlet</td>
        <td class="tl" style="width:250px">Catatan</td>
        <td class="tr" style="width:250px">Jumlah</td>
        <td class="tc">File</td>

        <td class="tc" style="width:100px">Status</td>
        <td class="tc" style="width:100px">Action</td>
        </tr>
        </thead>

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

			$img_url = $rs['po_img_src'];


			$id = $rs['po_autoid']	;
			if($rs['po_status']==1){$status = '<b class="text text-primary">Posted</b>';}
			if($rs['po_status']==99){$status = '<b class="text text-danger">Delete</b>';}
		?>
        <tr class="rec_body">
	   		<td><?php echo $rs['po_transno']?></td>
    	    <td><?php echo dtostr($rs['po_transdate'])?></td>
	        <td class="tl"><?php echo $rs['outlet_name']?></td>
            <td class="tl"><?php echo $rs['po_notes']?></td>
            <td class="tr"><?php echo number_format($rs['po_amount'])?></td>
            <td class="tc" style="width:100px"><a target="_blank" href="../../<?php echo $img_url?>" class="btn btn-success btn-sm">IMG</a></td>
            <td class="tc"><?php echo $status?></td>
            <td class="tc">
            	<a href="view?id=<?php echo $id?>"  data-toggle="tooltip" title="Edit Produk">
                <img src="../../image/view.png" title="View Purchase Order" class="icon"/></a>
            	<a href="unpost?id=<?php echo $id?>"  data-toggle="tooltip" title="Unpost PO">
                <img src="../../image/edit.png" title="Unpost Purchase Order" 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>No Records</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?> <?php echo $pageid?></td>
            </tr>
        </table>
    </div>
