<?php

/*include 'stacked_bar_classes.php';
$chart = array ( array ("", "Jan", "Feb", "Mar", "Apr" ), array ( "Serie 1", 100, 45, 25), 
						array ( "Serie 2", 80, 65, 35 ), array ( "Serie C", 55, 30, 80 ), array ( "Serie D", 55, 30, 80 ) );

	$tittle = "CHART TITTLE";
	$serie = array ( "0","FFFF00", "FF0000", "2F97FF", "564546", "784e3a", "677b75" );
	$width = 700;
	$height = 400;
	$hex_color = 'ffffff';
	$bg = new grafico($tittle,$width,$height,$hex_color,$chart,$serie);
	$bg->draw_graph();	*/
session_name('CAKEPHP'); session_start();
$uid=$_SESSION['authenticated_user_id'];
/*require_once('../../config.inc.php');
global $dbconfig;
$conn = mysql_connect($dbconfig['db_server'],$dbconfig['db_username'],$dbconfig['db_password']);
mysql_select_db($dbconfig['db_name']);*/
$conn = mysql_connect('localhost','root','');
mysql_select_db('wacorp');

if(isset($_REQUEST['urid']) && $_REQUEST['urid']!='')
		$uid=$_REQUEST['urid'];
	$cond = '';
	if($uid!=1 && $uid !=2) {
		$cond.="and user_id=$uid";
		$cond1 ="and crm.smownerid=$uid";
	}

	$sql = "select sum(target_assigned) as `totcount`,start_date from xpert_sales_targets where financial_id=2 $cond group by start_date";
	//echo $sql;
	$result=mysql_query($sql);
	$i=0;
	$targ_asgn = array('Assigned');
	while ($row = mysql_fetch_array($result)) 
	{	
		
			$targ_asgn[]=$row["totcount"]; 	
		
	}
	$sql1 = "select sum(total) as totcount from xpert_invoice inv, xpert_crmentity crm where crm.crmid = inv.invoiceid $cond1 group by inv.invoicedate";
	//echo $sql1;
	$result1=mysql_query($sql1);
	$i=0;
	$targ_ach = array('Achieved');
	while ($row1 = mysql_fetch_array($result1)) 
	{	
		
			$targ_ach[]=number_format($row1["totcount"],2); 	
		
	}
	//echo count($targ_asgn)-1;
if(count($targ_asgn)<12){
	for($i=1;$i<=10;$i++){		
		$targ_asgn[] = 0;		
	}	
}
if(count($targ_ach)<12){
	for($i=1;$i<=10;$i++){		
		$targ_ach[] = 0;		
	}	
}
//$target_assign = implode(', ',$targ_asgn);
//echo $target_assign;
//$target_achieve = implode(', ',$targ_ach);
include 'stacked_bar_classes.php';
$chart = array ( array ("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" ), $targ_ach,
						$targ_asgn );

	$tittle = "Target Assigned Vs. Achievement";
	$serie = array ( "0", "00c100", "3845e2", "2F97FF", "564546", "784e3a", "677b75" );
	$width = 550;
	$height = 400;
	$hex_color = 'ffffff';
	$bg = new grafico($tittle,$width,$height,$hex_color,$chart,$serie);
	$bg->draw_graph();
?>