<?php
session_name('CAKEPHP'); session_start();
$conn = mysql_connect('localhost','root','');
mysql_select_db('wacorp2');

	$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[]=$row1["totcount"]; 	
		
	}
if(count($targ_asgn)<12){
	$targ_asgn = array_pad($targ_asgn, 12, 0);
	
}
if(count($targ_ach)<12){
	$targ_ach = array_pad($targ_ach, 12, 0);
}


require_once 'Chart.php';

$bars2 = $targ_asgn;
$bars1 = $targ_ach;
$dates = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

$graph = new Chart();
$graph->gradient = true;
$graph->addBars($bars1, 'ff0000');
$graph->addBars($bars2, '0000ff');
$graph->addXLabels($dates, '000000');
$graph->addYScale('000000');

$graph->output();
?>