PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/asterix14/dolibarr
PHP | 554 lines | 357 code | 84 blank | 113 comment | 31 complexity | 8c202c8cd0d5c20c4b62a732cc49a529 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_merou.modules.php
  22. * \ingroup expedition
  23. * \brief Fichier de la classe permettant de generer les bordereaux envoi au modele Merou
  24. */
  25. require_once DOL_DOCUMENT_ROOT."/core/modules/expedition/pdf/ModelePdfExpedition.class.php";
  26. require_once DOL_DOCUMENT_ROOT."/contact/class/contact.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_expedition_merou
  31. * \brief Classe permettant de generer les borderaux envoi au modele Merou
  32. */
  33. Class pdf_expedition_merou extends ModelePdfExpedition
  34. {
  35. var $emetteur; // Objet societe qui emet
  36. /**
  37. * Constructor
  38. *
  39. * @param DoliDB $DB Database handler
  40. */
  41. function pdf_expedition_merou($db=0)
  42. {
  43. global $conf,$langs,$mysoc;
  44. $this->db = $db;
  45. $this->name = "merou";
  46. //$this->description = "Modele Merou A5";
  47. $this->description = $langs->trans("DocumentModelMerou");
  48. $this->type = 'pdf';
  49. $formatarray=pdf_getFormat();
  50. $this->page_largeur = $formatarray['width'];
  51. $this->page_hauteur = round($formatarray['height']/2);
  52. $this->format = array($this->page_largeur,$this->page_hauteur);
  53. $this->marge_gauche=10;
  54. $this->marge_droite=10;
  55. $this->marge_haute=10;
  56. $this->marge_basse=10;
  57. $this->option_logo = 1; // Affiche logo
  58. // Recupere emmetteur
  59. $this->emetteur=$mysoc;
  60. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // By default if not defined
  61. }
  62. /**
  63. * \brief Fonction generant le document sur le disque
  64. * \param object Objet expedition a generer (ou id si ancienne methode)
  65. * \param outputlangs Lang output object
  66. * \return int 1=ok, 0=ko
  67. */
  68. function write_file(&$object, $outputlangs)
  69. {
  70. global $user,$conf,$langs,$mysoc;
  71. $default_font_size = pdf_getPDFFontSize($outputlangs);
  72. $object->fetch_thirdparty();
  73. if (! is_object($outputlangs)) $outputlangs=$langs;
  74. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  75. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  76. $outputlangs->load("main");
  77. $outputlangs->load("dict");
  78. $outputlangs->load("companies");
  79. $outputlangs->load("bills");
  80. $outputlangs->load("products");
  81. $outputlangs->load("propal");
  82. $outputlangs->load("sendings");
  83. $outputlangs->load("deliveries");
  84. //Generation de la fiche
  85. $this->expe = $object;
  86. //Verification de la configuration
  87. if ($conf->expedition->dir_output)
  88. {
  89. $object->fetch_thirdparty();
  90. $origin = $object->origin;
  91. //Creation de l expediteur
  92. $this->expediteur = $mysoc;
  93. //Creation du destinataire
  94. $idcontact = $object->$origin->getIdContact('external','SHIPPING');
  95. $this->destinataire = new Contact($this->db);
  96. if ($idcontact[0]) $this->destinataire->fetch($idcontact[0]);
  97. //Creation du livreur
  98. $idcontact = $object->$origin->getIdContact('internal','LIVREUR');
  99. $this->livreur = new User($this->db);
  100. if ($idcontact[0]) $this->livreur->fetch($idcontact[0]);
  101. // Definition de $dir et $file
  102. if ($object->specimen)
  103. {
  104. $dir = $conf->expedition->dir_output."/sending";
  105. $file = $dir . "/SPECIMEN.pdf";
  106. }
  107. else
  108. {
  109. $expref = dol_sanitizeFileName($object->ref);
  110. $dir = $conf->expedition->dir_output . "/sending/" . $expref;
  111. $file = $dir . "/" . $expref . ".pdf";
  112. }
  113. if (! file_exists($dir))
  114. {
  115. if (create_exdir($dir) < 0)
  116. {
  117. $this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir);
  118. return 0;
  119. }
  120. }
  121. //Si le dossier existe
  122. if (file_exists($dir))
  123. {
  124. $pdf=pdf_getInstance($this->format,'mm','l');
  125. if (class_exists('TCPDF'))
  126. {
  127. $pdf->setPrintHeader(false);
  128. $pdf->setPrintFooter(false);
  129. }
  130. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  131. $pdf->Open();
  132. $pagenb=0;
  133. $pdf->SetDrawColor(128,128,128);
  134. //Generation de l entete du fichier
  135. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  136. $pdf->SetSubject($outputlangs->transnoentities("Sending"));
  137. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  138. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  139. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Sending"));
  140. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  141. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  142. $pdf->SetAutoPageBreak(1,0);
  143. $pdf->SetFont('','', $default_font_size - 3);
  144. // New page
  145. $pdf->AddPage();
  146. $pagenb++;
  147. $this->_pagehead($pdf, $this->expe, 1, $outputlangs);
  148. $pdf->SetFont('','', $default_font_size - 3);
  149. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  150. $pdf->SetTextColor(0,0,0);
  151. //Initialisation des coordonnees
  152. $tab_top = 53;
  153. $tab_height = $this->page_hauteur - 78;
  154. $pdf->SetFillColor(240,240,240);
  155. $pdf->SetTextColor(0,0,0);
  156. $pdf->SetFont('','', $default_font_size - 3);
  157. $pdf->SetXY(10, $tab_top + 5);
  158. $iniY = $pdf->GetY();
  159. $curY = $pdf->GetY();
  160. $nexY = $pdf->GetY();
  161. //Generation du tableau
  162. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
  163. $nblignes = count($object->lines);
  164. for ($i = 0 ; $i < $nblignes ; $i++)
  165. {
  166. // Description de la ligne produit
  167. //Creation des cases a cocher
  168. $pdf->rect(10+3, $curY+1, 3, 3);
  169. $pdf->rect(20+3, $curY+1, 3, 3);
  170. //Insertion de la reference du produit
  171. $pdf->SetXY(30, $curY+1 );
  172. $pdf->SetFont('','B', $default_font_size - 3);
  173. $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0);
  174. //Insertion du libelle
  175. $pdf->SetFont('','', $default_font_size - 3);
  176. $pdf->SetXY(50, $curY+1 );
  177. //$libelleproduitservice=pdf_getlinedesc($object->$origin,$i,$outputlangs);
  178. $libelleproduitservice = pdf_writelinedesc($pdf,$object->$origin,$i,$outputlangs,90,3,50,$curY+1,1);
  179. //$pdf->writeHTMLCell(90, 3, 50, $curY+1, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 'L', 0);
  180. //Insertion de la quantite commandee
  181. $pdf->SetFont('','', $default_font_size - 3);
  182. $pdf->SetXY(140, $curY+1 );
  183. $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0, 'C', 0);
  184. //Insertion de la quantite a envoyer
  185. $pdf->SetFont('','', $default_font_size - 3);
  186. $pdf->SetXY(170, $curY+1 );
  187. $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'C', 0);
  188. //Generation de la page 2
  189. $curY += (dol_nboflines_bis($libelleproduitservice,0,$outputlangs->charset_output)*3+1);
  190. $nexY = $curY;
  191. if ($nexY > ($tab_top+$tab_height-10) && $i < $nblignes - 1)
  192. {
  193. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
  194. $this->_pagefoot($pdf, $object, $outputlangs);
  195. $pdf->AliasNbPages();
  196. $curY = $iniY;
  197. // New page
  198. $pdf->AddPage();
  199. $pagenb++;
  200. $this->_pagehead($pdf, $this->expe, 0, $outputlangs);
  201. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  202. $pdf->SetTextColor(0,0,0);
  203. $pdf->SetFont('','', $default_font_size - 3);
  204. }
  205. }
  206. //Insertion du pied de page
  207. $this->_pagefoot($pdf, $object, $outputlangs);
  208. $pdf->AliasNbPages();
  209. $pdf->Close();
  210. $pdf->Output($file,'F');
  211. if (! empty($conf->global->MAIN_UMASK))
  212. @chmod($file, octdec($conf->global->MAIN_UMASK));
  213. return 1;
  214. }
  215. else
  216. {
  217. $this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir);
  218. return 0;
  219. }
  220. }
  221. else
  222. {
  223. $this->error=$outputlangs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
  224. return 0;
  225. }
  226. $this->error=$outputlangs->transnoentities("ErrorUnknown");
  227. return 0; // Erreur par defaut
  228. }
  229. //********************************
  230. // Generation du tableau
  231. //********************************
  232. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs)
  233. {
  234. global $langs;
  235. $default_font_size = pdf_getPDFFontSize($outputlangs);
  236. $langs->load("main");
  237. $langs->load("bills");
  238. $pdf->SetFont('','B', $default_font_size - 2);
  239. $pdf->SetXY(10,$tab_top);
  240. $pdf->MultiCell(10,5,"LS",0,'C',1);
  241. $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
  242. $pdf->SetXY(20,$tab_top);
  243. $pdf->MultiCell(10,5,"LR",0,'C',1);
  244. $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
  245. $pdf->SetXY(30,$tab_top);
  246. $pdf->MultiCell(20,5,$outputlangs->transnoentities("Ref"),0,'C',1);
  247. $pdf->SetXY(50,$tab_top);
  248. $pdf->MultiCell(90,5,$outputlangs->transnoentities("Description"),0,'L',1);
  249. $pdf->SetXY(140,$tab_top);
  250. $pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyOrdered"),0,'C',1);
  251. $pdf->SetXY(170,$tab_top);
  252. $pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyToShip"),0,'C',1);
  253. $pdf->Rect(10, $tab_top, 190, $tab_height);
  254. }
  255. /**
  256. * Show footer of page
  257. *
  258. * @param pdf PDF factory
  259. * @param object Object invoice
  260. * @param outputlangs Object lang for output
  261. */
  262. function _pagefoot(&$pdf, $object, $outputlangs)
  263. {
  264. $default_font_size = pdf_getPDFFontSize($outputlangs);
  265. $pdf->SetFont('','', $default_font_size - 2);
  266. $pdf->SetY(-23);
  267. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("GoodStatusDeclaration"), 0, 'L');
  268. $pdf->SetY(-13);
  269. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ToAndDate"), 0, 'C');
  270. $pdf->SetXY(120,-23);
  271. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("NameAndSignature"), 0, 'C');
  272. // Show page nb only on iso languages (so default Helvetica font)
  273. //if (pdf_getPDFFont($outputlangs) == 'Helvetica')
  274. //{
  275. // $pdf->SetXY(-10,-10);
  276. // $pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
  277. //}
  278. }
  279. /**
  280. * Show header of page
  281. *
  282. * @param pdf Object PDF
  283. * @param object Object invoice
  284. * @param showaddress 0=no, 1=yes
  285. * @param outputlang Object lang for output
  286. */
  287. function _pagehead(&$pdf, $object, $showaddress=1, $outputlangs)
  288. {
  289. global $conf, $langs;
  290. $default_font_size = pdf_getPDFFontSize($outputlangs);
  291. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  292. //Affiche le filigrane brouillon - Print Draft Watermark
  293. if($object->statut==0 && (! empty($conf->global->SENDING_DRAFT_WATERMARK)) )
  294. {
  295. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SENDING_DRAFT_WATERMARK);
  296. }
  297. $posy=$this->marge_haute;
  298. $posx=$this->page_largeur-$this->marge_droite-100;
  299. $Xoff = 90;
  300. $Yoff = 0;
  301. $tab4_top = 60;
  302. $tab4_hl = 6;
  303. $tab4_sl = 4;
  304. $line = 2;
  305. //*********************LOGO****************************
  306. $pdf->SetXY(11,7);
  307. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  308. if ($this->emetteur->logo)
  309. {
  310. if (is_readable($logo))
  311. {
  312. $pdf->Image($logo,10, 5, 0, 22);
  313. }
  314. else
  315. {
  316. $pdf->SetTextColor(200,0,0);
  317. $pdf->SetFont('','B', $default_font_size - 2);
  318. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  319. $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  320. }
  321. }
  322. else
  323. {
  324. $text=$this->emetteur->name;
  325. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($text), 0, 'L');
  326. }
  327. //*********************Entete****************************
  328. //Nom du Document
  329. $pdf->SetXY($Xoff,7);
  330. $pdf->SetFont('','B', $default_font_size + 2);
  331. $pdf->SetTextColor(0,0,0);
  332. $pdf->MultiCell(0, 3, $outputlangs->transnoentities("SendingSheet"), '', 'L'); // Bordereau expedition
  333. //Num Expedition
  334. $Yoff = $Yoff+7;
  335. $Xoff = 142;
  336. //$pdf->rect($Xoff, $Yoff, 85, 8);
  337. $pdf->SetXY($Xoff,$Yoff);
  338. $pdf->SetFont('','', $default_font_size - 2);
  339. $pdf->SetTextColor(0,0,0);
  340. $pdf->MultiCell(0, 3, $outputlangs->transnoentities("RefSending").': '.$outputlangs->convToOutputCharset($object->ref), '', 'R');
  341. //$this->Code39($Xoff+43, $Yoff+1, $object->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
  342. // Add list of linked elements
  343. // TODO possibility to use with other elements (business module,...)
  344. //$object->load_object_linked();
  345. $origin = $object->origin;
  346. $origin_id = $object->origin_id;
  347. // TODO move to external function
  348. if ($conf->$origin->enabled)
  349. {
  350. $outputlangs->load('orders');
  351. $classname = ucfirst($origin);
  352. $linkedobject = new $classname($this->db);
  353. $result=$linkedobject->fetch($origin_id);
  354. if ($result >= 0)
  355. {
  356. $Yoff = $Yoff+4;
  357. $pdf->SetXY($Xoff,$Yoff);
  358. $pdf->SetFont('','', $default_font_size - 2);
  359. $text=$linkedobject->ref;
  360. if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
  361. $pdf->MultiCell(0, 3, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R');
  362. }
  363. }
  364. //$this->Code39($Xoff+43, $Yoff+1, $object->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
  365. //Definition Emplacement du bloc Societe
  366. $Xoff = 110;
  367. $blSocX=90;
  368. $blSocY=21;
  369. $blSocW=50;
  370. $blSocX2=$blSocW+$blSocXs;
  371. // Sender name
  372. $pdf->SetTextColor(0,0,60);
  373. $pdf->SetXY($blSocX,$blSocY);
  374. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  375. $pdf->SetTextColor(0,0,0);
  376. // Sender properties
  377. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  378. $pdf->SetFont('','', $default_font_size - 3);
  379. $pdf->SetXY($blSocX,$blSocY+3);
  380. $pdf->MultiCell(80, 2, $carac_emetteur, 0, 'L');
  381. if ($object->client->code_client)
  382. {
  383. $Yoff+=7;
  384. $posy=$Yoff;
  385. $pdf->SetXY(100,$posy);
  386. $pdf->SetTextColor(0,0,60);
  387. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'R');
  388. }
  389. //Date Expedition
  390. $Yoff = $Yoff+7;
  391. $pdf->SetXY($blSocX-80,$blSocY+20);
  392. $pdf->SetFont('','B', $default_font_size - 2);
  393. $pdf->SetTextColor(0,0,0);
  394. $pdf->MultiCell(50, 8, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date_delivery,'day',false,$outputlangs,true), '', 'L');
  395. // Deliverer
  396. $pdf->SetXY($blSocX-80,$blSocY+23);
  397. $pdf->SetFont('','', $default_font_size - 2);
  398. $pdf->SetTextColor(0,0,0);
  399. if (! empty($object->tracking_number))
  400. {
  401. $object->GetUrlTrackingStatus($object->tracking_number);
  402. if (! empty($object->tracking_url))
  403. {
  404. if ($object->expedition_method_id > 0)
  405. {
  406. // Get code using getLabelFromKey
  407. $code=$outputlangs->getLabelFromKey($this->db,$object->expedition_method_id,'c_shipment_mode','rowid','code');
  408. $label=$outputlangs->trans("SendingMethod".strtoupper($code))." :";
  409. }
  410. else
  411. {
  412. $label=$outputlangs->transnoentities("Deliverer");
  413. }
  414. $pdf->writeHTMLCell(50, 8, '', '', $label." ".$object->tracking_url, '', 'L');
  415. }
  416. }
  417. else
  418. {
  419. $pdf->MultiCell(50, 8, $outputlangs->transnoentities("Deliverer")." ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)), '', 'L');
  420. }
  421. /**********************************/
  422. //Emplacement Informations Expediteur (My Company)
  423. /**********************************/
  424. $Ydef = $Yoff;
  425. $blExpX=$Xoff-20;
  426. $blW=52;
  427. $Yoff = $Yoff+5;
  428. $Ydef = $Yoff;
  429. $blSocY = 1;
  430. $pdf->Rect($blExpX, $Yoff, $blW, 20);
  431. $object->fetch_thirdparty();
  432. // If SHIPPING contact defined on order, we use it
  433. $usecontact=false;
  434. $arrayidcontact=$object->$origin->getIdContact('external','SHIPPING');
  435. if (count($arrayidcontact) > 0)
  436. {
  437. $usecontact=true;
  438. $result=$object->fetch_contact($arrayidcontact[0]);
  439. }
  440. // Recipient name
  441. if (! empty($usecontact))
  442. {
  443. // On peut utiliser le nom de la societe du contact
  444. if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
  445. else $socname = $object->client->nom;
  446. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  447. }
  448. else
  449. {
  450. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  451. }
  452. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  453. $blDestX=$blExpX+55;
  454. $blW=50;
  455. $Yoff = $Ydef +1;
  456. $pdf->Rect($blDestX, $Yoff-1, $blW, 20);
  457. //Titre
  458. $pdf->SetFont('','B', $default_font_size - 3);
  459. $pdf->SetXY($blDestX,$Yoff-4);
  460. $pdf->MultiCell($blW,3, $outputlangs->transnoentities("Recipient"), 0, 'L');
  461. // Show customer/recipient
  462. $pdf->SetFont('','B', $default_font_size - 3);
  463. $pdf->SetXY($blDestX,$Yoff);
  464. $pdf->MultiCell($blW,3, $carac_client_name, 0, 'L');
  465. $pdf->SetFont('','', $default_font_size - 3);
  466. $pdf->SetXY($blDestX,$Yoff+4);
  467. $pdf->MultiCell($blW,2, $carac_client, 0, 'L');
  468. }
  469. }
  470. ?>