<?PHP


ob_start();


session_start();


include 'connect.php';


if(isset($_SESSION['adminemail']))


{


$user=$_SESSION['adminemail'];





$gtp=mysqli_query($conn,"select * from admin where username='$user'");


$gtp1=mysqli_fetch_assoc($gtp);





include 'top.php';


?>










<div id="page-wrapper" >
          <div id="page-inner">
			<div class="main-content">


				<div class="main-content-inner">


					<div class="breadcrumbs ace-save-state" id="breadcrumbs">


						<ul class="breadcrumb">


							<li>


								<i class="ace-icon fa fa-home home-icon"></i>


								<a href="#">Home</a>


							</li>


							<li class="active">Teamwise Report</li>


						</ul><!-- /.breadcrumb -->


					</div>





					<div class="page-content">


			





						<div class="page-header">


                        


<?php





$aca=mysqli_query($conn,"select * from financial where user='$user' order by ID desc");


$aca1=mysqli_fetch_assoc($aca);





$financial=$aca1['financial'];





?>                        


                        


							<table style="width:100%;">


                        


                        <tr><td style="width:50%;">


                        


							<h1>


								Teamwise Report


							</h1>


                            


                            </td>


                            


                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">


                            


                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>


                            


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


                            


						</div><!-- /.page-header -->





						<div class="row">


							<div class="col-xs-12">


                            


								<!-- PAGE CONTENT BEGINS -->





<script src="assets/js/jquery-2.1.4.min.js"></script>











<?php








	if(isset($_GET['month']))


	{





		$month=$_POST['month'];


		$year=$_POST['year'];





		echo"<table class='table table-bordered table-condensed'>


		


		<thead><tr><th>Team</th><th>New Customer</th><th>Follow Up</th><th>Orders Confirmed</th></tr></thead>";


		


		$ll=mysqli_query($conn,"select * from team_allocation group by team_leader order by team_leader asc");


		while($ll1=mysqli_fetch_assoc($ll))


		{


			


			$tln=mysqli_query($conn,"select * from employee where ID='$ll1[team_leader]'");


			$tln1=mysqli_fetch_assoc($tln);


			


			$cus=mysqli_query($conn,"select * from crm_customer left join team_allocation on team_allocation.executive=crm_customer.executive where team_allocation.team_leader='$ll1[team_leader]'");


			$cus1=mysqli_num_rows($cus);


			


			$flw=mysqli_query($conn,"select * from followup left join team_allocation on team_allocation.executive=followup.executive where team_allocation.team_leader='$ll1[team_leader]' and month(followup.date)='$month' and year(followup.date)='$year'");


			$flw1=mysqli_num_rows($flw);


			


			$cflw=mysqli_query($conn,"select * from followup left join team_allocation on team_allocation.executive=followup.executive where team_allocation.team_leader='$ll1[team_leader]' and month(followup.date)='$month' and year(followup.date)='$year' and followup.status='Confirmed'");


			$cflw1=mysqli_num_rows($cflw);


			


			echo"<tr><td>".$tln1['name']." - Team</td><td>".$cus1."</td><td>".$flw1."</td><td>".$cflw1."</td></tr>";


			


		}


		


		echo"</table><br />


		


		<center><a href='teamwisereport.php'>Back</a></center>";


		





	}





	else


	{





		echo'<center><form action="teamwisereport.php" method="get" id="course">


		


		


		<table style="margin:auto;">





		


		<tr><td id="page">Month  <select class="form-control" style="width: 30ch; margin-bottom:10px" name="month" id="month">





		<option value="">Select Month</option>';





		$i=1;





		while($i<=12)





		{





		if($i<10)


		{


		$i='0'.$i;


		}


		else


		{


		$i=$i;


		}





		$monthname=date("F",mktime(0,0,0,$i,10));





		if($i==$mn)


		{


		echo"<option value='".$i."' selected='selected'>".$monthname."</option>";


		}


		else


		{


		echo"<option value='".$i."'>".$monthname."</option>";


		}





		$i=$i+1;





		}





		echo'</select></td>





		<td id="page" style="padding:0 7px;">Year  <select class="form-control" style="width: 30ch; margin-bottom:10px" name="year" id="year"><option value="">Select Year</option>';





		$y="2019";


		$cy=date('Y');





		while($y<=$cy)


		{





		if($y==$yr)


		{


		echo"<option value='".$y."' selected='selected'>".$y."</option>";


		}


		else


		{


		echo"<option value='".$y."'>".$y."</option>";


		}





		$y=$y+1;





		$j++;





		}





		echo'</select></td></tr>








		<tr><td colspan="2" style="padding-top:7px; text-align:center;"><input class="btn btn btn-primary" type="submit" name="submit" value="Save" /></td></tr>


		


		</table></form></center>';





	}





?>














										<!-- PAGE CONTENT ENDS -->


									</div><!-- /.col -->


								</div><!-- /.row -->


							</div><!-- /.page-content -->


						</div>


					</div><!-- /.main-content -->
					</div><!-- /.main-content -->
					</div><!-- /.main-content -->











<?php





include 'bottom.php';





}


else


{





 header("location:login.php");





}








ob_flush();





?>