<?php
$PageSecurity = 3;
	include ('includes/session.inc');
	include ('includes/function_lib.php');
	include('includes/fun-php.php');
	include('includes/fun-HRClass.php');
    require_once('piechart/as-diagrams.php');
	
?>
<STYLE TYPE="text/css">
<!--
  body     { font-family:arial,helvetica;font-size:12px; }
  pre { color:#0000FF; }
  td   { font-family:arial,helvetica;font-size:12px;}
  tr.odd   { background-color: #F0F0F8; color:#000000; }
  tr.even  { background-color: #E0E0F0; color:#000000; }
  h4       { background-color: #E0E0F0; color:#000000;
           text-align: left; }
  h5       { background-color: #E0E0F0; color:#000000;
           text-align: center; }
		   
		   tr.barodd   { background-color: #F0F0F8; color:#000000;
              FONT-size: 10px; FONT-FAMILY: Arial, Helvetica;
            }
tr.bareven  { background-color: #E0E0F0; color:#000000;
              FONT-size: 10px; FONT-FAMILY: Arial, Helvetica;
            }
tr.barhead  { background-color: #B0B0E0; color:#000000;
           BORDER-TOP: 1px solid #0000F0; BORDER-LEFT: 1px solid #0000F0 ;
           BORDER-RIGHT: 1px solid #0000F0 ; BORDER-BOTTOM: 1px solid #0000F0 ;
           font-size: 12px; FONT-FAMILY: Arial, Helvetica; font-weight: bold;
           text-align: center;
           filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#F8F8FF,endColorStr=#C0C0F0);
}
td.barhead  { background-color: #B0B0E0; color:#000000;
           BORDER-TOP: 1px solid #8080F0; BORDER-LEFT: 1px solid #8080F0;
           BORDER-RIGHT: 1px solid #8080F0; BORDER-BOTTOM: 1px solid #8080F0;
           font-size: 12px; FONT-FAMILY: Arial, Helvetica; font-weight: bold;
           filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#F8F8FF,endColorStr=#C0C0F0);
}
-->
</STYLE>
<?php 
$tar=array();
$tar1=array();
$monthdata=array();
$FinY=DB_query("SELECT *,YEAR(BookPeriodStart) AS SYear,YEAR(BookPeriodEnd) AS EYEAR FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
$FinYRow=DB_fetch_array($FinY);		 
$username=$s->getField('www_users','id',$_REQUEST['id'],'realname');
$data_title = 'Target Assigned Vs. Achievement For User   '.$username; // title for the diagram
$month=array('04','05','06','07','08','09','10','11','12','01','02','03');

for($i=0;$i<count($month);$i++)
{
if($i<9)
{  
$year=$FinYRow['SYear'];
$awl="select * from crmsales_target  where month='".$month[$i]."' and yearmonth='".$FinYRow['SYear']."' and mst_usersid='".$_REQUEST['id']."'";	
$target=DB_query("select * from crmsales_target  where month='".$month[$i]."' and yearmonth='".$FinYRow['SYear']."' and mst_usersid='".$_REQUEST['id']."' ",$db);
}
else
{
$year=$FinYRow['EYEAR'];
$awl="select * from crmsales_target  where month='".$month[$i]."' and yearmonth='".$FinYRow['EYEAR']."' and mst_usersid='".$_REQUEST['id']."'";	
$target=DB_query("select * from crmsales_target  where month='".$month[$i]."' and yearmonth='".$FinYRow['EYEAR']."' and mst_usersid='".$_REQUEST['id']."' ",$db);
}

$targetdata=DB_fetch_array($target);
$tar[]=$targetdata['target'];
$Sales1=DB_query("select sum(basicAmount) as Total from salesorder_details inner join salesorder on salesorder_details.masterId=salesorder.id where month(orderDate)='".$month[$i]."' and Sale_Key_Exec='".$_REQUEST['id']."' and year(orderDate)='".$year."'  and ApprovalStatus='Approved' 
",$db);
 $Sales1Row=DB_fetch_array($Sales1);
 
 $tar1[]=$Sales1Row['Total'];	
 $timestamp = mktime(0, 0, 0, $month[$i], 1, $year);
 $monthdata= date("M", $timestamp);
 $mtdata=$monthdata."-".$year;
 $monthdata1[]=$mtdata;
}
;
$data = array();
for($i=0;$i<12;$i++)
{
 $data[]=$tar[$i];
 $data[]=$tar1[$i];
 
}

$data1=array_chunk($data,2);
$legend_x = $monthdata1;
$legend_y = array('Assigned','Achieved');
$graph = new CAsBarDiagram;
$graph->bwidth = 20; // set one bar width, pixels
$graph->bt_total = 'Summary'; // 'totals' column title, if other than 'Totals'
// $graph->showtotals = 0;  // uncomment it if You don't need 'totals' column
$graph->precision = 2;  // decimal precision
// call drawing function

$graph->DiagramBar($legend_x, $legend_y, $data1, $data_title);

?>