PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/facture/doc/pdf_oursin.modules.php

https://github.com/asterix14/dolibarr
PHP | 1035 lines | 724 code | 164 blank | 147 comment | 113 complexity | b04549076480348c74b28a64ddf78b99 MD5 | raw file
Possible License(s): LGPL-2.0
  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) 2005 Sylvain SCATTOLINI <sylvain@s-infoservices.com>
  5. * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  6. * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. * or see http://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/modules/facture/doc/pdf_oursin.modules.php
  24. * \ingroup facture
  25. * \brief Fichier de la classe permettant de generer les factures au modele oursin
  26. * \author Sylvain SCATTOLINI base sur un modele de Laurent Destailleur
  27. */
  28. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/modules/facture/modules_facture.php");
  30. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  31. require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
  32. /**
  33. * \class pdf_oursin
  34. * \brief Classe permettant de generer les factures au modele oursin
  35. */
  36. class pdf_oursin extends ModelePDFFactures
  37. {
  38. var $marges=array("g"=>10,"h"=>5,"d"=>10,"b"=>15);
  39. var $phpmin = array(4,3,0); // Minimum version of PHP required by module
  40. var $version = 'dolibarr';
  41. var $emetteur; // Objet societe qui emet
  42. /**
  43. * Constructor
  44. *
  45. * @param DoliDB $DB Database handler
  46. */
  47. function pdf_oursin($db)
  48. {
  49. global $conf,$langs,$mysoc;
  50. $langs->load("main");
  51. $langs->load("bills");
  52. $langs->load("products");
  53. $this->db = $db;
  54. $this->name = "oursin";
  55. $this->description = $langs->transnoentities('PDFOursinDescription');
  56. // Dimension page pour format A4
  57. $this->type = 'pdf';
  58. $formatarray=pdf_getFormat();
  59. $this->page_largeur = $formatarray['width'];
  60. $this->page_hauteur = $formatarray['height'];
  61. $this->format = array($this->page_largeur,$this->page_hauteur);
  62. $this->marge_gauche=10;
  63. $this->marge_droite=10;
  64. $this->marge_haute=10;
  65. $this->marge_basse=10;
  66. $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO
  67. $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
  68. $this->option_modereg = 1; // Gere choix mode reglement FACTURE_CHQ_NUMBER, FACTURE_RIB_NUMBER
  69. $this->option_condreg = 1; // Affiche conditions reglement
  70. $this->option_codeproduitservice = 1; // Affiche code produit-service
  71. $this->option_multilang = 1; // Dispo en plusieurs langues
  72. $this->option_escompte = 0; // Affiche si il y a eu escompte
  73. $this->option_credit_note = 1; // Support credit note
  74. $this->option_freetext = 1; // Support add of a personalised text
  75. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  76. $this->franchise=!$mysoc->tva_assuj;
  77. // Recupere emmetteur
  78. $this->emetteur=$mysoc;
  79. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'�tait pas d�fini
  80. // Defini position des colonnes
  81. $this->posxdesc=$this->marge_gauche+1;
  82. $this->posxtva=111;
  83. $this->posxup=126;
  84. $this->posxqty=145;
  85. $this->posxdiscount=162;
  86. $this->postotalht=174;
  87. $this->tva=array();
  88. $this->atleastoneratenotnull=0;
  89. $this->atleastonediscount=0;
  90. }
  91. /**
  92. * Function to build pdf onto disk
  93. *
  94. * @param int $object Id of object to generate
  95. * @param object $outputlangs Lang output object
  96. * @param string $srctemplatepath Full path of source filename for generator using a template file
  97. * @param int $hidedetails Do not show line details
  98. * @param int $hidedesc Do not show desc
  99. * @param int $hideref Do not show ref
  100. * @param object $hookmanager Hookmanager object
  101. * @return int 1=OK, 0=KO
  102. */
  103. function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false)
  104. {
  105. global $user,$langs,$conf;
  106. if (! is_object($outputlangs)) $outputlangs=$langs;
  107. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  108. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  109. $default_font_size = pdf_getPDFFontSize($outputlangs);
  110. $outputlangs->load("main");
  111. $outputlangs->load("dict");
  112. $outputlangs->load("companies");
  113. $outputlangs->load("bills");
  114. $outputlangs->load("products");
  115. if ($conf->facture->dir_output)
  116. {
  117. $object->fetch_thirdparty();
  118. $deja_regle = $object->getSommePaiement();
  119. $amount_credit_notes_included = $object->getSumCreditNotesUsed();
  120. $amount_deposits_included = $object->getSumDepositsUsed();
  121. // Definition of $dir and $file
  122. if ($object->specimen)
  123. {
  124. $dir = $conf->facture->dir_output;
  125. $file = $dir . "/SPECIMEN.pdf";
  126. }
  127. else
  128. {
  129. $objectref = dol_sanitizeFileName($object->ref);
  130. $dir = $conf->facture->dir_output . "/" . $objectref;
  131. $file = $dir . "/" . $objectref . ".pdf";
  132. }
  133. if (! file_exists($dir))
  134. {
  135. if (create_exdir($dir) < 0)
  136. {
  137. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  138. return 0;
  139. }
  140. }
  141. if (file_exists($dir))
  142. {
  143. $pdf=pdf_getInstance($this->format);
  144. if (class_exists('TCPDF'))
  145. {
  146. $pdf->setPrintHeader(false);
  147. $pdf->setPrintFooter(false);
  148. }
  149. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  150. $pdf->Open();
  151. $pagenb=0;
  152. $pdf->SetDrawColor(128,128,128);
  153. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  154. $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
  155. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  156. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  157. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Invoice"));
  158. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  159. $pdf->SetMargins(10, 10, 10);
  160. $pdf->SetAutoPageBreak(1,0);
  161. // New page
  162. $pdf->AddPage();
  163. $pagenb++;
  164. $this->_pagehead($pdf, $object, 1, $outputlangs);
  165. $pdf->SetFont('','', $default_font_size - 1);
  166. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  167. $pdf->SetTextColor(0,0,0);
  168. $tab_top = $this->marges['h']+90;
  169. $tab_height = 110;
  170. $pdf->SetFillColor(220,220,220);
  171. $pdf->SetFont('','', $default_font_size - 1);
  172. $pdf->SetXY($this->marges['g'], $tab_top + $this->marges['g'] );
  173. $iniY = $pdf->GetY();
  174. $curY = $pdf->GetY();
  175. $nexY = $pdf->GetY();
  176. $nblignes = count($object->lines);
  177. // Loop on each lines
  178. for ($i = 0 ; $i < $nblignes ; $i++)
  179. {
  180. $curY = $nexY;
  181. // Description of product line
  182. pdf_writelinedesc($pdf,$object,$i,$outputlangs,108,3,$this->posxdesc-1,$curY+1,$hideref,$hidedesc,0,$hookmanager);
  183. $nexY = $pdf->GetY();
  184. // TVA
  185. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  186. {
  187. if ($this->franchise!=1)
  188. {
  189. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager);
  190. $pdf->SetXY($this->marges['g']+118, $curY);
  191. $pdf->MultiCell(12, 3, $vat_rate, 0, 'R');
  192. }
  193. }
  194. // Prix unitaire HT avant remise
  195. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
  196. $pdf->SetXY($this->marges['g']+132, $curY);
  197. $pdf->MultiCell(16, 3, $up_excl_tax, 0, 'R', 0);
  198. // Quantity
  199. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager);
  200. $pdf->SetXY($this->marges['g']+150, $curY);
  201. $pdf->MultiCell(10, 3, $qty, 0, 'R');
  202. // Remise sur ligne
  203. $pdf->SetXY($this->marges['g']+160, $curY);
  204. if ($object->lines[$i]->remise_percent) {
  205. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails, $hookmanager);
  206. $pdf->MultiCell(14, 3, $remise_percent, 0, 'R');
  207. }
  208. // Total HT
  209. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
  210. $pdf->SetXY($this->marges['g']+168, $curY);
  211. $pdf->MultiCell(21, 3, $total_excl_tax, 0, 'R', 0);
  212. if ($nexY > 200 && $i < $nblignes - 1)
  213. {
  214. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $object, $outputlangs);
  215. $nexY = $iniY;
  216. // New page
  217. $pdf->AddPage();
  218. $pagenb++;
  219. $this->_pagehead($pdf, $object, 0, $outputlangs);
  220. $pdf->SetFont('','', $default_font_size - 1);
  221. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  222. $pdf->SetTextColor(0,0,0);
  223. }
  224. }
  225. $posy=$this->_tableau($pdf, $tab_top, $tab_height, $nexY, $object, $outputlangs);
  226. $bottomlasttab=$tab_top + $tab_height + 1;
  227. // Affiche zone infos
  228. $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
  229. // Affiche zone totaux
  230. $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  231. // Affiche zone versements
  232. if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
  233. {
  234. $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
  235. }
  236. // Pied de page
  237. $this->_pagefoot($pdf, $object, $outputlangs);
  238. $pdf->AliasNbPages();
  239. $pdf->Close();
  240. $pdf->Output($file,'F');
  241. // Actions on extra fields (by external module or standard code)
  242. include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
  243. $hookmanager=new HookManager($this->db);
  244. $hookmanager->callHooks(array('pdfgeneration'));
  245. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  246. global $action;
  247. $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
  248. if (! empty($conf->global->MAIN_UMASK))
  249. @chmod($file, octdec($conf->global->MAIN_UMASK));
  250. return 1; // Pas d'erreur
  251. }
  252. else
  253. {
  254. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  255. return 0;
  256. }
  257. }
  258. else
  259. {
  260. $this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR");
  261. return 0;
  262. }
  263. $this->error=$langs->transnoentities("ErrorUnknown");
  264. return 0; // Erreur par defaut
  265. }
  266. /**
  267. * \brief Affiche tableau des versement
  268. * \param pdf Objet PDF
  269. * \param fac Objet facture
  270. * \param posy Position y in PDF
  271. * \param outputlangs Object langs for output
  272. * \return int <0 if KO, >0 if OK
  273. */
  274. function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
  275. {
  276. $tab3_posx = $this->marges['g']+110;
  277. $tab3_top = $posy + 8;
  278. $tab3_width = 80;
  279. $tab3_height = 4;
  280. $default_font_size = pdf_getPDFFontSize($outputlangs);
  281. $pdf->SetFont('','', $default_font_size - 2);
  282. $pdf->SetXY($tab3_posx, $tab3_top - 5);
  283. $pdf->MultiCell(60, 5, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0);
  284. $pdf->Rect($tab3_posx, $tab3_top-1, $tab3_width, $tab3_height);
  285. $pdf->SetFont('','', $default_font_size - 4);
  286. $pdf->SetXY($tab3_posx, $tab3_top-1 );
  287. $pdf->MultiCell(20, 4, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
  288. $pdf->SetXY($tab3_posx+21, $tab3_top-1 );
  289. $pdf->MultiCell(20, 4, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
  290. $pdf->SetXY($tab3_posx+40, $tab3_top-1 );
  291. $pdf->MultiCell(20, 4, $outputlangs->transnoentities("Type"), 0, 'L', 0);
  292. $pdf->SetXY($tab3_posx+58, $tab3_top-1 );
  293. $pdf->MultiCell(20, 4, $outputlangs->transnoentities("Num"), 0, 'L', 0);
  294. $y=0;
  295. $pdf->SetFont('','', $default_font_size - 4);
  296. // Loop on each credit note included
  297. $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
  298. $sql.= " re.description, re.fk_facture_source,";
  299. $sql.= " f.type, f.datef";
  300. $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f";
  301. $sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id;
  302. $resql=$this->db->query($sql);
  303. if ($resql)
  304. {
  305. $num = $this->db->num_rows($resql);
  306. $i=0;
  307. $invoice=new Facture($this->db);
  308. while ($i < $num)
  309. {
  310. $y+=3;
  311. $obj = $this->db->fetch_object($resql);
  312. if ($obj->type == 2) $text=$outputlangs->trans("CreditNote");
  313. elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit");
  314. else $text=$outputlangs->trans("UnknownType");
  315. $invoice->fetch($obj->fk_facture_source);
  316. $pdf->SetXY($tab3_posx, $tab3_top+$y );
  317. $pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0);
  318. $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
  319. $pdf->MultiCell(20, 3, price($obj->amount_ttc), 0, 'L', 0);
  320. $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
  321. $pdf->MultiCell(20, 3, $text, 0, 'L', 0);
  322. $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
  323. $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0);
  324. $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3 );
  325. $i++;
  326. }
  327. }
  328. else
  329. {
  330. $this->error=$outputlangs->trans("Error")." sql=".$sql;
  331. dol_syslog($this->db,$this->error, LOG_ERR);
  332. return -1;
  333. }
  334. // Loop on each payment
  335. $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount,";
  336. $sql.= " cp.code";
  337. $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
  338. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  339. $sql.= " WHERE pf.fk_paiement = p.rowid and pf.fk_facture = ".$object->id;
  340. $sql.= " ORDER BY p.datep";
  341. $resql=$this->db->query($sql);
  342. if ($resql)
  343. {
  344. $num = $this->db->num_rows($resql);
  345. $i=0;
  346. while ($i < $num) {
  347. $y+=3;
  348. $row = $this->db->fetch_object($resql);
  349. $pdf->SetXY($tab3_posx, $tab3_top+$y );
  350. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
  351. $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
  352. $pdf->MultiCell(20, 3, price($row->amount), 0, 'L', 0);
  353. $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
  354. $oper = $outputlangs->getTradFromKey("PaymentTypeShort" . $row->code);
  355. $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
  356. $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
  357. $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
  358. $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3 );
  359. $i++;
  360. }
  361. }
  362. else
  363. {
  364. $this->error=$this->db->lasterror();
  365. dol_syslog($this->db,$this->error, LOG_ERR);
  366. return -1;
  367. }
  368. }
  369. /**
  370. * \brief Affiche infos divers
  371. * \param pdf Objet PDF
  372. * \param object Objet facture
  373. * \param posy Position depart
  374. * \param outputlangs Objet langs
  375. * \return y Position pour suite
  376. */
  377. function _tableau_info(&$pdf, $object, $posy, $outputlangs)
  378. {
  379. global $conf;
  380. $default_font_size = pdf_getPDFFontSize($outputlangs);
  381. $pdf->SetFont('','', $default_font_size - 1);
  382. // If France, show VAT mention if not applicable
  383. if ($this->emetteur->pays_code == 'FR' && $this->franchise == 1)
  384. {
  385. $pdf->SetFont('','B', $default_font_size - 2);
  386. $pdf->SetXY($this->marge_gauche, $posy);
  387. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  388. $posy=$pdf->GetY()+4;
  389. }
  390. // Show payments conditions
  391. if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement))
  392. {
  393. $pdf->SetFont('','B', $default_font_size - 2);
  394. $pdf->SetXY($this->marge_gauche, $posy);
  395. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  396. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  397. $pdf->SetFont('','', $default_font_size - 2);
  398. $pdf->SetXY(52, $posy);
  399. $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);
  400. $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
  401. $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
  402. $posy=$pdf->GetY()+3;
  403. }
  404. if ($object->type != 2)
  405. {
  406. // Check a payment mode is defined
  407. if (empty($object->mode_reglement_code)
  408. && ! $conf->global->FACTURE_CHQ_NUMBER
  409. && ! $conf->global->FACTURE_RIB_NUMBER)
  410. {
  411. $pdf->SetXY($this->marge_gauche, $posy);
  412. $pdf->SetTextColor(200,0,0);
  413. $pdf->SetFont('','B', $default_font_size - 2);
  414. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
  415. $pdf->SetTextColor(0,0,0);
  416. $posy=$pdf->GetY()+1;
  417. }
  418. // Sown payment mode
  419. if ($object->mode_reglement_code
  420. && $object->mode_reglement_code != 'CHQ'
  421. && $object->mode_reglement_code != 'VIR')
  422. {
  423. $pdf->SetFont('','B', $default_font_size - 2);
  424. $pdf->SetXY($this->marge_gauche, $posy);
  425. $titre = $outputlangs->transnoentities("PaymentMode").':';
  426. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  427. $pdf->SetFont('','', $default_font_size - 2);
  428. $pdf->SetXY(50, $posy);
  429. $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);
  430. $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
  431. $posy=$pdf->GetY()+2;
  432. }
  433. // Show payment mode CHQ
  434. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
  435. {
  436. // Si mode reglement non force ou si force a CHQ
  437. if ($conf->global->FACTURE_CHQ_NUMBER)
  438. {
  439. if ($conf->global->FACTURE_CHQ_NUMBER > 0)
  440. {
  441. $account = new Account($this->db);
  442. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  443. $pdf->SetXY($this->marge_gauche, $posy);
  444. $pdf->SetFont('','B', $default_font_size - 2);
  445. $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio).':',0,'L',0);
  446. $posy=$pdf->GetY()+1;
  447. $pdf->SetXY($this->marge_gauche, $posy);
  448. $pdf->SetFont('','', $default_font_size - 2);
  449. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($account->adresse_proprio), 0, 'L', 0);
  450. $posy=$pdf->GetY()+2;
  451. }
  452. if ($conf->global->FACTURE_CHQ_NUMBER == -1)
  453. {
  454. $pdf->SetXY($this->marge_gauche, $posy);
  455. $pdf->SetFont('','B', $default_font_size - 2);
  456. $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedToShort').' '.$outputlangs->convToOutputCharset($this->emetteur->name).' '.$outputlangs->transnoentities('SendTo').':',0,'L',0);
  457. $posy=$pdf->GetY()+1;
  458. $pdf->SetXY($this->marge_gauche, $posy);
  459. $pdf->SetFont('','', $default_font_size - 2);
  460. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  461. $posy=$pdf->GetY()+2;
  462. }
  463. }
  464. }
  465. // If payment mode not forced or forced to VIR, show payment with BAN
  466. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
  467. {
  468. if (! empty($conf->global->FACTURE_RIB_NUMBER))
  469. {
  470. $account = new Account($this->db);
  471. $account->fetch($conf->global->FACTURE_RIB_NUMBER);
  472. $curx=$this->marge_gauche;
  473. $cury=$posy;
  474. $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account);
  475. $posy+=2;
  476. }
  477. }
  478. }
  479. return $posy;
  480. }
  481. /**
  482. * Affiche le total a payer
  483. *
  484. * @param pdf Objet PDF
  485. * @param object Objet facture
  486. * @param deja_regle Montant deja regle
  487. * @param posy Position depart
  488. * @param outputlangs Objet langs
  489. * @return y Position pour suite
  490. */
  491. function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  492. {
  493. global $conf,$langs;
  494. $sign=1;
  495. if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
  496. $langs->load("main");
  497. $langs->load("bills");
  498. $default_font_size = pdf_getPDFFontSize($outputlangs);
  499. $tab2_top = $this->marges['h']+202;
  500. $tab2_hl = 4;
  501. $pdf->SetFont('','', $default_font_size - 1);
  502. // Tableau total
  503. $col1x=$this->marges['g']+110; $col2x=$this->marges['g']+164;
  504. $lltot = 200; $largcol2 = $lltot - $col2x;
  505. $pdf->SetXY($this->marges['g'], $tab2_top + 0);
  506. $useborder=0;
  507. $index = 0;
  508. // Total HT
  509. $pdf->SetXY($col1x, $tab2_top + 0);
  510. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 0);
  511. $pdf->SetXY($col2x, $tab2_top + 0);
  512. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($object->total_ht + $object->remise)), 0, 'R', 0);
  513. // Show VAT by rates and total
  514. $pdf->SetFillColor(248,248,248);
  515. $this->atleastoneratenotnull=0;
  516. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  517. {
  518. foreach( $this->tva as $tvakey => $tvaval )
  519. {
  520. if ($tvakey > 0) // On affiche pas taux 0
  521. {
  522. $this->atleastoneratenotnull++;
  523. $index++;
  524. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  525. $tvacompl='';
  526. if (preg_match('/\*/',$tvakey))
  527. {
  528. $tvakey=str_replace('*','',$tvakey);
  529. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  530. }
  531. $totalvat =$outputlangs->transnoentities("TotalVAT").' ';
  532. $totalvat.=vatrate($tvakey,1).$tvacompl;
  533. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  534. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  535. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $tvaval), 0, 'R', 1);
  536. }
  537. }
  538. if (! $this->atleastoneratenotnull) // If no vat at all
  539. {
  540. $index++;
  541. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  542. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
  543. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  544. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', 1);
  545. }
  546. }
  547. // Total TTC
  548. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  549. {
  550. $index++;
  551. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  552. $pdf->SetTextColor(22,137,210);
  553. $pdf->SetFont('','B', $default_font_size + 1);
  554. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), 0, 'L', 0);
  555. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  556. $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_ttc), 0, 'R', 0);
  557. $pdf->SetTextColor(0,0,0);
  558. }
  559. $creditnoteamount=$object->getSumCreditNotesUsed();
  560. $depositsamount=$object->getSumDepositsUsed();
  561. $resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  562. if ($object->paye) $resteapayer=0;
  563. if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0)
  564. {
  565. $pdf->SetFont('','', $default_font_size);
  566. // Already paid + Deposits
  567. $index++;
  568. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  569. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
  570. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  571. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount), 0, 'R', 0);
  572. // Credit note
  573. if ($creditnoteamount)
  574. {
  575. $index++;
  576. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  577. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
  578. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  579. $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0);
  580. }
  581. // Escompte
  582. if ($object->close_code == 'discount_vat')
  583. {
  584. $index++;
  585. $pdf->SetFillColor(255,255,255);
  586. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  587. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOffered"), $useborder, 'L', 1);
  588. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  589. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount), $useborder, 'R', 1);
  590. $resteapayer=0;
  591. }
  592. $index++;
  593. $pdf->SetTextColor(0,0,60);
  594. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  595. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), 0, 'L', 0);
  596. $pdf->SetFillColor(224,224,224);
  597. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  598. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), 0, 'R', 0);
  599. // Fin
  600. $pdf->SetFont('','B', $default_font_size + 1);
  601. $pdf->SetTextColor(0,0,0);
  602. }
  603. $index++;
  604. return ($tab2_top + ($tab2_hl * $index));
  605. }
  606. /*
  607. * Affiche la grille des lignes de factures
  608. * @param pdf objet PDF
  609. */
  610. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $object, $outputlangs)
  611. {
  612. global $conf,$langs;
  613. $langs->load("main");
  614. $langs->load("bills");
  615. $default_font_size = pdf_getPDFFontSize($outputlangs);
  616. $pdf->line($this->marges['g'], $tab_top+8, 210-$this->marges['d'], $tab_top+8);
  617. $pdf->line($this->marges['g'], $tab_top + $tab_height, 210-$this->marges['d'], $tab_top + $tab_height);
  618. $pdf->SetFont('','', $default_font_size - 1);
  619. $pdf->SetXY($this->marges['g'],$tab_top + 1);
  620. $pdf->MultiCell(0, 4, $outputlangs->transnoentities("Designation"), 0, 'L');
  621. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  622. {
  623. $pdf->SetXY($this->marges['g']+120,$tab_top + 1);
  624. $pdf->MultiCell(0, 4, $outputlangs->transnoentities("VAT"), 0, 'L');
  625. }
  626. $pdf->SetXY($this->marges['g']+135,$tab_top + 1);
  627. $pdf->MultiCell(0, 4, $outputlangs->transnoentities("PriceUHT"), 0, 'L');
  628. $pdf->SetXY($this->marges['g']+153,$tab_top + 1);
  629. $pdf->MultiCell(0, 4, $outputlangs->transnoentities("Qty"), 0, 'L');
  630. $nblignes = count($object->lines);
  631. $rem=0;
  632. for ($i = 0 ; $i < $nblignes ; $i++)
  633. {
  634. if ($object->lines[$i]->remise_percent)
  635. {
  636. $rem=1;
  637. }
  638. }
  639. if ($rem==1)
  640. {
  641. $pdf->SetXY($this->marges['g']+165,$tab_top + 1);
  642. $pdf->MultiCell(0, 4, $outputlangs->transnoentities("%"), 0, 'L');
  643. }
  644. $pdf->SetXY($this->marges['g']+170,$tab_top + 1);
  645. $pdf->MultiCell(20, 4, $outputlangs->transnoentities("TotalHTShort"), 0, 'R');
  646. return $pdf->GetY();
  647. }
  648. /*
  649. * Affiche en-tete facture
  650. *
  651. * @param pdf objet PDF
  652. * @param fac objet facture
  653. */
  654. function _pagehead(&$pdf, $object, $showaddress=0, $outputlangs)
  655. {
  656. global $langs,$conf;
  657. $langs->load("main");
  658. $langs->load("bills");
  659. $langs->load("propal");
  660. $langs->load("companies");
  661. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  662. $default_font_size = pdf_getPDFFontSize($outputlangs);
  663. //Affiche le filigrane brouillon - Print Draft Watermark
  664. if($object->statut==0 && (! empty($conf->global->FACTURE_DRAFT_WATERMARK)) )
  665. {
  666. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FACTURE_DRAFT_WATERMARK);
  667. }
  668. $pdf->SetTextColor(0,0,60);
  669. $pdf->SetFont('','B',$default_font_size + 3);
  670. $pdf->SetXY($this->marges['g'],6);
  671. // Logo
  672. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  673. if ($this->emetteur->logo)
  674. {
  675. if (is_readable($logo))
  676. {
  677. $taille=getimagesize($logo);
  678. $length=$taille[0]/2.835;
  679. $pdf->Image($logo, $this->marges['g'], $this->marges['h'], 0, 24);
  680. }
  681. else
  682. {
  683. $pdf->SetTextColor(200,0,0);
  684. $pdf->SetFont('','B', $default_font_size - 2);
  685. $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  686. $pdf->MultiCell(80, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  687. }
  688. }
  689. else
  690. {
  691. $text=$this->emetteur->name;
  692. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  693. }
  694. if ($showaddress)
  695. {
  696. // Sender properties
  697. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  698. // Show sender
  699. $posy=30;
  700. $posx=$this->marge_gauche;
  701. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  702. $hautcadre=40;
  703. // Show sender frame
  704. $pdf->SetTextColor(0,0,0);
  705. $pdf->SetFont('','', $default_font_size - 2);
  706. $pdf->SetXY($posx,$posy-5);
  707. //$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
  708. $pdf->SetXY($posx,$posy);
  709. $pdf->SetFillColor(255,255,255);
  710. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  711. $pdf->SetTextColor(0,0,60);
  712. // Show sender name
  713. $pdf->SetXY($posx+2,$posy+3);
  714. $pdf->SetFont('','B', $default_font_size);
  715. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  716. // Show sender information
  717. $pdf->SetXY($posx+2,$posy+8);
  718. $pdf->SetFont('','', $default_font_size - 1);
  719. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  720. // If BILLING contact defined on invoice, we use it
  721. $usecontact=false;
  722. $arrayidcontact=$object->getIdContact('external','BILLING');
  723. if (count($arrayidcontact) > 0)
  724. {
  725. $usecontact=true;
  726. $result=$object->fetch_contact($arrayidcontact[0]);
  727. }
  728. // Recipient name
  729. if (! empty($usecontact))
  730. {
  731. // On peut utiliser le nom de la societe du contact
  732. if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
  733. else $socname = $object->client->nom;
  734. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  735. }
  736. else
  737. {
  738. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  739. }
  740. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  741. // Show recipient
  742. $posy=30;
  743. $posx=$this->page_largeur-$this->marge_droite-100;
  744. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  745. // Show recipient frame
  746. $pdf->SetTextColor(0,0,0);
  747. $pdf->SetFont('','', $default_font_size - 2);
  748. $pdf->SetXY($posx+2,$posy-5);
  749. $pdf->MultiCell(80,5, $outputlangs->transnoentities("BillTo").":",0,'L');
  750. $pdf->rect($posx, $posy, 100, $hautcadre);
  751. // Show recipient name
  752. $pdf->SetXY($posx+2,$posy+3);
  753. $pdf->SetFont('','B', $default_font_size);
  754. $pdf->MultiCell(96,4, $carac_client_name, 0, 'L');
  755. // Show recipient information
  756. $pdf->SetFont('','', $default_font_size - 1);
  757. $pdf->SetXY($posx+2,$posy+8);
  758. $pdf->MultiCell(86,4, $carac_client, 0, 'L');
  759. }
  760. /*
  761. * ref facture
  762. */
  763. $posy=78;
  764. $pdf->SetFont('','B', $default_font_size + 3);
  765. $pdf->SetXY($this->marges['g'],$posy-5);
  766. $pdf->SetTextColor(0,0,0);
  767. $title=$outputlangs->transnoentities("Invoice");
  768. if ($object->type == 1) $title=$outputlangs->transnoentities("InvoiceReplacement");
  769. if ($object->type == 2) $title=$outputlangs->transnoentities("InvoiceAvoir");
  770. if ($object->type == 3) $title=$outputlangs->transnoentities("InvoiceDeposit");
  771. if ($object->type == 4) $title=$outputlangs->transnoentities("InvoiceProForma");
  772. $pdf->MultiCell(100, 10, $title.' '.$outputlangs->transnoentities("Of").' '.dol_print_date($object->date,"day",false,$outputlangs,true), '', 'L');
  773. $pdf->SetFont('','B', $default_font_size + 1);
  774. $pdf->SetXY($this->marges['g'],$posy);
  775. $pdf->SetTextColor(22,137,210);
  776. $pdf->MultiCell(100, 10, $outputlangs->transnoentities("RefBill")." : " . $outputlangs->transnoentities($object->ref), '', 'L');
  777. $pdf->SetTextColor(0,0,0);
  778. $posy+=4;
  779. $objectidnext=$object->getIdReplacingInvoice('validated');
  780. if ($object->type == 0 && $objectidnext)
  781. {
  782. $objectreplacing=new Facture($this->db);
  783. $objectreplacing->fetch($objectidnext);
  784. $posy+=4;
  785. $pdf->SetXY($this->marges['g'],$posy);
  786. $pdf->SetTextColor(0,0,60);
  787. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ReplacementByInvoice").' : '.$outputlangs->convToOutputCharset($objectreplacing->ref), '', 'L');
  788. }
  789. if ($object->type == 1)
  790. {
  791. $objectreplaced=new Facture($this->db);
  792. $objectreplaced->fetch($object->fk_facture_source);
  793. $posy+=4;
  794. $pdf->SetXY($this->marges['g'],$posy);
  795. $pdf->SetTextColor(0,0,60);
  796. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ReplacementInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'L');
  797. }
  798. if ($object->type == 2)
  799. {
  800. $objectreplaced=new Facture($this->db);
  801. $objectreplaced->fetch($object->fk_facture_source);
  802. $posy+=4;
  803. $pdf->SetXY($this->marges['g'],$posy);
  804. $pdf->SetTextColor(0,0,60);
  805. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CorrectionInvoice").' : '.$outputlangs->convToOutputCharset($objectreplaced->ref), '', 'L');
  806. }
  807. if ($object->type != 2)
  808. {
  809. $posy+=5;
  810. $pdf->SetXY($this->marges['g'],$posy);
  811. $pdf->SetFont('','', $default_font_size - 1);
  812. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEcheance")." : " . dol_print_date($object->date_lim_reglement,"day",false,$outputlangs,true), '', 'L');
  813. }
  814. if ($object->client->code_client)
  815. {
  816. $posy+=4;
  817. $pdf->SetXY($this->marges['g'],$posy);
  818. $pdf->SetFont('','', $default_font_size - 1);
  819. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'L');
  820. }
  821. // Add list of linked orders and proposals
  822. // TODO mutualiser
  823. $object->fetchObjectLinked();
  824. foreach($object->linkedObjects as $objecttype => $objects)
  825. {
  826. if ($objecttype == 'propal')
  827. {
  828. $outputlangs->load('propal');
  829. $num=count($objects);
  830. for ($i=0;$i<$num;$i++)
  831. {
  832. $posy+=4;
  833. $pdf->SetXY($this->marges['g'],$posy);
  834. $pdf->SetFont('','', $default_font_size - 1);
  835. $pdf->MultiCell(60, 3, $outputlangs->transnoentities("RefProposal")." : ".$outputlangs->transnoentities($objects[$i]->ref));
  836. }
  837. }
  838. else if ($objecttype == 'commande')
  839. {
  840. $num=count($objects);
  841. for ($i=0;$i<$num;$i++)
  842. {
  843. $posy+=4;
  844. $pdf->SetXY($this->marges['g'],$posy);
  845. $pdf->SetFont('','', $default_font_size - 1);
  846. $text=$objects[$i]->ref;
  847. if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')';
  848. $pdf->MultiCell(60, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text));
  849. }
  850. }
  851. }
  852. // Amount in (at tab_top - 1)
  853. $pdf->SetTextColor(0,0,0);
  854. $pdf->SetFont('','', $default_font_size-1);
  855. $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->monnaie));
  856. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), 90);
  857. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  858. }
  859. /**
  860. * \brief Show footer of page
  861. * \param pdf PDF factory
  862. * \param object Object invoice
  863. * \param outputlang Object lang for output
  864. * \remarks Need this->emetteur object
  865. */
  866. function _pagefoot(&$pdf, $object, $outputlangs)
  867. {
  868. return pdf_pagefoot($pdf,$outputlangs,'FACTURE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  869. }
  870. }
  871. ?>