PageRenderTime 309ms CodeModel.GetById 98ms app.highlight 124ms RepoModel.GetById 80ms app.codeStats 1ms

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