<?php 
$pagename = 'Orders'; 
require_once('./include/admin-load.php');
$orders = $order->all();
// Pagination
$currpage = (isset($_GET['page'])) ? $_GET['page'] : 1;
$maxres = 50;
$num = count($orders);
$pages = $num / $maxres;
$pages = ceil($pages);
$start = ( $currpage - 1 ) * $maxres ;
$last = $start + $maxres -1;
////////////////
require_once('./header.php');

?>
<a href="orders-new.php" class="btn btn-primary">New Orders</a>&nbsp;<a href="orders-monthly.php" class="btn btn-primary">Monthly Orders</a>&nbsp;<a href="create-invoice.php" class="btn btn-primary">Create Invoices</a><hr>
<?php if($num == 0){
?>
<h2 align='center'>No Orders Yet.</h2>
<?php
}else{?>
<div class="pagination-centered pagination"><ul>
<?php 
$i='';
$count= 1;
echo "<li><a href=\"orders.php?page=1\">First</a></li>";
for($i = 1 ; $i<=$pages ; $i++){
if(($currpage - $i) <=3  && ($count <= 7)){

echo "<li><a href=\"orders.php?page=" . $i . "\">" . $i . "</a></li>";
$count = $count+1 ;
}
elseif($currpage==$i){
echo "<li><a href=\"orders.php?page=" . $i . "\">" . $i . "</a></li>";
$count = $count+ 1;

}
}
echo "<li><a href=\"orders.php?page=" . $pages . "\">Last</a></li>";
?>
</ul>
</div>
<table class="table table-hover">
<thead>
<tr>
<th>Date</th>
<th>Order ID</th>
<th>Amount</th>
<th>Gateway</th>
<th>Payment Status</th>
<th>Order Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php for($i = $start; $i <= $last; $i++) {
if (isset($orders[$i])){
switch ($orders[$i]['payment']){
	case '1':
	$payment = 'Completed';
	break;
	case '2':
	$payment = 'Pending';
	break;
	case '3':
	$payment = 'Failed';
	break;
	case '4':
	$payment = 'Refunded';
	break;
	default:
	$role = 'Unknown';	
}
switch ($orders[$i]['status']){
	case '1':
	$status = 'Completed';
	break;
	case '2':
	$status = 'Pending';
	break;
	case '3':
	$status = 'Cancelled';
	break;
	case '4':
	$status = 'Shipped';
	break;
	case '5':
	$status = 'Delivered';
	break;
	case '6':
	$status = 'Returned';
	break;
	default:
	$status = 'Unknown';
}

	?>
<tr<?php if($orders[$i]['seen']=='no'){ echo " class='info'";}?>>
<td><?php echo $orders[$i]['date']; ?></td>
<td><?php echo $orders[$i]['id']; ?></td>
<td><?php echo $setting['currency_symbol'] . " " . number_format(($orders[$i]['amount'] - $orders[$i]['discount'] + $orders[$i]['tax']), 2, '.', '') ; ?></td>
<td><?php echo $orders[$i]['gateway']; ?></td>
<td><?php echo $payment; ?></td>
<td><?php echo $status; ?></td>
<td><a href="order-details.php?id=<?php echo $orders[$i]['id']; ?>">View / Edit</a></td>
</tr>
<?php }
}?></tbody>

</table>

<form action="order-details.php" method="get" class="form-inline">
<label for="order-input">Get Order Details</label>&nbsp;
<input type="text" name="id" placeholder="Order ID" required>&nbsp;
<button class="btn">Show Details</button>
</form>
<?php
}
require_once('./footer.php');

?>