Passed
Branch develop (a7390e)
by
unknown
25:38
created

pdf_soleil   F

Complexity

Total Complexity 69

Size/Duplication

Total Lines 699
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 338
c 0
b 0
f 0
dl 0
loc 699
rs 2.88
wmc 69

5 Methods

Rating   Name   Duplication   Size   Complexity  
F _pagehead() 0 164 16
B __construct() 0 33 6
A _pagefoot() 0 5 1
A _tableau() 0 48 2
F write_file() 0 316 44

How to fix   Complexity   

Complex Class

Complex classes like pdf_soleil often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use pdf_soleil, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* Copyright (C) 2003		Rodolphe Quiedeville		<[email protected]>
3
 * Copyright (C) 2004-2010	Laurent Destailleur			<[email protected]>
4
 * Copyright (C) 2005-2012	Regis Houssin				<[email protected]>
5
 * Copyright (C) 2008		Raphael Bertrand (Resultic)	<[email protected]>
6
 * Copyright (C) 2011		Fabrice CHERRIER
7
 * Copyright (C) 2013		Cédric Salvador				<[email protected]>
8
 * Copyright (C) 2015       Marcos García               <[email protected]>
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
 * or see http://www.gnu.org/
23
 */
24
25
/**
26
 *	\file       htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php
27
 *	\ingroup    ficheinter
28
 *	\brief      Fichier de la classe permettant de generer les fiches d'intervention au modele Soleil
29
 */
30
require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
31
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
33
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
35
36
37
/**
38
 *	Class to build interventions documents with model Soleil
39
 */
40
class pdf_soleil extends ModelePDFFicheinter
41
{
42
	 /**
43
     * @var DoliDb Database handler
44
     */
45
    public $db;
46
47
	/**
48
     * @var string model name
49
     */
50
    public $name;
51
52
	/**
53
     * @var string model description (short text)
54
     */
55
    public $description;
56
57
	/**
58
     * @var string document type
59
     */
60
    public $type;
61
62
    /**
63
     * @var array Minimum version of PHP required by module.
64
     * e.g.: PHP ≥ 5.5 = array(5, 5)
65
     */
66
	public $phpmin = array(5, 5);
67
68
	/**
69
     * Dolibarr version of the loaded document
70
     * @var string
71
     */
72
	public $version = 'dolibarr';
73
74
	/**
75
     * @var int page_largeur
76
     */
77
    public $page_largeur;
78
79
	/**
80
     * @var int page_hauteur
81
     */
82
    public $page_hauteur;
83
84
	/**
85
     * @var array format
86
     */
87
    public $format;
88
89
	/**
90
     * @var int marge_gauche
91
     */
92
	public $marge_gauche;
93
94
	/**
95
     * @var int marge_droite
96
     */
97
	public $marge_droite;
98
99
	/**
100
     * @var int marge_haute
101
     */
102
	public $marge_haute;
103
104
	/**
105
     * @var int marge_basse
106
     */
107
	public $marge_basse;
108
109
	/**
110
	 * Issuer
111
	 * @var Company object that emits
112
	 */
113
	public $emetteur;
114
115
	/**
116
	 *	Constructor
117
	 *
118
	 *  @param		DoliDB		$db      Database handler
119
	 */
120
	public function __construct($db)
121
	{
122
		global $conf,$langs,$mysoc;
123
124
		$this->db = $db;
125
		$this->name = 'soleil';
126
		$this->description = $langs->trans("DocumentModelStandardPDF");
127
128
		// Dimension page pour format A4
129
		$this->type = 'pdf';
130
		$formatarray=pdf_getFormat();
131
		$this->page_largeur = $formatarray['width'];
132
		$this->page_hauteur = $formatarray['height'];
133
		$this->format = array($this->page_largeur,$this->page_hauteur);
134
		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
135
		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
136
		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
137
		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
138
139
		$this->option_logo = 1;                    // Affiche logo
140
		$this->option_tva = 0;                     // Gere option tva FACTURE_TVAOPTION
141
		$this->option_modereg = 0;                 // Affiche mode reglement
142
		$this->option_condreg = 0;                 // Affiche conditions reglement
143
		$this->option_codeproduitservice = 0;      // Affiche code produit-service
144
		$this->option_multilang = 1;               // Dispo en plusieurs langues
145
		$this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
146
147
		// Get source company
148
		$this->emetteur=$mysoc;
149
		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang, -2);    // By default, if not defined
150
151
		// Define position of columns
152
		$this->posxdesc=$this->marge_gauche+1;
153
	}
154
155
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
156
	/**
157
	 *  Function to build pdf onto disk
158
	 *
159
	 *  @param		Object			$object				Object to generate
160
	 *  @param		Translate		$outputlangs		Lang output object
161
	 *  @param		string			$srctemplatepath	Full path of source filename for generator using a template file
162
	 *  @param		int				$hidedetails		Do not show line details
163
	 *  @param		int				$hidedesc			Do not show desc
164
	 *  @param		int				$hideref			Do not show ref
165
	 *  @return		int									1=OK, 0=KO
166
	 */
167
	public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
168
	{
169
        // phpcs:enable
170
		global $user,$langs,$conf,$mysoc,$db,$hookmanager;
171
172
		if (! is_object($outputlangs)) $outputlangs=$langs;
173
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
174
		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
175
176
		// Load traductions files requiredby by page
177
		$outputlangs->loadLangs(array("main", "interventions", "dict", "companies"));
178
179
		if ($conf->ficheinter->dir_output)
180
		{
181
			$object->fetch_thirdparty();
182
183
		    // Definition of $dir and $file
184
			if ($object->specimen)
185
			{
186
				$dir = $conf->ficheinter->dir_output;
187
				$file = $dir . "/SPECIMEN.pdf";
188
			}
189
			else
190
			{
191
				$objectref = dol_sanitizeFileName($object->ref);
192
				$dir = $conf->ficheinter->dir_output . "/" . $objectref;
193
				$file = $dir . "/" . $objectref . ".pdf";
194
			}
195
196
			if (! file_exists($dir))
197
			{
198
				if (dol_mkdir($dir) < 0)
199
				{
200
					$this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
201
					return 0;
202
				}
203
			}
204
205
			if (file_exists($dir))
206
			{
207
				// Add pdfgeneration hook
208
				if (! is_object($hookmanager))
209
				{
210
					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
211
					$hookmanager=new HookManager($this->db);
212
				}
213
214
				$hookmanager->initHooks(array('pdfgeneration'));
215
				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
216
				global $action;
217
				$reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
218
219
				$nblines = count($object->lines);
220
221
				// Create pdf instance
222
				$pdf=pdf_getInstance($this->format);
223
				$default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
224
				$heightforinfotot = 50;	// Height reserved to output the info and total part
225
				$heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
226
				$heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
227
				if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
228
				$pdf->SetAutoPageBreak(1, 0);
229
230
				if (class_exists('TCPDF'))
231
				{
232
					$pdf->setPrintHeader(false);
233
					$pdf->setPrintFooter(false);
234
				}
235
				$pdf->SetFont(pdf_getPDFFont($outputlangs));
236
				// Set path to the background PDF File
237
				if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
238
				{
239
					$pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
240
					$tplidx = $pdf->importPage(1);
241
				}
242
243
				$pdf->Open();
244
				$pagenb=0;
245
				$pdf->SetDrawColor(128, 128, 128);
246
247
				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
248
				$pdf->SetSubject($outputlangs->transnoentities("InterventionCard"));
249
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
250
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
251
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("InterventionCard"));
252
				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
253
254
				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
255
256
				// New page
257
				$pdf->AddPage();
258
				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
259
				$pagenb++;
260
				$this->_pagehead($pdf, $object, 1, $outputlangs);
261
				$pdf->SetFont('', '', $default_font_size - 1);
262
				$pdf->SetTextColor(0, 0, 0);
263
264
				$tab_top = 90;
265
				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
266
				$tab_height = 130;
267
				$tab_height_newpage = 150;
268
269
				// Affiche notes
270
				$notetoshow=empty($object->note_public)?'':$object->note_public;
271
				if ($notetoshow)
272
				{
273
					$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
274
					complete_substitutions_array($substitutionarray, $outputlangs, $object);
275
					$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
276
					$notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
277
278
					$tab_top = 88;
279
280
					$pdf->SetFont('', '', $default_font_size - 1);
281
					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
282
					$nexY = $pdf->GetY();
283
					$height_note=$nexY-$tab_top;
284
285
					// Rect prend une longueur en 3eme param
286
					$pdf->SetDrawColor(192, 192, 192);
287
					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
288
289
					$tab_height = $tab_height - $height_note;
290
					$tab_top = $nexY+6;
291
				}
292
				else
293
				{
294
					$height_note=0;
295
				}
296
297
				$iniY = $tab_top + 7;
298
				$curY = $tab_top + 7;
299
				$nexY = $tab_top + 7;
300
301
				$pdf->SetXY($this->marge_gauche, $tab_top);
302
				$pdf->MultiCell(190, 5, $outputlangs->transnoentities("Description"), 0, 'L', 0);
303
				$pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur-$this->marge_droite, $tab_top + 5);
304
305
				$pdf->SetFont('', '', $default_font_size - 1);
306
307
				$pdf->SetXY($this->marge_gauche, $tab_top + 5);
308
				$text=$object->description;
309
				if ($object->duration > 0)
310
				{
311
				    $totaltime=convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
312
				    $text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
313
				}
314
				$desc=dol_htmlentitiesbr($text, 1);
315
				//print $outputlangs->convToOutputCharset($desc); exit;
316
317
				$pdf->writeHTMLCell(180, 3, 10, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
318
				$nexY = $pdf->GetY();
319
320
				$pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
321
322
				$nblines = count($object->lines);
323
324
				// Loop on each lines
325
				for ($i = 0; $i < $nblines; $i++)
326
				{
327
					$objectligne = $object->lines[$i];
328
329
					$valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
330
					if ($valide > 0 || $object->specimen)
331
					{
332
						$curY = $nexY;
333
						$pdf->SetFont('', '', $default_font_size - 1);   // Into loop to work with multipage
334
						$pdf->SetTextColor(0, 0, 0);
335
336
						$pdf->setTopMargin($tab_top_newpage);
337
						$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
338
						$pageposbefore=$pdf->getPage();
339
340
						// Description of product line
341
						$curX = $this->posxdesc-1;
342
343
                        // Description of product line
344
                        if (empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
345
                            $txt=$outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei, 'dayhour', false, $outputlangs, true);
346
                        } else {
347
                            $txt=$outputlangs->transnoentities("Date")." : ".dol_print_date($objectligne->datei, 'day', false, $outputlangs, true);
348
                        }
349
350
						if ($objectligne->duration > 0)
351
						{
352
							$txt.=" - ".$outputlangs->transnoentities("Duration")." : ".convertSecondToTime($objectligne->duration);
353
						}
354
						$txt='<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).'</strong>';
355
						$desc=dol_htmlentitiesbr($objectligne->desc, 1);
356
357
						$pdf->startTransaction();
358
						$pdf->writeHTMLCell(0, 0, $curX, $curY + 1, dol_concatdesc($txt, $desc), 0, 1, 0);
359
						$pageposafter=$pdf->getPage();
360
						if ($pageposafter > $pageposbefore)	// There is a pagebreak
361
						{
362
							$pdf->rollbackTransaction(true);
363
							$pageposafter=$pageposbefore;
364
							//print $pageposafter.'-'.$pageposbefore;exit;
365
							$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
366
							$pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt, $desc), 0, 1, 0);
367
							$pageposafter=$pdf->getPage();
368
							$posyafter=$pdf->GetY();
369
							//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
370
							if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
371
							{
372
								if ($i == ($nblines-1))	// No more lines, and no space left to show total, so we create a new page
373
								{
374
									$pdf->AddPage('', '', true);
375
									if (! empty($tplidx)) $pdf->useTemplate($tplidx);
376
									if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
377
									$pdf->setPage($pageposafter+1);
378
								}
379
							}
380
						}
381
						else	// No pagebreak
382
						{
383
							$pdf->commitTransaction();
384
						}
385
386
						$nexY = $pdf->GetY();
387
						$pageposafter=$pdf->getPage();
388
						$pdf->setPage($pageposbefore);
389
						$pdf->setTopMargin($this->marge_haute);
390
						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
391
392
						// We suppose that a too long description is moved completely on next page
393
						if ($pageposafter > $pageposbefore) {
394
							$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
395
						}
396
397
						$pdf->SetFont('', '', $default_font_size - 1);   // On repositionne la police par defaut
398
399
						// Detect if some page were added automatically and output _tableau for past pages
400
						while ($pagenb < $pageposafter)
401
						{
402
							$pdf->setPage($pagenb);
403
							if ($pagenb == 1)
404
							{
405
								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
406
							}
407
							else
408
							{
409
								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
410
							}
411
							$this->_pagefoot($pdf, $object, $outputlangs, 1);
412
							$pagenb++;
413
							$pdf->setPage($pagenb);
414
							$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
415
							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
416
						}
417
						if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
418
						{
419
							if ($pagenb == 1)
420
							{
421
								$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
422
							}
423
							else
424
							{
425
								$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
426
							}
427
							$this->_pagefoot($pdf, $object, $outputlangs, 1);
428
							// New page
429
							$pdf->AddPage();
430
							if (! empty($tplidx)) $pdf->useTemplate($tplidx);
431
							$pagenb++;
432
							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
433
						}
434
					}
435
				}
436
437
				// Show square
438
				if ($pagenb == 1)
439
				{
440
					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
441
					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
442
				}
443
				else
444
				{
445
					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
446
					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
447
				}
448
449
				$this->_pagefoot($pdf, $object, $outputlangs);
450
				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
451
452
				$pdf->Close();
453
				$pdf->Output($file, 'F');
454
455
				// Add pdfgeneration hook
456
				$hookmanager->initHooks(array('pdfgeneration'));
457
				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
458
				global $action;
459
				$reshook=$hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
460
				if ($reshook < 0)
461
				{
462
				    $this->error = $hookmanager->error;
463
				    $this->errors = $hookmanager->errors;
464
				}
465
466
				if (! empty($conf->global->MAIN_UMASK))
467
				@chmod($file, octdec($conf->global->MAIN_UMASK));
468
469
				$this->result = array('fullpath'=>$file);
470
471
				return 1;
472
			}
473
			else
474
			{
475
				$this->error=$langs->trans("ErrorCanNotCreateDir", $dir);
476
				return 0;
477
			}
478
		}
479
		else
480
		{
481
			$this->error=$langs->trans("ErrorConstantNotDefined", "FICHEINTER_OUTPUTDIR");
482
			return 0;
483
		}
484
	}
485
486
	/**
487
	 *   Show table for lines
488
	 *
489
	 *   @param		PDF			$pdf     		Object PDF
490
	 *   @param		string		$tab_top		Top position of table
491
	 *   @param		string		$tab_height		Height of table (rectangle)
492
	 *   @param		int			$nexY			Y
493
	 *   @param		Translate	$outputlangs	Langs object
494
	 *   @param		int			$hidetop		Hide top bar of array
495
	 *   @param		int			$hidebottom		Hide bottom bar of array
496
	 *   @return	void
497
	 */
498
	private function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
499
	{
500
		global $conf;
501
502
503
		$default_font_size = pdf_getPDFFontSize($outputlangs);
504
/*
505
		$pdf->SetXY($this->marge_gauche, $tab_top);
506
		$pdf->MultiCell(190,8,$outputlangs->transnoentities("Description"),0,'L',0);
507
		$pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur-$this->marge_droite, $tab_top + 8);
508
509
		$pdf->SetFont('','', $default_font_size - 1);
510
511
		$pdf->MultiCell(0, 3, '');		// Set interline to 3
512
		$pdf->SetXY($this->marge_gauche, $tab_top + 8);
513
		$text=$object->description;
514
		if ($object->duration > 0)
515
		{
516
			$totaltime=convertSecondToTime($object->duration,'all',$conf->global->MAIN_DURATION_OF_WORKDAY);
517
			$text.=($text?' - ':'').$langs->trans("Total").": ".$totaltime;
518
		}
519
		$desc=dol_htmlentitiesbr($text,1);
520
		//print $outputlangs->convToOutputCharset($desc); exit;
521
522
		$pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
523
		$nexY = $pdf->GetY();
524
525
		$pdf->line($this->marge_gauche, $nexY, $this->page_largeur-$this->marge_droite, $nexY);
526
527
		$pdf->MultiCell(0, 3, '');		// Set interline to 3. Then writeMultiCell must use 3 also.
528
*/
529
530
		// Output Rect
531
		$this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height+1, 0, 0);	// Rect prend une longueur en 3eme param et 4eme param
532
533
		if (empty($hidebottom))
534
		{
535
			$pdf->SetXY(20, 230);
536
			$pdf->MultiCell(66, 5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"), 0, 'L', 0);
537
538
			$pdf->SetXY(20, 235);
539
			$pdf->MultiCell(80, 25, '', 1);
540
541
			$pdf->SetXY(110, 230);
542
			$pdf->MultiCell(80, 5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"), 0, 'L', 0);
543
544
			$pdf->SetXY(110, 235);
545
			$pdf->MultiCell(80, 25, '', 1);
546
		}
547
	}
548
549
	/**
550
	 *  Show top header of page.
551
	 *
552
	 *  @param	PDF			$pdf     		Object PDF
553
	 *  @param  Object		$object     	Object to show
554
	 *  @param  int	    	$showaddress    0=no, 1=yes
555
	 *  @param  Translate	$outputlangs	Object lang for output
556
	 *  @return	void
557
	 */
558
	private function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
559
	{
560
		global $conf,$langs;
561
		$default_font_size = pdf_getPDFFontSize($outputlangs);
562
563
		// Load traductions files requiredby by page
564
		$outputlangs->loadLangs(array("main", "dict", "companies", "interventions"));
565
566
		pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
567
568
		//Affiche le filigrane brouillon - Print Draft Watermark
569
		if($object->statut==0 && (! empty($conf->global->FICHINTER_DRAFT_WATERMARK)) )
570
		{
571
			pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FICHINTER_DRAFT_WATERMARK);
572
		}
573
574
		//Prepare la suite
575
		$pdf->SetTextColor(0, 0, 60);
576
		$pdf->SetFont('', 'B', $default_font_size + 3);
577
578
		$posx=$this->page_largeur-$this->marge_droite-100;
579
		$posy=$this->marge_haute;
580
581
		$pdf->SetXY($this->marge_gauche, $posy);
582
583
		// Logo
584
		$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
585
		if ($this->emetteur->logo)
586
		{
587
			if (is_readable($logo))
588
			{
589
			    $height=pdf_getHeightForLogo($logo);
590
			    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
591
			}
592
			else
593
			{
594
				$pdf->SetTextColor(200, 0, 0);
595
				$pdf->SetFont('', 'B', $default_font_size - 2);
596
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
597
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
598
			}
599
		}
600
		else
601
		{
602
			$text=$this->emetteur->name;
603
			$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
604
		}
605
606
		$pdf->SetFont('', 'B', $default_font_size + 3);
607
		$pdf->SetXY($posx, $posy);
608
		$pdf->SetTextColor(0, 0, 60);
609
		$title=$outputlangs->transnoentities("InterventionCard");
610
		$pdf->MultiCell(100, 4, $title, '', 'R');
611
612
		$pdf->SetFont('', 'B', $default_font_size + 2);
613
614
		$posy+=5;
615
		$pdf->SetXY($posx, $posy);
616
		$pdf->SetTextColor(0, 0, 60);
617
		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
618
619
		$posy+=1;
620
		$pdf->SetFont('', '', $default_font_size);
621
622
		$posy+=4;
623
		$pdf->SetXY($posx, $posy);
624
		$pdf->SetTextColor(0, 0, 60);
625
		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->datec, "day", false, $outputlangs, true), '', 'R');
626
627
		if ($object->thirdparty->code_client)
628
		{
629
			$posy+=4;
630
			$pdf->SetXY($posx, $posy);
631
			$pdf->SetTextColor(0, 0, 60);
632
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
633
		}
634
635
		if ($showaddress)
636
		{
637
			// Sender properties
638
			$carac_emetteur='';
639
			// Add internal contact of proposal if defined
640
			$arrayidcontact=$object->getIdContact('internal', 'INTERREPFOLL');
641
			if (count($arrayidcontact) > 0)
642
			{
643
				$object->fetch_user($arrayidcontact[0]);
644
				$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
645
			}
646
647
			$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
648
649
			// Show sender
650
			$posy=42;
651
			$posx=$this->marge_gauche;
652
			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
653
			$hautcadre=40;
654
655
			// Show sender frame
656
			$pdf->SetTextColor(0, 0, 0);
657
			$pdf->SetFont('', '', $default_font_size - 2);
658
			$pdf->SetXY($posx, $posy-5);
659
			$pdf->SetXY($posx, $posy);
660
			$pdf->SetFillColor(230, 230, 230);
661
			$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
662
663
			// Show sender name
664
			$pdf->SetXY($posx+2, $posy+3);
665
			$pdf->SetTextColor(0, 0, 60);
666
			$pdf->SetFont('', 'B', $default_font_size);
667
			$pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
668
			$posy=$pdf->getY();
669
670
			// Show sender information
671
			$pdf->SetFont('', '', $default_font_size - 1);
672
			$pdf->SetXY($posx+2, $posy);
673
			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
674
675
676
			// If CUSTOMER contact defined, we use it
677
			$usecontact=false;
678
			$arrayidcontact=$object->getIdContact('external', 'CUSTOMER');
679
			if (count($arrayidcontact) > 0)
680
			{
681
				$usecontact=true;
682
				$result=$object->fetch_contact($arrayidcontact[0]);
683
			}
684
685
			//Recipient name
686
			// On peut utiliser le nom de la societe du contact
687
			if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
688
				$thirdparty = $object->contact;
689
			} else {
690
				$thirdparty = $object->thirdparty;
691
			}
692
693
			$carac_client_name=pdfBuildThirdpartyName($thirdparty, $outputlangs);
694
695
			$carac_client=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact)?$object->contact:''), $usecontact, 'target', $object);
696
697
			// Show recipient
698
			$widthrecbox=100;
699
			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
700
			$posy=42;
701
			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
702
			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
703
704
			// Show recipient frame
705
			$pdf->SetTextColor(0, 0, 0);
706
			$pdf->SetFont('', '', $default_font_size - 2);
707
			$pdf->SetXY($posx+2, $posy-5);
708
			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
709
			$pdf->SetTextColor(0, 0, 0);
710
711
			// Show recipient name
712
			$pdf->SetXY($posx+2, $posy+3);
713
			$pdf->SetFont('', 'B', $default_font_size);
714
			$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
715
716
			$posy = $pdf->getY();
717
718
			// Show recipient information
719
			$pdf->SetFont('', '', $default_font_size - 1);
720
			$pdf->SetXY($posx+2, $posy);
721
			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
722
		}
723
	}
724
725
	/**
726
	 *   	Show footer of page. Need this->emetteur object
727
	 *
728
	 *   	@param	PDF			$pdf     			PDF
729
	 * 		@param	Object		$object				Object to show
730
	 *      @param	Translate	$outputlangs		Object lang for output
731
	 *      @param	int			$hidefreetext		1=Hide free text
732
	 *      @return	integer
733
	 */
734
	private function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
735
	{
736
		global $conf;
737
		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
738
		return pdf_pagefoot($pdf, $outputlangs, 'FICHINTER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
739
	}
740
}
741