/[dolibarr]/dolibarr/htdocs/telephonie/script/graph-statistiques-ca.php
ViewVC logotype

Diff of /dolibarr/htdocs/telephonie/script/graph-statistiques-ca.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by rodolphe, Mon Nov 14 07:40:51 2005 UTC revision 1.16 by rodolphe, Tue Dec 6 10:13:43 2005 UTC
# Line 23  Line 23 
23   */   */
24  require ("../../master.inc.php");  require ("../../master.inc.php");
25    
26    $verbose = 0;
27    for ($i = 1 ; $i < sizeof($argv) ; $i++)
28    {
29      if ($argv[$i] == "-v")
30        {
31          $verbose = 1;
32        }
33      if ($argv[$i] == "-vv")
34        {
35          $verbose = 2;
36        }
37      if ($argv[$i] == "-vvv")
38        {
39          $verbose = 3;
40        }
41    }
42    
43  require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php");  require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php");
44  require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php");  require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php");
45  require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie-tarif.class.php");  require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie-tarif.class.php");
# Line 44  $error = 0; Line 61  $error = 0;
61    
62  $datetime = time();  $datetime = time();
63  $date = strftime("%d%h%Y%Hh%Mm%S",$datetime);  $date = strftime("%d%h%Y%Hh%Mm%S",$datetime);
 $month = strftime("%m", $datetime);  
64  $year = strftime("%Y", $datetime);  $year = strftime("%Y", $datetime);
65    
66  if ($month == 1)  $img_root = DOL_DATA_ROOT."/graph/telephonie";
 {  
   $month = "12";  
   $year = $year - 1;  
 }  
 else  
 {  
   $month = substr("00".($month - 1), -2) ;  
 }  
   
67    
68  $img_root = DOL_DATA_ROOT."/graph/telephonie/";  $month = array();
69    $month[1] = 'J';
70    $month[2] = 'F';
71    $month[3] = 'M';
72    $month[4] = 'A';
73    $month[5] = 'M';
74    $month[6] = 'J';
75    $month[7] = 'J';
76    $month[8] = 'A';
77    $month[9] = 'S';
78    $month[10] = 'O';
79    $month[11] = 'N';
80    $month[12] = 'D';
81    
82  /**********************************************************************/  /**********************************************************************/
83  /*  /*
# Line 69  $img_root = DOL_DATA_ROOT."/graph/teleph Line 88  $img_root = DOL_DATA_ROOT."/graph/teleph
88    
89  $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_stats";  $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_stats";
90  $sql .= " WHERE graph IN ('factures.facture_moyenne','factures.ca_mensuel','factures.nb_mensuel')";  $sql .= " WHERE graph IN ('factures.facture_moyenne','factures.ca_mensuel','factures.nb_mensuel')";
91    $sql .= " AND legend like '".$this->year."%';";
92  $resql = $db->query($sql);  $resql = $db->query($sql);
93    
94    $sql = "SELECT date_format(tf.date,'%Y%m'), sum(tf.cout_vente)";
95  $sql = "SELECT date_format(tf.date,'%Y%m'), sum(tf.cout_vente), sum(tf.cout_achat), sum(tf.gain), count(tf.cout_vente)";  $sql .= ", sum(tf.cout_achat), sum(tf.gain), count(tf.cout_vente)";
   
96  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as tf";  $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as tf";
97  $sql .= " GROUP BY date_format(tf.date,'%Y%m') ASC ";  $sql .= " WHERE date_format(tf.date,'%Y') ='".$year."'";
98    $sql .= " GROUP BY date_format(tf.date,'%Y%m') ASC ;";
99    
100  $resql = $db->query($sql);  $resql = $db->query($sql);
101    
102  if ($resql)  if ($resql)
103  {  {
104    $cout_vente_type = array();    $cout_vente = array_pad(array(),12,0);
   $cout_vente = array();  
105    $cout_vente_prev = array();    $cout_vente_prev = array();
106    $cout_vente_autr = array();    $cout_vente_autr = array();
107    $cout_vente_moyen = array();    $cout_vente_moyen = array();
108    $nb_factures = array();    $nb_factures = array_pad(array(),12,0);
109    $jour_semaine_nb = array();    $jour_semaine_nb = array();
110    $jour_semaine_duree = array();    $jour_semaine_duree = array();
111    $gain = array();    $gain = array_pad(array(),12,0);
112    $gain_moyen = array();    $gain_moyen = array_pad(array(),12,0);
113      $labels = array_pad(array(),12,0);
114      $short_labels = array_pad(array(),12,0);
115    
116    $num = $db->num_rows($resql);    $num = $db->num_rows($resql);
117    $i = 0;    $i = 0;
# Line 115  if ($resql) Line 136  if ($resql)
136        $cout_vente_moyen[$i] = ($row[1]/$row[4]);        $cout_vente_moyen[$i] = ($row[1]/$row[4]);
137        $nb_factures[$i] = $row[4];        $nb_factures[$i] = $row[4];
138        $labels[$i] = $row[0];        $labels[$i] = $row[0];
139        $short_labels[$i] = substr($row[0],-2);        $short_labels[$i] = $month[(substr($row[0],-2)*1)];
140    
141        $sqli = " INSERT INTO ".MAIN_DB_PREFIX."telephonie_stats";        $sqli = " INSERT INTO ".MAIN_DB_PREFIX."telephonie_stats";
142        $sqli .= " (graph, ord, legend, valeur) VALUES (";        $sqli .= " (graph, ord, legend, valeur) VALUES (";
# Line 154  $graph->barcolor = "blue"; Line 175  $graph->barcolor = "blue";
175  $graph->width = 440;  $graph->width = 440;
176  $graph->GraphDraw($file, $cout_vente_moyen, $short_labels);  $graph->GraphDraw($file, $cout_vente_moyen, $short_labels);
177    
178  $file = $img_root . "/factures/gain_mensuel.png";  $file = $img_root . "/factures/gain_mensuel.$year.png";
179  if ($verbose) print "Graph $file\n";  if ($verbose) print "Graph $file\n";
180  $graph = new GraphBar ($db, $file);  $graph = new GraphBar ($db, $file);
181  $graph->titre = "Gain par mois en euros HT";  $graph->titre = "Marge en euros HT $year";
182  $graph->width = 440;  $graph->width = 440;
183  $graph->GraphDraw($file, $gain, $short_labels);  $graph->GraphDraw($file, $gain, $short_labels);
184    
185  $file = $img_root . "/factures/gain_moyen.png";  $file = $img_root . "/factures/gain_moyen.$year.png";
186  if ($verbose) print "Graph $file\n";  if ($verbose) print "Graph $file\n";
187  $graph = new GraphBar ($db, $file);  $graph = new GraphBar ($db, $file);
188  $graph->titre = "Gain moyen par facture par mois";  $graph->titre = "Marge moyenne par facture $year";
189  $graph->width = 440;  $graph->width = 440;
190  $graph->barcolor = "blue";  $graph->barcolor = "blue";
191  $graph->GraphDraw($file, $gain_moyen, $short_labels);  $graph->GraphDraw($file, $gain_moyen, $short_labels);
192    
193  $file = $img_root . "/factures/nb_facture.png";  $file = $img_root . "/factures/nb_facture.$year.png";
194  if ($verbose) print "Graph $file\n";  if ($verbose) print "Graph $file\n";
195  $graph = new GraphBar ($db, $file);  $graph = new GraphBar ($db, $file);
196  $graph->titre = "Nb de facture mois";  $graph->titre = "Nb de facture mois $year";
197  $graph->width = 440;  $graph->width = 440;
198  $graph->barcolor = "yellow";  $graph->barcolor = "yellow";
199  $graph->GraphDraw($file, $nb_factures, $short_labels);  $graph->GraphDraw($file, $nb_factures, $short_labels);

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26