PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php

https://github.com/asterix14/dolibarr
PHP | 883 lines | 587 code | 152 blank | 144 comment | 67 complexity | 97d9c977757a503d66451f4fc6c042bb MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
  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, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php
  21. * \ingroup fournisseur
  22. * \brief Class file to generate the supplier invoices with the canelle model
  23. */
  24. require_once(DOL_DOCUMENT_ROOT."/core/modules/supplier_invoice/modules_facturefournisseur.php");
  25. require_once(DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.facture.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
  29. /**
  30. * \class pdf_canelle
  31. * \brief Class to generate the supplier invoices with the canelle model
  32. */
  33. class pdf_canelle extends ModelePDFSuppliersInvoices
  34. {
  35. var $db;
  36. var $name;
  37. var $description;
  38. var $type;
  39. var $phpmin = array(4,3,0); // Minimum version of PHP required by module
  40. var $version = 'dolibarr';
  41. var $page_largeur;
  42. var $page_hauteur;
  43. var $format;
  44. var $marge_gauche;
  45. var $marge_droite;
  46. var $marge_haute;
  47. var $marge_basse;
  48. var $emetteur; // Objet societe qui emet
  49. /**
  50. * Constructor
  51. *
  52. * @param DoliDB $DB Database handler
  53. */
  54. function pdf_canelle($db,$object)
  55. {
  56. global $conf,$langs,$mysoc;
  57. $langs->load("main");
  58. $langs->load("bills");
  59. $this->db = $db;
  60. $this->name = "canelle";
  61. $this->description = $langs->trans('SuppliersInvoiceModel');
  62. // Dimension page pour format A4
  63. $this->type = 'pdf';
  64. $formatarray=pdf_getFormat();
  65. $this->page_largeur = $formatarray['width'];
  66. $this->page_hauteur = $formatarray['height'];
  67. $this->format = array($this->page_largeur,$this->page_hauteur);
  68. $this->marge_gauche=10;
  69. $this->marge_droite=10;
  70. $this->marge_haute=10;
  71. $this->marge_basse=10;
  72. $this->option_logo = 1; // Affiche logo
  73. $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
  74. $this->option_modereg = 1; // Affiche mode reglement
  75. $this->option_condreg = 1; // Affiche conditions reglement
  76. $this->option_codeproduitservice = 1; // Affiche code produit-service
  77. $this->option_multilang = 1; // Dispo en plusieurs langues
  78. $this->franchise=!$mysoc->tva_assuj;
  79. // Get source company
  80. if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
  81. $this->emetteur=$object->thirdparty;
  82. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // By default, if was not defined
  83. // Defini position des colonnes
  84. $this->posxdesc=$this->marge_gauche+1;
  85. $this->posxtva=111;
  86. $this->posxup=126;
  87. $this->posxqty=145;
  88. $this->posxdiscount=162;
  89. $this->postotalht=174;
  90. $this->tva=array();
  91. $this->localtax1=array();
  92. $this->localtax2=array();
  93. $this->atleastoneratenotnull=0;
  94. $this->atleastonediscount=0;
  95. }
  96. /**
  97. * Write the invoice as a document onto disk
  98. * @param object Object invoice to build (or id if old method)
  99. * @param outputlangs Lang object for output language
  100. * @return int 1=OK, 0=KO
  101. */
  102. function write_file($object,$outputlangs='')
  103. {
  104. global $user,$langs,$conf,$mysoc;
  105. if (! is_object($outputlangs)) $outputlangs=$langs;
  106. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  107. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  108. $outputlangs->load("main");
  109. $outputlangs->load("dict");
  110. $outputlangs->load("companies");
  111. $outputlangs->load("bills");
  112. $outputlangs->load("products");
  113. $default_font_size = pdf_getPDFFontSize($outputlangs);
  114. if ($conf->fournisseur->dir_output.'/facture')
  115. {
  116. $object->fetch_thirdparty();
  117. $deja_regle = $object->getSommePaiement();
  118. //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
  119. //$amount_deposits_included = $object->getSumDepositsUsed();
  120. // Definition de $dir et $file
  121. if ($object->specimen)
  122. {
  123. $dir = $conf->fournisseur->facture->dir_output;
  124. $file = $dir . "/SPECIMEN.pdf";
  125. }
  126. else
  127. {
  128. $objectref = dol_sanitizeFileName($object->ref);
  129. $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$objectref;
  130. $file = $dir . "/" . $objectref . ".pdf";
  131. }
  132. if (! file_exists($dir))
  133. {
  134. if (create_exdir($dir) < 0)
  135. {
  136. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  137. return 0;
  138. }
  139. }
  140. if (file_exists($dir))
  141. {
  142. $nblignes = count($object->lines);
  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("Order"));
  158. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  159. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  160. $pdf->SetAutoPageBreak(1,0);
  161. // Positionne $this->atleastonediscount si on a au moins une remise
  162. for ($i = 0 ; $i < $nblignes ; $i++)
  163. {
  164. if ($object->lines[$i]->remise_percent)
  165. {
  166. $this->atleastonediscount++;
  167. }
  168. }
  169. // New page
  170. $pdf->AddPage();
  171. $pagenb++;
  172. $this->_pagehead($pdf, $object, 1, $outputlangs);
  173. $pdf->SetFont('','', $default_font_size - 1);
  174. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  175. $pdf->SetTextColor(0,0,0);
  176. $tab_top = 90;
  177. $tab_top_newpage = 50;
  178. $tab_height = 110;
  179. $tab_height_newpage = 150;
  180. // Affiche notes
  181. if (! empty($object->note_public))
  182. {
  183. $tab_top = 88;
  184. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  185. $pdf->SetXY($this->posxdesc-1, $tab_top);
  186. $pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'L');
  187. $nexY = $pdf->GetY();
  188. $height_note=$nexY-$tab_top;
  189. // Rect prend une longueur en 3eme param
  190. $pdf->SetDrawColor(192,192,192);
  191. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  192. $tab_height = $tab_height - $height_note;
  193. $tab_top = $nexY+6;
  194. }
  195. else
  196. {
  197. $height_note=0;
  198. }
  199. $iniY = $tab_top + 7;
  200. $curY = $tab_top + 7;
  201. $nexY = $tab_top + 7;
  202. // Boucle sur les lignes
  203. for ($i = 0 ; $i < $nblignes ; $i++)
  204. {
  205. $curY = $nexY;
  206. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  207. // Description of product line
  208. $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
  209. $curX = $this->posxdesc-1;
  210. pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,0,0,1);
  211. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  212. $nexY = $pdf->GetY();
  213. // VAT rate
  214. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  215. {
  216. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs);
  217. $pdf->SetXY($this->posxtva, $curY);
  218. $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
  219. }
  220. // Unit price before discount
  221. $pdf->SetXY($this->posxup, $curY);
  222. $pdf->MultiCell($this->posxqty-$this->posxup-1, 3, price($object->lines[$i]->pu_ht), 0, 'R', 0);
  223. // Quantity
  224. $pdf->SetXY($this->posxqty, $curY);
  225. $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $object->lines[$i]->qty, 0, 'R');
  226. // Discount on line
  227. $pdf->SetXY($this->posxdiscount, $curY);
  228. if ($object->lines[$i]->remise_percent)
  229. {
  230. $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
  231. }
  232. // Total HT line
  233. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs);
  234. $pdf->SetXY($this->postotalht, $curY);
  235. $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0);
  236. // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
  237. $tvaligne=$object->lines[$i]->total_tva;
  238. $localtax1ligne=$object->lines[$i]->total_localtax1;
  239. $localtax2ligne=$object->lines[$i]->total_localtax2;
  240. if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
  241. $vatrate=(string) $object->lines[$i]->tva_tx;
  242. $localtax1rate=(string) $object->lines[$i]->localtax1_tx;
  243. $localtax2rate=(string) $object->lines[$i]->localtax2_tx;
  244. if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
  245. $this->tva[$vatrate] += $tvaligne;
  246. $this->localtax1[$localtax1rate]+=$localtax1ligne;
  247. $this->localtax2[$localtax2rate]+=$localtax2ligne;
  248. $nexY+=2; // Passe espace entre les lignes
  249. // Test if a new page is required
  250. if ($pagenb == 1)
  251. {
  252. $tab_top_in_current_page=$tab_top;
  253. $tab_height_in_current_page=$tab_height;
  254. }
  255. else
  256. {
  257. $tab_top_in_current_page=$tab_top_newpage;
  258. $tab_height_in_current_page=$tab_height_newpage;
  259. }
  260. if (($nexY+$nblineFollowDesc) > ($tab_top_in_current_page+$tab_height_in_current_page) && $i < ($nblignes - 1))
  261. {
  262. if ($pagenb == 1)
  263. {
  264. $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
  265. }
  266. else
  267. {
  268. $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
  269. }
  270. $this->_pagefoot($pdf, $object, $outputlangs);
  271. // New page
  272. $pdf->AddPage();
  273. $pagenb++;
  274. $this->_pagehead($pdf, $object, 0, $outputlangs);
  275. $pdf->SetFont('','', $default_font_size - 1);
  276. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  277. $pdf->SetTextColor(0,0,0);
  278. $nexY = $tab_top_newpage + 7;
  279. }
  280. }
  281. // Show square
  282. if ($pagenb == 1)
  283. {
  284. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
  285. $bottomlasttab=$tab_top + $tab_height + 1;
  286. }
  287. else
  288. {
  289. $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
  290. $bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1;
  291. }
  292. // Affiche zone totaux
  293. $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  294. if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
  295. {
  296. $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
  297. }
  298. // Pied de page
  299. $this->_pagefoot($pdf, $object, $outputlangs);
  300. $pdf->AliasNbPages();
  301. $pdf->Close();
  302. $pdf->Output($file,'F');
  303. if (! empty($conf->global->MAIN_UMASK))
  304. @chmod($file, octdec($conf->global->MAIN_UMASK));
  305. return 1; // Pas d'erreur
  306. }
  307. else
  308. {
  309. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  310. return 0;
  311. }
  312. }
  313. else
  314. {
  315. $this->error=$langs->trans("ErrorConstantNotDefined","SUPPLIER_OUTPUTDIR");
  316. return 0;
  317. }
  318. $this->error=$langs->trans("ErrorUnknown");
  319. return 0; // Erreur par defaut
  320. }
  321. /**
  322. * \brief Show total to pay
  323. * \param pdf Object PDF
  324. * \param object Object invoice
  325. * \param deja_regle Amount payed
  326. * \return y Next position
  327. */
  328. function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  329. {
  330. global $conf,$mysoc;
  331. $default_font_size = pdf_getPDFFontSize($outputlangs);
  332. $tab2_top = $posy;
  333. $tab2_hl = 4;
  334. $pdf->SetFont('','', $default_font_size - 1);
  335. $pdf->SetXY($this->marge_gauche, $tab2_top + 0);
  336. // If France, show VAT mention if not applicable
  337. if ($this->emetteur->pays_code == 'FR' && $this->franchise == 1)
  338. {
  339. $pdf->MultiCell(100, $tab2_hl, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  340. }
  341. // Tableau total
  342. $lltot = 200; $col1x = 120; $col2x = 170; $largcol2 = $lltot - $col2x;
  343. // Total HT
  344. $pdf->SetFillColor(255,255,255);
  345. $pdf->SetXY($col1x, $tab2_top + 0);
  346. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  347. $pdf->SetXY($col2x, $tab2_top + 0);
  348. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + $object->remise), 0, 'R', 1);
  349. // Affichage des totaux de TVA par taux (conformement a reglementation)
  350. $pdf->SetFillColor(248,248,248);
  351. foreach( $this->tva as $tvakey => $tvaval )
  352. {
  353. if ($tvakey > 0) // On affiche pas taux 0
  354. {
  355. $this->atleastoneratenotnull++;
  356. $index++;
  357. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  358. $tvacompl='';
  359. if (preg_match('/\*/',$tvakey))
  360. {
  361. $tvakey=str_replace('*','',$tvakey);
  362. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  363. }
  364. $totalvat =$outputlangs->transnoentities("TotalVAT").' ';
  365. $totalvat.=vatrate($tvakey,1).$tvacompl;
  366. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  367. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  368. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  369. }
  370. }
  371. if (! $this->atleastoneratenotnull) // If not vat at all
  372. {
  373. $index++;
  374. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  375. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
  376. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  377. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
  378. // Total LocalTax1
  379. if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
  380. {
  381. $index++;
  382. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  383. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code), $useborder, 'L', 1);
  384. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  385. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
  386. }
  387. // Total LocalTax2
  388. if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
  389. {
  390. $index++;
  391. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  392. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code), $useborder, 'L', 1);
  393. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  394. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
  395. }
  396. }
  397. else
  398. {
  399. //Local tax 1
  400. if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  401. {
  402. foreach( $this->localtax1 as $tvakey => $tvaval )
  403. {
  404. if ($tvakey>0) // On affiche pas taux 0
  405. {
  406. //$this->atleastoneratenotnull++;
  407. $index++;
  408. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  409. $tvacompl='';
  410. if (preg_match('/\*/',$tvakey))
  411. {
  412. $tvakey=str_replace('*','',$tvakey);
  413. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  414. }
  415. $totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
  416. $totalvat.=vatrate($tvakey,1).$tvacompl;
  417. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  418. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  419. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  420. }
  421. }
  422. }
  423. //Local tax 2
  424. if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  425. {
  426. foreach( $this->localtax2 as $tvakey => $tvaval )
  427. {
  428. if ($tvakey>0) // On affiche pas taux 0
  429. {
  430. //$this->atleastoneratenotnull++;
  431. $index++;
  432. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  433. $tvacompl='';
  434. if (preg_match('/\*/',$tvakey))
  435. {
  436. $tvakey=str_replace('*','',$tvakey);
  437. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  438. }
  439. $totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
  440. $totalvat.=vatrate($tvakey,1).$tvacompl;
  441. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  442. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  443. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  444. }
  445. }
  446. }
  447. }
  448. $useborder=0;
  449. $index++;
  450. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  451. $pdf->SetTextColor(0,0,60);
  452. $pdf->SetFillColor(224,224,224);
  453. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
  454. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  455. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc), $useborder, 'R', 1);
  456. $pdf->SetFont('','', $default_font_size - 1);
  457. $pdf->SetTextColor(0,0,0);
  458. if ($deja_regle > 0)
  459. {
  460. $index++;
  461. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  462. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
  463. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  464. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
  465. $index++;
  466. $pdf->SetTextColor(0,0,60);
  467. //$pdf->SetFont('','B', $default_font_size - 1);
  468. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  469. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
  470. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  471. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle), $useborder, 'R', 1);
  472. $pdf->SetFont('','', $default_font_size - 1);
  473. $pdf->SetTextColor(0,0,0);
  474. }
  475. $index++;
  476. return ($tab2_top + ($tab2_hl * $index));
  477. }
  478. /**
  479. * Show the lines of invoice
  480. * @param pdf object PDF
  481. */
  482. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs)
  483. {
  484. global $conf;
  485. $default_font_size = pdf_getPDFFontSize($outputlangs);
  486. // Amount in (at tab_top - 1)
  487. $pdf->SetTextColor(0,0,0);
  488. $pdf->SetFont('','',$default_font_size - 2);
  489. $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->monnaie));
  490. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
  491. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  492. $pdf->SetDrawColor(128,128,128);
  493. // Rect prend une longueur en 3eme param
  494. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
  495. // line prend une position y en 3eme param
  496. $pdf->line($this->marge_gauche, $tab_top+6, $this->page_largeur-$this->marge_droite, $tab_top+6);
  497. $pdf->SetFont('','', $default_font_size - 1);
  498. $pdf->SetXY($this->posxdesc-1, $tab_top+2);
  499. $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
  500. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  501. {
  502. $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
  503. $pdf->SetXY($this->posxtva-3, $tab_top+2);
  504. $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
  505. }
  506. $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
  507. $pdf->SetXY($this->posxup-1, $tab_top+2);
  508. $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
  509. $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
  510. $pdf->SetXY($this->posxqty-1, $tab_top+2);
  511. $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
  512. $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
  513. if ($this->atleastonediscount)
  514. {
  515. $pdf->SetXY($this->posxdiscount-1, $tab_top+2);
  516. $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
  517. }
  518. if ($this->atleastonediscount)
  519. {
  520. $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
  521. }
  522. $pdf->SetXY($this->postotalht-1, $tab_top+2);
  523. $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHTShort"),'','C');
  524. }
  525. /**
  526. * Show payments table
  527. * @param pdf Object PDF
  528. * @param object Object invoice
  529. * @param posy Position y in PDF
  530. * @param outputlangs Object langs for output
  531. * @return int <0 if KO, >0 if OK
  532. */
  533. function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
  534. {
  535. $tab3_posx = 120;
  536. $tab3_top = $posy + 8;
  537. $tab3_width = 80;
  538. $tab3_height = 4;
  539. $default_font_size = pdf_getPDFFontSize($outputlangs);
  540. $pdf->SetFont('','', $default_font_size - 2);
  541. $pdf->SetXY($tab3_posx, $tab3_top - 5);
  542. $pdf->MultiCell(60, 5, $outputlangs->transnoentities("PaymentsAlreadyDone"), 0, 'L', 0);
  543. $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height);
  544. $pdf->SetFont('','', $default_font_size - 4);
  545. $pdf->SetXY($tab3_posx, $tab3_top );
  546. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0);
  547. $pdf->SetXY($tab3_posx+21, $tab3_top );
  548. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0);
  549. $pdf->SetXY($tab3_posx+40, $tab3_top );
  550. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0);
  551. $pdf->SetXY($tab3_posx+58, $tab3_top );
  552. $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0);
  553. $y=0;
  554. $pdf->SetFont('','', $default_font_size - 4);
  555. // Loop on each payment
  556. $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount,";
  557. $sql.= " cp.code";
  558. $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX."paiementfourn as p";
  559. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id";
  560. $sql.= " WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".$object->id;
  561. $sql.= " ORDER BY p.datep";
  562. $resql=$this->db->query($sql);
  563. if ($resql)
  564. {
  565. $num = $this->db->num_rows($resql);
  566. $i=0;
  567. while ($i < $num) {
  568. $y+=3;
  569. $row = $this->db->fetch_object($resql);
  570. $pdf->SetXY($tab3_posx, $tab3_top+$y );
  571. $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0);
  572. $pdf->SetXY($tab3_posx+21, $tab3_top+$y);
  573. $pdf->MultiCell(20, 3, price($row->amount), 0, 'L', 0);
  574. $pdf->SetXY($tab3_posx+40, $tab3_top+$y);
  575. $oper = $outputlangs->getTradFromKey("PaymentTypeShort" . $row->code);
  576. $pdf->MultiCell(20, 3, $oper, 0, 'L', 0);
  577. $pdf->SetXY($tab3_posx+58, $tab3_top+$y);
  578. $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0);
  579. $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3 );
  580. $i++;
  581. }
  582. }
  583. else
  584. {
  585. $this->error=$this->db->lasterror();
  586. dol_syslog($this->db,$this->error, LOG_ERR);
  587. return -1;
  588. }
  589. }
  590. /**
  591. * Show header of page
  592. *
  593. * @param $pdf Object PDF
  594. * @param $object Object order
  595. * @param $showaddress 0=no, 1=yes
  596. * @param $outputlangs Object lang for output
  597. */
  598. function _pagehead(&$pdf, $object, $showaddress=1, $outputlangs)
  599. {
  600. global $langs,$conf,$mysoc;
  601. $outputlangs->load("main");
  602. $outputlangs->load("bills");
  603. $outputlangs->load("orders");
  604. $outputlangs->load("companies");
  605. $default_font_size = pdf_getPDFFontSize($outputlangs);
  606. // Do not add the BACKGROUND as this is for suppliers
  607. //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  608. $pdf->SetTextColor(0,0,60);
  609. $pdf->SetFont('','B', $default_font_size + 3);
  610. $posx=$this->page_largeur-$this->marge_droite-100;
  611. $posy=$this->marge_haute;
  612. $pdf->SetXY($this->marge_gauche,$posy);
  613. // Logo
  614. /*
  615. $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  616. if ($mysoc->logo)
  617. {
  618. if (is_readable($logo))
  619. {
  620. $pdf->Image($logo, $this->marge_gauche, $posy, 0, 24);
  621. }
  622. else
  623. {
  624. $pdf->SetTextColor(200,0,0);
  625. $pdf->SetFont('','B', $default_font_size - 2);
  626. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  627. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  628. }
  629. }
  630. else
  631. {*/
  632. $text=$this->emetteur->name;
  633. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  634. //}
  635. $pdf->SetFont('','B', $default_font_size + 3);
  636. $pdf->SetXY($posx,$posy);
  637. $pdf->SetTextColor(0,0,60);
  638. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("SupplierInvoice")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  639. $pdf->SetFont('','', $default_font_size + 2);
  640. $posy+=6;
  641. $pdf->SetXY($posx,$posy);
  642. if ($object->date)
  643. {
  644. $pdf->SetTextColor(0,0,60);
  645. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
  646. }
  647. else
  648. {
  649. $pdf->SetTextColor(255,0,0);
  650. $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
  651. }
  652. if ($showaddress)
  653. {
  654. // Sender properties
  655. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  656. // Show sender
  657. $posy=42;
  658. $posx=$this->marge_gauche;
  659. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  660. $hautcadre=40;
  661. // Show sender frame
  662. $pdf->SetTextColor(0,0,0);
  663. $pdf->SetFont('','', $default_font_size - 2);
  664. $pdf->SetXY($posx,$posy-5);
  665. $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
  666. $pdf->SetXY($posx,$posy);
  667. $pdf->SetFillColor(230,230,230);
  668. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  669. $pdf->SetTextColor(0,0,60);
  670. // Show sender name
  671. $pdf->SetXY($posx+2,$posy+3);
  672. $pdf->SetFont('','B', $default_font_size);
  673. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  674. // Show sender information
  675. $pdf->SetXY($posx+2,$posy+8);
  676. $pdf->SetFont('','', $default_font_size - 1);
  677. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  678. // If BILLING contact defined on invoice, we use it
  679. $usecontact=false;
  680. $arrayidcontact=$object->getIdContact('external','BILLING');
  681. if (count($arrayidcontact) > 0)
  682. {
  683. $usecontact=true;
  684. $result=$object->fetch_contact($arrayidcontact[0]);
  685. }
  686. // Recipient name
  687. if (! empty($usecontact))
  688. {
  689. // On peut utiliser le nom de la societe du contact
  690. if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
  691. else $socname = $object->client->nom;
  692. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  693. }
  694. else
  695. {
  696. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  697. }
  698. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  699. // Show recipient
  700. $posy=42;
  701. $posx=$this->page_largeur-$this->marge_droite-100;
  702. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  703. // Show recipient frame
  704. $pdf->SetTextColor(0,0,0);
  705. $pdf->SetFont('','', $default_font_size - 2);
  706. $pdf->SetXY($posx+2,$posy-5);
  707. $pdf->MultiCell(80,5, $outputlangs->transnoentities("BillTo").":",0,'L');
  708. $pdf->rect($posx, $posy, 100, $hautcadre);
  709. // Show recipient name
  710. $pdf->SetXY($posx+2,$posy+3);
  711. $pdf->SetFont('','B', $default_font_size);
  712. $pdf->MultiCell(96,4, $carac_client_name, 0, 'L');
  713. // Show recipient information
  714. $pdf->SetFont('','', $default_font_size - 1);
  715. $pdf->SetXY($posx+2,$posy+8);
  716. $pdf->MultiCell(86,4, $carac_client, 0, 'L');
  717. }
  718. }
  719. /**
  720. * \brief Show footer of page
  721. * \param pdf PDF factory
  722. * \param object Object invoice
  723. * \param outputlang Object lang for output
  724. * \remarks Need this->emetteur object
  725. */
  726. function _pagefoot(&$pdf, $object, $outputlangs)
  727. {
  728. return pdf_pagefoot($pdf,$outputlangs,'SUPPLIER_INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  729. }
  730. }
  731. ?>