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

$page_name = "Stores-main";
include ("../navigation/access.php");

if ($permission_num==1) {

include ("../navigation/store_sidebar.php");

include('../include/period_select_date.php');

$table_name2 = $_SESSION['db_prefix']."_order_return";
$deliver_query = "SELECT order_return_no, order_no, cust_id, return_date FROM $table_name2 WHERE  return_date BETWEEN '".$start."' AND '".$end."'  ORDER BY return_date DESC ";

$deliver_result = mySQL_query($deliver_query);
$deliver_num = mysql_num_rows($deliver_result);	

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

       
</head>

<body>

<div class="main_frame">
 
  <div class="page_head_frame">
    <label class="label_page_head">Returned tiles & accessories</label>
  </div>

<div class="page_middle_frame">   

<script type="text/javascript" language="javascript" src="../jscript/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#scroll_table').dataTable( {
					"sScrollY": "400px",
					"bPaginate": false,
					"bScrollCollapse": true,
					"aaSorting": [[ 1, "desc" ]],
					"aoColumns": [
								{"iDataSort": 1},
								{"bVisible": false},
								{"iDataSort": 5},
								{"bSortable": true},
								{"bSortable": true},
								{"bVisible": false}
							 ]
				} );
			} );
		</script>
       
        
<?php
$page='tile_delivered_list.php';
$reference_name='';
$reference='';
$reference_name_2='';
$reference_2='';
include('../include/period_select_block_2.php');
?>

<div class="page_inside_frame">            
          <table width="681" id="scroll_table" class="data_display" >
            <thead>
            <tr>
              <th align="center" >Return<br />no</th>
              <th align="center" >&nbsp;</th>
              <th >Return date</th>
              <th >Order no</th>
              <th >Customer</th>
              <th width="32">&nbsp;</th>
              </tr>
            </thead>
            <?php 
$i=0;

$a7tot=0;
$price=0;
$all_total = 0;
while ($i<$deliver_num) {
	$a1 = mysql_result($deliver_result, $i, "order_return_no");
		
	     $a2 = mysql_result($deliver_result, $i, "cust_id");
	     $table_name3 = $_SESSION['db_prefix']."_customer";
         $customer_query = "SELECT comp_name, status, bag_box, box_no, postal_place, phone, contact_1 FROM $table_name3 WHERE cust_id = '".$a2."' ";
		 $customer_result = mySQL_query($customer_query);
		 $customer_num = mysql_num_rows($customer_result);
		 if ($customer_num!=0) {
         $a2a = mysql_result($customer_result, 0, "comp_name");
		 $a2b = mysql_result($customer_result, 0, "bag_box");
		 $a2c = mysql_result($customer_result, 0, "box_no");
		 $a2d = mysql_result($customer_result, 0, "postal_place");
		 $a2e = mysql_result($customer_result, 0, "phone");
		 $a2f = mysql_result($customer_result, 0, "contact_1");
		 $a3 = mysql_result($customer_result, 0, "status");
		 
		 }
	
	$a4 = mysql_result($deliver_result, $i, "order_no");
	$a5 = mysql_result($deliver_result, $i, "return_date");
	//$a6 = mysql_result($deliver_result, $i, "delivery_address");
	$a6 = '';
		
	
	$table_name = $_SESSION['db_prefix']."_order_return_lines";
	$line_query = "SELECT  store_item_id, quantity  FROM $table_name WHERE order_return_no = '".$a1."' ";
	$line_result = mySQL_query($line_query);
	$line_num = mysql_num_rows($line_result);
	
	
	$l=0;
	$total=0;
	$line_text="";
	$products=mysql_result($line_result, 0, "store_item_id");
		
	while($l<$line_num) {
		$store_item_id = mysql_result($line_result, $l, "store_item_id");
		$quantity = mysql_result($line_result, $l, "quantity");
		
				
		$table_name = $_SESSION['db_prefix']."_store_items";
		$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
		$name_result = mySQL_query($name_query);
		$store_item_name = mysql_result($name_result, 0, "item_name");
				
					  
	   	$line_text = $line_text."<tr><td>".$store_item_name."</td><td>".$quantity."</td></tr>";
	   $l++;
	}
	
	
	$table_name = $_SESSION['db_prefix']."_order_lines";
	$order_query = "SELECT store_item_id, quantity FROM $table_name WHERE order_no = '".$a4."' ";
	$order_result = mySQL_query($order_query);
	$order_num = mysql_num_rows($order_result);
	$k=0;
	$order_total=0;
	$order_all_total=0;
	$order_line_text="";
	while ($k<$order_num) {
	$store_item_id = mysql_result($order_result, $k, "store_item_id");
			$table_name = $_SESSION['db_prefix']."_store_items";
			$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
			$name_result = mySQL_query($name_query);
			$store_item_name = mysql_result($name_result, 0, "item_name");
			$sub_total =  $quantity * $price;
			$total = $total + $sub_total;
	$order_quantity = mysql_result($order_result, $k, "quantity");
	$order_line_text = $order_line_text."<tr><td>".$store_item_name."</td><td>".$order_quantity."</td></tr>";
		
	$k++;
	}
	$orderTT ="<table id=table_tool_tip width=250 ><tr><td>Item</td><td>Quantity</td></tr>".$order_line_text."<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table><br><b>Click for details</b>";
	
	$customerTT ="<table id=table_tool_tip width=250 ><tr><td  width=75>Company:</td><td width=175>".$a2a."</td></tr><tr><td>Address:</td><td>".$a2b."&nbsp;".$a2c."<br>".$a2d."</td></tr><tr><td>Phone:</td><td>".$a2e."</td></tr><tr><td>Contact:</td><td>".$a2f."</td></tr></table><br><b>Click for details</b>";
	
	$table_name = $_SESSION['db_prefix']."_order_return_lines";
	$return_query = "SELECT store_item_id, quantity FROM $table_name WHERE order_return_no = '".$a1."' ";
	$return_result = mySQL_query($return_query);
	$return_num = mysql_num_rows($return_result);
	$m=0;
	$return_total=0;
	$return_all_total=0;
	$return_line_text="";
	while ($m<$return_num) {
	$store_item_id = mysql_result($return_result, $m, "store_item_id");
			$table_name = $_SESSION['db_prefix']."_store_items";
			$name_query = "SELECT item_name FROM $table_name WHERE store_item_id = '".$store_item_id."'  ";
			$name_result = mySQL_query($name_query);
			$store_item_name = mysql_result($name_result, 0, "item_name");
			$sub_total =  $quantity * $price;
			$total = $total + $sub_total;
	$return_quantity = mysql_result($return_result, $m, "quantity");
	$return_line_text = $return_line_text."<tr><td>".$store_item_name."</td><td>".$return_quantity."</td></tr>";
	$m++;
	}	
	
	$returnTT ="<table id=table_tool_tip width=250 ><tr><td>Item</td><td>Quantity</td></tr>".$return_line_text."<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table><br><b>Click for details</b>";
	
	
	?>
            <tr>               
              <td width="56"align="left"  style="padding-left:0px;"><a href="order_return.php?order_return_no=<?php echo $a1 ?> " onmouseover="ddrivetip('<?php echo $returnTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a1 ?></a></td>
              <td width="20"align="left"  style="padding-left:0px;"><?php echo $a4 ?></td>
              <td width="123" align="left"><?php echo date("d-m-Y", strtotime($a5))?></td>
              <td width="76" align="left"><a href="order.php?order_no=<?php echo $a4 ?>" onmouseover="ddrivetip('<?php echo $orderTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a4 ?></a></td>
              <td width="346" align="left"><a href="account_details.php?cust_id=<?php echo $a2 ?>" onmouseover="ddrivetip('<?php echo $customerTT?>', 250)"; onmouseout="hideddrivetip()"><?php echo $a2a ?></a></td>
              <td align="left"><?php echo $a5 ?></td>
            </tr>
            <?php
  $i++;
}
?>
            <tfoot>
            </tfoot>
          </table>
 
 </div>
</div>

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

