<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include ("../navigation/header.php");


$order_return_no = $_GET['order_return_no'];
$table_name = $_SESSION['db_prefix']."_order_return";
$additional_query = "SELECT order_no, order_reference  FROM $table_name WHERE order_return_no = '".$order_return_no."' ";
$additional_result = $con->query($additional_query);
$row = mysqli_fetch_assoc($additional_result);
$order_no = $row["order_no"];
$order_reference = $row["order_reference"];

//$quote='no';
$table_name = $_SESSION['db_prefix']."_orders";
$order_query = "SELECT * FROM $table_name WHERE order_reference = '".$order_reference."' ";
$order_result = $con->query($order_query);
$row = mysqli_fetch_assoc($order_result);
$cust_id = $row["cust_id"];

$table_name2 = $_SESSION['db_prefix']."_customer";
		$customer_query = "SELECT * FROM $table_name2 WHERE cust_id ='".$cust_id."' ";
		$customer_result = $con->query($customer_query);
		$row = mysqli_fetch_assoc($customer_result);
		$a1 = $row["account_type"];
		$name = $row["comp_name"];
			
			
$table_name = $_SESSION['db_prefix']."_order_return";
$return_id_query = "SELECT order_return_id,  order_no, return_date, returned_to FROM $table_name WHERE  order_return_no = '".$order_return_no."' ";
$return_id_result = $con->query($return_id_query);
$row = mysqli_fetch_assoc($return_id_result);
$order_return_id = $row["order_return_id"];
$return_date = $row["return_date"];
$forman_name = 	$row["returned_to"];		
			
$table_name = $_SESSION['db_prefix']."_order_return_lines";
$item_query = "SELECT product_item_id, item_name, quantity, stock_return FROM $table_name WHERE  order_return_no = '".$order_return_no."' ";
$item_result = $con->query($item_query);


?>

<!--style sheets-->
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../css/tooltip.css" />

<!--jscript-->
<script type="text/javascript" src="../jscript/tablesort.js"></script>
<script language="JavaScript" src="../jscript/tooltip.js"  type="text/javascript"></script> 

</head>
<body>
<?php
$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
?>
<div class="main_frame" style="height:auto;">
 <div class="page_head_frame">
     <table width="700" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="472"><label class="label_page_head">Return from order no.:</label>
              &nbsp;&nbsp;&nbsp;<label class="label_page_head_2"><?php echo $order_no ?>&nbsp;&nbsp;&nbsp; <?php echo $name ?></label></td>
            
            </tr>
        </table>
      </div>
 <div class="page_middle_frame">
 
<div class="page_inside_frame"> 
<?php 
		include ('../include/customer_block.php');
?>
</div>

<div class="page_inside_frame">
<table width="650" id="table_details_display">
  <tr>
    <td width="97">Return no:</td>
    <td width="157"><?php echo $order_return_no ?></td>
    <td width="156">&nbsp;</td>
    <td width="170">&nbsp;</td>
  </tr>
  <tr>
    <td>Return  date:</td>
    <td><?php echo date("d-m-Y", strtotime($return_date)) ?></td>
    <td>Received by :</td>
    <td><?php echo $forman_name ?></td>
  </tr>
</table>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;
<table width="650" id="table_details_display">
  <tr>
    <td width="448">Item</td>
    <td width="89" align="center">Returned</td>
    <td width="92" align="center">To recycle</td>
  </tr>
  <?php
  $i=0;
  while($row = $item_result->fetch_assoc()) {
	 $product_item_id = $row["product_item_id"];
	 $spec_name = $row["item_name"];
	 $delivered =  $row["quantity"];
	 $stock_return =  $row["stock_return"];
		
	       		$table_name = $_SESSION['db_prefix']."_product_store";
				$name_query = "SELECT item_name FROM $table_name WHERE product_item_id = '".$product_item_id."'  ";
				$name_result = $con->query($name_query);
				$row = mysqli_fetch_assoc($name_result);
				$store_item_name = $row["item_name"];
				
	  
	  ?>
  <tr>
    <td><?php echo $store_item_name ?></td>
    <td align="center"><?php echo $delivered ?></td>
    <td align="center"><?php echo $stock_return ?>&nbsp;</td>
  </tr>
  <?php
  $i++;
  }
  ?>
</table>

</div>

<div class="page_inside_frame">
<a href="order_return_print.php?order_return_no=<?php echo $order_return_no  ?>" target="_blank"><input name="print_button" type="button" class="imagebutton" value="Print return sheet"></a>
</div>

</div>
</div>

<?php include ('../navigation/side_bar.php'); ?>

</body>
<?php } else {
$_SESSION['denied_return'] = "store/store_main.php";	
include ("../navigation/store_sidebar.php");?>
	<body onLoad="accessdenied(); return false">
	</body>
<?php }
?>
</html>