<?php
session_name('CAKEPHP'); session_start();
$conn = mysql_connect('localhost','root','');
mysql_select_db('wacorp');
 	$sql = "select sum(target_assigned) as `totcount`,start_date from xpert_sales_targets where financial_id=2 and user_id=14 group by start_date";
	//echo $sql;
	$result=mysql_query($sql);
	$i=0;
	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 and crm.smownerid = 14 group by inv.invoicedate";
	//echo $sql;
	$result1=mysql_query($sql1);
	$i=0;
	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;		
	}	
}


$target_assign = implode(',',$targ_asgn);
//echo $target_assign;
$target_achieve = implode(',',$targ_ach);
            include_once "ws_charts.php";  

            $test=new CHART("tmp/",500,400);                    

            $test->values="Target=$target_assign;Achieve=$target_achieve;"; // values
			//echo $test->values;
			$test->categories="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sept,Oct,Nov,Dec";
			 
            $test->background="cyan-white-white-plum";

            $test->set_theme("enhanced bar"); // theme

            $test->force_no_save=true;

            $test->shaddow_alpha=110;

            $test->shaddow_x=50;

            $test->shaddow_y=-40;

            $test->showcoords=true;
			$test->showgrid=false;
           $test->show('bar');        

?>