From 3ff8a09c1f9cb998338852ac810d9f2c49e80c07 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Thu, 10 Nov 2005 15:38:15 +0000 Subject: [PATCH] Nouveau fichier --- .../graph-statistiques-distributeurs.php | 125 ++++++++++++++++++ .../distributeur.commission.class.php | 93 +++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 htdocs/telephonie/script/graph-statistiques-distributeurs.php create mode 100644 htdocs/telephonie/stats/distributeurs/distributeur.commission.class.php diff --git a/htdocs/telephonie/script/graph-statistiques-distributeurs.php b/htdocs/telephonie/script/graph-statistiques-distributeurs.php new file mode 100644 index 00000000000..ab19f7e22d4 --- /dev/null +++ b/htdocs/telephonie/script/graph-statistiques-distributeurs.php @@ -0,0 +1,125 @@ + + * + * 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 relatifs aux distributeurs + * + */ +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/commerciaux/commercial.ca.class.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/commerciaux/commercial.gain.class.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/commerciaux/groupes/groupe.gain.class.php"); +require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/commerciaux/groupes/groupe.ca.class.php"); + +$error = 0; + +/* + * 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/distributeurs/"; + +$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"; + } + } + } +} + +/* + * Distributeurs + * + */ +$sql = "SELECT distinct fk_distributeur"; +$sql .= " FROM ".MAIN_DB_PREFIX."telephonie_distributeur_commerciaux"; + +$resql = $db->query($sql); +if ($resql) +{ + while ($row = $db->fetch_row($resql)) + { + /* Gain */ + require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/distributeurs/distributeur.gain.class.php"); + $dir = $img_root . "distributeurs/".$row[0]."/"; + _cdir($dir); + $file = $dir."gain.mensuel.png"; + if ($verbose) print "Graph : gain distributeur $file\n"; + $graph = new GraphDistributeurGain($db, $file); + $graph->width = 500; + $graph->GraphMakeGraph($row[0]); + + /* Commission */ + require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/distributeurs/distributeur.commission.class.php"); + $dir = $img_root . "distributeurs/".$row[0]."/"; + _cdir($dir); + $file = $dir."commission.mensuel.png"; + if ($verbose) print "Graph : commission distributeur $file\n"; + $graph = new GraphDistributeurCommission($db, $file); + $graph->width = 500; + $graph->GraphMakeGraph($row[0]); + + } +} + + +function _cdir($dir) +{ + 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"; + } + } +} + +?> diff --git a/htdocs/telephonie/stats/distributeurs/distributeur.commission.class.php b/htdocs/telephonie/stats/distributeurs/distributeur.commission.class.php new file mode 100644 index 00000000000..f49e3ff562e --- /dev/null +++ b/htdocs/telephonie/stats/distributeurs/distributeur.commission.class.php @@ -0,0 +1,93 @@ + + * + * 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/bar.class.php"); + +class GraphDistributeurCommission extends GraphBar { + + Function GraphDistributeurCommission($DB, $file) + { + $this->db = $DB; + $this->file = $file; + + $this->client = 0; + $this->titre = "Commission mensuelle"; + + $this->barcolor = "orange"; + $this->showframe = true; + } + + Function GraphMakeGraph($distributeur=0) + { + $num = 0; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_stats"; + $sql .= " WHERE graph='distributeur.commission.mensuel.".$distributeur."';"; + + $resql = $this->db->query($sql); + + $sql = "SELECT date, montant"; + $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_commission"; + $sql .= " WHERE fk_distributeur = ".$distributeur; + $sql .= " ORDER BY date ASC"; + + $resql = $this->db->query($sql); + + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + $j = -1; + $datas = array(); + $labels = array(); + + while ($i < $num) + { + $row = $this->db->fetch_row($resql); + + $datas[$i] = $row[1]; + $labels[$i] = substr($row[0],-2)."/".substr($row[0],2,2); + + $sqli = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_stats"; + $sqli .= " (graph,ord,legend,valeur)"; + $sqli .= " VALUES ('distributeur.commission.mensuel.".$distributeur."'"; + $sqli .= ",'$i','".$row[0]."','".$datas[$i]."');"; + + $resqli = $this->db->query($sqli); + + $i++; + } + + $this->db->free($resql); + } + else + { + print $this->db->error() . ' ' . $sql; + } + + if (sizeof($datas)) + { + $this->GraphDraw($this->file, $datas, $labels); + } + } +} +?>