<?php include 'inc_classes.php'; 
include "admin_authentication.php";
// $edit_access='';
// $sel_acc="select * from edit_previleges where admin_id='".$_SESSION['admin_id']."' and privilege_id='392'";
// $ptr_access=mysql_query($sel_acc);
// if(mysql_num_rows($ptr_access))
// {
// 	$edit_access='yes';
// }
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title> Employee Yearly Performance Report </title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap datepicker -->
    <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="bower_components/select2/dist/css/select2.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- paginate style -->
    <link rel="stylesheet" href="dist/css/paginate.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
    <!-- Google Font -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<script>
   function submitAction(action)
	{
		var chks = document.getElementsByName('chkRecords[]');
		var hasChecked = false;
		for (var i = 0; i < chks.length; i++)
		{
			if (chks[i].checked)
			{
				hasChecked = true;
				break;
			}
		}
		if (hasChecked == false)
		{
			alert("Please select at least one record to do operation");
			$('#selAction').val('');
			return false;
		}

		document.getElementById('formAction').value=action;
		if(action=="delete")
		{
			if(confirm("Are you sure, you want to delete selected record(s)?"))
				document.frmTakeAction.submit();
			else
			{
				$('#selAction').val('');
				return false;
			}
		}
		else
			document.frmTakeAction.submit();
	}

	function getstaffDetails(branch_id)
	{
		var data1="action=sel_staff&branch_id="+branch_id;	
		$.ajax({
		url: "tk_fill_kpi_ajax.php", type: "post", data: data1, cache: false,
		success: function (html)
		{
			if(html !='')
			{
				document.getElementById("staff_ids").innerHTML=html;
				$("#staff_id").chosen({allow_single_deselect:true});
			}
		},
		error:function(exception){alert('Exception:'+exception);}
		});
	}
function select_staff(branch)
{
	var branch_data="action=staff&branch_name="+branch;
    // alert(branch);
	$.ajax({
	url: "tk_fill_kpi_ajax.php",type:"post", data: branch_data,cache: false,
	success: function(retstaff)
	{
		// alert(retstaff);
		document.getElementById("sel_name").innerHTML=retstaff;
	
	}
	});
}
	function isNumber(evt) {
		evt = (evt) ? evt : window.event;
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if (charCode > 31 && (charCode < 48 || charCode > 57)) {
			return false;
		}
		return true;
	}
	function issue_value(val) {
            var issueRow = document.getElementById("issuevalue");
            if(val == 'issue') {
				// alert("hi");
                issueRow.classList.remove("hidden");
            } else {
                issueRow.classList.add("hidden");
            }
        }
	function check_date(dates) {
		// var dates=document.getElementById("date").value;
		// alert(dates);
		var today_dates=document.getElementById("today_date").value;
		// alert(today_dates);
		if (today_dates > dates) {
				alert("Date are not less than todays date")
                window.location.reload();
            }
	}
	function check_next_date(to_date) {
		// var dates=document.getElementById("date").value;
		// alert(dates);
		var today_dates=document.getElementById("today_date").value;
		// alert(today_dates);
		if (today_dates < to_date) {
				alert("Date are not Greater than todays date")
                window.location.reload();
            }
	}
	function validation() {
    var from_date = document.getElementById("date1").value;
    var to_date = document.getElementById("date2").value;
    var branch_name = document.getElementById("branch_name").value;
    var staff_id = document.getElementById("staff_id").value;
    var target_type = document.getElementById("target_type").value;
    var target_name = document.getElementById("target_name").value;
    var tot_points = document.getElementById("tot_points").value;
    var comments = document.getElementById("comments").value;

    var error = '';
    var show_error = 'Please Correct The Following Error \n';

    if (branch_name == "") {
        error = 'yes';
        show_error += 'Please Select Branch \n';
    }
    if (staff_id == "") {
        error = 'yes';
        show_error += 'Please Select Staff \n';
    }
    if (target_type == "") {
        error = 'yes';
        show_error += 'Please Select Target Type \n';
    }
    if (target_name == "") {
        error = 'yes';
        show_error += 'Please Add Target Name \n';
    }
    if (tot_points == "") {
        error = 'yes';
        show_error += 'Please Add Percentage \n';
    }
    if (from_date == "") {
        error = 'yes';
        show_error += 'Please Select the From Date\n';
    }
    if (to_date == "") {
        error = 'yes';
        show_error += 'Please Select the To Date\n';
    }

    if (from_date !== "" && to_date !== "") {
        var fromDateObj = new Date(from_date.split('/').reverse().join('/'));
        var toDateObj = new Date(to_date.split('/').reverse().join('/'));

        if (toDateObj < fromDateObj) {
            error = 'yes';
            show_error += 'From Date should not be later than To Date\n';
        }
    }

    if (comments == "") {
        error = 'yes';
        show_error += 'Please Add Comments \n';
    }

    if (error == 'yes') {
        alert(show_error);
        return false;
    } else {
        return true;
    }
}	
function select_status(status,target_id)
{
	// alert('status = '+status);
	// alert('target_id = '+target_id);
	var target_data="action=changestatus&status="+status+"&target_id="+target_id;
	$.ajax({
	url: "target_ajax.php",type:"post", data: target_data,cache: false,
	success: function(rettarget)
	{
		alert("Status Updated Successfully");
		// document.getElementById("sel_name").innerHTML=retstaff;
        // $("#sel_name").chosen({allow_single_deselect:true});

	}
	});
}
function select_quality(quality,target_id)
{
	// alert('quality = '+quality);
	// alert('target_id = '+target_id);
	var quality_data="action=changequality&quality="+quality+"&target_id="+target_id;
	$.ajax({
	url: "target_ajax.php",type:"post", data: quality_data,cache: false,
	success: function(retquality)
	{
		alert("Status Updated Successfully");
	}
	});
}
function changevalue(value,target_id)
{
	// alert('value = '+value);
	// alert('target_id = '+target_id);
	var target_value="action=valuechange&value="+value+"&target_id="+target_id;
	$.ajax({
	url: "target_ajax.php",type:"post", data: target_value,cache: false,
	success: function(rettarget)
	{
		// alert(rettarget);
		// alert("Value changed Successfully");
	}
	});
}
</script>
<style>
    .hidden {
        display:none; 
    }
</style>
</script>
<?php
include "include/ps_pagination.php";
	?>
<body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">
        <?php include "include/header-main.php"; ?>
        <!-- Left side column. contains the logo and sidebar -->
        <?php include "include/menu_left.php"; ?>
        <!-- Content Wrapper. Contains page content -->
        <!-- Left side column. contains the logo and sidebar -->
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                    Employee Yearly Performance Report
                </h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                    <li class="active">Dashboard</li>
                </ol>
            </section>
            <!-- Main content -->
            <?php   
            if($_REQUEST['record_id'])
            {
                $record_id=$_REQUEST['record_id'];
                $sql_record= "SELECT * FROM pm_target where target_id='".$record_id."'";
                if(mysql_num_rows($db->query($sql_record)))
                    $row_record=$db->fetch_array($db->query($sql_record));
                else
                    $record_id=0;
            }
            if($_POST['save_changes'])
            {
                
                $branch_name=( ($_POST['branch_name'])) ? $_POST['branch_name'] : "";
                $added_date=date('Y-m-d H:i:s');  
                $admin_id=$_SESSION['admin_id'];

				if($_SESSION['type']=='S' || $_SESSION['branch_access']=='yes')
				{
					$sel_branch="select cm_id ,admin_id from site_setting where branch_name='".$branch_name."' and type='A'";
					$ptr_branch=mysql_query($sel_branch);
					$data_branch=mysql_fetch_array($ptr_branch);
					$cm_id=$data_branch['cm_id'];
					
					$branch_name1=$branch_name;
					$_SESSION['cm_id_notification']=$data_branch['cm_id'];
				}	
				else
				{
					$cm_id=$_SESSION['cm_id'];
					$branch_name1=$_SESSION['branch_name'];
				}

                $ad_date=$_POST['from_date'];
                $new_dates=explode("/",$ad_date);
                $from_date=$new_dates[2].'-'.$new_dates[1].'-'.$new_dates[0];
                $to_date=$_POST['to_date'];
                $new_to_date=explode("/",$to_date);
                $to_dates=$new_to_date[2].'-'.$new_to_date[1].'-'.$new_to_date[0];

                $data_record['staff_id'] = $_POST['staff_id'];
                $data_record['from_date']=$from_date;
                $data_record['to_date'] = $to_dates;
                $data_record['status'] = 'pending';
                $data_record['target_quality'] ='0';
                $data_record['points']=$_POST['points'];
                $data_record['target_name'] = $_POST['target_name'];
                $data_record['target_type'] = $_POST['target_type'];
                $data_record['comments'] = $_POST['comments'];
                $data_record['admin_id'] =$admin_id;
                $data_record['cm_id'] =$cm_id;
                
                if($record_id)
                {
                    $where_record="target_id='".$record_id."'";
                    $db->query_update("pm_target", $data_record,$where_record);
                    {
                        ?>
                        <div class="alert alert-success alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                            <p> Record Updated Successfully.</p>
                        </div>
                        <script>
                            setTimeout('document.location.href="tk_add_target.php";', 500);
                        </script>
                        <?php
                    }
                }
                else
                {
                    $data_record['added_date'] =$added_date;
					$checkout_prod_map_id=$db->query_insert("pm_target", $data_record);						
                    if($checkout_prod_map_id)
                    {
                        ?>
                        <div class="alert alert-success alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                            <p> Record Inserted Successfully.</p>
                        </div>
                        <script>
                            setTimeout('document.location.href="tk_add_target.php";', 500);
                        </script>
                        <?php
                    }
                }
            }
			if($_REQUEST['deleteRecord']!='' && $_REQUEST['record_ids']!='')
			{
				$id=$_REQUEST['record_ids'];
                $delete="delete from pm_target where target_id='".$id."'";  
                $ptr_delete=mysql_query($delete);
                if ($ptr_delete)
                {
                    ?>
                        <div class="alert alert-danger alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <h4><i class="icon fa fa-ban"></i> Alert!</h4>
                            <p> Record Deleted Successfully.</p>
                        </div>
                        <script>
                            setTimeout('document.location.href="tk_add_target.php";', 500);
                        </script>
                    <?php
                }
			}            
            ?>
            <section class="content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="box box-info">
                            <div class="box-header with-border">
                                <!-- <h3 class="box-title"> Target Report</h3> -->
                                <div class="table-responsive">
                                    <form method="get" name="search">
                                        <table class="table no-margin" >
                                            <tr>
                                                <td>
                                                    <?php
                                                    if($_SESSION['type']=='S' || $_SESSION['branch_access']=='yes')
                                                    {
                                                        ?>
                                                        <select class="form-control select2" id="branch_name"
                                                            style="width:150px" name="branch_name"
                                                            onchange="select_staff(this.value)" ;>
                                                            <option value="">Select Branch</option>
                                                            <?php 
                                                            $sel_branch="select branch_id,branch_name from branch";
                                                            $ptr_sel=mysql_query($sel_branch);
                                                            while($data_branch=mysql_fetch_array($ptr_sel))
                                                            {
                                                                $sel='';
                                                                if($data_branch['branch_name']==$_GET['branch_name'])
                                                                {
                                                                    $sel='selected="selected"';
                                                                }
                                                                echo '<option '.$sel.' value="'.$data_branch['branch_name'].'" >'.$data_branch['branch_name'].'</option>';
                                                            }
                                                            ?>
                                                        </select>
                                                        <?php
                                                    }
                                                    else
                                                    {
                                                        ?>
                                                            <input type="hidden" name="branch_name" id="branch_name" value="<?php echo $_SESSION['branch_name']; ?>" />
                                                        <?php
                                                    }
                                                    ?>
                                                </td>
                                                <td>
                                                    <?php
                                                    if($_GET['sel_name']!='')
                                                    {
                                                        $sel_staffs="select admin_id,name from site_setting where 1 and system_status='Enabled' and branch_name='".$_GET['branch_name']."'";
                                                        $ptr_que=mysql_query($sel_staffs);
                                                        ?>    
                                                        <select class="form-control select2" style="width:200px" id="sel_name" name="sel_name">
                                                            <option value="">Select Staff</option>
                                                                <?php
                                                                while($data_query=mysql_fetch_array($ptr_que))
                                                                {
                                                                    $sel='';
                                                                    if($data_query['admin_id']==$_GET['sel_name'])
                                                                    {
                                                                        $sel='selected="selected"';
                                                                    }
                                                                    ?>
                                                                    <option <?php echo $sel;?> value="<?php echo $data_query['admin_id'] ;?>"><?php echo $data_query['name'] ;?></option>
                                                                    <?php
                                                                }
                                                                ?>
                                                        </select>
                                                        <?php
                                                    }
                                                    else
                                                    {
                                                        ?>
                                                        <select class="form-control select2" style="width:200px" id="sel_name" name="sel_name">
                                                        <option value="">Select Staff</option>
                                                        </select>
                                                        <?php
                                                    }
                                                    ?>    
                                                </td>
                                                <td width="">
                                                    <input type="text" name="from_month" class="form-control" placeholder="From Month" readonly="1" id="date1" title="From Month" value="<?php echo $_REQUEST['from_month'];?>" style="width:150px">
                                                </td>
                                                <td width="">
                                                    <input type="text" name="to_month" class="form-control" placeholder="To Month" readonly="1" id="date2"  title="To Month" value="<?php echo $_REQUEST['to_month'];?>" style="width:150px">
                                                </td>
                                                <td>
                                                    <input type="image" src="images/search.jpg" name="search" value="search"
                                                        style="height:32px;">
                                                </td>
                                            </tr>
                                            <style>
                                                th{
                                                    text-align: center;
                                                }
                                            </style>
                                            <?php
                                            if($_REQUEST['sel_name'])
                                            {
                                                ?>
                                                <tr>
                                                    <div class="box-body">
                                                        <table class="table no-margin" style="text-align:center">
                                                            <thead>
                                                                <?php
                                                                $emp_name="select name from site_setting where 1 and admin_id='".$_REQUEST['sel_name']."'";
                                                                $ptr_emp_name=mysql_query($emp_name);
                                                                $data_emp_name=mysql_fetch_array($ptr_emp_name);
                                                                ?>
                                                                <tr><h4 style="text-align:center"><strong>Staff Name : <span  style="font-size:17px;color:Blue;"><?php echo ucfirst($data_emp_name['name']) ?></span></strong></h4></tr>
                                                                <tr>
                                                                    <th>Sr. No.</th>
                                                                    <th>Month</th>
                                                                    <th>Year</th>
                                                                    <th>Issue Damage Value</th>
                                                                    <th>Issue Percentage</th>
                                                                    <th>Accolades Percentage</th>
                                                                    <th>Performance Percentage</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php    
                                                                if($_REQUEST['from_month'] && $_REQUEST['from_month']!=="0000-00-00" )
                                                                {
                                                                    // echo'<br>'.$_REQUEST['from_month'];
                                                                    $frm_date=explode("/",$_REQUEST['from_month']);
                                                                    $new_date=$frm_date[1]."-".$frm_date[0];
                                                                    $start_date=$frm_dates;
                                                                    '<br>'.$from_year=$frm_date[1];
                                                                    '<br>'.$from_month=$frm_date[0];
                                                                    $date_start=" and from_date >='".$new_date."'";
                                                                }
                                                                if($_REQUEST['to_month'] && $_REQUEST['to_month']!=="0000-00-00")
                                                                {
                                                                    // echo'<br>'.$_REQUEST['to_month'];
                                                                    $frm_to_date=explode("/",$_REQUEST['to_month']);
                                                                    $frm_to_dates=$frm_to_date[1]."-".$frm_to_date[0];
                                                                    $start_to_date=$frm_to_dates;
                                                                    '<br>'.$to_year=$frm_to_date[1];
                                                                    '<br>'.$to_month=$frm_to_date[0];
                                                                    // date("Y-m", strtotime($frm_to_dates))
                                                                    $to_date=" and to_date <='".$frm_to_dates."'";
                                                                }
                                                                if($_REQUEST['from_month']!='' && $_REQUEST['to_month']!=''){
                                                                    $search_year='and year >="'.$from_year.'" and year <="'.$to_year.'"';
                                                                    $search_month='and month >="'.$from_month.'" and month <="'.$to_month.'"';
                                                                }
                                                                else{
                                                                    $search_year='and year >="'.date('Y').'" and year <="'.date('Y').'"';
                                                                    $search_month='';
                                                                }
                                                                if($_SESSION['type']=="S" || $_SESSION['type']=='Z' || $_SESSION['type']=='LD')
                                                                {
                                                                    if($_REQUEST['branch_name']!='')
                                                                    {
                                                                        $branch_name=$_REQUEST['branch_name'];
                                                                        $select_cm_id="select cm_id from site_setting where 1 and system_status='Enabled' and branch_name='".$branch_name."' and type='A'";
                                                                        $ptr_cm_id=mysql_query($select_cm_id);
                                                                        $data_cm_id=mysql_fetch_array($ptr_cm_id);
                                                                        $search_cm_id=" and cm_id='".$data_cm_id['cm_id']."'";
                                                                        $cm_ids=$data_cm_id['cm_id'];
                                                                    }
                                                                }
                                                                if($_REQUEST['sel_name'])
                                                                {
                                                                    $staff_ids=$_REQUEST['sel_name'];
                                                                    $where_staff_id=" and employee_id='".$staff_ids."'";
                                                                    $staff_id=" and staff_id='".$staff_ids."'";
                                                                }
                                                                else
                                                                {
                                                                    $where_staff_id='';
                                                                }
                                                                '<br>'.$sql_query= "SELECT * FROM pm_monthly_performance where 1 and staff_id='".$_REQUEST['sel_name']."' ".$search_month." ".$search_year." "; 
                                                                $db=mysql_query($sql_query); 
                                                                $no_of_records=mysql_num_rows($db);
                                                                    $current_month=date("m");
                                                                    $out_of_point='';
                                                                    $sr=1;
                                                                    $damage_val='';
                                                                if($no_of_records)
                                                                {
                                                                    while($val_query=mysql_fetch_array($db))
                                                                    {
                                                                        '<br>'.$sel_issue= "SELECT total_percentage,damage_val FROM pm_emp_extra_performance where 1 and staff_id='".$_REQUEST['sel_name']."' and Month(date)='".$val_query['month']."' and Year(date)='".$val_query['year']."' and type='issue' "; 
                                                                        $ptr_issue=mysql_query($sel_issue);
                                                                        $issue_per=0;
                                                                        $damage='0';
                                                                        while($data_issue=mysql_fetch_array($ptr_issue))
                                                                        {
                                                                            $tot_issue='-'.$data_issue['total_percentage'];
                                                                            $issue_per+=$tot_issue;
                                                                            '<br>'.$damage+=$data_issue['damage_val'];
                                                                        }
                                                                        $fianl_issue+=$issue_per;
                                                                        $damage_val+=$damage;
                                                                        '<br>'.$sel_accolate= "SELECT total_percentage FROM pm_emp_extra_performance where 1 and staff_id='".$_REQUEST['sel_name']."' and Month(date)='".$val_query['month']."' and type='accolades' "; 
                                                                        $ptr_accolate=mysql_query($sel_accolate);
                                                                        $accolate_per=0;
                                                                        while($data_accolate=mysql_fetch_array($ptr_accolate)){
                                                                            $tot_accolates=$data_accolate['total_percentage'];
                                                                            $accolate_per+=$tot_accolates;
                                                                        }
                                                                        $fianl_accolades+=$accolate_per;
                                                                        $sel_mont="select month_name,month_id from months where month_id='".$val_query['month']."'";
                                                                        $ptr_mont=mysql_query($sel_mont);
                                                                        $data_mont=mysql_fetch_array($ptr_mont);
                                                                        if($bgColorCounter%2==0)
                                                                            $bgcolor='class="grey_td"';
                                                                        else
                                                                            $bgcolor="";                
                                                                        $listed_record_id=$val_query['admin_id']; 
                                                                        include "include/paging_script.php";
                                                                        $sel_branch_name="select branch_id,branch_name,cm_id from branch where 1 and cm_id='".$val_query['cm_id']."'";
                                                                        $ptr_sel_name=mysql_query($sel_branch_name);
                                                                        $data_branch_name=mysql_fetch_array($ptr_sel_name);
                                                                        ?>
                                                                        <tr>
                                                                            <td>
                                                                                <?php echo $sr++; ?>
                                                                            </td>
                                                                            <td align="center"><?php echo ucfirst($data_mont['month_name'])?></td>
                                                                            <td align="center"><?php echo ucfirst($val_query['year'])?></td>
                                                                            <td>
                                                                                <?php echo $damage?>
                                                                            </td>
                                                                            <td>
                                                                                <?php echo $issue_per?>
                                                                            </td>
                                                                            <td>
                                                                                <?php echo $accolate_per?>
                                                                            </td>
                                                                            <td>
                                                                                <?php echo $val_query['performance_percentage']?>
                                                                            </td>
                                                                        </tr>
                                                                        <?php
                                                                        $tot_rec=$no_of_records*100;
                                                                        $totol_percentage+=$val_query['performance_percentage'];  
                                                                        $final_per=($totol_percentage/$tot_rec)*100;
                                                                        $bgColorCounter++;
                                                                    }
                                                                    ?>
                                                                    <tr style="background-color:#e9e8e8;font-size:22px !important">
                                                                        <td colspan="3" align="center" style="font-size:18px;color:"> Total Performance (For Selected Date Range)</td>
                                                                        <td  align="center" style="font-size:18px;color:blue; width:100px;"><b><?php echo round($damage_val)?></b></td>
                                                                        <td  align="center" style="font-size:18px;color:red; width:100px;"><b><?php echo round($fianl_issue)?></b></td>
                                                                        <td  align="center" style="font-size:18px;color:green; width:100px;"><b><?php echo round($fianl_accolades)?></b></td>
                                                                        <td  align="center" style="font-size:18px;color:#fa6015; width:100px;"><b><?php echo round($final_per)?>% </b></td>
                                                                    </tr>
                                                                    <?php
                                                                }
                                                                ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </tr>
                                                <tr>
                                                    <div class="box-body">
                                                        <table class="table no-margin" style="text-align:center">
                                                            <thead>
                                                                <tr ><h2 style="text-align:center">Targets</h2></tr>
                                                                <tr>
                                                                    <th>Sr. No.</th>
                                                                    <th>Target Name</th>
                                                                    <th>Target Point</th>
                                                                    <th>Quality Point</th>
                                                                    <th>From Date</th>
                                                                    <th>To Date</th>
                                                                    <th>Status</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php
                                                                '<br>'.$sql_target= "SELECT * FROM pm_target where 1 and staff_id='".$_REQUEST['sel_name']."' ".$date_start." ".$to_date.""; 
                                                                $db=mysql_query($sql_target); 
                                                                $no_of_record=mysql_num_rows($db);
                                                                $current_month=date("m");
                                                                if($no_of_records)
                                                                {
                                                                    $sr1=1;
                                                                    while($data_target=mysql_fetch_array($db))
                                                                    {
                                                                        if($bgColorCounter%2==0)
                                                                            $bgcolor='class="grey_td"';
                                                                        else
                                                                            $bgcolor="";                
                                                                        $listed_record_id=$val_query['admin_id']; 
                                                                        $sel_quality="select * from tk_quality_work_point where 1 and quality_id='".$data_target['target_quality']."'";
                                                                            $ptr_quality=mysql_query($sel_quality);
                                                                            $data_quality=mysql_fetch_array($ptr_quality);
                                                                        ?>
                                                                        <tr>
                                                                            <td>
                                                                                <?php echo $sr1++; ?>
                                                                            </td>
                                                                            <td align="center"><?php echo ucfirst($data_target['target_name'])?></td>
                                                                            <td align="center"><?php echo $data_target['points']?></td>
                                                                                <?php
                                                                                if($data_target['quality_point'] && $data_quality['rating']){
                                                                                echo '<td align="center" style="color:green";>'.$data_target['quality_point'].' ('.ucfirst($data_quality['rating']).')</td>';
                                                                                }else{
                                                                                    echo '<td align="center" style="color:green";>'.$data_target['quality_point'].'</td>';
                                                                                }
                                                                                $t_quality+=$data_target['quality_point'];
                                                                                echo '<td align="center" >'.date("d-m-Y", strtotime($data_target['from_date'])).'</td>';
                                                                                echo '<td align="center" >'.date("d-m-Y",strtotime($data_target['to_date'])).'</td>';
                                                                                echo '<td align="center" >';
                                                                                if($data_target['status']=='complete')
                                                                                {
                                                                                    echo '<strong style="color:green">'.ucfirst($data_target['status']).'</strong>';
                                                                                }
                                                                                else if($data_target['status']=='incomplete')
                                                                                {
                                                                                    echo '<strong style="color:red">'.ucfirst($data_target['status']).'</strong>';
                                                                                }
                                                                                else{
                                                                                    echo '<strong style="color:blue">'.ucfirst($data_target['status']).'</strong>';
                                                                                }
                                                                            echo '</td>';
                                                                        echo '</tr>'; 
                                                                        $rec_value=$no_of_record*100;
                                                                    }
                                                                    $sel_target_cmplt="SELECT * FROM pm_target where 1 and staff_id='".$_REQUEST['sel_name']."' ".$date_start." ".$to_date." and status='complete'";
                                                                    $ptr_target_cmplt=mysql_query($sel_target_cmplt);
                                                                    $targets_cmplt=0;
                                                                    $tar_qult=0;
                                                                    $l=0;
                                                                    while($data_target_cmplt=mysql_fetch_array($ptr_target_cmplt)){
                                                                        $targets_cmplt+=$data_target_cmplt['points'];
                                                                        $tar_qult+=$data_target_cmplt['quality_point'];
                                                                        $l++;
                                                                    }
                                                                    $rec_value=$l*100;
                                                                    $targets_qult=($tar_qult/$rec_value)*100;
                                                                    '<br>'.$quality_compt=$targets_cmplt+$targets_qult;
                                                                    '<br>'.$targets_points=($quality_compt/200)*100;
                                                                    $sel_weightage1="select percentage from pm_weightage where 1 and name='performance'";
                                                                    $ptr_weightage1=mysql_query($sel_weightage1);
                                                                    $data_weightage1=mysql_fetch_array($ptr_weightage1);
                                                                    '<br>'. $per_perc=($final_per/100)*$data_weightage1['percentage'];
                                                                    $sel_weightage2="select percentage from pm_weightage where 1 and name='target'";
                                                                    $ptr_weightage2=mysql_query($sel_weightage2);
                                                                    $data_weightage2=mysql_fetch_array($ptr_weightage2);
                                                                    '<br>'. $tar_perc=($targets_points/100)*$data_weightage2['percentage'];
                                                                    $yearly_per=($per_perc+$tar_perc);
                                                                    ?>
                                                                    <tr style="background-color:#e9e8e8;">
                                                                        <td colspan="2" align="center" > Total Percentage of Completed Targets (For Selected Date Range)</td>
                                                                        <td colspan="1"  align="center" style="font-size:15px;color:blue; width:100px;"><b><?php echo round($targets_cmplt)?></b></td>
                                                                        <td colspan="1"  align="center" style="font-size:15px;color:blue; width:100px;" ><b><?php echo round($targets_qult)?></b></td>
                                                                        <td colspan="3"  align="center" style="font-size:17px;color:#fa6015;; width:100px;"><b> Total Target Percentage : <?php echo round($targets_points)?>%</b></td>
                                                                    </tr>
                                                                    <?php
                                                                }
                                                                ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </tr>
                                                <tr>
                                                    <div class="box-body">
                                                        <table class="table no-margin" style="text-align:center">
                                                            <thead>
                                                                <tr ><h2 style="text-align:center">Final Records</h2></tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php
                                                                echo '<tr style="background-color:#e9e8e8;font-size:22px !important">';
                                                                    echo '<td colspan="2" align="center" style="font-size:16px;color:"><b>Performance Percentage ('.$data_weightage1['percentage'].'% weightage)</b></td>';
                                                                    echo '<td colspan="2" align="center" style="font-size:16px;"><b>Target Percentage + Target Quality ('.$data_weightage2['percentage'].'% weightage)</b></td>';
                                                                    echo '<td colspan="2" align="center" style="font-size:16px;"><b>Final Performance</b></td>';
                                                                    echo '<td colspan="2" align="center" style="font-size:16px;"><b>Issuse Damage Value</b></td>';
                                                                echo '</tr>';
                                                                echo '<tr style="background-color:#e9e8e8;font-size:22px !important">';
                                                                    echo '<td colspan="2" align="center" style="font-size:16px;color:#fa6015"> <b>'.round($per_perc).'</b></td>';
                                                                    echo '<td colspan="2"  align="center" style="font-size:16px;color:#fa6015; "><b>'.round($tar_perc).'</b></td>';
                                                                    echo '<td colspan="2"  align="center" ><span style="font-size:24px;color:red;text-shadow: 1.5px 1.5px black;"><b>'.round($yearly_per).'% </b></span></td>';
                                                                    echo '<td colspan="2"  align="center" style="font-size:16px;color:blue; "><b>'.round($damage_val).' rs</b></td>';
                                                                echo '</tr>';
                                                                ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </tr>
                                                <?php
                                            }
                                            ?>
                                        </table>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
        <?php include "include/footer-main.php"; ?>
    </div>
    <!-- jQuery 3 -->
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- Select2 -->
    <script src="bower_components/select2/dist/js/select2.full.min.js"></script>
    <!-- InputMask -->
    <script src="plugins/input-mask/jquery.inputmask.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
    <script src="plugins/input-mask/jquery.inputmask.extensions.js"></script>
    <!-- date-range-picker -->
    <script src="bower_components/moment/min/moment.min.js"></script>
    <script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
    <!-- bootstrap datepicker -->
    <script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <!-- bootstrap color picker -->
    <script src="bower_components/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
    <!-- bootstrap time picker -->
    <script src="plugins/timepicker/bootstrap-timepicker.min.js"></script>
    <!-- SlimScroll -->
    <script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
    <!-- iCheck 1.0.1 -->
    <script src="plugins/iCheck/icheck.min.js"></script>
    <!-- FastClick -->
    <script src="bower_components/fastclick/lib/fastclick.js"></script>
    <!-- AdminLTE App -->
    <script src="dist/js/adminlte.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>
    <!-- Page script -->
    <script>
        $(function () {
            //Initialize Select2 Elements
            $('.select2').select2()

            //Datemask dd/mm/yyyy
            /*$('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
            //Datemask2 mm/dd/yyyy
            $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
            //Money Euro
            $('[data-mask]').inputmask()
        
            //Date range picker
            $('#reservation').daterangepicker()
            //Date range picker with time picker
            $('#reservationtime').daterangepicker({ timePicker: true, timePickerIncrement: 30, format: 'MM/DD/YYYY h:mm A' })
            //Date range as a button
            $('#daterange-btn').daterangepicker(
              {
                ranges   : {
                  'Today'       : [moment(), moment()],
                  'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                  'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
                  'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                  'This Month'  : [moment().startOf('month'), moment().endOf('month')],
                  'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                },
                startDate: moment().subtract(29, 'days'),
                endDate  : moment()
              },
              function (start, end) {
                $('#daterange-btn span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
              }
            )*/

            //Date picker
            // $('#from_date').datepicker({
            //     autoclose: true,
            //     format: 'dd/mm/yyyy',
            //     // startDate: '-0d',
            //     Default: true,
            //     todayHighlight: true
            // })
            // $('#to_date').datepicker({
            //     autoclose: true,
            //     format: 'dd/mm/yyyy',
            //     Default: true,
            //     todayHighlight: true
            // })
            $('#date1').datepicker({
                autoclose: true,
                format: 'mm/yyyy',
                minViewMode: 1,
                todayHighlight: true
            });

            $('#date2').datepicker({
                autoclose: true,
                format: 'mm/yyyy',
                minViewMode: 1,
                todayHighlight: true
            });

            //iCheck for checkbox and radio inputs
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            })
            //Red color scheme for iCheck
            $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
                checkboxClass: 'icheckbox_minimal-red',
                radioClass: 'iradio_minimal-red'
            })
            //Flat red color scheme for iCheck
            $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-green'
            })
            $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-yellow'
            })

            //Colorpicker
            $('.my-colorpicker1').colorpicker()
            //color picker with addon
            $('.my-colorpicker2').colorpicker()

            //Timepicker
            $('.timepicker').timepicker({
                showInputs: false
            })
        })
    </script>
    <?php
	// if($_SESSION['type']!='S' || $edit_access!='yes'){
		?>
    <script>
        // branch = document.getElementById("branch_name").value;
        // select_staff(branch);
    </script>
    <?php
	// }
	?>
</body>

</html>