<?php
$id=$_GET['id'];

include("database_connection.php");

  function cleanData($str)
  {
    $str = preg_replace("/\t/", "\\t", $str);
    $str = preg_replace("/\r?\n/", "\\n", $str);
    if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
  }

  // filename for download
  $filename = "Scanner Report From" .$id.  ".xls";

 	header("Content-Disposition: attachment; filename=\"$filename\"");
  	header("Content-Type: application/vnd.ms-excel");

  $flag = false;
 ?><table border="1">
	<tr> 
		<th>Sr No</th>
		<th>Scanner Name</th>
		<th>Resi</th>
		<th>Office</th>		
		<th>Total</th>
				
	</tr>
	<?php
	$dump_date=$id;
	$queryr="SELECT distinct(scanner_name) FROM `scanner_tb` WHERE scan_date='$dump_date' and scanner_name!='' order by scanner_name asc";
	$resultr = MYSQLI_QUERY($conn,$queryr);
		
	 $j=1;
	while($data=mysqli_fetch_array($resultr)) {	
	$scanner_name=$data['scanner_name'];
	
	$sqlrv="select count(id) as num from scanner_tb where scanner_name='$scanner_name' and  scan_date='$dump_date' and type='RV'" ;
	$resultrv=mysqli_query($conn,$sqlrv);
	$datarv=mysqli_fetch_array($resultrv);
	$sqlov="select count(id) as num from scanner_tb where scanner_name='$scanner_name' and  scan_date='$dump_date' and type='OV'" ;
	$resultov=mysqli_query($conn,$sqlov);
	$dataov=mysqli_fetch_array($resultov);
	$rv=$datarv[0];
	$ov=$dataov[0];
	$total=$rv+$ov;
	$rvt +=$rv;
	$ovt +=$ov;
	$totalt +=$total;
	if($total>0)
	{
 ?>
	
	<tr  >
	<td><?php echo trim(strtoupper($j));?></td>	
	<td><b><?php echo strtoupper($data['scanner_name']);?></b></td>
	<td><b><?php echo strtoupper($rv);?></b></td>
	<td><b><?php echo $ov;?></b></td>
	<td><b><?php echo $total;?></b></td>	
	</tr>
	<?php
	$j++; } } ?>
	 <tr >
<td align="center"><font size="2"><b></b></font></td>
<td align="center"><font size="2"><b>Total</b></font></td>
<td  align="center" ><font size="4"><b><?php echo $rvt;?></b></font></td>
<td  align="center" ><font size="4"><b><?php echo $ovt;?></b></font></td>
<td  align="center" ><font size="4"><b><?php echo $totalt;?></b></font></td>
</tr>
</table>

