<?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']);
	$repId = mysql_real_escape_string($_GET['repId']);
	
	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) );	
	
	
    
	$repQuery = "SELECT  first_name, last_name FROM rad_representatives  WHERE repId = ".$repId;
	$repResult = execsql($repQuery);
	$repName = mysql_result($repResult, 0, "first_name")." ".mysql_result($repResult, 0, "last_name");
	
	   
	$selectQuery = "SELECT * FROM rad_store_supply  WHERE name ='".$repId."' 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">
	Store Issues
	</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"><?php echo $repName ?></font></font></label>
	</p>
	<br />
<br />

<div id="coloredContainer">
  <form action="issuesTocotex.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="repIdo" type="hidden" id="repId" value="<?php echo $repId ?>" />
    
  </form>
</div><br />

<table width="576" class="sortable-onload-0 rowstyle-alt no-arrow " id="tableList"  >
  <thead>
    <tr>
      <th width="65" class="sortable-text">Date</th>
      <th width="189" class="sortable-text">Product</th>
      <th width="40" class="sortable-text">Qty</th>
      <th width="46" class="sortable-text">price</th>
      <th width="58" class="sortable-numeric">total</th>
      <th width="150" >&nbsp;</th>
     
    </tr>
  </thead>
  <tbody>
    <?php
  $i=0;
  $b6=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, "costs");
			 $b4 = mysql_result($selectResult, $i, "name"); 
			 
		$status = mysql_result($selectResult, $i, "status");
		if ($status=="employee") {
		  $empQuery = "SELECT empLName, empFName FROM employees WHERE empId = $b4";
		 
		  $empResult = execsql($empQuery);
		  $b4a = mysql_result($empResult, 0, "empFName")." ".mysql_result($empResult, 0, "empLName");
		}
		if ( ($status=="representative") OR ($status=="transport") ) {
		  $repQuery = "SELECT last_name, first_name FROM rad_representatives WHERE repId = $b4";
		 
		  $repResult = execsql($repQuery);
		  $b4a = mysql_result($repResult, 0, "first_name")." ".mysql_result($repResult, 0, "last_name");	
		}
		if ($status=="department") { $b4a = $b4 ; }
		
		$b5 = $b2*$b3;
		$b6 = $b6 + $b5;
			 
  
  ?>
    <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>&nbsp;</td>
    </tr>
    <?php
  $i++;
  }
  ?>
  </tbody>
  <tfoot>
  <tr>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <td>total:</td>
  <td align="right"><?php echo number_format($b6 , 2, '.', ', ') ?> </td>
  <td>&nbsp;</td>
  </tr>
  </tfoot>
  
</table>
<p><br />
	  <br />
	  <br />
	  <br />
	  <br />
	  <br />
	  <br />
	  <br />
	  <br />
      <br />
      
	 
    </p>
    </td>
</tr>
</table><!--end of tableMain-->
<?php 
include("../footer.php");
}
?>
