PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php

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