pdf_crabe.modules.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. <?php
  2. /* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  4. * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
  5. * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. * or see http://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/includes/modules/facture/doc/pdf_crabe.modules.php
  23. * \ingroup facture
  24. * \brief File of class to generate invoices from crab model
  25. * \author Laurent Destailleur
  26. */
  27. require_once(DOL_DOCUMENT_ROOT."/includes/modules/facture/modules_facture.php");
  28. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
  31. require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php');
  32. /**
  33. * \class pdf_crabe
  34. * \brief Classe permettant de generer les factures au modele Crabe
  35. */
  36. class pdf_crabe extends ModelePDFFactures
  37. {
  38. var $db;
  39. var $name;
  40. var $description;
  41. var $type;
  42. var $phpmin = array(4,3,0); // Minimum version of PHP required by module
  43. var $version = 'dolibarr';
  44. var $page_largeur;
  45. var $page_hauteur;
  46. var $format;
  47. var $marge_gauche;
  48. var $marge_droite;
  49. var $marge_haute;
  50. var $marge_basse;
  51. var $emetteur; // Objet societe qui emet
  52. /**
  53. * Constructor
  54. *
  55. * @param DoliDB $DB Database handler
  56. */
  57. function pdf_crabe($db)
  58. {
  59. global $conf,$langs,$mysoc;
  60. $langs->load("main");
  61. $langs->load("bills");
  62. $this->db = $db;
  63. $this->name = "crabe";
  64. $this->description = $langs->trans('PDFCrabeDescription');
  65. // Dimension page pour format A4
  66. $this->type = 'pdf';
  67. $formatarray=pdf_getFormat();
  68. $this->page_largeur = $formatarray['width'];
  69. $this->page_hauteur = $formatarray['height'];
  70. $this->format = array($this->page_largeur,$this->page_hauteur);
  71. $this->marge_gauche=10;
  72. $this->marge_droite=10;
  73. $this->marge_haute=10;
  74. $this->marge_basse=10;
  75. $this->option_logo = 1; // Affiche logo
  76. $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
  77. $this->option_modereg = 1; // Affiche mode reglement
  78. $this->option_condreg = 1; // Affiche conditions reglement
  79. $this->option_codeproduitservice = 1; // Affiche code produit-service
  80. $this->option_multilang = 1; // Dispo en plusieurs langues
  81. $this->option_escompte = 1; // Affiche si il y a eu escompte
  82. $this->option_credit_note = 1; // Support credit notes
  83. $this->option_freetext = 1; // Support add of a personalised text
  84. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  85. $this->franchise=!$mysoc->tva_assuj;
  86. // Get source company
  87. $this->emetteur=$mysoc;
  88. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // By default, if was not defined
  89. // Defini position des colonnes
  90. $this->posxdesc=$this->marge_gauche+1;
  91. $this->posxtva=111;
  92. $this->posxup=126;
  93. $this->posxqty=145;
  94. $this->posxdiscount=162;
  95. $this->postotalht=174;
  96. $this->tva=array();
  97. $this->localtax1=array();
  98. $this->localtax2=array();
  99. $this->atleastoneratenotnull=0;
  100. $this->atleastonediscount=0;
  101. }
  102. /**
  103. * Function to build pdf onto disk
  104. *
  105. * @param int $object Id of object to generate
  106. * @param object $outputlangs Lang output object
  107. * @param string $srctemplatepath Full path of source filename for generator using a template file
  108. * @param int $hidedetails Do not show line details
  109. * @param int $hidedesc Do not show desc
  110. * @param int $hideref Do not show ref
  111. * @param object $hookmanager Hookmanager object
  112. * @return int 1=OK, 0=KO
  113. */
  114. function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false)
  115. {
  116. global $user,$langs,$conf;
  117. if (! is_object($outputlangs)) $outputlangs=$langs;
  118. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  119. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  120. $outputlangs->load("main");
  121. $outputlangs->load("dict");
  122. $outputlangs->load("companies");
  123. $outputlangs->load("bills");
  124. $outputlangs->load("products");
  125. $default_font_size = pdf_getPDFFontSize($outputlangs);
  126. if ($conf->facture->dir_output)
  127. {
  128. $object->fetch_thirdparty();
  129. $deja_regle = $object->getSommePaiement();
  130. $amount_credit_notes_included = $object->getSumCreditNotesUsed();
  131. $amount_deposits_included = $object->getSumDepositsUsed();
  132. // Definition of $dir and $file
  133. if ($object->specimen)
  134. {
  135. $dir = $conf->facture->dir_output;
  136. $file = $dir . "/SPECIMEN.pdf";
  137. }
  138. else
  139. {
  140. $objectref = dol_sanitizeFileName($object->ref);
  141. $dir = $conf->facture->dir_output . "/" . $objectref;
  142. $file = $dir . "/" . $objectref . ".pdf";
  143. }
  144. if (! file_exists($dir))
  145. {
  146. if (create_exdir($dir) < 0)
  147. {
  148. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  149. return 0;
  150. }
  151. }
  152. if (file_exists($dir))
  153. {
  154. $nblignes = count($object->lines);
  155. $pdf=pdf_getInstance($this->format);
  156. if (class_exists('TCPDF'))
  157. {
  158. $pdf->setPrintHeader(false);
  159. $pdf->setPrintFooter(false);
  160. }
  161. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  162. $pdf->Open();
  163. $pagenb=0;
  164. $pdf->SetDrawColor(128,128,128);
  165. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  166. $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
  167. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  168. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  169. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Invoice"));
  170. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  171. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  172. $pdf->SetAutoPageBreak(1,0);
  173. // Positionne $this->atleastonediscount si on a au moins une remise
  174. for ($i = 0 ; $i < $nblignes ; $i++)
  175. {
  176. if ($object->lines[$i]->remise_percent)
  177. {
  178. $this->atleastonediscount++;
  179. }
  180. }
  181. // New page
  182. $pdf->AddPage();
  183. $pagenb++;
  184. $this->_pagehead($pdf, $object, 1, $outputlangs);
  185. $pdf->SetFont('','', $default_font_size - 1);
  186. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  187. $pdf->SetTextColor(0,0,0);
  188. $tab_top = 90;
  189. $tab_top_newpage = 50;
  190. $tab_height = 110;
  191. $tab_height_newpage = 150;
  192. // Affiche notes
  193. if (! empty($object->note_public))
  194. {
  195. $tab_top = 88;
  196. $pdf->SetFont('','', $default_font_size - 1);
  197. $pdf->SetXY($this->posxdesc-1, $tab_top);
  198. //$pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'J', false, 1, '', '', true, 0, false, false, 0, 'T', true);
  199. $pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'L'); // FPDF
  200. $nexY = $pdf->GetY();
  201. $height_note=$nexY-$tab_top;
  202. // Rect prend une longueur en 3eme param
  203. $pdf->SetDrawColor(192,192,192);
  204. //print $pdf->getStringHeight(200,'SPECIMEN',false,false);
  205. //print "$this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1";exit;
  206. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  207. $tab_height = $tab_height - $height_note;
  208. $tab_top = $nexY+6;
  209. }
  210. else
  211. {
  212. $height_note=0;
  213. }
  214. $iniY = $tab_top + 7;
  215. $curY = $tab_top + 7;
  216. $nexY = $tab_top + 7;
  217. // Loop on each lines
  218. for ($i = 0 ; $i < $nblignes ; $i++)
  219. {
  220. $curY = $nexY;
  221. // Description of product line
  222. $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
  223. $curX = $this->posxdesc-1;
  224. pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc,0,$hookmanager);
  225. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  226. $nexY = $pdf->GetY();
  227. // VAT Rate
  228. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  229. {
  230. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager);
  231. $pdf->SetXY($this->posxtva, $curY);
  232. $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
  233. }
  234. // Prix unitaire HT avant remise
  235. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
  236. $pdf->SetXY($this->posxup, $curY);
  237. $pdf->MultiCell($this->posxqty-$this->posxup-1, 3, $up_excl_tax, 0, 'R', 0);
  238. // Quantity
  239. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager);
  240. $pdf->SetXY($this->posxqty, $curY);
  241. $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $qty, 0, 'R'); // Enough for 6 chars
  242. // Discount
  243. if ($object->lines[$i]->remise_percent)
  244. {
  245. $pdf->SetXY($this->posxdiscount-2, $curY);
  246. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails, $hookmanager);
  247. $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
  248. }
  249. // Total HT ligne
  250. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
  251. $pdf->SetXY($this->postotalht, $curY);
  252. $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0);
  253. // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
  254. $tvaligne=$object->lines[$i]->total_tva;
  255. $localtax1ligne=$object->lines[$i]->total_localtax1;
  256. $localtax2ligne=$object->lines[$i]->total_localtax2;
  257. if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
  258. if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
  259. if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
  260. $vatrate=(string) $object->lines[$i]->tva_tx;
  261. $localtax1rate=(string) $object->lines[$i]->localtax1_tx;
  262. $localtax2rate=(string) $object->lines[$i]->localtax2_tx;
  263. if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
  264. $this->tva[$vatrate] += $tvaligne;
  265. $this->localtax1[$localtax1rate]+=$localtax1ligne;
  266. $this->localtax2[$localtax2rate]+=$localtax2ligne;
  267. $nexY+=2; // Passe espace entre les lignes
  268. // Cherche nombre de lignes a venir pour savoir si place suffisante
  269. if ($i < ($nblignes - 1) && empty($hidedesc)) // If it's not last line
  270. {
  271. //on recupere la description du produit suivant
  272. $follow_descproduitservice = $object->lines[$i+1]->desc;
  273. //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
  274. $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4;
  275. // Et si on affiche dates de validite, on ajoute encore une ligne
  276. if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
  277. {
  278. $nblineFollowDesc += 4;
  279. }
  280. }
  281. else // If it's last line
  282. {
  283. $nblineFollowDesc = 0;
  284. }
  285. // Test if a new page is required
  286. if ($pagenb == 1)
  287. {
  288. $tab_top_in_current_page=$tab_top;
  289. $tab_height_in_current_page=$tab_height;
  290. }
  291. else
  292. {
  293. $tab_top_in_current_page=$tab_top_newpage;
  294. $tab_height_in_current_page=$tab_height_newpage;
  295. }
  296. if (($nexY+$nblineFollowDesc) > ($tab_top_in_current_page+$tab_height_in_current_page) && $i < ($nblignes - 1))
  297. {
  298. if ($pagenb == 1)
  299. {
  300. $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
  301. }
  302. else
  303. {
  304. $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
  305. }
  306. $this->_pagefoot($pdf,$object,$outputlangs);
  307. // New page
  308. $pdf->AddPage();
  309. $pagenb++;
  310. $this->_pagehead($pdf, $object, 0, $outputlangs);
  311. $pdf->SetFont('','', $default_font_size - 1);
  312. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  313. $pdf->SetTextColor(0,0,0);
  314. $nexY = $tab_top_newpage + 7;
  315. }
  316. }
  317. // Show square
  318. if ($pagenb == 1)
  319. {
  320. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
  321. $bottomlasttab=$tab_top + $tab_height + 1;
  322. }
  323. else
  324. {
  325. $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
  326. $bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1;
  327. }
  328. // Affiche zone infos
  329. $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
  330. // Affiche zone totaux
  331. $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  332. // Affiche zone versements
  333. if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
  334. {
  335. $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
  336. }
  337. // Pied de page
  338. $this->_pagefoot($pdf,$object,$outputlangs);
  339. $pdf->AliasNbPages();
  340. $pdf->Close();
  341. $pdf->Output($file,'F');
  342. if (! empty($conf->global->MAIN_UMASK))
  343. @chmod($file, octdec($conf->global->MAIN_UMASK));
  344. return 1; // Pas d'erreur
  345. }
  346. else
  347. {
  348. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  349. return 0;
  350. }
  351. }
  352. else
  353. {
  354. $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR");
  355. return 0;
  356. }
  357. $this->error=$langs->trans("ErrorUnknown");
  358. return 0; // Erreur par defaut
  359. }
  360. /**
  361. * Show payments table
  362. *
  363. * @param pdf Object PDF
  364. * @param object Object invoice
  365. * @param posy Position y in PDF
  366. * @param outputlangs Object langs for output
  367. * @return int <0 if KO, >0 if OK
  368. */
  369. function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
  370. {
  371. $tab3_posx = 120;
  372. $tab3_top = $posy + 8;
  373. $tab3_width = 80;
  374. $tab3_height = 4;
  375. $default_font_size = pdf_getPDFFontSize($outputlangs);
  376. $pdf->SetFont('','', $default_font_size - 2);
  377. $pdf->SetXY($tab3_posx, $tab3_top - 5);
  378. $pdf->MultiCell(60, 5, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0);
  379. $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
  380. $pdf->SetFont('','', $default_font_size - 4);
  381. $pdf->SetXY($tab3_posx, $tab3_top );
  382. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
  383. $pdf->SetXY($tab3_posx+21, $tab3_top );
  384. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
  385. $pdf->SetXY($tab3_posx+40, $tab3_top );
  386. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
  387. $pdf->SetXY($tab3_posx+58, $tab3_top );
  388. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
  389. $y=0;
  390. $pdf->SetFont('','', $default_font_size - 4);
  391. // Loop on each deposits and credit notes included
  392. $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
  393. $sql.= " re.description, re.fk_facture_source, re.fk_facture_source,";
  394. $sql.= " f.type, f.datef";
  395. $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
  396. $sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
  397. $resql=$this->db->query($sql);
  398. if ($resql)
  399. {
  400. $num = $this->db->num_rows($resql);
  401. $i=0;
  402. $invoice=new Facture($this->db);
  403. while ($i < $num)
  404. {
  405. $y+=3;
  406. $obj = $this->db->fetch_object($resql);
  407. if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
  408. elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
  409. else $text=$outputlangs->trans("UnknownType");
  410. $invoice->fetch($obj->fk_facture_source);
  411. $pdf->SetXY($tab3_posx, $tab3_top+$y );
  412. $pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
  413. $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
  414. $pdf->MultiCell(20, 3, price($obj->amount_ttc), 0, 'L', 0);
  415. $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
  416. $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
  417. $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
  418. $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
  419. $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3 );
  420. $i++;
  421. }
  422. }
  423. else
  424. {
  425. $this->error=$this->db->lasterror();
  426. dol_syslog($this->db,$this->error, LOG_ERR);
  427. return -1;
  428. }
  429. // Loop on each payment
  430. $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount,";
  431. $sql.= " cp.code";
  432. $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
  433. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  434. $sql.= " WHERE pf.fk_paiement = p.rowid and pf.fk_facture = ".$object->id;
  435. $sql.= " ORDER BY p.datep";
  436. $resql=$this->db->query($sql);
  437. if ($resql)
  438. {
  439. $num = $this->db->num_rows($resql);
  440. $i=0;
  441. while ($i < $num) {
  442. $y+=3;
  443. $row = $this->db->fetch_object($resql);
  444. $pdf->SetXY($tab3_posx, $tab3_top+$y );
  445. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
  446. $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
  447. $pdf->MultiCell(20, 3, price($row->amount), 0, 'L', 0);
  448. $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
  449. $oper = $outputlangs->getTradFromKey("PaymentTypeShort" . $row->code);
  450. $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
  451. $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
  452. $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
  453. $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3 );
  454. $i++;
  455. }
  456. }
  457. else
  458. {
  459. $this->error=$this->db->lasterror();
  460. dol_syslog($this->db,$this->error, LOG_ERR);
  461. return -1;
  462. }
  463. }
  464. /**
  465. * Show other information
  466. *
  467. * @param pdf Objet PDF
  468. * @param object Objet facture
  469. * @param posy Position depart
  470. * @param outputlangs Objet langs
  471. * @return y Position pour suite
  472. */
  473. function _tableau_info(&$pdf, $object, $posy, $outputlangs)
  474. {
  475. global $conf;
  476. $default_font_size = pdf_getPDFFontSize($outputlangs);
  477. $pdf->SetFont('','', $default_font_size - 1);
  478. // If France, show VAT mention if not applicable
  479. if ($this->emetteur->pays_code == 'FR' && $this->franchise == 1)
  480. {
  481. $pdf->SetFont('','B', $default_font_size - 2);
  482. $pdf->SetXY($this->marge_gauche, $posy);
  483. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  484. $posy=$pdf->GetY()+4;
  485. }
  486. // Show payments conditions
  487. if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
  488. {
  489. $pdf->SetFont('','B', $default_font_size - 2);
  490. $pdf->SetXY($this->marge_gauche, $posy);
  491. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  492. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  493. $pdf->SetFont('','', $default_font_size - 2);
  494. $pdf->SetXY(52, $posy);
  495. $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
  496. $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
  497. $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
  498. $posy=$pdf->GetY()+3;
  499. }
  500. if ($object->type != 2)
  501. {
  502. // Check a payment mode is defined
  503. if (empty($object->mode_reglement_code)
  504. && ! $conf->global->FACTURE_CHQ_NUMBER
  505. && ! $conf->global->FACTURE_RIB_NUMBER)
  506. {
  507. $pdf->SetXY($this->marge_gauche, $posy);
  508. $pdf->SetTextColor(200,0,0);
  509. $pdf->SetFont('','B', $default_font_size - 2);
  510. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
  511. $pdf->SetTextColor(0,0,0);
  512. $posy=$pdf->GetY()+1;
  513. }
  514. // Show payment mode
  515. if ($object->mode_reglement_code
  516. && $object->mode_reglement_code != 'CHQ'
  517. && $object->mode_reglement_code != 'VIR')
  518. {
  519. $pdf->SetFont('','B', $default_font_size - 2);
  520. $pdf->SetXY($this->marge_gauche, $posy);
  521. $titre = $outputlangs->transnoentities("PaymentMode").':';
  522. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  523. $pdf->SetFont('','', $default_font_size - 2);
  524. $pdf->SetXY(50, $posy);
  525. $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
  526. $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
  527. $posy=$pdf->GetY()+2;
  528. }
  529. // Show payment mode CHQ
  530. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
  531. {
  532. // Si mode reglement non force ou si force a CHQ
  533. if ($conf->global->FACTURE_CHQ_NUMBER)
  534. {
  535. if ($conf->global->FACTURE_CHQ_NUMBER > 0)
  536. {
  537. $account = new Account($this->db);
  538. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  539. $pdf->SetXY($this->marge_gauche, $posy);
  540. $pdf->SetFont('','B', $default_font_size - 2);
  541. $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio).':',0,'L',0);
  542. $posy=$pdf->GetY()+1;
  543. $pdf->SetXY($this->marge_gauche, $posy);
  544. $pdf->SetFont('','', $default_font_size - 2);
  545. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($account->adresse_proprio), 0, 'L', 0);
  546. $posy=$pdf->GetY()+2;
  547. }
  548. if ($conf->global->FACTURE_CHQ_NUMBER == -1)
  549. {
  550. $pdf->SetXY($this->marge_gauche, $posy);
  551. $pdf->SetFont('','B', $default_font_size - 2);
  552. $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedToShort').' '.$outputlangs->convToOutputCharset($this->emetteur->name).' '.$outputlangs->transnoentities('SendTo').':',0,'L',0);
  553. $posy=$pdf->GetY()+1;
  554. $pdf->SetXY($this->marge_gauche, $posy);
  555. $pdf->SetFont('','', $default_font_size - 2);
  556. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  557. $posy=$pdf->GetY()+2;
  558. }
  559. }
  560. }
  561. // If payment mode not forced or forced to VIR, show payment with BAN
  562. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
  563. {
  564. if (! empty($conf->global->FACTURE_RIB_NUMBER))
  565. {
  566. $account = new Account($this->db);
  567. $account->fetch($conf->global->FACTURE_RIB_NUMBER);
  568. $curx=$this->marge_gauche;
  569. $cury=$posy;
  570. $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account);
  571. $posy+=2;
  572. }
  573. }
  574. }
  575. return $posy;
  576. }
  577. /**
  578. * Show total to pay
  579. *
  580. * @param pdf Objet PDF
  581. * @param object Objet facture
  582. * @param deja_regle Montant deja regle
  583. * @param posy Position depart
  584. * @param outputlangs Objet langs
  585. * @return y Position pour suite
  586. */
  587. function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  588. {
  589. global $conf,$mysoc;
  590. $default_font_size = pdf_getPDFFontSize($outputlangs);
  591. $tab2_top = $posy;
  592. $tab2_hl = 4;
  593. $pdf->SetFont('','', $default_font_size - 1);
  594. // Tableau total
  595. $lltot = 200; $col1x = 120; $col2x = 170; $largcol2 = $lltot - $col2x;
  596. $useborder=0;
  597. $index = 0;
  598. // Total HT
  599. $pdf->SetFillColor(255,255,255);
  600. $pdf->SetXY($col1x, $tab2_top + 0);
  601. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  602. $pdf->SetXY($col2x, $tab2_top + 0);
  603. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + $object->remise), 0, 'R', 1);
  604. // Show VAT by rates and total
  605. $pdf->SetFillColor(248,248,248);
  606. $this->atleastoneratenotnull=0;
  607. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  608. {
  609. foreach( $this->tva as $tvakey => $tvaval )
  610. {
  611. if ($tvakey > 0) // On affiche pas taux 0
  612. {
  613. $this->atleastoneratenotnull++;
  614. $index++;
  615. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  616. $tvacompl='';
  617. if (preg_match('/\*/',$tvakey))
  618. {
  619. $tvakey=str_replace('*','',$tvakey);
  620. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  621. }
  622. $totalvat =$outputlangs->transnoentities("TotalVAT").' ';
  623. $totalvat.=vatrate($tvakey,1).$tvacompl;
  624. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  625. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  626. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  627. }
  628. }
  629. if (! $this->atleastoneratenotnull) // If no vat at all
  630. {
  631. $index++;
  632. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  633. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
  634. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  635. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
  636. // Total LocalTax1
  637. if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
  638. {
  639. $index++;
  640. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  641. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code), $useborder, 'L', 1);
  642. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  643. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
  644. }
  645. // Total LocalTax2
  646. if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
  647. {
  648. $index++;
  649. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  650. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code), $useborder, 'L', 1);
  651. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  652. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
  653. }
  654. }
  655. else
  656. {
  657. if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  658. {
  659. //Local tax 1
  660. foreach( $this->localtax1 as $tvakey => $tvaval )
  661. {
  662. if ($tvakey>0) // On affiche pas taux 0
  663. {
  664. //$this->atleastoneratenotnull++;
  665. $index++;
  666. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  667. $tvacompl='';
  668. if (preg_match('/\*/',$tvakey))
  669. {
  670. $tvakey=str_replace('*','',$tvakey);
  671. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  672. }
  673. $totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
  674. $totalvat.=vatrate($tvakey,1).$tvacompl;
  675. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  676. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  677. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  678. }
  679. }
  680. }
  681. if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  682. {
  683. //Local tax 2
  684. foreach( $this->localtax2 as $tvakey => $tvaval )
  685. {
  686. if ($tvakey>0) // On affiche pas taux 0
  687. {
  688. //$this->atleastoneratenotnull++;
  689. $index++;
  690. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  691. $tvacompl='';
  692. if (preg_match('/\*/',$tvakey))
  693. {
  694. $tvakey=str_replace('*','',$tvakey);
  695. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  696. }
  697. $totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
  698. $totalvat.=vatrate($tvakey,1).$tvacompl;
  699. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  700. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  701. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  702. }
  703. }
  704. }
  705. }
  706. }
  707. // Total TTC
  708. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  709. {
  710. $index++;
  711. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  712. $pdf->SetTextColor(0,0,60);
  713. $pdf->SetFillColor(224,224,224);
  714. $text=$outputlangs->transnoentities("TotalTTC");
  715. if ($object->type == 2) $text=$outputlangs->transnoentities("TotalTTCToYourCredit");
  716. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $text, $useborder, 'L', 1);
  717. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  718. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc), $useborder, 'R', 1);
  719. }
  720. $pdf->SetTextColor(0,0,0);
  721. $creditnoteamount=$object->getSumCreditNotesUsed();
  722. $depositsamount=$object->getSumDepositsUsed();
  723. //print "x".$creditnoteamount."-".$depositsamount;exit;
  724. $resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  725. if ($object->paye) $resteapayer=0;
  726. if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0)
  727. {
  728. // Already paid + Deposits
  729. $index++;
  730. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  731. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
  732. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  733. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount), 0, 'R', 0);
  734. // Credit note
  735. if ($creditnoteamount)
  736. {
  737. $index++;
  738. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  739. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
  740. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  741. $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0);
  742. }
  743. // Escompte
  744. if ($object->close_code == 'discount_vat')
  745. {
  746. $index++;
  747. $pdf->SetFillColor(255,255,255);
  748. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  749. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOffered"), $useborder, 'L', 1);
  750. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  751. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount), $useborder, 'R', 1);
  752. $resteapayer=0;
  753. }
  754. $index++;
  755. $pdf->SetTextColor(0,0,60);
  756. $pdf->SetFillColor(224,224,224);
  757. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  758. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
  759. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  760. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
  761. // Fin
  762. $pdf->SetFont('','', $default_font_size - 1);
  763. $pdf->SetTextColor(0,0,0);
  764. }
  765. $index++;
  766. return ($tab2_top + ($tab2_hl * $index));
  767. }
  768. /**
  769. * Affiche la grille des lignes de factures
  770. *
  771. * @param pdf objet PDF
  772. */
  773. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs)
  774. {
  775. global $conf;
  776. $default_font_size = pdf_getPDFFontSize($outputlangs);
  777. // Amount in (at tab_top - 1)
  778. $pdf->SetTextColor(0,0,0);
  779. $pdf->SetFont('','', $default_font_size - 2);
  780. $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->monnaie));
  781. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
  782. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  783. $pdf->SetDrawColor(128,128,128);
  784. // Rect prend une longueur en 3eme param et 4eme param
  785. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
  786. // line prend une position y en 2eme param et 4eme param
  787. $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);
  788. $pdf->SetFont('','', $default_font_size - 1);
  789. $pdf->SetXY($this->posxdesc-1, $tab_top+1);
  790. $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
  791. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  792. {
  793. $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
  794. $pdf->SetXY($this->posxtva-3, $tab_top+1);
  795. $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
  796. }
  797. $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
  798. $pdf->SetXY($this->posxup-1, $tab_top+1);
  799. $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
  800. $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
  801. $pdf->SetXY($this->posxqty-1, $tab_top+1);
  802. $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
  803. $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
  804. if ($this->atleastonediscount)
  805. {
  806. $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
  807. $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
  808. }
  809. if ($this->atleastonediscount)
  810. {
  811. $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
  812. }
  813. $pdf->SetXY($this->postotalht-1, $tab_top+1);
  814. $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
  815. }
  816. /**
  817. * Show header of page
  818. *
  819. * @param pdf Object PDF
  820. * @param object Object invoice
  821. * @param showaddress 0=no, 1=yes
  822. * @param outputlangs Object lang for output
  823. */
  824. function _pagehead(&$pdf, $object, $showaddress=1, $outputlangs)
  825. {
  826. global $conf,$langs;
  827. $outputlangs->load("main");
  828. $outputlangs->load("bills");
  829. $outputlangs->load("propal");
  830. $outputlangs->load("companies");
  831. $default_font_size = pdf_getPDFFontSize($outputlangs);
  832. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  833. if($object->statut==0 && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
  834. {
  835. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
  836. }
  837. $pdf->SetTextColor(0,0,60);
  838. $pdf->SetFont('','B', $default_font_size + 3);
  839. $posy=$this->marge_haute;
  840. $posx=$this->page_largeur-$this->marge_droite-100;
  841. $pdf->SetXY($this->marge_gauche,$posy);
  842. // Logo
  843. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  844. if ($this->emetteur->logo)
  845. {
  846. if (is_readable($logo))
  847. {
  848. $pdf->Image($logo, $this->marge_gauche, $posy, 0, 24); // width=0 (auto), max height=24
  849. }
  850. else
  851. {
  852. $pdf->SetTextColor(200,0,0);
  853. $pdf->SetFont('','B',$default_font_size - 2);
  854. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  855. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  856. }
  857. }
  858. else
  859. {
  860. $text=$this->emetteur->name;
  861. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  862. }
  863. $pdf->SetFont('','B', $default_font_size + 3);
  864. $pdf->SetXY($posx,$posy);
  865. $pdf->SetTextColor(0,0,60);
  866. $title=$outputlangs->transnoentities("Invoice");
  867. if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
  868. if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
  869. if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
  870. if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProFormat");
  871. $pdf->MultiCell(100, 4, $title, '', 'R');
  872. $pdf->SetFont('','B', $default_font_size + 2);
  873. $posy+=6;
  874. $pdf->SetXY($posx,$posy);
  875. $pdf->SetTextColor(0,0,60);
  876. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
  877. $posy+=2;
  878. $pdf->SetFont('','', $default_font_size - 1);
  879. $objectidnext=$object->getIdReplacingInvoice('validated');
  880. if ($object->type == 0 && $objectidnext)
  881. {
  882. $objectreplacing=new Facture($this->db);
  883. $objectreplacing->fetch($objectidnext);
  884. $posy+=4;
  885. $pdf->SetXY($posx,$posy);
  886. $pdf->SetTextColor(0,0,60);
  887. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
  888. }
  889. if ($object->type == 1)
  890. {
  891. $objectreplaced=new Facture($this->db);
  892. $objectreplaced->fetch($object->fk_facture_source);
  893. $posy+=4;
  894. $pdf->SetXY($posx,$posy);
  895. $pdf->SetTextColor(0,0,60);
  896. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
  897. }
  898. if ($object->type == 2)
  899. {
  900. $objectreplaced=new Facture($this->db);
  901. $objectreplaced->fetch($object->fk_facture_source);
  902. $posy+=4;
  903. $pdf->SetXY($posx,$posy);
  904. $pdf->SetTextColor(0,0,60);
  905. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
  906. }
  907. $posy+=4;
  908. $pdf->SetXY($posx,$posy);
  909. $pdf->SetTextColor(0,0,60);
  910. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateInvoice")." : " . dol_print_date($object->date,"day",false,$outputlangs), '', 'R');
  911. if ($object->type != 2)
  912. {
  913. $posy+=4;
  914. $pdf->SetXY($posx,$posy);
  915. $pdf->SetTextColor(0,0,60);
  916. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEcheance")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'R');
  917. }
  918. if ($object->client->code_client)
  919. {
  920. $posy+=4;
  921. $pdf->SetXY($posx,$posy);
  922. $pdf->SetTextColor(0,0,60);
  923. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'R');
  924. }
  925. // Add list of linked orders and proposals
  926. // TODO mutualiser
  927. $object->fetchObjectLinked();
  928. foreach($object->linkedObjects as $objecttype => $objects)
  929. {
  930. if ($objecttype == 'propal')
  931. {
  932. $outputlangs->load('propal');
  933. $num=count($objects);
  934. for ($i=0;$i<$num;$i++)
  935. {
  936. $posy+=4;
  937. $pdf->SetXY($posx,$posy);
  938. $pdf->SetFont('','', $default_font_size - 1);
  939. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefProposal")." : ".$outputlangs->transnoentities($objects[$i]->ref), '', 'R');
  940. }
  941. }
  942. else if ($objecttype == 'commande')
  943. {
  944. $outputlangs->load('orders');
  945. $num=count($objects);
  946. for ($i=0;$i<$num;$i++)
  947. {
  948. $posy+=4;
  949. $pdf->SetXY($posx,$posy);
  950. $pdf->SetFont('','', $default_font_size - 1);
  951. $text=$objects[$i]->ref;
  952. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  953. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  954. }
  955. }
  956. }
  957. if ($showaddress)
  958. {
  959. // Sender properties
  960. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  961. // Show sender
  962. $posy=42;
  963. $posx=$this->marge_gauche;
  964. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  965. $hautcadre=40;
  966. // Show sender frame
  967. $pdf->SetTextColor(0,0,0);
  968. $pdf->SetFont('','', $default_font_size - 2);
  969. $pdf->SetXY($posx,$posy-5);
  970. $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
  971. $pdf->SetXY($posx,$posy);
  972. $pdf->SetFillColor(230,230,230);
  973. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  974. $pdf->SetTextColor(0,0,60);
  975. // Show sender name
  976. $pdf->SetXY($posx+2,$posy+3);
  977. $pdf->SetFont('','B', $default_font_size);
  978. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  979. // Show sender information
  980. $pdf->SetXY($posx+2,$posy+8);
  981. $pdf->SetFont('','', $default_font_size - 1);
  982. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  983. // If BILLING contact defined on invoice, we use it
  984. $usecontact=false;
  985. $arrayidcontact=$object->getIdContact('external','BILLING');
  986. if (count($arrayidcontact) > 0)
  987. {
  988. $usecontact=true;
  989. $result=$object->fetch_contact($arrayidcontact[0]);
  990. }
  991. // Recipient name
  992. if (! empty($usecontact))
  993. {
  994. // On peut utiliser le nom de la societe du contact
  995. if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
  996. else $socname = $object->client->nom;
  997. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  998. }
  999. else
  1000. {
  1001. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  1002. }
  1003. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  1004. // Show recipient
  1005. $posy=42;
  1006. $posx=$this->page_largeur-$this->marge_droite-100;
  1007. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  1008. // Show recipient frame
  1009. $pdf->SetTextColor(0,0,0);
  1010. $pdf->SetFont('','', $default_font_size - 2);
  1011. $pdf->SetXY($posx+2,$posy-5);
  1012. $pdf->MultiCell(80,5, $outputlangs->transnoentities("BillTo").":",0,'L');
  1013. $pdf->rect($posx, $posy, 100, $hautcadre);
  1014. // Show recipient name
  1015. $pdf->SetXY($posx+2,$posy+3);
  1016. $pdf->SetFont('','B', $default_font_size);
  1017. $pdf->MultiCell(96,4, $carac_client_name, 0, 'L');
  1018. // Show recipient information
  1019. $pdf->SetFont('','', $default_font_size - 1);
  1020. $pdf->SetXY($posx+2,$posy+8);
  1021. $pdf->MultiCell(86,4, $carac_client, 0, 'L');
  1022. }
  1023. }
  1024. /**
  1025. * \brief Show footer of page
  1026. * \param pdf PDF factory
  1027. * \param object Object invoice
  1028. * \param outputlangs Object lang for output
  1029. * \remarks Need this->emetteur object
  1030. */
  1031. function _pagefoot(&$pdf,$object,$outputlangs)
  1032. {
  1033. return pdf_pagefoot($pdf,$outputlangs,'FACTURE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  1034. }
  1035. }
  1036. ?>