| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?PHP 2 /* Copyright (C) 2004 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-analyse.php,v 1.5 2005/06/15 14:22:12 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/graph-statistiques-analyse.php,v $ 20 * 21 * 22 * Generation des graphiques 23 * 24 * 25 * 26 */ 27 require ("../../master.inc.php"); 28 29 require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"); 30 require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php"); 31 require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie-tarif.class.php"); 32 require_once (DOL_DOCUMENT_ROOT."/telephonie/communication.class.php"); 33 34 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/bar.class.php"); 35 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/camenbert.class.php"); 36 37 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/ca.class.php"); 38 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/gain.class.php"); 39 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/heureappel.class.php"); 40 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/joursemaine.class.php"); 41 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/camoyen.class.php"); 42 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/appelsdureemoyenne.class.php"); 43 require_once (DOL_DOCUMENT_ROOT."/telephonie/stats/graph/comm.nbmensuel.class.php"); 44 45 $error = 0; 46 47 $datetime = time(); 48 49 $date = strftime("%d%h%Y%Hh%Mm%S",$datetime); 50 51 $month = strftime("%m", $datetime); 52 $year = strftime("%Y", $datetime); 53 54 if ($month == 1) 55 { 56 $month = "12"; 57 $year = $year - 1; 58 } 59 else 60 { 61 $month = substr("00".($month - 1), -2) ; 62 } 63 64 65 $img_root = DOL_DATA_ROOT."/graph/telephonie/"; 66 67 /***********************************************************************/ 68 /* 69 /* Chiffre d'affaire mensuel 70 /* 71 /***********************************************************************/ 72 73 $file = $img_root . "ca/ca.mensuel.png"; 74 print "Graph : Chiffre d'affaire mensuel $file\n"; 75 $graphca = new GraphCa($db, $file); 76 $graphca->GraphDraw(); 77 78 /************************************************************************/ 79 /* 80 /* Chiffre d'affaire moyen 81 /* 82 /* 83 /************************************************************************/ 84 85 print "\nGraph ca moyen\n"; 86 87 $file = $img_root . "ca/gain_moyen_par_client.png"; 88 $graphgain = new GraphCaMoyen ($db, $file); 89 90 $graphgain->show_console = 0 ; 91 $graphgain->GraphDraw(); 92 93 /*************************************************************************/ 94 /* 95 /* Stats sur les communications 96 /* 97 /* 98 /*************************************************************************/ 99 100 $sql = "SELECT ".$db->pdate("date")." as date, duree"; 101 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 102 103 if ($db->query($sql)) 104 { 105 $heure_appel = array(); 106 $jour_semaine_nb = array(); 107 $jour_semaine_duree = array(); 108 109 $num = $db->num_rows(); 110 print "$num lignes de comm a traiter\n"; 111 $i = 0; 112 113 while ($i < $num) 114 { 115 $obj = $db->fetch_object(); 116 117 $h = strftime("%H",$obj->date) * 1; // suppression du 0 118 119 $heure_appel_nb[$h]++; 120 $heure_appel_duree[$h] += $obj->duree; 121 122 $u = strftime("%u",$obj->date) - 1; // 1 pour Lundi 123 124 $jour_semaine_nb[$u]++; 125 $jour_semaine_duree[$u] += $obj->duree; 126 127 $i++; 128 } 129 } 130 131 $file = $img_root . "communications/heure_appel_nb.png"; 132 $graphha = new GraphHeureAppel ($db, $file); 133 $graphha->GraphDraw($heure_appel_nb); 134 135 136 $file = $img_root . "communications/joursemaine_nb.png"; 137 $graphha = new GraphJourSemaine ($db, $file); 138 $graphha->GraphDraw($jour_semaine_nb); 139 140 repart_comm($db); 141 142 $year = strftime("%Y", $datetime); 143 $month = strftime("%m", $datetime); 144 145 for ($i = 1 ; $i < 4 ; $i++) 146 { 147 $month = $month - 1; 148 149 if ($month == 0) 150 { 151 $year = $year - 1; 152 $month = 12; 153 } 154 155 repart($db,$year, $month); 156 repart_comm($db,$year, $month); 157 158 } 159 160 161 function repart_comm($db, $year = 0, $month = 0) 162 { 163 print "Répartition des communications\n"; 164 165 $sql = "SELECT duree, numero"; 166 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 167 168 if ($year && $month) 169 { 170 print "Répartition des communications pour $month/$year\n"; 171 $month = substr("00".$month, -2); 172 $sql .= " WHERE date_format(date,'%Y%m') = '$year$month'"; 173 } 174 175 if ($db->query($sql)) 176 { 177 $labels_duree = array(); 178 $repart_duree = array(0,0,0,0,0,0); 179 $repart_dureelong = array(0,0); 180 181 $labels_dest= array(); 182 $repart_dest = array(0,0,0); 183 $repart_dest_temps = array(0,0,0); 184 185 $num = $db->num_rows(); 186 187 $i = 0; 188 189 while ($i < $num) 190 { 191 $row = $db->fetch_row(); 192 193 if ($row[0] < 10) 194 { 195 $repart_duree[0]++; 196 } 197 elseif ($row[0] >= 10 && $row[0] < 30) 198 { 199 $repart_duree[1]++; 200 } 201 elseif ($row[0] >= 30 && $row[0] < 60) 202 { 203 $repart_duree[2]++; 204 } 205 elseif ($row[0] >= 60 && $row[0] < 120) 206 { 207 $repart_duree[3]++; 208 } 209 elseif ($row[0] >= 120 && $row[0] < 300) 210 { 211 $repart_duree[4]++; 212 } 213 else 214 { 215 $repart_duree[5]++; 216 } 217 218 if ($row[0] < 600) 219 { 220 $repart_dureelong[0]++; 221 } 222 else 223 { 224 $repart_dureelong[1]++; 225 } 226 227 if (substr($row[1],0,2) == '00') 228 { 229 $repart_dest[0]++; 230 $repart_dest_temps[0] += $row[0]; 231 } 232 elseif (substr($row[1],0,2) == '06') 233 { 234 $repart_dest[1]++; 235 $repart_dest_temps[1] += $row[0]; 236 } 237 else 238 { 239 $repart_dest[2]++; 240 $repart_dest_temps[2] += $row[0]; 241 } 242 $i++; 243 } 244 } 245 else 246 { 247 print $sql ; 248 } 249 250 if ($num > 0) 251 { 252 $labels_duree[0] = "< 10 sec"; 253 $labels_duree[1] = "10-30 sec"; 254 $labels_duree[2] = "30-60 sec"; 255 $labels_duree[3] = "60-120 sec"; 256 $labels_duree[4] = "120-300 sec"; 257 $labels_duree[5] = "> 300 sec"; 258 259 $labels_dureelong[0] = "< 600 sec"; 260 $labels_dureelong[1] = "> 600 sec"; 261 262 $labels_dest[0] = 'International'; 263 $labels_dest[1] = 'Mobile'; 264 $labels_dest[2] = 'Local/National'; 265 266 $filem = DOL_DOCUMENT_ROOT."/telephonie/stats/communications/duree_repart.png"; 267 $filec = DOL_DOCUMENT_ROOT."/telephonie/stats/communications/dureelong_repart.png"; 268 $filed = DOL_DOCUMENT_ROOT."/telephonie/stats/communications/dest_repart.png"; 269 $filedt = DOL_DOCUMENT_ROOT."/telephonie/stats/communications/dest_temps_repart.png"; 270 271 if ($year && $month) 272 { 273 $filem = DOL_DOCUMENT_ROOT."/telephonie/stats/communications/duree_repart-$year$month.png"; 274 $filec = DOL_DOCUMENT_ROOT."/telephonie/stats/communications/dureelong_repart-$year$month.png"; 275 $filed = DOL_DOCUMENT_ROOT."/telephonie/stats/communications/dest_repart-$year$month.png"; 276 $filedt = DOL_DOCUMENT_ROOT."/telephonie/stats/communications/dest_temps_repart-$year$month.png"; 277 } 278 279 $graphm = new GraphCamenbert ($db, $filem); 280 $graphc = new GraphCamenbert ($db, $filec); 281 $graphd = new GraphCamenbert ($db, $filed); 282 $graphdt = new GraphCamenbert ($db, $filedt); 283 284 $graphm->titre = "Répartition du nombre de communications par duree"; 285 $graphc->titre = "Répartition du nombre de communications par duree"; 286 $graphd->titre = "Répartition du nombre de communications par destination"; 287 $graphdt->titre = "Répartition du nombre de communications par destination"; 288 289 if ($year && $month) 290 { 291 $graphm->titre = "Répart. du nbre de communications par duree $month/$year"; 292 $graphc->titre = "Répart. du nbre de communications par duree $month/$year"; 293 $graphd->titre = "Répart. du nbre de communications par destination $month/$year"; 294 $graphdt->titre = "Répart. du temps de communications par destination $month/$year"; 295 } 296 297 $graphm->colors= array('#993333','#66cc99','#6633ff','#33ff33','#336699','#00ffff'); 298 $graphd->colors= array('#FFC0FF','#FF00FF','#C000C0'); 299 $graphdt->colors= array('#FFFFC0','#FFFF0F','#C0C000'); 300 301 $graphm->GraphDraw($repart_duree, $labels_duree); 302 $graphc->GraphDraw($repart_dureelong, $labels_dureelong); 303 $graphd->GraphDraw($repart_dest, $labels_dest); 304 $graphdt->GraphDraw($repart_dest_temps, $labels_dest); 305 } 306 } 307 308 /***************************************************************************/ 309 $sql = "SELECT date_format(date, '%Y%m'), count(distinct(ligne))"; 310 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 311 $sql .= " GROUP BY date_format(date, '%Y%m') ASC"; 312 313 if ($db->query($sql)) 314 { 315 $nblignes = array(); 316 317 $num = $db->num_rows(); 318 319 $i = 0; 320 321 while ($i < $num) 322 { 323 $row = $db->fetch_row(); 324 $nblignes[$i] = $row[1]; 325 $i++; 326 } 327 } 328 329 /* 330 * 331 * 332 */ 333 334 $sql = "SELECT date_format(date, '%Y%m'), sum(duree), count(duree)"; 335 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 336 $sql .= " GROUP BY date_format(date, '%Y%m') ASC"; 337 338 $resql = $db->query($sql); 339 340 if ($resql) 341 { 342 $durees = array(); 343 $kilomindurees = array(); 344 $durees_moyenne = array(); 345 $nombres = array(); 346 $labels = array(); 347 348 $num = $db->num_rows($resql); 349 350 $i = 0; 351 352 while ($i < $num) 353 { 354 $row = $db->fetch_row($resql); 355 $labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2); 356 $durees[$i] = $row[1]; 357 $kilomindurees[$i] = ($row[1]/60000); 358 $durees_moyenne[$i] = ($row[1] / $row[2]); 359 $nombres[$i] = $row[2]; 360 361 $nbappels_ligne[$i] = ($nombres[$i] / $nblignes[$i]); 362 363 $i++; 364 } 365 } 366 367 368 369 $file = $img_root . "communications/nbappelsparligne.png"; 370 $graphgain = new GraphBar ($db, $file); 371 $graphgain->show_console = 0 ; 372 $graphgain->titre = "Nb appels moyen par ligne"; 373 print $graphgain->titre."\n"; 374 $graphgain->barcolor = "pink"; 375 $graphgain->GraphDraw($file, $nbappels_ligne, $labels); 376 377 $file = $img_root . "communications/dureemoyenne.png"; 378 $graphgain = new GraphBar ($db, $file); 379 $graphgain->show_console = 0 ; 380 $graphgain->titre = "Durée moyenne d'un appel"; 381 print $graphgain->titre."\n"; 382 $graphgain->barcolor = "yellow"; 383 $graphgain->GraphDraw($file, $durees_moyenne, $labels); 384 385 $file = $img_root . "communications/nombre.png"; 386 $graphgain = new GraphBar ($db, $file); 387 $graphgain->show_console = 0 ; 388 $graphgain->titre = "Nombres d'appel mensuels"; 389 print $graphgain->titre."\n"; 390 $graphgain->GraphDraw($file, $nombres, $labels); 391 392 /* ---------------------------------------------- */ 393 394 $sql = "SELECT date_format(date, '%Y%m'), sum(duree), count(duree)"; 395 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 396 $sql .= " WHERE numero like '06%'"; 397 $sql .= " GROUP BY date_format(date, '%Y%m') ASC"; 398 399 if ($db->query($sql)) 400 { 401 $durees = array(); 402 $kilomindurees = array(); 403 $durees_moyenne = array(); 404 $nombres = array(); 405 $labels = array(); 406 407 $num = $db->num_rows(); 408 409 $i = 0; 410 411 while ($i < $num) 412 { 413 $row = $db->fetch_row(); 414 $labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2); 415 $durees[$i] = $row[1]; 416 $kilomindurees_mob[$i] = ($row[1]/60000); 417 418 $i++; 419 } 420 } 421 422 423 424 /* ---------------------------------------------- */ 425 426 $sql = "SELECT date_format(date, '%Y%m'), sum(duree), count(duree)"; 427 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 428 $sql .= " WHERE numero like '00%'"; 429 $sql .= " GROUP BY date_format(date, '%Y%m') ASC"; 430 431 if ($db->query($sql)) 432 { 433 $durees = array(); 434 $kilomindurees_inter = array(); 435 $durees_moyenne = array(); 436 $nombres = array(); 437 $labels = array(); 438 439 $num = $db->num_rows(); 440 441 $i = 0; 442 443 while ($i < $num) 444 { 445 $row = $db->fetch_row(); 446 $labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2); 447 $durees[$i] = $row[1]; 448 $kilomindurees_inter[$i] = ($row[1]/60000); 449 450 $i++; 451 } 452 } 453 454 $file = $img_root . "communications/duree_inter.png"; 455 $graphgain = new GraphBar ($db, $file); 456 $graphgain->show_console = 0 ; 457 $graphgain->titre = "Nb minutes -> inter (milliers)"; 458 print $graphgain->titre."\n"; 459 $graphgain->GraphDraw($file, $kilomindurees_inter, $labels); 460 461 /* ---------------------------------------------- */ 462 463 $sql = "SELECT date_format(date, '%Y%m'), sum(duree)"; 464 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details"; 465 $sql .= " WHERE substring(numero, 1, 2) <> '00'"; 466 $sql .= " AND substring(numero, 1, 2) <> '06'"; 467 $sql .= " GROUP BY date_format(date, '%Y%m') ASC"; 468 469 if ($db->query($sql)) 470 { 471 $kilomindurees_loc = array(); 472 $labels = array(); 473 $num = $db->num_rows(); 474 $i = 0; 475 476 while ($i < $num) 477 { 478 $row = $db->fetch_row(); 479 $labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2); 480 $kilomindurees_loc[$i] = ($row[1]/60000); 481 482 $i++; 483 } 484 } 485 486 $file = $img_root . "communications/duree_loc.png"; 487 $graphgain = new GraphBar ($db, $file); 488 $graphgain->show_console = 0 ; 489 $graphgain->titre = "Nb minutes -> local/national (milliers)"; 490 print $graphgain->titre."\n"; 491 $graphgain->GraphDraw($file, $kilomindurees_loc, $labels); 492 493 494 /**********************************************************************/ 495 /* 496 /* Stats sur les factures 497 /* 498 /* 499 /**********************************************************************/ 500 501 $sql = "SELECT date_format(date,'%Y%m'), sum(cout_vente), sum(cout_achat), sum(gain), count(cout_vente)"; 502 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture"; 503 $sql .= " GROUP BY date_format(date,'%Y%m') ASC "; 504 505 if ($db->query($sql)) 506 { 507 $cout_vente = array(); 508 $cout_vente_moyen = array(); 509 $nb_factures = array(); 510 $jour_semaine_nb = array(); 511 $jour_semaine_duree = array(); 512 $gain = array(); 513 $gain_moyen = array(); 514 515 $num = $db->num_rows(); 516 print "$num lignes de comm a traiter\n"; 517 $i = 0; 518 519 while ($i < $num) 520 { 521 $row = $db->fetch_row(); 522 523 $cout_vente[$i] = $row[1]; 524 525 $gain[$i] = $row[3]; 526 $gain_moyen[$i] = ($row[3]/$row[4]); 527 $cout_vente_moyen[$i] = ($row[1]/$row[4]); 528 $nb_factures[$i] = $row[4]; 529 $labels[$i] = substr($row[0],4,2) . '/'.substr($row[0],2,2); 530 $i++; 531 } 532 } 533 534 535 $file = $img_root . "/factures/facture_moyenne.png"; 536 $graph = new GraphBar ($db, $file, $labels); 537 $graph->titre = "Facture moyenne"; 538 print $graph->titre."\n"; 539 $graph->barcolor = "blue"; 540 $graph->GraphDraw($file, $cout_vente_moyen, $labels); 541 542 $file = $img_root . "/factures/gain_mensuel.png"; 543 $graph = new GraphBar ($db, $file); 544 $graph->titre = "Gain par mois en euros HT"; 545 print $graph->titre."\n"; 546 $graph->GraphDraw($file, $gain, $labels); 547 548 $file = $img_root . "/factures/gain_moyen.png"; 549 $graph = new GraphBar ($db, $file); 550 $graph->titre = "Gain moyen par facture par mois"; 551 print $graph->titre."\n"; 552 $graph->barcolor = "blue"; 553 $graph->GraphDraw($file, $gain_moyen, $labels); 554 555 $file = $img_root . "/factures/nb_facture.png"; 556 $graph = new GraphBar ($db, $file); 557 $graph->titre = "Nb de facture mois"; 558 print $graph->titre."\n"; 559 $graph->barcolor = "yellow"; 560 $graph->GraphDraw($file, $nb_factures, $labels); 561 562 /* 563 * Répartition des factures 564 * 565 * 566 */ 567 repart($db); 568 569 function repart($db, $year = 0, $month = 0) 570 { 571 print "Répartition des factures\n"; 572 573 $sql = "SELECT cout_vente, gain"; 574 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture"; 575 576 if ($year && $month) 577 { 578 print "Répartition des factures pour $month/$year\n"; 579 $month = substr("00".$month, -2); 580 $sql .= " WHERE date_format(date,'%Y%m') = '$year$month'"; 581 } 582 583 if ($db->query($sql)) 584 { 585 $labels = array(); 586 $repart_montant = array(); 587 $num = $db->num_rows(); 588 589 $i = 0; 590 591 while ($i < $num) 592 { 593 $row = $db->fetch_row(); 594 595 if ($row[0] < 10) 596 { 597 $repart_montant[0]++; 598 } 599 elseif ($row[0] >= 10 && $row[0] < 20) 600 { 601 $repart_montant[1]++; 602 } 603 elseif ($row[0] >= 20 && $row[0] < 40) 604 { 605 $repart_montant[2]++; 606 } 607 elseif ($row[0] >= 40 && $row[0] < 70) 608 { 609 $repart_montant[3]++; 610 } 611 elseif ($row[0] >= 70 && $row[0] < 100) 612 { 613 $repart_montant[4]++; 614 } 615 else 616 { 617 $repart_montant[5]++; 618 } 619 620 621 if ($row[1] < 1) 622 { 623 $repart_gain[0]++; 624 } 625 elseif ($row[1] >= 1 && $row[1] < 5) 626 { 627 $repart_gain[1]++; 628 } 629 elseif ($row[1] >= 5 && $row[1] < 10) 630 { 631 $repart_gain[2]++; 632 } 633 elseif ($row[1] >= 10 && $row[1] < 20) 634 { 635 $repart_gain[3]++; 636 } 637 elseif ($row[1] >= 20 && $row[1] < 50) 638 { 639 $repart_gain[4]++; 640 } 641 else 642 { 643 $repart_gain[5]++; 644 } 645 $i++; 646 } 647 } 648 else 649 { 650 print $sql ; 651 } 652 653 if ($num > 0) 654 { 655 $labels_montant[0] = "< 10"; 656 $labels_montant[1] = "10-20"; 657 $labels_montant[2] = "20-40"; 658 $labels_montant[3] = "40-70"; 659 $labels_montant[4] = "70-100"; 660 $labels_montant[5] = "> 100"; 661 662 $labels_gain[0] = "< 1"; 663 $labels_gain[1] = "1-5"; 664 $labels_gain[2] = "5-10"; 665 $labels_gain[3] = "10-20"; 666 $labels_gain[4] = "20-50"; 667 $labels_gain[5] = "> 50"; 668 669 $filem = DOL_DOCUMENT_ROOT."/telephonie/stats/factures/montant_repart.png"; 670 $fileg = DOL_DOCUMENT_ROOT."/telephonie/stats/factures/gain_repart.png"; 671 672 if ($year && $month) 673 { 674 $filem = DOL_DOCUMENT_ROOT."/telephonie/stats/factures/montant_repart-$year$month.png"; 675 $fileg = DOL_DOCUMENT_ROOT."/telephonie/stats/factures/gain_repart-$year$month.png"; 676 } 677 678 $graphm = new GraphCamenbert ($db, $filem); 679 $graphg = new GraphCamenbert ($db, $fileg); 680 681 682 $graphm->titre = "Répartition du nombre de factures par montant"; 683 $graphg->titre = "Répartition du nombre de factures par gain"; 684 685 if ($year && $month) 686 { 687 $graphm->titre = "Répart. du nbre de factures par montant $month $year"; 688 $graphg->titre = "Répart. du nbre de factures par gain $month $year"; 689 } 690 691 $graphm->colors= array('#993333','#66cc99','#6633ff','#33ff33','#336699','#00ffff'); 692 693 // $graphm->GraphDraw($filem, $repart_montant, $labels_montant); 694 // $graphg->GraphDraw($fileg, $repart_gain, $labels_gain); 695 } 696 } 697 ?>
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 |
|