
<?php
include("../include/session.php");
if( !$session->isAdmin() && !$session->isRadstoneReceptionUser() && !$session->isRadstoneStoreUser() ){
	//header("Location: ../Store/storeMenu.php");?>
	<script language="javascript" type="text/javascript">
        <!--
		  window.location="denied2.php";
        -->
       </script>
	   <?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", strtotime("-1 month") ) ;
	$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) );		
			
	$regNo =  mysql_real_escape_string($_GET['RegNoText']);
		
	$query = "SELECT productId, quantity, costs, name, reg_no, mileage, date, order_no FROM nam_rad_store_supply WHERE reg_no = '".$regNo."' and date >= '$start' AND date <= '$end' ORDER BY date DESC ";
	$result = mySQL_query($query) or die ("There is an error the database, the list cannot be displayed completely");
	$i = 0;
	$num = mysql_num_rows($result);
	
    
	
?>
<script type="text/javascript" src="../css/tablesort.js"></script>

<script type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
//-->
</script>

<link
	href="calendar.css" rel="stylesheet" type="text/css" />
<script
	language="javascript" src="../include/calendar.js"></script>
	   <link href="../css/main.css" rel="stylesheet" type="text/css" />
<div class="headerbox2" > Vehicle report    <b>
       <?php echo $regNo?>
	   </b></div><br />
<br /><br />



<div id="coloredContainer">
  <form action="vehicleReport.php" method="get" name="dateform" class="today" id="dateform">
    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="RegNoText" type="hidden" id="RegNoText" value="<?php echo $regNo ?>" />
  </form>
</div><br />

<table id="tableList" class="sortable-onload-0r rowstyle-alt no-arrow " >
	<thead>
		<tr>
		    <th width="63" class="sortable-date-dmy">Date</span></th>
			<th width="83" class="sortable-numeric">Mileage</th>
			<th width="52" class="sortable-numeric">Qty</th>
			<th width="67" class="sortable-numeric">Unit price</th>
			<th width="60" class="sortable-numeric">Costs</th>
			<th width="382" >Order no</th>
		</tr>
	</thead>
	<tbody>
<?php 
$i=0;
$totalCost = 0;
$totQty = 0;
$totMileage = 0;
while ($i<$num) {
	$a0 = mysql_result($result, $i, "productId"); 
	$a1 = mysql_result($result, $i, "quantity"); 
	$a2 = mysql_result($result, $i, "costs"); 
	$a3 = mysql_result($result, $i, "mileage"); 
	$a4 = mysql_result($result, $i, "date");
	$a5 = mysql_result($result, $i, "order_no");

?>
	
  <tr>
    <td><?php echo date("d-m-Y", strtotime( $a4))?></td>
    <td><?php echo $a3 ?> <?php $totMileage =  $totMileage + $a3 ?></td>
    <td><?php echo $a1 ?></td>
    <td align="right"><?php echo $a2 ?></td>
    <td align="right"><?php $a4=$a2*$a1; echo number_format($a4 , 2, '.', ', ')  ?></td>
    <td><?php echo $a5 ?></td>
  </tr>
  
<?php
$totalCost += $a4;
$totQty  += $a1;

$i++;
}
?>
</tbody>
<tfoot>
<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><?php echo $totQty ?></td>
    <td>&nbsp;</td>
    <td align="right"><?php echo number_format($totalCost , 2, '.', ', ') ?></td>
    <td>&nbsp;</td>
  </tr>
  </tfoot>
</table>
<br />

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

?>
	      
       </p>
	   