PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/asterix14/dolibarr
PHP | 459 lines | 281 code | 84 blank | 94 comment | 34 complexity | 8d215023df4426023419003adf7fcc1e MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  5. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
  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/livraison/pdf/pdf_sirocco.modules.php
  23. * \ingroup livraison
  24. * \brief File of class to manage receving receipts with template Sirocco
  25. */
  26. require_once(DOL_DOCUMENT_ROOT."/core/modules/livraison/modules_livraison.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_sirocco
  31. * \brief Classe permettant de generer les bons de livraison au modele Sirocco
  32. */
  33. class pdf_sirocco extends ModelePDFDeliveryOrder
  34. {
  35. /**
  36. * Constructor
  37. *
  38. * @param DoliDB $DB Database handler
  39. */
  40. function pdf_sirocco($db)
  41. {
  42. global $conf,$langs,$mysoc;
  43. $langs->load("main");
  44. $langs->load("bills");
  45. $langs->load("sendings");
  46. $langs->load("companies");
  47. $this->db = $db;
  48. $this->name = "sirocco";
  49. $this->description = $langs->trans("DocumentModelSirocco");
  50. // Dimension page pour format A4
  51. $this->type = 'pdf';
  52. $formatarray=pdf_getFormat();
  53. $this->page_largeur = $formatarray['width'];
  54. $this->page_hauteur = $formatarray['height'];
  55. $this->format = array($this->page_largeur,$this->page_hauteur);
  56. $this->marge_gauche=10;
  57. $this->marge_droite=10;
  58. $this->marge_haute=10;
  59. $this->marge_basse=10;
  60. // Recupere emmetteur
  61. $this->emetteur=$mysoc;
  62. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'�tait pas d�fini
  63. $this->tva=array();
  64. }
  65. /**
  66. * Fonction generant le bon de livraison sur le disque
  67. * @param object Object livraison a generer
  68. * @param outputlangs Lang output object
  69. * @return int 1 if OK, <=0 if KO
  70. */
  71. function write_file($object,$outputlangs)
  72. {
  73. global $user,$conf,$langs;
  74. $default_font_size = pdf_getPDFFontSize($outputlangs);
  75. if (! is_object($outputlangs)) $outputlangs=$langs;
  76. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  77. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  78. $outputlangs->load("main");
  79. $outputlangs->load("dict");
  80. $outputlangs->load("bills");
  81. $outputlangs->load("products");
  82. $outputlangs->load("deliveries");
  83. $outputlangs->load("sendings");
  84. if ($conf->expedition->dir_output."/receipt")
  85. {
  86. $object->fetch_thirdparty();
  87. $nblines = count($object->lines);
  88. $objectref = dol_sanitizeFileName($object->ref);
  89. $dir = $conf->expedition->dir_output."/receipt";
  90. if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
  91. $file = $dir . "/" . $objectref . ".pdf";
  92. if (! file_exists($dir))
  93. {
  94. if (create_exdir($dir) < 0)
  95. {
  96. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  97. return 0;
  98. }
  99. }
  100. if (file_exists($dir))
  101. {
  102. $pdf=pdf_getInstance($this->format);
  103. if (class_exists('TCPDF'))
  104. {
  105. $pdf->setPrintHeader(false);
  106. $pdf->setPrintFooter(false);
  107. }
  108. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  109. // Complete object by loading several other informations
  110. $expedition=new Expedition($this->db);
  111. $result = $expedition->fetch($object->expedition_id);
  112. $commande = new Commande($this->db);
  113. if ($expedition->origin == 'commande')
  114. {
  115. $commande->fetch($expedition->origin_id);
  116. }
  117. $object->commande=$commande;
  118. $pdf->Open();
  119. $pagenb=0;
  120. $pdf->SetDrawColor(128,128,128);
  121. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  122. $pdf->SetSubject($outputlangs->transnoentities("DeliveryOrder"));
  123. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  124. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  125. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("DeliveryOrder"));
  126. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  127. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  128. $pdf->SetAutoPageBreak(1,0);
  129. // New page
  130. $pdf->AddPage();
  131. $pagenb++;
  132. $this->_pagehead($pdf, $object, 1, $outputlangs);
  133. $pdf->SetFont('','', $default_font_size - 1);
  134. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  135. $pdf->SetTextColor(0,0,0);
  136. $tab_top = 100;
  137. $tab_top_newpage = 50;
  138. $tab_height = 140;
  139. $tab_height_newpage = 190;
  140. $iniY = $tab_top + 7;
  141. $curY = $tab_top + 7;
  142. $nexY = $tab_top + 7;
  143. for ($i = 0 ; $i < $nblines ; $i++)
  144. {
  145. $curY = $nexY;
  146. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  147. // Description de la ligne produit
  148. //$libelleproduitservice=pdf_getlinedesc($object,$i,$outputlangs);
  149. pdf_writelinedesc($pdf,$object,$i,$outputlangs,100,3,30,$curY,1);
  150. //$pdf->writeHTMLCell(100, 3, 30, $curY, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 1);
  151. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  152. $nexY = $pdf->GetY();
  153. $pdf->SetXY(10, $curY );
  154. $pdf->MultiCell(20, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'C');
  155. // TODO Field not yet saved in database
  156. //$pdf->SetXY(133, $curY );
  157. //$pdf->MultiCell(10, 5, $object->lines[$i]->tva_tx, 0, 'C');
  158. $pdf->SetXY(145, $curY );
  159. $pdf->MultiCell(10, 3, $object->lines[$i]->qty_shipped, 0, 'C');
  160. // TODO Field not yet saved in database
  161. //$pdf->SetXY(156, $curY );
  162. //$pdf->MultiCell(20, 3, price($object->lines[$i]->price), 0, 'R', 0);
  163. // TODO Field not yet saved in database
  164. //$pdf->SetXY(174, $curY );
  165. //$total = price($object->lines[$i]->price * $object->lines[$i]->qty_shipped);
  166. //$pdf->MultiCell(26, 3, $total, 0, 'R', 0);
  167. $pdf->line(10, $curY-1, 200, $curY-1);
  168. $nexY+=2; // Passe espace entre les lignes
  169. // Cherche nombre de lignes a venir pour savoir si place suffisante
  170. if ($i < ($nblines - 1) && empty($hidedesc)) // If it's not last line
  171. {
  172. //on recupere la description du produit suivant
  173. $follow_descproduitservice = $object->lines[$i+1]->desc;
  174. //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
  175. $nblineFollowDesc = (dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4);
  176. }
  177. else // If it's last line
  178. {
  179. $nblineFollowDesc = 0;
  180. }
  181. // Test if a new page is required
  182. if ($pagenb == 1)
  183. {
  184. $tab_top_in_current_page=$tab_top;
  185. $tab_height_in_current_page=$tab_height;
  186. }
  187. else
  188. {
  189. $tab_top_in_current_page=$tab_top_newpage;
  190. $tab_height_in_current_page=$tab_height_newpage;
  191. }
  192. if (($nexY+$nblineFollowDesc) > ($tab_top_in_current_page+$tab_height_in_current_page) && $i < ($nblignes - 1))
  193. {
  194. if ($pagenb == 1)
  195. {
  196. $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
  197. }
  198. else
  199. {
  200. $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
  201. }
  202. $this->_pagefoot($pdf, $object, $outputlangs);
  203. // New page
  204. $pdf->AddPage();
  205. $pagenb++;
  206. $this->_pagehead($pdf, $object, 0, $outputlangs);
  207. $pdf->SetFont('','', $default_font_size - 1);
  208. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  209. $pdf->SetTextColor(0,0,0);
  210. $nexY = $tab_top_newpage + 7;
  211. }
  212. }
  213. // Show square
  214. if ($pagenb == 1)
  215. {
  216. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
  217. $bottomlasttab=$tab_top + $tab_height + 1;
  218. }
  219. else
  220. {
  221. $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
  222. $bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1;
  223. }
  224. /*
  225. * Pied de page
  226. */
  227. $this->_pagefoot($pdf, $object, $outputlangs);
  228. $pdf->AliasNbPages();
  229. $pdf->Close();
  230. $pdf->Output($file,'F');
  231. if (! empty($conf->global->MAIN_UMASK))
  232. @chmod($file, octdec($conf->global->MAIN_UMASK));
  233. return 1;
  234. }
  235. }
  236. else
  237. {
  238. $this->error=$langs->transnoentities("ErrorConstantNotDefined","LIVRAISON_OUTPUTDIR");
  239. return 0;
  240. }
  241. }
  242. /**
  243. * \brief Affiche la grille des lignes
  244. * \param pdf objet PDF
  245. */
  246. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs)
  247. {
  248. $default_font_size = pdf_getPDFFontSize($outputlangs);
  249. $pdf->SetFont('','', $default_font_size - 1);
  250. $pdf->SetXY(30, $tab_top+1);
  251. $pdf->MultiCell(60, 2, $outputlangs->transnoentities("Designation"), 0, 'L');
  252. $pdf->line(144, $tab_top, 144, $tab_top + $tab_height);
  253. $pdf->SetXY(147, $tab_top+1);
  254. $pdf->MultiCell(30, 2, $outputlangs->transnoentities("QtyShipped"), 0, 'L');
  255. $pdf->Rect(10, $tab_top, 190, $tab_height);
  256. }
  257. /**
  258. * Show header of page
  259. *
  260. * @param $pdf Object PDF
  261. * @param $object Object delivery
  262. * @param $showaddress 0=no, 1=yes
  263. * @param $outputlangs Object lang for output
  264. */
  265. function _pagehead(&$pdf, $object, $showaddress=1, $outputlangs)
  266. {
  267. global $langs,$conf,$mysoc;
  268. $default_font_size = pdf_getPDFFontSize($outputlangs);
  269. $outputlangs->load("companies");
  270. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  271. $pdf->SetTextColor(0,0,60);
  272. $pdf->SetFont('','B', $default_font_size + 3);
  273. $posx=$this->page_largeur-$this->marge_droite-100;
  274. $posy=$this->marge_haute;
  275. $pdf->SetXY($this->marge_gauche,$posy);
  276. if ($conf->global->MAIN_INFO_SOCIETE_NOM)
  277. {
  278. $pdf->SetTextColor(0,0,200);
  279. $pdf->SetFont('','B', $default_font_size + 2);
  280. $pdf->MultiCell(76, 4, $outputlangs->convToOutputCharset(MAIN_INFO_SOCIETE_NOM), 0, 'L');
  281. }
  282. // Sender properties
  283. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  284. $pdf->SetFont('','', $default_font_size - 1);
  285. $pdf->SetXY($this->marge_gauche,$posy+4);
  286. $pdf->MultiCell(80, 3, $carac_emetteur, 0, 'L');
  287. /*
  288. * Adresse Client
  289. */
  290. // If SHIPPING contact defined on invoice, we use it
  291. $usecontact=false;
  292. $arrayidcontact=$object->commande->getIdContact('external','SHIPPING');
  293. if (count($arrayidcontact) > 0)
  294. {
  295. $usecontact=true;
  296. $result=$object->fetch_contact($arrayidcontact[0]);
  297. }
  298. // Recipient name
  299. if (! empty($usecontact))
  300. {
  301. // On peut utiliser le nom de la societe du contact
  302. if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
  303. else $socname = $object->client->nom;
  304. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  305. }
  306. else
  307. {
  308. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  309. }
  310. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  311. $pdf->SetTextColor(0,0,0);
  312. $pdf->SetFont('','B', $default_font_size + 1);
  313. $pdf->SetXY(102,42);
  314. $pdf->MultiCell(96,5, $carac_client_name, 0, 'L');
  315. $pdf->SetFont('','B', $default_font_size);
  316. $pdf->SetXY(102,47);
  317. $pdf->MultiCell(96,5, $carac_client, 0, 'L');
  318. $pdf->rect(100, 40, 100, 40);
  319. $pdf->SetTextColor(0,0,60);
  320. $pdf->SetFont('','B', $default_font_size + 1);
  321. $pdf->SetXY($posx, 86);
  322. $pdf->MultiCell(100, 2, $outputlangs->transnoentities("Date")." : " . dol_print_date(($object->date_delivery?$object->date_delivery:$date->valid),"day",false,$outputlangs,true), 0, 'R');
  323. $pdf->SetXY($posx, 92);
  324. $pdf->MultiCell(100, 2, $outputlangs->transnoentities("DeliveryOrder")." ".$outputlangs->convToOutputCharset($object->ref), 0, 'R');
  325. if ($object->client->code_client)
  326. {
  327. $posy+=7;
  328. $pdf->SetXY($posx, $posy);
  329. $pdf->SetTextColor(0,0,60);
  330. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'R');
  331. }
  332. $pdf->SetFont('','B', $default_font_size - 1);
  333. // Add origin linked objects
  334. // TODO extend to other objects
  335. $object->fetchObjectLinked('','',$object->id,'delivery');
  336. if (! empty($object->linkedObjects))
  337. {
  338. $outputlangs->load('orders');
  339. foreach($object->linkedObjects as $elementtype => $objects)
  340. {
  341. $object->fetchObjectLinked('','',$objects[0]->id,$objects[0]->element);
  342. foreach($object->linkedObjects as $elementtype => $objects)
  343. {
  344. $num=count($objects);
  345. for ($i=0;$i<$num;$i++)
  346. {
  347. $order=new Commande($this->db);
  348. $result=$order->fetch($objects[$i]->id);
  349. if ($result >= 0)
  350. {
  351. $posy+=5;
  352. $pdf->SetXY($posx,$posy);
  353. $pdf->SetFont('','', $default_font_size - 1);
  354. $text=$order->ref;
  355. if ($order->ref_client) $text.=' ('.$order->ref_client.')';
  356. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  357. }
  358. }
  359. }
  360. }
  361. }
  362. }
  363. /**
  364. * \brief Show footer of page
  365. * \param pdf PDF factory
  366. * \param object Object invoice
  367. * \param outputlangs Object lang for output
  368. * \remarks Need this->emetteur object
  369. */
  370. function _pagefoot(&$pdf,$object,$outputlangs)
  371. {
  372. return pdf_pagefoot($pdf,$outputlangs,'DELIVERY_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  373. }
  374. }
  375. ?>