<?php
include ("../include/session.php");
if (!$session->isRadstoneStoreUser() && !$session->isRadstoneReceptionUser() && !$session->isAdmin()) {
	header("Location: ../main.php");
} else {
	include ("../storeHeader.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-d") ;
	$end = date("Y-m-d");
	}
		
	$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']);
	$productName="";
	if ($productId!='') {
	$productQuery = "SELECT productName FROM products WHERE productId = ".$productId;
	$productResult = execsql($productQuery);
	$productName = mysql_result($productResult, 0, "productName");
	}
	
	if ($productId=="") {
	$supplyQuery = "SELECT * FROM rad_store_supply WHERE date >= '".$start."' AND date  <= '". $end."' ";  
	}
	else {
	$supplyQuery = "SELECT * FROM rad_store_supply WHERE productId=$productId";
	}
	$supplyResult =  execsql($supplyQuery);
	$supplyResultNum = mysql_num_rows($supplyResult);
	  
?>

<link
	<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">Store issues</div>
<p class="main">
  <label class="std"><b><font size="3"><font size="3"><font size="3"><font size="3"> <?php if( $productName=="") {echo "All" ;} else {echo $productName; } ?> </font></font></font></font></label>
</p>
<br /><br /><br /><br />
    <div id="coloredContainer">
      <form action="issuedReport.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 id="tableMain" width="595"> <!--begin of tableMain-->
    <tr>
      <td >
    
</td> <!--center of tableMain-->
</tr>
<tr>
<td> <!--center of tableMain-->
            <table width="601" class="sortable-onload-4r rowstyle-alt no-arrow " id="tableList" >
    <thead>
      <tr>
        <th width="142" class="sortable-text"><div align="left">Product</div></th>
        <th width="47" class="sortable-numeric"><div align="left">Qty</div></th>
        <th width="65" class="sortable-numeric"><div align="left">Cost</div></th>
        <th width="97" class="sortable-text">Company</th>
        <th width="125" class="sortable-text">Emp / Rep</th>
        <th width="97" class="sortable-date-dmy"><div align="left">Date</div></th>
      </tr>
    </thead>
    <tbody>
    <?php

    $b11=0.00;
	$k = 0;
	while ($k < $supplyResultNum) {
//		
		$b2 = mysql_result($supplyResult, $k, "productId");
		
		  $productQuery = "SELECT productId, productName, category FROM products WHERE productID = $b2";
		  $productResult = execsql($productQuery);
		  $b2a = mysql_result($productResult, 0, "productName");
		  $b2c = mysql_result($productResult, 0, "category");
		  
		$b3 = mysql_result($supplyResult, $k, "company");
		  $companyQuery = "SELECT name FROM rad_tocotex WHERE account_no = $b3";
		  $companyResult = execsql($companyQuery);
		  $b3a = mysql_result($companyResult, 0, "name");
		
		$b8 = mysql_result($supplyResult, $k, "name");
		$status = mysql_result($supplyResult, $k, "status");
		if ($status=="employee") {
		  $empQuery = "SELECT empLName, empFName FROM employees WHERE empId = $b8";
		 
		  $empResult = execsql($empQuery);
		  $b8a = 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 = $b8";
		 
		  $repResult = execsql($repQuery);
		  $b8a = mysql_result($repResult, 0, "first_name")." ".mysql_result($repResult, 0, "last_name");	
		}
		if ($status=="department") { $b8a = $b8 ; }
		
		$b4 = mysql_result($supplyResult, $k, "quantity");
		$b9 = mysql_result($supplyResult, $k, "costs");
		$b10 = $b4*$b9;
		$b11 = $b11 + $b10;
		$b5 = mysql_result($supplyResult, $k, "notes");
		$b6 = mysql_result($supplyResult, $k, "date");
		$b7 = date("d-m-Y", strtotime($b6));
		

?>

        <tr class="alt">
        <td><div align="left">
          </a><div align="left"><a href="stockMovement.php?monthdisplay=0&cat=<?php echo $b2c ?>&productIdSelect=<?php echo $b2 ?>&date=0" onmouseover="ddrivetip('<?php echo $b2a."<br>(".$b2.")<br><b>Click for item history</b>" ?>','lightyellow', 150)" onmouseout="hideddrivetip()";>
            <?php echo $b2a?>
          </a></div></td>
        <td><div align="right"><?php echo $b4?></div></td>
        <td><div align="right">
          <?php echo number_format($b10 , 2, '.', ', ')?>
        </div></td>
        <td><?php echo $b3a ?></td>
        <td><?php echo $b8a ?></td>
        <td><?php echo $b7?></td>
        
        </tr>
		<?php
  $k++;
	}
?>
       <tfoot>
	    <tr class="alt">
          <td colspan="2"><div align="right">Total:&nbsp;&nbsp;</div></td>
          <td><div align="right"><?php echo number_format($b11, 2, '.', ',')?></div></td>
          <td colspan="3">&nbsp;</td>
         </tr> 
		</tfoot>
</tbody>
</table>

</td>
</tr>
</table>  <!--end of tableMain-->
<?php


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