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

/htdocs/core/modules/expedition/pdf/pdf_expedition_rouget.modules.php

https://github.com/asterix14/dolibarr
PHP | 542 lines | 351 code | 93 blank | 98 comment | 37 complexity | cbf4e53a8429e54bf67da00d799a0904 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * or see http://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/modules/expedition/pdf/pdf_expedition_rouget.modules.php
  22. * \ingroup expedition
  23. * \brief Fichier de la classe permettant de generer les bordereaux envoi au modele Rouget
  24. */
  25. require_once DOL_DOCUMENT_ROOT."/core/modules/expedition/pdf/ModelePdfExpedition.class.php";
  26. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
  28. /**
  29. * \class pdf_expedition_dorade
  30. * \brief Classe permettant de generer les borderaux envoi au modele Rouget
  31. */
  32. Class pdf_expedition_rouget extends ModelePdfExpedition
  33. {
  34. var $emetteur; // Objet societe qui emet
  35. /**
  36. * \brief Constructeur
  37. * \param db Database handler
  38. */
  39. function pdf_expedition_rouget($db=0)
  40. {
  41. global $conf,$langs,$mysoc;
  42. $this->db = $db;
  43. $this->name = "rouget";
  44. $this->description = $langs->trans("DocumentModelSimple");
  45. $this->type = 'pdf';
  46. $formatarray=pdf_getFormat();
  47. $this->page_largeur = $formatarray['width'];
  48. $this->page_hauteur = $formatarray['height'];
  49. $this->format = array($this->page_largeur,$this->page_hauteur);
  50. $this->marge_gauche=10;
  51. $this->marge_droite=10;
  52. $this->marge_haute=10;
  53. $this->marge_basse=10;
  54. $this->option_logo = 1;
  55. // Recupere emmetteur
  56. $this->emetteur=$mysoc;
  57. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // By default if not defined
  58. // Defini position des colonnes
  59. $this->posxdesc=$this->marge_gauche+1;
  60. $this->posxqtyordered=120;
  61. $this->posxqtytoship=160;
  62. }
  63. /**
  64. * \brief Fonction generant le document sur le disque
  65. * \param object Objet expedition a generer (ou id si ancienne methode)
  66. * \param outputlangs Lang output object
  67. * \return int 1=ok, 0=ko
  68. */
  69. function write_file(&$object, $outputlangs)
  70. {
  71. global $user,$conf,$langs;
  72. $default_font_size = pdf_getPDFFontSize($outputlangs);
  73. $object->fetch_thirdparty();
  74. if (! is_object($outputlangs)) $outputlangs=$langs;
  75. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  76. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  77. $outputlangs->load("main");
  78. $outputlangs->load("dict");
  79. $outputlangs->load("companies");
  80. $outputlangs->load("bills");
  81. $outputlangs->load("products");
  82. $outputlangs->load("propal");
  83. $outputlangs->load("deliveries");
  84. $outputlangs->load("sendings");
  85. if ($conf->expedition->dir_output)
  86. {
  87. // Definition de $dir et $file
  88. if ($object->specimen)
  89. {
  90. $dir = $conf->expedition->dir_output."/sending";
  91. $file = $dir . "/SPECIMEN.pdf";
  92. }
  93. else
  94. {
  95. $expref = dol_sanitizeFileName($object->ref);
  96. $dir = $conf->expedition->dir_output."/sending/" . $expref;
  97. $file = $dir . "/" . $expref . ".pdf";
  98. }
  99. if (! file_exists($dir))
  100. {
  101. if (create_exdir($dir) < 0)
  102. {
  103. $this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir);
  104. return 0;
  105. }
  106. }
  107. if (file_exists($dir))
  108. {
  109. $pdf=pdf_getInstance($this->format);
  110. if (class_exists('TCPDF'))
  111. {
  112. $pdf->setPrintHeader(false);
  113. $pdf->setPrintFooter(false);
  114. }
  115. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  116. $pdf->Open();
  117. $pagenb=0;
  118. $pdf->SetDrawColor(128,128,128);
  119. $pdf->AliasNbPages();
  120. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  121. $pdf->SetSubject($outputlangs->transnoentities("Sending"));
  122. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  123. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  124. $pdf->SetKeyWords($outputlangs->convToOutputCharset($fac->ref)." ".$outputlangs->transnoentities("Sending"));
  125. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  126. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  127. $pdf->SetAutoPageBreak(1,0);
  128. // New page
  129. $pdf->AddPage();
  130. $pagenb++;
  131. $this->_pagehead($pdf, $object, 1, $outputlangs);
  132. $pdf->SetFont('','', $default_font_size - 1);
  133. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  134. $pdf->SetTextColor(0,0,0);
  135. $tab_top = 90;
  136. $tab_height = 170;
  137. if (! empty($object->note_public) || ! empty($object->tracking_number))
  138. {
  139. $tab_top = 88;
  140. // Tracking number
  141. if (! empty($object->tracking_number))
  142. {
  143. $object->GetUrlTrackingStatus($object->tracking_number);
  144. if (! empty($object->tracking_url))
  145. {
  146. if ($object->expedition_method_id > 0)
  147. {
  148. // Get code using getLabelFromKey
  149. $code=$outputlangs->getLabelFromKey($this->db,$object->expedition_method_id,'c_shipment_mode','rowid','code');
  150. $label=$outputlangs->trans("LinkToTrackYourPackage")."<br>";
  151. $label.=$outputlangs->trans("SendingMethod".strtoupper($code))." :";
  152. $pdf->SetFont('','B', $default_font_size - 2);
  153. $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $label." ".$object->tracking_url, 0, 1, false, true, 'L');
  154. }
  155. }
  156. }
  157. // Affiche notes
  158. if (! empty($object->note_public))
  159. {
  160. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  161. $pdf->SetXY($this->posxdesc-1, $tab_top);
  162. $pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'L');
  163. }
  164. $nexY = $pdf->GetY();
  165. $height_note=$nexY-$tab_top;
  166. // Rect prend une longueur en 3eme param
  167. $pdf->SetDrawColor(192,192,192);
  168. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  169. $tab_height = $tab_height - $height_note;
  170. $tab_top = $nexY+6;
  171. }
  172. else
  173. {
  174. $height_note=0;
  175. }
  176. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
  177. $nexY = $tab_top + 7;
  178. $num=count($object->lines);
  179. for ($i = 0; $i < $num; $i++)
  180. {
  181. $curY = $nexY;
  182. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  183. // Description de la ligne produit
  184. pdf_writelinedesc($pdf,$object,$i,$outputlangs,150,3,$this->posxdesc,$curY,0,1);
  185. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  186. $nexY = $pdf->GetY();
  187. $pdf->SetXY($this->posxqtyordered+5, $curY);
  188. $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked,'','C');
  189. $pdf->SetXY($this->posxqtytoship+5, $curY);
  190. $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped,'','C');
  191. $nexY+=2; // Passe espace entre les lignes
  192. }
  193. // Pied de page
  194. $this->_pagefoot($pdf,$object,$outputlangs);
  195. $pdf->AliasNbPages();
  196. $pdf->Close();
  197. $pdf->Output($file,'F');
  198. if (! empty($conf->global->MAIN_UMASK))
  199. @chmod($file, octdec($conf->global->MAIN_UMASK));
  200. return 1;
  201. }
  202. else
  203. {
  204. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  205. return 0;
  206. }
  207. }
  208. else
  209. {
  210. $this->error=$langs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
  211. return 0;
  212. }
  213. $this->error=$langs->transnoentities("ErrorUnknown");
  214. return 0; // Erreur par defaut
  215. }
  216. /**
  217. * Build table
  218. * @param pdf objet PDF
  219. */
  220. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs)
  221. {
  222. global $conf;
  223. $default_font_size = pdf_getPDFFontSize($outputlangs);
  224. $pdf->SetTextColor(0,0,0);
  225. $pdf->SetDrawColor(128,128,128);
  226. // Rect prend une longueur en 3eme param
  227. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
  228. // line prend une position y en 3eme param
  229. $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);
  230. $pdf->SetFont('','',$default_font_size - 1);
  231. $pdf->SetXY($this->posxdesc-1, $tab_top+1);
  232. $pdf->MultiCell(108, 2, $outputlangs->trans("Description"), '', 'L');
  233. $pdf->line($this->posxqtyordered-1, $tab_top, $this->posxqtyordered-1, $tab_top + $tab_height);
  234. $pdf->SetXY($this->posxqtyordered-1, $tab_top+1);
  235. $pdf->MultiCell(40,2, $outputlangs->transnoentities("QtyOrdered"),'','C');
  236. $pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height);
  237. $pdf->SetXY($this->posxqtytoship-1, $tab_top+1);
  238. $pdf->MultiCell(40,2, $outputlangs->transnoentities("QtyToShip"),'','C');
  239. }
  240. /**
  241. * Show header of document
  242. *
  243. * @param pdf Object PDF
  244. * @param object Object commercial proposal
  245. * @param showaddress 0=no, 1=yes
  246. * @param outputlangs Object lang for output
  247. */
  248. function _pagehead(&$pdf, $object, $showaddress=1, $outputlangs)
  249. {
  250. global $conf,$langs,$mysoc;
  251. $default_font_size = pdf_getPDFFontSize($outputlangs);
  252. $langs->load("orders");
  253. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  254. //Affiche le filigrane brouillon - Print Draft Watermark
  255. if($object->statut==0 && (! empty($conf->global->SHIPPING_DRAFT_WATERMARK)) )
  256. {
  257. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SHIPPING_DRAFT_WATERMARK);
  258. }
  259. //Prepare la suite
  260. $pdf->SetTextColor(0,0,60);
  261. $pdf->SetFont('','B', $default_font_size + 3);
  262. $posx=$this->page_largeur-$this->marge_droite-100;
  263. $posy=$this->marge_haute;
  264. $pdf->SetXY($this->marge_gauche,$posy);
  265. // Logo
  266. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  267. if ($this->emetteur->logo)
  268. {
  269. if (is_readable($logo))
  270. {
  271. $pdf->Image($logo, $this->marge_gauche, $posy, 0, 24);
  272. }
  273. else
  274. {
  275. $pdf->SetTextColor(200,0,0);
  276. $pdf->SetFont('','B', $default_font_size - 2);
  277. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  278. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  279. }
  280. }
  281. else
  282. {
  283. $text=$this->emetteur->name;
  284. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  285. }
  286. // Show barcode
  287. if ($conf->barcode->enabled)
  288. {
  289. $posx=105;
  290. }
  291. else
  292. {
  293. $posx=$this->marge_gauche+3;
  294. }
  295. //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
  296. if ($conf->barcode->enabled)
  297. {
  298. // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  299. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  300. //$pdf->Image($logo,10, 5, 0, 24);
  301. }
  302. $pdf->SetDrawColor(128,128,128);
  303. if ($conf->barcode->enabled)
  304. {
  305. // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  306. //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  307. //$pdf->Image($logo,10, 5, 0, 24);
  308. }
  309. $posx=100;
  310. $posy=$this->marge_haute;
  311. $pdf->SetFont('','B', $default_font_size + 2);
  312. $pdf->SetXY($posx,$posy);
  313. $pdf->SetTextColor(0,0,60);
  314. $title=$outputlangs->transnoentities("SendingSheet");
  315. $pdf->MultiCell(100, 4, $title, '', 'R');
  316. $posy+=1;
  317. $pdf->SetFont('','', $default_font_size + 1);
  318. $posy+=4;
  319. $pdf->SetXY($posx,$posy);
  320. $pdf->SetTextColor(0,0,60);
  321. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R');
  322. //Date Expedition
  323. $posy+=4;
  324. $pdf->SetXY($posx,$posy);
  325. $pdf->SetTextColor(0,0,60);
  326. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date_creation,"daytext",false,$outputlangs,true), '', 'R');
  327. if (! empty($object->client->code_client))
  328. {
  329. $posy+=4;
  330. $pdf->SetXY($posx,$posy);
  331. $pdf->SetTextColor(0,0,60);
  332. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'R');
  333. }
  334. $pdf->SetFont('','', $default_font_size + 3);
  335. $Yoff=25;
  336. // Add list of linked orders
  337. // TODO possibility to use with other document (business module,...)
  338. //$object->load_object_linked();
  339. $origin = $object->origin;
  340. $origin_id = $object->origin_id;
  341. // TODO move to external function
  342. if ($conf->$origin->enabled)
  343. {
  344. $outputlangs->load('orders');
  345. $classname = ucfirst($origin);
  346. $linkedobject = new $classname($this->db);
  347. $result=$linkedobject->fetch($origin_id);
  348. if ($result >= 0)
  349. {
  350. $pdf->SetFont('','', $default_font_size - 2);
  351. $text=$linkedobject->ref;
  352. if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
  353. $Yoff = $Yoff+8;
  354. $pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff);
  355. $pdf->MultiCell(60, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
  356. $Yoff = $Yoff+4;
  357. $pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff);
  358. $pdf->MultiCell(60, 2, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->commande->date,"daytext",false,$outputlangs,true), 0, 'R');
  359. }
  360. }
  361. if ($showaddress)
  362. {
  363. // Sender properties
  364. $carac_emetteur='';
  365. // Add internal contact of proposal if defined
  366. $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
  367. if (count($arrayidcontact) > 0)
  368. {
  369. $object->fetch_user($arrayidcontact[0]);
  370. $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  371. }
  372. $carac_emetteur .= pdf_build_address($outputlangs,$this->emetteur);
  373. // Show sender
  374. $posx=$this->marge_gauche;
  375. $posy=42;
  376. $hautcadre=40;
  377. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=118;
  378. // Show sender frame
  379. $pdf->SetTextColor(0,0,0);
  380. $pdf->SetFont('','', $default_font_size - 2);
  381. $pdf->SetXY($posx,$posy-5);
  382. $pdf->MultiCell(66,5, $outputlangs->transnoentities("Sender").":", 0, 'L');
  383. $pdf->SetXY($posx,$posy);
  384. $pdf->SetFillColor(230,230,230);
  385. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  386. // Show sender name
  387. $pdf->SetXY($posx+2,$posy+3);
  388. $pdf->SetTextColor(0,0,60);
  389. $pdf->SetFont('','B',$default_font_size);
  390. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  391. // Show sender information
  392. $pdf->SetFont('','', $default_font_size - 1);
  393. $pdf->SetXY($posx+2,$posy+8);
  394. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  395. // If CUSTOMER contact defined, we use it
  396. $usecontact=false;
  397. $arrayidcontact=$object->getIdContact('external','CUSTOMER');
  398. if (count($arrayidcontact) > 0)
  399. {
  400. $usecontact=true;
  401. $result=$object->fetch_contact($arrayidcontact[0]);
  402. }
  403. // Recipient name
  404. if (! empty($usecontact))
  405. {
  406. // On peut utiliser le nom de la societe du contact
  407. if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
  408. else $socname = $object->client->nom;
  409. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  410. }
  411. else
  412. {
  413. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  414. }
  415. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  416. // Show recipient
  417. $posy=42;
  418. $posx=100;
  419. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  420. // Show recipient frame
  421. $pdf->SetTextColor(0,0,0);
  422. $pdf->SetFont('','', $default_font_size - 2);
  423. $pdf->SetXY($posx,$posy-5);
  424. $pdf->MultiCell(80, 4, $outputlangs->transnoentities("Recipient").":", 0, 'L');
  425. $pdf->rect($posx, $posy, 100, $hautcadre);
  426. $pdf->SetTextColor(0,0,0);
  427. // Show recipient name
  428. $pdf->SetXY($posx+2,$posy+3);
  429. $pdf->SetFont('','B', $default_font_size);
  430. $pdf->MultiCell(96,4, $carac_client_name, 0, 'L');
  431. // Show recipient information
  432. $pdf->SetFont('','', $default_font_size - 1);
  433. $pdf->SetXY($posx+2,$posy+8);
  434. $pdf->MultiCell(86,4, $carac_client, 0, 'L');
  435. }
  436. }
  437. /**
  438. * \brief Show footer of page
  439. * \param pdf PDF factory
  440. * \param object Object invoice
  441. * \param outputlangs Object lang for output
  442. * \remarks Need this->emetteur object
  443. */
  444. function _pagefoot(&$pdf,$object,$outputlangs)
  445. {
  446. return pdf_pagefoot($pdf,$outputlangs,'SHIPPING_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  447. }
  448. }
  449. ?>