<?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>Daily Performance Cron Run</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>

<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>
                    Update Performance Report
                    <!--<small>Version 2.0</small>-->
                </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 -->
            <section class="content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="box box-info">
                            <?php
                            // update pm_daily_emp_performance set `staff_id`='289',`staff_type`='LD',`status`='present',`date`='2023-06-20',`task_percentage`='34',`task_quality_percentage`='67',`key_point_percentage`='100',`student_feedback_percentage`='',`councelling_point`='67',`lead_point`='',`feedback_management_approach`='',`total_hour`='8',`hour_not_worked`='0',`total_percentage`='121',`point_reduce`='0',`final_percentage`='121' ,`added_date`='2023-06-21 18:31:05' ,`admin_id`='289',`cm_id`='2' where staff_id='289'and date='2023-06-20'
                            if(isset($_POST['submit']))
                            {
                            
                                $frm_date=explode("/",$_POST['start_date']);
                                $frm_dates=$frm_date[2]."-".$frm_date[1]."-".$frm_date[0];
                                $start_date=$frm_dates;
                                $date=date('Y-m-d',strtotime($frm_dates));
                                    $date.'<br>';
                                    $sel_admin_id="select admin_id,name,type,cm_id from site_setting where 1 and system_status='Enabled' and admin_id='289'";
                                    $ptr_admin_id=mysql_query($sel_admin_id);
                                    while($data_admin_id=mysql_fetch_array($ptr_admin_id))
                                    {
                                        // ============================== Updating in-complete task =====================================
                                        $sel_in_complete="select staff_task_id,points,staff_id,cm_id,admin_id from tk_individual_task where DATE(due_date) ='".$date."' and staff_id='".$data_admin_id['admin_id']."' and status='in_progress'";
                                        $ptr_in_complt=mysql_query($sel_in_complete);
                                        while($data_in_cmplt=mysql_fetch_array($ptr_in_complt))
                                        {
                                            $point=$data_in_cmplt['points'];
                                            $points='-'.$point;
                                            $rating_point='0';
                                            $ins_per="insert into tk_employee_performance (`staff_task_id`,`staff_id`,`earn_points`,`rating_point`,`date`,`cm_id`,`admin_id`)values('".$data_in_cmplt['staff_task_id']."','".$data_in_cmplt['staff_id']."','".$points."','".$rating_point."','".$date."','".$data_in_cmplt['cm_id']."','".$data_in_cmplt['admin_id']."')";
                                            $ptr_p=mysql_query($ins_per);
                                        
                                            $update_status="update tk_individual_task set `status`='in_complete',`earn_points`='".$points."',`rating_point`='".$rating_point."',`sta_updated_admin_id`='".$data_in_cmplt['admin_id']."',`sta_complete_date`='".date('Y-m-d : H:i:s')."' where staff_task_id='".$data_in_cmplt['staff_task_id']."'";
                                            $ptr_ins_t=mysql_query($update_status); 
                                        }
                                        // =============================== Task Point And Task Quality Point ================================
                                            $sel_task_per="select earn_points,rating_point,staff_task_id from tk_employee_performance where date='".$date."' and staff_id='".$data_admin_id['admin_id']."'";
                                            $ptr_task_per=mysql_query($sel_task_per);
                                            $count=mysql_num_rows($ptr_task_per);
                                            $task_point1=0;
                                            $qualty_point=0;
                                            $task_quality_point=0;
                                            while($data_task_per=mysql_fetch_array($ptr_task_per))
                                            {
                                                
                                                //  '<br>staff_id-'.$data_admin_id['admin_id']. '---- staff_name-'.$data_admin_id['name'];
                                                
                                                $task_point1+=$data_task_per['earn_points'];
                                                $qualty_point=$data_task_per['rating_point'];
                                                $task_quality_point+=$qualty_point;
                                            }
                                            $task_point=$task_point1;
                                            $tot_cont=$count*100;
                                            $tot_quality_point= ($task_quality_point/$tot_cont)*100;
                                            // $task_tot_point=$task_point+$tot_quality_point;
                                            // $task_hour='';
                                            '<br>' .$sel_hour="select sum(hours) as today_hour from tk_individual_task where 1 and DATE(added_date)='".$date."
                                            ' and staff_id='".$data_admin_id['admin_id']."' and status!='halt' and status!='cancle' and Validation='valid '";
                                            $ptr_hour=mysql_query($sel_hour);
                                            $data_hour=mysql_fetch_array( $ptr_hour);
                                            '<br>'. $today_hours=$data_hour['today_hour'];
                                            '<br>'. $task_hour=$today_hours/60;
                                    
                                            '<br>'. $sel_key_point_per="select total_percentage,status from pm_total_keypoint_performancee where date='".$date."' and employee_id='".$data_admin_id['admin_id']."'";
                                            $ptr_key_point_per=mysql_query($sel_key_point_per);
                                            $tot_kpi_record=mysql_num_rows($ptr_key_point_per);
                                            // $task_point='';
                                            // $tot_key_point='';
                                            $data_key_point_per=mysql_fetch_array($ptr_key_point_per);
                                                '<br>staff_name-'.$data_admin_id['name'];
                                                $tot_key_point=$data_key_point_per['total_percentage'];
                                                $tot_conc_pnt=0;
                                                // if($data_admin_id['type']=='C' || $data_admin_id['type']=='A')
                                                // {
                                                    '<br>' .$sel_conc_pnt="select total_minute from tk_sales_point where 1 and DATE(added_date)='".$date."' and staff_id='".$data_admin_id['admin_id']."' and total_minute >0";
                                                    $ptr_conc_pnt=mysql_query($sel_conc_pnt);
                                                    $tot_sale_record=mysql_num_rows($ptr_conc_pnt);
                                                    $data_conc_pnt=mysql_fetch_array( $ptr_conc_pnt);
                                                    $tot_conc_time=$data_conc_pnt['total_minute'];
                                                    '<br>Tot Councillor point '.$tot_conc_pnt=round($tot_conc_time*0.208);
                                                    '<br>Tot Councillor Hour '.$tot_conc_hour= $tot_conc_time/60;
                                                // }
                                            // ======================Student performance for faculty=================
                                            if($data_admin_id['type']=='F')
                                            {
                                                    //$sel_student_batch="select distinct(batch_id) from student_batch_feedback where staff_id='".$data_admin_id['admin_id']."' and attendance_date='".$date."'";
                                                    $sel_student_batch="select DISTINCT(s.course_batch_id) as batch_id from student_attendence s, course_batch_mapping b where s.course_batch_id=b.c_b_id and b.staff_id='".$data_admin_id['admin_id']."' and DATE(s.attendence_date)='".$date."'";
                                                    $ptr_student_batch=mysql_query($sel_student_batch);
                                                    $tot_batch_id=mysql_num_rows($ptr_student_batch);
                                                    '<br> today batch- '. $batch_cnt=$tot_batch_id*100;
                                                    $i=1;
                                                    $total_feedback_point=0;
                                                    $total_feedback_percentage=0;
                                                    while($data_student_batch=mysql_fetch_array($ptr_student_batch))
                                                    {
                                                        //taking all present student of perticular batch
                                                        $sel_tot_batch_std="select count(enroll_id) as student_count from student_attendence where attendence='present' and course_batch_id='".$data_student_batch['batch_id']."' and attendence_date='".$date."'";
                                                        $ptr_count=mysql_query($sel_tot_batch_std);
                                                        $data_count=mysql_fetch_array( $ptr_count);
                                                        $tot_std_fed=$data_count['student_count'];
                                                        '<br> present student- '.$point_cnt=$tot_std_fed*100;
                                                        '<br>'.$sel_std_fed="select teaching_method,monitoring_class,faculty_behaviour,class_attention,management_approach,phone_submission from student_batch_feedback where staff_id='".$data_admin_id['admin_id']."' and batch_id='".$data_student_batch['batch_id']."' and attendance_date='".$date."'";
                                                        $ptr_std_fed=mysql_query($sel_std_fed);
                                                        $tot_std_fed=mysql_num_rows($ptr_std_fed);
                                                        //$point_cnt=$tot_std_fed*100;
                                                        $teaching_method=0;
                                                        $monitoring_class=0;
                                                        $faculty_behaviour=0;
                                                        $class_attention=0;
                                                        $phone_submission=0;
                                                        
                                                        // $tot_managemnt_approch=0;
                                                        while($sata_student_fed=mysql_fetch_array($ptr_std_fed))
                                                        {
                                                            $teaching_method+=$sata_student_fed['teaching_method'];
                                                            $monitoring_class+=$sata_student_fed['monitoring_class'];
                                                            $faculty_behaviour+=$sata_student_fed['faculty_behaviour'];
                                                            $class_attention+=$sata_student_fed['class_attention'];
                                                            $phone_submission+=$sata_student_fed['phone_submission'];
                                                            // $management_approach+=$sata_student_fed['management_approach'];
                                                        }
                                                        '<br> <b> Lecture NO -'.$data_student_batch['batch_id'].'</b>';
                                                        '<br> teaching_method -'.$teaching_method;
                                                        '<br> monitoring_class -'.$monitoring_class;
                                                        '<br> faculty_behaviour -'.$faculty_behaviour;
                                                        '<br> class_attention -'.$class_attention;
                                                        '<br> phone_submission -'.$phone_submission;
                                                        //  '<br> management_approach -'.$management_approach;
                                                        '<br>'.$teaching_method_point=($teaching_method/$point_cnt)*100;
                                                        '<br>'.$monitoring_class_point=($monitoring_class/$point_cnt)*100;
                                                        '<br>'.$faculty_behaviour_point=($faculty_behaviour/$point_cnt)*100;
                                                        '<br>'.$class_attention_point=($class_attention/$point_cnt)*100;
                                                        '<br>'.$phone_submission_point=($phone_submission/$point_cnt)*100;
                                                        //  '<br>'.$management_approach_point=($management_approach/$point_cnt)*100;
                                                        '<br>'.$total_feedback_point=$teaching_method_point+$monitoring_class_point+$faculty_behaviour_point+$class_attention_point+$phone_submission_point;
                                                        '<br> total_percentage = '.$total_feedback_point;
                                                        $total_feedback_percentage+=($total_feedback_point/500)*100;
                                                        //  '<br> Final_percentage one Lecture = '.$total_feedback_percentage;
                                                    }
                                                $tot_daily_feedback_percentage=($total_feedback_percentage/$batch_cnt)*100;
                                                
                                                
                                                //Student Feedback percentage
                                                '<br> ToTal Student Feedback percentage '.$ins_tot_daily_feedback_percentage=round($tot_daily_feedback_percentage);
                                            //    '<br>'.$sel_lec_hour="select distinct(course_batch_id) from student_attendence where attendence_date='".$date."' and admin_id='".$data_admin_id['admin_id']."'";
                                            //   $ptr_lec_hour=mysql_query($sel_lec_hour);
                                            //  $tot_batch_daily=mysql_num_rows($ptr_lec_hour);
                                                '<br> ToTal batch_hour_cnt = '.  $batch_hour_cnt=$tot_batch_id*2.5;
                                            }    
                                            // total task point
                                            '<br> ToTal_Task_Points '.$ins_task_point=round($task_point);
                                            // total task quality point of day out of 100
                                            '<br> ToTal_Task_ Qualty_Points '.$ins_tot_quality_point=round($tot_quality_point);
                                            // total key point of day
                                            '<br> ToTal_Key_Points '.$ins_tot_key_point=round($tot_key_point);
                                    
                                            '<br>'.$sel_minute="select minutes from pm_sales_kpi where action_name='add_lead'";
                                                $ptr_mintute=mysql_query($sel_minute);
                                                $data_minute=mysql_fetch_array($ptr_mintute);
                                                $lead_min=$data_minute['minutes'];
                                                $sel_lead="select count(inquiry_id) as tot_lead from inquiry where DATE(added_date)='".$date."' and admin_id='".$data_admin_id['admin_id']."'";
                                                $ptr_lead=mysql_query($sel_lead);
                                                $lead_record=mysql_num_rows($ptr_lead);
                                                $data_lead=mysql_fetch_array($ptr_lead);
                                                $lead_point=0;
                                                $ins_lead_point=0;
                                                if($lead_record){
                                                '<br>Lead Count- '.$tot_lead=$data_lead['tot_lead'];
                                                '<br>Lead Time- '.$lead_time=$tot_lead*$lead_min;
                                                $lead_hour=$lead_time/60;
                                                '<br>Lead Point- '.$lead_point=$lead_time*0.208;
                                                $ins_lead_point=round($lead_point);
                                                }
                                                // else{
                                                //     '<br>Lead Point- '.$lead_point=0;
                                                //     $ins_lead_point=0;
                                                // }
                                            if($data_admin_id['type']=='F')
                                            {
                                                $hours=7.5;
                                                '<br> Todays hour Reduce - '. $hour_calc=$hours-($task_hour + $batch_hour_cnt);
                                                '<br> Today Hour Work '.$today_hour=$task_hour+ $batch_hour_cnt;
                                    
                                                '<br> Todays hour Reduce Point- '. $hour_reduce_point=round(abs($hour_calc)*13.3);
                                    
                                                $total_day_per=$task_point+$tot_quality_point+$tot_key_point+$tot_daily_feedback_percentage;
                                                // $total_day_per=38+100+100+100;
                                                if($data_hour!='')
                                                {
                                                    if($today_hour <= $hours )
                                                    {
                                                        '<br> divide '.$tot_div=($task_hour*12.5)+300;
                                                        '<br> Todays hour Reduce - '.$hour_reduce=round($hour_calc);
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=abs($hour_calc*60);
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=round($hour_reduce_point);
                                                    }
                                                    elseif($today_hour > $hours)
                                                    {
                                                        '<br> divide '.$tot_div=400;
                                                        '<br> Todays hour Reduce - '.$hour_reduce=0;
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=$hour_reduce;
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=0;
                                                    }
                                                }
                                                else 
                                                {
                                                    if($today_hour < $hours )
                                                    {
                                                        '<br> divide '.$tot_div=200;
                                                        '<br> Todays hour Reduce - '.$hour_reduce=round($hour_calc);
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=abs($hour_calc*60);
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=round($hour_reduce_point);
                                                    }
                                                    elseif($today_hour > $hours)
                                                    {
                                                        '<br> divide '.$tot_div=200;
                                                        '<br> Todays hour Reduce - '.$hour_reduce=0;
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=$hour_reduce;
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=0;
                                                    }
                                                    //  '<br> divide '.$tot_div=200;
                                                }
                                                "<br/> CALC ".$total_day_per.' - '.$tot_div;
                                                $performance=($total_day_per/$tot_div)*100;
                                                if($today_hour >= $hours){
                                                    "<br> Total Hour Work=yes";
                                                $final_performance=$performance+$hour_reduce_point;
                                                '<br> 1 Total One Day Performance without reducing point '.$ins_performance=round($final_performance);
                                                }
                                                elseif( $today_hour < $hours){
                                                    "<br> Total Hour Work=no";
                                                    $final_performance=$performance-$hour_reduce_point;
                                                    '<br> 2Total One Day Performance without reducing point '.$ins_performance=round($performance);
                                                }
                                                '<br> Final One Day Performance '.$ins_final_performance=round($final_performance);   //final_performance
                                            }
                                            // elseif($data_admin_id['type']=='C' || $data_admin_id['type']=='A' || $data_admin_id['type']=='LD')
                                            elseif($tot_sale_record)
                                            {
                                                if($data_admin_id['type']=='A')
                                                {
                                                    $sel_tot_batch_stds="select count(enroll_id) as student_counts from student_attendence where attendence='present' and attendence_date='".$date."'";
                                                    $ptr_counts=mysql_query($sel_tot_batch_stds);
                                                    $data_counts=mysql_fetch_array($ptr_counts);
                                                    $tot_stds_fed=$data_counts['student_counts'];
                                                    '<br>divides - '.$point_cnts=$tot_stds_fed*100;
                                                    '<br>'.$sel_std_fed="select management_approach from student_batch_feedback where 1 and  attendance_date='".$date."'";
                                                    $ptr_std_fed=mysql_query($sel_std_fed);
                                                    $tot_std_fed=mysql_num_rows($ptr_std_fed);
                                                    $management_approach=0;
                                                    $tot_managemnt_approch=0;
                                                    while($sata_student_fed=mysql_fetch_array($ptr_std_fed))
                                                    {
                                                        $management_approach+=$sata_student_fed['management_approach'];
                                                    }
                                                    $management_approach_point=($management_approach/$point_cnts)*100;
                                                    '<br>management_approach- '.$management_pts=$management_approach_point;
                                                    $tot_managemnt_approch=round($management_pts);
                                                    $management_ptot=100;
                                                }
                                                else{
                                                    '<br>management_approach'.$management_pts=0;
                                                    $management_ptot=0;
                                                }
                                                $hours=8;
                                                '<br> Todays hour Reduce - '. $hour_calc=$hours-($task_hour + $tot_conc_hour);
                                                '<br> Today Hour Work '.$today_hour=$task_hour+ $tot_conc_hour;
                                        
                                                '<br> Todays hour Reduce Point- '. $hour_reduce_point=round(abs($hour_calc)*12.5);
                                        
                                                '<br> Todays hour Reduce Point- '. $hour_reduce_point=round(abs($hour_calc)*12.5);
                                                
                                                echo'<br> task_point ='.$task_point ;
                                                echo'<br> task_quality ='. $tot_quality_point ;
                                                echo'<br> kpi ='. $tot_key_point ;
                                                echo'<br> sale point ='.$tot_conc_pnt;
                                                echo'<br> management app ='.$management_pts;
                                                echo'<br> lead Point ='.$lead_point;
                                               echo'<br> tot_point'. $total_day_per=$task_point+$tot_quality_point+$tot_key_point+$tot_conc_pnt+$management_pts+$lead_point;
                                                // $total_day_per=38+100+100+100;
                                                if($task_point!='' && $tot_quality_point!='')
                                                {
                                                    if($today_hour < $hours )
                                                    {
                                                        '<br> divide '.$tot_div=($task_hour*12.5)+300 + $management_ptot;
                                                        '<br> Todays hour Reduce - '.$hour_reduce=round($hour_calc);
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=abs($hour_calc*60);
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=round($hour_reduce_point);
                                                    }
                                                    elseif($today_hour > $hours)
                                                    {
                                                        '<br> divide '.$tot_div=400 +  $management_ptot;
                                                        '<br> Todays hour Reduce - '.$hour_reduce=0;
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=$hour_reduce;
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=0;
                                                    }
                                                }
                                                else 
                                                {
                                                    if($today_hour < $hours )
                                                    {
                                                        '<br> divide '.$tot_div=200 +  $management_ptot;
                                                        '<br> Todays hour Reduce - '.$hour_reduce=round($hour_calc);
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=abs($hour_calc*60);
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=round($hour_reduce_point);
                                                    }
                                                    elseif($today_hour > $hours)
                                                    {
                                                        '<br> divide '.$tot_div=200 +  $management_ptot;
                                                        '<br> Todays hour Reduce - '.$hour_reduce=0;
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=$hour_reduce;
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=0;
                                                    }
                                                }
                                                '<br> divide '.$tot_div;
                                                $performance=($total_day_per/$tot_div)*100;
                                                if($today_hour >= $hours){
                                                    "<br> Total Hour Work=yes";
                                                $final_performance=$performance+$hour_reduce_point;
                                                '<br> Total One Day Performance without reducing point '.$ins_performance=round($final_performance);
                                                }
                                                elseif( $today_hour <= $hours){
                                                    "<br> Total Hour Work=no";
                                                    $final_performance=$performance-$hour_reduce_point;
                                                    '<br> Total One Day Performance without reducing point '.$ins_performance=round($performance);
                                                }
                                                '<br> Final One Day Performance '.$ins_final_performance=round($final_performance);   //final_performance
                                        
                                            }
                                        else{
                                                $hours=8;
                                                // '<br>'.$sel_minute="select minutes from pm_sales_kpi where action_name='add_lead'";
                                                // $ptr_mintute=mysql_query($sel_minute);
                                                // $data_minute=mysql_fetch_array($ptr_mintute);
                                                // $lead_min=$data_minute['minutes'];
                                                // $sel_lead="select count(inquiry_id) as tot_lead from inquiry where DATE(added_date)='".$date."' and admin_id='".$data_admin_id['admin_id']."'";
                                                // $ptr_lead=mysql_query($sel_lead);
                                                // $data_lead=mysql_fetch_array($ptr_lead);
                                                // '<br>Lead Count- '.$tot_lead=$data_lead['tot_lead'];
                                                // '<br>Lead Time- '.$lead_time=$tot_lead*$lead_min;
                                                // $lead_hour=$lead_time/60;
                                                // '<br>Lead Point- '.$lead_point=$lead_time*0.208;
                                                // $ins_lead_point=round($lead_point);
                                                // echo'<br>Lead Point- '.$lead_quality=100;
                                                $today_hour=$task_hour+$lead_hour;
                                                '<br> Todays hour Reduce - '.$hour_calc=$hours-$today_hour;
                                                 '<br> Today Hour Work- '.$today_hour;
                                                '<br> Todays hour Reduce Point- '.$hour_reduce_point=abs($hour_calc)*12.5;
                                            
                                                '<br>'.$total_day_per=$task_point+$lead_point+$tot_quality_point+$tot_key_point;
                                                // '<br> Todays hour Reduce - '.$hour_calc=$hours-$task_hour;
                                                // '<br> Today Hour Work- '.$task_hour;
                                                // '<br> Todays hour Reduce Point- '.$hour_reduce_point=abs($hour_calc)*12.5;
                                    
                                                // '<br>'.$total_day_per=$task_point+$tot_quality_point+$tot_key_point;
                                                // '<br>'.$total_day_per=110+100+100;
                                                // if($task_hour < $hours ){
                                                //      '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=$hour_reduce_point;
                                                // }
                                                // elseif($task_hour > $hours){
                                                //      '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=0;
                                                // }
                                                $performance=($total_day_per/300)*100;
                                                // $final_performance=$performance $hour_reduce_point;
                                                
                                                if( $today_hour >= $hours){
                                                    "<br> Total Hour Work=yes";
                                                    '<br> Todays hour Reduce - '.$hour_reduce=0;
                                                    '<br> Todays Minute Reduce - '. $minute_reduce=$hour_reduce;
                                                    '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=0;
                                                    $final_performance=$performance+$hour_reduce_point;
                                                    '<br> Total One Day Performance without reducing point '.$ins_performance=round($final_performance);
                                                    }
                                                    elseif( $today_hour <= $hours){
                                                        "<br>  Total Hour Work=no";
                                                        '<br> Todays hour Reduce - '.$hour_reduce=round($hour_calc);
                                                        '<br> Todays Minute Reduce - '. $minute_reduce=abs($hour_calc*60);
                                                        '<br> Todays hour Reduce Point- '. $hour_reduce_point_f=round($hour_reduce_point);
                                                    $final_performance=$performance-$hour_reduce_point;
                                                    '<br> Total One Day Performance without reducing point '.$ins_performance=round($performance);
                                                    }
                                                '<br> Final One Day Performance '.$ins_final_performance=round($final_performance);
                                            }
                                    // }
                                    // http://localhost/faculty_login-1/performance_calc.php
                                    // select distinct(course_batch_id) from student_attendence where attendence_date='2022-09-01' and admin_id='244'
                                    // if($tot_kpi_record!=''){
                                        '<br>'.$selct_record="select * from pm_daily_emp_performance where 1 and staff_id='".$data_admin_id['admin_id']."' and date='".$date."'";
                                        $ptr_record=mysql_query($selct_record);
                                        $data_records=mysql_fetch_array($ptr_record);
                                        $data_date=$data_records['date'];
                                        $data_staff=$data_records['staff_id'];
                                        if( $data_date &&  $data_staff){
                                            if($data_key_point_per['status']=='present')
                                            {
                                                echo '<br>'.$upd_query="update pm_daily_emp_performance set `staff_id`='".$data_staff."',`staff_type`='".$data_admin_id['type']."',`status`='".$data_key_point_per['status']."',`date`='".$data_date."',`task_percentage`='".$ins_task_point."',`task_quality_percentage`='".$ins_tot_quality_point."',`key_point_percentage`='".$ins_tot_key_point."',`student_feedback_percentage`='".$ins_tot_daily_feedback_percentage."',`councelling_point`='".$tot_conc_pnt."',`lead_point`='".$ins_lead_point."',`feedback_management_approach`='".$tot_managemnt_approch."',`total_hour`='".$hours."',`hour_not_worked`='".$minute_reduce."',`total_percentage`='".$ins_performance."',`point_reduce`='".$hour_reduce_point_f."',`final_percentage`='".$ins_final_performance."' ,`added_date`='".$data_records['added_date']."' ,`admin_id`='".$data_admin_id['admin_id']."',`cm_id`='".$data_admin_id['cm_id']."' where staff_id='".$data_admin_id['admin_id']."'and date='".$date."'";
                                                $ptr_Update=mysql_query($upd_query);
                                            }
                                            elseif($data_key_point_per['status']=='absent')
                                            {
                                                 '<br>'. $sel_key_point_pers="select total_percentage from pm_total_keypoint_performancee where date='".$data_date."' and employee_id='".$data_staff."'";
                                                $ptr_key_point_pers=mysql_query($sel_key_point_pers);
                                                $data_key_point_pers=mysql_fetch_array($ptr_key_point_pers);
                                                 '<br>staff_name-'.$data_admin_id['name'];
                                                $tot_key_points=$data_key_point_pers['total_percentage'];
                                                 '<br>'.$upd_querys="update pm_daily_emp_performance set `staff_id`='".$data_staff."',`staff_type`='".$data_admin_id['type']."',`status`='absent',`date`='".$data_date."',`task_percentage`='0',`task_quality_percentage`='0',`key_point_percentage`='".$tot_key_points."',`student_feedback_percentage`='0',`councelling_point`='0',`lead_point`='0',`feedback_management_approach`='0',`total_hour`='0',`hour_not_worked`='0',`total_percentage`='".$tot_key_points."',`point_reduce`='0',`final_percentage`='".$tot_key_points."' ,`added_date`='".$data_records['added_date']."' ,`admin_id`='".$data_admin_id['admin_id']."',`cm_id`='".$data_admin_id['cm_id']."' where staff_id='".$data_admin_id['admin_id']."'and date='".$date."'";
                                                $ptr_Updates=mysql_query($upd_querys);
                                            }
                                        }
                                        else
                                        {
                                            if($data_key_point_per['status']=='present')
                                            {
                                                '<br>'.$ins_performance="insert into pm_daily_emp_performance (`staff_id`,`staff_type`,`status`,`date`,`task_percentage`,`task_quality_percentage`,`key_point_percentage`,`student_feedback_percentage`,`councelling_point`,`lead_point`,`feedback_management_approach`,`total_hour`,`hour_not_worked`,`total_percentage`,`point_reduce`,`final_percentage`,`added_date`,`admin_id`,`cm_id`)values('".$data_admin_id['admin_id']."','".$data_admin_id['type']."','present','".$date."','".$ins_task_point."','".$ins_tot_quality_point."','".$ins_tot_key_point."','".$ins_tot_daily_feedback_percentage."','".$tot_conc_pnt."','".$ins_lead_point."','".$tot_managemnt_approch."','".$hours."','".$minute_reduce."','".$ins_performance."','".$hour_reduce_point_f."','".$ins_final_performance."','".date('Y-m-d : H:i:s')."','".$_SESSION['admin_id']."','".$data_admin_id['cm_id']."')";
                                                $ptr_ins_performance=mysql_query($ins_performance);
                                            }
                                            elseif($data_key_point_per['status']=='absent')
                                            {
                                                '<br>'. $sel_key_point_per="select total_percentage from pm_total_keypoint_performancee where date='".$date."' and employee_id='".$data_admin_id['admin_id']."'";
                                                $ptr_key_point_per=mysql_query($sel_key_point_per);
                                                $data_key_point_per=mysql_fetch_array($ptr_key_point_per);
                                                '<br>staff_name-'.$data_admin_id['name'];
                                                $tot_key_point=$data_key_point_per['total_percentage'];
                                    
                                                '<br>'.$ins_performance="insert into pm_daily_emp_performance (`staff_id`,`staff_type`,`status`,`date`,`task_percentage`,`task_quality_percentage`,`key_point_percentage`,`student_feedback_percentage`,`councelling_point`,`lead_point`,`feedback_management_approach`,`total_hour`,`hour_not_worked`,`total_percentage`,`point_reduce`,`final_percentage`,`added_date`,`admin_id`,`cm_id`)values('".$data_admin_id['admin_id']."','".$data_admin_id['type']."','absent','".$date."','0','0','".$tot_key_point."','0','0','0','0','0','0','".$tot_key_point."','0','".$tot_key_point."','".date('Y-m-d : H:i:s')."','".$_SESSION['admin_id']."','".$data_admin_id['cm_id']."')";
                                                $ptr_ins_performance=mysql_query($ins_performance);
                                            }
                                        }
                                    
                                    //   '<hr>';
                                    }

                            }
                            ?>
                            <table>
                                <form name="performance_form" method="post">
                                    <tr>
                                        <td>
                                            <div>
                                                <input type="text" name="start_date" class="input_text datepicker"
                                                    placeholder="From Date" id="datepicker" title="From Date"
                                                    value="<?php  echo date('d/m/Y',strtotime('-1 days')) ?>">
                                            </div>
                                        </td>
                                        <td width="5px"></td>
                                        <td>
                                            <input type="submit" name="submit" value="Update Record"
                                                class="btn btn-block btn-success">
                                        </td>
                                    </tr>
                                </form>
                            </table>
                        </div>
                    </div>
                </div>
            </section>
        </div>
        <!-- /.content-wrapper -->
        <?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()
            //Date picker
            $('#datepicker').datepicker({
                autoclose: true,
                format: 'dd/mm/yyyy',
                // startDate: '-0d',
                Default: true,
                todayHighlight: true
            })


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