
<?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']);
		
	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) );	 
		
	$displayQuery = "SELECT rad_returns.quantity, delivery.quantity,  rad_returns.reference, rad_returns.date, delivery.date  FROM rad_returns, delivery WHERE (rad_returns.productId='100292' OR delivery.productId='100292')  AND ( (rad_returns.date >= '$start' AND rad_returns.date <= '$end') ) " ;
	$displayResult = mySQL_query($displayQuery) or die ("Error in query:   $displayQuery . * ". mySQL_error());
	$i = 0;
	$displayNum = 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">Pallets in / out</div>

       
       <br />
<br />



       <br /><br />

<div id="coloredContainer">
  <form action="pallets_in_out.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" />
      
    </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">Delivered</th>
			<th width="86" class="sortable-text">Returned</th>
			<th width="45" class="sortable-text">Balance</th>
			<th width="176" class="sortable-text">returned by</th>
		</tr>
	</thead>
	<tbody>
	<?php 
	while ($i < $displayNum) {
	   $toolTipText="";
	   $toolTipText2="";
	   $b0 = mysql_result($displayResult, $i, "rad_returns.date");
	   //$b1a = mysql_result($displayResult, $i, "productId");
	     // $productNameQuery = "SELECT productName FROM products WHERE productId = $b1a ";
//	      $productNameResult = execsql($productNameQuery);
//		  $b1 = mysql_result($productNameResult, 0, "productName");
	  $b2 = mysql_result($displayResult, $i, "delivery.quantity");	  
	   if ($b2!='') {
	            $b2 = mysql_result($displayResult, $i, "delivery.quantity");	
	   			$b3 = "";
	   }
	   else {
	            $b2 = "";	
	   			$b3 = mysql_result($displayResult, $i, "rad_returns.quantity");
	   }
	   
	   $b4 = "";
	  $b5 = mysql_result($displayResult, $i, "rad_returns.reference");
		   
		   //$custNameQuery = "SELECT  CompanyName FROM customer WHERE custNo = $b5a ";
//		   $custNameResult = execsql($custNameQuery);
//		   $b5 = mysql_result($custNameResult, 0, "CompanyName");
//		   
//		   $b4 = mysql_result($displayResult, $i, "reference");
//		   $toolTipText = "returned on order: ".$b4;
		   
		
		  
		   
						
	     ?>
		<tr class=>
		  <td><?php echo date("d-m-Y", strtotime($b0)) ?></td>
		  <td>&nbsp;</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 echo $b5 ?>&nbsp;</td>
	    </tr>
		
	<?php 
	$i++;
	}
	?>
	</tbody>
</table>

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

?>
      
