<?php
include("../include/session.php");
if(!$session->isRadstoneStoreUser() && !$session->isAdmin() && !$session->isRadstoneReceptionUser()){
	header("Location: ../Store/storeMenu.php");
}else{
	
	include("../storeHeader.php");
//	include("../include/db.php");
	

    require_once('classes/tc_calendar.php');
	$date = mysql_real_escape_string($_GET['date']);
	
		
	
    $category = mysql_real_escape_string($_GET['category']);
	$availableQuery = "SELECT DISTINCT date FROM nam_rad_stock_count WHERE category = '$category' ORDER BY date DESC LIMIT 25";
	$arrId = array();
	$arrName = array();
	$availableResult = execsql($availableQuery);
	$availableNum = mysql_num_rows($availableResult);
	$start = mysql_result($availableResult, 0, "date");
	$a = 0;
	while($a < $availableNum) {
		$arrId[$a] = mysql_result($availableResult, $a, "date");
		$arrName[$a] = date("d-m-Y", strtotime(mysql_result($availableResult, $a, "date") )) ;
		$a++;
	}
	
	if ($date==1) {
	$start = mysql_real_escape_string($_GET['dateSelect']);
    }
	
		   
	$selectQuery = "SELECT * FROM nam_rad_stock_count  WHERE category = '".$category."' AND date = '".$start."' ";
	$selectResult = execsql($selectQuery);
	$selectNum = mysql_num_rows($selectResult);
		
   
	?>
<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../css/tablesort.js"></script>
<link href="../css/main.css" rel="stylesheet" type="text/css" />

 
<div class="pageheading">
	Stock Count
	</div>
<table id="tableMain" width="595"> <!--begin of tableMain-->
    <tr>
      <td valign="top" >
	<p class="main">
	<label class="std"><b><font size="3"><font size="3"><font size="3"><font size="3"><font size="3"><font size="3"><font size="3"><font size="3"><?php echo $category ?></font></font></font></font></font></font></font></font></label>
	</p>
    <p class="main">
      <input name="button" type="button" class="linkbutton" id="button" onclick="MM_goToURL('parent','showAllProducts.php?cat=Tiles and Accessories&productSelect=All&colorSelect=All');return document.MM_returnValue" value="Stock Item List" />
      <label class="std">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stock counts for:</label>
      <input name="button3" type="button" class="linkbutton" id="button3" onclick="MM_goToURL('parent','countStockReport.php?date=0&category=Tiles and Accessories');return document.MM_returnValue" value="Tiles &amp; Acc" />
      <input name="button2" type="button" class="linkbutton" id="button2" onclick="MM_goToURL('parent','countStockReport.php?date=0&category=Direct Materials');return document.MM_returnValue" value="Direct Materials" />
      <input name="button4" type="button" class="linkbutton" id="button4" onclick="MM_goToURL('parent','countStockReport.php?date=0&category=Store Item');return document.MM_returnValue" value="Store Items" />
    </p>
    <br />
<br />
<br /><br />
<div id="coloredContainer">
  <form action="countStockReport.php" method="get" name="dateform" class="today" id="dateform">
    <label class="std">available stock counts:</label>
&nbsp;<span class="wizard">
<select name="dateSelect" class="wizard3" id="dateSelect">
  <option value="<?php echo $start ?>" selected="selected"><?php echo  date("d-m-Y", strtotime($start)) ?></option>
  <?php
			for ($i = 0 ; $i < count($arrId) ; $i++) {
				echo "<option value=". "\"". $arrId[$i]. "\"" .">" . $arrName[$i] . "</option>";
			}

			?>
</select>
</span><span class="main">
<input name="button5" type="submit" class="linkbutton" id="button5"  value="Select" />
</span>
<input name="category" type="hidden" id="category " value="<?php echo $category ?> " />
  <input name="date" type="hidden" id="date" value="1" />
  </form></div><br />

<table width="578" class="sortable-onload-0 rowstyle-alt no-arrow " id="tableList"  >
  <thead>
    <tr>
      <th width="58" class="sortable-text">Date</th>
      <th width="139" class="sortable-text">Product</th>
      <th width="121" class="sortable-text">Catogory</th>
      <th width="70" class="sortable-text">stock</th>
      <th width="55" class="sortable-numeric">count</th>
      <th width="55" >dif</th>
      <th width="48" >%</th>
      <!--        <th>Reserved Stock</th>-->
    </tr>
  </thead>
  <tbody>
    <?php
  $i=0;
  while ($i < $selectNum) {
	         $b0 = mysql_result($selectResult, $i, "date"); 
			 $b1a = mysql_result($selectResult, $i, "productId");
			 
			    $productQuery = "SELECT productName FROM nam_products WHERE productId = '".$b1a."'";
	            $productResult = execsql($productQuery);
	            $b1 = mysql_result($productResult, 0, "productName");
				
			    
	         $b2 = mysql_result($selectResult, $i, "category");
			 $b3 = mysql_result($selectResult, $i, "old_stock");
			 $b4 = mysql_result($selectResult, $i, "new_stock"); 
			 $b5 = $b4-$b3;
			 if ($b4<>0) { 
			 $b6 = ($b5/$b4)*100;
			 }
			 else {
				 $b6=100;
			 }
  
  ?>
    <tr>
      <td><?php echo date("d-m-Y", strtotime($b0))?>  </td>
      <td><?php echo $b1 ?></td>
      <td><?php echo $b2 ?></td>
      <td align="right"><?php echo $b3  ?></td>
      <td align="right"><?php echo $b4  ?></td>
      <td align="right"><?php if ($b5<0) { ?> <font color="#FF0000"> <?php } ?>  <?php echo $b5 ?></td>
      <td align="right"><?php  echo number_format($b6 , 2, '.', ', ') ?></td>
    </tr>
    <?php
  $i++;
  }
  ?>
  </tbody>
</table>
<p><br />
	  <br />
	  <br />
	  <br />
	  <br />
	  <br />
	  <br />
	  <br />
	  <br />
      <br />
      
	 
    </p>
    </td>
</tr>
</table><!--end of tableMain-->
<?php 
include("../footer.php");
}
?>
	