<?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:FereportDate</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">
	<script>
	function getXMLHTTP() { //fuction to return the xml http object

	var xmlhttp=false;	

	try{

	xmlhttp=new XMLHttpRequest();

	}

	catch(e)	{		

	try{			

	xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");

	}

	catch(e){

	try{

	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	}

	catch(e1){

	xmlhttp=false;

	}

	}

	}
	return xmlhttp;

	}
	function getZonefe(strURL) {
		var req = getXMLHTTP();
		if (req) {
		req.onreadystatechange = function() {

		if (req.readyState == 4) {
		
		if (req.status == 200) {						

		document.getElementById('zonefediv').innerHTML=req.responseText;						

		} else {

		alert("There was a problem while using XMLHTTP:\n" + req.statusText);

		}

		}				

		}			

		req.open("GET", strURL, true);

		req.send(null);
		}
		}
		 

	</script>

</head>
<body>
	<div class="borderHeader">
	<div align=left><img src="images/kmspl.PNG" /></div><div class="pagename"><h2>VIEW FE 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_fereportdatebetween" id="view_fereportdatebetween">
	<?php
	if(isset($_POST['txtsubmit']) && $_POST['txtsubmit']=='REFRESH')
	{
	$_POST['dump_date']='';
	$_POST['dump_date1']='';
	$_POST['user_code']='';
	}
	if(isset($_POST['txtsubmit']) && $_POST['txtsubmit']=='SEARCH')
 	{  
	$dump_date=$_POST['dump_date'];
	$dump_date1=$_POST['dump_date1'];
	$user_code=$_POST['user_code'];
	}

	date_default_timezone_set('Asia/Calcutta');
	?>
	<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>From</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_fereportdatebetween',

                            // input name

                            'controlname': 'dump_date'

                        });
                    </script></td>
		<td align="center" ><b>To</b> &nbsp;<input type ="text" name="dump_date1" value="<?php echo $_POST['dump_date1'];?>" style="width:100px; height"35px;"; required />
	  <script language="JavaScript">

                        new tcal ({

                            // form name

                            'formname': 'view_fereportdatebetween',

                            // input name

                            'controlname': 'dump_date1'

                        });
                    </script></td>
		<td align="center" ><b>Zone</b> &nbsp;&nbsp;
				<select name="zone" id="zone"  style="width:200px;height:35px;" onChange="getZonefe('zonefe_list.php?zone='+this.value)" required >
				<option value="<?php echo $_POST['zone'];?>"><?php echo $_POST['zone'];?></option>
				<?php
				$sqlzone="select distinct(zone) from user_tbl where uniqe_id='F' order by zone asc ";
				$resultzone=mysqli_query($conn,$sqlzone);
				while($datazone=mysqli_fetch_array($resultzone))
				{
				?>
				<option value="<?php echo $datazone['zone'];?>"><?php echo $datazone['zone'];?></option>
				<?php
				}
				?>
				</select>
 &nbsp;&nbsp;<b>Fe Name</b> </td>
				<td   id="zonefediv" ><select name="user_code" id="user_code"  style="width:200px;height:35px;" required >
				<?php
				$usercode=$_POST['user_code'];
				$sqlu="select first_name,last_name from user_tbl where  uniqe_id='F' and status='A'  and user_code='$usercode' ";
				$resultu=mysqli_query($conn,$sqlu);
				$datau=mysqli_fetch_array($resultu);
				?>
				<option value="<?php echo $_POST['user_code'];?>"><?php echo $datau['first_name'].' '.$datau['last_name'];?></option>
				<?php
				$sqlzone="select user_code,first_name,last_name from user_tbl where  uniqe_id='F' and status='A'  order by first_name asc ";
				$resultzone=mysqli_query($conn,$sqlzone);
				while($datazone=mysqli_fetch_array($resultzone))
				{
				?>
				<option value="<?php echo $datazone['user_code'];?>"><?php echo $datazone['first_name'].' '.$datazone['last_name'];?></option>
				<?php
				}
				?>
				
				</select> </td>
 <td align="center" ><input type="submit" name="txtsubmit"  value="SEARCH" id="searchbutton" > 
		
			<input type="submit" name="txtsubmit"  value="REFRESH" id="searchbutton"> 
<!--&nbsp;&nbsp;
	<?php
	if(strlen($dump_date)>0 and $dump_date1 and $user_code)
	{
	$dir=$dump_date;
	?>
	<a href="export_fereportdatesearch.php?id=<?php echo $dir?>"><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>Fe Name</b></th>				
				<th class="center"><b>Allocation</b></th>
				<th class="center"><b>Done</b></th>
				<th class="center"><b>Pending</b></th>
			</tr>
		 </thead>
		 <tbody>
		<?php
		
		if($dump_date and $dump_date1 and $user_code)
		{
		$dump_date11=explode('-',$dump_date1);
		$y=$dump_date11[2];
	$queryr="SELECT distinct(dump_date) from allocation_tbl  where dump_date between  '$dump_date' and '$dump_date1' and '$user_code'  and month like '%$y%' order by id asc";
	$resultr = MYSQLI_QUERY($conn,$queryr);
	}	
	 $j=1;
	while($data=mysqli_fetch_array($resultr)) {
	$dump_datet=$data['dump_date'];
	
	/*$sqlalloc="select count(id) as num from allocation_tbl where user_code='$user_code' and dump_date='$dump_datet' " ;
	$resultalloc=mysql_query($sqlalloc);
	$dataalloc=mysql_fetch_array($resultalloc);
	
	$sqldone="select count(id) as num from allocation_tbl where user_code='$user_code' and report_date='$dump_datet' and  dump_date!='$dump_datet' " ;
	$resultdone=mysql_query($sqldone);
	$datadone=mysql_fetch_array($resultdone);
	$done1=$datadone[0];


	$sqldone2="select count(id) as num from allocation_tbl where user_code='$user_code' and report_date='$dump_datet' and  dump_date='$dump_datet' " ;
	$resultdone2=mysql_query($sqldone2);
	$datadone2=mysql_fetch_array($resultdone2);
	$done2=$datadone2[0];

	$allocations1=$dataalloc[0];
	$allocations =$allocations1+$done1;
	//$allocation=$allocations;
	$allocationt +=$allocations;
	$done=$done1+$done2;
	$donet +=$done;
	$pending=$allocations-$done; */
	$sql2="select min(`unix_time`) as min FROM `allocation_tbl` WHERE dump_date='$dump_datet' ";
		$result2 = MYSQLI_QUERY($conn,$sql2);
		$data2=mysqli_fetch_array($result2);
		$unix_time=$data2['min'];
	$sqlalloc="select count(id) as num from allocation_tbl where user_code='$user_code' and dump_date='$dump_datet'  and report_date!='$dump_datet' " ;
	$resultalloc=mysqli_query($conn,$sqlalloc);
	$dataalloc=mysqli_fetch_array($resultalloc);
	$allocations1=$dataalloc[0];
	$sqlalloc2="select count(id) as num from allocation_tbl where user_code='$user_code' and dump_date='$dump_datet'  and  status='4' " ;
	$resultalloc2=mysqli_query($conn,$sqlalloc2);
	$dataalloc2=mysqli_fetch_array($resultalloc2);
	$allocations2=$dataalloc2[0];
	$sqlalloc22="select count(id) as num from allocation_tbl where user_code='$user_code' and unix_time<'unix_time' and  status='4' " ;
	$resultalloc22=mysqli_query($conn,$sqlalloc22);
	$dataalloc22=mysqli_fetch_array($resultalloc22);
	$allocations22=$dataalloc22[0];
	$sqldone="select count(id) as num from allocation_tbl where user_code='$user_code' and report_date='$dump_datet'  " ;
	$resultdone=mysqli_query($conn,$sqldone);
	$datadone=mysqli_fetch_array($resultdone);
	$done=$datadone[0];
	$allocations=$allocations1+$allocations2+$allocations22+$done;
	$pending=$allocations-$done; 
	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";
		}
		$sqlt="SELECT  count(id) as num from allocation_tbl  where dump_date between  '$dump_date' and '$dump_date1' and '$user_code' ";
		$resultt = MYSQLI_QUERY($conn,$sqlt);
		$datat=mysqli_fetch_array($resultt);
		$allocation=$datat[0];
	if($allocation>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['dump_date']);?></b></font></td>
<td align="center"><font size="2"><b><?php echo strtoupper($allocations);?></b></font></td>
<td align="center"><font size="2"><b><?php echo strtoupper($done);?></b></font></td>
<td align="center"><font size="2"><b><?php echo strtoupper($pending);?></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></b></font></td>
<td align="center"><font size="2"><b>Total</b></font></td>
<td  align="center" ><font size="4"><b><?php echo $allocationt;?></b></font></td>
<td  align="center" ><font size="4"><b><?php echo $donet;?></b></font></td>
<td  align="center" ><font size="4"><b><?php echo $pendingt;?></b></font></td>
</tr>-->
</tbody>
 </table>
</td>
</tr>
</table>

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