From c0d339b744649c1e4cc5fd7de9569e9878ce7e51 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Fri, 19 Mar 2004 18:05:27 +0000 Subject: [PATCH] Nouveau fichier --- htdocs/rapport/AtomeFactureValidee.class.php | 95 +++++++++++++++++ htdocs/rapport/index.php | 101 +++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 htdocs/rapport/AtomeFactureValidee.class.php create mode 100644 htdocs/rapport/index.php diff --git a/htdocs/rapport/AtomeFactureValidee.class.php b/htdocs/rapport/AtomeFactureValidee.class.php new file mode 100644 index 00000000000..50865e9b4fe --- /dev/null +++ b/htdocs/rapport/AtomeFactureValidee.class.php @@ -0,0 +1,95 @@ + + * + * 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$ + * + */ + +include_once(DOL_DOCUMENT_ROOT.'/rapport/Atome.class.php'); + +class AtomeFactureValidee extends Atome +{ + var $id; + var $db; + var $periode; + + /** + * Initialisation de la classe + * + */ + Function AtomeFactureValidee($DB, $periode, $daystart) + { + $this->db = $DB ; + $this->name = 'AtomeFactureValidee'; + $this->AtomeInitialize($periode,'AtomeFactureValidee', $daystart); + $this->datas = array(); + } + + /** + * + * + * + */ + Function fetch() + { + if ($this->periode == 'year') + { + $sql = "SELECT date_format(f.datef,'%Y%m'), sum(f.amount) as am"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.fk_statut = 1"; + + $sql .= " AND date_format(f.datef,'%Y') = $this->year "; + $sql .= " GROUP BY date_format(f.datef,'%Y%m') ASC ;"; + } + + if ($this->periode == 'month') + { + $sql = "SELECT date_format(f.datef,'%Y%m%d'), sum(f.amount) as am"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.fk_statut = 1"; + $sql .= " AND date_format(f.datef,'%Y%m') = ".$this->year.$this->month; + $sql .= " GROUP BY date_format(f.datef,'%Y%m%d') ASC ;"; + } + + if ($this->db->query($sql) ) + { + $i = 0; + $num = $this->db->num_rows(); + $arr = array(); + while ($i < $num) + { + $row = $this->db->fetch_row($i); + + $arr[$row[0]] = $row[1]; + //print $row[0] .'-'.$row[1]. '
'; + $i++; + } + + $this->db->free(); + $this->datas = $arr; + return $arr; + } + else + { + print $this->db->error(); + print "
$sql"; + return -3; + } + } +} +?> diff --git a/htdocs/rapport/index.php b/htdocs/rapport/index.php new file mode 100644 index 00000000000..b9dc78f108a --- /dev/null +++ b/htdocs/rapport/index.php @@ -0,0 +1,101 @@ + + * + * 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("./pre.inc.php"); + +require("./AtomeFactureValidee.class.php"); +require("./AtomePropaleValidee.class.php"); + +llxHeader(); + +print_fiche_titre("Rapports"); + + + +/* + * Initialisation d'un atome + * + * Parametre + * - id de connexion à la bdd + * - période 'year' ou 'month' (Reste à faire les hebdo) + * - une date dans la période voulue + * -> retourne un objet + * + */ +$x = new AtomeFactureValidee($db,'year', time()); + +/* + * Lecture des données + * -> retourne un tableau + */ +$arr = $x->fetch(); +/* + * Création du graph + * -> retounre le nom du fichier + */ +$img = $x->BarGraph(); +print $img."
"; + + +// + +$x = new AtomeFactureValidee($db,'year', mktime(12,0,0,1,12,2003)); +$arr = $x->fetch('year'); + +$img = $x->BarGraph(); +print $img."
"; +for ($i = 1 ; $i < 5; $i++) +{ + $x = new AtomeFactureValidee($db,'month', mktime(12,0,0,$i,12,2003)); + $x->periode = 'month'; + + $arr = $x->fetch('month'); + + + $img = $x->BarGraph(); + print $img."
"; +} + +// + +$x = new AtomePropaleValidee($db,'year',mktime(12,0,0,1,12,2003)); + +$arr = $x->fetch(); + +var_dump($arr); + +$img = $x->BarGraph(); +print $img."
"; + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?> + + + + + + + + + +