Nouveau fichier

This commit is contained in:
Rodolphe Quiedeville 2005-02-08 12:33:39 +00:00
parent c2fce55460
commit 3cc861a15e
10 changed files with 1461 additions and 0 deletions

View File

@ -0,0 +1,628 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*
* Generation des graphiques
*
*
*
*/
require ("../../master.inc.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie-tarif.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/communication.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/bar.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/camenbert.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/ca.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/gain.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/heureappel.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/joursemaine.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/camoyen.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/appelsdureemoyenne.class.php");
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/comm.nbmensuel.class.php");
$error = 0;
$datetime = time();
$date = strftime("%d%h%Y%Hh%Mm%S",$datetime);
$month = strftime("%m", $datetime);
$year = strftime("%Y", $datetime);
if ($month == 1)
{
$month = "12";
$year = $year - 1;
}
else
{
$month = substr("00".($month - 1), -2) ;
}
/*
* Création des répertoires
*
*/
$dirs[0] = DOL_DATA_ROOT."/graph/";
$dirs[1] = DOL_DATA_ROOT."/graph/telephonie/";
$dirs[2] = DOL_DATA_ROOT."/graph/telephonie/communications/";
$dirs[3] = DOL_DATA_ROOT."/graph/telephonie/factures/";
$dirs[4] = DOL_DATA_ROOT."/graph/telephonie/ca/";
$dirs[5] = DOL_DATA_ROOT."/graph/telephonie/client/";
$img_root = DOL_DATA_ROOT."/graph/telephonie/";
if (is_array($dirs))
{
foreach ($dirs as $key => $value)
{
$dir = $value;
if (! file_exists($dir))
{
umask(0);
if (! @mkdir($dir, 0755))
{
print "Erreur: Le répertoire '$dir' n'existe pas et Dolibarr n'a pu le créer.";
}
else
{
print $dir ." créé\n";
}
}
}
}
/***********************************************************************/
/*
/* Chiffre d'affaire mensuel
/*
/***********************************************************************/
$file = $img_root . "ca/ca.mensuel.png";
print "Graph : Chiffre d'affaire mensuel $file\n";
$graphca = new GraphCa($db, $file);
$graphca->GraphDraw();
/************************************************************************/
/*
/* Chiffre d'affaire moyen
/*
/*
/************************************************************************/
print "\nGraph ca moyen\n";
$file = $img_root . "ca/gain_moyen_par_client.png";
$graphgain = new GraphCaMoyen ($db, $file);
$graphgain->show_console = 1 ;
$graphgain->GraphDraw();
/*************************************************************************/
/*
/* Stats sur les communications
/*
/*
/*************************************************************************/
$sql = "SELECT ".$db->pdate("date")." as date, duree";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
if ($db->query($sql))
{
$heure_appel = array();
$jour_semaine_nb = array();
$jour_semaine_duree = array();
$num = $db->num_rows();
print "$num lignes de comm a traiter\n";
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object();
$h = strftime("%H",$obj->date) * 1; // suppression du 0
$heure_appel_nb[$h]++;
$heure_appel_duree[$h] += $obj->duree;
$u = strftime("%u",$obj->date) - 1; // 1 pour Lundi
$jour_semaine_nb[$u]++;
$jour_semaine_duree[$u] += $obj->duree;
$i++;
}
}
$file = $img_root . "communications/heure_appel_nb.png";
$graphha = new GraphHeureAppel ($db, $file);
$graphha->GraphDraw($heure_appel_nb);
$file = $img_root . "communications/joursemaine_nb.png";
$graphha = new GraphJourSemaine ($db, $file);
$graphha->GraphDraw($jour_semaine_nb);
repart_comm($db);
$year = strftime("%Y", $datetime);
$month = strftime("%m", $datetime);
for ($i = 1 ; $i < 4 ; $i++)
{
$month = $month - 1;
if ($month == 0)
{
$year = $year - 1;
$month = 12;
}
repart($db,$year, $month);
repart_comm($db,$year, $month);
}
function repart_comm($db, $year = 0, $month = 0)
{
print "Répartition des communications\n";
$sql = "SELECT duree, numero";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
if ($year && $month)
{
print "Répartition des communications pour $month/$year\n";
$month = substr("00".$month, -2);
$sql .= " WHERE date_format(date,'%Y%m') = '$year$month'";
}
if ($db->query($sql))
{
$labels_duree = array();
$repart_duree = array(0,0,0,0,0,0);
$repart_dureelong = array(0,0);
$labels_dest= array();
$repart_dest = array(0,0,0);
$repart_dest_temps = array(0,0,0);
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row();
if ($row[0] < 10)
{
$repart_duree[0]++;
}
elseif ($row[0] >= 10 && $row[0] < 30)
{
$repart_duree[1]++;
}
elseif ($row[0] >= 30 && $row[0] < 60)
{
$repart_duree[2]++;
}
elseif ($row[0] >= 60 && $row[0] < 120)
{
$repart_duree[3]++;
}
elseif ($row[0] >= 120 && $row[0] < 300)
{
$repart_duree[4]++;
}
else
{
$repart_duree[5]++;
}
if ($row[0] < 600)
{
$repart_dureelong[0]++;
}
else
{
$repart_dureelong[1]++;
}
if (substr($row[1],0,2) == '00')
{
$repart_dest[0]++;
$repart_dest_temps[0] += $row[0];
}
elseif (substr($row[1],0,2) == '06')
{
$repart_dest[1]++;
$repart_dest_temps[1] += $row[0];
}
else
{
$repart_dest[2]++;
$repart_dest_temps[2] += $row[0];
}
$i++;
}
}
else
{
print $sql ;
}
if ($num > 0)
{
$labels_duree[0] = "< 10 sec";
$labels_duree[1] = "10-30 sec";
$labels_duree[2] = "30-60 sec";
$labels_duree[3] = "60-120 sec";
$labels_duree[4] = "120-300 sec";
$labels_duree[5] = "> 300 sec";
$labels_dureelong[0] = "< 600 sec";
$labels_dureelong[1] = "> 600 sec";
$labels_dest[0] = 'International';
$labels_dest[1] = 'Mobile';
$labels_dest[2] = 'Local/National';
$filem = DOL_DATA_ROOT."/graph/telephonie/communications/duree_repart.png";
$filec = DOL_DATA_ROOT."/graph/telephonie/communications/dureelong_repart.png";
$filed = DOL_DATA_ROOT."/graph/telephonie/communications/dest_repart.png";
$filedt = DOL_DATA_ROOT."/graph/telephonie/communications/dest_temps_repart.png";
if ($year && $month)
{
$filem = DOL_DATA_ROOT."/graph/telephonie/communications/duree_repart-$year$month.png";
$filec = DOL_DATA_ROOT."/graph/telephonie/communications/dureelong_repart-$year$month.png";
$filed = DOL_DATA_ROOT."/graph/telephonie/communications/dest_repart-$year$month.png";
$filedt = DOL_DATA_ROOT."/graph/telephonie/communications/dest_temps_repart-$year$month.png";
}
$graphm = new GraphCamenbert ($db, $filem);
$graphc = new GraphCamenbert ($db, $filec);
$graphd = new GraphCamenbert ($db, $filed);
$graphdt = new GraphCamenbert ($db, $filedt);
$graphm->titre = "Répartition du nombre de communications par duree";
$graphc->titre = "Répartition du nombre de communications par duree";
$graphd->titre = "Répartition du nombre de communications par destination";
$graphdt->titre = "Répartition du nombre de communications par destination";
if ($year && $month)
{
$graphm->titre = "Répart. du nbre de communications par duree $month/$year";
$graphc->titre = "Répart. du nbre de communications par duree $month/$year";
$graphd->titre = "Répart. du nbre de communications par destination $month/$year";
$graphdt->titre = "Répart. du temps de communications par destination $month/$year";
}
$graphm->colors= array('#993333','#66cc99','#6633ff','#33ff33','#336699','#00ffff');
$graphd->colors= array('#FFC0FF','#FF00FF','#C000C0');
$graphdt->colors= array('#FFFFC0','#FFFF0F','#C0C000');
$graphm->GraphDraw($repart_duree, $labels_duree);
$graphc->GraphDraw($repart_dureelong, $labels_dureelong);
$graphd->GraphDraw($repart_dest, $labels_dest);
$graphdt->GraphDraw($repart_dest_temps, $labels_dest);
}
}
/***************************************************************************/
$sql = "SELECT date_format(date, '%Y%m'), count(distinct(ligne))";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
$sql .= " GROUP BY date_format(date, '%Y%m') ASC";
if ($db->query($sql))
{
$nblignes = array();
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row();
$nblignes[$i] = $row[1];
$i++;
}
}
$sql = "SELECT date_format(date, '%Y%m'), sum(duree), count(duree)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
$sql .= " GROUP BY date_format(date, '%Y%m') ASC";
if ($db->query($sql))
{
$durees = array();
$kilomindurees = array();
$durees_moyenne = array();
$nombres = array();
$labels = array();
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row();
$labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2);
$durees[$i] = $row[1];
$kilomindurees[$i] = ($row[1]/60000);
$durees_moyenne[$i] = ($row[1] / $row[2]);
$nombres[$i] = $row[2];
$nbappels_ligne[$i] = ($nombres[$i] / $nblignes[$i]);
$i++;
}
}
$file = $img_root . "communications/duree.png";
$graphgain = new GraphBar ($db, $file);
$graphgain->show_console = 0 ;
$graphgain->titre = "Nb minutes (milliers)";
print $graphgain->titre."\n";
$graphgain->GraphDraw($file, $kilomindurees, $labels);
$file = $img_root . "communications/nbappelsparligne.png";
$graphgain = new GraphBar ($db, $file);
$graphgain->show_console = 0 ;
$graphgain->titre = "Nb appels moyen par ligne";
print $graphgain->titre."\n";
$graphgain->barcolor = "pink";
$graphgain->GraphDraw($file, $nbappels_ligne, $labels);
$file = $img_root . "communications/dureemoyenne.png";
$graphgain = new GraphBar ($db, $file);
$graphgain->show_console = 0 ;
$graphgain->titre = "Durée moyenne d'un appel";
print $graphgain->titre."\n";
$graphgain->barcolor = "yellow";
$graphgain->GraphDraw($file, $durees_moyenne, $labels);
$file = $img_root . "communications/nombre.png";
$graphgain = new GraphBar ($db, $file);
$graphgain->show_console = 0 ;
$graphgain->titre = "Nombres d'appel mensuels";
print $graphgain->titre."\n";
$graphgain->GraphDraw($file, $nombres, $labels);
/**********************************************************************/
/*
/* Stats sur les factures
/*
/*
/**********************************************************************/
$sql = "SELECT date_format(date,'%Y%m'), sum(cout_vente), sum(cout_achat), sum(gain), count(cout_vente)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " GROUP BY date_format(date,'%Y%m') ASC ";
if ($db->query($sql))
{
$cout_vente = array();
$cout_vente_moyen = array();
$nb_factures = array();
$jour_semaine_nb = array();
$jour_semaine_duree = array();
$gain = array();
$gain_moyen = array();
$num = $db->num_rows();
print "$num lignes de comm a traiter\n";
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row();
$cout_vente[$i] = $row[1];
$gain[$i] = $row[3];
$gain_moyen[$i] = ($row[3]/$row[4]);
$cout_vente_moyen[$i] = ($row[1]/$row[4]);
$nb_factures[$i] = $row[4];
$labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2);
$i++;
}
}
$file = $img_root . "/factures/ca_mensuel.png";
$graph = new GraphBar ($db, $file);
$graph->titre = "Chiffre d'affaire par mois en euros HT";
print $graph->titre."\n";
$graph->GraphDraw($file, $cout_vente, $labels);
$file = $img_root . "/factures/facture_moyenne.png";
$graph = new GraphBar ($db, $file, $labels);
$graph->titre = "Facture moyenne";
print $graph->titre."\n";
$graph->barcolor = "blue";
$graph->GraphDraw($file, $cout_vente_moyen, $labels);
$file = $img_root . "/factures/gain_mensuel.png";
$graph = new GraphBar ($db, $file);
$graph->titre = "Gain par mois en euros HT";
print $graph->titre."\n";
$graph->GraphDraw($file, $gain, $labels);
$file = $img_root . "/factures/gain_moyen.png";
$graph = new GraphBar ($db, $file);
$graph->titre = "Gain moyen par facture par mois";
print $graph->titre."\n";
$graph->barcolor = "blue";
$graph->GraphDraw($file, $gain_moyen, $labels);
$file = $img_root . "/factures/nb_facture.png";
$graph = new GraphBar ($db, $file);
$graph->titre = "Nb de facture mois";
print $graph->titre."\n";
$graph->barcolor = "yellow";
$graph->GraphDraw($file, $nb_factures, $labels);
/*
* Répartition des factures
*
*
*/
repart($db);
function repart($db, $year = 0, $month = 0)
{
print "Répartition des factures\n";
$sql = "SELECT cout_vente, gain";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
if ($year && $month)
{
print "Répartition des factures pour $month/$year\n";
$month = substr("00".$month, -2);
$sql .= " WHERE date_format(date,'%Y%m') = '$year$month'";
}
if ($db->query($sql))
{
$labels = array();
$repart_montant = array();
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row();
if ($row[0] < 10)
{
$repart_montant[0]++;
}
elseif ($row[0] >= 10 && $row[0] < 20)
{
$repart_montant[1]++;
}
elseif ($row[0] >= 20 && $row[0] < 40)
{
$repart_montant[2]++;
}
elseif ($row[0] >= 40 && $row[0] < 70)
{
$repart_montant[3]++;
}
elseif ($row[0] >= 70 && $row[0] < 100)
{
$repart_montant[4]++;
}
else
{
$repart_montant[5]++;
}
if ($row[1] < 1)
{
$repart_gain[0]++;
}
elseif ($row[1] >= 1 && $row[1] < 5)
{
$repart_gain[1]++;
}
elseif ($row[1] >= 5 && $row[1] < 10)
{
$repart_gain[2]++;
}
elseif ($row[1] >= 10 && $row[1] < 20)
{
$repart_gain[3]++;
}
elseif ($row[1] >= 20 && $row[1] < 50)
{
$repart_gain[4]++;
}
else
{
$repart_gain[5]++;
}
$i++;
}
}
else
{
print $sql ;
}
if ($num > 0)
{
$labels_montant[0] = "< 10";
$labels_montant[1] = "10-20";
$labels_montant[2] = "20-40";
$labels_montant[3] = "40-70";
$labels_montant[4] = "70-100";
$labels_montant[5] = "> 100";
$labels_gain[0] = "< 1";
$labels_gain[1] = "1-5";
$labels_gain[2] = "5-10";
$labels_gain[3] = "10-20";
$labels_gain[4] = "20-50";
$labels_gain[5] = "> 50";
$filem = DOL_DATA_ROOT."/graph/telephonie/factures/montant_repart.png";
$fileg = DOL_DATA_ROOT."/graph/telephonie/factures/gain_repart.png";
if ($year && $month)
{
$filem = DOL_DATA_ROOT."/graph/telephonie/factures/montant_repart-$year$month.png";
$fileg = DOL_DATA_ROOT."/graph/telephonie/factures/gain_repart-$year$month.png";
}
$graphm = new GraphCamenbert ($db, $filem);
$graphg = new GraphCamenbert ($db, $fileg);
$graphm->titre = "Répartition du nombre de factures par montant";
$graphg->titre = "Répartition du nombre de factures par gain";
if ($year && $month)
{
$graphm->titre = "Répart. du nbre de factures par montant $month $year";
$graphg->titre = "Répart. du nbre de factures par gain $month $year";
}
$graphm->colors= array('#993333','#66cc99','#6633ff','#33ff33','#336699','#00ffff');
// $graphm->GraphDraw($filem, $repart_montant, $labels_montant);
// $graphg->GraphDraw($fileg, $repart_gain, $labels_gain);
}
}
?>

View File

@ -0,0 +1,102 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/brouzouf.class.php");
class GraphAppelsDureeMoyenne extends GraphBrouzouf{
Function GraphAppelsDureeMoyenne($DB, $file)
{
$this->db = $DB;
$this->file = $file;
$this->client = 0;
$this->titre = "Durée moyenne des appels";
//$this->type = "LinePlot";
$this->barcolor = "pink";
}
Function GraphDraw()
{
$num = 0;
$ligne = new LigneTel($this->db);
if ($this->client == 0)
{
$sql = "SELECT date_format(date,'%Y%m'), sum(duree), count(duree)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details";
$sql .= " GROUP BY date_format(date,'%Y%m') ASC ";
}
else
{
$sql = "SELECT date_format(td.date,'%Y%m'), sum(td.duree), count(td.duree)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details as td";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as s";
$sql .= " WHERE td.ligne = s.ligne";
$sql .= " AND s.fk_client_comm = ".$this->client;
$sql .= " GROUP BY date_format(td.date,'%Y%m') ASC ";
}
if ($this->db->query($sql))
{
$num = $this->db->num_rows();
$i = 0;
$labels = array();
while ($i < $num)
{
$row = $this->db->fetch_row();
$labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2);
$datas[$i] = ($row[1] / $row[2] ) ;
$i++;
}
$this->db->free();
}
else
{
print $this->db->error() . ' ' . $sql;
exit ;
}
if ($this->show_console)
{
print $this->client . " " . $cv[$i - 1]."\n";
}
if ($num > 1)
{
$this->GraphMakeGraph($datas, $labels);
}
}
}
?>

View File

@ -0,0 +1,97 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/graph.class.php");
class GraphBar extends DolibarrGraph {
Function GraphBar($DB, $file)
{
$this->db = $DB;
$this->file = $file;
$this->bgcolor = "#DEE7EC";
$this->barcolor = "green";
$this->client = 0;
$this->showframe = true;
}
Function GraphDraw($file, $datas, $labels)
{
// Create the graph. These two calls are always required
$height = 240;
$width = 320;
if ($this->width <> $width && $this->width > 0)
$width = $this->width;
if ($this->height <> $height && $this->height > 0)
$height = $this->height;
$graph = new Graph($width, $height,"auto");
$graph->SetScale("textlin");
$graph->yaxis->scale->SetGrace(20);
$graph->SetFrame($this->showframe);
$graph->img->SetMargin(40,20,20,40);
if ($this->type == 'LinePlot')
{
$b2plot = new LinePlot($datas);
}
else
{
$b2plot = new BarPlot($datas);
}
$b2plot->SetFillColor($this->barcolor);
$graph->xaxis->scale->SetGrace(20);
$LabelAngle = 45;
if ($this->LabelAngle <> $LabelAngle && $this->LabelAngle > 0)
$LabelAngle = $this->LabelAngle;
$graph->xaxis->SetLabelAngle($LabelAngle);
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,8);
$graph->Add($b2plot);
$graph->title->Set($this->titre);
$graph->title->SetFont(FF_VERDANA,FS_NORMAL);
$graph->yaxis->title->SetFont(FF_FONT2);
$graph->xaxis->title->SetFont(FF_FONT1);
$graph->xaxis->SetTickLabels($labels);
// Display the graph
$graph->img->SetImgFormat("png");
$graph->Stroke($file);
}
}
?>

View File

@ -0,0 +1,94 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
class GraphBrouzouf {
Function GraphBrouzouf($DB, $file)
{
$this->db = $DB;
$this->file = $file;
$this->client = 0;
}
Function GraphMakeGraph($datas, $labels)
{
// Create the graph. These two calls are always required
$height = 240;
$width = 320;
if ($this->width <> $width && $this->width > 0)
$width = $this->width;
$graph = new Graph($width, $height,"auto");
$graph->SetScale("textlin");
$graph->yaxis->scale->SetGrace(20);
$graph->img->SetMargin(40,20,20,40);
if ($this->type == 'LinePlot')
{
$b2plot = new LinePlot($datas);
}
else
{
$b2plot = new BarPlot($datas);
}
$b2plot->SetFillColor($this->barcolor);
$graph->xaxis->scale->SetGrace(20);
//$graph->xaxis->SetLabelAlign('center','bottom');
$LabelAngle = 45;
if ($this->LabelAngle <> $LabelAngle && $this->LabelAngle > 0)
$LabelAngle = $this->LabelAngle;
$graph->xaxis->SetLabelAngle($LabelAngle);
//$graph->xaxis->SetLabelFormat('%d');
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,8);
$graph->Add($b2plot);
$graph->title->Set($this->titre);
$graph->title->SetFont(FF_VERDANA,FS_NORMAL);
$graph->yaxis->title->SetFont(FF_VERDANA,FS_NORMAL);
$graph->xaxis->title->SetFont(FF_VERDANA,FS_NORMAL);
$graph->xaxis->SetTickLabels($labels);
// Display the graph
$graph->img->SetImgFormat("png");
$graph->Stroke($this->file);
}
}
?>

View File

@ -0,0 +1,106 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/brouzouf.class.php");
class GraphCa extends GraphBrouzouf{
Function GraphCa($DB, $file)
{
$this->db = $DB;
$this->file = $file;
$this->client = 0;
$this->titre = "Chiffre d'affaire (euros HT)";
$this->barcolor = "green";
}
Function GraphDraw()
{
$num = 0;
$ligne = new LigneTel($this->db);
if ($this->client == 0)
{
$sql = "SELECT date, sum(gain), sum(cout_vente), sum(fourn_montant)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " WHERE fk_facture is not null";
$sql .= " GROUP BY date ASC";
}
else
{
$sql = "SELECT date, sum(gain), sum(cout_vente), sum(fourn_montant)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as s";
$sql .= " WHERE fk_facture is not null";
$sql .= " AND s.rowid = fk_ligne";
$sql .= " AND s.fk_client_comm = ".$this->client;
$sql .= " GROUP BY date ASC";
}
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows();
$i = 0;
$j = -1;
$labels = array();
$cf = array();
$cv = array();
$gg = array();
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$cf[$i] = $row[3];
$cv[$i] = $row[2];
$g[$i] = $row[1];
$labels[$i] = substr($row[0],5,2)."/".substr($row[0],2,2);
$i++;
}
$this->db->free();
}
else
{
print $this->db->error() . ' ' . $sql;
}
if ($this->show_console)
{
print $this->client . " " . $cv[$i - 1]."\n";
}
if ($num > 0)
{
$this->GraphMakeGraph($cv, $labels);
}
}
}
?>

View File

@ -0,0 +1,83 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/graph.class.php");
class GraphCamenbert extends DolibarrGraph {
Function GraphCamenbert($DB, $file)
{
$this->file = $file;
$this->titre = "Camenbert";
$this->colors = array('pink','yellow','blue','green','red','white','grey');
}
Function GraphDraw($datas, $legends)
{
// Create the graph. These two calls are always required
$graph = new PieGraph(420,260,"auto");
$graph->SetColor("gray") ;
// Create the bar plots
$pieplot = new PiePlot($datas);
$pieplot->SetCenter(0.33,0.5);
// Label font and color setup
$pieplot->SetFont(FF_FONT1,FS_BOLD);
$pieplot->SetFontColor("darkred");
// Use absolute values (type==1)
//$pieplot->SetLabelType(0);
// Label format
//$pieplot->SetLabelFormat("%d%%");
$pieplot->SetSliceColors($this->colors);
//$pieplot->SetStartAngle(45);
//$pieplot->SetLabelPos(0.6);
// Size of pie in fraction of the width of the graph
$pieplot->SetSize(0.38);
// Legends
$pieplot->SetLegends($legends);
$graph->legend->Pos(0.05,0.15);
$graph->Add($pieplot);
$graph->title->Set($this->titre);
$graph->title->SetFont(FF_FONT1,FS_BOLD);
// Display the graph
$graph->img->SetImgFormat("png");
$graph->Stroke($this->file);
}
}
?>

View File

@ -0,0 +1,139 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/brouzouf.class.php");
class GraphCaMoyen extends GraphBrouzouf{
Function GraphCaMoyen($DB, $file)
{
$this->db = $DB;
$this->file = $file;
$this->show_console = 0;
$this->client = 0;
$this->titre = "Chiffre d'affaire moyen par client (euros HT)";
$this->barcolor = "yellow";
}
Function GraphDraw()
{
$num = 0;
$ligne = new LigneTel($this->db);
$sql = "SELECT date, sum(gain), sum(cout_vente), sum(fourn_montant)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " WHERE fk_facture is not null";
$sql .= " GROUP BY date ASC";
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows();
$i = 0;
$labels = array();
$cf = array();
$cv = array();
$gg = array();
while ($i < $num)
{
$row = $this->db->fetch_row();
$g[$i] = $row[1];
$cv[$i] = $row[2];
$cf[$i] = $row[3];
$labels[$i] = substr($row[0],5,2)."/".substr($row[0],2,2);
$i++;
}
$this->db->free();
}
else
{
print $this->db->error() . ' ' . $sql;
}
$sql = "SELECT f.date, count(l.fk_client_comm)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
$sql .= " WHERE f.fk_facture is not null";
$sql .= " AND l.rowid = f.fk_ligne";
$sql .= " GROUP BY f.date ASC";
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows();
$i = 0;
$nbc = array();
while ($i < $num)
{
$row = $this->db->fetch_row();
$nbc[$i] = $row[1];
$i++;
}
$this->db->free();
}
else
{
print $this->db->error() . ' ' . $sql;
}
if ($this->show_console)
{
print $this->client . " " . $cv[$i - 1]."\n";
}
for ($j = 0 ; $j < sizeof($nbc) ; $j++)
{
$camoy[$j] = $cv[$j] / $nbc[$j];
if ($this->show_console)
{
print $labels[$j] . "\t" . $nbc[$j] ."\t" . price($cv[$j]) ."\t\t" . price($camoy[$j]) ."\n";
}
}
if ($num > 0)
{
$this->GraphMakeGraph($camoy, $labels);
}
}
}
?>

View File

@ -0,0 +1,116 @@
<?PHP
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/brouzouf.class.php");
class GraphGain extends GraphBrouzouf{
Function GraphGain($DB, $file)
{
$this->db = $DB;
$this->file = $file;
$this->client = 0;
$this->titre = "Gain (euros HT)";
$this->barcolor = "blue";
}
Function GraphDraw()
{
$num = 0;
$ligne = new LigneTel($this->db);
if ($this->client == 0)
{
$sql = "SELECT date, sum(gain), sum(cout_vente), sum(fourn_montant)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " WHERE fk_facture is not null";
$sql .= " GROUP BY date ASC";
}
else
{
$sql = "SELECT date, sum(gain), sum(cout_vente), sum(fourn_montant)";
$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture";
$sql .= " , ".MAIN_DB_PREFIX."telephonie_societe_ligne as s";
$sql .= " WHERE fk_facture is not null";
$sql .= " AND s.rowid = fk_ligne";
$sql .= " AND s.fk_client_comm = ".$this->client;
$sql .= " GROUP BY date ASC";
}
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows();
$i = 0;
$j = -1;
$labels = array();
$cf = array();
$cv = array();
$gg = array();
$this->total_gain = 0;
$this->total_ca = 0;
$this->total_cout = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$cf[$i] = $row[3];
$cv[$i] = $row[2];
$g[$i] = $row[1];
$labels[$i] = substr($row[0],5,2)."/".substr($row[0],2,2);
$this->total_gain += $row[1];
$this->total_ca += $row[2];
$this->total_cout += $row[3];
$i++;
}
$this->db->free();
}
else
{
print $this->db->error() . ' ' . $sql;
}
if ($this->show_console)
{
print $this->client . " " . $g[$i - 1]."\n";
}
if ($num > 0)
{
$this->GraphMakeGraph($g, $labels);
}
}
}
?>

View File

@ -0,0 +1,48 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/brouzouf.class.php");
class GraphHeureAppel extends GraphBrouzouf{
Function GraphHeureAppel($DB, $file)
{
$this->db = $DB;
$this->file = $file;
$this->client = 0;
$this->titre = "Heure d'appel";
$this->width = 400;
$this->LabelAngle = 90;
$this->barcolor = "blue";
}
Function GraphDraw($g)
{
$this->GraphMakeGraph($g, $labels);
}
}
?>

View File

@ -0,0 +1,48 @@
<?PHP
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/brouzouf.class.php");
class GraphJoursemaine extends GraphBrouzouf{
Function GraphJoursemaine($DB, $file)
{
$this->db = $DB;
$this->file = $file;
$this->client = 0;
$this->titre = "Jour de la semaine";
$this->width = 400;
$this->LabelAngle = 45;
$this->barcolor = "green";
}
Function GraphDraw($g)
{
$this->GraphMakeGraph($g,array('Lun','Mar','Mer','Jeu','Ven','Sam','Dim'));
}
}
?>