121 lines
3.9 KiB
PHP
121 lines
3.9 KiB
PHP
|
|
<?php
|
||
|
|
session_start();
|
||
|
|
include_once( '/var/www/html/e5crm/config.php');
|
||
|
|
$sql=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
|
||
|
|
mysql_select_db($sugar_config['dbconfig']['db_name']);
|
||
|
|
mysql_query("set names utf8");
|
||
|
|
include_once( '/var/www/html/e5crm/include/ECM/open_flash_chart/ofc-library/open-flash-chart.php' );
|
||
|
|
//include_once('/var/www/html/e5crm/modules/EcmCharts/chartHelper.php');
|
||
|
|
include_once("/var/www/html/e5crm/modules/EcmReports/cache.php");
|
||
|
|
function repl($t){
|
||
|
|
$a1=array("ą","ś","ę","ż","ź","ć","ń","ó","ł","Ą","Ś","Ę","Ż","Ź","Ć","Ń","Ó","Ł");
|
||
|
|
$a2=array("a","s","e","z","z","c","n","o","l","A","S","E","Z","Z","C","N","O","L");
|
||
|
|
return str_replace($a1,$a2,$t);
|
||
|
|
}
|
||
|
|
function getCallTime($id,$year){
|
||
|
|
if($id){$acc_ids=array();
|
||
|
|
$acc_ids[]="e.bean_id='".$id."'";
|
||
|
|
$w=mysql_query("select contact_id from accounts_contacts where deleted='0' and account_id='".$id."'");
|
||
|
|
while($r=mysql_fetch_array($w)){
|
||
|
|
$acc_ids[]="e.bean_id='".$r['contact_id']."'";
|
||
|
|
}
|
||
|
|
$w=mysql_query("select id from accounts where deleted='0' and parent_id='".$id."'");
|
||
|
|
while($r=mysql_fetch_array($w)){
|
||
|
|
$acc_ids[]="e.bean_id='".$r['id']."'";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if(count($acc_ids)>0)$where="(".implode(" or ",$acc_ids).") and ";
|
||
|
|
else $where="";
|
||
|
|
$z="select sum(c.duration) as d,Month(e.date_modified) as m from ecmcalls_beans as e inner join cdr as c on c.id=e.ecmcall_id where ".$where."e.date_modified like '".$year."%' group by Month(e.date_modified)";
|
||
|
|
$w=mysql_query($z);
|
||
|
|
while($r=mysql_fetch_array($w)){
|
||
|
|
$d[$year."-".$r['m']]+=$r['d'];
|
||
|
|
}
|
||
|
|
return $d;
|
||
|
|
|
||
|
|
}
|
||
|
|
function getMinSec($v){
|
||
|
|
$min=floor($v/60);
|
||
|
|
$min1=$min;
|
||
|
|
$h=floor($min/60);
|
||
|
|
$min-=$h*60;
|
||
|
|
$sec=$v-$min1*60;
|
||
|
|
if($min1>0 || $sec>0 || $h>0)$str=$h."h ".$min."m ".$sec."s";
|
||
|
|
return $str;
|
||
|
|
}
|
||
|
|
|
||
|
|
$year=$_SESSION['EcmCharts_6_year'];
|
||
|
|
$category=$_SESSION['EcmCharts_6_category'];
|
||
|
|
$account=$_SESSION['EcmCharts_6_account'];
|
||
|
|
|
||
|
|
$months=array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień');
|
||
|
|
|
||
|
|
$s=sum($year,$account,$category);
|
||
|
|
$time=getCallTime($account,$year);
|
||
|
|
for($i=1;$i<=12;$i++){
|
||
|
|
if($i<10)$n="0".$i;
|
||
|
|
else $n=$i;
|
||
|
|
$ss=getSum($s,$year."-".$n,"",$category);
|
||
|
|
if($temp<$ss['total'])$temp=$ss['total'];
|
||
|
|
$arr_s[]=array(
|
||
|
|
"name"=>repl($months[$i-1]),
|
||
|
|
"value"=>$ss['total'],
|
||
|
|
);
|
||
|
|
if($tempr<$time[$year."-".$i])$tempr=$time[$year."-".$i];
|
||
|
|
$arr_c[]=array(
|
||
|
|
"name"=>repl($months[$i-1]),
|
||
|
|
"value"=>$time[$year."-".$i],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
for($i=0;$i<count($arr_s);$i++){
|
||
|
|
$data_1[]=$arr_s[$i]['value'];
|
||
|
|
$data_2[]=$arr_c[$i]['value'];
|
||
|
|
$cats[]=$arr_s[$i]['name'];
|
||
|
|
}
|
||
|
|
|
||
|
|
$g = new graph();
|
||
|
|
|
||
|
|
//$g->title( 'Sales: '.$year_month, '{font-size:20px; color: #000000; margin: 5px; background-color: #ffffff; padding:5px; padding-left: 20px; padding-right: 20px;}' );
|
||
|
|
|
||
|
|
$g->bg_colour = '#ffffff';
|
||
|
|
|
||
|
|
$d1 = new bar( 75, '#D54C78' );
|
||
|
|
$d2 = new bar( 75, '#3334AD' );
|
||
|
|
$d2->key( 'Czas rozmowy', 10 );
|
||
|
|
$d1->key( 'Sprzedaż', 10 );
|
||
|
|
for($i=0;$i<count($data_1);$i++){
|
||
|
|
$d1->add_data_tip($data_1[$i],"Sprzedaż: ".round($data_1[$i],2)."\nCzas rozmowy: ".getMinSec(round($data_2[$i],2)));
|
||
|
|
$d2->add_data_tip($data_2[$i],"Sprzedaż: ".round($data_1[$i],2)."\nCzas rozmowy ".getMinSec(round($data_2[$i],2)));
|
||
|
|
}
|
||
|
|
$g->data_sets[]=$d1;
|
||
|
|
$g->data_sets[]=$d2;
|
||
|
|
|
||
|
|
$g->set_tool_tip( '#x_label#<br>#tip#<br>' );
|
||
|
|
|
||
|
|
//$g->set_data($data_1);
|
||
|
|
//$g->bar( 75, '#D54C78', '', 10 );
|
||
|
|
//$g->set_data($data_2);
|
||
|
|
//$g->bar( 75, '#3334AD', '', 10 );
|
||
|
|
|
||
|
|
$g->attach_to_y_right_axis(2);
|
||
|
|
|
||
|
|
$g->x_axis_colour( '#909090', '#ADB5C7' );
|
||
|
|
$g->y_axis_colour( '#909090', '#ADB5C7' );
|
||
|
|
$g->y_right_axis_colour( '#909090' );
|
||
|
|
|
||
|
|
$g->set_x_labels( $cats );
|
||
|
|
$g->set_x_label_style( 10, '#000000', 2 );
|
||
|
|
|
||
|
|
$g->set_y_max( $temp );
|
||
|
|
$g->set_y_right_max( $tempr );
|
||
|
|
|
||
|
|
$g->y_label_steps( 20 );
|
||
|
|
//$g->y_right_label_steps( 20 );
|
||
|
|
|
||
|
|
$g->set_y_legend( '', 12, '#736AFF' );
|
||
|
|
$g->set_y_right_legend( '' ,12 , '#164166' );
|
||
|
|
|
||
|
|
echo $g->render();
|
||
|
|
mysql_close($sql);
|
||
|
|
?>
|