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


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