<?php include 'inc_classes.php'; 

include "admin_authentication.php";
include "include/headHeader.php";
?>

<?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>Graphical View</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">

    <!-- Morris chart -->

    <!-- <link rel="stylesheet" href="bower_components/morris.js/morris.css"> -->
    <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">

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


    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- <script src="https://cdn.jsdelivr.net/npm/chart.js@3.5.1/dist/chart.min.js"></script> -->
    <!-- <script src="https://cdn.jsdelivr.net/npm/chart.js@3.5.1/dist/chart.min.js"></script> -->
    
    <link rel="stylesheet"

        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

</head>
<script>
    function sel_branch(branch) {
        // alert(branch);
        var branch_data ="action=user_interface&branch_names=" + branch;
        alert(branch);
        $.ajax({
            url: "tk_dashboard_ajax.php", type: "post", data: branch_data, cache: false,
            success: function (retadmin) {
                alert(retadmin);
                document.getElementById("report").innerHTML = retadmin;

            }
        });
    }
</script>
<?php

 function convertToHoursMins($time, $format = '%02d:%02d') {

    if ($time < 1) {

        return;

    }

    $hours = floor($time / 60);

    $minutes = ($time % 60);

    return sprintf($format, $hours, $minutes);

}

?>

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

        <!-- ================= boxes starts================ -->
        <?php include "include/tk_header_box.php"; ?>
        <!-- ================= boxes end================ -->
        <!-- main body code start -->

            <section class="content">
                <div class="row">
                    <!-- <div style="margin-left:30%;width:395px">
                        <div class="nav-tabs-custom" style="background-color:lightblue">
                            <ul class="nav nav-tabs">
                                <li ><a href="tk_dashboard.php" ><b>Tabular View</b></a></li>
                                <li class="active"><a data-toggle="tab" ><b>Graphical View</b></a></li>
                                <li ><a href="tk_calendar.php" ><b>Calendar View</b></a></li>
                            </ul>
                        </div>
                    </div> -->
                <?php
                $days=date("l");
                if($_SESSION['type']=='S' || $edit_access=='yes'){
                ?>
                    <div class="box box-primary">
                        <div class="box-body">   
                            <div class="table-responsive">
                                <table class="table no-margin" >
                                    <tr> 
                                        <td>
                                            <?php
                                            if($days=='Tuesday'){
                                                $dates_p=date("Y-m-d",strtotime('-3days'));
                                                // $dates_p='2023-06-26';
                                                $dates_per=date("d-M-Y",strtotime('-3days'));
                                            }
                                            else{
                                            $dates_p=date("Y-m-d",strtotime('-2days'));
                                            // $dates_p='2023-06-26';
                                            $dates_per=date("d-M-Y",strtotime('-2days'));
                                            } 
                                            ?>
                                            <!-- <div>
                                                <select class="form-control select2" id="branch_name1" style="width:150px" name="branch_name1" onchange="sel_branch(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_name1'])
                                                    //         {
                                                    //             $sel='selected="selected"';
                                                    //                             }
                                                    //         echo '<option '.$sel.' value="'.$data_branch['branch_name'].'" >'.$data_branch['branch_name'].'</option>';
                                                    //     }
                                                    ?>
                                                <!-- </select>
                                            </div> -->
                                            <!-- <div id="report"> -->
                                                <div style="text-align:center;font-weight: bold;font-size: 20px;">
                                                    <span> Employee Performance : <?php echo $dates_per ?></span>
                                                </div>
                                                <?php
                                                    //  $cm_ids=$_REQUEST['branch'];
                                                    $daily_per_emp="select date,final_percentage,staff_id from pm_daily_emp_performance where 1 and date ='".$dates_p."' and status='present'  order by id ASC";  //and cm_id='".$_SESSION['cm_id']."'
                                                    $ptr_daily_per_emp=mysql_query($daily_per_emp);
                                                    $staff_id=[];
                                                    $daily_performance_array_emp=[];
                                                    // $bgcolor_array=[];
                                                    // $bgcolor_array1=[];
                                                    while($data_daily_per_emp=mysql_fetch_array($ptr_daily_per_emp)){
                                                    // if($data_daily_per_emp['final_percentage']<0){
                                                    //     $bgcolors='rgba(255, 73, 45, 1)';
                                                    // }
                                                    // elseif($data_daily_per_emp['final_percentage']>0){
                                                    //     $bgcolors1='rgba(35, 138, 53, 1)';
                                                    // }
                                                    // $bgcolor_array[]=$bgcolors;
                                                    // $bgcolor_array1[]=$bgcolors1;
                                                    $daily_performance_array_emp[]=$data_daily_per_emp['final_percentage'];
                                                    $sel_name="select name from site_setting where 1 and admin_id='".$data_daily_per_emp['staff_id']."'";
                                                    $ptr_name=mysql_query($sel_name);
                                                    $data_name=mysql_fetch_array( $ptr_name);
                                                    $staff_id[]=$data_name['name'];
                                                    }
                                                    // print_r($staff_id);
                                                ?>
                                                <canvas id="emp_report"></canvas> 
                                                <!-- <input type="text" name="branch" id="branch_name" value="<?php //echo $_SESSION['cm_id']?>"/>  -->
                                                <div style="text-align:center"><strong>Staff Name </strong></div>
                                            <!-- </div> -->
                                        </td>    
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                    <?php
                }
                ?>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <div class="box box-primary">
                            <div class="box-body">
                            <div style="text-align:center"><strong> Daily Performance </strong></div>
                                <canvas id="daily"  ></canvas>  
                                <div style="text-align:center"><strong>Date </strong></div>
                               <?php
                                $first_date=date("Y-m-d",strtotime('-12days'));
                                // $first_date='2023-06-19';
                                $daily_per="select date,final_percentage from pm_daily_emp_performance where 1 and date>='".$first_date."' and staff_id='".$_SESSION['admin_id']."' order by id ASC";
                                $ptr_daily_per=mysql_query($daily_per);
                                $date_array=[];
                                $performance_array=[];
                                while($data_daily_per=mysql_fetch_array($ptr_daily_per)){
                                $date_array[]=date("d M",strtotime($data_daily_per['date']));
                                $performance_array[]=$data_daily_per['final_percentage'];
                               }
                            //    print_r($performance_array);
                               ?>
                            </div>
                        </div>
                        <div class="box box-primary">
                            <div class="box-body">
                                <?php
                                 $month=date("m");
                                 $year=date("Y");
                                ?>
                            <div style="text-align:center"><strong>Monthly Performance - <?php echo $year?> </strong></div>
                                <canvas id="month_report"  ></canvas>  
                                <div style="text-align:center"><strong>Months </strong></div>
                               <?php
                               
                                // $month='04';
                                $sel_month="select * from pm_monthly_performance where 1 and month<='".$month."' and year='".$year."' and staff_id='".$_SESSION['admin_id']."' order by id ASC";
                                $ptr_month=mysql_query($sel_month);
                                $month_array=[];
                                $month_per_array=[];
                                while($data_month=mysql_fetch_array($ptr_month))
                                {
                                   $months=$data_month['month'];
                                    // $month_per=date("F",strtotime($data_month['month']));
                                    $month_per = date("F", mktime(0, 0, 0, $months, 10));
                                  

                                    $month_array[]=$month_per;
                                    $month_per_array[]=$data_month['performance_percentage'];
                                }
                            //    print_r($month_per_array);
                               ?>
                            </div>
                        </div>
                    </div>
                    <!-- ============================================== Daily Performane Report ====================================================== -->
                    <div class="col-md-6">
                    <div class="box box-primary">
                        <?php
                        // if($_SESSION['type']=='LD'){
                        ?>
                            <div class="box-header with-border">
                                <div class="box-tools pull-right">
                                    <!-- <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                                    </button>
                                    <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button> -->
                                </div>
                            </div>
                            <div class="box-body">
                           
                            <?php
                            if($days=='Tuesday'){
                                $fdate=date("Y-m-d",strtotime('-3days'));
                                $fdates=date("d-M-Y",strtotime('-3days'));
                            }
                            else{
                                $fdate=date("Y-m-d",strtotime('-2days'));
                                $fdates=date("d-M-Y",strtotime('-2days'));
                            }
                            //    $fdate=date("Y-m-d",strtotime('-2days'));
                            //    $fdates=date("Y-m-d",strtotime('-2days'));

                            //    $fdate='2023-06-26';
                            $daily_per="select * from pm_daily_emp_performance where 1 and date='".$fdate."' and staff_id='".$_SESSION['admin_id']."' order by id ASC";
                            $ptr_performance=mysql_query($daily_per);
                            $data_daily_per=mysql_fetch_array($ptr_performance);
                            $task_performances[]= $data_daily_per['task_percentage'];
                            $task_quality[]= $data_daily_per['task_quality_percentage'];
                            $task_kpi[]= $data_daily_per['key_point_percentage'];
                            $std_feedback[]= $data_daily_per['student_feedback_percentage'];
                            $manag_app[]= $data_daily_per['feedback_management_approach'];
                            $councelling_point[]= $data_daily_per['councelling_point'];
                            $lead_point[]= $data_daily_per['lead_point'];
                            echo '<div style="text-align:center;font-weight: bold;font-size: 20px;">Daily Working Basis Performance</div>';
                            echo '<div style="text-align:center;font-weight: bold;font-size: 20px;"><span> Date : '.$fdates.'</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <span>Performance: '.$data_daily_per['final_percentage'].' %</span></div>';
                            if($data_daily_per['staff_type']=='LD')
                            {
                                if($data_daily_per['lead_point']!='' && $data_daily_per['lead_point']!='0')
                                {
                                    $performances=array_merge($task_performances, $task_quality, $task_kpi, $lead_point);
                                    $labelss=['Task Point '.$data_daily_per['task_percentage'].'%', 'Task Quality '.$data_daily_per['task_quality_percentage'].'%','Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%','Lead Point '.$data_daily_per['lead_point'].'%'];
                                }
                                else
                                {
                                    $performances=array_merge($task_performances, $task_quality, $task_kpi);
                                    $labelss=['Task Point '.$data_daily_per['task_percentage'].'%', 'Task Quality '.$data_daily_per['task_quality_percentage'].'%','Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%'];
                                }
                            }
                            elseif($data_daily_per['staff_type']=='F')
                            {
                                if($data_daily_per['task_percentage']!='' && $data_daily_per['task_percentage']!='0')
                                {
                                    $performances=array_merge($task_performances, $task_quality, $task_kpi, $std_feedback);
                                    $labelss=['Task Point '.$data_daily_per['task_percentage'].'%', 'Task Quality '.$data_daily_per['task_quality_percentage'].'%','Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Student FeedBack '.$data_daily_per['student_feedback_percentage'].'%'];
                                }
                                else
                                {
                                    $performances=array_merge($task_kpi, $std_feedback);
                                    $labelss=['Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Student FeedBack '.$data_daily_per['student_feedback_percentage'].'%'];
                                }
                            }
                            elseif($data_daily_per['staff_type']=='A')
                            {
                                if($data_daily_per['lead_point']!='' && $data_daily_per['lead_point']!='0')
                                {
                                    if($data_daily_per['task_percentage']!='' && $data_daily_per['task_percentage']!='0')
                                    {
                                        $performances=array_merge($task_performances, $task_quality, $task_kpi, $manag_app ,$councelling_point, $lead_point);
                                        $labelss=['Task Point '.$data_daily_per['task_percentage'].'%', 'Task Quality '.$data_daily_per['task_quality_percentage'].'%','Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Management Approach '.$data_daily_per['feedback_management_approach'].'%','Sale Point '.$data_daily_per['councelling_point'].'%','Lead Point '.$data_daily_per['lead_point'].'%'];
                                    }
                                    else
                                    {
                                        $performances=array_merge($task_kpi, $manag_app ,$councelling_point, $lead_point);
                                        $labelss=['Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Management Approach '.$data_daily_per['feedback_management_approach'].'%','Sale Point '.$data_daily_per['councelling_point'].'%','Lead Point '.$data_daily_per['lead_point'].'%'];
                                    }
                                }
                                else
                                {
                                    if($data_daily_per['task_percentage']!='' && $data_daily_per['task_percentage']!='0')
                                    {
                                        $performances=array_merge($task_performances, $task_quality, $task_kpi, $manag_app ,$councelling_point);
                                        $labelss=['Task Point '.$data_daily_per['task_percentage'].'%', 'Task Quality '.$data_daily_per['task_quality_percentage'].'%','Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Management Approach '.$data_daily_per['feedback_management_approach'].'%','Sale Point '.$data_daily_per['councelling_point'].'%'];
                                    }
                                    else
                                    { 
                                        $performances=array_merge($task_kpi, $manag_app ,$councelling_point);
                                        $labelss=['Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Management Approach '.$data_daily_per['feedback_management_approach'].'%','Sale Point '.$data_daily_per['councelling_point'].'%'];
                                    }
                                    
                                }
                            }
                            elseif($data_daily_per['staff_type']=='C')
                            {
                                if($data_daily_per['lead_point']!='' && $data_daily_per['lead_point']!='0')
                                {
                                    if($data_daily_per['task_percentage']!='' && $data_daily_per['task_percentage']!='0')
                                    {
                                        $performances=array_merge($task_performances, $task_quality, $task_kpi,$councelling_point , $lead_point);
                                        $labelss=['Task Point '.$data_daily_per['task_percentage'].'%', 'Task Quality '.$data_daily_per['task_quality_percentage'].'%','Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Sale Point '.$data_daily_per['councelling_point'].'%','Lead Point '.$data_daily_per['lead_point'].'%'];
                                    }
                                    else
                                    { 
                                        $performances=array_merge($task_kpi,$councelling_point , $lead_point);
                                        $labelss=['Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Sale Point '.$data_daily_per['councelling_point'].'%','Lead Point '.$data_daily_per['lead_point'].'%'];
                                    }
                                }
                                else
                                {
                                    if($data_daily_per['task_percentage']!='' && $data_daily_per['task_percentage']!='0')
                                    {
                                        $performances=array_merge($task_performances, $task_quality, $task_kpi,$councelling_point );
                                        $labelss=['Task Point '.$data_daily_per['task_percentage'].'%', 'Task Quality '.$data_daily_per['task_quality_percentage'].'%','Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Sale Point '.$data_daily_per['councelling_point'].'%'];
                                    }
                                    else
                                    { 
                                        $performances=array_merge($task_kpi,$councelling_point );
                                        $labelss=['Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%' ,'Sale Point '.$data_daily_per['councelling_point'].'%'];
                                        //   print_r($labelss);
                                    }
                                }
                            }
                            else
                            {
                                    $performances=array_merge($task_performances, $task_quality, $task_kpi);
                                    $labelss=['Task Point '.$data_daily_per['task_percentage'].'%', 'Task Quality '.$data_daily_per['task_quality_percentage'].'%','Key Performance Indicator '.$data_daily_per['key_point_percentage'].'%'];
                            }
                                // print_r($labelss);
                               ?><br><br>
                                <canvas id="earning"></canvas>
                            </div>
                         
                        </div>
                    </div>
                </div>
                <!-- ======================= Monthly Performance Report ===================================  -->
                <div class="row">
                <div class="col-md-6">
                <?php
                         if($days=='Monday'){
                            $date=date("Y-m-d",strtotime('-2days'));
                            $date_per=date("d-M-Y",strtotime('-2days'));
                          }
                          else{
                            $date=date("Y-m-d",strtotime('-1days'));
                            $date_per=date("d-M-Y",strtotime('-1days'));
                          }
                        // $date=date("Y-m-d",strtotime('-1days'));
                        // $date_per=date("d-M-Y",strtotime('-1days'));
                        $sel_progress="select staff_task_id from tk_individual_task where 1 and DATE(added_date)='".$date."' and staff_id='".$_SESSION['admin_id']."' and Validation='valid' and status!='cancle' and status!='halt'";
                        $ptr_progress=mysql_query($sel_progress);
                        $tot_rec=mysql_num_rows( $ptr_progress);
                        if($tot_rec)
                        {
                            ?>
                            <div class="box box-danger" style="width:300px;margin-left:20%">
                                <div class="box-body">
                                <div style="text-align:center"><strong>Task Status</strong></div>
                                    <canvas id="task"  ></canvas>  
                                    <div style="text-align:center"><strong>Date : <?php echo $date_per ?> </strong></div>
                                    <?php
                                    
                                    //  $date='2023-06-27';
                                    $sel_progress="select count(staff_task_id)as in_progress from tk_individual_task where 1 and DATE(added_date)='".$date."' and staff_id='".$_SESSION['admin_id']."' and status='in_progress' and Validation='valid'";
                                    $ptr_progress=mysql_query($sel_progress);
                                    $data_progress=mysql_fetch_array($ptr_progress);
                                    $inprogress[]=$data_progress['in_progress'];
                                    $sel_incomplete="select count(staff_task_id)as in_complete from tk_individual_task where 1 and DATE(added_date)='".$date."' and staff_id='".$_SESSION['admin_id']."' and status='in_complete' and Validation='valid'";
                                    $ptr_incomplete=mysql_query($sel_incomplete);
                                    $data_incomplete=mysql_fetch_array($ptr_incomplete);
                                    $in_complete[]=$data_incomplete['in_complete'];
                                    $sel_complete="select count(staff_task_id)as complete from tk_individual_task where 1 and DATE(added_date)='".$date."' and staff_id='".$_SESSION['admin_id']."' and status='complete' and Validation='valid'";
                                    $ptr_complete=mysql_query($sel_complete);
                                    $data_complete=mysql_fetch_array($ptr_complete);
                                    $complete[]=$data_complete['complete'];
                                    $daily_task=array_merge($inprogress, $complete, $in_complete);
                                    //   print_r($complete);
                                ?>
                                </div>
                            </div>
                            <?php
                          }
                        ?>
                        </div>
                        <div class="col-md-6">
                        <div class="box box-danger" style="width:300px;margin-left:20%">
                            <div class="box-body">
                            <?php
                            if($days=='Monday'){
                                $work_date=date("Y-m-d",strtotime('-2days'));
                                $work_dates=date("d-M-Y",strtotime('-2days'));
                              }
                              else{
                                $work_date=date("Y-m-d",strtotime('-1days'));
                                $work_dates=date("d-M-Y",strtotime('-1days'));
                              }
                            // $work_date=date("Y-m-d",strtotime('-1days'));
                            // $work_dates=date("d-M-Y",strtotime('-1days'));
                                    // $work_date=date("Y-m-d");
                                    // $work_dates=date("d-M-Y");
                                    if($_SESSION['type']=='F'){
                                        $daily_working_hour=7.5;
                                    }
                                    else{
                                        $daily_working_hour=8;
                                    }
                                    $daily_working_minute=$daily_working_hour*60;
                                    $tot_working_time= convertToHoursMins($daily_working_minute, '%02d hour %02d min');
                                    
                                ?>
                                <div style="text-align:center"><strong>Working Hours : <?php echo $tot_working_time;?></strong></div>
                                <canvas id="working_hour"  ></canvas>  
                                <div style="text-align:center"><strong>Date : <?php echo $work_dates ?> </strong></div>
                                <?php
                                    $hour=0;
                                   
                        // ==================================================task hour =======================================
                                    $sel_hour="select sum(hours)as tot_hour from tk_individual_task where 1 and DATE(added_date)='".$work_date."' and staff_id='".$_SESSION['admin_id']."' and status!='cancel' and status!='halt' and Validation='valid'";
                                    $ptr_hour=mysql_query($sel_hour);
                                    $data_hour=mysql_fetch_array($ptr_hour);
                                    $work_hour=$data_hour['tot_hour'];
                                    $hour= $work_hour/60;
                                    // $hour=7.4;
                                   '<br>'. $not_worked=abs($daily_working_hour-$hour);
                                    $not_work_hour=$not_worked*60;
                                    // $hour_array[]=$hour;
                                    // $not_worked_array[]=$not_worked;
                                    $times1= convertToHoursMins($work_hour, '%02d hour %02d min');
                                     '<br>'.  $times2= convertToHoursMins($not_work_hour, '%02d hour %02d min');
                                    // $array_1[]=$times1;
                                    // $array_2[]=$times2;

                                    $assign_hour=substr($hour,0,3);
                                    '<br>'. $remain_hour=substr($not_worked,0,3);

                                    $hour_array[]=$assign_hour;
                                    $not_worked_array[]=$remain_hour;
                 // =========lead 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 1 and DATE(added_date) ='".$work_date."' and admin_id='".$_SESSION['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;

                                    $tot_lead_hour=$lead_time/60;
                                    $not_lead_time=abs($daily_working_hour-($tot_lead_hour+$hour));
                                    $tot_lead_hour_str=substr($tot_lead_hour,0,3);
                                    $not_lead_time_str=substr($not_lead_time,0,3);
                                    $lead_time_array[]=$tot_lead_hour_str;
                                    $not_lead_time_array[]=$not_lead_time_str;
                                    $not_lead_minute=$not_lead_time*60;
                                    $tot_lead_time1= convertToHoursMins($lead_time, '%02d hour %02d min');
                                    $not_lead_time2= convertToHoursMins($not_lead_minute, '%02d hour %02d min');
                                    // $nos_of_records=mysql_num_rows($ptr_lead);
                                    // if($data_daily_per['lead_point']!=''  && $data_daily_per['lead_point']!='0')
                                    // {
                                    
                // ====================sale point ============================
                                    '<br>' .$sel_conc_pnt="select total_minute from tk_sales_point where 1 and DATE(added_date)='".$work_date."' and staff_id='". $_SESSION['admin_id']."' and total_minute >0";
                                    $ptr_conc_pnt=mysql_query($sel_conc_pnt);
                                    $nos_of_record=mysql_num_rows($ptr_conc_pnt);
                                    $data_conc_pnt=mysql_fetch_array( $ptr_conc_pnt);
                                    $tot_conc_time=$data_conc_pnt['total_minute'];
                                    $time_in_hour=$tot_conc_time/60;

                                    $not_sale=abs($daily_working_hour-($time_in_hour+$hour));
                                    $not_sale_minute=$not_sale*60;
                                    // $tot_sale=$tot_conc_time*60;
                                    $time_in_hour_str=substr($time_in_hour,0,3);
                                    $not_sale_str=substr($not_sale,0,3);
                                    $tot_sale_hour[]= $time_in_hour_str;
                                    $not_sale_array[]= $not_sale_str;
                                    $tot_sale_time1= convertToHoursMins($tot_conc_time, '%02d hour %02d min');
                                    $not_sale_time2= convertToHoursMins($not_sale_minute, '%02d hour %02d min');


                // ========================= batch =================
                                // $sql_query1="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='".$_SESSION['admin_id']."' and attendence_date='".$work_date."'";
                                // $ptr_query=mysql_query($sql_query1);
                                // $no_of_records=mysql_num_rows($ptr_query);
                                $sel_student_batch="select distinct(c_b_id) from batch_timetable where staff_id='".$_SESSION['admin_id']."' and date='".$work_date."'";
                                $ptr_student_batch=mysql_query($sel_student_batch);
                                $no_of_records=mysql_num_rows($ptr_student_batch);
                                $batch_cnt=$no_of_records*100;
                                $tot_batch=2.5*$no_of_records;
                                $not_batch=abs($daily_working_hour-($tot_batch+$hour));
                                $tot_minute1= $tot_batch*60;
                                $tot_minute2= $not_batch*60;
                                $tot_batch_time= convertToHoursMins($tot_minute1, '%02d hour %02d min');
                                '<br>' . $not_batch_time= convertToHoursMins($tot_minute2, '%02d hour %02d min');
                                if($_SESSION['type']=='F')
                                {
                                    $tot_batch_str=substr($tot_batch,0,3);
                                    $not_batch_str=substr($not_batch,0,3);
                                        $batch_time_array[]=$tot_batch_str;
                                        $batch_reamin_array[]=$not_batch_str;

                                        // $workhourarray=array_merge($hour_array,$not_worked);
                                        if($tot_batch+$hour>$daily_working_hour){
                                        if($work_hour!=0 ){
                                            $workhourarray=array_merge($hour_array, $batch_time_array, $batch_reamin_array);
                                            $labels_array=['Task Hour: '.$times1,'Batch Hour: '.$tot_batch_time,'Extra Hour: '.$not_batch_time];
                                        }
                                        else{
                                        $workhourarray=array_merge($batch_time_array, $batch_reamin_array);
                                        $labels_array=['Batch Hour: '.$tot_batch_time,'Remain Hour: '.$not_batch_time];
                                        // $labelss=[''Task Hour'.$data_daily_per['key_point_percentage'].'%' ,'Sale Point '.$data_daily_per['councelling_point'].'%','Lead Point '.$data_daily_per['lead_point'].'%'];
                                        // print_r($workhourarray);
                                        }
                                    }
                                    elseif($tot_batch+$hour<$daily_working_hour){
                                        if($work_hour!=0 ){
                                            $workhourarray=array_merge($hour_array, $batch_time_array, $batch_reamin_array);
                                            $labels_array=['Task Hour: '.$times1 ,'Batch Hour: '.$tot_batch_time,'Remain Hour: '.$not_batch_time];
                                        }
                                        else{
                                        $workhourarray=array_merge($batch_time_array, $batch_reamin_array);
                                        $labels_array=['Batch Hour: '.$tot_batch_time,'Remain Hour: '.$not_batch_time];
                                        // $labelss=[''Task Hour'.$data_daily_per['key_point_percentage'].'%' ,'Sale Point '.$data_daily_per['councelling_point'].'%','Lead Point '.$data_daily_per['lead_point'].'%'];
                                        // print_r($workhourarray);
                                        }
                                    }
                                }
                                elseif($_SESSION['type']=='C' || $_SESSION['type']=='A')
                                {
                                    if(($hour+$time_in_hour)>$daily_working_hour){
                                        if($work_hour!=0 ){
                                            $workhourarray=array_merge($hour_array,$tot_sale_hour ,$not_sale_array);
                                            $labels_array=['Task Hour: '.$times1,'Sale Hour: '.$tot_sale_time1,'Extra Hour: '.$not_sale_time2]; 
                                        }
                                        else{
                                            $workhourarray=array_merge($tot_sale_hour, $not_sale_array);
                                            $labels_array=['Sale Hour: '.$tot_sale_time1,'Extra Hour: '.$not_sale_time2];
                                        }
                                    }
                                    elseif(($hour+$time_in_hour)<$daily_working_hour){
                                        if($work_hour!=0 ){
                                            $workhourarray=array_merge($hour_array,$tot_sale_hour ,$not_sale_array);
                                            $labels_array=['Task Hour: '.$times1,'Sale Hour: '.$tot_sale_time1,'Remain Hour: '.$not_sale_time2]; 
                                            // echo "hello1";
                                        }
                                        else{
                                            // echo $time_in_hour;
                                            $workhourarray=array_merge($tot_sale_hour, $not_sale_array);
                                            $labels_array=['Sale Hour: '.$tot_sale_time1,'Remain Hour: '.$not_sale_time2];   
                                            // echo "hello2";
                                        }
                                    }
                                    //   print_r($workhourarray);
                                }
                                else{
                                                
                                    if($hour>$daily_working_hour){
                                        if($tot_lead!=0 && $tot_lead!=''){
                                            $workhourarray=array_merge($hour_array,$lead_time_array, $not_lead_time_array);
                                            $labels_array=['Task Hour: '.$times1,'Lead Hour: '.$tot_lead_time1,'Extra Hour: '.$not_lead_time2];
                                        }
                                        else{
                                            $workhourarray=array_merge($hour_array, $not_worked_array);
                                            $labels_array=['Task Hour: '.$times1,'Extra Hour: '.$times2];
                                        }
                                    }
                                    elseif($hour<$daily_working_hour){
                                        if($tot_lead!=0 && $tot_lead!=''){
                                            $workhourarray=array_merge($hour_array,$lead_time_array, $not_lead_time_array);
                                            $labels_array=['Task Hour: '.$times1,'Lead Hour: '.$tot_lead_time1,'Remain Hour: '.$not_lead_time2];   
                                        }
                                        else{
                                            $workhourarray=array_merge($hour_array, $not_worked_array);
                                            $labels_array=['Task Hour: '.$times1,'Remain Hour: '.$times2];   
                                        }
                                    }
                                                    // $workhourarray=array_merge($hour_array,$not_worked);
                                                     // print_r($workhourarray);
                                }
                                // print_r($workhourarray);
                                // print_r($labels_array);

                               ?>
                            </div>
                        </div>
            </section>
            <div>

            </div>
        </div>

        <?php include "include/footer-main.php"; ?>

    </div>
<script>

    </script>
    <!-- jQuery 3 -->
    <!-- https://cdn.jsdelivr.net/npm/chart.js@4.3.0/dist/chart.umd.min.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.3.0/dist/chart.umd.min.js"></script>
    <!-- <script src="my_chart.js"></script> -->
    <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-datalabels/2.2.0/chartjs-plugin-datalabels.min.js" integrity="sha512-JPcRR8yFa8mmCsfrw4TNte1ZvF1e3+1SdGMslZvmrzDYxS69J7J49vkFL8u6u8PlPJK+H3voElBtUCzaXj+6ig==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script>
        var earning = document.getElementById('earning').getContext('2d');
        var daily = document.getElementById('daily').getContext('2d');
        var month_report = document.getElementById('month_report').getContext('2d');
        // var task_hour = document.getElementById('task_hour').getContext('2d');
        const percentagearray=<?php echo json_encode($performances);?>;
        const taskarray=<?php echo json_encode($task_performances);?>;
        const qualityarray=<?php echo json_encode($task_quality);?>;
        const kpiarray=<?php echo json_encode($task_kpi);?>;
        const lablearray=<?php echo json_encode($labelss);?>;
        var myChart = new Chart(earning, {
            type: 'polarArea',
            data: {
                // labels: ['Task Point '+taskarray+'%', 'Task Quality '+qualityarray+'%','Key Performance Indicator '+kpiarray +'%'],
                labels:lablearray ,
                datasets: [{
                    label: '',
                    // data: [60, 70, 100],
                    data:percentagearray,
                    backgroundColor: [
                        'rgba(255, 99, 132, 0.7)',
                        'rgba(54, 162, 235, 0.7)',
                        'rgba(35, 138, 53, 0.7) ',
                        'rgba(255, 159, 64, 0.7)',
                        'rgba(227, 221, 45, 0.7)',
                        'rgba(255, 73, 45, 0.7)'
                    ],
                    borderWidth: 1
                }]
            },
            plugins : [ChartDataLabels],
            options: {
                scales: {
                    // y: {
                    //     responsive: true
                    // }
                }
            }
        });
// ============================================================================================
<?php
 if($tot_rec){
?>
 var task = document.getElementById('task').getContext('2d');
const inprogress=<?php echo json_encode($inprogress);?>;
const complete=<?php echo json_encode($complete);?>;
const incomplete=<?php echo json_encode($in_complete);?>;
const dailytask=<?php echo json_encode($daily_task);?>;
// const doughnutLabel;
var myChart = new Chart(task, {
            type: 'doughnut',
            data: {
                labels: ['In_Progress Task-'+inprogress, 'Completed Task - '+complete,'In_Complete Task '+incomplete ],
                datasets: [{
                    label: '',
                    // data: [60, 70, 100],
                    data:dailytask,
                    backgroundColor: [
                        'rgba(227, 221, 45, 1)',
                        'rgba(35, 138, 53, 1) ',
                        'rgba(255, 73, 45, 1)'
                    ],
                    borderWidth: 1
                }]
            },

            plugins : [ChartDataLabels],
            options: {
               
                // plugins:[doughnutLabel],
            },
        });
        // const  doughnutLabel = {
        //         id: 'doughnutLabel',
        //         beforeDatasetsDraw(chart,args,pluginOption){
        //             const {task,data}=chart;
        //             task.save();
        //             const xCoor=Chart.getDatasetMeta(0).data[0].x;
        //             const yCoor=Chart.getDatasetMeta(0).data[0].y;
        //             task.font='bold 30px sans-serif';
        //             task.fillStyle= 'rgba(255, 206, 86, 0.7)';
        //             task.textAlign= 'center';
        //             task.textBaseline= 'middle';
        //             task.fillText('text',xCoor,yCoor);
        //         }
        //     }
           
<?php }?>

const datearray=<?php echo json_encode($date_array);?>;
const performancearray=<?php echo json_encode($performance_array);?>;
var myChart = new Chart(daily, {
    type: 'line',
    data: {
        
        // labels: [ 'Green', 'Green', 'Green', 'Green', 'Purple', 'Orange'],
        labels: datearray,
        datasets: [{
            label: 'Performance (%)',
            data: performancearray,
            backgroundColor: [
                'rgba(255, 99, 132, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'
            ],
            // borderWidth:3,
            pointRadius: 12,
            pointHoverRadius: 15,
            borderWidth: 1
        }]
    },
     plugins : [ChartDataLabels],
    options: {
        scales: {
            y: {
                beginAtZero: true,
                grid:{
                    drawOnChartArea:false,
                    tickColor: 'red'
                },
                ticks: {
                    color: 'blue',
                },
                border: {
                  color: 'black'
                }
            },
            x: {
                // beginAtZero: true
                grid:{
                    drawOnChartArea:false,
                    tickColor: 'red'
                },
                ticks: {
                    color: 'blue',
                },
                border: {
                  color: 'black'
                }
            }
        }
    }
   
});
// =======================================================================================
<?php  if($_SESSION['type']=='S' || $edit_access=='yes'){ ?>
var emp_report = document.getElementById('emp_report').getContext('2d');
const daily_performance_array_emp=<?php echo json_encode($daily_performance_array_emp);?>;
// const bgcolor_array=<?php //echo json_encode($bgcolor_array);?>;
// const bgcolor_array1=<?php //echo json_encode($bgcolor_array1);?>;
const staff_id=<?php echo json_encode($staff_id);?>;
var myChart = new Chart(emp_report, {
    type: 'bar',
    data: {
        
        // labels: [ 'Green', 'Green', 'Green', 'Green', 'Purple', 'Orange'],
        labels: staff_id,
        datasets: [{
            label: 'Performance (%)',
            data: daily_performance_array_emp,
            backgroundColor: [
                'rgba(255, 99, 132, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'
                // 'rgba(227, 221, 45, 1)',
                // 'rgba(35, 138, 53, 1) ',
                // 'rgba(255, 73, 45, 1)'
            ],
            borderWidth: 1
        }]
    },
    options: {
        scales: {
            y: {
                beginAtZero: true,
                grid:{
                    drawOnChartArea:false,
                    tickColor: 'red'
                },
                ticks: {
                    color: 'blue',
                },
                border: {
                  color: 'black'
                }
            },
            x: {
                // beginAtZero: true
                grid:{
                    drawOnChartArea:false,
                    tickColor: 'red'
                },
                ticks: {
                    color: 'blue',
                },
                border: {
                  color: 'black'
                }
            }
        }
    },
    plugins : [ChartDataLabels]
});
<?php
}
?>
// ================================= Month Report ===================================================
const month_array=<?php echo json_encode($month_array);?>;
const month_per_array=<?php echo json_encode($month_per_array);?>;
var myChart = new Chart(month_report, {
    type: 'bar',
    data: {
        
        // labels: [ 'Green', 'Green', 'Green', 'Green', 'Purple', 'Orange'],
        labels: month_array,
        datasets: [{
            label: 'Performance (%)',
            data: month_per_array,
            backgroundColor: [
                'rgba(255, 99, 132, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'
            ],
            borderWidth: 1
        }]
    },
    plugins : [ChartDataLabels],
    options: {
        scales: {
            y: {
                beginAtZero: true,
                grid:{
                    drawOnChartArea:false,
                    tickColor: 'red'
                },
                ticks: {
                    color: 'blue',
                },
                border: {
                  color: 'black'
                }
            },
            x: {
                // beginAtZero: true
                grid:{
                    drawOnChartArea:false,
                    tickColor: 'red'
                },
                ticks: {
                    color: 'blue',
                },
                border: {
                  color: 'black'
                }
            }
        }
    }
});
// ======================= Task Hours ==========================================================
var working_hour = document.getElementById('working_hour').getContext('2d');
const hour_array=<?php echo json_encode($array_1);?>;
const not_worked=<?php echo json_encode($array_2);?>;
const workhourarray=<?php echo json_encode($workhourarray);?>;
const labels_array=<?php echo json_encode($labels_array);?>;
// const doughnutLabel;
var myChart = new Chart(working_hour, {
            type: 'doughnut',
            data: {
                // labels: ['Assign Task Hours - '+hour_array, 'Remain Working Hours - '+not_worked],
                labels:labels_array,
                datasets: [{
                    label: '',
                    // data: [60, 70],
                    data:workhourarray,
                    backgroundColor: [
                        // 'rgba(35, 138, 53, 1) ',
                        // 'rgba(255, 73, 45, 1)',
                        // 'rgba(227, 221, 45, 1)'
                        'rgba(75, 192, 192, 1)',
                        'rgba(153, 102, 255, 1)',
                        'rgba(255, 159, 64, 1)'
                    ],
                    borderWidth: 1
                }]
            },
            plugins : [ChartDataLabels],
           
            options: {
               
                // plugins:[doughnutLabel],
            },
        });

    </script>
     <script src="https://cdn.jsdelivr.net/npm/chart.js@3.5.1/dist/chart.min.js"></script>
    <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>

    <!-- Morris.js charts -->
    <!-- <script src="bower_components/raphael/raphael.min.js"></script>
    <script src="bower_components/morris.js/morris.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>
    <!-- <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>
    <!-- <script src="bower_components/Flot/jquery.flot.js"></script> -->
<!-- FLOT RESIZE PLUGIN - allows the chart to redraw when the window is resized -->
<!-- <script src="bower_components/Flot/jquery.flot.resize.js"></script> -->
<!-- FLOT PIE PLUGIN - also used to draw donut charts -->
<!-- <script src="bower_components/Flot/jquery.flot.pie.js"></script> -->
<!-- FLOT CATEGORIES PLUGIN - Used to draw bar charts -->
<!-- <script src="bower_components/Flot/jquery.flot.categories.js"></script> -->

    <!-- Page script -->
    <?php // if($_SESSION['type']=='S' || $edit_access=='yes'){ 
       ?>
       <script>
        //    branch = document.getElementById("branch_name").value;
        //    sel_branch(branch);
        //    branch1 = document.getElementById("branch_names1").value;
        //    select_admin(branch1);
       </script>
       <?php
    // }
        ?>

    

</body>



</html>