[ 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_papier.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_papier.modules.php,v 1.2 2005/11/29 13:17:42 rodolphe Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/pdf/pdfdetail_papier.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  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  require_once DOL_DOCUMENT_ROOT."/telephonie/pdf/xlsdetail_nodet.modules.php";
  28  
  29  
  30  class pdfdetail_papier {
  31  
  32    function pdfdetail_papier ($db=0, $ligne, $year, $month, $factel)
  33      { 
  34        $this->db = $db;
  35        $this->description = "Modèle de facture détaillée sans les communications";
  36        $this->ligne = $ligne;
  37        $this->year  = $year;
  38        $this->month = $month;
  39        $this->factel = $factel;
  40      }
  41  
  42    /*
  43     *
  44     *
  45     */
  46    function write_pdf_file($factel, $ligne)
  47    {
  48      $xpdf = 0;
  49      $this->_write_pdf_file($factel, $ligne, $xpdf, 0);
  50    }
  51  
  52    function _write_pdf_file($factel, $ligne, &$pdf, $output)
  53      {
  54        $fac = new Facture($this->db,"",$factel->fk_facture);
  55        $fac->fetch($factel->fk_facture);  
  56        $fac->fetch_client();
  57  
  58        $objlignetel = new LigneTel($this->db);
  59  
  60        $result = $objlignetel->fetch($ligne);
  61  
  62        if (defined("FAC_OUTPUTDIR"))
  63      {
  64        $dir  = FAC_OUTPUTDIR . "/" . $fac->ref . "/" ;
  65        $file = $dir . $fac->ref . "-$ligne-detail.pdf";
  66  
  67        if (strlen($objlignetel->code_analytique) > 0)
  68          {
  69            $file = $dir . $fac->ref . "-$ligne-$objlignetel->code_analytique-detail.pdf";
  70          }
  71        
  72        if (! file_exists($dir))
  73          {
  74            umask(0);
  75            if (! mkdir($dir, 0755))
  76          {
  77            $this->error="Erreur: Le répertoire '$dir' n'existe pas et Dolibarr n'a pu le créer.";
  78            return 0;
  79          }
  80          }
  81  
  82        if (file_exists($dir) OR $output)
  83          {
  84            if ($output == 0)
  85          {
  86            $pdf = new pdfdetail_standard_modeles('P','mm','A4');
  87          }
  88  
  89            $pdf->fac = $fac;
  90            $pdf->factel = $factel;
  91  
  92            $pdf->client_nom     = $fac->client->nom; 
  93            $pdf->client_adresse = $fac->client->adresse;
  94            $pdf->client_cp      = $fac->client->cp;
  95            $pdf->client_ville   = $fac->client->ville;
  96  
  97            $pdf->ligne = $ligne;
  98            $pdf->year  = $this->year;
  99            $pdf->month = $this->month;
 100  
 101            $pdf->ligne_ville = '';
 102            if ($objlignetel->code_analytique)
 103          {
 104            $soca = new Societe($this->db);
 105            $soca->fetch($objlignetel->client_id);
 106  
 107            $pdf->ligne = $ligne . " (".$objlignetel->code_analytique.")";
 108            $pdf->ligne_ville = $soca->ville;
 109          }
 110  
 111                $pdf->SetAutoPageBreak(0, 24);
 112            $pdf->SetLineWidth(0.1);
 113            $pdf->tab_top = 20;
 114            $pdf->tab_height = 222;
 115            $pdf->FirstPage = 1;
 116            /*
 117             * Libelle
 118             */
 119            
 120            $pdf->libelle = "Du ".strftime("%d/%m/%Y",$factel->get_comm_min_date($this->year.$this->month));
 121            $pdf->libelle .= " au ".strftime("%d/%m/%Y",$factel->get_comm_max_date($this->year.$this->month));
 122  
 123  
 124            /*
 125             * Liste des appels
 126             *
 127             */
 128            $sql = "SELECT t.ligne, ".$this->db->pdate("t.date")." as pdate";
 129            $sql .= " , t.numero, t.dest, t.duree, t.cout_vente";
 130            $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_communications_details as t ";
 131            $sql .= " WHERE fk_telephonie_facture =".$factel->id;
 132            $sql .= " ORDER BY t.date ASC";
 133      
 134            $resql = $this->db->query($sql) ;
 135  
 136            if ( $resql )
 137          {
 138            $num = $this->db->num_rows($resql);
 139  
 140            $pdf->AddPage();
 141            $this->ListHeader($pdf);
 142            $i = 0;
 143            $var = 1;
 144            $line_height = 2;
 145            $this->colonne = 1;
 146  
 147            while ($i < $num)
 148              {
 149                $obj = $this->db->fetch_object($resql);
 150                $Y = $pdf->GetY();
 151          
 152                if ($this->inc > 130 && $this->colonne == 1)
 153              {
 154                $col = 95;
 155                $Y = $pdf->tab_top + 6;
 156                $this->inc = 0;
 157                $this->colonne = 2;
 158                $old_dest='';
 159                $old_date='';
 160              }
 161  
 162                if ($this->inc > 130 && $this->colonne == 2)
 163              {
 164                $pdf->AddPage();
 165                $this->ListHeader($pdf);
 166                $var = 0;
 167                $col = 0;
 168                $Y = $pdf->tab_top + 6;
 169                $this->inc = 0;
 170                $old_dest='';
 171                $old_date='';
 172                $this->colonne = 1;
 173              }
 174  
 175                $var=!$var;
 176  
 177                $pdf->SetFont('Arial','', 6);
 178  
 179                $pdf->SetXY (10 + $col, $Y);
 180  
 181                if ($old_date == strftime("%d/%m/%Y", $obj->pdate))
 182              {
 183                $date = "";
 184              }
 185                else
 186              {
 187                $old_date = strftime("%d/%m/%Y", $obj->pdate) ;
 188                $date = strftime("%d/%m/%y",$obj->pdate);
 189              }
 190  
 191                $pdf->MultiCell(11, $line_height, $date, 0,'L',$var);
 192  
 193                if ($Y > $pdf->GetY())
 194              $Y = $pdf->GetY() - $line_height;
 195  
 196                $pdf->SetXY (21 + $col, $Y);
 197                $heure = strftime("%H:%M:%S",$obj->pdate);
 198                $pdf->MultiCell(11, $line_height, $heure, 0,'L',$var);
 199  
 200                $pdf->SetXY (32 + $col, $Y);
 201                $numero = ereg_replace("^00","",$obj->numero);
 202                $pdf->MultiCell(17, $line_height, $numero, 0,'L',$var);
 203  
 204                $pdf->SetXY (48 + $col, $Y);
 205  
 206                if ($obj->dest == $old_dest)
 207              {
 208                $dest = ' "';
 209              }
 210                else
 211              {
 212                $old_dest = $obj->dest ;
 213                $dest = $obj->dest;
 214              }
 215  
 216                $pdf->MultiCell(37, $line_height, $dest, 0, 'L',$var);
 217  
 218                $pdf->SetXY (85 + $col, $Y);
 219                $pdf->MultiCell(10, $line_height, $obj->duree, 0, 'R',$var);
 220  
 221                $pdf->SetXY (95 + $col, $Y);
 222                $pdf->MultiCell(10, $line_height, sprintf("%01.3f", $obj->cout_vente), 0,'R',$var);
 223  
 224                $i++;
 225                $this->inc++;
 226              }
 227          }
 228            else
 229          {
 230            dolibarr_syslog("Erreur lecture des communications");
 231          }
 232  
 233            /*
 234             *
 235             */
 236  
 237  
 238            return 0;
 239          }
 240        else
 241          {
 242            $this->error="Erreur: Le répertoire '$dir' n'existe pas et Dolibarr n'a pu le créer.";
 243            return -1;
 244          }
 245      }
 246        else
 247      {
 248              $this->error="Erreur: FAC_OUTPUTDIR non défini !";
 249              return -2;
 250      }
 251      }
 252  
 253    /*
 254     * Header
 255     */
 256  
 257    function Header(&$pdf, $output)
 258    {
 259      $pdf->SetXY(10,5);
 260      $pdf->SetTextColor(0,90,200);
 261      $pdf->SetFont('Arial','',10);
 262      $pdf->SetXY(11,31);
 263      $pdf->MultiCell(89, 4, "Facture détaillée : ".$pdf->fac->ref);
 264  
 265      $pdf->SetX(11);
 266      $pdf->MultiCell(89, 4, "Ligne : " . $pdf->ligne);
 267  
 268      $pdf->SetX(11);
 269      $pdf->MultiCell(89, 4, $pdf->libelle, 0);
 270  
 271      $pdf->SetX(11);
 272      if ($output == 0)
 273        {
 274      $pdf->MultiCell(80, 4, "Page : ". $pdf->PageNo() ."/{nb}", 0);
 275        }
 276  
 277      // Clients spéciaux
 278  
 279      if ($pdf->ligne_ville)
 280        {
 281      $pdf->SetX(11);
 282      $pdf->MultiCell(80, 4, "Agence : ". $pdf->ligne_ville, 0);
 283        }
 284  
 285      $pdf->rect(10, 30, 95, 23);
 286      
 287      $pdf->SetTextColor(0,0,0);
 288      $pdf->SetFont('Arial','',10);
 289  
 290      $pdf->SetXY(107, 31);
 291  
 292      $pdf->MultiCell(66,4, $pdf->client_nom);
 293  
 294      $pdf->SetX(107);
 295      $pdf->MultiCell(86,4, $pdf->client_adresse . "\n" . $pdf->client_cp . " " . $pdf->client_ville);
 296  
 297      $pdf->rect(105, 30, 95, 23);
 298  
 299      /*
 300       * On positionne le curseur pour la liste
 301       */        
 302      $pdf->SetXY(10,$pdf->tab_top + 6);
 303      $pdf->colonne = 1;
 304      $pdf->inc = 0;
 305    }
 306  
 307    /* 
 308     * Footer
 309     */
 310  
 311    function Footer(&$pdf)
 312    {
 313  
 314      if ($pdf->FirstPage == 1)
 315        {
 316      $pdf->FirstPage = 0;
 317        }
 318      else
 319        {
 320  
 321      $pdf->SetFont('Arial','',8);
 322      
 323      $pdf->Text(11, $pdf->tab_top + 3,'Date');
 324      $pdf->Text(106, $pdf->tab_top + 3,'Date');
 325      
 326      $w = 33;
 327      
 328      $pdf->Text($w+1, $pdf->tab_top + 3,'Numéro');
 329      $pdf->Text($w+96, $pdf->tab_top + 3,'Numéro');
 330      
 331      $w = 47;
 332      
 333      $pdf->Text($w+1, $pdf->tab_top + 3,'Destination');
 334      $pdf->Text($w+96, $pdf->tab_top + 3,'Destination');
 335      
 336      $w = 86;
 337      
 338      $pdf->Text($w+1, $pdf->tab_top + 3,'Durée');
 339      $pdf->Text($w+96, $pdf->tab_top + 3,'Durée');
 340      
 341      $w = 98;
 342      
 343      $pdf->Text($w+1, $pdf->tab_top + 3,'HT');
 344      $pdf->Text($w+96, $pdf->tab_top + 3,'HT');
 345      
 346      $pdf->line(10, $pdf->tab_top + 4, 200, $pdf->tab_top + 4 );
 347  
 348      /* Ligne Médiane */
 349  
 350      $pdf->line(105, $pdf->tab_top, 105, $pdf->tab_top + $pdf->tab_height);
 351      
 352        }
 353  
 354      $pdf->Rect(10, $pdf->tab_top, 190, $pdf->tab_height);
 355    }
 356  
 357    function ListHeader(&$pdf)
 358    {
 359      $pdf->SetXY(10,5);
 360      //$pdf->SetTextColor(0,90,200);
 361      $pdf->SetFont('Arial','',10);
 362      $pdf->SetXY(11,5);
 363      $pdf->MultiCell(89, 4, "Facture détaillée : ".$pdf->fac->ref);
 364  
 365      $pdf->SetX(11);
 366      $pdf->MultiCell(89, 4, "Ligne : " . $pdf->ligne);
 367      $pdf->SetX(11);
 368  
 369      $libelle = "Du ".strftime("%d/%m/%Y",$pdf->factel->get_comm_min_date($this->year.$this->month));
 370      $libelle .= " au ".strftime("%d/%m/%Y",$pdf->factel->get_comm_max_date($this->year.$this->month));
 371      $pdf->MultiCell(89, 4, $libelle, 0);
 372  
 373      //$pdf->SetX(11);
 374      //$pdf->MultiCell(80, 4, "Page : ". $pdf->PageNo() ."/{nb}", 0);
 375      // Clients spéciaux
 376  
 377      if ($pdf->ligne_ville)
 378        {
 379      $pdf->SetX(11);
 380      $pdf->MultiCell(80, 4, "Agence : ". $pdf->ligne_ville, 0);
 381        }
 382  
 383      $pdf->rect(10, 4, 95, 19);
 384      $pdf->SetTextColor(0,0,0);
 385      $pdf->SetFont('Arial','',10);
 386  
 387      $pdf->SetXY(107, 5);
 388  
 389      $pdf->MultiCell(66,4, $pdf->client_nom);
 390  
 391      $pdf->SetX(107);
 392      $pdf->MultiCell(86,4, $pdf->client_adresse . "\n" . $pdf->client_cp . " " . $pdf->client_ville);
 393  
 394      $pdf->rect(105, 4, 95, 19);
 395  
 396      /*
 397       * On positionne le curseur pour la liste
 398       */        
 399      $pdf->SetXY(10,$pdf->tab_top + 6);
 400      $pdf->colonne = 1;
 401      $pdf->inc = 0;
 402    }
 403  
 404  }
 405  ?>


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