<style>
    .info-box{
            /* box-shadow: 2px 2px 5px 3px #414a4c; */
            /* border-radius: 10px 35px;  */
            /* text-shadow: 2px 2px 4px #000000; */
            text-align:center;
            align-items: center;
        }
    .info-box:hover {
            transform: scale(1.1);
        }
    .colors{
        color:black;
        /* font-weight: bold; */
    }
    .textcolor{
        color:white;
        /* font-weight: bold; */
    }
</style>
<link rel="stylesheet" href="../../bower_components/morris.js/morris.css">

<section class="content-header">
                <div class="row">
                    <?php
                        $days=date("l");
                        if($days=='Tuesday'){
                            $dates=date("Y-m-d",strtotime('-3days'));
                        }
                        else{
                            $dates=date("Y-m-d",strtotime('-2days'));
                        }
                        $my_task="select final_percentage from pm_daily_emp_performance where 1 and staff_id='".$_SESSION['admin_id']."' and DATE(date)='".$dates."' order by date DESC";
                        $ptr_data=mysql_query($my_task);
                        $data_performance=mysql_fetch_array($ptr_data);
                        $performance= $data_performance['final_percentage'];
                    ?>
                    <div class="col-md-2 col-sm-6 col-xs-12">
                        <div class="info-box bg-Orange">
                            <h4 align="center" class="colors">Self Performance</h4>
                            <h5 align="center" class="colors">Date : 
                                <?php 
                                if($days=='Tuesday'){
                                    echo $dates=date('d-m-Y',strtotime('-3 days'));
                                }
                                else{
                                    echo $dates=date('d-m-Y',strtotime('-2 days'));
                                }
                                ?>
                            </h5>
                            <h5 align="center">
                                <strong class="colors">
                                <?php 
                                    echo $performance.'%';
                                ?>
                                </strong>
                            </h5>
                        </div>
                    </div>
                    <?php
                        $datess=date('m',strtotime('-1 month'));
                        $my_perf="select performance_percentage,month from pm_monthly_performance where 1 and staff_id='".$_SESSION['admin_id']."' and month='".$datess."' order by date DESC";
                        $ptr_perf=mysql_query($my_perf);
                        $data_perf=mysql_fetch_array($ptr_perf);
                        $month_performance= $data_perf['performance_percentage'];
                    ?>
                    <div class="col-md-2 col-sm-6 col-xs-12">
                        <div class="info-box bg-olive">
                            <h4 align="center" class="colors">Self Performance</h4>
                            <h5 align="center" class="colors">Month : <?php echo date('M',strtotime('-1 month')); ?></h5>
                            <h5 align="center" class="colors">
                                <strong>
                                <?php 
                                    echo $month_performance.'%';
                                ?>
                                </strong>
                            </h5>
                        </div>
                    </div>
                    <?php
                    $date=date("Y-m-d");
                    $sel_task_h="select sum(hours) as tot_hour from tk_individual_task where 1 and staff_id='".$_SESSION['admin_id']."' and DATE(added_date)='". $date."' and status!='cancel' and Validation='valid'";
                    $ptr_task_h=mysql_query( $sel_task_h);
                    $data_task_h=mysql_fetch_array( $ptr_task_h);
                    ?>
                    <div class="col-md-2 col-sm-6 col-xs-12">
                        <div class="info-box bg-fuchsia">
                            <h4 align="center" class="colors">Today's Task Assign Hour</h4>
                            <h5 align="center" class="colors"><strong>
                                <?php 
                                if( $data_task_h['tot_hour']!=''){
                                    $hours= $data_task_h['tot_hour'];
                                    $time1= convertToHoursMins($hours, '%02d hour %02d min');
                                    echo $time1;
                                }
                                else{
                                    echo '0';
                                }      
                                ?>
                            </strong></h5>
                        </div>
                    </div>
                    <?php
                    $sel_task_c="select sum(hours) as tot_cmplt_hour from tk_individual_task where 1 and staff_id='".$_SESSION['admin_id']."' and DATE(sta_complete_date)='". $date."' and status='complete'";
                    $ptr_task_c=mysql_query( $sel_task_c);
                    $data_task_c=mysql_fetch_array( $ptr_task_c);
                    ?>
                    <div class="col-md-2 col-sm-6 col-xs-12">
                        <div class="info-box bg-teal">
                            <h4 align="center" class="colors">Today's Task Completed Hour</h4>
                            <h5 align="center" class="colors"><strong>
                                <?php
                                if( $data_task_c['tot_cmplt_hour']!='')
                                {
                                    $tot_complete=$data_task_c['tot_cmplt_hour'];
                                    $complt_time= convertToHoursMins($tot_complete, '%02d hour %02d min');
                                    echo  $complt_time;
                                }
                                else{
                                    echo '0';
                                }  
                                ?> 
                            </strong></h5>
                        </div>
                    </div>
                    <?php
                    if($_SESSION['type']=='F')
                    {
                        $sel_student_batch="select distinct(c_b_id) from batch_timetable where staff_id='".$_SESSION['admin_id']."' and date='".$date."'";
                        $ptr_student_batch=mysql_query($sel_student_batch);
                        $tot_batch_id=mysql_num_rows($ptr_student_batch);
                        ?>
                        <div class="col-md-2 col-sm-6 col-xs-12">
                            <div class="info-box bg-green">
                                <h4 align="center" class="colors">Today's Batch </h4>
                                <div align="center" class="colors"> Total Batch : <?php echo  $tot_batch_id; ?> </div>
                                <div align="center" class="colors"> Total Batch  Time:
                                    <?php 
                                    $batch_time= $tot_batch_id*2.5;
                                    $hour=  $batch_time*60 ;
                                    $time= convertToHoursMins($hour, '%02d hour %02d min');
                                    echo  $time;
                                    ?>
                                </div>
                            </div>
                        </div>
                        <?php
                    }
                    if($_SESSION['type']=='S' || $edit_access=='yes')
                    {
                        $sel_task_p="select count(staff_task_id) as tot_count from tk_individual_task where 1 and Validation='pending' and status='in_progress'";
                        $ptr_student_pen=mysql_query($sel_task_p);
                        $tot_pending=mysql_fetch_array( $ptr_student_pen);
                        ?>
                        <div class="col-md-2 col-sm-6 col-xs-12">
                            <div class="info-box bg-red">
                                <h4 align="center" class="colors">All Validation Pending Records</h4>
                                <h4 align="center" class="colors"><strong><?php echo  $tot_pending['tot_count']; ?></strong> </h4>
                            </div>
                        </div>
                        <?php
                    }
                    else if($manager_access=='manager')
                    {
                        $sel_task_pe="select count(staff_task_id) as tot_cou from tk_individual_task where 1 and Validation='pending' and status='in_progress' and (".$string.")";
                        $ptr_student_pe=mysql_query($sel_task_pe);
                        $tot_pe=mysql_fetch_array( $ptr_student_pe);
                        ?>
                        <div class="col-md-2 col-sm-6 col-xs-12">
                            <div class="info-box bg-red">
                                <h4 align="center" class="colors">Team Validation Pending Records</h4>
                                <h4 align="center" class="colors"><strong><?php echo  $tot_pe['tot_cou']; ?></strong> </h4>
                            </div>
                        </div>
                        <?php
                    }
                    else
                    {
                        $sel_task_ps="select count(staff_task_id) as tot_counts from tk_individual_task where 1 and Validation='pending' and status='in_progress' and staff_id='".$_SESSION['admin_id']."'";
                        $ptr_student_pens=mysql_query($sel_task_ps);
                        $tot_pendings=mysql_fetch_array( $ptr_student_pens);
                        ?>
                        <div class="col-md-2 col-sm-6 col-xs-12">
                            <div class="info-box bg-red">
                                <h4 align="center" class="colors">My Validation Pending Records</h4>
                                <h5 align="center" class="colors"><strong><?php echo  $tot_pendings['tot_counts']; ?></strong> </h5>
                            </div>
                        </div>
                        <?php
                    }
                    $per_date=" and DATE(date )='".date('Y-m-d',strtotime($dates))."'";
                    if($_SESSION['type']=='S' || $edit_access=='yes')
                    {
                        '<br>'.$sel_per="select final_percentage from pm_daily_emp_performance where 1 ".$per_date." and cm_id='2' and status='present'";
                        $ptr_per=mysql_query($sel_per);
                        $tot=mysql_num_rows( $ptr_per);
                        $tot_div= $tot*100;
                        while($data_per=mysql_fetch_array($ptr_per)){
                            $branch_per+=$data_per['final_percentage'];
                        }
                        $final_branch_per= ($branch_per/$tot_div)*100;
                        $perf_title='All Employee Performance';
                    }
                    else if($manager_access=='manager')
                    {
                        $sel_sept_staff="SELECT * FROM dept_employee where 1 and ".$dept_string." ";
                        $ptr_sept_staff=mysql_query($sel_sept_staff);
                        $tot_staff=mysql_num_rows($ptr_sept_staff);
                        $tot_div= $tot_staff*100;
                        while($data_sept_staff=mysql_fetch_array($ptr_sept_staff))
                        {
                            '<br>'.$sel_per="select final_percentage from pm_daily_emp_performance where 1 ".$per_date." and cm_id='2' and status='present' and staff_id='".$data_sept_staff['staff_id']."'";
                            $ptr_per=mysql_query($sel_per);
                            $data_per=mysql_fetch_array($ptr_per);
                            $branch_per+=$data_per['final_percentage'];
                        }
                        '<br>'.$final_branch_per= ($branch_per/$tot_div)*100;
                        $perf_title='Team Performance';
                    }
                    if($_SESSION['type']=='S' || $edit_access=='yes' || $manager_access=='manager')
                    {
                        ?>
                        <div class="col-md-2 col-sm-6 col-xs-12">
                            <div class="info-box bg-Purple">
                                <h4 align="center" class="textcolor"><?php echo $perf_title ?></h4>
                                <h5 align="center" class="textcolor">Date : 
                                    <?php 
                                    if($days=='Tuesday'){
                                        echo date('d-m-Y',strtotime('-3 days'));
                                    }
                                    else{
                                        echo date('d-m-Y',strtotime('-2 days'));
                                    }
                                    ?>
                                </h5>   
                                <h5 align="center" class="textcolor">
                                    <strong>
                                        <?php 
                                            echo round($final_branch_per).'%';
                                        ?>
                                    </strong>
                                </h5>
                            </div>
                        </div>
                        <?php
                    }
                    ?>
                </div>
                <div class="row">
                    <div class="col-lg-8">
                        <div class="row">
                            <?php
                            if($_SESSION['type']=='S' || $edit_access=='yes')
                            {
                                '<br>'.$selincom="select count(staff_task_id) as totcount from tk_individual_task where 1 and status='in_complete'";
                                $ptr_selincom=mysql_query($selincom);
                                $tot_selincom=mysql_fetch_array( $ptr_selincom);
                                ?>
                                <div class="col-md-3 ">
                                    <div class="info-box bg-gray">
                                        <h4 align="center" class="colors">All In-Complete Records</h4>
                                        <h4 align="center" class="colors"><strong><?php echo  $tot_selincom['totcount']; ?></strong> </h4>
                                    </div>
                                </div>
                                <?php
                            }
                            else if($manager_access=='manager')
                            {
                        
                                '<br>'.$selincom="select count(staff_task_id) as totcount from tk_individual_task where 1 and status='in_complete' and ".$string."";
                                $ptr_selincom=mysql_query($selincom);
                                $tot_selincom=mysql_fetch_array( $ptr_selincom);
                                ?>
                                <div class="col-md-3">
                                    <div class="info-box bg-gray">
                                        <h4 align="center" class="colors">Team In-Complete Records</h4>
                                        <h4 align="center" class="colors"><strong><?php echo  $tot_selincom['totcount']; ?></strong> </h4>
                                    </div>
                                </div>
                                <?php
                            }
                            else
                            {
                                '<br>'.$selincom="select count(staff_task_id) as totcount from tk_individual_task where 1 and status='in_complete' and  staff_id='".$_SESSION['admin_id']."'";
                                $ptr_selincom=mysql_query($selincom);
                                $tot_selincom=mysql_fetch_array( $ptr_selincom);
                                ?>
                                <div class="col-md-3 ">
                                    <div class="info-box bg-gray">
                                        <h4 align="center"class="colors" >My In-Complete Records</h4>
                                        <h4 align="center" class="colors"><strong><?php echo  $tot_selincom['totcount']; ?></strong> </h4>
                                    </div>
                                </div>
                                <?php
                            }
                            if($_SESSION['type']=='S' || $edit_access=='yes')
                            {
                                '<br>'.$selincom="select count(staff_task_id) as totcount from tk_individual_task where 1 and status='in_progress'";
                                $ptr_selincom=mysql_query($selincom);
                                $tot_selincom=mysql_fetch_array( $ptr_selincom);
                                ?>
                                <div class="col-md-3 ">
                                    <div class="info-box bg-yellow">
                                        <h4 align="center" class="colors">All In-Progress Records</h4>
                                        <h4 align="center" class="colors"><strong><?php echo  $tot_selincom['totcount']; ?></strong> </h4>
                                    </div>
                                </div>
                                <?php
                            }
                            else if($manager_access=='manager')
                            {
                        
                                '<br>'.$selincom="select count(staff_task_id) as totcount from tk_individual_task where 1 and status='in_progress' and ".$string."";
                                $ptr_selincom=mysql_query($selincom);
                                $tot_selincom=mysql_fetch_array( $ptr_selincom);
                                ?>
                                <div class="col-md-3">
                                    <div class="info-box bg-yellow">
                                        <h4 align="center" class="colors">Team In-Progress Records</h4>
                                        <h4 align="center" class="colors"><strong><?php echo  $tot_selincom['totcount']; ?></strong> </h4>
                                    </div>
                                </div>
                                <?php
                            }
                            else
                            {
                                '<br>'.$selincom="select count(staff_task_id) as totcount from tk_individual_task where 1 and status='in_progress' and staff_id='".$_SESSION['admin_id']."'";
                                $ptr_selincom=mysql_query($selincom);
                                $tot_selincom=mysql_fetch_array( $ptr_selincom);
                                ?>
                                <div class="col-md-3 ">
                                    <div class="info-box bg-yellow">
                                        <h4 align="center" class="colors">My In-Progress Records</h4>
                                        <h4 align="center" class="colors"><strong><?php echo  $tot_selincom['totcount']; ?></strong> </h4>
                                    </div>
                                </div>
                                <?php
                            }
                            $datess=date('m',strtotime('-1 month'));
                            if($datess=='12')
                            {
                                $years1=date('Y',strtotime('-1 year'));
                            }
                            else{
                                $years1=date('Y');
                            }
                            if($_SESSION['type']=='S' || $edit_access=='yes')
                            {
                                '<br>'.$my_perf="select performance_percentage,month from pm_monthly_performance where 1 and month='".$datess."' and year='".$years1."' and cm_id='2'";
                                $ptr_perf=mysql_query($my_perf);
                                '<br>'.$month_rec=mysql_num_rows($ptr_perf);
                                $month_per='';
                                while($data_perf=mysql_fetch_array($ptr_perf))
                                {
                                    $month_per+=$data_perf['performance_percentage'];
                                }
                                '<br>'.$month_div= $month_rec*100;
                                '<br>'.$final_month_per= ($month_per/$month_div)*100;
                                $title1='All Employee Performance';
                            }
                            else if($manager_access=='manager')
                            {
                                $sel_sept_staff="SELECT * FROM dept_employee where 1 and ".$dept_string." ";
                                $ptr_sept_staff=mysql_query($sel_sept_staff);
                                $month_per='';
                                $tot='';
                                while($data_sept_staff=mysql_fetch_array($ptr_sept_staff))
                                {
                                    '<br>'.$sel_staff="select admin_id from site_setting where 1 and admin_id='".$data_sept_staff['staff_id']."' and system_status='Enabled'"; 
                                    $ptr_staff=mysql_query($sel_staff);
                                    '<br>'.$month_rec=mysql_num_rows($ptr_staff);
                                    while($data_dep_staff=mysql_fetch_array($ptr_staff))
                                    {
                                        '<br>'.$my_perf="select performance_percentage,month from pm_monthly_performance where 1 and month='".$datess."' and year='".$years1."' and cm_id='2' and staff_id='".$data_dep_staff['admin_id']."'";
                                        $ptr_perf=mysql_query($my_perf);
                                        // echo'<br>'.$month_=mysql_num_rows($ptr_perf);
                                        $data_perf=mysql_fetch_array($ptr_perf);
                                        // '<br>'.$data_perf['performance_percentage'];
                                        $month_per+=$data_perf['performance_percentage'];
                                    }
                                    '<br>'.$tot+=$month_rec;
                                }
                                '<br>'.$month_div= $tot*100;
                                '<br>'.$final_month_per= ($month_per/$month_div)*100;
                                $title1='Team Employee Performance';
                            }
                            if($_SESSION['type']=='S' || $edit_access=='yes' || $manager_access=='manager')
                            {
                                ?>
                                <div class="col-md-3">
                                    <div class="info-box bg-lime">
                                        <h4 align="center" class="colors"><?php echo $title1?></h4>
                                        <h5 align="center" class="colors">Month : <?php echo date('M',strtotime('-1 month')); ?></h5>
                                        <h5 align="center" class="colors">
                                            <strong>
                                            <?php 
                                                echo round($final_month_per).'%';
                                            ?>
                                            </strong>
                                        </h5>
                                    </div>
                                </div>
                                <?php
                            }
                            ?>
                            <div class="col-md-3">
                                <div class="info-box bg-blue">
                                    <h4 align="center" class="textcolor"><?php echo date("l") ?></h4>
                                    <h5 align="center" class="textcolor"><?php echo date("d-m-Y ") ?></h5>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <br>
                            <div style="margin-left:30%;width:395px">
                                <div class="nav-tabs-custom" style="background-color:lightblue">
                                    <ul class="nav nav-tabs">
                                        <li class="active"><a><b>Tabular View</b></a></li>
                                        <li ><a href="tk_dashboard_view.php" ><b>Graphical View</b></a></li>
                                        <li ><a href="tk_calendar.php" ><b>Calendar View</b></a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4">
                        <!-- <div class="col-md-4 "> -->
                            <div class="info-box bg-snow">
                                <!-- <h4 align="center" class="colors">Line Chart</h4> -->
                                <?php
                                $first_dates=date("Y-m-d",strtotime('-7days'));

                                // echo '<br>'.$daily_all_per="select final_percentage from pm_daily_emp_performance where 1 and date>='".$first_dates."' and cm_id='2' and status='present'";
                                ?>
                                <div class="box-body chart-responsive">
                                    <div class="chart" style="height:170px;">
                                    <canvas id="alldaily"  ></canvas>  
                                    <div style="text-align:center"><strong>Date </strong></div>
                                    </div>
                                <?php
                                    // $first_date='2023-06-19';
                                    $end_dates=date("Y-m-d",strtotime('-1days'));
                                    $sel_dates_d="select distinct(date) from pm_daily_emp_performance where 1 and date>='".$first_dates."' and cm_id='2' and status='present'";
                                    $ptr_dates_d=mysql_query($sel_dates_d);
                                    $date_all_array=[];
                                    $performance_all_array=[];
                                    while($data_datesd=mysql_fetch_array($ptr_dates_d)){
                                        '<br>'.$daily_all_per="select date,final_percentage from pm_daily_emp_performance where 1 and date='".$data_datesd['date']."' and cm_id='2' and status='present'";
                                        // echo $daily_all_per="select date,final_percentage from pm_daily_emp_performance where 1 and date>='".$first_dates."' and staff_id='".$_SESSION['admin_id']."' order by id ASC";
                                        $ptr_all_daily_per=mysql_query($daily_all_per);
                                        $tot_all=mysql_num_rows($ptr_all_daily_per);
                                        $branch_all_per='';
                                        while($data_all_daily_per=mysql_fetch_array($ptr_all_daily_per)){
                                            $branch_all_per+=$data_all_daily_per['final_percentage'];
                                        }
                                        '<br>'.$tot_div_all= $tot_all*100;
                                        $date_all_array[]=date("d",strtotime($data_datesd['date']));
                                        '<br>'.$final_all_per=($branch_all_per/$tot_div_all)*100;
                                        '<br>'. $performance_all_array[]=$final_all_per;
                                    }
                                    $perf_title='All Employee Performance';
                                //     print_r($date_all_array).'<br>';
                                //    print_r($performance_all_array);
                                ?>
                                    
                                </div>
                            </div>
                        <!-- </div> -->
                    </div>
                </div>
            </section>
            <!-- 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>
    const dateallarray=<?php echo json_encode($date_all_array);?>;
    const performanceallarray=<?php echo json_encode($performance_all_array);?>;
    var myChart = new Chart(alldaily, {
    type: 'line',
    data: {
        
        // labels: [ 'Green', 'Green', 'Green', 'Green', 'Purple', 'Orange'],
        labels: dateallarray,
        datasets: [{
            label: 'All Employee Performance',
            data: performanceallarray,
            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'
                }
            }
        }
    }
   
});
</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>
    <script src="../../bower_components/raphael/raphael.min.js"></script>
<script src="../../bower_components/morris.js/morris.min.js"></script>
