[ Index ] |
|
Code source de Dolibarr 2.0.1 |
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: graph-statistiques.php,v 1.8 2005/06/15 14:21:39 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/graph-statistiques.php,v $ 20 * 21 * 22 * Generation des graphiques 23 * 24 * 25 * 26 */ 27 require ("../../master.inc.php"); 28 29 $verbose = 0; 30 31 for ($i = 1 ; $i < sizeof($argv) ; $i++) 32 { 33 if ($argv[$i] == "-v") 34 { 35 $verbose = 1; 36 } 37 if ($argv[$i] == "--verbose") 38 { 39 $verbose = 1; 40 } 41 } 42 43 require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"); 44 require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php"); 45 46 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/bar.class.php"); 47 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/camenbert.class.php"); 48 49 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/ca.class.php"); 50 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/camoyen.class.php"); 51 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/gain.class.php"); 52 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/heureappel.class.php"); 53 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/joursemaine.class.php"); 54 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/appelsdureemoyenne.class.php"); 55 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/comm.nbmensuel.class.php"); 56 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/lignes/actives.class.php"); 57 58 $error = 0; 59 60 $datetime = time(); 61 62 $date = strftime("%d%h%Y%Hh%Mm%S",$datetime); 63 64 $month = strftime("%m", $datetime); 65 $year = strftime("%Y", $datetime); 66 67 if ($month == 1) 68 { 69 $month = "12"; 70 $year = $year - 1; 71 } 72 else 73 { 74 $month = substr("00".($month - 1), -2) ; 75 } 76 77 78 $img_root = DOL_DATA_ROOT."/graph/telephonie/"; 79 80 81 /***********************************************************************/ 82 /* 83 /* Lignes actives 84 /* 85 /***********************************************************************/ 86 87 $file = $img_root . "lignes/lignes.actives.png"; 88 if ($verbose) print "Lignes actives ($file)\n"; 89 $graph = new GraphLignesActives($db, $file); 90 $graph->GraphMakeGraph(); 91 92 /***********************************************************************/ 93 /* 94 /* Chiffre d'affaire mensuel 95 /* 96 /***********************************************************************/ 97 98 $file = $img_root . "ca/ca.mensuel.png"; 99 if ($verbose) print "Chiffre d'affaire mensuel ($file)\n"; 100 $graphca = new GraphCa($db, $file); 101 $graphca->GraphDraw(); 102 103 /************************************************************************/ 104 /* 105 /* Chiffre d'affaire moyen 106 /* 107 /* 108 /************************************************************************/ 109 110 $file = $img_root . "ca/gain_moyen_par_client.png"; 111 if ($verbose) print "Graph ca moyen\n"; 112 $graphgain = new GraphCaMoyen ($db, $file); 113 $graphgain->show_console = 0 ; 114 $graphgain->GraphDraw(); 115 116 /*************************************************************************/ 117 /* 118 /* Stats sur les communications 119 /* 120 /* 121 /*************************************************************************/ 122 123 $file = $img_root . "communications/heure_appel_nb.png"; 124 if ($verbose) print "Heures d'appels\n"; 125 $graphha = new GraphHeureAppel ($db, $file); 126 $graphha->GraphDraw(); 127 128 $file = $img_root . "communications/joursemaine_nb.png"; 129 if ($verbose) print "Jours de semaines\n"; 130 $graphha = new GraphJourSemaine ($db, $file); 131 $graphha->GraphDraw(); 132 133 repart_comm($db); 134 135 $year = strftime("%Y", $datetime); 136 $month = strftime("%m", $datetime); 137 138 for ($i = 1 ; $i < 4 ; $i++) 139 { 140 $month = $month - 1; 141 142 if ($month == 0) 143 { 144 $year = $year - 1; 145 $month = 12; 146 } 147 148 repart($db,$year, $month); 149 repart_comm($db,$year, $month); 150 151 } 152 153 154 function repart_comm($db, $year = 0, $month = 0) 155 { 156 if ($verbose) print "Répartition des communications\n"; 157 158 $sql = "SELECT duree, numero"; 159 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 160 161 if ($year && $month) 162 { 163 if ($verbose) print "Répartition des communications pour $month/$year\n"; 164 $month = substr("00".$month, -2); 165 $sql .= " WHERE date_format(date,'%Y%m') = '$year$month'"; 166 } 167 168 if ($db->query($sql)) 169 { 170 $labels_duree = array(); 171 $repart_duree = array(0,0,0,0,0,0); 172 $repart_dureelong = array(0,0); 173 174 $labels_dest= array(); 175 $repart_dest = array(0,0,0); 176 $repart_dest_temps = array(0,0,0); 177 178 $num = $db->num_rows(); 179 180 $i = 0; 181 182 while ($i < $num) 183 { 184 $row = $db->fetch_row(); 185 186 if ($row[0] < 10) 187 { 188 $repart_duree[0]++; 189 } 190 elseif ($row[0] >= 10 && $row[0] < 30) 191 { 192 $repart_duree[1]++; 193 } 194 elseif ($row[0] >= 30 && $row[0] < 60) 195 { 196 $repart_duree[2]++; 197 } 198 elseif ($row[0] >= 60 && $row[0] < 120) 199 { 200 $repart_duree[3]++; 201 } 202 elseif ($row[0] >= 120 && $row[0] < 300) 203 { 204 $repart_duree[4]++; 205 } 206 else 207 { 208 $repart_duree[5]++; 209 } 210 211 if ($row[0] < 600) 212 { 213 $repart_dureelong[0]++; 214 } 215 else 216 { 217 $repart_dureelong[1]++; 218 } 219 220 if (substr($row[1],0,2) == '00') 221 { 222 $repart_dest[0]++; 223 $repart_dest_temps[0] += $row[0]; 224 } 225 elseif (substr($row[1],0,2) == '06') 226 { 227 $repart_dest[1]++; 228 $repart_dest_temps[1] += $row[0]; 229 } 230 else 231 { 232 $repart_dest[2]++; 233 $repart_dest_temps[2] += $row[0]; 234 } 235 $i++; 236 } 237 } 238 else 239 { 240 print $sql ; 241 } 242 243 if ($num > 0) 244 { 245 $labels_duree[0] = "< 10 sec"; 246 $labels_duree[1] = "10-30 sec"; 247 $labels_duree[2] = "30-60 sec"; 248 $labels_duree[3] = "60-120 sec"; 249 $labels_duree[4] = "120-300 sec"; 250 $labels_duree[5] = "> 300 sec"; 251 252 $labels_dureelong[0] = "< 600 sec"; 253 $labels_dureelong[1] = "> 600 sec"; 254 255 $labels_dest[0] = 'International'; 256 $labels_dest[1] = 'Mobile'; 257 $labels_dest[2] = 'Local/National'; 258 259 260 $filem = DOL_DATA_ROOT."/graph/telephonie/communications/duree_repart.png"; 261 $filec = DOL_DATA_ROOT."/graph/telephonie/communications/dureelong_repart.png"; 262 $filed = DOL_DATA_ROOT."/graph/telephonie/communications/dest_repart.png"; 263 $filedt = DOL_DATA_ROOT."/graph/telephonie/communications/dest_temps_repart.png"; 264 265 if ($year && $month) 266 { 267 $filem = DOL_DATA_ROOT."/graph/telephonie/communications/duree_repart-$year$month.png"; 268 $filec = DOL_DATA_ROOT."/graph/telephonie/communications/dureelong_repart-$year$month.png"; 269 $filed = DOL_DATA_ROOT."/graph/telephonie/communications/dest_repart-$year$month.png"; 270 $filedt = DOL_DATA_ROOT."/graph/telephonie/communications/dest_temps_repart-$year$month.png"; 271 } 272 273 $graphm = new GraphCamenbert ($db, $filem); 274 $graphc = new GraphCamenbert ($db, $filec); 275 $graphd = new GraphCamenbert ($db, $filed); 276 $graphdt = new GraphCamenbert ($db, $filedt); 277 278 $graphm->titre = "Répartition du nombre de communications par duree"; 279 $graphc->titre = "Répartition du nombre de communications par duree"; 280 $graphd->titre = "Répartition du nombre de communications par destination"; 281 $graphdt->titre = "Répartition du nombre de communications par destination"; 282 283 if ($year && $month) 284 { 285 $graphm->titre = "Répart. du nbre de communications par duree $month/$year"; 286 $graphc->titre = "Répart. du nbre de communications par duree $month/$year"; 287 $graphd->titre = "Répart. du nbre de communications par destination $month/$year"; 288 $graphdt->titre = "Répart. du temps de communications par destination $month/$year"; 289 } 290 291 $graphm->colors= array('#993333','#66cc99','#6633ff','#33ff33','#336699','#00ffff'); 292 $graphd->colors= array('#FFC0FF','#FF00FF','#C000C0'); 293 $graphdt->colors= array('#FFFFC0','#FFFF0F','#C0C000'); 294 295 $graphm->GraphDraw($repart_duree, $labels_duree); 296 $graphc->GraphDraw($repart_dureelong, $labels_dureelong); 297 $graphd->GraphDraw($repart_dest, $labels_dest); 298 $graphdt->GraphDraw($repart_dest_temps, $labels_dest); 299 } 300 } 301 302 303 304 /**********************************************************************/ 305 /* 306 /* Stats sur les factures 307 /* 308 /* 309 /**********************************************************************/ 310 311 $sql = "SELECT date_format(date,'%Y%m'), sum(cout_vente), sum(cout_achat), sum(gain), count(cout_vente)"; 312 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture"; 313 $sql .= " GROUP BY date_format(date,'%Y%m') ASC "; 314 315 if ($db->query($sql)) 316 { 317 $cout_vente = array(); 318 $cout_vente_moyen = array(); 319 $nb_factures = array(); 320 $jour_semaine_nb = array(); 321 $jour_semaine_duree = array(); 322 $gain = array(); 323 $gain_moyen = array(); 324 325 $num = $db->num_rows(); 326 if ($verbose) print "$num lignes de comm a traiter\n"; 327 $i = 0; 328 329 while ($i < $num) 330 { 331 $row = $db->fetch_row(); 332 333 $cout_vente[$i] = $row[1]; 334 335 $gain[$i] = $row[3]; 336 $gain_moyen[$i] = ($row[3]/$row[4]); 337 $cout_vente_moyen[$i] = ($row[1]/$row[4]); 338 $nb_factures[$i] = $row[4]; 339 $labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2); 340 $i++; 341 } 342 } 343 344 345 $file = $img_root . "/factures/facture_moyenne.png"; 346 $graph = new GraphBar ($db, $file, $labels); 347 $graph->titre = "Facture moyenne"; 348 if ($verbose) print $graph->titre."\n"; 349 $graph->barcolor = "blue"; 350 $graph->GraphDraw($file, $cout_vente_moyen, $labels); 351 352 $file = $img_root . "/factures/gain_mensuel.png"; 353 $graph = new GraphBar ($db, $file); 354 $graph->titre = "Gain par mois en euros HT"; 355 if ($verbose) print $graph->titre."\n"; 356 $graph->GraphDraw($file, $gain, $labels); 357 358 $file = $img_root . "/factures/gain_moyen.png"; 359 $graph = new GraphBar ($db, $file); 360 $graph->titre = "Gain moyen par facture par mois"; 361 if ($verbose) print $graph->titre."\n"; 362 $graph->barcolor = "blue"; 363 $graph->GraphDraw($file, $gain_moyen, $labels); 364 365 $file = $img_root . "/factures/nb_facture.png"; 366 $graph = new GraphBar ($db, $file); 367 $graph->titre = "Nb de facture mois"; 368 if ($verbose) print $graph->titre."\n"; 369 $graph->barcolor = "yellow"; 370 $graph->GraphDraw($file, $nb_factures, $labels); 371 372 /* 373 * Répartition des factures 374 * 375 * 376 */ 377 repart($db); 378 379 function repart($db, $year = 0, $month = 0) 380 { 381 if ($verbose) print "Répartition des factures\n"; 382 383 $sql = "SELECT cout_vente, gain"; 384 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture"; 385 386 if ($year && $month) 387 { 388 if ($verbose) print "Répartition des factures pour $month/$year\n"; 389 $month = substr("00".$month, -2); 390 $sql .= " WHERE date_format(date,'%Y%m') = '$year$month'"; 391 } 392 393 if ($db->query($sql)) 394 { 395 $labels = array(); 396 $repart_montant = array(); 397 $num = $db->num_rows(); 398 399 $i = 0; 400 401 while ($i < $num) 402 { 403 $row = $db->fetch_row(); 404 405 if ($row[0] < 10) 406 { 407 $repart_montant[0]++; 408 } 409 elseif ($row[0] >= 10 && $row[0] < 20) 410 { 411 $repart_montant[1]++; 412 } 413 elseif ($row[0] >= 20 && $row[0] < 40) 414 { 415 $repart_montant[2]++; 416 } 417 elseif ($row[0] >= 40 && $row[0] < 70) 418 { 419 $repart_montant[3]++; 420 } 421 elseif ($row[0] >= 70 && $row[0] < 100) 422 { 423 $repart_montant[4]++; 424 } 425 else 426 { 427 $repart_montant[5]++; 428 } 429 430 431 if ($row[1] < 1) 432 { 433 $repart_gain[0]++; 434 } 435 elseif ($row[1] >= 1 && $row[1] < 5) 436 { 437 $repart_gain[1]++; 438 } 439 elseif ($row[1] >= 5 && $row[1] < 10) 440 { 441 $repart_gain[2]++; 442 } 443 elseif ($row[1] >= 10 && $row[1] < 20) 444 { 445 $repart_gain[3]++; 446 } 447 elseif ($row[1] >= 20 && $row[1] < 50) 448 { 449 $repart_gain[4]++; 450 } 451 else 452 { 453 $repart_gain[5]++; 454 } 455 $i++; 456 } 457 } 458 else 459 { 460 print $sql ; 461 } 462 463 if ($num > 0) 464 { 465 $labels_montant[0] = "< 10"; 466 $labels_montant[1] = "10-20"; 467 $labels_montant[2] = "20-40"; 468 $labels_montant[3] = "40-70"; 469 $labels_montant[4] = "70-100"; 470 $labels_montant[5] = "> 100"; 471 472 $labels_gain[0] = "< 1"; 473 $labels_gain[1] = "1-5"; 474 $labels_gain[2] = "5-10"; 475 $labels_gain[3] = "10-20"; 476 $labels_gain[4] = "20-50"; 477 $labels_gain[5] = "> 50"; 478 479 $filem = DOL_DATA_ROOT."/graph/telephonie/factures/montant_repart.png"; 480 $fileg = DOL_DATA_ROOT."/graph/telephonie/factures/gain_repart.png"; 481 482 if ($year && $month) 483 { 484 $filem = DOL_DATA_ROOT."/graph/telephonie/factures/montant_repart-$year$month.png"; 485 $fileg = DOL_DATA_ROOT."/graph/telephonie/factures/gain_repart-$year$month.png"; 486 } 487 488 $graphm = new GraphCamenbert ($db, $filem); 489 $graphg = new GraphCamenbert ($db, $fileg); 490 491 492 $graphm->titre = "Répartition du nombre de factures par montant"; 493 $graphg->titre = "Répartition du nombre de factures par gain"; 494 495 if ($year && $month) 496 { 497 $graphm->titre = "Répart. du nbre de factures par montant $month $year"; 498 $graphg->titre = "Répart. du nbre de factures par gain $month $year"; 499 } 500 501 $graphm->colors= array('#993333','#66cc99','#6633ff','#33ff33','#336699','#00ffff'); 502 503 // $graphm->GraphDraw($filem, $repart_montant, $labels_montant); 504 // $graphg->GraphDraw($fileg, $repart_gain, $labels_gain); 505 } 506 } 507 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |