[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> 3 /* Copyright (C) 2005 Sylvain SCATTOLINI <sylvain@s-infoservices.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * or see http://www.gnu.org/ 19 * 20 * $Id: pdf_oursin.modules.php,v 1.18 2005/12/18 13:43:33 hregis Exp $ 21 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/includes/modules/facture/pdf_oursin.modules.php,v $ 22 */ 23 24 /** 25 \file htdocs/includes/modules/facture/pdf_oursin.modules.php 26 \ingroup facture 27 \brief Fichier de la classe permettant de générer les factures au modèle oursin 28 \author Sylvain SCATTOLINI basé sur un modèle de Laurent Destailleur 29 \version $Revision: 1.18 $ 30 */ 31 32 require_once(DOL_DOCUMENT_ROOT."/product.class.php"); 33 require_once (DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); 34 35 36 /** 37 \class pdf_oursin 38 \brief Classe permettant de générer les factures au modèle oursin 39 */ 40 41 class pdf_oursin extends ModelePDFFactures 42 { 43 var $marges=array("g"=>10,"h"=>5,"d"=>10,"b"=>15); 44 45 46 /** 47 \brief Constructeur 48 \param db handler accès base de donnée 49 */ 50 function pdf_oursin($db) 51 { 52 $this->db = $db; 53 $this->description = "Modèle de facture complet (basé sur crabe, gère l'option fiscale de facturation TVA, le choix du mode de règlement à afficher, les remises, le nom du projet, la reference propal, 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 60 $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO 61 $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION 62 $this->option_modereg = 1; // Gere choix mode règlement FACTURE_CHQ_NUMBER, FACTURE_RIB_NUMBER 63 $this->option_codeproduitservice = 1; // Affiche code produit-service FACTURE_CODEPRODUITSERVICE 64 $this->option_tvaintra = 1; // Affiche tva intra MAIN_INFO_TVAINTRA 65 $this->option_capital = 1; // Affiche capital MAIN_INFO_CAPITAL 66 if (defined("FACTURE_TVAOPTION") && FACTURE_TVAOPTION == 'franchise') 67 $this->franchise=1; 68 69 // Recupere code pays 70 $this->code_pays=substr($langs->defaultlang,-2); // Par defaut, pays de la localisation 71 $sql = "SELECT code from ".MAIN_DB_PREFIX."c_pays"; 72 $sql .= " WHERE rowid = ".MAIN_INFO_SOCIETE_PAYS; 73 $result=$this->db->query($sql); 74 if ($result) { 75 $obj = $this->db->fetch_object($result); 76 if ($obj->code) $this->code_pays=$obj->code; 77 } 78 else { 79 dolibarr_print_error($this->db); 80 } 81 $this->db->free($result); 82 } 83 84 85 /** 86 \brief Fonction générant la facture sur le disque 87 \param facid id de la facture à générer 88 \return int 1=ok, 0=ko 89 \remarks Variables utilisées 90 \remarks MAIN_INFO_SOCIETE_NOM 91 \remarks MAIN_INFO_SIRET 92 \remarks MAIN_INFO_SIREN 93 \remarks MAIN_INFO_CAPITAL 94 \remarks MAIN_INFO_TVAINTRA 95 \remarks FAC_PDF_LOGO 96 \remarks FACTURE_CODEPRODUITSERVICE 97 \remarks FACTURE_CHQ_NUMBER 98 \remarks FACTURE_RIB_NUMBER 99 \remarks FAC_PDF_INTITULE 100 \remarks FAC_PDF_TEL 101 \remarks FAC_PDF_ADRESSE 102 */ 103 function write_pdf_file($facid) 104 { 105 global $user,$langs,$conf; 106 107 $langs->load("main"); 108 $langs->load("bills"); 109 $langs->load("products"); 110 111 if ($conf->facture->dir_output) 112 { 113 $fac = new Facture($this->db,"",$facid); 114 $fac->fetch($facid); 115 116 $facref = sanitize_string($fac->ref); 117 $dir = $conf->facture->dir_output . "/" . $facref; 118 $file = $dir . "/" . $facref . ".pdf"; 119 120 if (! file_exists($dir)) 121 { 122 if (create_exdir($dir) < 0) 123 { 124 $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); 125 return 0; 126 } 127 } 128 129 if (file_exists($dir)) 130 { 131 // Initialisation facture vierge 132 $pdf=new FPDF('P','mm','A4'); 133 $pdf->Open(); 134 $pdf->AddPage(); 135 136 $this->_pagehead($pdf, $fac); 137 138 $pdf->SetTitle($fac->ref); 139 $pdf->SetSubject($langs->trans("Bill")); 140 $pdf->SetCreator("Dolibarr ".DOL_VERSION); 141 $pdf->SetAuthor($user->fullname); 142 143 $pdf->SetMargins(10, 10, 10); 144 $pdf->SetAutoPageBreak(1,0); 145 146 $tab_top = $this->marges['h']+90; 147 $tab_height = 110; 148 149 $pdf->SetFillColor(220,220,220); 150 $pdf->SetFont('Arial','', 9); 151 $pdf->SetXY ($this->marges['g'], $tab_top + $this->marges['g'] ); 152 153 $iniY = $pdf->GetY(); 154 $curY = $pdf->GetY(); 155 $nexY = $pdf->GetY(); 156 $nblignes = sizeof($fac->lignes); 157 158 // Boucle sur les lignes de factures 159 for ($i = 0 ; $i < $nblignes ; $i++) 160 { 161 $curY = $nexY; 162 163 // Description produit 164 $codeproduitservice=""; 165 $pdf->SetXY ($this->marges['g']+ 1, $curY ); 166 if (defined("FACTURE_CODEPRODUITSERVICE") && FACTURE_CODEPRODUITSERVICE) { 167 // Affiche code produit si ligne associée à un code produit 168 169 $prodser = new Product($this->db); 170 171 $prodser->fetch($fac->lignes[$i]->produit_id); 172 if ($prodser->ref) { 173 $codeproduitservice=" - ".$langs->trans("ProductCode")." ".$prodser->ref; 174 } 175 } 176 if ($fac->lignes[$i]->date_start && $fac->lignes[$i]->date_end) { 177 // Affichage durée si il y en a une 178 $codeproduitservice.=" (".$langs->trans("From")." ".dolibarr_print_date($fac->lignes[$i]->date_start)." ".$langs->trans("to")." ".dolibarr_print_date($fac->lignes[$i]->date_end).")"; 179 } 180 $pdf->MultiCell(108, 5, $fac->lignes[$i]->desc."$codeproduitservice", 0, 'J'); 181 182 $nexY = $pdf->GetY(); 183 184 // TVA 185 if ($this->franchise!=1) 186 { 187 $pdf->SetXY ($this->marges['g']+119, $curY); 188 $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); 189 } 190 // Prix unitaire HT avant remise 191 $pdf->SetXY ($this->marges['g']+132, $curY); 192 $pdf->MultiCell(16, 5, price($fac->lignes[$i]->subprice), 0, 'R', 0); 193 194 // Quantité 195 $pdf->SetXY ($this->marges['g']+150, $curY); 196 $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'R'); 197 198 // Remise sur ligne 199 $pdf->SetXY ($this->marges['g']+160, $curY); 200 if ($fac->lignes[$i]->remise_percent) { 201 $pdf->MultiCell(14, 5, $fac->lignes[$i]->remise_percent."%", 0, 'R'); 202 } 203 204 // Total HT 205 $pdf->SetXY ($this->marges['g']+168, $curY); 206 $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); 207 $pdf->MultiCell(21, 5, $total, 0, 'R', 0); 208 209 210 if ($nexY > 200 && $i < $nblignes - 1) 211 { 212 $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $fac); 213 $pdf->AddPage(); 214 $nexY = $iniY; 215 $this->_pagehead($pdf, $fac); 216 $pdf->SetTextColor(0,0,0); 217 $pdf->SetFont('Arial','', 10); 218 } 219 220 } 221 $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $fac); 222 223 $deja_regle = $fac->getSommePaiement(); 224 225 $this->_tableau_tot($pdf, $fac, $deja_regle); 226 227 if ($deja_regle) { 228 $this->_tableau_versements($pdf, $fac); 229 } 230 231 /* 232 * Mode de règlement 233 */ 234 if ((! defined("FACTURE_CHQ_NUMBER") || ! FACTURE_CHQ_NUMBER) && (! defined("FACTURE_RIB_NUMBER") || ! FACTURE_RIB_NUMBER)) { 235 $pdf->SetXY ($this->marges['g'], 228); 236 $pdf->SetTextColor(200,0,0); 237 $pdf->SetFont('Arial','B',8); 238 $pdf->MultiCell(90, 3, $langs->trans("ErrorNoPaiementModeConfigured"),0,'L',0); 239 $pdf->MultiCell(90, 3, $langs->trans("ErrorCreateBankAccount"),0,'L',0); 240 $pdf->SetTextColor(0,0,0); 241 } 242 243 /* 244 * Propose mode règlement par CHQ 245 */ 246 if (defined("FACTURE_CHQ_NUMBER")) 247 { 248 if (FACTURE_CHQ_NUMBER > 0) 249 { 250 $account = new Account($this->db); 251 $account->fetch(FACTURE_CHQ_NUMBER); 252 253 $pdf->SetXY ($this->marges['g'], 225); 254 $pdf->SetFont('Arial','B',8); 255 $pdf->MultiCell(90, 3, "Règlement par chèque à l'ordre de ".$account->proprio." envoyé à:",0,'L',0); 256 $pdf->SetXY ($this->marges['g'], 230); 257 $pdf->SetFont('Arial','',8); 258 $pdf->MultiCell(80, 3, $account->adresse_proprio, 0, 'L', 0); 259 } 260 } 261 262 /* 263 * Propose mode règlement par RIB 264 */ 265 if (defined("FACTURE_RIB_NUMBER")) 266 { 267 if (FACTURE_RIB_NUMBER > 0) 268 { 269 $account = new Account($this->db); 270 $account->fetch(FACTURE_RIB_NUMBER); 271 272 $cury=240; 273 $pdf->SetXY ($this->marges['g'], $cury); 274 $pdf->SetFont('Arial','B',8); 275 $pdf->MultiCell(90, 3, "Règlement par virement sur le compte ci-dessous:", 0, 'L', 0); 276 $cury=245; 277 $pdf->SetFont('Arial','B',6); 278 $pdf->line($this->marges['g'], $cury, $this->marges['g'], $cury+10 ); 279 $pdf->SetXY ($this->marges['g'], $cury); 280 $pdf->MultiCell(18, 3, "Code banque", 0, 'C', 0); 281 $pdf->line($this->marges['g']+18, $cury, $this->marges['g']+18, $cury+10 ); 282 $pdf->SetXY ($this->marges['g']+18, $cury); 283 $pdf->MultiCell(18, 3, "Code guichet", 0, 'C', 0); 284 $pdf->line($this->marges['g']+36, $cury, $this->marges['g']+36, $cury+10 ); 285 $pdf->SetXY ($this->marges['g']+36, $cury); 286 $pdf->MultiCell(24, 3, "Numéro compte", 0, 'C', 0); 287 $pdf->line($this->marges['g']+60, $cury, $this->marges['g']+60, $cury+10 ); 288 $pdf->SetXY ($this->marges['g']+60, $cury); 289 $pdf->MultiCell(13, 3, "Clé RIB", 0, 'C', 0); 290 $pdf->line($this->marges['g']+73, $cury, $this->marges['g']+73, $cury+10 ); 291 292 $pdf->SetFont('Arial','',8); 293 $pdf->SetXY ($this->marges['g'], $cury+5); 294 $pdf->MultiCell(18, 3, $account->code_banque, 0, 'C', 0); 295 $pdf->SetXY ($this->marges['g']+18, $cury+5); 296 $pdf->MultiCell(18, 3, $account->code_guichet, 0, 'C', 0); 297 $pdf->SetXY ($this->marges['g']+36, $cury+5); 298 $pdf->MultiCell(24, 3, $account->number, 0, 'C', 0); 299 $pdf->SetXY ($this->marges['g']+60, $cury+5); 300 $pdf->MultiCell(13, 3, $account->cle_rib, 0, 'C', 0); 301 302 $pdf->SetXY ($this->marges['g'], $cury+15); 303 $pdf->MultiCell(90, 3, "Domiciliation : " . $account->domiciliation, 0, 'L', 0); 304 $pdf->SetXY ($this->marges['g'], $cury+25); 305 $pdf->MultiCell(90, 3, "Prefix IBAN : " . $account->iban_prefix, 0, 'L', 0); 306 $pdf->SetXY ($this->marges['g'], $cury+30); 307 $pdf->MultiCell(90, 3, "BIC : " . $account->bic, 0, 'L', 0); 308 } 309 } 310 311 /* 312 * Conditions de règlements 313 */ 314 $pdf->SetFont('Arial','B',10); 315 $pdf->SetXY($this->marges['g'], 217); 316 $titre = "Conditions de réglement:"; 317 $pdf->MultiCell(80, 5, $titre, 0, 'L'); 318 $pdf->SetFont('Arial','',10); 319 $pdf->SetXY($this->marges['g']+44, 217); 320 $pdf->MultiCell(80, 5, $fac->cond_reglement_facture,0,'L'); 321 322 323 /* 324 * Pied de page 325 */ 326 $this->_pagefoot($pdf, $fac); 327 $pdf->AliasNbPages(); 328 329 $pdf->Close(); 330 331 $pdf->Output($file); 332 333 return 1; // Pas d'erreur 334 } 335 else 336 { 337 $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); 338 return 0; 339 } 340 } 341 else 342 { 343 $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); 344 return 0; 345 } 346 $this->error=$langs->trans("ErrorUnknown"); 347 return 0; // Erreur par defaut 348 } 349 350 351 /* 352 * \brief Affiche tableau des versement 353 * \param pdf objet PDF 354 * \param fac objet facture 355 */ 356 function _tableau_versements(&$pdf, $fac) 357 { 358 global $langs; 359 $langs->load("main"); 360 $langs->load("bills"); 361 362 $tab3_posx = $this->marges['g']+110; 363 $tab3_top = $this->marges['h']+235; 364 $tab3_width = 80; 365 $tab3_height = 4; 366 367 $pdf->SetFont('Arial','',8); 368 $pdf->SetXY ($tab3_posx, $tab3_top - 5); 369 $pdf->MultiCell(60, 5, "Versements déjà effectués", 0, 'L', 0); 370 371 $pdf->Rect($tab3_posx, $tab3_top-1, $tab3_width, $tab3_height); 372 373 $pdf->SetXY ($tab3_posx, $tab3_top-1 ); 374 $pdf->MultiCell(20, 4, $langs->trans("Payment"), 0, 'L', 0); 375 $pdf->SetXY ($tab3_posx+21, $tab3_top-1 ); 376 $pdf->MultiCell(20, 4, $langs->trans("Amount"), 0, 'L', 0); 377 $pdf->SetXY ($tab3_posx+41, $tab3_top-1 ); 378 $pdf->MultiCell(20, 4, $langs->trans("Type"), 0, 'L', 0); 379 $pdf->SetXY ($tab3_posx+60, $tab3_top-1 ); 380 $pdf->MultiCell(20, 4, $langs->trans("Ref"), 0, 'L', 0); 381 382 $sql = "SELECT ".$this->db->pdate("p.datep")."as date, p.amount as amount, p.fk_paiement as type, p.num_paiement as num "; 383 $sql.= "FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."paiement_facture as pf "; 384 $sql.= "WHERE pf.fk_paiement = p.rowid and pf.fk_facture = ".$fac->id." "; 385 $sql.= "ORDER BY p.datep"; 386 if ($this->db->query($sql)) 387 { 388 $pdf->SetFont('Arial','',6); 389 $num = $this->db->num_rows(); 390 $i=0; $y=0; 391 while ($i < $num) { 392 $y+=3; 393 $row = $this->db->fetch_row(); 394 395 $pdf->SetXY ($tab3_posx, $tab3_top+$y ); 396 $pdf->MultiCell(20, 4, strftime("%d/%m/%y",$row[0]), 0, 'L', 0); 397 $pdf->SetXY ($tab3_posx+21, $tab3_top+$y); 398 $pdf->MultiCell(20, 4, $row[1], 0, 'L', 0); 399 $pdf->SetXY ($tab3_posx+41, $tab3_top+$y); 400 switch ($row[2]) 401 { 402 case 1: 403 $oper = 'TIP'; 404 break; 405 case 2: 406 $oper = 'VIR'; 407 break; 408 case 3: 409 $oper = 'PRE'; 410 break; 411 case 4: 412 $oper = 'LIQ'; 413 break; 414 case 5: 415 $oper = 'VAD'; 416 break; 417 case 6: 418 $oper = 'CB'; 419 break; 420 case 7: 421 $oper = 'CHQ'; 422 break; 423 } 424 $pdf->MultiCell(20, 4, $oper, 0, 'L', 0); 425 $pdf->SetXY ($tab3_posx+60, $tab3_top+$y); 426 $pdf->MultiCell(20, 4, $row[3], 0, 'L', 0); 427 428 $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3 ); 429 430 $i++; 431 } 432 } 433 else 434 { 435 $this->error=$langs->trans("ErrorSQL")." $sql"; 436 return 0; 437 } 438 439 } 440 441 /* 442 * \brief Affiche le total à payer 443 * \param pdf objet PDF 444 * \param fac objet facture 445 * \param deja_regle montant deja regle 446 */ 447 function _tableau_tot(&$pdf, $fac, $deja_regle) 448 { 449 global $langs; 450 $langs->load("main"); 451 $langs->load("bills"); 452 453 $tab2_top = $this->marges['h']+202; 454 $tab2_hl = 5; 455 $tab2_height = $tab2_hl * 4; 456 $pdf->SetFont('Arial','', 9); 457 458 // Affiche la mention TVA non applicable selon option 459 $pdf->SetXY ($this->marges['g'], $tab2_top + 0); 460 if ($this->franchise==1) 461 { 462 $pdf->MultiCell(100, $tab2_hl, "* TVA non applicable art-293B du CGI", 0, 'L', 0); 463 } 464 465 // Tableau total 466 $col1x=$this->marges['g']+110; $col2x=$this->marges['g']+164; 467 $pdf->SetXY ($col1x, $tab2_top + 0); 468 $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalHT"), 0, 'L', 0); 469 470 $pdf->SetXY ($col2x, $tab2_top + 0); 471 $pdf->MultiCell(26, $tab2_hl, price($fac->total_ht + $fac->remise), 0, 'R', 0); 472 473 if ($fac->remise > 0) 474 { 475 $pdf->SetXY ($col1x, $tab2_top + $tab2_hl); 476 $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("GlobalDiscount"), 0, 'L', 0); 477 478 $pdf->SetXY ($col2x, $tab2_top + $tab2_hl); 479 $pdf->MultiCell(26, $tab2_hl, "-".$fac->remise_percent."%", 0, 'R', 0); 480 481 $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * 2); 482 $pdf->MultiCell($col2x-$col1x, $tab2_hl, "Total HT après remise", 0, 'L', 0); 483 484 $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * 2); 485 $pdf->MultiCell(26, $tab2_hl, price($fac->total_ht), 0, 'R', 0); 486 487 $index = 3; 488 } 489 else 490 { 491 $index = 1; 492 } 493 494 $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); 495 $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalVAT"), 0, 'L', 0); 496 497 $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); 498 $pdf->MultiCell(26, $tab2_hl, price($fac->total_tva), 0, 'R', 0); 499 500 $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * ($index+1)); 501 $pdf->SetTextColor(22,137,210); 502 $pdf->SetFont('Arial','B', 11); 503 $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalTTC"), 0, 'L', 0); 504 505 $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * ($index+1)); 506 $pdf->MultiCell(26, $tab2_hl, price($fac->total_ttc), 0, 'R', 0); 507 $pdf->SetTextColor(0,0,0); 508 509 if ($deja_regle > 0) 510 { 511 $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * ($index+2)); 512 $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("AlreadyPayed"), 0, 'L', 0); 513 514 $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * ($index+2)); 515 $pdf->MultiCell(26, $tab2_hl, price($deja_regle), 0, 'R', 0); 516 517 $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * ($index+3)); 518 $pdf->SetTextColor(22,137,210); 519 $pdf->SetFont('Arial','B', 11); 520 $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("RemainderToPay"), 0, 'L', 0); 521 522 $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * ($index+3)); 523 $pdf->MultiCell(26, $tab2_hl, price($fac->total_ttc - $deja_regle), 0, 'R', 0); 524 $pdf->SetTextColor(0,0,0); 525 } 526 } 527 528 /* 529 * \brief Affiche la grille des lignes de factures 530 * \param pdf objet PDF 531 */ 532 function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $fac) 533 { 534 global $langs; 535 $langs->load("main"); 536 $langs->load("bills"); 537 538 $pdf->line( $this->marges['g'], $tab_top+8, 210-$this->marges['d'], $tab_top+8 ); 539 $pdf->line( $this->marges['g'], $tab_top + $tab_height, 210-$this->marges['d'], $tab_top + $tab_height ); 540 541 $pdf->SetFont('Arial','B',10); 542 543 $pdf->Text($this->marges['g']+2,$tab_top + 5, $langs->trans("Designation")); 544 if ($this->franchise!=1) $pdf->Text($this->marges['g']+120, $tab_top + 5, $langs->trans("VAT")); 545 $pdf->Text($this->marges['g']+135, $tab_top + 5,$langs->trans("PriceUHT")); 546 $pdf->Text($this->marges['g']+153, $tab_top + 5, $langs->trans("Qty")); 547 548 $nblignes = sizeof($fac->lignes); 549 $rem=0; 550 for ($i = 0 ; $i < $nblignes ; $i++) 551 if ($fac->lignes[$i]->remise_percent) 552 { 553 $rem=1; 554 } 555 if ($rem==1) 556 { 557 $pdf->Text($this->marges['g']+163, $tab_top + 5,'Rem.'); 558 } 559 $pdf->Text($this->marges['g']+175, $tab_top + 5, $langs->trans("TotalHT")); 560 } 561 562 /* 563 * \brief Affiche en-tête facture 564 * \param pdf objet PDF 565 * \param fac objet facture 566 */ 567 function _pagehead(&$pdf, $fac) 568 { 569 global $langs,$conf; 570 $langs->load("main"); 571 $langs->load("bills"); 572 $langs->load("propal"); 573 $langs->load("companies"); 574 575 $pdf->SetTextColor(0,0,60); 576 $pdf->SetFont('Arial','B',13); 577 578 $pdf->SetXY($this->marges['g'],6); 579 580 // Logo 581 if (defined("FAC_PDF_LOGO") && FAC_PDF_LOGO) $logo=DOL_DATA_ROOT.FAC_PDF_LOGO; 582 if ($logo) 583 { 584 if (is_readable($logo)) 585 { 586 $taille=getimagesize($logo); 587 $longueur=$taille[0]/2.835; 588 $pdf->Image($logo, $this->marges['g'], $this->marges['h'], 0, 24); 589 } 590 else 591 { 592 $pdf->SetTextColor(200,0,0); 593 $pdf->SetFont('Arial','B',8); 594 $pdf->MultiCell(80, 3, $langs->trans("ErrorLogoFileNotFound",$logo), 0, 'L'); 595 $pdf->MultiCell(80, 3, $langs->trans("ErrorGoToModuleSetup"), 0, 'L'); 596 } 597 } 598 else if (defined("FAC_PDF_INTITULE")) 599 { 600 $pdf->MultiCell(80, 6, FAC_PDF_INTITULE, 0, 'L'); 601 } 602 603 604 /* 605 * Emetteur 606 */ 607 $posy=$this->marges['h']+24; 608 $pdf->SetTextColor(0,0,0); 609 $pdf->SetFont('Arial','',8); 610 $pdf->SetXY($this->marges['g'],$posy-5); 611 612 613 $pdf->SetXY($this->marges['g'],$posy); 614 $pdf->SetFillColor(255,255,255); 615 $pdf->MultiCell(82, 34, "", 0, 'R', 1); 616 617 618 $pdf->SetXY($this->marges['g'],$posy+4); 619 620 // Nom emetteur 621 $pdf->SetTextColor(0,0,60); 622 $pdf->SetFont('Arial','B',12); 623 if (defined("FAC_PDF_SOCIETE_NOM") && FAC_PDF_SOCIETE_NOM) // Prioritaire sur MAIN_INFO_SOCIETE_NOM 624 { 625 $pdf->MultiCell(80, 4, FAC_PDF_SOCIETE_NOM, 0, 'L'); 626 } 627 else // Par defaut 628 { 629 $pdf->MultiCell(80, 4, MAIN_INFO_SOCIETE_NOM, 0, 'L'); 630 } 631 632 // Caractéristiques emetteur 633 $pdf->SetFont('Arial','',9); 634 if (defined("FAC_PDF_ADRESSE")) 635 { 636 $pdf->MultiCell(80, 4, FAC_PDF_ADRESSE); 637 } 638 if (defined("FAC_PDF_TEL") && FAC_PDF_TEL) 639 { 640 $pdf->MultiCell(80, 4, $langs->trans("Phone").": ".FAC_PDF_TEL); 641 } 642 if (defined("FAC_PDF_MEL") && FAC_PDF_MEL) 643 { 644 $pdf->MultiCell(80, 4, $langs->trans("Email").": ".FAC_PDF_MEL); 645 } 646 if (defined("FAC_PDF_WWW") && FAC_PDF_WWW) 647 { 648 $pdf->MultiCell(80, 4, $langs->trans("Web").": ".FAC_PDF_WWW); 649 } 650 651 $pdf->SetFont('Arial','',7); 652 if (defined("MAIN_INFO_SIREN") && MAIN_INFO_SIREN) 653 { 654 $pdf->MultiCell(80, 4, $langs->transcountry("ProfId1",$this->code_pays).": ".MAIN_INFO_SIREN); 655 } 656 elseif (defined("MAIN_INFO_SIRET") && MAIN_INFO_SIRET) 657 { 658 $pdf->MultiCell(80, 4, $langs->transcountry("ProfId2",$this->code_pays).": ".MAIN_INFO_SIRET); 659 } 660 661 662 /* 663 * Client 664 */ 665 $posy=45; 666 $pdf->SetTextColor(0,0,0); 667 $pdf->SetFont('Arial','',8); 668 $pdf->SetXY($this->marges['g']+100,$posy-5); 669 $pdf->SetFont('Arial','B',11); 670 $fac->fetch_client(); 671 $pdf->SetXY($this->marges['g']+100,$posy+4); 672 $pdf->MultiCell(86,4, $fac->client->nom, 0, 'L'); 673 $pdf->SetFont('Arial','B',10); 674 $pdf->SetXY($this->marges['g']+100,$posy+12); 675 $pdf->MultiCell(86,4, $fac->client->adresse . "\n\n" . $fac->client->cp . " " . $fac->client->ville); 676 677 /* 678 * ref facture 679 */ 680 $posy=65; 681 $pdf->SetFont('Arial','B',13); 682 $pdf->SetXY($this->marges['g'],$posy); 683 $pdf->SetTextColor(0,0,0); 684 $pdf->MultiCell(100, 10, $langs->trans("Bill")." du ".dolibarr_print_date($fac->date,"%d %B %Y"), '' , 'L'); 685 $pdf->SetFont('Arial','B',11); 686 $pdf->SetXY($this->marges['g'],$posy+6); 687 $pdf->SetTextColor(22,137,210); 688 $pdf->MultiCell(100, 10, $langs->trans("RefBill")." : " . $fac->ref, '', 'L'); 689 $pdf->SetTextColor(0,0,0); 690 691 /* 692 * ref projet 693 */ 694 if ($fac->projetid > 0) 695 { 696 $projet = New Project($fac->db); 697 $projet->fetch($fac->projetid); 698 $pdf->SetFont('Arial','',9); 699 $pdf->MultiCell(60, 4, $langs->trans("Project")." : ".$projet->title); 700 } 701 702 /* 703 * ref propal 704 */ 705 $sql = "SELECT ".$fac->db->pdate("p.datep")." as dp, p.ref, p.rowid as propalid"; 706 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $fac->id"; 707 $result = $fac->db->query($sql); 708 if ($result) 709 { 710 $objp = $fac->db->fetch_object(); 711 $pdf->SetFont('Arial','',9); 712 $pdf->MultiCell(60, 4, $langs->trans("RefProposal")." : ".$objp->ref); 713 } 714 715 /* 716 * monnaie 717 */ 718 $pdf->SetTextColor(0,0,0); 719 $pdf->SetFont('Arial','',10); 720 $titre = $langs->trans("AmountInCurrency",$langs->trans("Currency".$conf->monnaie)); 721 $pdf->Text(200 - $pdf->GetStringWidth($titre), 94, $titre); 722 /* 723 */ 724 725 } 726 727 /* 728 * \brief Affiche le pied de page de la facture 729 * \param pdf objet PDF 730 * \param fac objet facture 731 */ 732 function _pagefoot(&$pdf, $fac) 733 { 734 global $langs, $conf; 735 $langs->load("main"); 736 $langs->load("bills"); 737 $langs->load("companies"); 738 739 $footy=13; 740 $pdf->SetFont('Arial','',8); 741 742 $ligne=""; 743 if (defined('MAIN_INFO_CAPITAL') && MAIN_INFO_CAPITAL) { 744 $ligne="SARL au Capital de " . MAIN_INFO_CAPITAL." ".$langs->trans("Currency".$conf->monnaie); 745 } 746 if (defined('MAIN_INFO_SIREN') && MAIN_INFO_SIREN) { 747 $ligne.=($ligne?" - ":"").$langs->transcountry("ProfId1",$this->code_pays).": ".MAIN_INFO_SIREN; 748 } 749 if (defined('MAIN_INFO_SIRET') && MAIN_INFO_SIRET) { 750 $ligne.=($ligne?" - ":"").$langs->transcountry("ProfId2",$this->code_pays).": ".MAIN_INFO_SIRET; 751 } 752 if (defined('MAIN_INFO_RCS') && MAIN_INFO_RCS) { 753 $ligne.=($ligne?" - ":"").$langs->transcountry("ProfId4",$this->code_pays).": ".MAIN_INFO_RCS; 754 } 755 if ($ligne) { 756 $pdf->SetY(-$footy); 757 $pdf->MultiCell(190, 3, $ligne, 0, 'C'); 758 $footy-=3; 759 } 760 761 // Affiche le numéro de TVA intracommunautaire 762 if (MAIN_INFO_TVAINTRA == 'MAIN_INFO_TVAINTRA') { 763 $pdf->SetY(-$footy); 764 $pdf->SetTextColor(200,0,0); 765 $pdf->SetFont('Arial','B',8); 766 $pdf->MultiCell(190, 3, $langs->trans("ErrorVATIntraNotConfigured"),0,'L',0); 767 $pdf->MultiCell(190, 3, $langs->trans("ErrorGoToGlobalSetup"),0,'L',0); 768 $pdf->SetTextColor(0,0,0); 769 } 770 elseif (MAIN_INFO_TVAINTRA != '') { 771 $pdf->SetY(-$footy); 772 $pdf->MultiCell(190, 3, $langs->trans("TVAIntra")." : ".MAIN_INFO_TVAINTRA, 0, 'C'); 773 } 774 775 $pdf->SetXY(-15,-15); 776 $pdf->MultiCell(10, 3, $pdf->PageNo().'/{nb}', 0, 'R'); 777 } 778 779 } 780 781 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |