diff --git a/htdocs/bargraph.class.php b/htdocs/bargraph.class.php index c2926a99929..c41e73063ec 100644 --- a/htdocs/bargraph.class.php +++ b/htdocs/bargraph.class.php @@ -1,5 +1,6 @@ + * Copyright (c) 2004 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 @@ -25,14 +26,25 @@ class BarGraph extends Graph { var $db; var $errorstr; - + /** * Initialisation - * + * Retour: 0 si ko, 1 si ok */ - Function BarGraph($data=array()) - { + Function BarGraph($data=array()) { + + $modules_list = get_loaded_extensions(); + $isgdinstalled=0; + foreach ($modules_list as $module) + { + if ($module == 'gd') { $isgdinstalled=1; } + } + if (! $isgdinstalled) { + $this->errorstr="Erreur: Le module GD pour PHP ne semble pas disponible. Il est requis pour générer les graphiques."; + return; + } + $this->data = $data; include_once(DOL_DOCUMENT_ROOT."/includes/phplot/phplot.php"); @@ -51,15 +63,18 @@ class BarGraph extends Graph $this->PlotType = 'bars'; - return 1; + return; + } + + Function isGraphKo() { + return $this->errorstr; } /** * Dessine le graphique * */ - Function draw($file, $data, $title='') - { + Function draw($file, $data, $title='') { $this->prepare($file, $data, $title); if (substr($this->MaxValue,0,1) == 1) diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php index f6eedc3ab48..b106862f8f8 100644 --- a/htdocs/comm/propal/stats/index.php +++ b/htdocs/comm/propal/stats/index.php @@ -1,5 +1,6 @@ + * Copyright (C) 2004 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 @@ -36,13 +37,16 @@ $data = $stats->getNbByMonthWithPrevYear($year); $filev = "/document/images/nbpropale2year-$year.png"; $px = new BarGraph($data); -$px->SetMaxValue($px->GetMaxValue()); -$px->SetLegend(array($year - 1, $year)); -$px->SetWidth(450); -$px->SetHeight(280); +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetMaxValue($px->GetMaxValue()); + $px->SetLegend(array($year - 1, $year)); + $px->SetWidth(450); + $px->SetHeight(280); + + $px->draw(DOL_DOCUMENT_ROOT.$filev, $data, $year); +} -$px->draw(DOL_DOCUMENT_ROOT.$filev, $data, $year); - $sql = "SELECT count(*), date_format(datep,'%Y') as dm, sum(price) FROM ".MAIN_DB_PREFIX."propal WHERE fk_statut > 0 GROUP BY dm DESC "; if ($db->query($sql)) { @@ -51,7 +55,9 @@ if ($db->query($sql)) print ''; print ''; print ''; $i = 0; while ($i < $num) diff --git a/htdocs/comm/propal/stats/month.php b/htdocs/comm/propal/stats/month.php index eb7b14f54b8..693416e5515 100644 --- a/htdocs/comm/propal/stats/month.php +++ b/htdocs/comm/propal/stats/month.php @@ -1,5 +1,6 @@ + * Copyright (C) 2004 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 @@ -24,36 +25,36 @@ require("./pre.inc.php"); require("./propalestats.class.php"); llxHeader(); -$year = $_GET["year"]; -$mesg = ''; -print_fiche_titre('Statistiques des propositions commerciales '.$year, $mesg); +$year = isset($_GET["year"])?$_GET["year"]:date("Y",time()); -print ''.($year - 1).' - '; -print ''.($year + 1).''; +$mesg = ''.img_previous().' '; +$mesg.= "Année $year"; +$mesg.= ' '.img_next().''; /* * * */ -$stats = new PropaleStats($db); + +print_fiche_titre('Statistiques des propositions commerciales', $mesg); $dir = DOL_DOCUMENT_ROOT; -//////////////////////// - +$stats = new PropaleStats($db); $data = $stats->getNbByMonth($year); $filev = "/document/images/propale$year.png"; $px = new BarGraph($data); -$px->SetMaxValue($px->GetMaxValue()); -$px->SetWidth(500); -$px->SetHeight(280); - -$px->draw($dir.$filev, $data, $year); - -///// +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetMaxValue($px->GetMaxValue()); + $px->SetWidth(500); + $px->SetHeight(280); + + $px->draw($dir.$filev, $data, $year); +} $res = $stats->getAmountByMonth($year); @@ -67,13 +68,15 @@ for ($i = 1 ; $i < 13 ; $i++) $file_amount = "/document/images/propalamount$year.png"; $px = new BarGraph($data); -$px->SetYLabel("Montant"); -$px->SetMaxValue($px->GetAmountMaxValue()); -$px->SetWidth(500); -$px->SetHeight(250); - -$px->draw($dir.$file_amount, $data, $year); - +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetYLabel("Montant"); + $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetWidth(500); + $px->SetHeight(250); + + $px->draw($dir.$file_amount, $data, $year); +} $res = $stats->getAverageByMonth($year); $data = array(); @@ -83,26 +86,32 @@ for ($i = 1 ; $i < 13 ; $i++) $data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); } $file_avg = "/document/images/propalaverage$year.png"; -$px = new BarGraph($data); -$px->SetYLabel("Montant moyen"); -$px->SetMaxValue($px->GetAmountMaxValue()); -$px->SetWidth(500); -$px->SetHeight(250); -$px->draw($dir.$file_avg, $data, $year); +$px = new BarGraph($data); +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetYLabel("Montant moyen"); + $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetWidth(500); + $px->SetHeight(250); + $px->draw($dir.$file_avg, $data, $year); +} print '
AnnéeNb de propositionSomme des propositions'; - print 'Nombre de proposition par mois
Graphique nombre de commande'; + print 'Nombre de proposition par mois
'; + if ($mesg) { print "$mesg"; } + else { print 'Graphique nombre de commande'; } print '
'; print ''; print ''; print ''; print ''; print ''; print '
Nombre par mois'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
Sommes'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
Montant moyen'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
'; $db->close(); diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php index 41076245c28..fea36414e66 100644 --- a/htdocs/commande/stats/index.php +++ b/htdocs/commande/stats/index.php @@ -1,5 +1,6 @@ + * Copyright (c) 2004 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 @@ -46,19 +47,23 @@ $data = $stats->getNbCommandeByMonthWithPrevYear($year); $filev = "/document/images/nbcommande2year.png"; $px = new BarGraph($data); -$px->SetMaxValue($px->GetMaxValue()); -$px->SetWidth(450); -$px->SetHeight(280); -$px->SetYLabel("Nombre de commande"); -$px->draw(DOL_DOCUMENT_ROOT.$filev, $data, $year); - +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetMaxValue($px->GetMaxValue()); + $px->SetWidth(450); + $px->SetHeight(280); + $px->SetYLabel("Nombre de commande"); + $px->draw(DOL_DOCUMENT_ROOT.$filev, $data, $year); +} $rows = $stats->getNbByYear(); $num = sizeof($rows); print ''; print ''; print ''; $i = 0; while (list($key, $value) = each ($rows)) diff --git a/htdocs/commande/stats/month.php b/htdocs/commande/stats/month.php index 52fecd3d451..aa11d206565 100644 --- a/htdocs/commande/stats/month.php +++ b/htdocs/commande/stats/month.php @@ -1,5 +1,6 @@ + * Copyright (c) 2004 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 @@ -34,36 +35,35 @@ if ($user->societe_id > 0) llxHeader(); -$mesg = ''; +$year = isset($_GET["year"])?$_GET["year"]:date("Y",time()); + +$mesg = ''.img_previous().' '; +$mesg.= "Année $year"; +$mesg.= ' '.img_next().''; /* * * */ -$stats = new CommandeStats($db, $socidp); - -$year = $_GET["year"]; - -print_fiche_titre('Statistiques commandes '.$year, $mesg); +print_fiche_titre('Statistiques commandes', $mesg); $dir = DOL_DOCUMENT_ROOT; -//////////////////////// - +$stats = new CommandeStats($db, $socidp); $data = $stats->getNbCommandeByMonth($year); - $filev = "/document/images/commande$year.png"; $px = new BarGraph($data); -$px->SetMaxValue($px->GetMaxValue()); -$px->SetWidth(500); -$px->SetHeight(280); -$px->SetYLabel("Nombre de commande"); -$px->draw($dir.$filev, $data, $year); - -///// +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetMaxValue($px->GetMaxValue()); + $px->SetWidth(500); + $px->SetHeight(280); + $px->SetYLabel("Nombre de commande"); + $px->draw($dir.$filev, $data, $year); +} $res = $stats->getCommandeAmountByMonth($year); @@ -77,12 +77,14 @@ for ($i = 1 ; $i < 13 ; $i++) $file_amount = "/document/images/commandeamount.png"; $px = new BarGraph($data); -$px->SetMaxValue($px->GetAmountMaxValue()); -$px->SetWidth(500); -$px->SetHeight(250); -$px->SetYLabel("Montant des commande"); -$px->draw($dir.$file_amount, $data, $year); - +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetWidth(500); + $px->SetHeight(250); + $px->SetYLabel("Montant des commande"); + $px->draw($dir.$file_amount, $data, $year); +} $res = $stats->getCommandeAverageByMonth($year); $data = array(); @@ -93,25 +95,30 @@ for ($i = 1 ; $i < 13 ; $i++) } $file_avg = "/document/images/commandeaverage.png"; $px = new BarGraph($data); -$px->SetMaxValue($px->GetAmountMaxValue()); -$px->SetWidth(500); -$px->SetHeight(250); -$px->SetYLabel("Montant moyen des commande"); -$px->draw($dir.$file_avg, $data, $year); - +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetWidth(500); + $px->SetHeight(250); + $px->SetYLabel("Montant moyen des commande"); + $px->draw($dir.$file_avg, $data, $year); +} print '
AnnéeNb de commandeSomme des commandes'; -print 'Nombre de commande par mois
Graphique nombre de commande'; +print 'Nombre de commande par mois
'; +if ($mesg) { print $mesg; } +else { print 'Graphique nombre de commande'; } print '
'; print ''; print ''; print ''; print ''; print ''; print '
Nombre de commande par mois'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
Sommes des commandes'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
Montant moyen des commande'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
'; $db->close(); diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index 3295c84be69..5f9c0d56165 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -1,5 +1,6 @@ + * Copyright (c) 2004 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 @@ -43,12 +44,14 @@ $data = $stats->getNbByMonthWithPrevYear($year); $filev = "/document/images/nbfacture2year-$year.png"; $px = new BarGraph($data); -$px->SetMaxValue($px->GetMaxValue()); -$px->SetLegend(array($year - 1, $year)); -$px->SetWidth(450); -$px->SetHeight(280); - -$px->draw(DOL_DOCUMENT_ROOT.$filev, $data, $year); +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetMaxValue($px->GetMaxValue()); + $px->SetLegend(array($year - 1, $year)); + $px->SetWidth(450); + $px->SetHeight(280); + $px->draw(DOL_DOCUMENT_ROOT.$filev, $data, $year); +} $sql = "SELECT count(*), date_format(datef,'%Y') as dm, sum(total) FROM ".MAIN_DB_PREFIX."facture WHERE fk_statut > 0 "; if ($socidp) @@ -63,7 +66,9 @@ if ($db->query($sql)) print ''; print ''; print ''; $i = 0; while ($i < $num) diff --git a/htdocs/compta/facture/stats/month.php b/htdocs/compta/facture/stats/month.php index 1d4090d35e4..9ae46ac4a75 100644 --- a/htdocs/compta/facture/stats/month.php +++ b/htdocs/compta/facture/stats/month.php @@ -1,5 +1,6 @@ + * Copyright (c) 2004 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 @@ -21,6 +22,7 @@ */ require("./pre.inc.php"); + /* * Sécurité accés client */ @@ -31,36 +33,36 @@ if ($user->societe_id > 0) } llxHeader(); -$year = $_GET["year"]; -$mesg = ''; -print_fiche_titre('Statistiques des factures '.$year, $mesg); +$year = isset($_GET["year"])?$_GET["year"]:date("Y",time()); -print ''.($year-1).' - '; -print ''.($year + 1).''; +$mesg = ''.img_previous().' '; +$mesg.= "Année $year"; +$mesg.= ' '.img_next().''; /* * * */ -$stats = new FactureStats($db, $socidp); + +print_fiche_titre('Statistiques des factures '.$year, $mesg); + $dir = DOL_DOCUMENT_ROOT; -//////////////////////// - +$stats = new FactureStats($db, $socidp); $data = $stats->getNbByMonth($year); $filev = "/document/images/facture$year.png"; $px = new BarGraph($data); -$px->SetMaxValue($px->GetMaxValue()); -$px->SetWidth(500); -$px->SetHeight(280); - -$px->draw($dir.$filev, $data, $year); - -///// +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetMaxValue($px->GetMaxValue()); + $px->SetWidth(500); + $px->SetHeight(280); + $px->draw($dir.$filev, $data, $year); +} $res = $stats->getAmountByMonth($year); @@ -74,13 +76,14 @@ for ($i = 1 ; $i < 13 ; $i++) $file_amount = "/document/images/factureamount$year.png"; $px = new BarGraph($data); -$px->SetYLabel("Montant"); -$px->SetMaxValue($px->GetAmountMaxValue()); -$px->SetWidth(500); -$px->SetHeight(250); - -$px->draw($dir.$file_amount, $data, $year); - +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetYLabel("Montant"); + $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetWidth(500); + $px->SetHeight(250); + $px->draw($dir.$file_amount, $data, $year); +} $res = $stats->getAverageByMonth($year); $data = array(); @@ -91,25 +94,30 @@ for ($i = 1 ; $i < 13 ; $i++) } $file_avg = "/document/images/factureaverage$year.png"; $px = new BarGraph($data); -$px->SetYLabel("Montant moyen"); -$px->SetMaxValue($px->GetAmountMaxValue()); -$px->SetWidth(500); -$px->SetHeight(250); -$px->draw($dir.$file_avg, $data, $year); - +$mesg = $px->isGraphKo(); +if (! $mesg) { + $px->SetYLabel("Montant moyen"); + $px->SetMaxValue($px->GetAmountMaxValue()); + $px->SetWidth(500); + $px->SetHeight(250); + $px->draw($dir.$file_avg, $data, $year); +} print '
AnnéeNb de factureSomme des factures'; - print 'Nombre de facture par mois
Graphique nombre de commande'; + print 'Nombre de facture par mois
'; + if ($mesg) { print $mesg; } + else { print 'Graphique nombre de commande'; } print '
'; print ''; print ''; print ''; print ''; print ''; print '
Nombre par mois'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
Sommes'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
Montant moyen'; -print ''; +if ($mesg) { print $mesg; } +else { print ''; } print '
'; $db->close(); diff --git a/htdocs/product/stats/fiche.php b/htdocs/product/stats/fiche.php index a1fc71f39ea..5d1e537fa0f 100644 --- a/htdocs/product/stats/fiche.php +++ b/htdocs/product/stats/fiche.php @@ -1,5 +1,6 @@ + * Copyright (c) 2004 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 @@ -49,20 +50,23 @@ if ($id) } } - $filev = $dir . "/vente12mois.png"; - $filenv = $dir . "/vendu12mois.png"; - - if (! file_exists($filev) or $action == 'recalcul') - { - $px = new BarGraph(); - $graph_data = $product->get_num_vente(); - $px->draw($filev, $graph_data); - $px = new BarGraph(); - $graph_data = $product->get_nb_vente(); - $px->draw($filenv, $graph_data); - $mesg = "Graphiques générés"; - } - + $filenbvente = $dir . "/vente12mois.png"; + $filenbpiece = $dir . "/vendu12mois.png"; + + if (! file_exists($filenbvente) or $action == 'recalcul') + { + $px = new BarGraph(); + $mesg = $px->isGraphKo(); + if (! $mesg) { + $graph_data = $product->get_num_vente(); + $px->draw($filenbvente, $graph_data); + $px = new BarGraph(); + $graph_data = $product->get_nb_vente(); + $px->draw($filenbpiece, $graph_data); + $mesg = "Graphiques générés"; + } + } + print_fiche_titre('Fiche produit : '.$product->ref, $mesg); print ''; @@ -88,9 +92,17 @@ if ($id) print 'Ventes sur les 12 derniers mois'; print ''; - print ''; + if (file_exists($filenbvente) && filemtime($filenbvente)) { + print ''; + } else { + print ''; + } print ''; - print ''; + if (file_exists($filenbpiece) && filemtime($filenbpiece)) { + print ''; + } else { + print ''; + } print ''; print '
Généré le '.strftime("%d %b %Y %H:%M:%S",filemtime($filev)).'Généré le '.dolibarr_print_date(filemtime($filenbvente),"%d %b %Y %H:%M:%S").'Graphique non généré[Re-calculer]Généré le '.strftime("%d %b %Y %H:%M:%S",filemtime($filev)).'Généré le '.dolibarr_print_date(filemtime($filenbpiece),"%d %b %Y %H:%M:%S").'Graphique non généré[Re-calculer]
';