[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/telephonie/stats/clients/ -> clients.month.class.php (source)

   1  <?PHP
   2  /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   *
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: clients.month.class.php,v 1.1 2005/02/28 10:53:57 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/stats/clients/clients.month.class.php,v $
  20   *
  21   */
  22  
  23  require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/barmoy.class.php");
  24  
  25  class GraphClientsMonth extends GraphBarMoy {
  26  
  27    Function GraphClientsMonth($DB, $file)
  28    {
  29      $this->db = $DB;
  30      $this->file = $file;
  31  
  32      $this->client = 0;
  33      $this->titre = "Nouveaux clients par mois";
  34  
  35      $this->barcolor = "blue";
  36      $this->showframe = true;
  37    }
  38  
  39    Function GraphMakeGraph($commercial=0)
  40    {
  41      $num = 0;
  42  
  43      $sql = "SELECT fk_client_comm, date_format(date_commande,'%Y%m')";
  44      $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne";
  45      $sql .= " WHERE date_commande IS NOT NULL ";
  46  
  47      if ($commercial > 0)
  48        {
  49      $sql .= " AND fk_commercial = ".$commercial;
  50        }
  51  
  52      $sql .= " ORDER BY date_format(date_commande,'%Y%m') ASC";
  53  
  54      $result = $this->db->query($sql);
  55  
  56      if ($result)
  57        {
  58      $num = $this->db->num_rows();
  59      
  60      $i = 0;
  61      $j = 0;
  62      $datas = array();
  63      $labels = array();
  64      $oldweek = 0;
  65      $clients = array();
  66          
  67      while ($i < $num)
  68        {
  69          $row = $this->db->fetch_row();
  70  
  71          if ($oldweek == 0) 
  72            {
  73          $oldweek = $row[1];
  74          array_push($clients, $row[0]);
  75  
  76          $datas[$j] = 1;
  77          $labels[$j] = $row[1];
  78            }        
  79          else
  80            {
  81  
  82          if ($row[1] == $labels[$j])
  83            {
  84              if (! in_array($row[0], $clients))
  85              {
  86                array_push($clients, $row[0]);
  87                $datas[$j]++;
  88              }
  89            }
  90          else
  91            {
  92              $j++;
  93              if (! in_array($row[0], $clients))
  94                {
  95              array_push($clients, $row[0]);
  96              $datas[$j] = 1;
  97                }
  98              else
  99                {
 100              $datas[$j] = 0;
 101                }
 102  
 103              $labels[$j] = $row[1];
 104            }
 105  
 106            }
 107  
 108          $i++;
 109        }
 110      
 111      $this->db->free();
 112        }
 113      else 
 114        {
 115      print $this->db->error() . ' ' . $sql;
 116        }                  
 117  
 118      $datas_new = array();
 119      $labels_new = array();
 120      $j = 0 ;
 121  
 122      $datas_new[0] = $datas[0];
 123      $labels_new[0] = ceil(substr($labels[0],-2));
 124  
 125      for ($i = 1 ; $i < sizeof($labels) ; $i++)
 126        {
 127      if (substr($labels[$i], -2) - substr($labels[$i-1], -2) > 1)
 128        {
 129          for ($k = 1 ; $k < ($labels[$i] - $labels[$i-1]) ; $k++)
 130            {
 131          $datas_new[$i+$j] = 0;
 132          $labels_new[$i+$j] = ceil(substr($labels[$i-1], -2) + $k) ; // suppression du 0
 133  
 134          $j++;
 135            }
 136        }
 137  
 138      $datas_new[$i+$j] = $datas[$i];
 139      $labels_new[$i+$j] = ceil(substr($labels[$i], - 2));
 140        }
 141  
 142      $nbel = sizeof($datas_new);
 143  
 144      $moys = array();
 145      $moys[0] = $datas_new[0];
 146      $sum = $moys[0];
 147  
 148      for ($i = 1 ; $i < $nbel ; $i++)
 149        {
 150      $sum = $sum + $datas_new[$i];
 151  
 152      $moys[$i] = ($sum / ($i+1));
 153        }
 154  
 155      for ($i = 0 ; $i < ($nbel - 9) ; $i++)
 156        {
 157      array_shift($datas_new);
 158      array_shift($labels_new);
 159      array_shift($moys);
 160        }
 161  
 162      $this->GraphDraw($this->file, $datas_new, $labels_new, $moys);
 163    }
 164  }   
 165  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics