[ 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.week.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.week.class.php,v 1.4 2005/05/04 13:07:06 rodolphe Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/stats/clients/clients.week.class.php,v $
  20   *
  21   */
  22  
  23  require_once DOL_DOCUMENT_ROOT."/telephonie/stats/graph/barmoy.class.php";
  24  require_once DOL_DOCUMENT_ROOT.'/telephonie/distributeurtel.class.php';
  25  
  26  class GraphClientsWeek extends GraphBarMoy {
  27  
  28    Function GraphClientsWeek($DB, $file)
  29    {
  30      $this->db = $DB;
  31      $this->file = $file;
  32  
  33      $this->client = 0;
  34      $this->titre = "Nouveaux clients par semaine";
  35  
  36      $this->barcolor = "yellow";
  37      $this->showframe = true;
  38  
  39      $this->commercial = 0;
  40      $this->distributeur = 0;
  41    }
  42  
  43    Function GraphMakeGraph($commercial=0)
  44    {
  45      $num = 0;
  46  
  47      $sql = "SELECT l.fk_client_comm, date_format(l.date_commande,'%x%v')";
  48      $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
  49  
  50      if ($this->commercial > 0)
  51        {
  52      $sql .= " WHERE l.date_commande IS NOT NULL ";
  53      $sql .= " AND l.fk_commercial_sign = ".$this->commercial;
  54        }
  55  
  56  
  57      if ($this->distributeur > 0)
  58        {
  59      $distri = new DistributeurTelephonie($this->db);
  60      $distri->fetch($this->distributeur);
  61  
  62      $this->titre = $distri->nom . " Nouveaux clients par semaine";
  63  
  64      $sql .= " , ".MAIN_DB_PREFIX."telephonie_distributeur_commerciaux as dc";
  65  
  66      $sql .= " WHERE l.date_commande IS NOT NULL ";
  67      $sql .= " AND l.fk_commercial_sign = dc.fk_user";
  68      $sql .= " AND dc.fk_distributeur = ".$this->distributeur;
  69        }
  70  
  71  
  72      $sql .= " ORDER BY date_format(l.date_commande,'%x%v') ASC";
  73  
  74      $result = $this->db->query($sql);
  75  
  76      if ($result)
  77        {
  78      $num = $this->db->num_rows();
  79      
  80      $i = 0;
  81      $j = 0;
  82      $datas = array();
  83      $labels = array();
  84      $oldweek = 0;
  85      $clients = array();
  86          
  87      while ($i < $num)
  88        {
  89          $row = $this->db->fetch_row();
  90  
  91          if ($oldweek == 0) 
  92            {
  93          $oldweek = $row[1];
  94          array_push($clients, $row[0]);
  95  
  96          $datas[$j] = 1;
  97          $labels[$j] = $row[1];
  98            }        
  99          else
 100            {
 101  
 102          if ($row[1] == $labels[$j])
 103            {
 104              if (! in_array($row[0], $clients))
 105              {
 106                array_push($clients, $row[0]);
 107                $datas[$j]++;
 108              }
 109            }
 110          else
 111            {
 112              $j++;
 113              if (! in_array($row[0], $clients))
 114                {
 115              array_push($clients, $row[0]);
 116              $datas[$j] = 1;
 117                }
 118              else
 119                {
 120              $datas[$j] = 0;
 121                }
 122  
 123              $labels[$j] = $row[1];
 124            }
 125  
 126            }
 127  
 128          $i++;
 129        }
 130      
 131      $this->db->free();
 132        }
 133      else 
 134        {
 135      print $this->db->error() . ' ' . $sql;
 136        }                  
 137  
 138      $datas_new = array();
 139      $labels_new = array();
 140      $j = 0 ;
 141  
 142      $datas_new[0] = $datas[0];
 143      $labels_new[0] = ceil(substr($labels[0],-2));
 144  
 145      for ($i = 1 ; $i < sizeof($labels) ; $i++)
 146        {
 147      if (substr($labels[$i], -2) - substr($labels[$i-1], -2) > 1)
 148        {
 149          for ($k = 1 ; $k < ($labels[$i] - $labels[$i-1]) ; $k++)
 150            {
 151          $datas_new[$i+$j] = 0;
 152          $labels_new[$i+$j] = ceil(substr($labels[$i-1], -2) + $k) ; // suppression du 0
 153  
 154          $j++;
 155            }
 156        }
 157  
 158      $datas_new[$i+$j] = $datas[$i];
 159      $labels_new[$i+$j] = ceil(substr($labels[$i], - 2));
 160        }
 161  
 162      $nbel = sizeof($datas_new);
 163  
 164      $moys = array();
 165      $moys[0] = $datas_new[0];
 166      $sum = $moys[0];
 167  
 168      for ($i = 1 ; $i < $nbel ; $i++)
 169        {
 170      $sum = $sum + $datas_new[$i];
 171  
 172      $moys[$i] = ($sum / ($i+1));
 173        }
 174  
 175      for ($i = 0 ; $i < ($nbel - 18) ; $i++)
 176        {
 177      array_shift($datas_new);
 178      array_shift($labels_new);
 179      array_shift($moys);
 180        }
 181  
 182      $this->GraphDraw($this->file, $datas_new, $labels_new, $moys);
 183    }
 184  }   
 185  ?>


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