<?php
$title='Order Status';
require_once('header.inc.php');
require_once('nav.inc.php');
if(isset($_REQUEST['id'])){
	if(!empty($_REQUEST['id'])){
		$details = $order->details($_REQUEST['id']);
	}else{
		echo "Order  doesn't exists";
	}
	}else{
		$details = false ;
	}
	?>
	 <div class="page-header">
	<h2>Order Status</h2>
</div>
<?php 
if(!$details){?>
<form action="order-status.php" method="post" id="form-order-details">Get Order Details:<br><div class="input-append">

<input type="text" name="id" placeholder="Order ID" id="order-input">
<button class="btn btn-primary" type="submit" name="submit">Show Details</button></div>
</form>
<?php
if($order->msg){
	echo $order->msg;
	}
	if($order->error){
	echo $order->error;
	}
} else {
switch ($details['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 ($details['status']){
	case '1':
	$status = 'Approved';
	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';
}
$details['coupon'] = !empty($details['coupon']) ? $details['coupon']: 'None';
 ?>
<h3>Order ID: <?php echo $_REQUEST['id']; ?></h3>
<table class="table table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Discount Coupon</th>
<th>Net Amount (<?php echo $setting['currency_symbol'];?>)</th>
<th>Gateway</th>
<th>Payment Status</th>
<th>Order Status</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $details['date']; ?></td>
<td><?php echo $setting['currency_symbol'] ." ". $details['discount'] . " (" .$details['coupon'] . " )"; ?></td>
<td><?php echo $details['amount'] - $details['discount']; ?> + <?php echo $details['tax']; ?> (Tax) = <b><?php echo$details['amount'] - $details['discount']+ $details['tax'] ; ?></b></td>
<td><?php echo $details['gateway'];?></td>
<td><?php echo $payment; ?></td>
<td><?php echo $status; ?></td>
</tr>
</tbody>
</table>
<h3>Items</h3>
<table class="table table-bordered ">
<thead>
<tr>
<th>Sr no.</th>
<th>Product Name</th>
<th>Options</th>
<th>Price (<?php echo $setting['currency_symbol'] ;?>)</th>
<th>Quantity</th>
<th>Total Price (<?php echo $setting['currency_symbol'] ;?>)</th>
</tr>
</thead>
<tbody><?php 
$products = json_decode($details['items'],true);
$i = 0;
foreach($products as $pro){
	$i = $i + 1;
	if($pro['shipping'] == 0){$append = "";}else{$append = " + ".$pro['shipping']." *";}
	if(empty($pro['opt_name'])){
	$pro['opt_name'] = "None";
	}
?>
<tr>
<td><?php echo $i;?></td>
<td><span class="symbiotic-img" data-size="small"><?php echo $pro['id']; ?></span> <?php echo $pro['name'] ; ?></td>
<td><?php echo $pro['opt_name']; ?></td>
<td><?php echo number_format($pro['price'], 2, '.', '')  .$append ; ?></td>
<td><?php echo $pro['count']   ; ?></td>
<td><?php echo number_format(($pro['price'] + $pro['shipping']) * $pro['count'], 2, '.', '') ;?></td>
</tr>
<?php } ?>
</tbody>
</table>
<h3>Shipping Details</h3>
<?php if(!empty($details['track'])){
if(empty($details['track_url'])){$details['track_url'] ="#";} 
echo "Track id:".$details['track'] ." <a href=\"".$details['track_url'] ."\">Click here to track</a>";
 } else {
echo 'No details available yet. Come back later';
}?>
<h3>Order Remarks</h3>
<?php if(!empty($details['remarks'])){
echo $details['remarks'];
}else{
echo 'No details available yet. Come back later';
} 
 }  ?>
<?php
require_once('footer.inc.php');
?>