<?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) );	
	
	$newday=date("Y-m-d");
	$z=0;
	while ($z<365) {
	$newday = date('Y-m-d',mktime(0,0,0,date('d')+1, date('m'),  date('Y')));	
	$fillQuery = "INSERT INTO agenda (date) VALUES ('".$newday."')";
	$fillResult = mySQL_query($fillQuery);
	
	$z++;
	}
	
	

    $supplierName = mysql_real_escape_string($_GET['supplierName']);
	
		   
	$selectQuery = "SELECT * FROM delivery  WHERE supplierName ='".$supplierName."' AND date > '".$start."' AND date <= '".$end."' ";
	$selectResult = execsql($selectQuery);
	$selectNum = mysql_num_rows($selectResult);
		
   
	?>
<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">
	Receivals
	</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 $supplierName ?></font></font></font></font></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 type="submit" name="button5" id="button5" value="Go" />
      <input name="date" type="hidden" id="date" value="1" />
    </label>
    <input name="productId" type="hidden" id="supplierName" value="<?php echo $supplierName ?>" />
  </form>
</div><br />

<table width="576" class="sortable-onload-0 rowstyle-alt no-arrow " id="tableList"  >
  <thead>
    <tr>
      <th width="162" class="sortable-text">Date</th>
      <th width="162" class="sortable-text">Product</th>
      <th width="162" class="sortable-text">Qty</th>
      <th width="162" class="sortable-text">price</th>
      <th width="220" class="sortable-numeric">total</th>
      <th width="178" >deliveryNote</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 products WHERE productId = ".$b1a;
				 $productResult = execsql($productQuery);
				 $b1 = mysql_result($productResult, 0, "productName");
	         $b2 = mysql_result($selectResult, $i, "quantity");
			 $b3 = mysql_result($selectResult, $i, "pricePerUnit");
			 $b4 = mysql_result($selectResult, $i, "deliveryNote"); 
			 $b5 = $b2*$b3;
  
  ?>
    <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 number_format($b3 , 2, '.', ', ')  ?></td>
      <td align="right"><?php echo number_format($b5 , 2, '.', ', ') ?></td>
      <td><?php echo $b4 ?></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");
}
?>
