[ 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/includes/modules/facture/ -> pdf_crabe.modules.php (source)

   1  <?php
   2  /* Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   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: pdf_crabe.modules.php,v 1.70.2.2 2006/01/04 20:14:57 eldy Exp $
  20  * $Source: /cvsroot/dolibarr/dolibarr/htdocs/includes/modules/facture/pdf_crabe.modules.php,v $
  21  */
  22  
  23  /**
  24             \file       htdocs/includes/modules/facture/pdf_crabe.modules.php
  25          \ingroup    facture
  26          \brief      Fichier de la classe permettant de générer les factures au modèle Crabe
  27          \author        Laurent Destailleur
  28          \version    $Revision: 1.70.2.2 $
  29  */
  30  
  31  require_once (DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
  32  require_once(DOL_DOCUMENT_ROOT."/product.class.php");
  33  
  34  
  35  /**
  36          \class      pdf_crabe
  37          \brief      Classe permettant de générer les factures au modèle Crabe
  38  */
  39  
  40  class pdf_crabe extends ModelePDFFactures
  41  {
  42      
  43      /**
  44              \brief  Constructeur
  45              \param    db        Handler accès base de donnée
  46      */
  47      function pdf_crabe($db)
  48      {
  49          global $conf,$langs;
  50          
  51          $this->db = $db;
  52          $this->name = "crabe";
  53          $this->description = "Modèle de facture complet (Gère l'option fiscale de facturation TVA, le choix du mode de règlement à afficher, logo...)";
  54  
  55          // Dimension page pour format A4
  56          $this->page_largeur = 210;
  57          $this->page_hauteur = 297;
  58          $this->format = array($this->page_largeur,$this->page_hauteur);
  59          $this->marge_gauche=10;
  60          $this->marge_droite=10;
  61          $this->marge_haute=10;
  62          $this->marge_basse=10;
  63  
  64          $this->option_logo = 1;                    // Affiche logo FAC_PDF_LOGO
  65          $this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
  66          $this->option_modereg = 1;                 // Gere choix mode règlement FACTURE_CHQ_NUMBER, FACTURE_RIB_NUMBER
  67          $this->option_codeproduitservice = 1;      // Affiche code produit-service
  68          $this->option_tvaintra = 1;                // Affiche tva intra MAIN_INFO_TVAINTRA
  69          $this->option_capital = 1;                 // Affiche capital MAIN_INFO_CAPITAL
  70          if (defined("FACTURE_TVAOPTION") && FACTURE_TVAOPTION == 'franchise') 
  71                $this->franchise=1;
  72  
  73          // Recupere code pays de l'emmetteur
  74          $this->emetteur->code_pays=substr($langs->defaultlang,-2);    // Par defaut, si on trouve pas
  75          $sql  = "SELECT code from ".MAIN_DB_PREFIX."c_pays";
  76          $sql .= " WHERE rowid = '".$conf->global->MAIN_INFO_SOCIETE_PAYS."'";
  77          $result=$this->db->query($sql);
  78          if ($result) {
  79              $obj = $this->db->fetch_object($result);
  80              if ($obj->code) $this->emetteur->code_pays=$obj->code;
  81          }
  82          else {
  83              dolibarr_print_error($this->db);
  84          }
  85          $this->db->free($result);
  86          
  87          $this->tva=array();
  88          
  89          // Defini position des colonnes
  90          $this->posxdesc=$this->marge_gauche+1;
  91          $this->posxtva=121;
  92          $this->posxup=132;
  93          $this->posxqty=151;
  94          $this->posxdiscount=162;
  95          $this->postotalht=177;
  96  
  97          $this->atleastoneratenotnull=0;
  98          $this->atleastonediscount=0;
  99      }
 100  
 101  
 102      /**
 103              \brief      Fonction générant la facture sur le disque
 104              \param        id        Id de la facture à générer
 105              \return        int     1=ok, 0=ko
 106              \remarks    Variables utilisées
 107              \remarks    MAIN_INFO_SOCIETE_NOM
 108              \remarks    MAIN_INFO_ADRESSE
 109              \remarks    MAIN_INFO_CP
 110              \remarks    MAIN_INFO_VILLE
 111              \remarks    MAIN_INFO_TEL
 112              \remarks    MAIN_INFO_FAX
 113              \remarks    MAIN_INFO_WEB
 114              \remarks    MAIN_INFO_SIRET
 115              \remarks    MAIN_INFO_SIREN
 116              \remarks    MAIN_INFO_RCS
 117              \remarks    MAIN_INFO_CAPITAL
 118              \remarks    MAIN_INFO_TVAINTRA
 119              \remarks    MAIN_INFO_LOGO
 120              \remarks    FACTURE_CHQ_NUMBER
 121              \remarks    FACTURE_RIB_NUMBER
 122      */
 123      function write_pdf_file($id)
 124      {
 125          global $user,$langs,$conf;
 126  
 127          $langs->load("main");
 128          $langs->load("bills");
 129          $langs->load("products");
 130  
 131          if ($conf->facture->dir_output)
 132          {
 133              $fac = new Facture($this->db,"",$id);
 134              $ret=$fac->fetch($id);
 135              $nblignes = sizeof($fac->lignes);
 136  
 137              $facref = sanitize_string($fac->ref);
 138              $dir = $conf->facture->dir_output . "/" . $facref;
 139              $file = $dir . "/" . $facref . ".pdf";
 140  
 141              if (! file_exists($dir))
 142              {
 143                  if (create_exdir($dir) < 0)
 144                  {
 145                      $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
 146                      return 0;
 147                  }
 148              }
 149  
 150              if (file_exists($dir))
 151              {
 152                  // Initialisation document vierge
 153                  $pdf=new FPDF('P','mm',$this->format);
 154                  $pdf->Open();
 155                  $pdf->AddPage();
 156  
 157                  $pdf->SetDrawColor(128,128,128);
 158  
 159                  $pdf->SetTitle($fac->ref);
 160                  $pdf->SetSubject($langs->trans("Bill"));
 161                  $pdf->SetCreator("Dolibarr ".DOL_VERSION);
 162                  $pdf->SetAuthor($user->fullname);
 163  
 164                  $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
 165                  $pdf->SetAutoPageBreak(1,0);
 166  
 167                  // Positionne $this->atleastonediscount si on a au moins une remise
 168                  for ($i = 0 ; $i < $nblignes ; $i++)
 169                  {
 170                      if ($fac->lignes[$i]->remise_percent)
 171                      {
 172                          $this->atleastonediscount++;
 173                      }
 174                  }
 175  
 176                  $this->_pagehead($pdf, $fac);
 177  
 178                  $pagenb = 1;
 179                  $tab_top = 90;
 180                  $tab_top_newpage = 50;
 181                  $tab_height = 110;
 182  
 183                  $iniY = $tab_top + 8;
 184                  $curY = $tab_top + 8;
 185                  $nexY = $tab_top + 8;
 186  
 187                  // Boucle sur les lignes
 188                  for ($i = 0 ; $i < $nblignes ; $i++)
 189                  {
 190                      $curY = $nexY;
 191  
 192                      // Description de la ligne produit
 193                      $libelleproduitservice=$fac->lignes[$i]->libelle;
 194                      if ($fac->lignes[$i]->desc&&$fac->lignes[$i]->desc!=$fac->lignes[$i]->libelle)
 195                      {
 196                          if ($libelleproduitservice) $libelleproduitservice.="\n";
 197                          $libelleproduitservice.=$fac->lignes[$i]->desc;
 198                      }
 199                      // Si ligne associée à un code produit
 200                      if ($fac->lignes[$i]->produit_id)
 201                      {
 202                          $prodser = new Product($this->db);
 203  
 204                          $prodser->fetch($fac->lignes[$i]->produit_id);
 205                          if ($prodser->ref) {
 206                              $libelleproduitservice=$langs->trans("Product")." ".$prodser->ref." - ".$libelleproduitservice;
 207                          }
 208  
 209                          // Ajoute description du produit
 210                          if ($conf->global->FAC_ADD_PROD_DESC)
 211                          {
 212                              if ($fac->lignes[$i]->product_desc&&$fac->lignes[$i]->product_desc!=$fac->lignes[$i]->libelle&&$fac->lignes[$i]->product_desc!=$fac->lignes[$i]->desc)
 213                              {
 214                                  if ($libelleproduitservice) $libelleproduitservice.="\n";
 215                                  $libelleproduitservice.=$fac->lignes[$i]->product_desc;
 216                              }
 217                          }                    
 218                      }
 219  
 220                      if ($fac->lignes[$i]->date_start && $fac->lignes[$i]->date_end) {
 221                          // Affichage durée si il y en a une
 222                          $libelleproduitservice.="\n(".$langs->trans("From")." ".dolibarr_print_date($fac->lignes[$i]->date_start)." ".$langs->trans("to")." ".dolibarr_print_date($fac->lignes[$i]->date_end).")";
 223                      }
 224  
 225                      $pdf->SetFont('Arial','', 9);   // Dans boucle pour gérer multi-page
 226  
 227                      $pdf->SetXY ($this->posxdesc-1, $curY);
 228                      $pdf->MultiCell(108, 4, $libelleproduitservice, 0, 'J');
 229  
 230                      $nexY = $pdf->GetY();
 231  
 232                      // TVA
 233                      $pdf->SetXY ($this->posxtva, $curY);
 234                      $pdf->MultiCell(10, 4, ($fac->lignes[$i]->tva_taux < 0 ? '*':'').abs($fac->lignes[$i]->tva_taux), 0, 'R');
 235  
 236                      // Prix unitaire HT avant remise
 237                      $pdf->SetXY ($this->posxup, $curY);
 238                      $pdf->MultiCell(18, 4, price($fac->lignes[$i]->subprice), 0, 'R', 0);
 239  
 240                      // Quantité
 241                      $pdf->SetXY ($this->posxqty, $curY);
 242                      $pdf->MultiCell(10, 4, $fac->lignes[$i]->qty, 0, 'R');
 243  
 244                      // Remise sur ligne
 245                      $pdf->SetXY ($this->posxdiscount, $curY);
 246                      if ($fac->lignes[$i]->remise_percent)
 247                      {
 248                          $pdf->MultiCell(14, 4, $fac->lignes[$i]->remise_percent."%", 0, 'R');
 249                      }
 250  
 251                      // Total HT ligne
 252                      $pdf->SetXY ($this->postotalht, $curY);
 253                      $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty);
 254                      $pdf->MultiCell(23, 4, $total, 0, 'R', 0);
 255  
 256                      // Collecte des totaux par valeur de tva
 257                      // dans le tableau tva["taux"]=total_tva
 258                      $tvaligne=$fac->lignes[$i]->price * $fac->lignes[$i]->qty;
 259                      if ($fac->remise_percent) $tvaligne-=($tvaligne*$fac->remise_percent)/100;
 260                      $this->tva[ (string)$fac->lignes[$i]->tva_taux ] += $tvaligne;
 261  
 262                      $nexY+=2;    // Passe espace entre les lignes
 263  
 264                      if ($nexY > 200 && $i < ($nblignes - 1))
 265                      {
 266                          $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY);
 267                          $this->_pagefoot($pdf);
 268                          
 269                          // Nouvelle page
 270                          $pdf->AddPage();
 271                          $pagenb++;
 272                          $this->_pagehead($pdf, $fac, 0);
 273  
 274                          $nexY = $tab_top_newpage + 8;
 275                          $pdf->SetTextColor(0,0,0);
 276                          $pdf->SetFont('Arial','', 10);
 277                      }
 278  
 279                  }
 280                  // Affiche cadre tableau
 281                  if ($pagenb == 1)
 282                  {
 283                      $this->_tableau($pdf, $tab_top, $tab_height, $nexY);
 284                      $bottomlasttab=$tab_top + $tab_height + 1;
 285                  }
 286                  else 
 287                  {
 288                      $this->_tableau($pdf, $tab_top_newpage, $tab_height, $nexY);
 289                      $bottomlasttab=$tab_top_newpage + $tab_height + 1;
 290                  }
 291                  
 292                  $deja_regle = $fac->getSommePaiement();
 293  
 294                  $posy=$this->_tableau_tot($pdf, $fac, $deja_regle, $bottomlasttab);
 295  
 296                  if ($deja_regle) {            
 297                      $this->_tableau_versements($pdf, $fac, $posy);
 298                  }
 299  
 300                  /*
 301                   * Mode de règlement
 302                   */
 303                  if ((! defined("FACTURE_CHQ_NUMBER") || ! FACTURE_CHQ_NUMBER) && (! defined("FACTURE_RIB_NUMBER") || ! FACTURE_RIB_NUMBER))
 304                  {
 305                      $pdf->SetXY($this->marge_gauche, 228);
 306                      $pdf->SetTextColor(200,0,0);
 307                      $pdf->SetFont('Arial','B',8);
 308                      $pdf->MultiCell(90, 3, $langs->trans("ErrorNoPaiementModeConfigured"),0,'L',0);
 309                      $pdf->MultiCell(90, 3, $langs->trans("ErrorCreateBankAccount"),0,'L',0);
 310                      $pdf->SetTextColor(0,0,0);
 311                  }
 312  
 313                  /*
 314                   * Propose mode règlement par CHQ
 315                   */
 316                  if (defined("FACTURE_CHQ_NUMBER"))
 317                  {
 318                      if (FACTURE_CHQ_NUMBER > 0)
 319                      {
 320                          $account = new Account($this->db);
 321                          $account->fetch(FACTURE_CHQ_NUMBER);
 322  
 323                          $pdf->SetXY($this->marge_gauche, 227);
 324                          $pdf->SetFont('Arial','B',8);
 325                          $pdf->MultiCell(90, 3, "Règlement par chèque à l'ordre de ".$account->proprio." envoyé à:",0,'L',0);
 326                          $pdf->SetXY($this->marge_gauche, 231);
 327                          $pdf->SetFont('Arial','',8);
 328                          $pdf->MultiCell(80, 3, $account->adresse_proprio, 0, 'L', 0);
 329                      }
 330                  }
 331  
 332                  /*
 333                   * Propose mode règlement par RIB
 334                   */
 335                  if (defined("FACTURE_RIB_NUMBER"))
 336                  {
 337                      if (FACTURE_RIB_NUMBER > 0)
 338                      {
 339                          $account = new Account($this->db);
 340                          $account->fetch(FACTURE_RIB_NUMBER);
 341  
 342                          $this->marges['g']=$this->marge_gauche;
 343                          
 344                          $cury=242;
 345                          $pdf->SetXY ($this->marges['g'], $cury);
 346                          $pdf->SetFont('Arial','B',8);
 347                          $pdf->MultiCell(90, 3, "Règlement par virement sur le compte bancaire suivant:", 0, 'L', 0);
 348                          $cury+=4;
 349                          $pdf->SetFont('Arial','B',6);
 350                          $pdf->line($this->marges['g']+1, $cury, $this->marges['g']+1, $cury+10 );
 351                          $pdf->SetXY ($this->marges['g'], $cury);
 352                          $pdf->MultiCell(18, 3, "Code banque", 0, 'C', 0);
 353                          $pdf->line($this->marges['g']+18, $cury, $this->marges['g']+18, $cury+10 );
 354                          $pdf->SetXY ($this->marges['g']+18, $cury);
 355                          $pdf->MultiCell(18, 3, "Code guichet", 0, 'C', 0);
 356                          $pdf->line($this->marges['g']+36, $cury, $this->marges['g']+36, $cury+10 );
 357                          $pdf->SetXY ($this->marges['g']+36, $cury);
 358                          $pdf->MultiCell(24, 3, "Numéro compte", 0, 'C', 0);
 359                          $pdf->line($this->marges['g']+60, $cury, $this->marges['g']+60, $cury+10 );
 360                          $pdf->SetXY ($this->marges['g']+60, $cury);
 361                          $pdf->MultiCell(13, 3, "Clé RIB", 0, 'C', 0);
 362                          $pdf->line($this->marges['g']+73, $cury, $this->marges['g']+73, $cury+10 );
 363                          
 364                          $pdf->SetFont('Arial','',8);
 365                          $pdf->SetXY ($this->marges['g'], $cury+5);
 366                          $pdf->MultiCell(18, 3, $account->code_banque, 0, 'C', 0);
 367                          $pdf->SetXY ($this->marges['g']+18, $cury+5);
 368                          $pdf->MultiCell(18, 3, $account->code_guichet, 0, 'C', 0);
 369                          $pdf->SetXY ($this->marges['g']+36, $cury+5);
 370                          $pdf->MultiCell(24, 3, $account->number, 0, 'C', 0);
 371                          $pdf->SetXY ($this->marges['g']+60, $cury+5);
 372                          $pdf->MultiCell(13, 3, $account->cle_rib, 0, 'C', 0);
 373           
 374                          $pdf->SetXY ($this->marges['g'], $cury+12);
 375                          $pdf->MultiCell(90, 3, "Domiciliation : " . $account->domiciliation, 0, 'L', 0);
 376                          $pdf->SetXY ($this->marges['g'], $cury+22);
 377                          $pdf->MultiCell(90, 3, "Prefix IBAN : " . $account->iban_prefix, 0, 'L', 0);
 378                          $pdf->SetXY ($this->marges['g'], $cury+25);
 379                          $pdf->MultiCell(90, 3, "BIC : " . $account->bic, 0, 'L', 0);
 380  
 381                      }
 382                  }
 383  
 384                  /*
 385                   * Conditions de règlements
 386                   */
 387                  $pdf->SetFont('Arial','B',10);
 388                  $pdf->SetXY($this->marge_gauche, 217);
 389                  $titre = "Conditions de réglement:";
 390                  $pdf->MultiCell(80, 5, $titre, 0, 'L');
 391                  $pdf->SetFont('Arial','',10);
 392                  $pdf->SetXY(54, 217);
 393                  $pdf->MultiCell(80, 5, $fac->cond_reglement_facture,0,'L');
 394  
 395  
 396                  /*
 397                   * Pied de page
 398                   */
 399                  $this->_pagefoot($pdf);
 400                  $pdf->AliasNbPages();
 401                  
 402                  $pdf->Close();
 403  
 404                  $pdf->Output($file);
 405  
 406                  return 1;   // Pas d'erreur
 407              }
 408              else
 409              {
 410                  $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
 411                  return 0;
 412              }
 413          }
 414          else
 415          {
 416              $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR");
 417              return 0;
 418          }
 419          $this->error=$langs->trans("ErrorUnknown");
 420          return 0;   // Erreur par defaut
 421      }
 422  
 423  
 424      /*
 425       *   \brief      Affiche tableau des versement
 426       *   \param      pdf     objet PDF
 427       *   \param      fac     objet facture
 428       */
 429      function _tableau_versements(&$pdf, $fac, $posy)
 430      {
 431          global $langs;
 432          $langs->load("main");
 433          $langs->load("bills");
 434       
 435          $tab3_posx = 120;
 436          $tab3_top = $posy + 8;
 437          $tab3_width = 80;
 438          $tab3_height = 4;
 439  
 440          $pdf->SetFont('Arial','',8);
 441          $pdf->SetXY ($tab3_posx, $tab3_top - 5);
 442          $pdf->MultiCell(60, 5, $langs->trans("PaymentsAlreadyDone"), 0, 'L', 0);
 443  
 444          $pdf->Rect($tab3_posx, $tab3_top-1, $tab3_width, $tab3_height);
 445  
 446          $pdf->SetXY ($tab3_posx, $tab3_top-1 );
 447          $pdf->MultiCell(20, 4, $langs->trans("Payment"), 0, 'L', 0);
 448          $pdf->SetXY ($tab3_posx+21, $tab3_top-1 );
 449          $pdf->MultiCell(20, 4, $langs->trans("Amount"), 0, 'L', 0);
 450          $pdf->SetXY ($tab3_posx+41, $tab3_top-1 );
 451          $pdf->MultiCell(20, 4, $langs->trans("Type"), 0, 'L', 0);
 452          $pdf->SetXY ($tab3_posx+60, $tab3_top-1 );
 453          $pdf->MultiCell(20, 4, $langs->trans("Num"), 0, 'L', 0);
 454  
 455          $sql = "SELECT ".$this->db->pdate("p.datep")."as date, p.amount as amount, p.fk_paiement as type, p.num_paiement as num ";
 456          $sql.= "FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."paiement_facture as pf ";
 457          $sql.= "WHERE pf.fk_paiement = p.rowid and pf.fk_facture = ".$fac->id." ";
 458          $sql.= "ORDER BY p.datep";
 459          if ($this->db->query($sql))
 460          {
 461              $pdf->SetFont('Arial','',6);
 462              $num = $this->db->num_rows();
 463              $i=0; $y=0;
 464              while ($i < $num) {
 465                  $y+=3;
 466                  $row = $this->db->fetch_row();
 467      
 468                  $pdf->SetXY ($tab3_posx, $tab3_top+$y );
 469                  $pdf->MultiCell(20, 4, strftime("%d/%m/%y",$row[0]), 0, 'L', 0);
 470                  $pdf->SetXY ($tab3_posx+21, $tab3_top+$y);
 471                  $pdf->MultiCell(20, 4, $row[1], 0, 'L', 0);
 472                  $pdf->SetXY ($tab3_posx+41, $tab3_top+$y);
 473                  switch ($row[2])
 474                    {
 475                    case 1:
 476                      $oper = 'TIP';
 477                      break;
 478                    case 2:
 479                      $oper = 'VIR';
 480                      break;
 481                    case 3:
 482                      $oper = 'PRE';
 483                      break;
 484                    case 4:
 485                      $oper = 'LIQ';
 486                      break;
 487                    case 5:
 488                      $oper = 'VAD';
 489                      break;
 490                    case 6:
 491                      $oper = 'CB';
 492                      break;
 493                    case 7:
 494                      $oper = 'CHQ';
 495                      break;
 496                    }
 497                  $pdf->MultiCell(20, 4, $oper, 0, 'L', 0);
 498                  $pdf->SetXY ($tab3_posx+60, $tab3_top+$y);
 499                  $pdf->MultiCell(20, 4, $row[3], 0, 'L', 0);
 500      
 501                  $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3 );
 502  
 503                  $i++;
 504              }
 505          }
 506          else
 507          {
 508              $this->error=$langs->trans("ErrorSQL")." $sql";
 509              return 0;
 510          }
 511  
 512      }
 513  
 514      /*
 515       *   \brief      Affiche le total à payer
 516       *   \param      pdf             Objet PDF
 517       *   \param      fac             Objet facture
 518       *   \param      deja_regle      Montant deja regle
 519       *   \return     y               Position pour suite
 520       */
 521      function _tableau_tot(&$pdf, $fac, $deja_regle, $posy)
 522      {
 523          global $langs;
 524          $langs->load("main");
 525          $langs->load("bills");
 526  
 527          $tab2_top = $posy;
 528          $tab2_hl = 5;
 529          $tab2_height = $tab2_hl * 4;
 530          $pdf->SetFont('Arial','', 9);
 531  
 532          // Affiche la mention TVA non applicable selon option
 533          $pdf->SetXY($this->marge_gauche, $tab2_top + 0);
 534          if ($this->franchise==1)
 535            {
 536              $pdf->MultiCell(100, $tab2_hl, "* TVA non applicable art-293B du CGI", 0, 'L', 0);
 537          }
 538  
 539          // Tableau total
 540          $lltot = 200; $col1x = 120; $col2x = 182; $largcol2 = $lltot - $col2x;
 541  
 542          // Total HT
 543          $pdf->SetFillColor(256,256,256);
 544          $pdf->SetXY ($col1x, $tab2_top + 0);
 545          $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalHT"), 0, 'L', 1);
 546  
 547          $pdf->SetXY ($col2x, $tab2_top + 0);
 548          $pdf->MultiCell($largcol2, $tab2_hl, price($fac->total_ht + $fac->remise), 0, 'R', 1);
 549  
 550          // Remise globale
 551          if ($fac->remise > 0)
 552          {
 553              $pdf->SetXY ($col1x, $tab2_top + $tab2_hl);
 554              $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("GlobalDiscount"), 0, 'L', 1);
 555  
 556              $pdf->SetXY ($col2x, $tab2_top + $tab2_hl);
 557              $pdf->MultiCell($largcol2, $tab2_hl, "-".$fac->remise_percent."%", 0, 'R', 1);
 558  
 559              $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * 2);
 560              $pdf->MultiCell($col2x-$col1x, $tab2_hl, "Total HT après remise", 0, 'L', 1);
 561  
 562              $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * 2);
 563              $pdf->MultiCell($largcol2, $tab2_hl, price($fac->total_ht), 0, 'R', 1);
 564  
 565              $index = 2;
 566          }
 567          else
 568          {
 569              $index = 0;
 570          }
 571  
 572          // Affichage des totaux de TVA par taux (conformément à réglementation)
 573          $pdf->SetFillColor(248,248,248);
 574          foreach( $this->tva as $tvakey => $tvaval )
 575          {
 576              if ($tvakey)    // On affiche pas taux 0
 577              {
 578                  $this->atleastoneratenotnull++;
 579                  
 580                  $index++;
 581                  $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
 582                  $tvacompl = ( (float)$tvakey < 0 ) ? " (".$langs->trans("NonPercuRecuperable").")" : '' ; 
 583                  $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalVAT").' '.abs($tvakey).'%'.$tvacompl, 0, 'L', 1);
 584      
 585                  $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
 586                  $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval * (float)$tvakey / 100 ), 0, 'R', 1);
 587              }
 588          }
 589          if (! $this->atleastoneratenotnull)
 590          {
 591              $index++;
 592              $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
 593              $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalVAT"), 0, 'L', 1);
 594  
 595              $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
 596              $pdf->MultiCell($largcol2, $tab2_hl, price($fac->total_tva), 0, 'R', 1);
 597          }
 598  
 599          $useborder=0;
 600          
 601          $index++;
 602          $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
 603          $pdf->SetTextColor(0,0,60);
 604          $pdf->SetFillColor(224,224,224);
 605          $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalTTC"), $useborder, 'L', 1);
 606  
 607          $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
 608          $pdf->MultiCell($largcol2, $tab2_hl, price($fac->total_ttc), $useborder, 'R', 1);
 609          $pdf->SetFont('Arial','', 9);
 610          $pdf->SetTextColor(0,0,0);
 611  
 612          if ($deja_regle > 0)
 613          {
 614              $index++;
 615              
 616              $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
 617              $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("AlreadyPayed"), 0, 'L', 0);
 618  
 619              $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
 620              $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
 621  
 622              $index++;
 623              $pdf->SetTextColor(0,0,60);
 624              //$pdf->SetFont('Arial','B', 9);
 625              $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
 626              $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("RemainderToPay"), $useborder, 'L', 1);
 627  
 628              $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index);
 629              $pdf->MultiCell($largcol2, $tab2_hl, price($fac->total_ttc - $deja_regle), $useborder, 'R', 1);
 630              $pdf->SetFont('Arial','', 9);
 631              $pdf->SetTextColor(0,0,0);
 632          }
 633      
 634  /* Ne semble pas requis par la réglementation
 635          $index++;
 636          $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index);
 637          $pdf->MultiCell($col2x-$col1x+$largcol2, $tab2_hl, $langs->trans('DispenseMontantLettres'), 0, 'L' );
 638  */
 639          $index++;
 640          return ($tab2_top + ($tab2_hl * $index));
 641      }
 642  
 643      /*
 644       *   \brief      Affiche la grille des lignes de factures
 645       *   \param      pdf     objet PDF
 646       */
 647      function _tableau(&$pdf, $tab_top, $tab_height, $nexY)
 648      {
 649          global $langs,$conf;
 650          $langs->load("main");
 651          $langs->load("bills");
 652          
 653          // Montants exprimés en     (en tab_top - 1)
 654          $pdf->SetTextColor(0,0,0);
 655          $pdf->SetFont('Arial','',8);
 656          $titre = $langs->trans("AmountInCurrency",$langs->trans("Currency".$conf->monnaie));
 657          $pdf->Text($this->page_largeur - $this->marge_droite - $pdf->GetStringWidth($titre), $tab_top-1, $titre);
 658  
 659          $pdf->SetDrawColor(128,128,128);
 660  
 661          // Rect prend une longueur en 3eme param
 662          $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
 663          // line prend une position y en 3eme param
 664          $pdf->line($this->marge_gauche, $tab_top+6, $this->page_largeur-$this->marge_droite, $tab_top+6);
 665  
 666          $pdf->SetFont('Arial','',10);
 667  
 668          $pdf->SetXY ($this->posxdesc-1, $tab_top+2);
 669          $pdf->MultiCell(108,2, $langs->trans("Designation"),'','L');
 670  
 671          $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
 672          $pdf->SetXY ($this->posxtva-1, $tab_top+2);
 673          $pdf->MultiCell(12,2, $langs->trans("VAT"),'','C');
 674  
 675          $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
 676          $pdf->SetXY ($this->posxup-1, $tab_top+2);
 677          $pdf->MultiCell(18,2, $langs->trans("PriceUHT"),'','C');
 678  
 679          $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
 680          $pdf->SetXY ($this->posxqty-1, $tab_top+2);
 681          $pdf->MultiCell(11,2, $langs->trans("Qty"),'','C');
 682  
 683          $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
 684          if ($this->atleastonediscount)
 685          {
 686              $pdf->SetXY ($this->posxdiscount-1, $tab_top+2);
 687              $pdf->MultiCell(16,2, $langs->trans("Discount"),'','C');
 688          }
 689          
 690          if ($this->atleastonediscount)
 691          {
 692              $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
 693          }
 694          $pdf->SetXY ($this->postotalht-1, $tab_top+2);
 695          $pdf->MultiCell(23,2, $langs->trans("TotalHT"),'','C');
 696  
 697      }
 698  
 699      /*
 700       *      \brief      Affiche en-tête facture
 701       *      \param      pdf             Objet PDF
 702       *      \param      fac             Objet facture
 703       *      \param      showadress      0=non, 1=oui
 704       */
 705      function _pagehead(&$pdf, $fac, $showadress=1)
 706      {
 707          global $langs,$conf,$mysoc;
 708          
 709          $langs->load("main");
 710          $langs->load("bills");
 711          $langs->load("propal");
 712          $langs->load("companies");
 713          
 714          $pdf->SetTextColor(0,0,60);
 715          $pdf->SetFont('Arial','B',13);
 716  
 717          $posy=$this->marge_haute;
 718  
 719          $pdf->SetXY($this->marge_gauche,$posy);
 720  
 721          // Logo
 722          $logo=$mysoc->logo;
 723          if (defined("FAC_PDF_LOGO") && FAC_PDF_LOGO) $logo=DOL_DATA_ROOT.FAC_PDF_LOGO;
 724          if ($logo)
 725          {
 726              if (is_readable($logo))
 727              {
 728                  $pdf->Image($logo, $this->marge_gauche, $posy, 0, 24);
 729              }
 730              else
 731              {
 732                  $pdf->SetTextColor(200,0,0);
 733                  $pdf->SetFont('Arial','B',8);
 734                  $pdf->MultiCell(100, 3, $langs->trans("ErrorLogoFileNotFound",$logo), 0, 'L');
 735                  $pdf->MultiCell(100, 3, $langs->trans("ErrorGoToModuleSetup"), 0, 'L');
 736              }
 737          }
 738          else if (defined("FAC_PDF_INTITULE"))
 739          {
 740              $pdf->MultiCell(100, 4, FAC_PDF_INTITULE, 0, 'L');
 741          }
 742  
 743          $pdf->SetFont('Arial','B',13);
 744          $pdf->SetXY(100,$posy);
 745          $pdf->SetTextColor(0,0,60);
 746          $pdf->MultiCell(100, 4, $langs->trans("Bill")." ".$fac->ref, '' , 'R');
 747          $pdf->SetFont('Arial','',12);
 748          
 749          $posy+=6;
 750          $pdf->SetXY(100,$posy);
 751          $pdf->SetTextColor(0,0,60);
 752          $pdf->MultiCell(100, 4, $langs->trans("Date")." : " . dolibarr_print_date($fac->date,"%d %b %Y"), '', 'R');
 753  
 754          if ($showadress)
 755          {
 756              // Emetteur
 757              $posy=42;
 758              $hautcadre=40;
 759              $pdf->SetTextColor(0,0,0);
 760              $pdf->SetFont('Arial','',8);
 761              $pdf->SetXY($this->marge_gauche,$posy-5);
 762              $pdf->MultiCell(66,5, $langs->trans("BillFrom").":");
 763      
 764      
 765              $pdf->SetXY($this->marge_gauche,$posy);
 766              $pdf->SetFillColor(230,230,230);
 767              $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
 768      
 769      
 770              $pdf->SetXY($this->marge_gauche+2,$posy+3);
 771      
 772              // Nom emetteur
 773              $pdf->SetTextColor(0,0,60);
 774              $pdf->SetFont('Arial','B',11);
 775              if (defined("FAC_PDF_SOCIETE_NOM") && FAC_PDF_SOCIETE_NOM) $pdf->MultiCell(80, 4, FAC_PDF_SOCIETE_NOM, 0, 'L');
 776              else $pdf->MultiCell(80, 4, $mysoc->nom, 0, 'L');
 777      
 778              // Caractéristiques emetteur
 779              $carac_emetteur = '';
 780              if (defined("FAC_PDF_ADRESSE") && FAC_PDF_ADRESSE) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).FAC_PDF_ADRESSE;
 781              else {
 782                  $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$mysoc->adresse;
 783                  $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$mysoc->cp.' '.$mysoc->ville;
 784              }
 785              $carac_emetteur .= "\n";
 786              // Tel
 787              if (defined("FAC_PDF_TEL") && FAC_PDF_TEL) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Phone").": ".FAC_PDF_TEL;
 788              elseif ($mysoc->tel) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Phone").": ".$mysoc->tel;
 789              // Fax
 790              if (defined("FAC_PDF_FAX") && FAC_PDF_FAX) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Fax").": ".FAC_PDF_FAX;
 791              elseif ($mysoc->fax) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Fax").": ".$mysoc->fax;
 792              // EMail
 793              if (defined("FAC_PDF_MEL") && FAC_PDF_MEL) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Email").": ".FAC_PDF_MEL;
 794              elseif ($mysoc->email) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Email").": ".$mysoc->email;
 795              // Web
 796              if (defined("FAC_PDF_WWW") && FAC_PDF_WWW) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Web").": ".FAC_PDF_WWW;
 797              elseif ($mysoc->url) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Web").": ".$mysoc->url;
 798      
 799              $pdf->SetFont('Arial','',9);
 800              $pdf->SetXY($this->marge_gauche+2,$posy+8);
 801              $pdf->MultiCell(80,4, $carac_emetteur);
 802      
 803              // Client destinataire
 804              $posy=42;
 805              $pdf->SetTextColor(0,0,0);
 806              $pdf->SetFont('Arial','',8);
 807              $pdf->SetXY(102,$posy-5);
 808              $pdf->MultiCell(80,5, $langs->trans("BillTo").":");
 809              $fac->fetch_client();
 810              // Cadre client destinataire
 811              $pdf->rect(100, $posy, 100, $hautcadre);
 812      
 813              // Nom client
 814              $pdf->SetXY(102,$posy+3);
 815              $pdf->SetFont('Arial','B',11);
 816              $pdf->MultiCell(106,4, $fac->client->nom, 0, 'L');
 817      
 818              // Caractéristiques client
 819              $carac_client=$fac->client->adresse;
 820              $carac_client.="\n".$fac->client->cp . " " . $fac->client->ville."\n";
 821              if ($fac->client->tva_intra) $carac_client.="\n".$langs->trans("VATIntraShort").': '.$fac->client->tva_intra;
 822              $pdf->SetFont('Arial','',9);
 823              $pdf->SetXY(102,$posy+8);
 824              $pdf->MultiCell(86,4, $carac_client);
 825          }
 826          
 827      }
 828  
 829      /*
 830       *   \brief      Affiche le pied de page
 831       *   \param      pdf     objet PDF
 832       */
 833      function _pagefoot(&$pdf)
 834      {
 835          global $langs, $conf;
 836          $langs->load("main");
 837          $langs->load("bills");
 838          $langs->load("companies");
 839          
 840          $html=new Form($this->db);
 841          
 842          // Premiere ligne d'info réglementaires
 843          $ligne1="";
 844          if ($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE)
 845          {
 846              $ligne1.=($ligne1?" - ":"").$html->forme_juridique_name($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE);
 847          }
 848          if ($conf->global->MAIN_INFO_CAPITAL)
 849          {
 850              $ligne1.=($ligne1?" - ":"").$langs->trans("CapitalOf",$conf->global->MAIN_INFO_CAPITAL)." ".$langs->trans("Currency".$conf->monnaie);
 851          }
 852          if ($conf->global->MAIN_INFO_SIRET)
 853          {
 854              $ligne1.=($ligne1?" - ":"").$langs->transcountry("ProfId2",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_SIRET;
 855          }
 856          if ($conf->global->MAIN_INFO_SIREN && (! $conf->global->MAIN_INFO_SIRET || $this->emetteur->code_pays != 'FR'))
 857          {
 858              $ligne1.=($ligne1?" - ":"").$langs->transcountry("ProfId1",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_SIREN;
 859          }
 860          if ($conf->global->MAIN_INFO_APE)
 861          {
 862              $ligne1.=($ligne1?" - ":"").$langs->transcountry("ProfId3",$this->emetteur->code_pays).": ".MAIN_INFO_APE;
 863          }
 864  
 865          // Deuxieme ligne d'info réglementaires
 866          $ligne2="";
 867          if ($conf->global->MAIN_INFO_RCS)
 868          {
 869              $ligne2.=($ligne2?" - ":"").$langs->transcountry("ProfId4",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_RCS;
 870          }
 871          if ($conf->global->MAIN_INFO_TVAINTRA != '')
 872          {
 873              $ligne2.=($ligne2?" - ":"").$langs->trans("VATIntraShort").": ".$conf->global->MAIN_INFO_TVAINTRA;
 874          }
 875  
 876          $pdf->SetFont('Arial','',8);
 877          $pdf->SetDrawColor(224,224,224);
 878  
 879          // On positionne le debut du bas de page selon nbre de lignes de ce bas de page
 880          $posy=$this->marge_basse + 1 + ($ligne1?3:0) + ($ligne2?3:0);
 881  
 882          $pdf->SetY(-$posy);
 883          $pdf->line($this->marge_gauche, $this->page_hauteur-$posy, 200, $this->page_hauteur-$posy);
 884          $posy--;
 885          
 886          if ($ligne1)
 887          {
 888              $pdf->SetXY($this->marge_gauche,-$posy);
 889              $pdf->MultiCell(200, 2, $ligne1, 0, 'C', 0);
 890          }
 891  
 892          if ($ligne2)
 893          {
 894              $posy-=3;
 895              $pdf->SetXY($this->marge_gauche,-$posy);
 896              $pdf->MultiCell(200, 2, $ligne2, 0, 'C', 0);
 897          }
 898          
 899          $pdf->SetXY(-20,-$posy);
 900          $pdf->MultiCell(10, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0);
 901      }
 902  
 903  }
 904  
 905  ?>


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