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

pdf_espadon   F

Complexity

Total Complexity 151

Size/Duplication

Total Lines 1190
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 574
c 0
b 0
f 0
dl 0
loc 1190
rs 2
wmc 151

7 Methods

Rating   Name   Duplication   Size   Complexity  
F write_file() 0 491 80
C defineColumnField() 0 154 9
A __construct() 0 25 6
D _tableau_tot() 0 88 18
A _pagefoot() 0 5 1
F _pagehead() 0 237 31
A _tableau() 0 32 6

How to fix   Complexity   

Complex Class

Complex classes like pdf_espadon 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_espadon, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* Copyright (C) 2005      Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2005-2012 Laurent Destailleur	<[email protected]>
4
 * Copyright (C) 2005-2012 Regis Houssin		<[email protected]>
5
 * Copyright (C) 2014-2015 Marcos García        <[email protected]>
6
 * Copyright (C) 2018      Frédéric France      <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 * or see http://www.gnu.org/
21
 */
22
23
/**
24
 *	\file       htdocs/core/modules/expedition/doc/pdf_espadon.modules.php
25
 *	\ingroup    expedition
26
 *	\brief      Class file allowing Espadons shipping template generation
27
 */
28
29
require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
30
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
32
33
34
/**
35
 *	Class to build sending documents with model espadon
36
 */
37
class pdf_espadon extends ModelePdfExpedition
38
{
39
    /**
40
     * @var DoliDb Database handler
41
     */
42
    public $db;
43
44
    /**
45
     * @var string model name
46
     */
47
    public $name;
48
49
    /**
50
     * @var string model description (short text)
51
     */
52
    public $description;
53
54
	/**
55
     * @var string document type
56
     */
57
    public $type;
58
59
	/**
60
     * @var array Minimum version of PHP required by module.
61
     * e.g.: PHP ≥ 5.5 = array(5, 5)
62
     */
63
	public $phpmin = array(5, 5);
64
65
	/**
66
     * Dolibarr version of the loaded document
67
     * @var string
68
     */
69
	public $version = 'dolibarr';
70
71
	/**
72
     * @var int page_largeur
73
     */
74
    public $page_largeur;
75
76
	/**
77
     * @var int page_hauteur
78
     */
79
    public $page_hauteur;
80
81
	/**
82
     * @var array format
83
     */
84
    public $format;
85
86
	/**
87
     * @var int marge_gauche
88
     */
89
	public $marge_gauche;
90
91
	/**
92
     * @var int marge_droite
93
     */
94
	public $marge_droite;
95
96
	/**
97
     * @var int marge_haute
98
     */
99
	public $marge_haute;
100
101
	/**
102
     * @var int marge_basse
103
     */
104
	public $marge_basse;
105
106
	/**
107
	 * Issuer
108
	 * @var Societe object that emits
109
	 */
110
	public $emetteur;
111
112
113
	/**
114
	 *	Constructor
115
	 *
116
	 *	@param	DoliDB	$db		Database handler
117
	 */
118
	public function __construct($db = 0)
119
	{
120
		global $conf,$langs,$mysoc;
121
122
		$this->db = $db;
123
		$this->name = "espadon";
124
		$this->description = $langs->trans("DocumentModelStandardPDF");
125
126
		$this->type = 'pdf';
127
		$formatarray=pdf_getFormat();
128
		$this->page_largeur = $formatarray['width'];
129
		$this->page_hauteur = $formatarray['height'];
130
		$this->format = array($this->page_largeur, $this->page_hauteur);
131
		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
132
		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
133
		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
134
		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
135
136
		$this->option_logo = 1;
137
138
		// Get source company
139
		$this->emetteur=$mysoc;
140
		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang, -2);    // By default if not defined
141
142
		$this->tabTitleHeight = 5; // default height
143
	}
144
145
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
146
	/**
147
	 *	Function to build pdf onto disk
148
	 *
149
	 *	@param		Object		$object			Object expedition to generate (or id if old method)
150
	 *	@param		Translate	$outputlangs		Lang output object
151
     *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
152
     *  @param		int			$hidedetails		Do not show line details
153
     *  @param		int			$hidedesc			Do not show desc
154
     *  @param		int			$hideref			Do not show ref
155
     *  @return     int         	    			1=OK, 0=KO
156
	 */
157
	public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
158
	{
159
		// phpcs:enable
160
		global $user,$conf,$langs,$hookmanager;
161
162
		$object->fetch_thirdparty();
163
164
		if (! is_object($outputlangs)) $outputlangs=$langs;
165
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
166
		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
167
168
		// Load traductions files requiredby by page
169
		$outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
170
171
		$nblines = count($object->lines);
172
173
        // Loop on each lines to detect if there is at least one image to show
174
        $realpatharray=array();
175
        if (! empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE))
176
        {
177
            $objphoto = new Product($this->db);
178
179
            for ($i = 0 ; $i < $nblines ; $i++)
180
            {
181
                if (empty($object->lines[$i]->fk_product)) continue;
182
183
				$objphoto = new Product($this->db);
184
				$objphoto->fetch($object->lines[$i]->fk_product);
185
186
				$pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product') . $object->lines[$i]->fk_product ."/photos/";
187
				$dir = $conf->product->dir_output.'/'.$pdir;
188
189
				$realpath='';
190
191
                foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
192
                {
193
                    if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
194
                    {
195
                        if ($obj['photo_vignette'])
196
                        {
197
                            $filename=$obj['photo_vignette'];
198
                        }
199
                        else
200
                        {
201
                            $filename=$obj['photo'];
202
                        }
203
                    }
204
                    else
205
                    {
206
                        $filename=$obj['photo'];
207
                    }
208
209
                    $realpath = $dir.$filename;
210
                    break;
211
                }
212
213
                if ($realpath) $realpatharray[$i]=$realpath;
214
            }
215
        }
216
217
        if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol;
218
219
		if ($conf->expedition->dir_output)
220
		{
221
			// Definition de $dir et $file
222
			if ($object->specimen)
223
			{
224
				$dir = $conf->expedition->dir_output."/sending";
225
				$file = $dir . "/SPECIMEN.pdf";
226
			}
227
			else
228
			{
229
				$expref = dol_sanitizeFileName($object->ref);
230
				$dir = $conf->expedition->dir_output."/sending/" . $expref;
231
				$file = $dir . "/" . $expref . ".pdf";
232
			}
233
234
			if (! file_exists($dir))
235
			{
236
				if (dol_mkdir($dir) < 0)
237
				{
238
					$this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
239
					return 0;
240
				}
241
			}
242
243
			if (file_exists($dir))
244
			{
245
				// Add pdfgeneration hook
246
				if (! is_object($hookmanager))
247
				{
248
					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
249
					$hookmanager=new HookManager($this->db);
250
				}
251
				$hookmanager->initHooks(array('pdfgeneration'));
252
				$parameters=array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
253
				global $action;
254
				$reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
255
256
				// Set nblines with the new facture lines content after hook
257
				$nblines = count($object->lines);
258
259
				$pdf=pdf_getInstance($this->format);
260
				$default_font_size = pdf_getPDFFontSize($outputlangs);
261
				$heightforinfotot = 8;	// Height reserved to output the info and total part
262
		        $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
263
	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
264
	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
265
                $pdf->SetAutoPageBreak(1, 0);
266
267
                if (class_exists('TCPDF'))
268
                {
269
                    $pdf->setPrintHeader(false);
270
                    $pdf->setPrintFooter(false);
271
                }
272
                $pdf->SetFont(pdf_getPDFFont($outputlangs));
273
                // Set path to the background PDF File
274
                if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
275
                {
276
                    $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
277
                    $tplidx = $pdf->importPage(1);
278
                }
279
280
				$pdf->Open();
281
				$pagenb=0;
282
				$pdf->SetDrawColor(128, 128, 128);
283
284
				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
285
286
				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
287
				$pdf->SetSubject($outputlangs->transnoentities("Shipment"));
288
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
289
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
290
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
291
				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
292
293
				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
294
295
				// New page
296
				$pdf->AddPage();
297
				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
298
				$pagenb++;
299
				$this->_pagehead($pdf, $object, 1, $outputlangs);
300
				$pdf->SetFont('', '', $default_font_size - 1);
301
				$pdf->MultiCell(0, 3, '');		// Set interline to 3
302
				$pdf->SetTextColor(0, 0, 0);
303
304
				$tab_top = 90;
305
				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
306
				$tab_height = 130;
307
				$tab_height_newpage = 150;
308
309
				// Incoterm
310
				$height_incoterms = 0;
311
				if ($conf->incoterm->enabled)
312
				{
313
					$desc_incoterms = $object->getIncotermsForPDF();
314
					if ($desc_incoterms)
315
					{
316
						$tab_top = 88;
317
318
						$pdf->SetFont('', '', $default_font_size - 1);
319
						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
320
						$nexY = $pdf->GetY();
321
						$height_incoterms=$nexY-$tab_top;
322
323
						// Rect prend une longueur en 3eme param
324
						$pdf->SetDrawColor(192, 192, 192);
325
						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
326
327
						$tab_top = $nexY+6;
328
						$height_incoterms += 4;
329
					}
330
				}
331
332
				if (! empty($object->note_public) || ! empty($object->tracking_number))
333
				{
334
					$tab_top = 88 + $height_incoterms;
335
					$tab_top_alt = $tab_top;
336
337
					$pdf->SetFont('', 'B', $default_font_size - 2);
338
					$pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L');
339
340
					$tab_top_alt = $pdf->GetY();
341
					//$tab_top_alt += 1;
342
343
					// Tracking number
344
					if (! empty($object->tracking_number))
345
					{
346
						$object->getUrlTrackingStatus($object->tracking_number);
347
						if (! empty($object->tracking_url))
348
						{
349
							if ($object->shipping_method_id > 0)
350
							{
351
								// Get code using getLabelFromKey
352
								$code=$outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
353
								$label='';
354
								if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."<br>";
355
								$label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
356
								//var_dump($object->tracking_url != $object->tracking_number);exit;
357
								if ($object->tracking_url != $object->tracking_number)
358
								{
359
									$label.=" : ";
360
									$label.=$object->tracking_url;
361
								}
362
								$pdf->SetFont('', 'B', $default_font_size - 2);
363
								$pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L');
364
365
								$tab_top_alt = $pdf->GetY();
366
							}
367
						}
368
					}
369
370
					// Notes
371
					if (! empty($object->note_public))
372
					{
373
						$pdf->SetFont('', '', $default_font_size - 1);   // Dans boucle pour gerer multi-page
374
						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
375
					}
376
377
					$nexY = $pdf->GetY();
378
					$height_note=$nexY-$tab_top;
379
380
					// Rect prend une longueur en 3eme param
381
					$pdf->SetDrawColor(192, 192, 192);
382
					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
383
384
					$tab_height = $tab_height - $height_note;
385
					$tab_top = $nexY+6;
386
				}
387
				else
388
				{
389
					$height_note=0;
390
				}
391
392
393
				// Use new auto collum system
394
				$this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
395
396
				// Simulation de tableau pour connaitre la hauteur de la ligne de titre
397
				$pdf->startTransaction();
398
				$this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
399
				$pdf->rollbackTransaction(true);
400
401
402
				$iniY = $tab_top + $this->tabTitleHeight + 2;
403
				$curY = $tab_top + $this->tabTitleHeight + 2;
404
				$nexY = $tab_top + $this->tabTitleHeight + 2;
405
406
				// Loop on each lines
407
				for ($i = 0; $i < $nblines; $i++)
408
				{
409
					$curY = $nexY;
410
					$pdf->SetFont('', '', $default_font_size - 1);   // Into loop to work with multipage
411
					$pdf->SetTextColor(0, 0, 0);
412
413
					// Define size of image if we need it
414
					$imglinesize=array();
415
					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
416
417
					$pdf->setTopMargin($tab_top_newpage);
418
					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
419
					$pageposbefore=$pdf->getPage();
420
421
					$showpricebeforepagebreak=1;
422
					$posYAfterImage=0;
423
					$posYAfterDescription=0;
424
425
					if($this->getColumnStatus('photo'))
426
					{
427
					    // We start with Photo of product line
428
					    if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// If photo too high, we moved completely on new page
429
					    {
430
					        $pdf->AddPage('', '', true);
431
					        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
432
					        //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
433
					        $pdf->setPage($pageposbefore+1);
434
435
					        $curY = $tab_top_newpage;
436
					        $showpricebeforepagebreak=0;
437
					    }
438
439
440
					    if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height']))
441
					    {
442
					        $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
443
					        // $pdf->Image does not increase value return by getY, so we save it manually
444
					        $posYAfterImage=$curY+$imglinesize['height'];
445
					    }
446
					}
447
448
					// Description of product line
449
					if($this->getColumnStatus('desc'))
450
					{
451
					    $pdf->startTransaction();
452
					    pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc);
453
					    $pageposafter=$pdf->getPage();
454
					    if ($pageposafter > $pageposbefore)	// There is a pagebreak
455
					    {
456
					        $pdf->rollbackTransaction(true);
457
					        $pageposafter=$pageposbefore;
458
					        //print $pageposafter.'-'.$pageposbefore;exit;
459
					        $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
460
					        pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc);
461
462
					        $pageposafter=$pdf->getPage();
463
					        $posyafter=$pdf->GetY();
464
					        //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
465
					        if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot)))	// There is no space left for total+free text
466
					        {
467
					            if ($i == ($nblines-1))	// No more lines, and no space left to show total, so we create a new page
468
					            {
469
					                $pdf->AddPage('', '', true);
470
					                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
471
					                //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
472
					                $pdf->setPage($pageposafter+1);
473
					            }
474
					        }
475
					        else
476
					        {
477
					            // We found a page break
478
					            $showpricebeforepagebreak=0;
479
					        }
480
					    }
481
					    else	// No pagebreak
482
					    {
483
					        $pdf->commitTransaction();
484
					    }
485
					    $posYAfterDescription=$pdf->GetY();
486
					}
487
488
					$nexY = $pdf->GetY();
489
					$pageposafter=$pdf->getPage();
490
491
					$pdf->setPage($pageposbefore);
492
					$pdf->setTopMargin($this->marge_haute);
493
					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
494
495
					// We suppose that a too long description or photo were moved completely on next page
496
					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
497
						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
498
					}
499
500
					// We suppose that a too long description is moved completely on next page
501
					if ($pageposafter > $pageposbefore) {
502
						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
503
					}
504
505
					$pdf->SetFont('', '', $default_font_size - 1);   // On repositionne la police par defaut
506
507
					// weight
508
509
					$weighttxt='';
510
					if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight)
511
					{
512
					    $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->weight_units, "weight");
513
					}
514
					$voltxt='';
515
					if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume)
516
					{
517
					    $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0, "volume");
518
					}
519
520
521
					if ($this->getColumnStatus('weight'))
522
					{
523
					    $this->printStdColumnContent($pdf, $curY, 'weight', $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt, array('html'=>1));
524
					    $nexY = max($pdf->GetY(), $nexY);
525
					}
526
527
					if ($this->getColumnStatus('qty_asked'))
528
					{
529
					    $this->printStdColumnContent($pdf, $curY, 'qty_asked', $object->lines[$i]->qty_asked);
530
					    $nexY = max($pdf->GetY(), $nexY);
531
					}
532
533
					if ($this->getColumnStatus('qty_shipped'))
534
					{
535
					    $this->printStdColumnContent($pdf, $curY, 'qty_shipped', $object->lines[$i]->qty_shipped);
536
					    $nexY = max($pdf->GetY(), $nexY);
537
					}
538
539
					if ($this->getColumnStatus('subprice'))
540
					{
541
					    $this->printStdColumnContent($pdf, $curY, 'subprice', price($object->lines[$i]->subprice, 0, $outputlangs));
542
					    $nexY = max($pdf->GetY(), $nexY);
543
					}
544
545
546
547
					$nexY+=3;
548
					if ($weighttxt && $voltxt) $nexY+=2;
549
550
					// Add line
551
					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
552
					{
553
						$pdf->setPage($pageposafter);
554
						$pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80,80,80)));
555
						//$pdf->SetDrawColor(190,190,200);
556
						$pdf->line($this->marge_gauche, $nexY-1, $this->page_largeur - $this->marge_droite, $nexY-1);
557
						$pdf->SetLineStyle(array('dash'=>0));
558
					}
559
560
					// Detect if some page were added automatically and output _tableau for past pages
561
					while ($pagenb < $pageposafter)
562
					{
563
						$pdf->setPage($pagenb);
564
						if ($pagenb == 1)
565
						{
566
							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
567
						}
568
						else
569
						{
570
							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
571
						}
572
						$this->_pagefoot($pdf, $object, $outputlangs, 1);
573
						$pagenb++;
574
						$pdf->setPage($pagenb);
575
						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
576
						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
577
					}
578
					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
579
					{
580
						if ($pagenb == 1)
581
						{
582
							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
583
						}
584
						else
585
						{
586
							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
587
						}
588
						$this->_pagefoot($pdf, $object, $outputlangs, 1);
589
						// New page
590
						$pdf->AddPage();
591
						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
592
						$pagenb++;
593
						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
594
					}
595
				}
596
597
				// Show square
598
				if ($pagenb == 1)
599
				{
600
					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
601
					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
602
				}
603
				else
604
				{
605
					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
606
					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
607
				}
608
609
				// Affiche zone totaux
610
				$posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
611
612
				// Pied de page
613
				$this->_pagefoot($pdf, $object, $outputlangs);
614
				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
615
616
				$pdf->Close();
617
618
				$pdf->Output($file, 'F');
619
620
				// Add pdfgeneration hook
621
				$hookmanager->initHooks(array('pdfgeneration'));
622
				$parameters=array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
623
				global $action;
624
				$reshook=$hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
625
				if ($reshook < 0)
626
				{
627
				    $this->error = $hookmanager->error;
628
				    $this->errors = $hookmanager->errors;
629
				}
630
631
				if (! empty($conf->global->MAIN_UMASK))
632
				@chmod($file, octdec($conf->global->MAIN_UMASK));
633
634
				$this->result = array('fullpath'=>$file);
635
636
				return 1;	// No error
637
			}
638
			else
639
			{
640
				$this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
641
				return 0;
642
			}
643
		}
644
		else
645
		{
646
			$this->error=$langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
647
			return 0;
648
		}
649
	}
650
651
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
652
	/**
653
	 *	Show total to pay
654
	 *
655
	 *	@param	PDF			$pdf           Object PDF
656
	 *	@param  Facture		$object         Object invoice
657
	 *	@param  int			$deja_regle     Montant deja regle
658
	 *	@param	int			$posy			Position depart
659
	 *	@param	Translate	$outputlangs	Objet langs
660
	 *	@return int							Position pour suite
661
	 */
662
	private function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
663
	{
664
		// phpcs:enable
665
		global $conf,$mysoc;
666
667
        $sign=1;
668
669
        $default_font_size = pdf_getPDFFontSize($outputlangs);
670
671
		$tab2_top = $posy;
672
		$tab2_hl = 4;
673
		$pdf->SetFont('', 'B', $default_font_size - 1);
674
675
		// Tableau total
676
		$col1x = $this->posxweightvol-50; $col2x = $this->posxweightvol;
677
		/*if ($this->page_largeur < 210) // To work with US executive format
678
		{
679
			$col2x-=20;
680
		}*/
681
		if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
682
		else $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
683
684
		$useborder=0;
685
		$index = 0;
686
687
		$totalWeighttoshow='';
688
		$totalVolumetoshow='';
689
690
		// Load dim data
691
		$tmparray=$object->getTotalWeightVolume();
692
		$totalWeight=$tmparray['weight'];
693
		$totalVolume=$tmparray['volume'];
694
		$totalOrdered=$tmparray['ordered'];
695
		$totalToShip=$tmparray['toship'];
696
		// Set trueVolume and volume_units not currently stored into database
697
		if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
698
		{
699
		    $object->trueVolume=price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
700
		    $object->volume_units=$object->size_units * 3;
701
		}
702
703
		if ($totalWeight!='') $totalWeighttoshow=showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
704
		if ($totalVolume!='') $totalVolumetoshow=showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
705
		if ($object->trueWeight) $totalWeighttoshow=showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
706
		if ($object->trueVolume) $totalVolumetoshow=showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
707
708
709
710
711
    	if ($this->getColumnStatus('desc'))
712
    	{
713
    	    $this->printStdColumnContent($pdf, $tab2_top, 'desc', $outputlangs->transnoentities("Total"));
714
    	}
715
716
717
		if ($this->getColumnStatus('weight'))
718
		{
719
		    if ($totalWeighttoshow)
720
		    {
721
		        $this->printStdColumnContent($pdf, $tab2_top, 'weight', $totalWeighttoshow);
722
		        $index++;
723
		    }
724
725
		    if ($totalVolumetoshow)
726
		    {
727
		        $y = $tab2_top + ($tab2_hl * $index);
728
		        $this->printStdColumnContent($pdf, $y, 'weight', $totalVolumetoshow);
729
		    }
730
		}
731
732
		if ($this->getColumnStatus('qty_asked') && $totalOrdered)
733
		{
734
		    $this->printStdColumnContent($pdf, $tab2_top, 'qty_asked', $totalOrdered);
735
		}
736
737
		if ($this->getColumnStatus('qty_shipped') && $totalToShip)
738
		{
739
		    $this->printStdColumnContent($pdf, $tab2_top, 'qty_shipped', $totalToShip);
740
		}
741
742
		if ($this->getColumnStatus('subprice'))
743
		{
744
		    $this->printStdColumnContent($pdf, $tab2_top, 'subprice', price($object->total_ht, 0, $outputlangs));
745
		}
746
747
		$pdf->SetTextColor(0, 0, 0);
748
749
		return ($tab2_top + ($tab2_hl * $index));
750
	}
751
752
	/**
753
	 *   Show table for lines
754
	 *
755
	 *   @param		PDF			$pdf     		Object PDF
756
	 *   @param		string		$tab_top		Top position of table
757
	 *   @param		string		$tab_height		Height of table (rectangle)
758
	 *   @param		int			$nexY			Y
759
	 *   @param		Translate	$outputlangs	Langs object
760
	 *   @param		int			$hidetop		Hide top bar of array
761
	 *   @param		int			$hidebottom		Hide bottom bar of array
762
	 *   @return	void
763
	 */
764
	private function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
765
	{
766
		global $conf;
767
768
		// Force to disable hidetop and hidebottom
769
		$hidebottom=0;
770
		if ($hidetop) $hidetop=-1;
771
772
		$currency = !empty($currency) ? $currency : $conf->currency;
773
		$default_font_size = pdf_getPDFFontSize($outputlangs);
774
775
		// Amount in (at tab_top - 1)
776
		$pdf->SetTextColor(0, 0, 0);
777
		$pdf->SetFont('', '', $default_font_size - 2);
778
779
		if (empty($hidetop))
780
		{
781
			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
782
			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
783
		}
784
785
		$pdf->SetDrawColor(128, 128, 128);
786
		$pdf->SetFont('', '', $default_font_size - 1);
787
788
		// Output Rect
789
		$this->printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
790
791
792
		$this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
793
794
		if (empty($hidetop)){
795
		    $pdf->line($this->marge_gauche, $tab_top+$this->tabTitleHeight, $this->page_largeur-$this->marge_droite, $tab_top+$this->tabTitleHeight);	// line prend une position y en 2eme param et 4eme param
796
		}
797
	}
798
799
	/**
800
	 *  Show top header of page.
801
	 *
802
	 *  @param	PDF			$pdf     		Object PDF
803
	 *  @param  Object		$object     	Object to show
804
	 *  @param  int	    	$showaddress    0=no, 1=yes
805
	 *  @param  Translate	$outputlangs	Object lang for output
806
	 *  @return	void
807
	 */
808
	private function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
809
	{
810
		global $conf,$langs,$mysoc;
811
812
		$langs->load("orders");
813
814
		$default_font_size = pdf_getPDFFontSize($outputlangs);
815
816
		pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
817
818
		// Show Draft Watermark
819
		if($object->statut==0 && (! empty($conf->global->SHIPPING_DRAFT_WATERMARK)) )
820
		{
821
            		pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SHIPPING_DRAFT_WATERMARK);
822
		}
823
824
		//Prepare la suite
825
		$pdf->SetTextColor(0, 0, 60);
826
		$pdf->SetFont('', 'B', $default_font_size + 3);
827
828
		$w = 110;
829
830
		$posy=$this->marge_haute;
831
		$posx=$this->page_largeur-$this->marge_droite-$w;
832
833
		$pdf->SetXY($this->marge_gauche, $posy);
834
835
		// Logo
836
		$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
837
		if ($this->emetteur->logo)
838
		{
839
			if (is_readable($logo))
840
			{
841
			    $height=pdf_getHeightForLogo($logo);
842
			    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
843
			}
844
			else
845
			{
846
				$pdf->SetTextColor(200, 0, 0);
847
				$pdf->SetFont('', 'B', $default_font_size - 2);
848
				$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
849
				$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
850
			}
851
		}
852
		else
853
		{
854
			$text=$this->emetteur->name;
855
			$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
856
		}
857
858
		// Show barcode
859
		if (! empty($conf->barcode->enabled))
860
		{
861
			$posx=105;
862
		}
863
		else
864
		{
865
			$posx=$this->marge_gauche+3;
866
		}
867
		//$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
868
		if (! empty($conf->barcode->enabled))
869
		{
870
			// TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
871
			//$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
872
			//$pdf->Image($logo,10, 5, 0, 24);
873
		}
874
875
		$pdf->SetDrawColor(128, 128, 128);
876
		if (! empty($conf->barcode->enabled))
877
		{
878
			// TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
879
			//$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
880
			//$pdf->Image($logo,10, 5, 0, 24);
881
		}
882
883
884
		$posx=$this->page_largeur - $w - $this->marge_droite;
885
		$posy=$this->marge_haute;
886
887
		$pdf->SetFont('', 'B', $default_font_size + 2);
888
		$pdf->SetXY($posx, $posy);
889
		$pdf->SetTextColor(0, 0, 60);
890
		$title=$outputlangs->transnoentities("SendingSheet");
891
		$pdf->MultiCell($w, 4, $title, '', 'R');
892
893
		$pdf->SetFont('', '', $default_font_size + 1);
894
895
		$posy+=5;
896
897
		$pdf->SetXY($posx, $posy);
898
		$pdf->SetTextColor(0, 0, 60);
899
		$pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R');
900
901
		// Date planned delivery
902
		if (! empty($object->date_delivery))
903
		{
904
    			$posy+=4;
905
    			$pdf->SetXY($posx, $posy);
906
    			$pdf->SetTextColor(0, 0, 60);
907
    			$pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery, "day", false, $outputlangs, true), '', 'R');
908
		}
909
910
		if (! empty($object->thirdparty->code_client))
911
		{
912
			$posy+=4;
913
			$pdf->SetXY($posx, $posy);
914
			$pdf->SetTextColor(0, 0, 60);
915
			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
916
		}
917
918
919
		$pdf->SetFont('', '', $default_font_size + 3);
920
		$Yoff=25;
921
922
		// Add list of linked orders
923
		$origin 	= $object->origin;
924
		$origin_id 	= $object->origin_id;
925
926
	    // TODO move to external function
927
		if (! empty($conf->$origin->enabled))     // commonly $origin='commande'
928
		{
929
			$outputlangs->load('orders');
930
931
			$classname = ucfirst($origin);
932
			$linkedobject = new $classname($this->db);
933
			$result=$linkedobject->fetch($origin_id);
934
			if ($result >= 0)
935
			{
936
			    //$linkedobject->fetchObjectLinked()   Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
937
938
				$pdf->SetFont('', '', $default_font_size - 2);
939
				$text=$linkedobject->ref;
940
				if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
941
				$Yoff = $Yoff+8;
942
				$pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
943
				$pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
944
				$Yoff = $Yoff+3;
945
				$pdf->SetXY($this->page_largeur - $this->marge_droite - $w, $Yoff);
946
				$pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date, "day", false, $outputlangs, true), 0, 'R');
947
			}
948
		}
949
950
		if ($showaddress)
951
		{
952
			// Sender properties
953
			$carac_emetteur='';
954
		 	// Add internal contact of origin element if defined
955
			$arrayidcontact=array();
956
			if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal', 'SALESREPFOLL');
957
		 	if (is_array($arrayidcontact) && count($arrayidcontact) > 0)
958
		 	{
959
		 		$object->fetch_user(reset($arrayidcontact));
960
		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
961
		 	}
962
963
		 	$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
964
965
			// Show sender
966
			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
967
			$posx=$this->marge_gauche;
968
			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
969
970
			$hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
971
			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
972
973
			// Show sender frame
974
			$pdf->SetTextColor(0, 0, 0);
975
			$pdf->SetFont('', '', $default_font_size - 2);
976
			$pdf->SetXY($posx, $posy-5);
977
			$pdf->MultiCell(66, 5, $outputlangs->transnoentities("Sender").":", 0, 'L');
978
			$pdf->SetXY($posx, $posy);
979
			$pdf->SetFillColor(230, 230, 230);
980
			$pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
981
			$pdf->SetTextColor(0, 0, 60);
982
			$pdf->SetFillColor(255, 255, 255);
983
984
			// Show sender name
985
			$pdf->SetXY($posx+2, $posy+3);
986
			$pdf->SetFont('', 'B', $default_font_size);
987
			$pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
988
			$posy=$pdf->getY();
989
990
			// Show sender information
991
			$pdf->SetXY($posx+2, $posy);
992
			$pdf->SetFont('', '', $default_font_size - 1);
993
			$pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
994
995
996
			// If SHIPPING contact defined, we use it
997
			$usecontact=false;
998
			$arrayidcontact=$object->$origin->getIdContact('external', 'SHIPPING');
999
			if (count($arrayidcontact) > 0)
1000
			{
1001
				$usecontact=true;
1002
				$result=$object->fetch_contact($arrayidcontact[0]);
1003
			}
1004
1005
			//Recipient name
1006
			// On peut utiliser le nom de la societe du contact
1007
			if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1008
				$thirdparty = $object->contact;
1009
			} else {
1010
				$thirdparty = $object->thirdparty;
1011
			}
1012
1013
			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1014
1015
			$carac_client=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact)?$object->contact:null), $usecontact, 'targetwithdetails', $object);
1016
1017
			// Show recipient
1018
			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1019
			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1020
			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1021
			$posx=$this->page_largeur - $this->marge_droite - $widthrecbox;
1022
			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1023
1024
			// Show recipient frame
1025
			$pdf->SetTextColor(0, 0, 0);
1026
			$pdf->SetFont('', '', $default_font_size - 2);
1027
			$pdf->SetXY($posx+2, $posy-5);
1028
			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
1029
			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1030
1031
			// Show recipient name
1032
			$pdf->SetXY($posx+2, $posy+3);
1033
			$pdf->SetFont('', 'B', $default_font_size);
1034
			$pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1035
1036
			$posy = $pdf->getY();
1037
1038
			// Show recipient information
1039
			$pdf->SetFont('', '', $default_font_size - 1);
1040
			$pdf->SetXY($posx+2, $posy);
1041
			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1042
		}
1043
1044
		$pdf->SetTextColor(0, 0, 0);
1045
	}
1046
1047
	/**
1048
	 *   	Show footer of page. Need this->emetteur object
1049
     *
1050
	 *   	@param	PDF			$pdf     			PDF
1051
	 * 		@param	Object		$object				Object to show
1052
	 *      @param	Translate	$outputlangs		Object lang for output
1053
	 *      @param	int			$hidefreetext		1=Hide free text
1054
	 *      @return	int								Return height of bottom margin including footer text
1055
	 */
1056
	private function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1057
	{
1058
		global $conf;
1059
		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1060
		return pdf_pagefoot($pdf, $outputlangs, 'SHIPPING_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1061
	}
1062
1063
	/**
1064
	 *   	Define Array Column Field
1065
	 *
1066
	 *   	@param	object		   $object    	    common object
1067
	 *   	@param	Translate	   $outputlangs     langs
1068
	 *      @param	int			   $hidedetails		Do not show line details
1069
	 *      @param	int			   $hidedesc		Do not show desc
1070
	 *      @param	int			   $hideref			Do not show ref
1071
	 *      @return	null
1072
	 */
1073
	public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1074
	{
1075
	    global $conf, $hookmanager;
1076
1077
	    // Default field style for content
1078
	    $this->defaultContentsFieldsStyle = array(
1079
	        'align' => 'R', // R,C,L
1080
	        'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1081
	    );
1082
1083
	    // Default field style for content
1084
	    $this->defaultTitlesFieldsStyle = array(
1085
	        'align' => 'C', // R,C,L
1086
	        'padding' => array(0.5,0,0.5,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1087
	    );
1088
1089
	    /*
1090
	     * For exemple
1091
	     $this->cols['theColKey'] = array(
1092
	     'rank' => $rank, // int : use for ordering columns
1093
	     'width' => 20, // the column width in mm
1094
	     'title' => array(
1095
	     'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1096
	     'label' => ' ', // the final label : used fore final generated text
1097
	     'align' => 'L', // text alignement :  R,C,L
1098
	     'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1099
	     ),
1100
	     'content' => array(
1101
	     'align' => 'L', // text alignement :  R,C,L
1102
	     'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1103
	     ),
1104
	     );
1105
	     */
1106
1107
	    $rank=0; // do not use negative rank
1108
	    $this->cols['desc'] = array(
1109
	        'rank' => $rank,
1110
	        'width' => false, // only for desc
1111
	        'status' => true,
1112
	        'title' => array(
1113
	            'textkey' => 'Designation', // use lang key is usefull in somme case with module
1114
	            'align' => 'L',
1115
	            // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
1116
	            // 'label' => ' ', // the final label
1117
	            'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1118
	        ),
1119
	        'content' => array(
1120
	            'align' => 'L',
1121
	        ),
1122
	    );
1123
1124
	    $rank = $rank + 10;
1125
	    $this->cols['photo'] = array(
1126
	        'rank' => $rank,
1127
	        'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
1128
	        'status' => false,
1129
	        'title' => array(
1130
	            'textkey' => 'Photo',
1131
	            'label' => ' '
1132
	        ),
1133
	        'content' => array(
1134
	            'padding' => array(0,0,0,0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
1135
	        ),
1136
	        'border-left' => false, // remove left line separator
1137
	    );
1138
1139
	    if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto))
1140
	    {
1141
	        $this->cols['photo']['status'] = true;
1142
	    }
1143
1144
	    $rank = $rank + 10;
1145
	    $this->cols['weight'] = array(
1146
	        'rank' => $rank,
1147
	        'width' => 30, // in mm
1148
	        'status' => true,
1149
	        'title' => array(
1150
	            'textkey' => 'WeightVolShort'
1151
	        ),
1152
	        'border-left' => true, // add left line separator
1153
	    );
1154
1155
1156
	    $rank = $rank + 10;
1157
	    $this->cols['subprice'] = array(
1158
	        'rank' => $rank,
1159
	        'width' => 19, // in mm
1160
	        'status' => !empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)?1:0,
1161
	        'title' => array(
1162
	            'textkey' => 'PriceUHT'
1163
	        ),
1164
	        'border-left' => true, // add left line separator
1165
	    );
1166
1167
	    $rank = $rank + 10;
1168
	    $this->cols['totalexcltax'] = array(
1169
	        'rank' => $rank,
1170
	        'width' => 26, // in mm
1171
	        'status' => !empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)?1:0,
1172
	        'title' => array(
1173
	            'textkey' => 'TotalHT'
1174
	        ),
1175
	        'border-left' => true, // add left line separator
1176
	    );
1177
1178
	    $rank = $rank + 10;
1179
	    $this->cols['qty_asked'] = array(
1180
	        'rank' => $rank,
1181
	        'width' => 30, // in mm
1182
	        'status' => empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)?1:0,
1183
	        'title' => array(
1184
	            'textkey' => 'QtyOrdered'
1185
	        ),
1186
	        'border-left' => true, // add left line separator
1187
	        'content' => array(
1188
	            'align' => 'C',
1189
	        ),
1190
	    );
1191
1192
	    $rank = $rank + 10;
1193
	    $this->cols['qty_shipped'] = array(
1194
	        'rank' => $rank,
1195
	        'width' => 30, // in mm
1196
	        'status' => true,
1197
	        'title' => array(
1198
	            'textkey' => 'QtyToShip'
1199
	        ),
1200
	        'border-left' => true, // add left line separator
1201
	        'content' => array(
1202
	            'align' => 'C',
1203
	        ),
1204
	    );
1205
1206
1207
	    $parameters=array(
1208
	        'object' => $object,
1209
	        'outputlangs' => $outputlangs,
1210
	        'hidedetails' => $hidedetails,
1211
	        'hidedesc' => $hidedesc,
1212
	        'hideref' => $hideref
1213
	    );
1214
1215
	    $reshook=$hookmanager->executeHooks('defineColumnField', $parameters, $this);    // Note that $object may have been modified by hook
1216
	    if ($reshook < 0)
1217
	    {
1218
	        setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1219
	    }
1220
	    elseif (empty($reshook))
1221
	    {
1222
	        $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
1223
	    }
1224
	    else
1225
	    {
1226
	        $this->cols = $hookmanager->resArray;
1227
	    }
1228
	}
1229
}
1230