From e0d479a2bbdaef95783db55178d73f03b76460f1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 13 Aug 2006 13:30:53 +0000 Subject: [PATCH] =?UTF-8?q?Simplification=20de=20la=20couche=20generant=20?= =?UTF-8?q?les=20graphs.=20Tous=20les=20graphs=20passent=20par=20la=20clas?= =?UTF-8?q?se=20DolGraph.=20C'est=20cette=20classe=20qui=20doit=20ensuite?= =?UTF-8?q?=20s'appuier=20directement=20sur=20PHPlot=20ou=20une=20autre=20?= =?UTF-8?q?librairie=20graphique=20libre.=20Qual:=20La=20g=E9n=E9ration=20?= =?UTF-8?q?des=20soldes=20ne=20fait=20plus=20exception=20ce=20qui=20permet?= =?UTF-8?q?=20de=20ne=20plus=20d=E9pendre=20de=20jpgraph=20qui=20n'est=20p?= =?UTF-8?q?as=20libre.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/bargraph.class.php | 106 ------- htdocs/comm/propal/stats/index.php | 11 +- htdocs/comm/propal/stats/month.php | 28 +- htdocs/comm/propal/stats/pre.inc.php | 4 +- htdocs/commande/stats/index.php | 18 +- htdocs/commande/stats/month.php | 33 +- htdocs/commande/stats/pre.inc.php | 35 +- htdocs/compta/bank/graph.php | 403 ++++++++++++++++++++++-- htdocs/compta/facture/stats/index.php | 9 +- htdocs/compta/facture/stats/month.php | 25 +- htdocs/compta/facture/stats/pre.inc.php | 9 +- htdocs/dolgraph.class.php | 348 ++++++++++++++++++++ htdocs/expedition/stats/month.php | 11 +- htdocs/expedition/stats/pre.inc.php | 12 +- htdocs/graph.class.php | 268 ---------------- htdocs/main.inc.php | 2 +- htdocs/product/stats/fiche.php | 31 +- htdocs/product/stats/pre.inc.php | 1 - htdocs/rapport/Atome.class.php | 8 +- htdocs/rapport/index.php | 8 +- 20 files changed, 870 insertions(+), 500 deletions(-) delete mode 100644 htdocs/bargraph.class.php create mode 100644 htdocs/dolgraph.class.php delete mode 100644 htdocs/graph.class.php diff --git a/htdocs/bargraph.class.php b/htdocs/bargraph.class.php deleted file mode 100644 index 12e53eaaeca..00000000000 --- a/htdocs/bargraph.class.php +++ /dev/null @@ -1,106 +0,0 @@ - - * Copyright (c) 2004-2005 Laurent Destailleur - * - * 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$ - */ - -/** - \file htdocs/bargraph.class.php - \brief Fichier de la classe de gestion de graphs phplot - \version $Revision$ -*/ - -include_once(DOL_DOCUMENT_ROOT."/graph.class.php"); - - -/** - \class BarGraph - \brief Classe permettant la gestion des graphs Bar a travers de PHPlot - \remarks Usage: - $graph_data = array("1"=>10,"2"=>20); - $px = new BarGraph(); - $px->SetData($graph_data); - $px->SetTitle("title"); - $px->SetLegend(array("Val1","Val2")); - $px->SetWidth(width); - $px->SetHeight(height); - $px->draw("file.png"); -*/ - -class BarGraph extends Graph -{ - var $db; - var $error; - - - /** - * \brief Initialisation graphe - * \return int <0 si ko, >0 si ok - */ - function BarGraph() - { - global $conf; - - // Test si module GD présent - $modules_list = get_loaded_extensions(); - $isgdinstalled=0; - foreach ($modules_list as $module) - { - if ($module == 'gd') { $isgdinstalled=1; } - } - if (! $isgdinstalled) { - $this->error="Erreur: Le module GD pour php ne semble pas disponible. Il est requis pour générer les graphiques."; - return -1; - } - - // Défini propriétés de l'objet graphe - $this->data = $data; // En general data non defini qd on crée objet - - $this->bordercolor = array(235,235,224); - $this->datacolor = array(array(204,204,179), array(187,187,136), array(235,235,224)); - $this->bgcolor = array(235,235,224); - - $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php"; - if (is_readable($color_file)) - { - include($color_file); - if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor; - if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor; - if (isset($theme_bgcolor)) $this->bgcolor = $theme_bgcolor; - } - - $this->precision_y = 0; - - $this->width = 400; - $this->height = 200; - - $this->PlotType = 'bars'; - - return 1; - } - - - function isGraphKo() - { - return $this->error; - } - -} - -?> diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php index 74076db0b9d..df41da8328e 100644 --- a/htdocs/comm/propal/stats/index.php +++ b/htdocs/comm/propal/stats/index.php @@ -29,7 +29,8 @@ */ require("./pre.inc.php"); -require("./propalestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/comm/propal/stats/propalestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); $WIDTH=500; $HEIGHT=250; @@ -56,12 +57,14 @@ else $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=nbpropale2year-'.$year.'.png'; } -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); + $px->SetPrecisionY(0); $px->SetLegend(array($year - 1, $year)); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->draw($filename); diff --git a/htdocs/comm/propal/stats/month.php b/htdocs/comm/propal/stats/month.php index f1fcd615e19..79e9ad84b9b 100644 --- a/htdocs/comm/propal/stats/month.php +++ b/htdocs/comm/propal/stats/month.php @@ -29,7 +29,9 @@ */ require("./pre.inc.php"); -require("./propalestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/comm/propal/stats/propalestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); + llxHeader(); @@ -65,11 +67,13 @@ else $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propale'.$year.'.png'; } -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetPrecisionY(0); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->draw($filename); @@ -95,12 +99,14 @@ else $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleamount'.$year.'.png'; } -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); + $px->SetPrecisionY(0); $px->SetYLabel($langs->trans("AmountTotal")); - $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->draw($filename_amount, $data, $year); @@ -125,12 +131,14 @@ else $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage'.$year.'.png'; } -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); + $px->SetPrecisionY(0); $px->SetYLabel($langs->trans("AmountAverage")); - $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->draw($filename_avg); diff --git a/htdocs/comm/propal/stats/pre.inc.php b/htdocs/comm/propal/stats/pre.inc.php index 8824dbcc6a2..dbf3d3ec8e2 100644 --- a/htdocs/comm/propal/stats/pre.inc.php +++ b/htdocs/comm/propal/stats/pre.inc.php @@ -29,9 +29,9 @@ */ require("../../../main.inc.php"); -require(DOL_DOCUMENT_ROOT."/bargraph.class.php"); -function llxHeader($head = "", $urlp = "") { +function llxHeader($head = "", $urlp = "") +{ global $user, $conf, $langs; $langs->load("companies"); diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php index 800e53902b4..1d32ddf5b26 100644 --- a/htdocs/commande/stats/index.php +++ b/htdocs/commande/stats/index.php @@ -28,15 +28,15 @@ */ require("./pre.inc.php"); - -if (!$user->rights->commande->lire) accessforbidden(); - -require(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); -require("./commandestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); +require_once(DOL_DOCUMENT_ROOT."/commande/stats/commandestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); $WIDTH=500; $HEIGHT=250; +if (!$user->rights->commande->lire) accessforbidden(); + // Sécurité accés client if ($user->societe_id > 0) { @@ -75,11 +75,13 @@ else $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=nbcommande2year-'.$year.'.png'; } -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetPrecisionY(0); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetLegend(array($year - 1, $year)); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); diff --git a/htdocs/commande/stats/month.php b/htdocs/commande/stats/month.php index ecb9e3b9f45..3c21b31bf4e 100644 --- a/htdocs/commande/stats/month.php +++ b/htdocs/commande/stats/month.php @@ -29,12 +29,11 @@ */ require("./pre.inc.php"); -require(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); -require("./commandestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); +require_once(DOL_DOCUMENT_ROOT."/commande/stats/commandestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); -/* - * Sécurité accés client - */ +// Sécurité accés client if ($user->societe_id > 0) { $action = ''; @@ -75,11 +74,13 @@ else $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commande'.$year.'.png'; } -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetPrecisionY(0); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->SetYLabel("Nombre de commande"); @@ -106,11 +107,13 @@ else $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeamount'.$year.'.png'; } -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); - $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetPrecisionY(0); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->SetYLabel($langs->trans("AmountTotal")); @@ -136,11 +139,13 @@ else $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeaverage'.$year.'.png'; } -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); - $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetPrecisionY(0); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->SetYLabel($langs->trans("AmountAverage")); diff --git a/htdocs/commande/stats/pre.inc.php b/htdocs/commande/stats/pre.inc.php index 693c0bc311f..e3fdb59be72 100644 --- a/htdocs/commande/stats/pre.inc.php +++ b/htdocs/commande/stats/pre.inc.php @@ -18,40 +18,39 @@ * * $Id$ * $Source$ - * */ -/*! - \file htdocs/commande/stats/pre.inc.php - \ingroup commandes - \brief Gestionnaire du menu commandes - \version $Revision$ +/** + \file htdocs/commande/stats/pre.inc.php + \ingroup commandes + \brief Gestionnaire du menu commandes + \version $Revision$ */ require("../../main.inc.php"); -require("../../bargraph.class.php"); $user->getrights('commande'); $langs->load("orders"); + function llxHeader($head = "", $title="", $help_url='') { - global $user, $conf, $langs; + global $user, $conf, $langs; - top_menu($head, $title); + top_menu($head, $title); - $menu = new Menu(); + $menu = new Menu(); - $menu->add(DOL_URL_ROOT."/commande/", $langs->trans("Orders")); - $menu->add_submenu(DOL_URL_ROOT."/commande/liste.php", $langs->trans("List")); - $menu->add_submenu(DOL_URL_ROOT."/commande/stats/", $langs->trans("Statistics")); + $menu->add(DOL_URL_ROOT."/commande/", $langs->trans("Orders")); + $menu->add_submenu(DOL_URL_ROOT."/commande/liste.php", $langs->trans("List")); + $menu->add_submenu(DOL_URL_ROOT."/commande/stats/", $langs->trans("Statistics")); - if ($conf->expedition->enabled) - { - $menu->add(DOL_URL_ROOT."/expedition/", $langs->trans("Sendings")); - } + if ($conf->expedition->enabled) + { + $menu->add(DOL_URL_ROOT."/expedition/", $langs->trans("Sendings")); + } - left_menu($menu->liste, $help_url); + left_menu($menu->liste, $help_url); } ?> diff --git a/htdocs/compta/bank/graph.php b/htdocs/compta/bank/graph.php index 0960b33cf8a..788214bb619 100644 --- a/htdocs/compta/bank/graph.php +++ b/htdocs/compta/bank/graph.php @@ -1,5 +1,6 @@ + * Copyright (C) 2006 Laurent Destailleur * * 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 @@ -19,7 +20,8 @@ * $Source$ */ -/** \file htdocs/compta/bank/graph.php +/** + \file htdocs/compta/bank/graph.php \ingroup banque \brief Page de détail des transactions bancaires \version $Revision$ @@ -27,12 +29,13 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); if (!$user->rights->banque->lire) accessforbidden(); $account = $_GET["account"]; - +$mesg = ''; llxHeader(); @@ -40,12 +43,363 @@ llxHeader(); if ($account > 0) { $datetime = time(); - $month = strftime("%m", $datetime); $year = strftime("%Y", $datetime); + $month = strftime("%m", $datetime); + $day = strftime("%d", $datetime); $acct = new Account($db); $acct->fetch($account); - + + // Definition de $width et $height + $width = 750; + $height = 280; + + // Calcul de $min et $max + $sql = "SELECT min(".$db->pdate("datev")."),max(".$db->pdate("datev").")"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account = ".$account; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $row = $db->fetch_row($resql); + $min = $row[0]; + $max = $row[1]; + } + else + { + dolibarr_print_error($db); + } +// print strftime("%Y%m%d",$max); + + // Chargement du tableau $amounts + // \todo peut etre optimise en virant les date_format + $amounts = array(); + $sql = "SELECT date_format(datev,'%Y%m%d'), sum(amount)"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account = ".$account; + $sql .= " AND date_format(datev,'%Y%m') = '".$year.$month."'"; + $sql .= " GROUP BY date_format(datev,'%Y%m%d')"; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $amounts[$row[0]] = $row[1]; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + // Calcul de $solde avant le debut du graphe + $solde = 0; + $sql = "SELECT sum(amount)"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account = ".$account; + $sql .= " AND datev < '".$year."-".sprintf("%02s",$month)."-01'"; + $resql = $db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + $solde = $row[0]; + } + else + { + dolibarr_print_error($db); + } + + // Chargement de labels et datas pour tableau 1 + $labels = array(); + $datas = array(); + + $subtotal = 0; + $day = mktime(1,1,1,$month,1,$year); + $xmonth = substr("00".strftime("%m",$day), -2); + $i = 0; + while ($xmonth == $month) + { + //print strftime ("%e %d %m %y",$day)."\n"; + $subtotal = $subtotal + (isset($amounts[strftime("%Y%m%d",$day)]) ? $amounts[strftime("%Y%m%d",$day)] : 0); + if ($day > time()) + { + $datas[$i] = ''; // Valeur spéciale permettant de ne pas tracer le graph + } + else + { + $datas[$i] = $solde + $subtotal; + } + //$labels[$i] = strftime("%d",$day); + $labels[$i] = strftime("%d",$day); + $day += 86400; + $xmonth = substr("00".strftime("%m",$day), -2); + $i++; + } + + // Fabrication tableau 1 + $file= $conf->banque->dir_images."/solde.$account.$year.$month.png"; + $title=$langs->trans("Balance").' '.$langs->trans("Month").': '.$month.' '.$langs->trans("Year").': '.$year; + $graph_datas=array(); + foreach($datas as $i => $val) + { + $graph_datas[$i]=array("$labels[$i]",$datas[$i]); + } + $px = new DolGraph(); + $px->SetData($graph_datas); + $px->SetLegend(array($langs->trans("Balance"))); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetTitle($title); + $px->SetWidth($width); + $px->SetHeight($height); + $px->SetType('lines'); + $px->draw($file); + + + // Chargement du tableau $amounts + // \todo peut etre optimise en virant les date_format + $amounts = array(); + $sql = "SELECT date_format(datev,'%Y%m%d'), sum(amount)"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account = ".$account; + $sql .= " AND date_format(datev,'%Y') = '".$year."'"; + $sql .= " GROUP BY date_format(datev,'%Y%m%d')"; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $amounts[$row[0]] = $row[1]; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + // Calcul de $solde avant le debut du graphe + $solde = 0; + $sql = "SELECT sum(amount)"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account = ".$account; + $sql .= " AND datev < '".$year."-01-01'"; + $resql = $db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + $solde = $row[0]; + } + else + { + dolibarr_print_error($db); + } + + // Chargement de labels et datas pour tableau 2 + $labels = array(); + $datas = array(); + + $subtotal = 0; + $day = mktime(1,1,1,1,1,$year); + $xyear = strftime("%Y",$day); + $i = 0; + while ($xyear == $year) + { + $subtotal = $subtotal + (isset($amounts[strftime("%Y%m%d",$day)]) ? $amounts[strftime("%Y%m%d",$day)] : 0); + //print strftime ("%e %d %m %y",$day)." ".$subtotal."\n
"; + if ($day > time()) + { + $datas[$i] = ''; // Valeur spéciale permettant de ne pas tracer le graph + } + else + { + $datas[$i] = $solde + $subtotal; + } + if (strftime("%d",$day) == 15) + { + $labels[$i] = strftime("%m",$day); + } + $day += 86400; + $xyear = strftime("%Y",$day); + $i++; + } + + // Fabrication tableau 2 + $file= $conf->banque->dir_images."/solde.$account.$year.png"; + $title=$langs->trans("Balance").' '.$langs->trans("Year").': '.$year; + $graph_datas=array(); + foreach($datas as $i => $val) + { + $graph_datas[$i]=array(isset($labels[$i])?$labels[$i]:'',$datas[$i]); + } + $px = new DolGraph(); + $px->SetData($graph_datas); + $px->SetLegend(array($langs->trans("Balance"))); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetTitle($title); + $px->SetWidth($width); + $px->SetHeight($height); + $px->SetType('lines'); + $px->draw($file); + + + // Chargement du tableau $amounts + // \todo peut etre optimise en virant les date_format + $amounts = array(); + $sql = "SELECT date_format(datev,'%Y%m%d'), sum(amount)"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account = ".$account; + $sql .= " GROUP BY date_format(datev,'%Y%m%d')"; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + while ($i < $num) + { + $row = $db->fetch_row($resql); + $amounts[$row[0]] = $row[1]; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + // Calcul de $solde avant le debut du graphe + $solde = 0; + + // Chargement de labels et datas pour tableau 3 + $labels = array(); + $datas = array(); + $subtotal = 0; + $day = $min; + $i = 0; + while ($day <= ($max+1000000)) // On va bien au dela du dernier jour + { + $subtotal = $subtotal + (isset($amounts[strftime("%Y%m%d",$day)]) ? $amounts[strftime("%Y%m%d",$day)] : 0); + //print strftime ("%e %d %m %y",$day)." ".$subtotal."\n
"; + if ($day > ($max+86400)) + { + $datas[$i] = ''; // Valeur spéciale permettant de ne pas tracer le graph + } + else + { + $datas[$i] = $solde + $subtotal; + } + if (strftime("%d",$day) == 1) + { + $labels[$i] = strftime("%m",$day); + } + $day += 86400; + $i++; + } + + // Fabrication tableau 3 + $file= $conf->banque->dir_images."/solde.$account.png"; + $title=$langs->trans("Balance"); + $graph_datas=array(); + foreach($datas as $i => $val) + { + $graph_datas[$i]=array(isset($labels[$i])?$labels[$i]:'',$datas[$i]); + } + $px = new DolGraph(); + $px->SetData($graph_datas); + $px->SetLegend(array($langs->trans("Balance"))); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetTitle($title); + $px->SetWidth($width); + $px->SetHeight($height); + $px->SetType('lines'); + $px->draw($file); + + + // Chargement du tableau $credits, $debits + $credits = array(); + $debits = array(); + $sql = "SELECT date_format(datev,'%m'), sum(amount)"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account = ".$account; + $sql .= " AND date_format(datev,'%Y') = '".$year."'"; + $sql .= " AND amount > 0"; + $sql .= " GROUP BY date_format(datev,'%m');"; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $credits[$row[0]] = $row[1]; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + $sql = "SELECT date_format(datev,'%m'), sum(amount)"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account = ".$account; + $sql .= " AND date_format(datev,'%Y') = '".$year."'"; + $sql .= " AND amount < 0"; + $sql .= " GROUP BY date_format(datev,'%m');"; + $resql = $db->query($sql); + if ($resql) + { + while ($row = $db->fetch_row($resql)) + { + $debits[$row[0]] = abs($row[1]); + } + } + else + { + dolibarr_print_error($db); + } + + // Chargement de labels et data_xxx pour tableau 4 + $labels = array(); + $data_credit = array(); + $data_debit = array(); + for ($i = 0 ; $i < 12 ; $i++) + { + $data_credit[$i] = isset($credits[substr("0".($i+1),-2)]) ? $credits[substr("0".($i+1),-2)] : 0; + $data_debit[$i] = isset($debits[substr("0".($i+1),-2)]) ? $debits[substr("0".($i+1),-2)] : 0; + $labels[$i] = $i+1; + } + + // Fabrication tableau 4 + $file= $conf->banque->dir_images."/mouvement.$account.$year.png"; + $title=$langs->trans("Movements").' '.$langs->trans("Year").': '.$year; + $graph_datas=array(); + foreach($data_credit as $i => $val) + { + $graph_datas[$i]=array($labels[$i],$data_credit[$i],$data_debit[$i]); + } + $px = new DolGraph(); + $px->SetData($graph_datas); + $px->SetLegend(array($langs->trans("Debit"),$langs->trans("Credit"))); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetTitle($title); + $px->SetWidth($width); + $px->SetHeight($height); + $px->SetType('bars'); + $px->SetShading(8); + $px->draw($file); + $titre=$langs->trans("FinancialAccount")." : ".$acct->label; print_fiche_titre($titre,$mesg); @@ -53,36 +407,31 @@ if ($account > 0) // Onglets $head=bank_prepare_head($acct); dolibarr_fiche_head($head,'graph',$langs->trans("FinancialAccount"),0); - + print ''; - print ''; + + print ''; + print ''; - print '
'; + + print '
'; + $file = "solde.$account.$year.$month.png"; + print ''; + print '
'; $file = "solde.$account.$year.png"; - - if (! file_exists($conf->banque->dir_images."/".$file)) - { - print "Pour générer ou regénérer les graphiques, lancer le script ./scripts/banque/graph-solde.php en ligne de commande.
"; - print '
'; - } - else - { - print ''; - } - print ''; - print '
'; - - $file = "mouvement.$account.$year.png"; - - print ''; - - - print '
'; + print '
'; $file = "solde.$account.png"; - print ''; + print '
'; + print ''; + $file = "mouvement.$account.$year.png"; + print ''; + print ''; + + + print ''; print "\n\n"; diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index 1688710e291..9d258e3642d 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -29,6 +29,7 @@ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); $WIDTH=500; $HEIGHT=250; @@ -56,11 +57,13 @@ if (! is_dir($conf->facture->dir_images)) { mkdir($conf->facture->dir_images); } $filename = $conf->facture->dir_images."/nbfacture2year-".$year.".png"; $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=nbfacture2year-'.$year.'.png'; -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetPrecisionY(0); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetLegend(array($year - 1, $year)); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); diff --git a/htdocs/compta/facture/stats/month.php b/htdocs/compta/facture/stats/month.php index add0aa76ea0..1a62821429c 100644 --- a/htdocs/compta/facture/stats/month.php +++ b/htdocs/compta/facture/stats/month.php @@ -29,6 +29,7 @@ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); $GRAPHHEIGHT=250; $GRAPHWIDTH=500; @@ -60,11 +61,13 @@ if (! is_dir($conf->facture->dir_images)) { mkdir($conf->facture->dir_images); } $filename = $conf->facture->dir_images."/facture".$year.".png"; $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=facture'.$year.'.png'; -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetPrecisionY(0); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); $px->draw($filename); @@ -82,12 +85,14 @@ for ($i = 1 ; $i < 13 ; $i++) $filename_amount = $conf->facture->dir_images."/factureamount".$year.".png"; $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=factureamount'.$year.'.png'; -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); $px->SetYLabel($langs->trans("AmountTotal")); - $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetPrecisionY(0); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); $px->draw($filename_amount); @@ -104,12 +109,14 @@ for ($i = 1 ; $i < 13 ; $i++) $filename_avg = $conf->facture->dir_images."/factureaverage".$year.".png"; $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=factureaverage'.$year.'.png'; -$px = new BarGraph(); +$px = new DolGraph(); $mesg = $px->isGraphKo(); -if (! $mesg) { +if (! $mesg) +{ $px->SetData($data); + $px->SetPrecisionY(0); $px->SetYLabel($langs->trans("AmountAverage")); - $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($GRAPHWIDTH); $px->SetHeight($GRAPHHEIGHT); $px->draw($filename_avg); diff --git a/htdocs/compta/facture/stats/pre.inc.php b/htdocs/compta/facture/stats/pre.inc.php index 71256cbeb49..ef9df39e583 100644 --- a/htdocs/compta/facture/stats/pre.inc.php +++ b/htdocs/compta/facture/stats/pre.inc.php @@ -28,8 +28,8 @@ */ require("../../../main.inc.php"); -require(DOL_DOCUMENT_ROOT."/bargraph.class.php"); -require("./facturestats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/facture/stats/facturestats.class.php"); + function llxHeader($head = "", $urlp = "") { @@ -37,10 +37,6 @@ function llxHeader($head = "", $urlp = "") $langs->load("bills"); $langs->load("propal"); - /* - * - * - */ top_menu($head); $menu = new Menu(); @@ -50,6 +46,5 @@ function llxHeader($head = "", $urlp = "") $menu->add("index.php", $langs->trans("Statistics")); left_menu($menu->liste); - } ?> diff --git a/htdocs/dolgraph.class.php b/htdocs/dolgraph.class.php new file mode 100644 index 00000000000..559d78e9a04 --- /dev/null +++ b/htdocs/dolgraph.class.php @@ -0,0 +1,348 @@ + + * Copyright (c) 2004-2006 Laurent Destailleur + * + * 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$ + */ + +/** + \file htdocs/dolgraph.class.php + \brief Fichier de la classe mère de gestion des graph phplot + \version $Revision$ + \remarks Usage: + $graph_data = array(array('labelA',yA),array('labelB',yB)); + array(array('labelA',yA1,...,yAn),array('labelB',yB1,...yBn)); + $px = new DolGraph(); + $px->SetData($graph_data); + $px->SetMaxValue($px->GetCeilMaxValue()); + $px->SetMinValue($px->GetFloorMinValue()); + $px->SetTitle("title"); + $px->SetLegend(array("Val1","Val2")); + $px->SetWidth(width); + $px->SetHeight(height); + $px->draw("file.png"); +*/ + + +/** + \class Graph + \brief Classe mère permettant la gestion des graph +*/ + +class DolGraph +{ + var $type='bars'; // Type de graph + var $data; // Tableau de donnees + var $width=380; + var $height=200; + var $MaxValue=0; + var $MinValue=0; + var $SetShading=0; + var $PrecisionY=-1; + + var $graph; // Objet PHPlot + + var $error; + + + function DolGraph() + { + global $conf; + + // Test si module GD présent + $modules_list = get_loaded_extensions(); + $isgdinstalled=0; + foreach ($modules_list as $module) + { + if ($module == 'gd') { $isgdinstalled=1; } + } + if (! $isgdinstalled) { + $this->error="Erreur: Le module GD pour php ne semble pas disponible. Il est requis pour générer les graphiques."; + return -1; + } + + // Vérifie que chemin vers PHPLOT_PATH est connu et defini $graphpath + $graphpathdir=DOL_DOCUMENT_ROOT."/includes/phplot"; + if ($conf->global->PHPLOT_PATH) $graphpathdir=$conf->global->PHPLOT_PATH; + if (! eregi('[\\\/]$',$graphpathdir)) $graphpathdir.='/'; + + include_once($graphpathdir.'phplot.php'); + + + // Défini propriétés de l'objet graphe + $this->bordercolor = array(235,235,224); + $this->datacolor = array(array(120,130,150), array(160,160,180), array(190,190,220)); + $this->bgcolor = array(235,235,224); + + $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php"; + if (is_readable($color_file)) + { + include($color_file); + if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor; + if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor; + if (isset($theme_bgcolor)) $this->bgcolor = $theme_bgcolor; + } + + return 1; + } + + + function isGraphKo() + { + return $this->error; + } + + + /** + * \brief Génère le fichier graphique sur le disque + * \param file Nom du fichier image + */ + function draw($file) + { + // Prepare parametres + $this->prepare($file); + + // Génère le fichier $file + $this->graph->DrawGraph(); + } + + /** + * \brief Prépare l'objet PHPlot + * \param file Nom du fichier image à générer + */ + function prepare($file) + { + // Define the object + $this->graph = new PHPlot($this->width, $this->height); + $this->graph->SetIsInline(1); + + $this->graph->SetPlotType($this->type); + $this->graph->SetDataValues($this->data); + + // Precision axe y (pas de decimal si 3 chiffres ou plus) + if ($this->PrecisionY > -1) + { + $this->graph->SetPrecisionY($this->PrecisionY); + // Si precision de 0 + if ($this->PrecisionY == 0) + { + $maxval=$this->getCeilMaxValue(); + if (abs($maxval) < 2) + { + $this->SetMaxValue(2); + $this->graph->SetNumVertTicks(2); + } + else + { + $maxticks=min(10,$maxval); + $this->graph->SetNumVertTicks($maxticks); + } + } + } + else + { + $this->graph->SetPrecisionY(3-strlen(round($this->GetMaxValueInData()))); + } + $this->graph->SetPrecisionX(0); + + // Set areas + $this->graph->SetNewPlotAreaPixels(80, 40, $this->width-10, $this->height-40); + if (isset($this->MaxValue)) + { + $this->graph->SetPlotAreaWorld(0,$this->MinValue,sizeof($this->data),$this->MaxValue); + } + + if (isset($this->SetShading)) + { + $this->graph->SetShading($this->SetShading); + } + $this->graph->SetTickLength(6); + + $this->graph->SetBackgroundColor($this->bgcolor); + $this->graph->SetDataColors($this->datacolor, $this->bordercolor); + + //$this->graph->SetDrawHorizTicks(true); // Pour avoir les ticks axe x (phplot 5) + $this->graph->SetHorizTickIncrement(1); + + + //$this->graph->SetXGridLabelType('data'); + //$this->graph->SetXGridLabelType(''); + //$this->graph->SetXGridLabelType('title'); + + $this->graph->SetPlotBorderType("left"); // Affiche axe y a gauche uniquement + $this->graph->SetVertTickPosition('plotleft'); // Affiche tick axe y a gauche uniquement + + + + + + // Define title + if (strlen($this->title)) $this->graph->SetTitle($this->title); + + // Défini position du graphe (et legende) au sein de l'image + if (isset($this->Legend)) + { + $this->graph->SetLegend($this->Legend); + } + + $this->graph->SetOutputFile($file); + } + + function SetPrecisionY($which_prec) + { + $this->PrecisionY = $which_prec; + return true; + } + + function SetYLabel($label) + { + $this->YLabel = $label; + } + + function SetWidth($w) + { + $this->width = $w; + } + + function SetTitle($title) + { + $this->title = $title; + } + + function SetData($data) + { + $this->data = $data; + } + + function SetType($type) + { + $this->type = $type; + } + + function SetLegend($legend) + { + $this->Legend = $legend; + } + + function SetMaxValue($max) + { + $this->MaxValue = $max; + } + + function SetMinValue($min) + { + $this->MinValue = $min; + } + + function SetHeight($h) + { + $this->height = $h; + } + + function SetShading($s) + { + $this->SetShading = $s; + } + + function ResetBgColor() + { + unset($this->bgcolor); + } + + function SetBgColor($bg_color = array(255,255,255)) + { + $this->bgcolor = $bg_color; + } + + function ResetDataColor() + { + unset($this->datacolor); + } + + function GetMaxValueInData() + { + $k = 0; + $vals = array(); + + $nblines = sizeof($this->data); + $nbvalues = sizeof($this->data[0]) - 1; + + for ($j = 0 ; $j < $nblines ; $j++) + { + for ($i = 0 ; $i < $nbvalues ; $i++) + { + $vals[$k] = $this->data[$j][$i+1]; + $k++; + } + } + rsort($vals); + return $vals[0]; + } + + function GetMinValueInData() + { + $k = 0; + $vals = array(); + + $nblines = sizeof($this->data); + $nbvalues = sizeof($this->data[0]) - 1; + + for ($j = 0 ; $j < $nblines ; $j++) + { + for ($i = 0 ; $i < $nbvalues ; $i++) + { + $vals[$k] = $this->data[$j][$i+1]; + $k++; + } + } + sort($vals); + return $vals[0]; + } + + function GetCeilMaxValue() + { + $max = $this->GetMaxValueInData(); + $size=strlen(abs(ceil($max))); + $factor=1; + for ($i=0; $i < ($size-1); $i++) + { + $factor*=10; + } + $res=ceil($max/$factor)*$factor; + + //print "max=".$max." res=".$res; + return $res; + } + + function GetFloorMinValue() + { + $min = $this->GetMinValueInData(); + $size=strlen(abs(floor($min))); + $factor=1; + for ($i=0; $i < ($size-1); $i++) + { + $factor*=10; + } + $res=floor($min/$factor)*$factor; + + //print "min=".$min." res=".$res; + return $res; + } +} + +?> diff --git a/htdocs/expedition/stats/month.php b/htdocs/expedition/stats/month.php index db7487539cf..6be604527b1 100644 --- a/htdocs/expedition/stats/month.php +++ b/htdocs/expedition/stats/month.php @@ -29,8 +29,10 @@ */ require("./pre.inc.php"); -require("../expedition.class.php"); -require("./expeditionstats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/expedition/expedition.class.php"); +require_once(DOL_DOCUMENT_ROOT."/expedition/stats/expeditionstats.class.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); + llxHeader(); @@ -46,9 +48,10 @@ if (! is_dir($conf->expedition->dir_images)) { mkdir($conf->expedition->dir_imag $filename = $conf->expedition->dir_images."/expedition".$year.".png"; $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=expeditionstats&file=expedition'.$year.'.png'; -$px = new BarGraph(); +$px = new DolGraph(); $px->SetData($data); -$px->SetMaxValue($px->GetMaxValue()); +$px->SetMaxValue($px->GetCeilMaxValue()); +$px->SetPrecisionY(0); $px->SetWidth(600); $px->SetHeight(280); $px->draw($filename); diff --git a/htdocs/expedition/stats/pre.inc.php b/htdocs/expedition/stats/pre.inc.php index c099c5fda96..f1582422897 100644 --- a/htdocs/expedition/stats/pre.inc.php +++ b/htdocs/expedition/stats/pre.inc.php @@ -1,5 +1,6 @@ + * Copyright (C) 2006 Laurent Destailleur * * 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 @@ -17,10 +18,17 @@ * * $Id$ * $Source$ - * */ + +/** + \file htdocs/product/stats/pre.inc.php + \ingroup expedition + \brief Fichier gestionnaire du menu gauche des statistiques expedition + \version $Revision$ +*/ + require("../../main.inc.php"); -require("../../bargraph.class.php"); + $langs->load("orders"); function llxHeader($head = "", $title="", $urlp = "") diff --git a/htdocs/graph.class.php b/htdocs/graph.class.php deleted file mode 100644 index e42e9152d37..00000000000 --- a/htdocs/graph.class.php +++ /dev/null @@ -1,268 +0,0 @@ - - * Copyright (c) 2004-2005 Laurent Destailleur - * - * 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$ - */ - -/** - \file htdocs/graph.class.php - \brief Fichier de la classe mère de gestion des graph phplot - \version $Revision$ -*/ - -include_once(DOL_DOCUMENT_ROOT."/includes/phplot/phplot.php"); - - -/** - \class Graph - \brief Classe mère permettant la gestion des graph phplot -*/ - -class Graph -{ - var $db; - var $errorstr; - - var $graph; // Objet PHPlot - - - /** - * \brief Génère le fichier graphique sur le disque - * \param file Nom du fichier image - */ - function draw($file) - { - // Prepare parametres - $this->prepare($file); - - // Génère le fichier $file - $this->graph->DrawGraph(); - } - - /** - * \brief Prépare l'objet PHPlot - * \param file Nom du fichier image à générer - */ - function prepare($file) - { - // Define the object - $this->graph = new PHPlot($this->width, $this->height); - $this->graph->SetIsInline(1); - - $this->graph->SetPlotType( $this->PlotType ); - - //Set some data - $this->graph->SetDataValues($this->data); - - if (isset($this->MaxValue)) - { - $nts = array(); - $this->MaxValue = $this->MaxValue + 1; - $max = $this->MaxValue; - if (($max % 2) <> 0) - { - $this->MaxValue = $this->MaxValue + 1; - $max++; - } - - $this->graph->SetPlotAreaWorld(0,0,12,$this->MaxValue); - - $j = 0; - for ($i = 1 ; $i < 11 ; $i++) - { - $res = $max % $i; - $cal = $max / $i; - - if ($res == 0 && $cal <= 11) - { - $nts[$j] = $cal; - $j++; - } - - } - rsort($nts); - - $this->graph->SetNumVertTicks($nts[0]); - } - else - { - $this->graph->SetPlotAreaPixels(60, 10, $this->width-10, $this->height - 30) ; - } - - $this->graph->SetBackgroundColor($this->bgcolor); - $this->graph->SetDataColors($this->datacolor, $this->bordercolor); - - // Define title - if (strlen($this->title)) $this->graph->SetTitle($this->title); - - // TODO - //$this->graph->SetPrecisionY($this->precision_Y); - // $this->graph->SetVertTickIncrement(0); - // $this->graph->SetSkipBottomTick(1); - - $this->graph->SetVertTickPosition('plotleft'); - - $this->graph->SetYGridLabelType("data"); - - $this->graph->SetDrawYGrid(1); - - // Affiche les valeurs - //$this->graph->SetDrawDataLabels('1'); - //$this->graph->SetLabelScalePosition('1'); - - $this->graph->SetOutputFile($file); - - // Défini position du graphe (et legende) au sein de l'image - if (isset($this->Legend)) - { - $this->graph->SetMarginsPixels(100,100,10,30); - - $this->graph->SetLegend($this->Legend); - $this->graph->SetLegendWorld(13,$this->MaxValue); - } - else - { - $this->graph->SetMarginsPixels(100,10,10,30); - } - - if (substr($this->MaxValue,0,1) == 1) - { - $this->graph->SetNumVertTicks(10); - } - elseif (substr($this->MaxValue,0,1) == 2) - { - $this->graph->SetNumVertTicks(4); - } - elseif (substr($this->MaxValue,0,1) == 3) - { - $this->graph->SetNumVertTicks(6); - } - elseif (substr($this->MaxValue,0,1) == 4) - { - $this->graph->SetNumVertTicks(8); - } - else - { - $this->graph->SetNumVertTicks(substr($this->MaxValue,0,1)); - } - - } - - function SetPrecisionY($which_prec) - { - $this->precision_y = $which_prec; - return true; - } - - function SetYLabel($label) - { - $this->YLabel = $label; - } - - function SetWidth($w) - { - $this->width = $w; - } - - function SetTitle($title) - { - $this->title = $title; - } - - function SetData($data) - { - $this->data = $data; - } - - function SetLegend($legend) - { - $this->Legend = $legend; - } - - function SetMaxValue($max) - { - $this->MaxValue = $max; - } - - function SetHeight($h) - { - $this->height = $h; - } - - function ResetBgColor() - { - unset($this->bgcolor); - } - - function SetBgColor($bg_color = array(255,255,255)) - { - $this->bgcolor = $bg_color; - } - - function ResetDataColor() - { - unset($this->datacolor); - } - - function GetMaxValue() - { - $k = 0; - $vals = array(); - - $nblines = sizeof($this->data); - $nbvalues = sizeof($this->data[0]) - 1; - - for ($j = 0 ; $j < $nblines ; $j++) - { - for ($i = 0 ; $i < $nbvalues ; $i++) - { - $vals[$k] = $this->data[$j][$i+1]; - $k++; - } - } - rsort($vals); - return $vals[0]; - } - - function GetAmountMaxValue() - { - - $max = ceil($this->GetMaxValue()); - $size = strlen("$max"); - if (substr($max,0,1) == 9) - { - $res = 1; - } - else - { - $size = $size - 1; - $res = substr($max,0,1) + 1; - } - - for ($i = 0 ; $i < $size ; $i++) - { - $res .= "0"; - } - - return ($res - 2); - } - -} - -?> diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 7ea13bedc4a..cc98aa5cc8d 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -427,7 +427,7 @@ function top_menu($head, $title="", $target="") * Si la constante MAIN_NEED_UPDATE est definie (par le script de migration sql en general), c'est que * les donnees ont besoin d'un remaniement. Il faut passer le update.php */ - if ($conf->global->MAIN_NEED_UPDATE) + if (isset($conf->global->MAIN_NEED_UPDATE) && $conf->global->MAIN_NEED_UPDATE) { $langs->load("admin"); print '
'."\n"; diff --git a/htdocs/product/stats/fiche.php b/htdocs/product/stats/fiche.php index d44296c2b41..e6182ce15e0 100644 --- a/htdocs/product/stats/fiche.php +++ b/htdocs/product/stats/fiche.php @@ -33,6 +33,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); +require_once(DOL_DOCUMENT_ROOT."/dolgraph.class.php"); $langs->load("products"); $langs->load("bills"); @@ -92,35 +93,49 @@ if ($_GET["id"] || $_GET["ref"]) $WIDTH=380; $HEIGHT=200; - $px = new BarGraph(); + $px = new DolGraph(); $mesg = $px->isGraphKo(); if (! $mesg) { $graph_data = $product->get_num_vente($socid); $px->SetData($graph_data); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); + $px->SetPrecisionY(0); + $px->SetShading(6); $px->draw($filenbvente); + } - $px = new BarGraph(); + $px = new DolGraph(); + $mesg = $px->isGraphKo(); + if (! $mesg) + { $graph_data = $product->get_nb_vente($socid); $px->SetData($graph_data); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); + $px->SetPrecisionY(0); + $px->SetShading(6); $px->draw($filenbpiece); + } - $px = new BarGraph(); + $px = new DolGraph(); + $mesg = $px->isGraphKo(); + if (! $mesg) + { $graph_data = $product->get_num_propal($socid); $px->SetData($graph_data); - $px->SetMaxValue($px->GetMaxValue()); + $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); + $px->SetPrecisionY(0); + $px->SetShading(6); $px->draw($filenbpropal); + } - $mesg = $langs->trans("ChartGenerated"); - } + $mesg = $langs->trans("ChartGenerated"); $head=product_prepare_head($product); diff --git a/htdocs/product/stats/pre.inc.php b/htdocs/product/stats/pre.inc.php index 73a682933cc..8312b8dca40 100644 --- a/htdocs/product/stats/pre.inc.php +++ b/htdocs/product/stats/pre.inc.php @@ -28,7 +28,6 @@ */ require("../../main.inc.php"); -require(DOL_DOCUMENT_ROOT."/bargraph.class.php"); function llxHeader($head = "", $urlp = "", $title="") diff --git a/htdocs/rapport/Atome.class.php b/htdocs/rapport/Atome.class.php index cd742637a89..ad0927c16cd 100644 --- a/htdocs/rapport/Atome.class.php +++ b/htdocs/rapport/Atome.class.php @@ -25,7 +25,7 @@ \brief Fichier de la classe mère Atome de génération de rapports */ -include_once DOL_DOCUMENT_ROOT.'/bargraph.class.php'; +include_once DOL_DOCUMENT_ROOT.'/dolgraph.class.php'; /** @@ -57,7 +57,7 @@ class Atome * * */ - function BarGraph() + function ShowGraph() { $dir = DOL_DATA_ROOT.'/rapport/images/'; if (! is_dir($dir)) create_exdir($dir); @@ -111,7 +111,7 @@ class Atome // var_dump($this->graph_values); - $bgraph = new BarGraph(); + $bgraph = new DolGraph(); $bgraph->SetData($this->graph_values); $bgraph->bgcolor = array(255,255,255); $bgraph->SetWidth(600); @@ -120,5 +120,5 @@ class Atome return $filename; } - } +} ?> diff --git a/htdocs/rapport/index.php b/htdocs/rapport/index.php index 83255b62328..0f8e32eb544 100644 --- a/htdocs/rapport/index.php +++ b/htdocs/rapport/index.php @@ -51,7 +51,7 @@ $arr = $x->fetch(); * Création du graph * -> retounre le nom du fichier */ -$img = $x->BarGraph(); +$img = $x->ShowGraph(); print $img."
"; @@ -60,7 +60,7 @@ print $img."
"; $x = new AtomeFactureValidee($db,'year', mktime(12,0,0,1,12,2003)); $arr = $x->fetch('year'); -$img = $x->BarGraph(); +$img = $x->ShowGraph(); print $img."
"; for ($i = 1 ; $i < 5; $i++) { @@ -70,7 +70,7 @@ for ($i = 1 ; $i < 5; $i++) $arr = $x->fetch('month'); - $img = $x->BarGraph(); + $img = $x->ShowGraph(); print $img."
"; } @@ -82,7 +82,7 @@ $arr = $x->fetch(); var_dump($arr); -$img = $x->BarGraph(); +$img = $x->ShowGraph(); print $img."
"; $db->close();