[ 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/pdf/ -> pdfdetail_nodet.modules.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   * or see http://www.gnu.org/
  18   *
  19   * $Id: pdfdetail_nodet.modules.php,v 1.7 2005/11/24 12:55:57 rodolphe Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/pdf/pdfdetail_nodet.modules.php,v $
  21   *
  22   * Génère un PDF de la première page de résumé et un tableur des communications
  23   */
  24  
  25  require_once DOL_DOCUMENT_ROOT."/facture.class.php";
  26  require_once DOL_DOCUMENT_ROOT."/telephonie/facturetel.class.php";
  27  require_once DOL_DOCUMENT_ROOT."/telephonie/pdf/pdfdetail_standard.modeles.php";
  28  require_once DOL_DOCUMENT_ROOT."/telephonie/pdf/xlsdetail_nodet.modules.php";
  29  
  30  
  31  class pdfdetail_nodet {
  32  
  33    function pdfdetail_nodet ($db=0, $ligne, $year, $month, $factel)
  34      { 
  35        $this->db = $db;
  36        $this->description = "Modèle de facture détaillée sans les communications";
  37        $this->ligne = $ligne;
  38        $this->year  = $year;
  39        $this->month = $month;
  40        $this->factel = $factel;
  41      }
  42  
  43    /*
  44     *
  45     *
  46     */
  47    function write_pdf_file($factel, $ligne)
  48    {
  49      $xpdf = 0;
  50      $this->_write_pdf_file($factel, $ligne, $xpdf, 0);
  51    }
  52  
  53    function _write_pdf_file($factel, $ligne, &$pdf, $output)
  54      {
  55        $fac = new Facture($this->db,"",$factel->fk_facture);
  56        $fac->fetch($factel->fk_facture);  
  57        $fac->fetch_client();
  58  
  59        $objlignetel = new LigneTel($this->db);
  60  
  61        $result = $objlignetel->fetch($ligne);
  62  
  63        if (defined("FAC_OUTPUTDIR"))
  64      {
  65        $dir  = FAC_OUTPUTDIR . "/" . $fac->ref . "/" ;
  66        $file = $dir . $fac->ref . "-$ligne-detail.pdf";
  67  
  68        if (strlen($objlignetel->code_analytique) > 0)
  69          {
  70            $file = $dir . $fac->ref . "-$ligne-$objlignetel->code_analytique-detail.pdf";
  71          }
  72        
  73        if (! file_exists($dir))
  74          {
  75            umask(0);
  76            if (! mkdir($dir, 0755))
  77          {
  78            $this->error="Erreur: Le répertoire '$dir' n'existe pas et Dolibarr n'a pu le créer.";
  79            return 0;
  80          }
  81          }
  82  
  83        if (file_exists($dir) OR $output)
  84          {
  85            if ($output == 0)
  86          {
  87            $pdf = new pdfdetail_standard_modeles('P','mm','A4');
  88          }
  89  
  90            $pdf->fac = $fac;
  91  
  92            $pdf->factel = $this->factel;
  93  
  94            $pdf->client_nom     = $fac->client->nom; 
  95            $pdf->client_adresse = $fac->client->adresse;
  96            $pdf->client_cp      = $fac->client->cp;
  97            $pdf->client_ville   = $fac->client->ville;
  98  
  99            $pdf->ligne = $ligne;
 100  
 101            $pdf->year  = $this->year;
 102            $pdf->month = $this->month;
 103  
 104            $pdf->ligne_ville = '';
 105            if ($objlignetel->code_analytique)
 106          {
 107            $soca = new Societe($this->db);
 108            $soca->fetch($objlignetel->client_id);
 109  
 110            $pdf->ligne = $ligne . " (".$objlignetel->code_analytique.")";
 111            $pdf->ligne_ville = $soca->ville;
 112          }
 113  
 114            $pdf->AliasNbPages();
 115            if ($output == 0)
 116          {
 117            $pdf->Open();
 118  
 119            $pdf->SetTitle($fac->ref);
 120            $pdf->SetSubject("Facture détaillée");
 121            $pdf->SetCreator("Dolibarr");
 122            $pdf->SetAuthor("");
 123            
 124            $pdf->SetMargins(10, 10, 10);
 125          }
 126                $pdf->SetAutoPageBreak(1, 24);
 127            $pdf->SetLineWidth(0.1);
 128  
 129            $pdf->tab_top = 53;
 130            $pdf->tab_height = 222;
 131  
 132            /*
 133             *
 134             */
 135            $pdf->FirstPage = 1;
 136            $pdf->AddPage();
 137            $this->Header($pdf, $output);
 138  
 139            $pdf->SetFillColor(230,230,230);
 140            /*
 141             * Détails des comm
 142             *
 143             */
 144  
 145            $pdf->SetFont('Arial','', 12);
 146            
 147            $Y = $pdf->tab_top + 4;
 148            $pdf->SetXY(10, $Y);
 149            $pdf->MultiCell(100, 4, "Détails de vos communications", 0,'L',0);
 150  
 151            $pdf->SetFont('Arial','', 9);
 152  
 153            $Y = $pdf->GetY();
 154  
 155            $pdf->SetXY(140, $Y);
 156            $pdf->MultiCell(20, 4, "Durée", 0,'R',0);
 157  
 158            $pdf->SetXY(160, $Y);
 159            $pdf->MultiCell(20, 4, "Nb appels", 0,'R',0);
 160  
 161            $pdf->SetXY(180, $Y);
 162            $pdf->MultiCell(20, 4, "Coût", 0,'R',0);
 163  
 164            $sql = "SELECT count(*) as cc, sum(t.cout_vente) as cout_vente, sum(t.duree) as duree, t.dest";
 165            $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details as t ";
 166            $sql .= " WHERE t.fk_telephonie_facture =".$factel->id;
 167            $sql .= " GROUP BY t.dest";
 168            $sql .= " ORDER BY cout_vente DESC";
 169            $sql .= " LIMIT 10";
 170  
 171            $resql = $this->db->query($sql);
 172  
 173            $total_duree = 0;
 174            $total_nb = 0;
 175            $total_cout = 0;
 176  
 177            if ( $resql )
 178          {
 179            $num = $this->db->num_rows($resql);
 180            $i = 0;
 181  
 182            $pdf->SetFont('Arial','', 9);          
 183            $var = 0;
 184            $line_height = 4;
 185  
 186            $graph_values = array();
 187            $graph_values_duree = array();
 188            $graph_labels = array();
 189  
 190            while ($i < $num)
 191              {
 192                $obj = $this->db->fetch_object($i);
 193                $var=!$var;
 194          
 195                $Y = $pdf->GetY();
 196        
 197                $pdf->SetXY(10, $Y);
 198                $pdf->MultiCell(100, $line_height, $obj->dest, 0,'L',$var);
 199  
 200                if ($Y > $pdf->GetY())
 201              $Y = $pdf->GetY() - $line_height;
 202  
 203  
 204                $h = floor($obj->duree / 3600);
 205                $m = floor(($obj->duree - ($h * 3600)) / 60);
 206                $s = ($obj->duree - ( ($h * 3600 ) + ($m * 60) ) );
 207  
 208                if ($h > 0)
 209              {
 210                $dt = $h . " h " . $m ." min " . $s ." sec" ; 
 211              }
 212                else
 213              {
 214                if ($m > 0)
 215                  {
 216                    $dt = $m ." min " . $s ." sec" ; 
 217                  }
 218                else
 219                  {
 220                    $dt =  $s ." sec" ; 
 221                  }
 222              }
 223                
 224                $pdf->SetXY(110, $Y);
 225                $pdf->MultiCell(50, $line_height,$dt, 0,'R',$var);
 226                
 227                $pdf->SetXY(160, $Y);
 228                $pdf->MultiCell(20, $line_height,$obj->cc, 0,'R',$var);
 229  
 230                $pdf->SetXY(180, $Y);
 231                $pdf->MultiCell(20, $line_height,sprintf("%01.3f",$obj->cout_vente), 0,'R',$var);
 232  
 233                array_push($graph_values, $obj->cc);
 234                array_push($graph_values_duree, $obj->duree);
 235                array_push($graph_labels, $obj->dest);
 236  
 237                $total_duree = $total_duree + $obj->duree;
 238                $total_nb = $total_nb + $obj->cc;
 239                $total_cout = $total_cout + $obj->cout_vente;
 240  
 241                $i++;
 242              }
 243          }
 244            else
 245          {
 246            dolibarr_syslog("Erreur SQl");
 247            dolibarr_syslog($this->db->error());
 248          }
 249  
 250            $h = floor($total_duree / 3600);
 251            $m = floor(($total_duree - ($h * 3600)) / 60);
 252            $s = ($total_duree - ( ($h * 3600 ) + ($m * 60) ) );
 253            
 254            if ($h > 0)
 255          {
 256            $dt = $h . " h " . $m ." min " . $s ." sec" ; 
 257          }
 258            else
 259          {
 260            if ($m > 0)
 261              {
 262                $dt = $m ." min " . $s ." sec" ; 
 263              }
 264            else
 265              {
 266                $dt =  $s ." sec" ; 
 267              }
 268          }
 269            
 270            $var=!$var;
 271  
 272            $pdf->SetXY(10, $Y + $line_height);
 273            $pdf->MultiCell(100, $line_height,"Total : ", 0,'R',$var);
 274  
 275            $pdf->SetXY(110, $Y + $line_height);
 276            $pdf->MultiCell(50, $line_height,$dt, 0,'R',$var);
 277  
 278            $pdf->SetXY(160, $Y + $line_height);
 279            $pdf->MultiCell(20, $line_height,$total_nb, 0,'R',$var);
 280            
 281            $pdf->SetXY(180, $Y + $line_height);
 282            $pdf->MultiCell(20, $line_height,sprintf("%01.3f",$total_cout), 0,'R',$var);
 283  
 284  
 285            /*
 286             * Appels les plus important
 287             *
 288             */
 289  
 290            $pdf->SetFont('Arial','', 12);
 291            
 292            $Y = $pdf->GetY() + 10;
 293            $pdf->SetXY(10, $Y);
 294            $pdf->MultiCell(100, 4, "TOP 10 des numéros appelés en coût", 0,'L',0);
 295  
 296            $pdf->SetFont('Arial','', 9);
 297  
 298            $Y = $pdf->GetY();
 299            $pdf->SetXY(10, $Y);
 300            $pdf->MultiCell(150, 4, "Destination", 0,'L',0);
 301  
 302            $pdf->SetXY(140, $Y);
 303            $pdf->MultiCell(20, 4, "Durée", 0,'R',0);
 304  
 305            $pdf->SetXY(160, $Y);
 306            $pdf->MultiCell(20, 4, "Nb appels", 0,'R',0);
 307  
 308            $pdf->SetXY(180, $Y);
 309            $pdf->MultiCell(20, 4, "Coût", 0,'R',0);
 310  
 311            $sql = "SELECT count(*) as cc, sum(t.cout_vente) as cout_vente, sum(t.duree) as duree, t.numero, t.dest";
 312            $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details as t ";
 313            $sql .= " WHERE fk_telephonie_facture =".$factel->id;
 314            $sql .= " GROUP BY t.numero";
 315            $sql .= " ORDER BY cout_vente DESC";
 316            $sql .= " LIMIT 10";
 317  
 318            if ( $this->db->query($sql) )
 319          {
 320            $num = $this->db->num_rows();
 321  
 322            $pdf->SetFont('Arial','', 9);
 323            
 324            $i = 0;
 325            $var = 0;
 326            $line_height = 4;
 327  
 328            while ($i < $num)
 329              {
 330                $obj = $this->db->fetch_object($i);
 331                $var=!$var;
 332          
 333                $Y = $pdf->GetY();
 334        
 335                $pdf->SetXY(10, $Y);
 336                $pdf->MultiCell(80, $line_height, $obj->dest, 0,'L',$var);
 337  
 338                if ($Y > $pdf->GetY())
 339              $Y = $pdf->GetY() - $line_height;
 340  
 341                $pdf->SetXY(90, $Y);
 342                $pdf->MultiCell(30, $line_height, $obj->numero, 0,'L',$var);
 343  
 344                $h = floor($obj->duree / 3600);
 345                $m = floor(($obj->duree - ($h * 3600)) / 60);
 346                $s = ($obj->duree - ( ($h * 3600 ) + ($m * 60) ) );
 347  
 348                if ($h > 0)
 349              {
 350                $dt = $h . " h " . $m ." min " . $s ." sec" ; 
 351              }
 352                else
 353              {
 354                if ($m > 0)
 355                  {
 356                    $dt = $m ." min " . $s ." sec" ; 
 357                  }
 358                else
 359                  {
 360                    $dt =  $s ." sec" ; 
 361                  }
 362              }
 363  
 364                $pdf->SetXY(120, $Y);
 365                $pdf->MultiCell(40, $line_height,$dt, 0,'R',$var);
 366  
 367                $pdf->SetXY(160, $Y);
 368                $pdf->MultiCell(20, $line_height,$obj->cc, 0,'R',$var);
 369  
 370                $pdf->SetXY(180, $Y);
 371                $pdf->MultiCell(20, $line_height,sprintf("%01.3f",$obj->cout_vente), 0,'R',$var);
 372  
 373                $i++;
 374              }
 375          }
 376            /*
 377             *
 378             *
 379             */
 380            include_once ("/usr/share/jpgraph/jpgraph.php");
 381            include_once ("/usr/share/jpgraph/jpgraph_pie.php");
 382  
 383            $graph = new PieGraph(450,200,"auto");
 384            $graph->img->SetImgFormat("jpeg");
 385            $graph->SetFrame(false);
 386  
 387            // Setup title
 388            $graph->title->Set("Répartition des destinations en nombre d'appel");
 389            $graph->title->SetFont(FF_FONT1,FS_BOLD);
 390            
 391            $p1 = new PiePlot($graph_values);
 392            $p1->SetCenter(0.25,0.5);
 393            
 394            // Label font and color setup
 395            $p1->SetFont(FF_FONT1,FS_BOLD);
 396            $p1->SetFontColor("darkred");
 397            $p1->SetSize(0.3);          
 398            $p1->SetLegends($graph_labels);
 399            $graph->legend->Pos(0.05,0.15);
 400            
 401            $graph->Add($p1);
 402  
 403            $file_graph = "/tmp/graph".$factel->ligne.".jpg";
 404  
 405            $handle = $graph->Stroke($file_graph);
 406  
 407            $pdf->Image($file_graph, 11, ($pdf->GetY() + 10), 0, 0, 'JPG');
 408  
 409            /*
 410             *
 411             */
 412            if ($output == 0)
 413          {
 414            $pdf->Close();          
 415            $pdf->Output($file);
 416            dolibarr_syslog("Write $file");
 417          }
 418            $this->filename = $file;
 419  
 420  
 421            if(file_exists($file_graph))
 422          {
 423            unlink($file_graph);
 424          }
 425  
 426            if ($output == 0)
 427          {
 428            /* Génération du tableur */
 429            $xlsdet = new xlsdetail_nodet($this->db);
 430            $xlsdet->GenerateFile($objlignetel, $fac, $factel);
 431          }
 432            return 0;
 433          }
 434        else
 435          {
 436            $this->error="Erreur: Le répertoire '$dir' n'existe pas et Dolibarr n'a pu le créer.";
 437            return -1;
 438          }
 439      }
 440        else
 441      {
 442              $this->error="Erreur: FAC_OUTPUTDIR non défini !";
 443              return -2;
 444      }
 445      }
 446  
 447  
 448  
 449  
 450    /*
 451     * Header
 452     */
 453  
 454    function Header(&$pdf, $output)
 455    {
 456      $pdf->SetXY(10,5);
 457      
 458      // 400x186
 459  
 460      $logo_file = DOL_DOCUMENT_ROOT."/../documents/logo.jpg";
 461  
 462      if (file_exists($logo_file))
 463      {
 464        $pdf->Image($logo_file, 10, 5, 60, 27.9, 'JPG');
 465      }
 466  
 467      $pdf->SetTextColor(0,90,200);
 468      $pdf->SetFont('Arial','',10);
 469      $pdf->SetXY(11,31);
 470      $pdf->MultiCell(89, 4, "Facture détaillée : ".$pdf->fac->ref);
 471  
 472      $pdf->SetX(11);
 473      $pdf->MultiCell(89, 4, "Ligne : " . $pdf->ligne);
 474  
 475      $pdf->SetX(11);
 476  
 477      $libelle = "Du ".strftime("%d/%m/%Y",$pdf->factel->get_comm_min_date($pdf->year.$pdf->month));
 478      $libelle .= " au ".strftime("%d/%m/%Y",$pdf->factel->get_comm_max_date($pdf->year.$pdf->month));
 479      $pdf->MultiCell(89, 4, $libelle, 0);
 480  
 481      $pdf->SetX(11);
 482      if ($output == 0)
 483        {
 484      $pdf->MultiCell(80, 4, "Page : ". $pdf->PageNo() ."/{nb}", 0);
 485        }
 486  
 487      // Clients spéciaux
 488  
 489      if ($pdf->ligne_ville)
 490        {
 491      $pdf->SetX(11);
 492      $pdf->MultiCell(80, 4, "Agence : ". $pdf->ligne_ville, 0);
 493        }
 494  
 495      $pdf->rect(10, 30, 95, 23);
 496      
 497      $pdf->SetTextColor(0,0,0);
 498      $pdf->SetFont('Arial','',10);
 499  
 500      $pdf->SetXY(107, 31);
 501  
 502      $pdf->MultiCell(66,4, $pdf->client_nom);
 503  
 504      $pdf->SetX(107);
 505      $pdf->MultiCell(86,4, $pdf->client_adresse . "\n" . $pdf->client_cp . " " . $pdf->client_ville);
 506  
 507      $pdf->rect(105, 30, 95, 23);
 508  
 509      /*
 510       * On positionne le curseur pour la liste
 511       */        
 512      $pdf->SetXY(10,$pdf->tab_top + 6);
 513      $pdf->colonne = 1;
 514      $pdf->inc = 0;
 515    }
 516  
 517    /* 
 518     * Footer
 519     */
 520  
 521    function Footer(&$pdf)
 522    {
 523  
 524      if ($pdf->FirstPage == 1)
 525        {
 526      $pdf->FirstPage = 0;
 527        }
 528      else
 529        {
 530  
 531      $pdf->SetFont('Arial','',8);
 532      
 533      $pdf->Text(11, $pdf->tab_top + 3,'Date');
 534      $pdf->Text(106, $pdf->tab_top + 3,'Date');
 535      
 536      $w = 33;
 537      
 538      $pdf->Text($w+1, $pdf->tab_top + 3,'Numéro');
 539      $pdf->Text($w+96, $pdf->tab_top + 3,'Numéro');
 540      
 541      $w = 47;
 542      
 543      $pdf->Text($w+1, $pdf->tab_top + 3,'Destination');
 544      $pdf->Text($w+96, $pdf->tab_top + 3,'Destination');
 545      
 546      $w = 86;
 547      
 548      $pdf->Text($w+1, $pdf->tab_top + 3,'Durée');
 549      $pdf->Text($w+96, $pdf->tab_top + 3,'Durée');
 550      
 551      $w = 98;
 552      
 553      $pdf->Text($w+1, $pdf->tab_top + 3,'HT');
 554      $pdf->Text($w+96, $pdf->tab_top + 3,'HT');
 555      
 556      $pdf->line(10, $pdf->tab_top + 4, 200, $pdf->tab_top + 4 );
 557  
 558      /* Ligne Médiane */
 559  
 560      $pdf->line(105, $pdf->tab_top, 105, $pdf->tab_top + $pdf->tab_height);
 561      
 562        }
 563  
 564      $pdf->Rect(10, $pdf->tab_top, 190, $pdf->tab_height);
 565  
 566    }
 567  
 568  
 569  
 570  
 571  
 572  
 573  
 574  
 575  }
 576  ?>


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