<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005-2006 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of supportpro supportdesk                 |
// +----------------------------------------------------------------------+
// | Authors: sudheesh<sudheesh@armia.com>                                 |
// |                                                                                       // |
// +----------------------------------------------------------------------+


  $page = 'adminmain';
if(include('../fusionchart/Class/FusionCharts.php'))
    if(include('../fusionchart/graph/graph.php'))
        if(!isset($_GET['range']) || $_GET['range']=='Month') {
            $first_day_this_month = date('Y-m-01'); // hard-coded '01' for first day
            $last_day_this_month = date('Y-m-t');
            $where = "dPostDate>='".$first_day_this_month."' AND dPostDate<='".$last_day_this_month."'";
            
             $where1 = "spbl1.dPostDate>='".$first_day_this_month."' AND spbl1.dPostDate<='".$last_day_this_month."'";
             
             $between = "AND posted_date BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."' ";
            // $between1 = "posted_date BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."' ";
            $incident_where = " AND dLastAttempted>='".$first_day_this_month."' AND dLastAttempted<='".$last_day_this_month."'  ";
        }elseif(!isset($_GET['range']) || $_GET['range']=='L_Month'){
           
            
            $lastMOnth =  date('Y-m',  strtotime('-1 month'));
             $first_day_this_month = date("$lastMOnth-01") ;
           // echo $first_day_this_month;// hard-coded '01' for first day
            $last_day_this_month = date("$lastMOnth-t") ;
           // echo $last_day_this_month;
            $where = "dPostDate>='".$first_day_this_month."' AND dPostDate<='".$last_day_this_month."'";
            
             $where1 = "spbl1.dPostDate>='".$first_day_this_month."' AND spbl1.dPostDate<='".$last_day_this_month."'";
             
             $between = "AND posted_date BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."' ";
            // $between1 = "posted_date BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."' ";
            $incident_where = " AND dLastAttempted>='".$first_day_this_month."' AND dLastAttempted<='".$last_day_this_month."'  ";
        
        
        }elseif(!isset($_GET['range']) || $_GET['range']=='Year')
                 {
        $year = date('Y');

        $first_day_this_month = $year.'-'.'01'.'-'.'01';
        $last_day_this_month =  $year.'-'.'12'.'-'.'31';
                 $where = "dPostDate>='".$first_day_this_month."' AND dPostDate<='".$last_day_this_month."'";
                  $where1 = "spbl1.dPostDate>='".$first_day_this_month."' AND spbl1.dPostDate<='".$last_day_this_month."'";
                 $between = "AND posted_date BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."' ";
               //  $between1 = "posted_date BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."' "; 
                 $incident_where = " AND dLastAttempted>='".$first_day_this_month."' AND dLastAttempted<='".$last_day_this_month."'  ";
                 }
                 elseif(!isset($_GET['range']) || $_GET['range']=='Week')
                     {
$first_day_this_month = date('Y-m-d', strtotime('Last Monday', time()));
$last_day_this_month = date('Y-m-d', strtotime('Next Sunday', time()));
  $where = "dPostDate>='".$first_day_this_month."' AND dPostDate<='".$last_day_this_month."'";
  $where1 = "spbl1.dPostDate>='".$first_day_this_month."' AND spbl1.dPostDate<='".$last_day_this_month."'";
  $between = "AND posted_date BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."' ";
//  $between1 = "posted_date BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."' ";
  $incident_where = " AND dLastAttempted>='".$first_day_this_month."' AND dLastAttempted<='".$last_day_this_month."'  ";
                     } elseif(!isset($_GET['range']) || $_GET['range']=='All')
                         {
                         $where = "1";
                          $incident_where = "";
                          $between = " AND 1=1";
                        //  $between1 = " 1=1";
                         }

                         
                         
                         
                         
$sql_ticket = "SELECT vStatus,count(nTicketId) AS c FROM sptbl_tickets WHERE ".$where." AND vDelStatus = 0 GROUP BY vStatus";
//echo $sql_ticket;

$res = mysql_query($sql_ticket);


/************************ New Statics  ***************************/
$depts_id = $_GET['depts'];
if($depts_id =='' || $depts_id=='All')
{
    
    $deptWhere = " AND ti.nDeptId!=0";
}else{
    $deptWhere = " AND ti.nDeptId='".$depts_id."'";
}


$sql_ticket = "SELECT count(nTicketId) AS c,MIN(dPostDate) AS first_date FROM sptbl_tickets ti  WHERE $where $deptWhere AND vDelStatus = 0";
// $sql_ticket.'<br>';
$total_ticket_c = mysql_query($sql_ticket);

$total_ticket_count = mysql_result($total_ticket_c,0,0); 

$now = time(); // or your date as well
     $beginDate = strtotime($first_day_this_month);
     
     //$tatotalDate =  floor($datediff/(60*60*24));
     $tatotalDate = ceil(abs($now - $beginDate) / 86400);
       // echo $tatotalDate.'<br>';
       // echo $total_ticket_count;

if($_GET['range']=='All')
{
    $beginDate = strtotime(mysql_result($total_ticket_c,0,1));
     
     $tatotalDate = ceil(abs(date('Y-m-d H:i:s') - $beginDate) / 86400);
    
}
     
     
     
                         /*New Tickets */
     
 $sqlUnattempt = "select count(statistics_id) as st  from sptbl_ticket_statistics stat INNER JOIN sptbl_tickets ti ON ti.nTicketId = stat.ticket_id  where reply_time = 0  AND vDelStatus = 0 AND vStatus <> 'closed' $between $deptWhere";    
 //echo $sqlUnattempt;
 $total_ticket_unattempt= mysql_query($sqlUnattempt);

 $total_ticket_unattempt_count = mysql_result($total_ticket_unattempt,0,0);    
     
                          /*New Tickets */
 
                          /*Avg Ticket Reply Time*/
 $sqlReplyTime = "select count(statistics_id) as st,SUM(reply_time) as reply from sptbl_ticket_statistics stat INNER JOIN sptbl_tickets ti ON ti.nTicketId = stat.ticket_id where reply_time <> 0 AND closing_time <> 0 AND vDelStatus = 0 $between $deptWhere";    
 $total_avg_reply= mysql_query($sqlReplyTime);
 $st_count = mysql_result($total_avg_reply,0,0);       
 $tot_time = mysql_result($total_avg_reply,0,1);  
                          
  //echo $sqlReplyTime;                        /*Avg Ticket Reply Time*/
 
 
                         /*Avg Ticket Reply Time*/
 $sqlCloseTime = "select count(statistics_id) as st,SUM(closing_time) as reply from sptbl_ticket_statistics stat INNER JOIN sptbl_tickets ti ON ti.nTicketId = stat.ticket_id where closing_time <> 0 AND reply_time <> 0 AND vDelStatus = 0  $between $deptWhere";    
 //ECHO $sqlCloseTime;
 $total_avg_close= mysql_query($sqlCloseTime);
 $st_count_close = mysql_result($total_avg_close,0,0);       
 $tot_time_close = mysql_result($total_avg_close,0,1);  
                          
                          /*Avg Ticket Reply Time*/
 

 
 
 /************************* Code for all Ticket Entry to Statics TABLE **************/

$sql_priority = "SELECT vPriorityDesc,count(nTicketId) AS c FROM sptbl_tickets sptl INNER JOIN sptbl_priorities sp  ON sp.nPriorityValue=sptl.vPriority WHERE ".$where." AND vDelStatus = 0 GROUP BY sptl.vPriority";

$res_priority = mysql_query($sql_priority);

$dept_tickets_q = "SELECT count(nTicketId) AS c,vDeptDesc FROM sptbl_tickets sptl INNER JOIN sptbl_depts sd ON sd.nDeptId=sptl.nDeptId WHERE ".$where." AND vDelStatus = 0 GROUP BY sptl.nDeptId";

$dept_tickets = mysql_query($dept_tickets_q);


$res_staff_rating = "SELECT AVG(nMarks) AS mark,vStaffname FROM sptbl_staffratings str INNER JOIN sptbl_staffs ss ON str.nStaffId = ss.nStaffId GROUP BY str.nStaffId ORDER BY mark DESC LIMIT 0,4";
//echo $res_staff_rating;

$staff_rating = mysql_query($res_staff_rating);
$i=1;
if(mysql_num_rows($res)>0){
$statusName = array();
$statusCount = array();
while($row=mysql_fetch_array($res)) {
    $statusName [] = $row['vStatus'];
    $statusCount[] = $row['c'];
    $i++;

}
    $flag_str = "data";
}else{
    
    $flag_str = "no_data";
}
$statusName  = '"'.implode('","', $statusName).'"';
$statusCount = implode(',',$statusCount);

$j=1;
if(mysql_num_rows($res_priority)>0){
  $priorityName = array();
  $priorityCount = array();
while($row=mysql_fetch_array($res_priority)) {


    $priorityName[]= $row['vPriorityDesc'];
    $priorityCount[] = $row['c'];
    $j++;

}
$flag_strPr = "data";
}else{
    $flag_strPr = "no_data";
}
$priorityName  = '"'.implode('","', $priorityName).'"';
$priorityCount = implode(',',$priorityCount);
$k=1;
if(mysql_num_rows($staff_rating)>0){
  $StaffName = array();
  $StaffMark = array();
while($row=mysql_fetch_array($staff_rating)) {


    $StaffName[] = ucfirst($row['vStaffname']);
    $StaffMark[] = $row['mark'];
    $k++;

}
$flag_strRate = "data";
}else{
    $flag_strRate = "no_data";
}
$StaffName  = '"'.implode('","', $StaffName).'"';
$StaffMark = implode(',',$StaffMark);



$getDepartmentSql = "select * from sptbl_depts where nDeptVisibility = '1' " ;


$getDepartmant = mysql_query($getDepartmentSql);


$incident_query="SELECT MAX( REP.`dDate` ) as rep_date , TCK.dPostDate, REP.`nStaffId`, TCK.nDeptId, TCK.`nTicketId`, STF.vLogin 
FROM sptbl_tickets TCK, `sptbl_replies` REP LEFT JOIN sptbl_staffs STF ON STF.nStaffId = REP.nStaffId 
WHERE TCK.`nTicketId` = REP.`nTicketId`
AND REP.`nUserId` IS NULL
AND TCK.vStatus LIKE 'closed' ".$incident_where."
AND TCK.vDelStatus = 0 GROUP BY REP.`nTicketId`";
//echo $incident_query;
$ticketQry = mysql_query($incident_query);

$slaQry = mysql_query("SELECT nResponseTime, nDeptId FROM `sptbl_depts`");
if(mysql_num_rows($slaQry)) {
    while($slaRes = mysql_fetch_array($slaQry)) {
        $dept[$slaRes['nDeptId']] = $slaRes['nResponseTime'];
    }
}

if($ticketQry) {
    while($ticketRes = mysql_fetch_array($ticketQry)) {
        $diff = (strtotime($ticketRes['rep_date']) - strtotime($ticketRes['dPostDate'])) / 60;
        if($diff > $dept[$ticketRes['nDeptId']]) {
            $staff[$ticketRes['vLogin']]['delayed'][] = $ticketRes['nTicketId'];
        }
        else {
            $staff[$ticketRes['vLogin']]['on_time'][] = $ticketRes['nTicketId'];
        }
    }
    if(count($staff)>0)
    {
    foreach($staff as $key => $val) {
        $staff_total[$key] = count($staff[$key]['delayed']) + count($staff[$key]['on_time']);
    }

    arsort($staff_total);
    }
    $counter = 1;
    if(count($staff_total)>0)
    {
    foreach($staff_total as $key => $val) {
       // if($counter <= 5) {
            if(!isset($staff[$key]['delayed'])) {
                $final_staff[$key]['delayed'] = 0;
            }
            else {
                $final_staff[$key]['delayed'] = count($staff[$key]['delayed']);
            }
            if(!isset($staff[$key]['on_time'])) {
                $final_staff[$key]['on_time'] = 0;
            }
            else {
                $final_staff[$key]['on_time'] = count($staff[$key]['on_time']);
            }
       // }
        $counter++;
    }
    }

   // print_r($final_staff);
}


?>

<style>
.chart1{
display: block;
    width: 300px !important;
    height:250px !important;
  }
.chart2{
display: block;
    
    width: 987px !important;
        height: 350px;
  }
  .chart3{
display: block;
    
    width: 480px !important;
        height: 300px;
  }

</style>
<script language='javascript' src='../fusionchart/JSClass/FusionCharts.js'></script>
<div class="drop_down_container">
  <form name="graphfilter" method="get" action="">
    <div align="right">
        
        <select class="comm_input" onchange="document.graphfilter.submit();" name="range">
            <option value="Month" <?php if($_GET['range']=='Month'){echo "selected";} ?>><?php echo TEXT_MONTH; ?></option>
            <option value="L_Month" <?php if($_GET['range']=='L_Month'){echo "selected";} ?>><?php echo TEXT_LAST_MONTH; ?></option>
            <option value="Week" <?php if($_GET['range']=='Week'){echo "selected";} ?>><?php echo TEXT_WEEK; ?></option>
            <option value="Year" <?php if($_GET['range']=='Year'){echo "selected";} ?>><?php echo TEXT_YEAR; ?></option>
            <option value="All" <?php if($_GET['range']=='All'){echo "selected";} ?>><?php echo TEXT_ALL; ?></option>
      
  </select>
    </div>
 
</div>

<div class="DB_container_1" >
     <div class="DB_container_contentbox1"  style="padding:0;">
         <h2 style="margin:5px 5px 0 5px; "> <?php echo TICKET_STATISTICS ?>  <select class="comm_input" onchange="document.graphfilter.submit();" name="depts" style="float: right;margin-top: -3px;"> 
       <option value="All" <?php if($depts_id=='All'){echo "selected";}?>>All </option>
       <?php
       
       while($row=  mysql_fetch_array($getDepartmant))
       { ?>
           
           <option value="<?php echo $row['nDeptId'];?>" <?php if($depts_id==$row['nDeptId']){echo "selected";}?>> <?php echo $row['vDeptDesc'];?></option>
           
       <?php } ?>
       ?>    
       </select></h2>
      
       
        </form>
       <table style="" width="100%" cellpadding="0" border="0" cellspacing="5" class="ln_ht ticketstatitics">
        <tbody>
               <tr>
                   <td style="text-align:left;" class="col1">
           <h5><?php echo AVERAGE_TICKETS_DAY;?> 
           </h5>
           <p><?php echo ($tatotalDate)?number_format(($total_ticket_count/$tatotalDate),2):0; ?> </p>
           </td>
             
                   <td style="text-align:left;" class="col2">
            <h5><?php echo TOTAL_NEW_TICKETS;?> 
          </h5>
          <p><?php echo ($total_ticket_unattempt_count)?$total_ticket_unattempt_count:0; ?></p>
           </td>
               </tr>
                <tr>
                   <td style="text-align:left;" class="col3">
           <h5><?php echo AVERAGE_REPLY_TIME;?></h5>
           <p><?php echo  (mysql_num_rows($total_avg_reply)!=0 && $st_count!=0)?number_format(($tot_time/$st_count)):0; ?> </p>
           </td>
              
                   <td style="text-align:left;" class="col4">
           <h5><?php echo AVERAGE_REVOLVE_TIME;?></h5>
           <p><?php  echo  (mysql_num_rows($total_avg_close)!=0 && $st_count_close!=0)?number_format(($tot_time_close/$st_count_close)):0; ?></p>
           </td>
               </tr>
           </tbody></table>
</div>
    
    
     <div class="DB_container_contentbox2">
       <h2><?php echo TICKETS_BY_STATUS ?></h2>
      
        <div class="chart1">
             <?php if($flag_str=="data"){?>
       <canvas id= "myChart_1"  height=150 width=300 > </canvas>
             <?php }else{ ?>
             
             <br><br><br><br><br><br>No data to display.
             <?php } ?>
     </div>
    
    </div>
    <div class="DB_container_contentbox1"><h2><?php echo TICKETS_BY_PRIORITY ?></h2>
    
        <div class="DB_container_content">
          <div class="chart1">
             <?php if($flag_strPr=="data"){?>
            <canvas id= "myChart_2"  height=150 width=300 > </canvas>
               <?php }else{ ?>
             
             <br><br><br><br><br><br>No data to display.
             <?php } ?>
          </div>
        </div>
    
    </div>

    <div class="DB_container_contentbox2"><h2><?php echo TICKETS_BY_DEPT ?></h2>
        <?php


        $i=1;
        

//$graphXmlSource = "<chart caption='Plans Chosen By Brands' xAxisName='Month' yAxisName='Units' showValues='0' formatNumberScale='0' showBorder='0'>";
      
        $deptArr= array();
         $deptcountArr= array();
        if(mysql_num_rows($dept_tickets)>0){
        while($row=mysql_fetch_array($dept_tickets)) {
           // echo str_replace("'","_",$row["vDeptDesc"]).$row["c"];
            $deptArr[] = $row["vDeptDesc"];
            $deptcountArr[] = $row["c"];
            $i++;
       }
            $flag_strDept=  "data";
        }else{
             $flag_strDept=  "no_data";
        }
       
      $deptArr    =  '"'.implode('","', $deptArr).'"';
      $deptcountArr =  implode(',',$deptcountArr);

        ?>

      <div class="DB_container_content">
          
      <div class="chart1">
           <?php if($flag_strDept=="data"){?>
       <canvas id= "myChart_3"  height=200 width=300  > </canvas>
       <?php }else{ ?>
             
             <br><br><br><br><br><br>No data to display.
             <?php } ?>
     </div>
        
    </div>
  </div>
    <div class="DB_container_contentbox4"><h2 style="padding-left:80px;"><?php echo CLOSED_BY_OWNER ?></h2>
        <div class="DB_container_content">
            <?php 
            $arrStaffVal = array();
            $arrStaffNames = array();
            if(count($final_staff)>0)
               {
 
$p=2; $l=0;
$arrStaffVal_delayed  = array();
$arrStaffVal_ontime   = array();

                foreach($final_staff as $key =>$val)
                    {
$arrStaffNames[$l] = ucfirst($key);
$arrStaffVal_delayed[] = $val['delayed'];
$arrStaffVal_ontime[] = $val['on_time'];
          $p++;
          $l++;
                    }


$flag_strClosed = "data";

$staffName    =  '"'.implode('","', $arrStaffNames).'"';
$delayedCount =  implode(',',$arrStaffVal_delayed);
$ontimeCount  =  implode(',',$arrStaffVal_ontime);


                //$graphObj3 = new graph(6,400,200);
//$graphObj3->setChartParams("Ticket Status for period of ".date('d/m/Y',strtotime($first_day_this_month))."-".date('d/m/Y',strtotime($last_day_this_month)),'','',0,'');
       // $graphObj3->addChartData($arrStaffVal,$arrStaffNames);

        //$graphObj3->renderChart();
                }else{
                   $flag_strClosed = "no_data"; 
                }
?>
       <div class="chart3">
            <?php if($flag_strClosed=="data"){?>      
       <canvas id= "myChart_4"  height=250 width=400 > </canvas>
            <?php }else{ ?> 
             <br><br><br><br><br><br>No data to display.
             <?php } ?>
       
     </div>


        </div>
    </div>
   <!--  <div class="DB_container_contentbox1"><h2>Closed Incidents by Month</h2>
        <div class="DB_container_content"></div>
    </div> -->
   <div class="DB_container_contentbox5"><h2><?php echo STAFF_RATING_CUSTOMER ?></h2>
        <div class="DB_container_content">
            
              <div class="chart3">
                  
           <?php if($flag_strRate=="data"){?>        
       <canvas id= "myChart_5"   > </canvas>
        <?php }else{ ?>
             
             <br><br><br><br><br><br>No data to display.
             <?php } ?>
     </div>
            </div>
    </div>
</div>

<div class="DB_container_2" >
    <h2><?php echo TRENDING_INFO ?></h2>
    <div class="DB_container_content chart2">
        <?php


        $m=date('m',strtotime('-365days'));
        $y=date('Y',strtotime('-365days'));

        $arrCatName =array();

       
        for($i=1;$i<=12;$i++) {
            $date = date('M/Y',strtotime(date($y.'-'.$m.'-'.'01', strtotime($date)) . $i." month"));
            $arrCatName[$i]  = $date;
            
        }
        //echo"<pre>";print_r($arrCatName);
       
       // $arrData1[0][0] = TEXT_CLOSED;
        // $arrData1[0][1] = "";
        $count_closed  = array();
        $count_pending  = array();
        for($i=1;$i<=12;$i++) {
            $Ym = date('Y',strtotime(date($y.'-'.$m.'-'.'01', strtotime($date)) . $i." month"));
            $mm = date('m',strtotime(date($y.'-'.$m.'-'.'01', strtotime($date)) . $i." month"));
            $st = $Ym.'-'.$mm.'-'.'01';
            $end = $Ym.'-'.$mm.'-'.'31';
            $tick_mont_q = "SELECT nTicketId FROM sptbl_tickets WHERE vStatus='closed' AND vDelStatus = 0 AND dPostDate>='".$st."' AND dPostDate<='".$end."'";
//echo $tick_mont_q;
            $tick_count = mysql_query($tick_mont_q);
            $count_closed[] = mysql_num_rows($tick_count);
          //  $arrData1[0][$i+1] =$count;
           
            

        }
        // echo"<pre>";print_r($count_closed);
       // $arrData1[1][0] = TEXT_PENDING;
       //  $arrData1[1][1] = "";
        for($i=1;$i<=12;$i++) {
            $Ym = date('Y',strtotime(date($y.'-'.$m.'-'.'01', strtotime($date)) . $i." month"));
            $mm = date('m',strtotime(date($y.'-'.$m.'-'.'01', strtotime($date)) . $i." month"));
            $st = $Ym.'-'.$mm.'-'.'01';
            $end = $Ym.'-'.$mm.'-'.'31';
            $tick_mont_o = "SELECT nTicketId FROM sptbl_tickets WHERE dLastAttempted>='".$st."' AND dLastAttempted<='".$end."' AND vDelStatus = 0";
            $tick_count = mysql_query($tick_mont_o);
           $count_pending[] = mysql_num_rows($tick_count);
           // $arrData1[1][$i+1] = $count;
            

        }

 
 $arrCatName    =  '"'.implode('","', $arrCatName).'"';
 $count_closed =  implode(',',$count_closed);
 $count_pending  =  implode(',',$count_pending);
 
        ?>

<div class="chart2">
       <canvas id= "myChart_6" class="chart2"  > </canvas>
     </div>
<div class="clear"></div>
    </div>
</div>
<div class="comm_spacediv">&nbsp;</div>
<!--<div class="DB_container_3">
  <!--  <h2><?php echo TEXT_LICENCE_INFORMATION; ?></h2>-->
    <!--<div class="DB_container_content">
       
      
                                              
                                           <!-- <table width="100%"  border="0" align="left" cellpadding="8" cellspacing="0">
                                                <tr align="left" bgcolor="#FFFFFF" class="listingmaintext">
                                                    <td ><B><?php echo SITE_LICENSEKEY; ?></B> </td>
                                                    <td >:</td>
                                                    <td ><?php echo $_SESSION["sess_licensekey"];?></td>
                                                </tr>
                                                <tr align="left" bgcolor="#FFFFFF" class="listingmaintext">
                                                    <td width="40%" ><B><?php echo TEXT_INSTALLED_VERSION; ?></B> </td>
                                                    <td width="8%" >:</td>
                                                    <td width="52%" >4.0</td>
                                                </tr>
                                                <tr align="left" bgcolor="#FFFFFF" class="listingmaintext">
                                                    <td ><B><?php echo TEXT_CURRENT_VERSION; ?></B> </td>
                                                    <td >:</td>
                                                    <td >4.0</td>
                                                </tr>
                                            </table>
                                        
        
    
    
    </div>
</div> -->
<!--  <script src="https://charts.iscripts.com/ChartJs/chart.js"></script>
 -->  <!-- <script 
        src="https://rawgit.com/chartjs/chartjs.github.io/master/dist/master/Chart.min.js"
    ></script> -->

    <!-- <script
        src="https://cdn.jsdelivr.net/npm/chartjs-plugin-piechart-outlabels"
    ></script> -->
<script src="https://charts.iscripts.com/ChartJs/Plugins/Chart.min.js"></script>
<script src="https://charts.iscripts.com/ChartJs/Plugins/Out-label.js"></script>



 <script>
   var flg = '<?php echo $flag_str;?>';
    if(flg=="data"){
   
    var ctx = document.getElementById("myChart_1").getContext('2d');
    var myChart = new Chart(ctx, {
    type: 'horizontalBar',
    data: {


        labels: [<?php echo $statusName;?>],
       // labels: ["rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe"],

        datasets: [{
           label: '',
            data: [<?php echo $statusCount;?>],
          //data: [11,12,11,1,3,50,4,2,11,12,11,1],
            backgroundColor: [
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff'
            ],
            
            borderWidth: 1
        }]
    },
    options: {
          responsive : true,
  layout: {
        padding: {
            left:10,
            right: 10,
           // top: 60,
            //bottom: 20
        }
    },
      
        label: {
               display: false,

            },
      legend: {
            
                display: false,

                       
        },
        responsive : true,
  layout: {
        padding: {
            
            bottom: 20
        }
    },
        scales: {
           yAxes: [{
        scaleLabel: {
         display: true,
        labelString: 'Status',
        fontColor:'black',
        fontSize : 15
       },
        ticks: {
                   // fontColor: 'black',
                    fontSize: 13
                   }
            }],
          xAxes: [{


 ticks: {
               //fontColor: "black",
                    //max: 10,
                    fontSize: 13,
               
                beginAtZero: true
            },
            scaleLabel: {
         display: true,
        labelString: 'Count',
        fontColor:'black',
        fontSize : 15
       },
       gridLines: {
                color: "rgba(0, 0, 0, 0)",
            }  



          }]

        }
    }
});

}

var flg1 = '<?php echo $flag_strPr;?>';
    if(flg1=="data"){
 var ctx1 = document.getElementById("myChart_2").getContext('2d');
    var myChart = new Chart(ctx1, {
    type: 'horizontalBar',
    data: {


        labels: [<?php echo $priorityName;?>],
       // labels: ["rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe","rwe"],

        datasets: [{
           label: '',
            data: [<?php echo $priorityCount;?>],
          //data: [11,12,11,1,3,50,4,2,11,12,11,1],
            backgroundColor: [
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff',
                '#4876ff'
            ],
            
            borderWidth: 1
        }]
    },
    options: {
         responsive : true,
  layout: {
        padding: {
            left:10,
            right: 10,
            top: 25,
            //bottom: 20
        }
    },
      
        label: {
               display: false,

            },
      legend: {
            
                display: false,

                       
        },
        responsive : true,
  layout: {
        padding: {
            
            bottom: 20
        }
    },
        scales: {
           yAxes: [{
        scaleLabel: {
         display: true,
        labelString: 'Priority',
        fontColor:'black',
        fontSize : 15
       },
        ticks: {
                   // fontColor: 'black',
                    fontSize: 13
                   }
            }],
          xAxes: [{


 ticks: {
               //fontColor: "black",
                    //max: 10,
                    fontSize: 13,
               
                beginAtZero: true
            },
            scaleLabel: {
         display: true,
        labelString: 'Count',
        fontColor:'black',
        fontSize : 15
       },
       gridLines: {
                color: "rgba(0, 0, 0, 0)",
            }  



          }]

        }
    }
});

}
///////////////////////////////////
var flg2 = '<?php echo $flag_strDept;?>';
    if(flg2=="data"){

var ctx3 = document.getElementById("myChart_3").getContext('2d');
var myChart = new Chart(ctx3, {
  type: 'pie',
   options: {

         responsive : true,
  layout: {
        padding: {
            left:10,
            right: 10,
            top: 40,
            //bottom: 20
        }
    },
    legend: {
            
                display: false,
                    
        },
        tooltips: {
    callbacks: {
      label: function(tooltipItem, data) {
        var dataset = data.datasets[tooltipItem.datasetIndex];
        var meta = dataset._meta[Object.keys(dataset._meta)[0]];
        var total = meta.total;
        var currentValue = dataset.data[tooltipItem.index];
        var percentage = parseFloat((currentValue/total*100).toFixed(1));
        return   + percentage + '%';
      },
      title: function(tooltipItem, data) {
        return data.labels[tooltipItem[0].index];
      }
    }
  },

         plugins: {
              // legend: false,
                outlabels: {
                    text: '%l , %v',
                   //text: '%l PER : %p \n VAL : %v',
                    color: 'black',
                    stretch:10,
                    font: {
                       /// resizable: true,
                        minSize: 11,
                        maxSize: 12
                    },
                    display: 'auto'
                }
            }
  },
  data: {
    labels: [<?php echo $deptArr;?>],
    datasets: [{
      backgroundColor: [
        "#2ecc71",
        "#3498db",
        "#95a5a6",
        "#9b59b6",
        "#f1c40f",
        "#e74c3c",
        "#34495e"
      ],
      data: [<?php echo $deptcountArr;?>]
    }]
  }
});
}
//////////////////////////////////
var flg3 = '<?php echo $flag_strClosed;?>';
    if(flg3=="data"){

var ctx4 = document.getElementById('myChart_4').getContext('2d');
var chart = new Chart(ctx4, {
    // The type of chart we want to create
    type: 'bar',
    // The data for our dataset
    data: {
        labels: [<?php echo $staffName; ?>],
         datasets: [{
    label: "Blue",
    backgroundColor: "#2ecc71",
     label: 'Ontime',
    data: [<?php echo $ontimeCount; ?>]
  }, 
   {
   label: "Red",
    backgroundColor: "#34495e",
     label: 'Delayed',
    data: [<?php echo $delayedCount; ?>]
  }]
    },

    // Configuration options go here
    options: {
         legend: {
            
               // display: false,
                    
        },
         responsive : true,
  layout: {
        padding: {
            left:60,
           // right: 10,
           top: 40,
//bottom: 10
        }
    },
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                },
                scaleLabel: {
        display: true,
       // labelString: 'Count',
        fontColor:'black'
      },
      gridLines: {
                color: "rgba(0, 0, 0, 0)",
            } 
            }],
            xAxes: [{
                
                scaleLabel: {
        display: true,
        //labelString: 'Month',
        fontColor:'black'
      }
            }]
        }
    }

   
});

}
var flg4 = '<?php echo $flag_strRate;?>';
    if(flg4=="data"){

var ctx5 = document.getElementById("myChart_5").getContext('2d');
var myChart = new Chart(ctx5, {
    type: 'bar',
    data: {
        labels: [<?php echo $StaffName;?>],
        datasets: [{
           // label: 'Upgrades By Month',
            data: [<?php echo $StaffMark;?>],
            backgroundColor: ['#088DA5','#088DA5','#088DA5','#088DA5','#088DA5','#088DA5','#088DA5','#088DA5','#088DA5','#088DA5','#088DA5','#088DA5'],
            borderWidth: 1
        }]
    },
    options: {
         legend: {
            
                display: false,
                    
        },
        responsive : true,
  layout: {
        padding: {
            //left:10,
            //right: 10,
            top: 20,
            //bottom: 10
        }
  },
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero:true
                },
                scaleLabel: {
        display: true,
        //labelString: 'Count',
        //fontColor:'black'
      },
      gridLines: {
                color: "rgba(0, 0, 0, 0)",
            } 
            }],
            xAxes: [{
                
                scaleLabel: {
        display: true,
       // labelString: 'Month',
        //fontColor:'black'
      }
            }]
        }
    }
});

}


var ctx6 = document.getElementById("myChart_6").getContext('2d');
var myChart = new Chart(ctx6, {
    type: 'line',
    data: {
        labels: [<?php echo $arrCatName;?>],
        datasets: [{
           label: 'Closed',
          //  usePointStyle: true,
            data: [<?php echo $count_closed;?>],
            lineTension: 0.3,
            fill: false,
            borderColor: '#007790',
            backgroundColor: 'transparent',
           // pointBorderColor: 'red',
            pointBackgroundColor: '#007790',
            pointRadius: 1,
            pointHoverRadius: 5,
            pointHitRadius: 8,
            pointBorderWidth: 2,
            pointStyle: 'circle',

            
        },
        {
            label: 'Pending',
            data: [<?php echo $count_pending;?>],
            lineTension: 0.3,
            fill: false,
            borderColor: '#009872',
            backgroundColor: 'transparent',
            //pointBorderColor: 'purple',
            pointBackgroundColor: '#009872',
            pointRadius: 1,
            pointHoverRadius: 5,
            pointHitRadius: 8,
            pointBorderWidth: 2,
            pointStyle: 'circle' 
           

        }]
    },
    options: {
        legend: {
            display: true,
            labels : {
            useLineStyle: true,
            fontColor: "black",
            usePointStyle : true,
            fillStyle: Color

        }
        },
        // tooltips: {
        //      mode: 'dataset'
        // },
         tooltips: {
      mode: 'index',
      intersect: false
   },
   hover: {
      mode: 'index',
      intersect: false
   },
        scales: {
            yAxes: [{
                ticks: {
                    fontColor: "black",
                    beginAtZero:true
                },
                scaleLabel: {
        display: true,
       // labelString: 'Count',
        fontColor:'black'
      }
            }],
            xAxes: [{
              ticks: {
                    fontColor: "black"
                   
                },
                 scaleLabel: {
        display: true,
       // labelString: 'Month',
        fontColor:'black'
      }

            }]
        }
    }
});

  </script>