<?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">KPI 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>

								KPI 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>



<script>

	

jQuery(function($){

		   

	// simple jQuery validation script

	$('#course').submit(function(){

		

		var valid = true;

		var errormsg = 'This field is required!';

		var errorcn = 'error';

		

		$('.' + errorcn, this).remove();			

		

		$('#required', this).each(function(){

			var parent = $(this).parent();

			if( $(this).val() == '' ){

				var msg = $(this).attr('title');

				msg = (msg != '') ? msg : errormsg;

				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')

					.appendTo(parent)

					.fadeIn('fast')

					.click(function(){ $(this).remove(); });

				valid = false;

			};

		});

		

		return valid;

		

		$('input:submit').prop('disabled', true);

		

	});

	

});	



</script>







<?php  



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

{

	

	$employee=$_GET['employee'];

	$month=$_GET['month'];

	$year=$_GET['year'];

	

	$emp=mysqli_query($conn,"select * from employee where ID='$employee'");

	$emp1=mysqli_fetch_assoc($emp);

	

echo"<table style='margin:auto;'>



<tr><td>Employee</td><td style='padding:0 7px;'>:</td><td>".$emp1['name']."</td></tr>



<tr><td>Month</td><td style='padding:0 7px;'>:</td><td>".date("F",mktime($month))."</td></tr>



<tr><td>Year</td><td style='padding:0 7px;'>:</td><td>".$year."</td></tr>



</table>



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



<thead><tr><th>Date</th><th>Attendance</th><th>Social Media</th><th>CRM Update</th>

<th>Business Conversation</th><th>Delivery Feedback</th><th>Product Feedback</th>

<th>No Calls</th><th>Payment Collection</th><th>TD 6S</th><th>Customer Retention</th>

<th>Total</th><th>KPI Earnings</th></tr></thead>";



$date1 = $year.'-'.$month.'-01';

$dte=date("t",strtotime($date1));

$date2 = $year.'-'.$month.'-'.$dte;



function returnDates($fromdate, $todate) {

    $fromdate = DateTime::createFromFormat('d-m-Y', $fromdate);

    $todate = DateTime::createFromFormat('d-m-Y', $todate);

    return new DatePeriod(

        $fromdate,

        new DateInterval('P1D'),

        $todate->modify('+1 day')

    );

}



$date1 = date('d-m-Y',strtotime($date1));

$date2 = date('d-m-Y',strtotime($date2));



$datePeriod = returnDates($date1, $date2);



$tote=0;

foreach($datePeriod as $date) {



    $tdate = $date->format('d-m-Y');

	

	$cdate = $date->format('Y-m-d');



	$kp=mysqli_query($conn,"select * from kpi where date='$cdate' and employee='$employee'");

	$kp1=mysqli_fetch_assoc($kp);

	

	$sum=$kp1['attendance']+$kp1['socialmedia']+$kp1['crmupdate']+$kp1['businessconversation']+$kp1['deliveryfeedback']+$kp1['productfeedback']+$kp1['nocalls']+$kp1['paymentcollection']+$kp1['tds']+$td1['customerretention'];



	if($sum>0)

	{		

	$kpii=1400/30/$sum*$sum;

	}

	

	$kpii=number_format($kpii,0,'.','');

	

	echo"<tr><td>".$tdate."</td><td>".$kp1['attendance']."</td><td>".$kp1['socialmedia']."</td>

	<td>".$kp1['crmupdate']."</td><td>".$kp1['businessconversation']."</td>

	<td>".$kp1['deliveryfeedback']."</td><td>".$kp1['productfeedback']."</td>

	<td>".$kp1['nocalls']."</td><td>".$kp1['paymentcollection']."</td>

	<td>".$kp1['tds']."</td><td>".$td1['customerretention']."</td>

	<td>".$sum."</td><td style='text-align:right;'>".number_format($kpii,0,'.','').".00</td></tr>";



	$tote=$tote+$kpii;



}



echo"<tr><td colspan='12' style='text-align:right;'><b>Total</b></td><td style='text-align:right;'>".number_format($tote,0,'.','').".00</td></tr></table><br />



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



}

else

{



$mn=date("m");

$yr=date("Y");



echo'<br /><form action="kpireport.php" method="get">



<table style="margin:auto;">



<tr><td colspan="2" style="padding-bottom:7px;  text-align: left;"><span style="margin-left:130px;">Employee</span>  <select class="form-control" style="width: 30ch; margin-bottom:10px ; margin: 0 auto; display: block;" name="employee" class="select2" required><option value="">-- Select --</option>';



$sel=mysqli_query($conn,"select * from employee order by ID asc");

while($sel1=mysqli_fetch_assoc($sel))

{

	echo"<option value='".$sel1['ID']."'>".$sel1['name']."</option>";

}



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



<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 id="page" colspan="2" style="text-align:center; padding-top:11px;"><button type="submit" name="submit" value="submit" class="btn btn btn-primary">Go</button></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();



?>