<?php
session_start();
error_reporting(0);
$role=$_SESSION['role'];
$user_name=$_SESSION['user_name'];
	if($_SESSION['user_name']==""){ 
		header('Location: index.php');
	}
	include("database_connection.php");
	 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>View:Scanner</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php //title();?>
<link type="text/css" rel="stylesheet" href="Library/css/style-menu.css"   />
<link type="text/css" rel="stylesheet" href="Library/css/style-content.css"   />
<script type="text/javascript" src="Library/js/jquery-1.3.1.min.js" > </script> 
<script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'Billing Application Dashboard', 'height=650,width=750');
        mywindow.document.write('<html><head><title>Billing Application Dashboard</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();

        return true;
    }

</script>
<script language="JavaScript" type="text/javascript">  
   function checkdelete(){
		var r=confirm("Are you sure to delete?");
		if (r==true){
			return true;
		}
		else{
			return false;
		}
	}
	</script>      

<style>
.borderHeader{
	border:1px;
	border-style:solid;
	height:73px;
	background-color:white;
}
.centerimage{
	margin-top:20px;
}
.pagename
{
	text-align:center;
	margin-top:-60px;
	color:#8B0000;
}

.airtellogo
{
   margin-top:-60px;

}	
.center {
 text-align: center
}
td { 
	
	height:15px;
}
</style>
<link type="text/css" href="menu/menu_admin.css" rel="stylesheet" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script language="JavaScript" src="newdate/calendar_us.js"></script>
  <link rel="stylesheet" href="newdate/calendar.css">


</head>
<body>
	<div class="borderHeader">
	<div align=left><img src="images/kmspl.PNG" /></div><div class="pagename"><h2>VIEW SCANNER REPORT  DATE WISE</h2></div>
</div>
	<?php 
	if(($_SESSION['uniqe_id']=='S'))
	{
	include("menu/menu_superadmin.php");
	}
	elseif(($_SESSION['uniqe_id']=='A') or ($_SESSION['uniqe_id']=='T'))
	{
	include("menu/menu_admin.php");
	}
	elseif(($_SESSION['uniqe_id']=='D'))
	{
	include("menu/menu_deo.php");
	}
	elseif(($_SESSION['uniqe_id']=='X'))
	{
	include("menu/menu_scanner.php");
	}
	else
	{
	header('Location: index.php');
	}
	?>
	<form method="post" action=" " name="view_scannerdate" id="view_scannerdate">
	<?php
	if(isset($_POST['txtsubmit']) && $_POST['txtsubmit']=='REFRESH')
	{
	$_POST['dump_date']='';
	$_POST['scanner']='';
	}
	if(isset($_POST['txtsubmit']) && $_POST['txtsubmit']=='SEARCH')
 	{  
	$dump_date=$_POST['dump_date'];
	$scanner=$_POST['scanner'];
	}

	date_default_timezone_set('Asia/Calcutta');
	$sqlsp="select count(id) as num from allocation_tbl where status='5' ";
	$resultsp=mysqli_query($conn,$sqlsp);	
	$datasp=mysqli_fetch_array($resultsp);
	$scantoday=$datasp[0];	
	?>
	<table style="width:100%"   align="center"> 
	<tr>
	<td align="center" style="width:85%;">
	<table  border="1" bgcolor="white" style="width:85%;" class="table table-striped" > 
	<tr>
	<td align="center" ><b>Date</b> &nbsp;<input type ="text" name="dump_date" value="<?php echo $_POST['dump_date'];?>" style="width:100px; height"35px;"; required />
	  <script language="JavaScript">

                        new tcal ({

                            // form name

                            'formname': 'view_scannerdate',

                            // input name

                            'controlname': 'dump_date'

                        });



                    </script>
 
 &nbsp;&nbsp;<input type="submit" name="txtsubmit"  value="SEARCH" id="searchbutton" > 
		
			<input type="submit" name="txtsubmit"  value="REFRESH" id="searchbutton"> 
			&nbsp;&nbsp;<b>Total Scan Pending -&nbsp;<?php echo $scantoday;?>
&nbsp;&nbsp;
	<?php
	if(strlen($dump_date)>0 )
	{
	
	?>
	<a href="export_scanner.php?id=<?php echo $dump_date?>"><b>Export Data</b></a>
	<?php
	}
	else
	{
	}
	?>

</td>
	</tr>
	</table>
	</td>
	</tr>
	</table>
	<table style="width:100%"   align="center"> 
	<tr>
	<td align="center" style="width:85%;">
	<table  border="1" bgcolor="white" style="width:85%;" class="table table-striped" > 
	<thead>
	<tr height="25">
				<th class="center" ><b>Sr No</b></th>				
				<th class="center"><b>ScannerName</b></th>	
				<th class="center"><b>First Attempt</b></th>	
				<th class="center"><b>Last Attempt</b></th>		
				<th class="center"><b>Resi</b></th>
				<th class="center"><b>Office</b></th>
				<th class="center"><b>Total</b></th>
				
			</tr>
		 </thead>
		 <tbody>
		<?php
		if($dump_date)
		{
		$queryr="SELECT distinct(scanner_name) FROM `scanner_tb` WHERE scan_date='$dump_date' and scanner_name!='' and scanner_name!='natraj' order by scanner_name asc";
	$resultr = MYSQLI_QUERY($conn,$queryr);
	}	
	 $j=1;
	while($data=mysqli_fetch_array($resultr)) {	
	$scanner_name=$data['scanner_name'];
	$sqlft="select scan_time from scanner_tb where scanner_name='$scanner_name' and  scan_date='$dump_date' order by id asc " ;
	$resultft=mysqli_query($conn,$sqlft);
	$dataft=mysqli_fetch_array($resultft);
	$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;
	$sqllt="select scan_time from scanner_tb where scanner_name='$scanner_name' and  scan_date='$dump_date' order by id desc " ;
	$resultlt=mysqli_query($conn,$sqllt);
	$datalt=mysqli_fetch_array($resultlt);
	if($j%2==0)
		 {
		 $color="#FFFAFA";  
		 }
		 else
		 {
		 $color="white";  
 		}
		if($pending>0)
		{
		$bg="#FFA07A";
		}
		else
		{
		$bg="white";
		}
		if($pending2>0)
		{
		$bg2="#FFFF00";
		}
		else
		{
		$bg2="white";
		}
	if($total>0)
	{
	?>

<tr  bgcolor=" <?php echo $color;?>" height="15">
<td   align="center"><font size="2"><b><?php echo $j ;?></b></font></td>
<td align="center"><font size="2"><b><?php echo strtoupper($data['scanner_name']);?></b></font></td>
<td align="center"><font size="2"><b><?php echo $dataft['scan_time'];?></b></font></td>
<td align="center"><font size="2"><b><?php echo $datalt['scan_time'];?></b></font></td>
<td align="center"><font size="2"><b><?php echo strtoupper($rv);?></b></font></td>
<td   align="center"><font size="2"><b><?php echo $ov;?></b></font></td>
<td   align="center"><font size="2"><b><?php echo $total;?></b></font></td>

</tr>
<?php
	$j++; } } ?>
<tr >

<td align="center"><font size="2"><b></b></font></td>
<td align="center"><font size="2"><b></b></font></td>
<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>
<?php
	$scanner_name2="natraj";
	$sqlft2="select scan_time from scanner_tb where scanner_name='$scanner_name2' and  scan_date='$dump_date' order by id asc " ;
	$resultft2=mysqli_query($conn,$sqlft2);
	$dataft2=mysqli_fetch_array($resultft2);
	$sqlrv2="select count(id) as num from scanner_tb where scanner_name='$scanner_name2' and  scan_date='$dump_date' and type='RV'" ;
	$resultrv2=mysqli_query($conn,$sqlrv2);
	$datarv2=mysqli_fetch_array($resultrv2);
	$sqlov2="select count(id) as num from scanner_tb where scanner_name='$scanner_name2' and  scan_date='$dump_date' and type='OV'" ;
	$resultov2=mysqli_query($conn,$sqlov2);
	$dataov2=mysqli_fetch_array($resultov2);
	$rv2=$datarv2[0];
	$ov2=$dataov2[0];
	$total2=$rv2+$ov2;
	
	$sqllt2="select scan_time from scanner_tb where scanner_name='$scanner_name2' and  scan_date='$dump_date' order by id desc " ;
	$resultlt2=mysqli_query($conn,$sqllt2);
	$datalt2=mysqli_fetch_array($resultlt2);
?>
	<tr >
<td   align="center"><font size="2"><b></b></font></td>
<td align="center"><font size="2"><b><?php echo strtoupper($scanner_name2);?></b></font></td>
<td align="center"><font size="2"><b><?php echo $dataft2['scan_time'];?></b></font></td>
<td align="center"><font size="2"><b><?php echo $datalt2['scan_time'];?></b></font></td>
<td align="center"><font size="2"><b><?php echo strtoupper($rv2);?></b></font></td>
<td   align="center"><font size="2"><b><?php echo $ov2;?></b></font></td>
<td   align="center"><font size="2"><b><?php echo $total2;?></b></font></td>

</tr>
</tbody>
 </table>
</td>
</tr>
</table>

</div>
</body>
</html>			
