
<?php
include("../include/session.php");
if( !$session->isAdmin() && !$session->isRadstoneReceptionUser() && !$session->isRadstoneStoreUser() ){
	//header("Location: ../Store/storeMenu.php");?>
	<script language="javascript" type="text/javascript">
        <!--
		  window.location="denied.php";
        -->
       </script>
	   <?php 
}else{
	include("../storeHeader.php");
		//$message = mysql_real_escape_string($_GET['message']);
		
	require_once('classes/tc_calendar.php');
	$date = mysql_real_escape_string($_GET['date']);
	$category = mysql_real_escape_string($_GET['category']);
	
	if ($date==1) {
	$start = mysql_real_escape_string($_GET['date1']);
    $end = mysql_real_escape_string($_GET['date2']);
	}
	else {
	$start = date("Y-m-01");
	$end = date("Y-m-d");
	}
	
		
	if ($date!=1) {
	   $ds = "1"; }
	   else {
		$ds = date("d", strtotime($start) );
	   }
	$ms = date("m", strtotime($start) );
	$ys = date("Y", strtotime($start) );
	
	
	$de = date("d", strtotime($end) );
	$me = date("m", strtotime($end) );
	$ye = date("Y", strtotime($end) );	 
		
	if ($category=="") {
		$displayQuery = "SELECT DISTINCT * FROM nam_rad_returns WHERE  date >= '$start' AND date <= '$end' ORDER BY date DESC" ;
	}
	else {
	$displayQuery = "SELECT DISTINCT * FROM nam_rad_returns WHERE  category = '$category' AND date >= '$start' AND date <= '$end' ORDER BY date DESC" ;
	}
	$displayResult = mySQL_query($displayQuery) or die ("Error in query:   $Query . * ". mySQL_error());
	$i = 0;
	$num = mysql_num_rows($displayResult);
	
	//$custQuery = "SELECT CustNo, CompanyName FROM customer WHERE active=1 ORDER BY CompanyName ASC";
//	$custId = array();
//	$custName = array();
//	$custResult = execsql($custQuery);
//	$custNum = mysql_num_rows($custResult);
//	$p = 0;
//	while($p < $custNum){
//		$custId[$p] = mysql_result($custResult, $p, "CustNo");
//		$custName[$p] = mysql_result($custResult, $p, "CompanyName");
//		$p++;
//	}
	
	
?>
<link href="calendar.css" rel="stylesheet" type="text/css" />
<script	language="javascript" src="../include/calendar.js"></script>
<script type="text/javascript" src="../css/tablesort.js"></script>

<link href="../css/main.css" rel="stylesheet" type="text/css" />
	   <div class="headerbox2">Returns</div>

       <p class="main">
         <label class="std"><b><font size="3"><?php if ( $category=="") { echo "All items"; } else { echo $category; } ?></font></b></label>
       </p>
       <br />
<br />



       <br /><br />

<div id="coloredContainer">
  <form action="returnList.php" method="get" name="dateform" class="today" id="dateform">
    from:
    &nbsp;&nbsp;
    <?php
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($ds, $ms, $ys);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2000, 2030);
	 	$myCalendar->writeScript();?>
    &nbsp;&nbsp;to:&nbsp;&nbsp;
    <?php
		$myCalendar = new tc_calendar("date2", true);
		$myCalendar->setIcon("../img/iconCalendar.gif");
		$myCalendar->setDate($de, $me, $ye);
		$myCalendar->setPath("./");
		$myCalendar->setYearInterval(2000, 2030);
		$myCalendar->writeScript();?>
    &nbsp;&nbsp;
    <label>
      <input name="button5" type="submit" class="smalllinkbuttonblue"  id="button5" value="Select" />
      <input name="date" type="hidden" id="date" value="1" />
      <input name="category" type="hidden" id="category" value="<?php echo $category ?>" />
    </label>
    <br />
</form>
</div><br />

<table width="600" class="sortable-onload-0r rowstyle-alt no-arrow " id="tableList"  >
  <thead>
		<tr>
		    <th width="60" class="sortable-d-m-y">Date</th>
			<th width="155" class="sortable-text">Product</th>
			<th width="50" class="sortable-text">Qty</th>
			<th width="86" class="sortable-text">Ret to stock</th>
			<th width="45" class="sortable-text">Ref</th>
			<th width="176" class="sortable-text">returned by</th>
		</tr>
	</thead>
	<tbody>
	<?php 
	while ($i < $num) {
	   $toolTipText="";
	   $toolTipText2="";
	   $b0 = mysql_result($displayResult, $i, "date");
	   $b1a = mysql_result($displayResult, $i, "productId");
	      $productNameQuery = "SELECT productName FROM nam_products WHERE productId = $b1a ";
	      $productNameResult = execsql($productNameQuery);
		  $b1 = mysql_result($productNameResult, 0, "productName");
	   
	   $b2 = mysql_result($displayResult, $i, "quantity");	
	   $b3 = mysql_result($displayResult, $i, "ret_stock");
	   $b4 = "";
	   $b5 = "";
	   $b6 = mysql_result($displayResult, $i, "status"); 
	   if ($b6=="comp") { 
		   $b5a = mysql_result($displayResult, $i, "returned_by");
		   $custNameQuery = "SELECT  CompanyName FROM nam_customer WHERE custNo = $b5a ";
		   $custNameResult = execsql($custNameQuery);
		   $b5 = mysql_result($custNameResult, 0, "CompanyName");
		   
		   $b4 = mysql_result($displayResult, $i, "reference");
		   $toolTipText = "returned on order: ".$b4;
		   }
		if ($b6=="emp") { 
		   $b5a = mysql_result($displayResult, $i, "returned_by");
		   $empNameQuery = "SELECT  empFName, empLName FROM nam_employees WHERE empId = $b5a ";
		   $empNameResult = execsql($empNameQuery);
		   $empNameNum = mysql_num_rows($empNameResult);
		   if ($empNameNum==1) {
		   $b5 = mysql_result($empNameResult, 0, "empFName")." ".mysql_result($empNameResult, 0, "empLName");
		   $toolTipText2 = "returned by: ".$b5;
		   }
		   else {
		   $b5="";
		   }
		   }
		   if ($b6=="comp") { 
		   $b5a = mysql_result($displayResult, $i, "returned_by");
		   $custNameQuery = "SELECT  CompanyName FROM nam_customer WHERE CustNo = $b5a ";
		   $custNameResult = execsql($custNameQuery);
		   $custNameNum = mysql_num_rows($custNameResult);
		   if ($custNameNum==1) {
		   $b5 = mysql_result($custNameResult, 0, "CompanyName");
		   $toolTipText2 = "returned by: ".$b5;
		   }
		   else {
		   $b5="";
		   }
		   }
		   
						
	     ?>
		<tr class=>
		  <td><?php echo date("d-m-Y", strtotime($b0)) ?></td>
		  <td><?php echo $b1 ?></td>
		  <td><?php echo $b2 ?></td>
		  <td><?php echo $b3 ?></td>
		  <td><a href="displayOrder.php?OrderNoText=<?php echo $b4 ?>" onmouseover="ddrivetip('<?php echo $toolTipText ?>','', 150)" onmouseout="hideddrivetip()";><?php echo $b4 ?></a></td>
          <td><?php if ($b6=="emp") { ?><a href="../HR/searchAndDisplayE.php?empId=<?php echo $b5a ?>" onmouseover="ddrivetip('<?php echo $toolTipText2 ?>','', 150)" onmouseout="hideddrivetip()";><?php echo $b5 ?></a><?php } ?>
          <?php if ($b6=="comp") { ?><a href="displayCustomer.php?CustNo=<?php echo $b5a ?>" onmouseover="ddrivetip('<?php echo $toolTipText2 ?>','', 150)" onmouseout="hideddrivetip()";><?php echo $b5 ?></a><?php } ?></td>
	    </tr>
		
	<?php 
	$i++;
	}
	?>
	</tbody>
</table>

  
	  
	    <?php
	}
	include("../footer.php");

?>
      
