<?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>Performance Report</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
    <!-- daterange picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap datepicker -->
    <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <!-- Bootstrap Color Picker -->
    <link rel="stylesheet" href="bower_components/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css">
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="bower_components/select2/dist/css/select2.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- paginate style -->
    <link rel="stylesheet" href="dist/css/paginate.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
    <!-- Google Font -->
    <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<?php
 function convertToHoursMins($time, $format = '%02d:%02d') {
    if ($time < 1) {
        return;
    }
    $hours = floor($time / 60);
    $minutes = ($time % 60);
    return sprintf($format, $hours, $minutes);
}
?>

<script>
    function select_staff(branch1) {
        var branch_data1 = "action=admin&branch_name1=" + branch1;
        // alert(branch);
        $.ajax({
            url: "tk_staff_ajax.php", type: "post", data: branch_data1, cache: false,
            success: function (retadmin) {
                // alert(retstaff);
                document.getElementById("staff_name1").innerHTML = retadmin;

            }
        });
    }
</script>

<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>
                    All Employee Daily 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">
                    <!-- Left col -->
                    <div class="col-md-12">
                        <!-- TABLE: LATEST ORDERS -->
                        <div class="box box-info">
                            <!-- <div class="nav-tabs-custom"> -->
                              <div class="table-responsive">
                                <table class="table no-margin" >
                                    <form method="get" name="search">
                                        <tr>
                                            <td>
                                              <?php if($_SESSION['type']=='S' || $_SESSION['branch_access']=='yes')
                                              {
                                                ?>
                                                <select class="form-control select2" id="branch_name"
                                                    style="width:220px" name="branch_name">
                                                    <!-- onchange="select_staff(this.value)"; -->
                                                    <option value="">Select Branch</option>
                                                    <?php 
                                                      $sel_branch="select branch_id,branch_name from branch";
                                                      $ptr_sel=mysql_query($sel_branch);
                                                      while($data_branch=mysql_fetch_array($ptr_sel))
                                                      {
                                                        $sel='';
                                                        if($data_branch['branch_name']==$_GET['branch_name'])
                                                        {
                                                          $sel='selected="selected"';
                                                        }
                                                        echo '<option '.$sel.' value="'.$data_branch['branch_name'].'" >'.$data_branch['branch_name'].'</option>';
                                                      }
                                                    ?>
                                                </select>
                                                <?php
                                              }
                                              else
                                              {
                                                ?>
                                                <input type="hidden" name="branch_name" id="branch_name"
                                                      value="<?php echo $_SESSION['branch_name']; ?>" />
                                                <?php
                                              }
                                              ?>
                                            </td>
                                            <?php if($_SESSION['type']=='S' || $edit_access=='yes')
                                                    {
                                                        ?>
                                                        <td>
                                                            <select class="form-control select2" id="dept" style="width:200px"
                                                                name="dept" ;>
                                                                <option value="">Select Department</option>
                                                                <?php 
                                                                $sel_dept="select dept_id,dept_name from emp_dept";
                                                                $ptr_dept=mysql_query($sel_dept);
                                                                while($data_dept=mysql_fetch_array($ptr_dept))
                                                                {
                                                                    $sel='';
                                                                    if($data_dept['dept_id']==$_GET['dept'])
                                                                    {
                                                                    $sel='selected="selected"';
                                                                    }
                                                                    echo '<option '.$sel.' value="'.$data_dept['dept_id'].'" >'.$data_dept['dept_name'].'</option>';
                                                                }
                                                                ?>
                                                            </select>
                                                        </td>
                                                        <?php
                                                    }
                                                    ?> 
                                                    <?php if($manager_access=='manager' && $_SESSION['type']!='S' && $edit_access!='yes')
                                                    {
                                                        ?>
                                                        <td>
                                                            <select class="form-control select2" id="dept" style="width:200px"
                                                                name="dept" ;>
                                                                <option value="">Select Department</option>
                                                                <?php 
                                                                 $sel_dept="select dept_id,dept_name from emp_dept where ".$dept_string.""; 
                                                                $ptr_dept=mysql_query($sel_dept);
                                                                while($data_dept=mysql_fetch_array($ptr_dept))
                                                                {
                                                                    $sel='';
                                                                    if($data_dept['dept_id']==$_GET['dept'])
                                                                    {
                                                                    $sel='selected="selected"';
                                                                    }
                                                                    echo '<option '.$sel.' value="'.$data_dept['dept_id'].'" >'.$data_dept['dept_name'].'</option>';
                                                                }
                                                                ?>
                                                            </select>
                                                        </td>
                                                        <?php
                                                    }
                                                    ?>
                                            <!-- <td width="5px"></td> -->
                                            <td width="">
                                                <input type="text" name="start_date" class="input_text datepicker"
                                                    placeholder="Select Date" id="datepicker" title="Task Date"
                                                    value="<?php echo $_GET['start_date'] ;?>"  style="width:220px">
                                            </td>
                                            <!-- <td width="5px"></td> -->
                                            <td>
                                                <input type="image" src="images/search.jpg" name="search" value="search"
                                                    style="height:32px;">
                                            </td>
                                        </tr>
                                    </form>
                                <tr>
                                <?php
                                if($_REQUEST['start_date'] && $_REQUEST['start_date']!=="0000-00-00" && $_REQUEST['start_date']!="From Date")
                                {
                                    $frm_date=explode("/",$_REQUEST['start_date']);
                                    $frm_dates=$frm_date[2]."-".$frm_date[1]."-".$frm_date[0];
                                    $start_date=$frm_dates;
                                    $dates=" and DATE(date )='".date('Y-m-d',strtotime($frm_dates))."'";
                                }
                                else{
                                    $dates=" and DATE(date )='".date('Y-m-d',strtotime('-2 days'))."'";
                                }
                                if($_REQUEST['branch_name']!='')
                                {
                                  $branch_name=$_REQUEST['branch_name'];
                                  $select_cm_id="select cm_id from site_setting where branch_name='".$branch_name."' and type='A'";
                                  $ptr_cm_id=mysql_query($select_cm_id);
                                  $data_cm_id=mysql_fetch_array($ptr_cm_id);
                                  $search_cm_id="and cm_id='".$data_cm_id['cm_id']."'";
                                }
                                else
                                {
                                  $search_cm_id='and cm_id=2';
                                }
                                // $search=$_REQUEST['staff_name'];
                                if($_REQUEST['staff_name1']!='')
                                {
                                  $staff_id=$_REQUEST['staff_name1'];
                                  $search_staff_id="and staff_id='".$staff_id."'";
                                }
                                else
                                {
                                  $search_staff_id='';
                                }
                                if($_REQUEST['staff_names']!='')
                                {
                                  $admin_ids=$_REQUEST['staff_names'];
                                  $search_admin_id="and assign_by='".$admin_ids."'";
                                }
                                else
                                {
                                  $search_admin_id='';
                                }
                                if($_REQUEST['task_type']!='')
                                {
                                  $task_type=$_REQUEST['task_type'];
                                  $search_task_type="and task_type='".$task_type."'";
                                }
                                else if( $staff_id!='')
                                {
                                  $search_task_type='';
                                }
                                else
                                {
                                  $search_task_type='and task_type="adhoc_task"';
                                }
                                if($_REQUEST['status']!='')
                                {
                                  $status=$_REQUEST['status'];
                                  $search_status="and status='".$status."'";
                                }
                                else
                                {
                                  $search_status='';
                                }
                                if($_REQUEST['dept']!='')
                                  {
                                    $depa_array=array();
                                    $p=0;
                                    $tot_staff='';
                                    $sel_depa="SELECT * FROM emp_dept where 1 and dept_id='".$_REQUEST['dept']."' ";
                                    $ptr_depa=mysql_query($sel_depa);
                                    while($data_depat=mysql_fetch_array($ptr_depa))
                                    {
                                      '<br>'.$sel_sept_staff="SELECT * FROM dept_employee where 1 and dept_id='".$data_depat['dept_id']."' ";
                                        $ptr_sept_staff=mysql_query($sel_sept_staff);
                                        $l=0;
                                        $tot_staff=mysql_num_rows($ptr_sept_staff);
                                        while($data_sept_staff=mysql_fetch_array($ptr_sept_staff))
                                        {
                                            $depa_array[$l][$p]= $data_sept_staff['staff_id'];
                                            $l++;
                                        }
                                        $p++;
                                    }
                                    // array_multisort($staff_array, SORT_ASC,SORT_NUMERIC);
                                    $array_result = [];
                                    foreach ($depa_array as $sub_Array) {
                                        foreach ($sub_Array as $values) {
                                            $array_result[] = $values;
                                        }
                                    }
                                    // '<br><pre>'; print_r($array_result); echo '</pre> <br> <br>'; 
                                    $deptatment = "staff_id=" . implode(" or staff_id=", $array_result);
                                    $deptatments = "admin_id=" . implode(" or admin_id=", $array_result);
                                    if($tot_staff){
                                      $search_dept="and(". $deptatments.")";
                                      $search_depts="and(". $deptatments.")";
                                    }
                                    else{
                                      $search_dept="and admin_id='0'";
                                      $search_depts="and admin_id='0'";
                                    }
                                  }
                                  else{
                                    $search_dept="";
                                    $search_depts="and (".$admins.")";
                                  }
                                $i=1;
                                if($_REQUEST['keyword121']!="keyword121")
                                $search=trim($_REQUEST['keyword121']);
                                if($search)
                                {
                                  $task_search=" and (task_name like '%".$search."%' || priority like '%".$search."%' || status like '%".$search."%')";
                                }
                                else
                                {
                                  $task_search="";
                                }
                                if($_SESSION['type']=='S' || $edit_access=='yes')
                                {
                                  $sel_staff="select admin_id,name,type from site_setting where 1 and system_status='Enabled' ". $search_cm_id." ".$search_dept." order by name asc";
                                }
                                else if($manager_access=='manager')
                                {
                                  $sel_staff="select admin_id,name,type from site_setting where 1 ".$search_depts." and system_status='Enabled' ". $search_cm_id." order by name asc";
                                }
                                // echo $sel_staff;
                                $ptr_staff=mysql_query( $sel_staff);
                                $i=1;
                                ?>
                                <div class="box-body">
                                    <!-- <div class="table-responsive"> -->
                                        <table class="table no-margin" style="text-align:center">
                                            <thead>
                                                <tr>
                                                    <td colspan="12">
                                                        <h4><strong>Branch : <span style="color:blue;">
                                                                    <?php  if($_REQUEST['branch_name']!='')echo ucfirst($_GET['branch_name']); else echo 'Pune';?></strong></span>
                                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Date : <span
                                                                    style="color:blue;">
                                                                    <?php if($_REQUEST['start_date']!='') echo  date("d-m-Y",strtotime($start_date)); else echo date('d-m-Y',strtotime('-2 days'));  ?>
                                                                </span></b>
                                                        </h4>
                                                    </td>
                                                </tr>
                                                <tr style="background-color:rgb(192,192,192)">
                                                    <th style="text-align:center">Sr.No.</th>
                                                    <th style="text-align:center">Staff Name</th>
                                                    <th style="text-align:center">Task point</th>
                                                    <th style="text-align:center">Task Quality point</th>
                                                    <th style="text-align:center">Key Performance Indicators</th>
                                                    <th style="text-align:center">Student Feedback Point</th>
                                                    <th style="text-align:center">Sales Point</th>
                                                    <th style="text-align:center">Management Approach</th>
                                                    <th style="text-align:center">Total Point</th>
                                                    <th style="text-align:center">Hour Not Worked</th>
                                                    <th style="text-align:center">Reduce Point</th>
                                                    <th style="text-align:center">Final Percentage</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                              <?php
                                              $bgColorCounter=1;
                                              while($data_staff=mysql_fetch_array( $ptr_staff))
                                              {
                                                  if($bgColorCounter%2==0){
                                                      $bgcolor='style="background-color:rgb(220,220,220)"';
                                                  }
                                                  else{
                                                      $bgcolor="";    
                                                  }    
                                                '<br/>' . $my_performance="select * from pm_daily_emp_performance where 1 and staff_id='".$data_staff['admin_id']."' ".$dates." ". $search_cm_id."";
                                                  $ptr=mysql_query($my_performance);
                                                  $data_performance=mysql_fetch_array($ptr);
                                                  ?>
                                                <tr <?php echo $bgcolor ?> >
                                                    <td>
                                                        <?php echo $i++ ?>
                                                    </td>
                                                    <td>
                                                        <strong>
                                                            <?php echo strip_tags(ucwords($data_staff['name']))?>
                                                        </strong>
                                                    </td>
                                                    <?php
                                                    if( $data_performance['status']=='present')
                                                    {
                                                      ?>
                                                      <td>
                                                          <strong>
                                                              <?php echo strip_tags(ucwords($data_performance['task_percentage']))?>
                                                          </strong>
                                                      </td>
                                                      <td>
                                                          <strong>
                                                              <?php echo ucfirst($data_performance['task_quality_percentage'])?>
                                                          </strong>
                                                      </td>
                                                      <td>
                                                          <strong>
                                                              <?php echo ucfirst($data_performance['key_point_percentage'])?>
                                                          </strong>
                                                      </td>
                                                      <td>
                                                          <strong>
                                                            <?php
                                                            if($data_staff['type']=='F')
                                                            {
                                                                echo $data_performance['student_feedback_percentage'];
                                                            }
                                                            else{
                                                                echo '<span style="color:blue;">Null</span>';
                                                            }
                                                            ?>
                                                          </strong>
                                                      </td>
                                                      <td>
                                                          <strong>
                                                            <?php
                                                              if($data_staff['type']=='C' || $data_staff['type']=='A' )
                                                              {
                                                                  echo $data_performance['councelling_point'];
                                                              }
                                                              else{
                                                                  echo '<span style="color:blue;">Null</span>';
                                                              }
                                                            ?>
                                                          </strong>
                                                      </td>
                                                      <td>
                                                          <strong>
                                                            <?php
                                                              if($data_staff['type']=='A'  )
                                                              {
                                                                  echo $data_performance['feedback_management_approach'];
                                                              }
                                                              else{
                                                                  echo '<span style="color:blue;">Null</span>';
                                                              }
                                                            ?>
                                                          </strong>
                                                      </td>
                                                      <td>
                                                          <strong>
                                                              <?php echo $data_performance['total_percentage']?>
                                                          </strong>
                                                      </td>
                                                      <td>
                                                          <strong>
                                                              <?php 
                                                                if( $data_performance['hour_not_worked']!='0')
                                                                {
                                                                  $not_working= $data_performance['hour_not_worked'];
                                                                  $tot_hour= convertToHoursMins($not_working, '%02d hour %02d min');
                                                                  echo $tot_hour; 
                                                                }
                                                                else 
                                                                {
                                                                  echo '0';
                                                                }
                                                                ?>
                                                          </strong>
                                                      </td>
                                                      <td>
                                                          <strong>
                                                              <?php echo $data_performance['point_reduce']?>
                                                          </strong>
                                                      </td>
                                                      <?php
                                                    }
                                                    else
                                                    {
                                                    ?>
                                                    <td colspan="9" style="color:red">
                                                        <strong>
                                                            <?php echo ucfirst($data_performance['status'])?>
                                                        </strong>
                                                    </td>
                                                    <?php
                                                    }
                                                    ?>
                                                    <td>
                                                      <strong>
                                                        <?php echo $data_performance['final_percentage'];
                                                          $tot_pecentage+=$data_performance['final_percentage'];
                                                        ?>
                                                      </strong>
                                                    </td>
                                                </tr>
                                                <?php
                        	                      $bgColorCounter++;
                                              }
                                              $sel_per="select final_percentage from pm_daily_emp_performance where 1  ".$dates." ". $search_cm_id." and status='present'";
                                              $ptr_per=mysql_query($sel_per);
                                              $tot=mysql_num_rows( $ptr_per);
                                              $tot_div= $tot*100;
                                              $final_branch_per=0;
                                              while($data_per=mysql_fetch_array($ptr_per)){
                                                $branch_per+=$data_per['final_percentage'];
                                              }
                                              $final_branch_per= ($branch_per/$tot_div)*100;
                                              ?>
                                                <tr>
                                                    <td colspan="5" style="color:">
                                                        <h3><strong>
                                                                <?php  if($_REQUEST['branch_name']!='')echo ucfirst($_GET['branch_name']); else echo 'Pune';?>
                                                                Branch Performance :
                                                            </strong></h3>
                                                    </td>
                                                    <td colspan="" style="color:green">
                                                        <h3><strong>
                                                                <?php echo  round($final_branch_per); ?> %
                                                            </strong></h3>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                </div>
                                    <!-- /.box-body -->
                              </tr>
                            </table>
                          </div>
                        </div>
                            <!-- /.box -->
                      <!-- </div> -->
                        <!-- /.col -->
                    </div>
                </div>
                <!-- /.box -->
            </section>
            <!-- /.content -->
        </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' || $_SESSION['branch_access']!='yes'){
		?>
    <script>
        branch = document.getElementById("branch_name").value;
        select_staff(branch);
    </script>
    <?php
	}
	?>
</body>

</html>