| [ 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: rapport.php,v 1.4 2005/04/12 08:10:07 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/script/rapport.php,v $ 20 * 21 * Génération des rapports 22 * 23 */ 24 print "Mem : ".memory_get_usage() ."\n"; 25 require ("../../master.inc.php"); 26 27 require_once (DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"); 28 require_once (DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php"); 29 require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie-tarif.class.php"); 30 require_once (DOL_DOCUMENT_ROOT."/telephonie/communication.class.php"); 31 require_once (DOL_DOCUMENT_ROOT."/telephonie/numero.class.php"); 32 require_once (DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_workbook.inc.php"); 33 require_once (DOL_DOCUMENT_ROOT."/includes/php_writeexcel/class.writeexcel_worksheet.inc.php"); 34 35 36 $error = 0; 37 38 $datetime = time(); 39 40 $date = strftime("%d%h%Y%Hh%Mm%S",$datetime); 41 42 $month = strftime("%m", $datetime); 43 $year = strftime("%Y", $datetime); 44 45 if ($month == 1) 46 { 47 $month = "12"; 48 $year = $year - 1; 49 } 50 else 51 { 52 $month = substr("00".($month - 1), -2) ; 53 } 54 55 //$month = "02"; 56 //$year = "2005"; 57 58 /* 59 * Lecture des groupes de lignes 60 * 61 */ 62 $groupes = array(); 63 $numdatas = array(); 64 $lignes = array(); 65 66 $tarif_vente = new TelephonieTarif($db, 1, "vente"); 67 68 $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."telephonie_groupeligne"; 69 70 $resql = $db->query($sql); 71 72 if ($resql) 73 { 74 $nums = $db->num_rows($resql); 75 $i = 0; 76 while($i < $nums) 77 { 78 $row = $db->fetch_row($resql); 79 $groupes[$row[0]] = $row[1]; 80 print "Mem : ".memory_get_usage() ."\n"; 81 $i++; 82 } 83 $db->free($resql); 84 } 85 86 87 foreach ($groupes as $keygroupe => $groupe) 88 { 89 90 $dir = DOL_DATA_ROOT . "/telephonie/rapports/".$keygroupe; 91 92 if (! file_exists($dir)) 93 { 94 umask(0); 95 if (! @mkdir($dir, 0755)) 96 { 97 print "Erreur: Le répertoire '$dir' n'existe pas et Dolibarr n'a pu le créer."; 98 } 99 } 100 101 102 $fname = $dir."/".substr('00'.$month, -2)."-".$year.".xls"; 103 104 print "Open $fname\n"; 105 106 $workbook = &new writeexcel_workbook($fname); 107 108 $formatcc =& $workbook->addformat(); 109 $formatcc->set_align('center'); 110 $formatcc->set_align('vcenter'); 111 112 $fclient =& $workbook->addformat(); 113 $fclient->set_align('left'); 114 $fclient->set_align('vcenter'); 115 $fclient->set_border(1); 116 117 $fcode =& $workbook->addformat(); 118 $fcode->set_align('center'); 119 $fcode->set_align('vcenter'); 120 $fcode->set_border(1); 121 122 $fligne =& $workbook->addformat(); 123 $fligne->set_align('center'); 124 $fligne->set_align('vcenter'); 125 $fligne->set_right(6); 126 $fligne->set_bottom(1); 127 128 $fnb =& $workbook->addformat(); 129 $fnb->set_align('vcenter'); 130 $fnb->set_align('center'); 131 $fnb->set_top(1); 132 $fnb->set_right(1); 133 $fnb->set_bottom(1); 134 $fnb->set_left(6); 135 136 $fduree =& $workbook->addformat(); 137 $fduree->set_align('center'); 138 $fduree->set_align('vcenter'); 139 $fduree->set_border(1); 140 141 $fcout =& $workbook->addformat(); 142 $fcout->set_align('center'); 143 $fcout->set_align('vcenter'); 144 $fcout->set_num_format('0.00'); 145 $fcout->set_border(1); 146 147 $fmoy =& $workbook->addformat(); 148 $fmoy->set_align('center'); 149 $fmoy->set_align('vcenter'); 150 $fmoy->set_right(6); 151 $fmoy->set_bottom(1); 152 $fmoy->set_num_format('0.0000'); 153 154 $format_titre =& $workbook->addformat(); 155 $format_titre->set_align('center'); 156 $format_titre->set_align('vcenter'); 157 $format_titre->set_bold(); 158 $format_titre->set_border(1); 159 160 $format_titre_nb =& $workbook->addformat(); 161 $format_titre_nb->set_align('center'); 162 $format_titre_nb->set_align('vcenter'); 163 $format_titre_nb->set_bold(); 164 $format_titre_nb->set_right(1); 165 $format_titre_nb->set_top(1); 166 $format_titre_nb->set_bottom(1); 167 $format_titre_nb->set_left(6); 168 169 $format_titre_moy =& $workbook->addformat(); 170 $format_titre_moy->set_align('center'); 171 $format_titre_moy->set_align('vcenter'); 172 $format_titre_moy->set_bold(); 173 $format_titre_moy->set_right(1); 174 $format_titre_moy->set_top(1); 175 $format_titre_moy->set_bottom(1); 176 $format_titre_moy->set_right(6); 177 178 $format_titre_agence1 =& $workbook->addformat(); 179 $format_titre_agence1->set_align('center'); 180 $format_titre_agence1->set_align('vcenter'); 181 $format_titre_agence1->set_bold(); 182 $format_titre_agence1->set_right(1); 183 $format_titre_agence1->set_left(1); 184 $format_titre_agence1->set_top(1); 185 $format_titre_agence1->set_merge(); 186 187 $format_titre_agence2 =& $workbook->addformat(); 188 $format_titre_agence2->set_align('center'); 189 $format_titre_agence2->set_align('vcenter'); 190 $format_titre_agence2->set_bold(); 191 $format_titre_agence2->set_right(1); 192 $format_titre_agence2->set_left(1); 193 $format_titre_agence2->set_bottom(1); 194 $format_titre_agence2->set_merge(); 195 196 197 $format_titre_nat1 =& $workbook->addformat(); 198 $format_titre_nat1->set_align('center'); 199 $format_titre_nat1->set_align('vcenter'); 200 $format_titre_nat1->set_bold(); 201 $format_titre_nat1->set_left(6); 202 $format_titre_nat1->set_merge(); 203 204 $format_titre_nat2 =& $workbook->addformat(); 205 $format_titre_nat2->set_align('center'); 206 $format_titre_nat2->set_align('vcenter'); 207 $format_titre_nat2->set_bold(); 208 $format_titre_nat2->set_merge(); 209 210 $format_titre_nat3 =& $workbook->addformat(); 211 $format_titre_nat3->set_align('center'); 212 $format_titre_nat3->set_align('vcenter'); 213 $format_titre_nat3->set_bold(); 214 $format_titre_nat3->set_right(6); 215 $format_titre_nat3->set_merge(); 216 217 $format_titre_total1 =& $workbook->addformat(); 218 $format_titre_total1->set_align('center'); 219 $format_titre_total1->set_align('vcenter'); 220 $format_titre_total1->set_bold(); 221 $format_titre_total1->set_left(1); 222 $format_titre_total1->set_top(1); 223 $format_titre_total1->set_bottom(1); 224 $format_titre_total1->set_merge(); 225 226 $format_titre_total2 =& $workbook->addformat(); 227 $format_titre_total2->set_align('center'); 228 $format_titre_total2->set_align('vcenter'); 229 $format_titre_total2->set_bold(); 230 $format_titre_total2->set_top(1); 231 $format_titre_total2->set_bottom(1); 232 $format_titre_total2->set_merge(); 233 234 $format_titre_total3 =& $workbook->addformat(); 235 $format_titre_total3->set_align('center'); 236 $format_titre_total3->set_align('vcenter'); 237 $format_titre_total3->set_bold(); 238 $format_titre_total3->set_right(6); 239 $format_titre_total3->set_top(1); 240 $format_titre_total3->set_bottom(1); 241 $format_titre_total3->set_merge(); 242 243 244 $formatc =& $workbook->addformat(); 245 $formatc->set_align('vcenter'); 246 247 248 $fnbBold =& $workbook->addformat(); 249 $fnbBold->set_align('vcenter'); 250 $fnbBold->set_bold(); 251 252 $formatr =& $workbook->addformat(); 253 $formatr->set_align('vcenter'); 254 $formatr->set_align('right'); 255 256 $fcoutBold =& $workbook->addformat(); 257 $fcoutBold->set_align('right'); 258 $fcoutBold->set_num_format('0.00'); 259 $fcoutBold->set_bold(); 260 261 $fgrey =& $workbook->addformat(); 262 $fgrey->set_fg_color('yellow'); 263 $fgrey->set_bold(); 264 $fgrey->set_align('left'); 265 $fgrey->set_pattern(0x1); 266 267 $ftotal =& $workbook->addformat(); 268 $ftotal->set_bold(); 269 $ftotal->set_align('right'); 270 $ftotal->set_align('vcenter'); 271 $ftotal->set_pattern(0x1); 272 273 /* 274 * Chargement des numéros de datas 275 * 276 */ 277 278 $sql = "SELECT n.numero "; 279 $sql .=" FROM ".MAIN_DB_PREFIX."telephonie_numdata as n"; 280 $sql .= " WHERE n.fk_groupe = ".$keygroupe; 281 282 $resql = $db->query($sql); 283 284 if ($resql) 285 { 286 $nums = $db->num_rows($resql); 287 $si = 0; 288 while($si < $nums) 289 { 290 $row = $db->fetch_row($resql); 291 $numdatas[$row[0]] = $row[0]; 292 $si++; 293 } 294 $db->free($resql); 295 } 296 else 297 { 298 print $db->error(); 299 } 300 301 /* 302 * Boucle sur les mois 303 */ 304 for ($imonth = 1 ; $imonth <= ($month + 1) ; $imonth++) 305 { 306 307 if ($imonth > $month) 308 { 309 $page2 = &$workbook->addworksheet("Année $year"); 310 } 311 else 312 { 313 $page2 = &$workbook->addworksheet($year."-.".substr("00".$imonth,-2)); 314 } 315 316 for ($a = 0 ; $a < 200 ; $a++) 317 { 318 $page2->set_row($a,25); // A 319 } 320 321 $page2->set_column(0,0,40); // A 322 $page2->set_column(1,1,10); // B 323 $page2->set_column(2,2,13); // C 324 325 $page2->set_column(3,3,7); // D 326 $page2->set_column(6,6,7); // G 327 $page2->set_column(9,9,7); // J 328 $page2->set_column(12,12,7); // M 329 330 $page2->set_column(4,5,10); // E-F 331 $page2->set_column(7,8,10); // H-I 332 $page2->set_column(10,11,10); // K-L 333 $page2->set_column(13,14,10); // N-O 334 335 $page2->write(0, 0, "Agence/Filiale", $format_titre_agence1); 336 $page2->write_blank(1, 0, $format_titre_agence2); 337 338 $page2->write(0, 1, "Site", $format_titre); 339 $page2->write(0, 2, "Ligne", $format_titre); 340 341 $page2->write(0, 3, "Local/National", $format_titre_nat1); 342 $page2->write_blank(0, 4, $format_titre_nat2); 343 $page2->write_blank(0, 5, $format_titre_nat3); 344 345 346 $page2->write(1, 3, "Nb", $format_titre_nb); 347 $page2->write(1, 4, "Durée", $format_titre); 348 $page2->write(1, 5, "Coût", $format_titre); 349 350 351 $page2->write(0, 6, "Mobile SFR/Orange", $format_titre_nat1); 352 $page2->write_blank(0, 7, $format_titre_nat2); 353 $page2->write_blank(0, 8, $format_titre_nat3); 354 355 356 $page2->write(1, 6, "Nb", $format_titre_nb); 357 $page2->write(1, 7, "Durée", $format_titre); 358 $page2->write(1, 8, "Coût", $format_titre); 359 360 361 $page2->write(0, 9, "Mobile Bouygues", $format_titre_nat1); 362 $page2->write_blank(0, 10, $format_titre_nat2); 363 $page2->write_blank(0, 11, $format_titre_nat3); 364 365 $page2->write(1, 9, "Nb", $format_titre_nb); 366 $page2->write(1, 10, "Durée", $format_titre); 367 $page2->write(1, 11, "Coût", $format_titre); 368 369 370 $page2->write(0, 12, "Données", $format_titre_nat1); 371 $page2->write_blank(0, 13, $format_titre_nat2); 372 $page2->write_blank(0, 14, $format_titre_nat3); 373 374 $page2->write(1, 12, "Nb", $format_titre_nb); 375 $page2->write(1, 13, "Durée", $format_titre); 376 $page2->write(1, 14, "Coût", $format_titre); 377 378 379 $page2->write(0, 15, "Total", $format_titre_nat1); 380 $page2->write_blank(0, 16, $format_titre_nat2); 381 $page2->write_blank(0, 17, $format_titre_nat2); 382 $page2->write_blank(0, 18, $format_titre_nat3); 383 384 $page2->write(1, 15, "Nb", $format_titre_nb); 385 $page2->write(1, 16, "Durée", $format_titre); 386 $page2->write(1, 17, "Coût", $format_titre); 387 $page2->write(1, 18, "Moyenne\ncoût/sec", $format_titre_moy); 388 389 unset ($lignes); 390 391 /* 392 * 393 * 394 */ 395 $sql = "SELECT sl.rowid, sl.ligne"; 396 $sql .=" FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as sl"; 397 $sql .=" , ".MAIN_DB_PREFIX."telephonie_groupe_ligne as gl"; 398 399 $sql .= " WHERE gl.fk_ligne = sl.rowid"; 400 $sql .= " AND sl.statut <> 7"; 401 $sql .= " AND gl.fk_groupe = ".$keygroupe; 402 403 $sql .= " ORDER BY sl.fk_soc_facture ASC"; 404 405 if ( $db->query($sql) ) 406 { 407 $nums = $db->num_rows(); 408 $si = 0; 409 while($si < $nums) 410 { 411 $row = $db->fetch_row(); 412 413 $lignes[$row[0]] = $row[1]; 414 415 //print "Lecture $row[1]\n"; 416 $si++; 417 } 418 $db->free(); 419 } 420 else 421 { 422 print $db->error(); 423 } 424 425 /* 426 * 427 * 428 */ 429 430 $xx = 2; 431 $oldxx = $xx+1; 432 $oldana = ''; 433 $oldfk_soc = ''; 434 $lines = array(); 435 436 $fksoc = 0; 437 $tg = 0; // permet de gérer l'affichage du total groupe. 438 439 $total_global_nb = 0; 440 $total_global_duree = 0; 441 $total_global_cout = 0; 442 443 $total_global_mobile_nb = 0; 444 $total_global_mobile_duree = 0; 445 $total_global_mobile_cout = 0; 446 447 $total_global_data_nb = 0; 448 $total_global_data_duree = 0; 449 $total_global_data_cout = 0; 450 451 $total_global_inter_nb = 0; 452 $total_global_inter_duree = 0; 453 $total_global_inter_cout = 0; 454 455 $total_global_national_nb = 0; 456 $total_global_national_duree = 0; 457 $total_global_national_cout = 0; 458 459 $total_groupe_national_nb = 0; 460 $total_groupe_national_duree = 0; 461 $total_groupe_national_cout = 0; 462 463 $total_groupe_mobile_sfr_nb = 0; 464 $total_groupe_mobile_sfr_duree = 0; 465 $total_groupe_mobile_sfr_cout = 0; 466 467 $total_groupe_mobile_orange_nb = 0; 468 $total_groupe_mobile_orange_duree = 0; 469 $total_groupe_mobile_orange_cout = 0; 470 471 $total_groupe_mobile_bouygues_nb = 0; 472 $total_groupe_mobile_bouygues_duree = 0; 473 $total_groupe_mobile_bouygues_cout = 0; 474 475 $total_groupe_data_nb = 0; 476 $total_groupe_data_duree = 0; 477 $total_groupe_data_cout = 0; 478 479 $total_groupe_duree = 0; 480 $total_groupe_nb = 0; 481 $total_groupe_cout = 0; 482 483 foreach ($lignes as $keyligne => $ligne) 484 { 485 $lignetel = new LigneTel($db); 486 $lignetel->fetch_by_id($keyligne); 487 488 $client = new Societe($db); 489 $client->fetch($lignetel->client_id); 490 491 //print "Traitement ligne $keyligne ". $lignetel->numero."\n"; 492 493 $national_nb = 0; 494 $national_duree = 0; 495 $national_cout = 0; 496 497 $mobile_sfr_nb = 0; 498 $mobile_sfr_duree = 0; 499 $mobile_sfr_cout = 0; 500 501 $mobile_orange_nb = 0; 502 $mobile_orange_duree = 0; 503 $mobile_orange_cout = 0; 504 505 $mobile_bouygues_nb = 0; 506 $mobile_bouygues_duree = 0; 507 $mobile_bouygues_cout = 0; 508 509 $inter_nb = 0; 510 $inter_duree = 0; 511 $inter_cout = 0; 512 513 $data_nb = 0; 514 $data_duree = 0; 515 $data_cout = 0; 516 517 if (($oldfk_soc <> $lignetel->client_facture_id) && ($fksoc > 0)) 518 { 519 $page2->write_string($xx, 0, 'Total', $format_titre_total1); 520 $page2->write_blank($xx, 1, $format_titre_total2); 521 $page2->write_blank($xx, 2, $format_titre_total3); 522 523 $str = '=SUM(D'.$oldxx.':D'.($xx).')'; 524 $page2->write_formula($xx, 3, $str, $fnb); 525 526 //$page2->write($xx, 3, $total_groupe_national_nb, $fnb); 527 $page2->write_string($xx, 4, duree_text($total_groupe_national_duree), $fduree); 528 529 $str = '=SUM(F'.$oldxx.':F'.($xx).')'; 530 $page2->write_formula($xx, 5, $str, $fcout); 531 532 $str = '=SUM(G'.$oldxx.':G'.($xx).')'; 533 $page2->write_formula($xx, 6, $str, $fnb); 534 535 $page2->write_string($xx, 7, duree_text(($total_groupe_mobile_sfr_duree + $total_groupe_mobile_orange_duree)), $fduree); 536 537 538 $str = '=SUM(I'.$oldxx.':I'.($xx).')'; 539 $page2->write_formula($xx, 8, $str, $fcout); 540 541 $str = '=SUM(J'.$oldxx.':J'.($xx).')'; 542 $page2->write_formula($xx, 9, $str, $fnb); 543 544 $page2->write_string($xx, 10, duree_text($total_groupe_mobile_bouygues_duree), $fduree); 545 546 $str = '=SUM(L'.$oldxx.':L'.($xx).')'; 547 $page2->write_formula($xx, 11, $str, $fcout); 548 549 $str = '=SUM(M'.$oldxx.':M'.($xx).')'; 550 $page2->write_formula($xx, 12, $str, $fnb); 551 552 $page2->write_string($xx, 13, duree_text($total_groupe_data_duree), $fduree); 553 554 $str = '=SUM(O'.$oldxx.':O'.($xx).')'; 555 $page2->write_formula($xx, 14, $str, $fcout); 556 557 $tlg_nb = $total_groupe_national_nb + $total_groupe_mobile_sfr_nb + $total_groupe_mobile_orange_nb + $total_groupe_mobile_bouygues_nb + $total_groupe_data_nb; 558 559 $tlg_duree = $total_groupe_national_duree + $total_groupe_mobile_sfr_duree + $total_groupe_mobile_orange_duree + $total_groupe_mobile_bouygues_duree + $total_groupe_data_duree; 560 561 $tlg_cout = $total_groupe_national_cout + $total_groupe_mobile_sfr_cout + $total_groupe_mobile_orange_cout + $total_groupe_mobile_bouygues_cout + $total_groupe_data_cout; 562 563 $str ="=D".($xx+1)."+G".($xx+1)."+J".($xx+1)."+M".($xx+1); 564 565 $page2->write_formula($xx, 15, $str, $fnb); 566 $page2->write_string($xx, 16, duree_text($tlg_duree), $fduree); 567 $str ="=F".($xx+1)."+I".($xx+1)."+L".($xx+1)."+O".($xx+1); 568 $page2->write_formula($xx, 17, $str, $fcout); 569 570 571 if ($tlg_duree > 0) 572 { 573 $page2->write($xx, 18, round(($tlg_cout/$tlg_duree),4), $fmoy); 574 } 575 else 576 { 577 $page2->write($xx, 18, 0, $fmoy); 578 } 579 580 $tg = 0; 581 $total_groupe_duree = 0; 582 $total_groupe_nb = 0; 583 $total_groupe_cout = 0; 584 585 $total_groupe_national_nb = 0; 586 $total_groupe_national_duree = 0; 587 $total_groupe_national_cout = 0; 588 589 $total_groupe_mobile_sfr_nb = 0; 590 $total_groupe_mobile_sfr_duree = 0; 591 $total_groupe_mobile_sfr_cout = 0; 592 593 $total_groupe_mobile_orange_nb = 0; 594 $total_groupe_mobile_orange_duree = 0; 595 $total_groupe_mobile_orange_cout = 0; 596 597 $total_groupe_mobile_bouygues_nb = 0; 598 $total_groupe_mobile_bouygues_duree = 0; 599 $total_groupe_mobile_bouygues_cout = 0; 600 601 $total_groupe_data_nb = 0; 602 $total_groupe_data_duree = 0; 603 $total_groupe_data_cout = 0; 604 605 $lines = array(); 606 607 $oldfk_soc = $lignetel->client_facture_id; 608 $xx++; 609 $oldxx = $xx+1; 610 } 611 else 612 { 613 if ($tg == 1) 614 { 615 // Ecrase le total groupe si la ligne suivante fait partie du même groupe 616 $tg = 0; 617 } 618 } 619 620 $page2->write_string($xx, 1, $lignetel->code_analytique, $fcode); 621 $page2->write_string($xx, 0, $client->nom, $fclient); 622 623 $total_duree = 0; 624 $total_cout = 0; 625 $total_nb=0; 626 627 $page2->write_string($xx, 2, $lignetel->numero, $fligne); 628 629 /* 630 * Communications 631 */ 632 633 $sql = "SELECT ligne, numero, date, fourn_cout, fourn_montant, duree, tarif_achat_temp, tarif_achat_fixe, tarif_vente_temp, tarif_vente_fixe, cout_achat, cout_vente, remise"; 634 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details as l"; 635 $sql .= " WHERE ligne = '".$lignetel->numero."'"; 636 637 if ($imonth > $month) 638 { 639 $sql .= " AND date_format(date,'%Y') = ".$year; 640 } 641 else 642 { 643 $sql .= " AND date_format(date,'%Y%m') = ".$year.substr("00".$imonth, -2); 644 } 645 $sql .= " ORDER BY date ASC "; 646 647 $result = $db->query($sql); 648 if ($result) 649 { 650 $num = $db->num_rows(); 651 $i = 0; 652 653 while ($i < $num) 654 { 655 $obj = $db->fetch_object(); 656 657 $NumTel = new TelephonieNumero($obj->numero); 658 $type = $NumTel->NumeroType($lignetel->numero); 659 660 /* 661 * Type appel 662 * 663 */ 664 665 if ($type == 'mobile') 666 { 667 $z = ''; 668 $nnum = '0033'.substr($obj->numero, 1); 669 // print $nnum; 670 $tarif_vente->cout($nnum, $x, $y, $z); 671 // print " ".$z."\n"; 672 673 if ($z == 'FRANCE MOBILE SFR') 674 { 675 $type = 'mobile_sfr'; 676 } 677 elseif ($z == 'FRANCE MOBILE ORANGE') 678 { 679 $type = 'mobile_orange'; 680 } 681 elseif ($z == 'FRANCE MOBILE BOUYGUES') 682 { 683 $type = 'mobile_bouygues'; 684 } 685 else 686 { 687 print "ERROR ERROR ERROR ERROR\n"; 688 exit (1); 689 } 690 } 691 692 if (array_key_exists($obj->numero, $numdatas) ) 693 { 694 $data_nb++; 695 $data_duree += $obj->duree; 696 $data_cout += $obj->cout_vente; 697 698 $total_groupe_data_nb++; 699 $total_groupe_data_duree += $obj->duree; 700 $total_groupe_data_cout += $obj->cout_vente; 701 702 $total_global_data_nb++; 703 $total_global_data_duree += $obj->duree; 704 $total_global_data_cout += $obj->cout_vente; 705 } 706 else 707 { 708 if ($type == 'mobile_sfr') 709 { 710 $mobile_sfr_nb++; 711 $mobile_sfr_duree += $obj->duree; 712 $mobile_sfr_cout += $obj->cout_vente; 713 714 $total_groupe_mobile_sfr_nb++; 715 $total_groupe_mobile_sfr_duree += $obj->duree; 716 $total_groupe_mobile_sfr_cout += $obj->cout_vente; 717 718 $total_global_mobile_sfr_nb++; 719 $total_global_mobile_sfr_duree += $obj->duree; 720 $total_global_mobile_sfr_cout += $obj->cout_vente; 721 } 722 elseif ($type == 'mobile_orange') 723 { 724 $mobile_orange_nb++; 725 $mobile_orange_duree += $obj->duree; 726 $mobile_orange_cout += $obj->cout_vente; 727 728 $total_groupe_mobile_orange_nb++; 729 $total_groupe_mobile_orange_duree += $obj->duree; 730 $total_groupe_mobile_orange_cout += $obj->cout_vente; 731 732 $total_global_mobile_orange_nb++; 733 $total_global_mobile_orange_duree += $obj->duree; 734 $total_global_mobile_orange_cout += $obj->cout_vente; 735 } 736 elseif ($type == 'mobile_bouygues') 737 { 738 $mobile_bouygues_nb++; 739 $mobile_bouygues_duree += $obj->duree; 740 $mobile_bouygues_cout += $obj->cout_vente; 741 742 $total_groupe_mobile_bouygues_nb++; 743 $total_groupe_mobile_bouygues_duree += $obj->duree; 744 $total_groupe_mobile_bouygues_cout += $obj->cout_vente; 745 746 $total_global_mobile_bouygues_nb++; 747 $total_global_mobile_bouygues_duree += $obj->duree; 748 $total_global_mobile_bouygues_cout += $obj->cout_vente; 749 } 750 elseif ($type == 'inter') 751 { 752 $inter_nb++; 753 $inter_duree += $obj->duree; 754 $inter_cout += $obj->cout_vente; 755 756 $total_global_inter_nb++; 757 $total_global_inter_duree += $obj->duree; 758 $total_global_inter_cout += $obj->cout_vente; 759 } 760 elseif ($type == 'national') 761 { 762 $national_nb++; 763 $national_duree += $obj->duree; 764 $national_cout += $obj->cout_vente; 765 766 $total_groupe_national_nb++; 767 $total_groupe_national_duree += $obj->duree; 768 $total_groupe_national_cout += $obj->cout_vente; 769 770 $total_global_national_nb++; 771 $total_global_national_duree += $obj->duree; 772 $total_global_national_cout += $obj->cout_vente; 773 } 774 else 775 { 776 print "ERROR ERROR ERROR ERROR\n"; 777 exit (1); 778 } 779 } 780 781 $total_nb++; 782 $total_duree += $obj->duree; 783 $total_cout += $obj->cout_vente; 784 785 $total_groupe_nb++; 786 $total_groupe_duree += $obj->duree; 787 $total_groupe_cout += $obj->cout_vente; 788 789 $total_global_nb++; 790 $total_global_duree += $obj->duree; 791 $total_global_cout += $obj->cout_vente; 792 793 $i++; 794 } 795 } 796 else 797 { 798 print $db->error(); 799 } 800 801 /* 802 $page2->write($xx, 3, $data_nb, $formatc); 803 $page2->write_string($xx, 4, duree_text($data_duree), $fduree); 804 $page2->write($xx, 5, $data_cout, $fcout); 805 */ 806 807 /* Local / National */ 808 809 $page2->write($xx, 3, $national_nb, $fnb); 810 $page2->write_string($xx, 4, duree_text($national_duree), $fduree); 811 $page2->write($xx, 5, $national_cout, $fcout); 812 813 /* Mobile SFR + Mobile Orange */ 814 815 $page2->write($xx, 6, ($mobile_sfr_nb + $mobile_orange_nb), $fnb); 816 $page2->write_string($xx, 7, duree_text($mobile_sfr_duree + $mobile_orange_duree), $fduree); 817 $page2->write($xx, 8, ($mobile_sfr_cout+$mobile_orange_cout), $fcout); 818 819 /* Mobile Bouygues */ 820 821 $page2->write($xx, 9, $mobile_bouygues_nb, $fnb); 822 $page2->write_string($xx, 10, duree_text($mobile_bouygues_duree), $fduree); 823 $page2->write($xx, 11, $mobile_bouygues_cout, $fcout); 824 825 /* Data */ 826 827 $page2->write($xx, 12, $data_nb, $fnb); 828 $page2->write_string($xx, 13, duree_text($data_duree), $fduree); 829 $page2->write($xx, 14, $data_cout, $fcout); 830 831 /* Totaux */ 832 $tl_nb = $national_nb + $mobile_sfr_nb + $mobile_orange_nb + $mobile_bouygues_nb + $data_nb; 833 $tl_cout = $national_cout + $mobile_sfr_cout + $mobile_orange_cout + $mobile_bouygues_cout + $data_cout; 834 $tl_duree = $national_duree + $mobile_sfr_duree + $mobile_orange_duree + $mobile_bouygues_duree + $data_duree; 835 836 $str ="=D".($xx+1)."+G".($xx+1)."+J".($xx+1)."+M".($xx+1); 837 838 $page2->write_formula($xx, 15, $str , $fnb); 839 $page2->write_string($xx, 16, duree_text($tl_duree), $fduree); 840 841 $str ="=F".($xx+1)."+I".($xx+1)."+L".($xx+1)."+O".($xx+1); 842 843 $page2->write($xx, 17, $str, $fcout); 844 845 if ($tl_duree > 0) 846 { 847 $page2->write($xx, 18, round(($tl_cout/$tl_duree),4), $fmoy); 848 } 849 else 850 { 851 $page2->write($xx, 18, 0, $fmoy); 852 } 853 854 /* 855 $page2->write($xx, 3, $inter_nb, $formatc); 856 $page2->write_string($xx, 4, duree_text($inter_duree), $fduree); 857 $page2->write($xx, 5, $inter_cout, $fcout); 858 */ 859 860 861 /* 862 $page2->write($xx, 3, $total_nb, $ftotal); 863 $page2->write_string($xx, 4, duree_text($total_duree), $fdureeBold); 864 $page2->write($xx, 5, $total_cout, $fcoutBold); 865 */ 866 867 $xx++; 868 $fksoc++; 869 } // Fin de la boucle des lignes 870 /* 871 $page2->write_string($xx, 0, 'Total', $format_titre_total1); 872 $page2->write_blank($xx, 1, $format_titre_total2); 873 $page2->write_blank($xx, 2, $format_titre_total3); 874 875 $page2->write($xx, 3, $total_groupe_national_nb, $fnb); 876 $page2->write_string($xx, 4, duree_text($total_groupe_national_duree), $fduree); 877 $page2->write($xx, 5, $total_groupe_national_cout, $fcout); 878 879 880 $page2->write($xx, 6, ($total_groupe_mobile_sfr_nb + $total_groupe_mobile_orange_nb), $fnb); 881 $page2->write_string($xx, 7, duree_text(($total_groupe_mobile_sfr_duree + $total_groupe_mobile_orange_duree)), $fduree); 882 883 $page2->write($xx, 8, ($total_groupe_mobile_sfr_cout + $total_groupe_mobile_orange_cout), $fcout); 884 885 886 $page2->write($xx, 9, $total_groupe_mobile_bouygues_nb, $fnb); 887 $page2->write_string($xx, 10, duree_text($total_groupe_mobile_bouygues_duree ), $fduree); 888 889 $page2->write($xx, 11, $total_groupe_mobile_bouygues_cout, $fcout); 890 891 892 $page2->write($xx, 12, $total_groupe_data_nb, $fnb); 893 $page2->write_string($xx, 13, duree_text($total_groupe_data_duree), $fduree); 894 $page2->write($xx, 14, $total_groupe_data_cout, $fcout); 895 896 897 $tlg_nb = $total_groupe_national_nb + $total_groupe_mobile_sfr_nb + $total_groupe_mobile_orange_nb + $total_groupe_mobile_bouygues_nb + $total_groupe_data_nb; 898 899 $tlg_duree = $total_groupe_national_duree + $total_groupe_mobile_sfr_duree + $total_groupe_mobile_orange_duree + $total_groupe_mobile_bouygues_duree + $total_groupe_data_duree; 900 901 $tlg_cout = $total_groupe_national_cout + $total_groupe_mobile_sfr_cout + $total_groupe_mobile_orange_cout + $total_groupe_mobile_bouygues_cout + $total_groupe_data_cout; 902 903 $page2->write($xx, 19, $tlg_nb, $fnb); 904 $page2->write_string($xx, 20, duree_text($tlg_duree), $fduree); 905 $page2->write($xx, 21, $tlg_cout, $fcout); 906 $page2->write($xx, 22, ($tlg_cout/$tlg_duree), $fmoy); 907 908 */ 909 910 /******************************/ 911 912 $page2->write_string($xx, 0, 'Total', $format_titre_total1); 913 $page2->write_blank($xx, 1, $format_titre_total2); 914 $page2->write_blank($xx, 2, $format_titre_total3); 915 916 $str = '=SUM(D'.$oldxx.':D'.($xx).')'; 917 $page2->write_formula($xx, 3, $str, $fnb); 918 919 //$page2->write($xx, 3, $total_groupe_national_nb, $fnb); 920 $page2->write_string($xx, 4, duree_text($total_groupe_national_duree), $fduree); 921 922 $str = '=SUM(F'.$oldxx.':F'.($xx).')'; 923 $page2->write_formula($xx, 5, $str, $fcout); 924 925 $str = '=SUM(G'.$oldxx.':G'.($xx).')'; 926 $page2->write_formula($xx, 6, $str, $fnb); 927 928 $page2->write_string($xx, 7, duree_text(($total_groupe_mobile_sfr_duree + $total_groupe_mobile_orange_duree)), $fduree); 929 930 931 $str = '=SUM(I'.$oldxx.':I'.($xx).')'; 932 $page2->write_formula($xx, 8, $str, $fcout); 933 934 $str = '=SUM(J'.$oldxx.':J'.($xx).')'; 935 $page2->write_formula($xx, 9, $str, $fnb); 936 937 $page2->write_string($xx, 10, duree_text($total_groupe_mobile_bouygues_duree), $fduree); 938 939 $str = '=SUM(L'.$oldxx.':L'.($xx).')'; 940 $page2->write_formula($xx, 11, $str, $fcout); 941 942 $str = '=SUM(M'.$oldxx.':M'.($xx).')'; 943 $page2->write_formula($xx, 12, $str, $fnb); 944 945 $page2->write_string($xx, 13, duree_text($total_groupe_data_duree), $fduree); 946 947 $str = '=SUM(O'.$oldxx.':O'.($xx).')'; 948 $page2->write_formula($xx, 14, $str, $fcout); 949 950 $tlg_nb = $total_groupe_national_nb + $total_groupe_mobile_sfr_nb + $total_groupe_mobile_orange_nb + $total_groupe_mobile_bouygues_nb + $total_groupe_data_nb; 951 952 $tlg_duree = $total_groupe_national_duree + $total_groupe_mobile_sfr_duree + $total_groupe_mobile_orange_duree + $total_groupe_mobile_bouygues_duree + $total_groupe_data_duree; 953 954 $tlg_cout = $total_groupe_national_cout + $total_groupe_mobile_sfr_cout + $total_groupe_mobile_orange_cout + $total_groupe_mobile_bouygues_cout + $total_groupe_data_cout; 955 956 $str ="=D".($xx+1)."+G".($xx+1)."+J".($xx+1)."+M".($xx+1); 957 958 $page2->write_formula($xx, 15, $str, $fnb); 959 $page2->write_string($xx, 16, duree_text($tlg_duree), $fduree); 960 $str ="=F".($xx+1)."+I".($xx+1)."+L".($xx+1)."+O".($xx+1); 961 $page2->write_formula($xx, 17, $str, $fcout); 962 963 if ($tlg_duree > 0) 964 { 965 $page2->write($xx, 18, round(($tlg_cout/$tlg_duree),4), $fmoy); 966 } 967 else 968 { 969 $page2->write($xx, 18, 0, $fmoy); 970 } 971 972 973 974 /********************************/ 975 976 977 $tg = 0; 978 $total_groupe_duree = 0; 979 $total_groupe_nb = 0; 980 $total_groupe_cout = 0; 981 982 $total_groupe_national_nb = 0; 983 $total_groupe_national_duree = 0; 984 $total_groupe_national_cout = 0; 985 986 $total_groupe_mobile_sfr_nb = 0; 987 $total_groupe_mobile_sfr_duree = 0; 988 $total_groupe_mobile_sfr_cout = 0; 989 990 $total_groupe_mobile_orange_nb = 0; 991 $total_groupe_mobile_orange_duree = 0; 992 $total_groupe_mobile_orange_cout = 0; 993 994 $total_groupe_mobile_bouygues_nb = 0; 995 $total_groupe_mobile_bouygues_duree = 0; 996 $total_groupe_mobile_bouygues_cout = 0; 997 998 $total_groupe_data_nb = 0; 999 $total_groupe_data_duree = 0; 1000 $total_groupe_data_cout = 0; 1001 1002 $oldfk_soc = $lignetel->client_facture_id; 1003 $xx++; 1004 1005 } 1006 1007 $workbook->close(); 1008 dolibarr_syslog("Close $fname"); 1009 1010 } 1011 1012 function duree_text($duree) 1013 { 1014 $h = floor($duree / 3600); 1015 $m = floor(($duree - ($h * 3600)) / 60); 1016 $s = ($duree - ( ($h * 3600 ) + ($m * 60) ) ); 1017 1018 if ($h > 0) 1019 { 1020 $dt = $h . " h " . $m ." min " . $s ." sec" ; 1021 } 1022 else 1023 { 1024 if ($m > 0) 1025 { 1026 $dt = $m ." min " . $s ." sec" ; 1027 } 1028 else 1029 { 1030 $dt = $s ." sec" ; 1031 } 1032 } 1033 1034 1035 return $h.":".substr("00".$m, -2).":".substr("00".$s,-2); 1036 } 1037 1038 ?>
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 |
|