PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/livraison/pdf/pdf_typhon.modules.php

https://bitbucket.org/speedealing/speedealing
PHP | 684 lines | 421 code | 113 blank | 150 comment | 47 complexity | 24f59b6a85d50301a0eb8676a3ddb3df MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
  5. * Copyright (C) 2008 Chiptronik
  6. * Copyright (C) 2011-2012 Philippe Grand <philippe.grand@atoo-net.com>
  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 3 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/livraison/pdf/pdf_typhon.modules.php
  23. * \ingroup livraison
  24. * \brief File of class to manage receving receipts with template Typhon
  25. * \author Laurent Destailleur
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php';
  28. require_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.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. * Classe permettant de generer les bons de livraison au modele Typho
  33. */
  34. class pdf_typhon extends ModelePDFDeliveryOrder
  35. {
  36. var $emetteur; // Objet societe qui emet
  37. /**
  38. * Constructor
  39. *
  40. * @param DoliDB $db Database handler
  41. */
  42. function __construct($db = '')
  43. {
  44. global $conf,$langs,$mysoc;
  45. $langs->load("main");
  46. $langs->load("bills");
  47. $langs->load("sendings");
  48. $langs->load("companies");
  49. $this->db = $db;
  50. $this->name = "typhon";
  51. $this->description = $langs->trans("DocumentModelTyphon");
  52. // Dimension page pour format A4
  53. $this->type = 'pdf';
  54. $formatarray=pdf_getFormat();
  55. $this->page_largeur = $formatarray['width'];
  56. $this->page_hauteur = $formatarray['height'];
  57. $this->format = array($this->page_largeur,$this->page_hauteur);
  58. $this->marge_gauche=10;
  59. $this->marge_droite=10;
  60. $this->marge_haute=10;
  61. $this->marge_basse=10;
  62. $this->option_logo = 1; // Affiche logo FAC_PDF_LOGO
  63. $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
  64. $this->option_codeproduitservice = 1; // Affiche code produit-service
  65. $this->franchise=!$mysoc->tva_assuj;
  66. // Recupere emmetteur
  67. $this->emetteur=$mysoc;
  68. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'�tait pas d�fini
  69. // Defini position des colonnes
  70. $this->posxdesc=$this->marge_gauche+1;
  71. $this->posxcomm=120;
  72. //$this->posxtva=111;
  73. $this->posxup=132;
  74. $this->posxqty=168;
  75. $this->posxdiscount=162;
  76. $this->postotalht=177;
  77. $this->tva=array();
  78. $this->atleastoneratenotnull=0;
  79. $this->atleastonediscount=0;
  80. }
  81. /**
  82. * Fonction generant le bon de livraison sur le disque
  83. *
  84. * @param Object $object Object livraison a generer
  85. * @param Translate $outputlangs Lang output object
  86. * @return int 1 if OK, <=0 if KO
  87. */
  88. function write_file($object,$outputlangs)
  89. {
  90. global $user,$langs,$conf;
  91. $default_font_size = pdf_getPDFFontSize($outputlangs);
  92. if (! is_object($outputlangs)) $outputlangs=$langs;
  93. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  94. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  95. $outputlangs->load("main");
  96. $outputlangs->load("dict");
  97. $outputlangs->load("companies");
  98. $outputlangs->load("bills");
  99. $outputlangs->load("products");
  100. $outputlangs->load("deliveries");
  101. $outputlangs->load("sendings");
  102. if ($conf->expedition->dir_output."/receipt")
  103. {
  104. $object->fetch_thirdparty();
  105. $nblines = count($object->lines);
  106. $objectref = dol_sanitizeFileName($object->ref);
  107. $dir = $conf->expedition->dir_output."/receipt";
  108. if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
  109. $file = $dir . "/" . $objectref . ".pdf";
  110. if (! file_exists($dir))
  111. {
  112. if (dol_mkdir($dir) < 0)
  113. {
  114. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  115. return 0;
  116. }
  117. }
  118. if (file_exists($dir))
  119. {
  120. $pdf=pdf_getInstance($this->format);
  121. $heightforinfotot = 50; // Height reserved to output the info and total part
  122. $heightforfooter = 50; // Height reserved to output the footer (value include bottom margin)
  123. $pdf->SetAutoPageBreak(1,0);
  124. if (class_exists('TCPDF'))
  125. {
  126. $pdf->setPrintHeader(false);
  127. $pdf->setPrintFooter(false);
  128. }
  129. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  130. // Set path to the background PDF File
  131. if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  132. {
  133. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  134. $tplidx = $pdf->importPage(1);
  135. }
  136. // Complete object by loading several other informations
  137. $expedition=new Expedition($this->db);
  138. $result = $expedition->fetch($object->expedition_id);
  139. $commande = new Commande($this->db);
  140. if ($expedition->origin == 'commande')
  141. {
  142. $commande->fetch($expedition->origin_id);
  143. }
  144. $object->commande=$commande;
  145. $pdf->Open();
  146. $pagenb=0;
  147. $pdf->SetDrawColor(128,128,128);
  148. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  149. $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
  150. $pdf->SetCreator("Speedealing ".DOL_VERSION);
  151. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  152. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("DeliveryOrder"));
  153. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  154. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  155. /*
  156. // Positionne $this->atleastonediscount si on a au moins une remise
  157. for ($i = 0 ; $i < $nblignes ; $i++)
  158. {
  159. if ($object->lines[$i]->remise_percent)
  160. {
  161. $this->atleastonediscount++;
  162. }
  163. }
  164. */
  165. // New page
  166. $pdf->AddPage();
  167. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  168. $pagenb++;
  169. $this->_pagehead($pdf, $object, 1, $outputlangs);
  170. $pdf->SetFont('','', $default_font_size - 1);
  171. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  172. $pdf->SetTextColor(0,0,0);
  173. $tab_top = 90;
  174. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
  175. $tab_height = 130;
  176. $tab_height_newpage = 150;
  177. // Affiche notes
  178. if (! empty($object->note_public))
  179. {
  180. $tab_top = 88;
  181. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  182. $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
  183. $nexY = $pdf->GetY();
  184. $height_note=$nexY-$tab_top;
  185. // Rect prend une longueur en 3eme param
  186. $pdf->SetDrawColor(192,192,192);
  187. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  188. $tab_height = $tab_height - $height_note;
  189. $tab_top = $nexY+6;
  190. }
  191. else
  192. {
  193. $height_note=0;
  194. }
  195. $iniY = $tab_top + 7;
  196. $curY = $tab_top + 7;
  197. $nexY = $tab_top + 7;
  198. // Loop on each lines
  199. for ($i = 0 ; $i < $nblines ; $i++)
  200. {
  201. $curY = $nexY;
  202. $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
  203. $pdf->SetTextColor(0,0,0);
  204. $pdf->setTopMargin($tab_top_newpage);
  205. $pdf->setPageOrientation('', 1, $this->marge_basse+$heightforfooter+$heightforinfotot-50); // The only function to edit the bottom margin of current page to set it.
  206. $pageposbefore=$pdf->getPage();
  207. // Description of product line
  208. $curX = $this->posxdesc-1;
  209. pdf_writelinedesc($pdf,$object,$i,$outputlangs,108,3,$curX,$curY);
  210. $nexY = $pdf->GetY();
  211. $pageposafter=$pdf->getPage();
  212. $pdf->setPage($pageposbefore);
  213. $pdf->setTopMargin($this->marge_haute);
  214. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  215. // We suppose that a too long description is moved completely on next page
  216. if ($pageposafter > $pageposbefore) {
  217. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  218. }
  219. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  220. $nexY = $pdf->GetY()+4;
  221. /*
  222. // TVA
  223. $pdf->SetXY($this->posxtva, $curY);
  224. $pdf->MultiCell(10, 4, ($object->lines[$i]->tva_tx < 0 ? '*':'').abs($object->lines[$i]->tva_tx), 0, 'R');
  225. // Prix unitaire HT avant remise
  226. $pdf->SetXY($this->posxup, $curY);
  227. $pdf->MultiCell(20, 4, price($object->lines[$i]->subprice), 0, 'R', 0);
  228. */
  229. // Quantity
  230. $pdf->SetXY($this->posxqty, $curY);
  231. $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'R');
  232. /*
  233. // Remise sur ligne
  234. $pdf->SetXY($this->posxdiscount, $curY);
  235. if ($object->lines[$i]->remise_percent)
  236. {
  237. $pdf->MultiCell(14, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
  238. }
  239. // Total HT ligne
  240. $pdf->SetXY($this->postotalht, $curY);
  241. $total = price($object->lines[$i]->price * $object->lines[$i]->qty);
  242. $pdf->MultiCell(23, 3, $total, 0, 'R', 0);
  243. // Collecte des totaux par valeur de tva
  244. // dans le tableau tva["taux"]=total_tva
  245. $tvaligne=$object->lines[$i]->price * $object->lines[$i]->qty;
  246. if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
  247. $this->tva[ (string) $object->lines[$i]->tva_tx ] += $tvaligne;
  248. */
  249. $nexY+=2; // Passe espace entre les lignes
  250. // Detect if some page were added automatically and output _tableau for past pages
  251. while ($pagenb < $pageposafter)
  252. {
  253. $pdf->setPage($pagenb);
  254. if ($pagenb == 1)
  255. {
  256. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  257. }
  258. else
  259. {
  260. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  261. }
  262. $this->_pagefoot($pdf,$object,$outputlangs);
  263. $pagenb++;
  264. $pdf->setPage($pagenb);
  265. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  266. }
  267. if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  268. {
  269. if ($pagenb == 1)
  270. {
  271. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  272. }
  273. else
  274. {
  275. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  276. }
  277. $this->_pagefoot($pdf,$object,$outputlangs);
  278. // New page
  279. $pdf->AddPage();
  280. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  281. $pagenb++;
  282. }
  283. }
  284. // Show square
  285. if ($pagenb == 1)
  286. {
  287. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0);
  288. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1;
  289. }
  290. else
  291. {
  292. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0);
  293. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1;
  294. }
  295. /*
  296. * Pied de page
  297. */
  298. $this->_pagefoot($pdf,$object,$outputlangs);
  299. // Check product remaining to be delivered
  300. // TODO doit etre modifie
  301. //$waitingDelivery = $object->getRemainingDelivered();
  302. $waitingDelivery='';
  303. if (is_array($waitingDelivery) & !empty($waitingDelivery))
  304. {
  305. $pdf->AddPage('P', 'A4');
  306. $this->_pagehead($pdf, $object, 1, $outputlangs);
  307. $pdf-> SetY(90);
  308. $w=array(40,100,50);
  309. $header=array($outputlangs->transnoentities('Reference'),
  310. $outputlangs->transnoentities('Label'),
  311. $outputlangs->transnoentities('Qty')
  312. );
  313. // Header
  314. $num = count($header);
  315. for($i = 0; $i < $num; $i++)
  316. {
  317. $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
  318. }
  319. $pdf->Ln();
  320. // Data
  321. foreach($waitingDelivery as $value)
  322. {
  323. $pdf->Cell($w[0], 6, $value['ref'], 1, 0, 'L');
  324. $pdf->Cell($w[1], 6, $value['label'], 1, 0, 'L');
  325. $pdf->Cell($w[2], 6, $value['qty'], 1, 1, 'R');
  326. if ($pdf->GetY() > 250)
  327. {
  328. $this->_pagefoot($pdf,$object,$outputlangs);
  329. $pdf->AddPage('P', 'A4');
  330. $pdf->SetFont('','', $default_font_size - 1);
  331. $this->_pagehead($pdf, $object, 0, $outputlangs);
  332. $pdf-> SetY(40);
  333. $num = count($header);
  334. for($i = 0; $i < $num; $i++)
  335. {
  336. $pdf->Cell($w[$i],7,$header[$i],1,0,'C');
  337. }
  338. $pdf->Ln();
  339. }
  340. }
  341. $this->_pagefoot($pdf,$object,$outputlangs);
  342. }
  343. $pdf->AliasNbPages();
  344. $pdf->Close();
  345. $pdf->Output($file,'F');
  346. if (! empty($conf->global->MAIN_UMASK))
  347. @chmod($file, octdec($conf->global->MAIN_UMASK));
  348. return 1; // Pas d'erreur
  349. }
  350. else
  351. {
  352. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  353. return 0;
  354. }
  355. }
  356. $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR");
  357. return 0;
  358. }
  359. /**
  360. * Show table for lines
  361. *
  362. * @param PDF &$pdf Object PDF
  363. * @param string $tab_top Top position of table
  364. * @param string $tab_height Height of table (rectangle)
  365. * @param int $nexY Y
  366. * @param Translate $outputlangs Langs object
  367. * @param int $hidetop Hide top bar of array
  368. * @param int $hidebottom Hide bottom bar of array
  369. * @return void
  370. */
  371. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
  372. {
  373. global $conf,$mysoc;
  374. $default_font_size = pdf_getPDFFontSize($outputlangs);
  375. $pdf->SetDrawColor(128,128,128);
  376. // Rect prend une longueur en 3eme param
  377. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
  378. // line prend une position y en 3eme param
  379. $pdf->line($this->marge_gauche, $tab_top+6, $this->page_largeur-$this->marge_droite, $tab_top+6);
  380. $pdf->SetTextColor(0,0,0);
  381. $pdf->SetFont('','', $default_font_size - 1);
  382. $pdf->SetXY($this->posxdesc-1, $tab_top+1);
  383. $pdf->MultiCell(80,2, $outputlangs->transnoentities("Designation"),'','L');
  384. // Modif SEB pour avoir une col en plus pour les commentaires clients
  385. $pdf->line($this->posxcomm, $tab_top, $this->posxcomm, $tab_top + $tab_height);
  386. $pdf->SetXY($this->posxcomm, $tab_top+1);
  387. $pdf->MultiCell(80,2, $outputlangs->transnoentities("Comments"),'','L');
  388. // Qty
  389. $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
  390. $pdf->SetXY($this->posxqty-1, $tab_top+1);
  391. $pdf->MultiCell(30, 2, $outputlangs->transnoentities("QtyShipped"),'','R');
  392. // Modif Seb cadres signatures
  393. $pdf->SetFont('','', $default_font_size);
  394. $larg_sign = ($this->page_largeur-$this->marge_gauche-$this->marge_droite)/3;
  395. $pdf->Rect($this->marge_gauche, ($tab_top + $tab_height + 3), $larg_sign, 25);
  396. $pdf->SetXY($this->marge_gauche + 2, $tab_top + $tab_height + 5);
  397. $pdf->MultiCell($larg_sign,2, $outputlangs->trans("For").' '.$outputlangs->convToOutputCharset($mysoc->name).":",'','L');
  398. $pdf->Rect(2*$larg_sign+$this->marge_gauche, ($tab_top + $tab_height + 3), $larg_sign, 25);
  399. $pdf->SetXY(2*$larg_sign+$this->marge_gauche + 2, $tab_top + $tab_height + 5);
  400. $pdf->MultiCell($larg_sign,2, $outputlangs->trans("ForCustomer").':','','L');
  401. }
  402. /**
  403. * Show top header of page.
  404. *
  405. * @param PDF &$pdf Object PDF
  406. * @param Object $object Object to show
  407. * @param int $showaddress 0=no, 1=yes
  408. * @param Translate $outputlangs Object lang for output
  409. * @return void
  410. */
  411. function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  412. {
  413. global $langs,$conf,$mysoc;
  414. $default_font_size = pdf_getPDFFontSize($outputlangs);
  415. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  416. $pdf->SetTextColor(0,0,60);
  417. $pdf->SetFont('','B', $default_font_size + 3);
  418. $posx=$this->page_largeur-$this->marge_droite-100;
  419. $posy=$this->marge_haute;
  420. $pdf->SetXY($this->marge_gauche,$posy);
  421. // Logo
  422. $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
  423. if ($mysoc->logo)
  424. {
  425. if (is_readable($logo))
  426. {
  427. $height=pdf_getHeightForLogo($logo);
  428. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  429. }
  430. else
  431. {
  432. $pdf->SetTextColor(200,0,0);
  433. $pdf->SetFont('','B', $default_font_size - 2);
  434. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  435. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  436. }
  437. }
  438. else $pdf->MultiCell(100, 4, $this->emetteur->name, 0, 'L');
  439. $pdf->SetFont('','B', $default_font_size + 2);
  440. $pdf->SetXY($posx,$posy);
  441. $pdf->SetTextColor(0,0,60);
  442. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), '', 'R');
  443. $pdf->SetFont('','',$default_font_size + 2);
  444. $posy+=5;
  445. $pdf->SetXY($posx,$posy);
  446. $pdf->SetTextColor(0,0,60);
  447. if ($object->date_valid)
  448. {
  449. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dol_print_date(($object->date_delivery?$object->date_delivery:$date->valid),"%d %b %Y",false,$outputlangs,true), '', 'R');
  450. }
  451. else
  452. {
  453. $pdf->SetTextColor(255,0,0);
  454. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DeliveryNotValidated"), '', 'R');
  455. $pdf->SetTextColor(0,0,60);
  456. }
  457. if ($object->client->code_client)
  458. {
  459. $posy+=5;
  460. $pdf->SetXY($posx,$posy);
  461. $pdf->SetTextColor(0,0,60);
  462. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'R');
  463. }
  464. $pdf->SetTextColor(0,0,60);
  465. // Add origin linked objects
  466. // TODO extend to other objects
  467. $object->fetchObjectLinked('','',$object->id,'delivery');
  468. if (! empty($object->linkedObjects))
  469. {
  470. $outputlangs->load('orders');
  471. foreach($object->linkedObjects as $elementtype => $objects)
  472. {
  473. $object->fetchObjectLinked('','',$objects[0]->id,$objects[0]->element);
  474. foreach($object->linkedObjects as $elementtype => $objects)
  475. {
  476. $num=count($objects);
  477. for ($i=0;$i<$num;$i++)
  478. {
  479. $order=new Commande($this->db);
  480. $result=$order->fetch($objects[$i]->id);
  481. if ($result >= 0)
  482. {
  483. $posy+=5;
  484. $pdf->SetXY($posx,$posy);
  485. $pdf->SetFont('','', $default_font_size - 1);
  486. $text=$order->ref;
  487. if ($order->ref_client) $text.=' ('.$order->ref_client.')';
  488. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  489. }
  490. }
  491. }
  492. }
  493. }
  494. if ($showaddress)
  495. {
  496. // Emetteur
  497. $posy=42;
  498. $hautcadre=40;
  499. $pdf->SetTextColor(0,0,0);
  500. $pdf->SetFont('','', $default_font_size - 2);
  501. $pdf->SetXY($this->marge_gauche,$posy-5);
  502. $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":");
  503. $pdf->SetXY($this->marge_gauche,$posy);
  504. $pdf->SetFillColor(230,230,230);
  505. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  506. $pdf->SetXY($this->marge_gauche+2,$posy+3);
  507. // Nom emetteur
  508. $pdf->SetTextColor(0,0,60);
  509. $pdf->SetFont('','B',$default_font_size);
  510. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  511. // Sender properties
  512. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  513. $pdf->SetFont('','', $default_font_size - 1);
  514. $pdf->SetXY($this->marge_gauche+2,$posy+9);
  515. $pdf->MultiCell(80, 3, $carac_emetteur, 0, 'L');
  516. // Client destinataire
  517. $posy=42;
  518. $pdf->SetTextColor(0,0,0);
  519. $pdf->SetFont('','', $default_font_size - 2);
  520. $pdf->SetXY(102,$posy-5);
  521. $pdf->MultiCell(80,5, $outputlangs->transnoentities("DeliveryAddress").":", 0, 'L');
  522. // Cadre client destinataire
  523. $pdf->Rect(100, $posy, 100, $hautcadre);
  524. // If SHIPPING contact defined on invoice, we use it
  525. $usecontact=false;
  526. $arrayidcontact=$object->commande->getIdContact('external','SHIPPING');
  527. if (count($arrayidcontact) > 0)
  528. {
  529. $usecontact=true;
  530. $result=$object->fetch_contact($arrayidcontact[0]);
  531. }
  532. // Recipient name
  533. if (! empty($usecontact))
  534. {
  535. // On peut utiliser le nom de la societe du contact
  536. if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname;
  537. else $socname = $object->client->nom;
  538. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  539. }
  540. else
  541. {
  542. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  543. }
  544. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  545. // Show customer/recipient
  546. $pdf->SetXY(102,$posy+3);
  547. $pdf->SetFont('','B', $default_font_size);
  548. $pdf->MultiCell(106,4, $carac_client_name, 0, 'L');
  549. $pdf->SetFont('','', $default_font_size - 1);
  550. $pdf->SetXY(102,$posy+8);
  551. $pdf->MultiCell(86,4, $carac_client, 0, 'L');
  552. }
  553. }
  554. /**
  555. * Show footer of page. Need this->emetteur object
  556. *
  557. * @param PDF &$pdf PDF
  558. * @param Object $object Object to show
  559. * @param Translate $outputlangs Object lang for output
  560. * @return void
  561. */
  562. function _pagefoot(&$pdf,$object,$outputlangs)
  563. {
  564. return pdf_pagefoot($pdf,$outputlangs,'DELIVERY_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  565. }
  566. }
  567. ?>