<?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']);
	
	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) );	
	

    $productId = mysql_real_escape_string($_GET['productId']);
	$productQuery = "SELECT productName FROM products WHERE productId = ".$productId;
	$productResult = execsql($productQuery);
	$productName = mysql_result($productResult, 0, "productName");
	
	   
	$selectQuery = "SELECT productId, client, SUM(quantity) AS summedQuantity FROM sales  WHERE productId ='".$productId."' AND date > '".$start."' AND date <= '".$end."' GROUP BY productId, client ";
	$selectResult = execsql($selectQuery);
	$selectNum = mysql_num_rows($selectResult);
	
		
$f3="Tiles and Accessories";
if ($f3=="Tiles and Accessories") {
	$link="showAllProducts.php?cat=Tiles and Accessories&productSelect=All&colorSelect=All"; }
if ($f3=="Direct Materials") {
	$link="showAllProductsAll.php?searchText=All&CategorySelect=Direct Materials&subCatSelect="; }
if ($f3=="Store Item") {
	$link="showAllProductsAll.php?searchText=All&CategorySelect=Store Item&subCatSelect=$f4"; }
	
	
if ($f3=="Tiles and Accessories") {
    $link2="stockMovement.php?monthdisplay=0&cat=Store Item&productIdSelect=$productId" ; }
else {
	$link2="stockMovement.php?productIdSelect=$productId" ;
}	
   
	?>
<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 Delivery
	</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">
	  <?php echo $productName ?>
	</font></font></font></font></label>
	</p>
	<br />
<br />

<div id="coloredContainer">
  <form action="deliveriesStockItem.php" method="get" name="dateform" class="today" id="dateform">
    <span class="style7"> 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="Go" />
      <input name="date" type="hidden" id="date" value="1" />
    </label>
    <input name="productId" type="hidden" id="productId" value="<?php echo $productId ?>" />
  </form>
</div><br />

<table width="576" class="sortable-onload-0 rowstyle-alt no-arrow " id="tableList"  >
  <thead>
    <tr>
      <th width="200" class="sortable-text">Delivered to</th>
      <th width="98" class="sortable-numeric">Quantity</th>
      <th width="138" >&nbsp;</th>
      <!--        <th>Reserved Stock</th>-->
    </tr>
  </thead>
  <tbody>
    <?php
  $i=0;
  while ($i < $selectNum) {
			 //$b0 = mysql_result($selectResult, $i, "productId");
//			     $productQuery = "SELECT productName FROM products WHERE productId = ".$b0;
//	             $productResult = execsql($productQuery);
	         $b1 = mysql_result($selectResult, $i, "client");
			 $b2 = mysql_result($selectResult, $i, "summedQuantity"); 
  
  ?>
    <tr>
      <td><?php echo $b1 ?></td>
      <td align="right"><?php echo $b2 ?></td>
      <td>&nbsp;</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");
}
?>
