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

pdf_muscadet::_tableau()   C

Complexity

Conditions 16

Size

Total Lines 89
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 47
c 0
b 0
f 0
nop 8
dl 0
loc 89
rs 5.5666

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/* Copyright (C) 2004-2014 Laurent Destailleur   <[email protected]>
3
 * Copyright (C) 2005-2011 Regis Houssin         <[email protected]>
4
 * Copyright (C) 2007      Franky Van Liedekerke <[email protected]>
5
 * Copyright (C) 2010-2014 Juanjo Menent         <[email protected]>
6
 * Copyright (C) 2015      Marcos García         <[email protected]>
7
 * Copyright (C) 2017      Ferran Marcet         <[email protected]>
8
 * Copyright (C) 2018      Frédéric France       <[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/supplier_order/pdf/pdf_muscadet.modules.php
27
 *	\ingroup    fournisseur
28
 *	\brief      File of class to generate suppliers orders from muscadet model
29
 */
30
31
require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
32
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
33
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
36
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
37
38
39
/**
40
 *	Class to generate the supplier orders with the muscadet model
41
 */
42
class pdf_muscadet extends ModelePDFSuppliersOrders
43
{
44
    /**
45
     * @var DoliDb Database handler
46
     */
47
    public $db;
48
49
	/**
50
     * @var string model name
51
     */
52
    public $name;
53
54
	/**
55
     * @var string model description (short text)
56
     */
57
    public $description;
58
59
    /**
60
     * @var string document type
61
     */
62
    public $type;
63
64
    /**
65
     * @var array Minimum version of PHP required by module.
66
     * e.g.: PHP ≥ 5.5 = array(5, 5)
67
     */
68
	public $phpmin = array(5, 5);
69
70
	/**
71
     * Dolibarr version of the loaded document
72
     * @var string
73
     */
74
	public $version = 'dolibarr';
75
76
	/**
77
     * @var int page_largeur
78
     */
79
    public $page_largeur;
80
81
	/**
82
     * @var int page_hauteur
83
     */
84
    public $page_hauteur;
85
86
	/**
87
     * @var array format
88
     */
89
    public $format;
90
91
	/**
92
     * @var int marge_gauche
93
     */
94
	public $marge_gauche;
95
96
	/**
97
     * @var int marge_droite
98
     */
99
	public $marge_droite;
100
101
	/**
102
     * @var int marge_haute
103
     */
104
	public $marge_haute;
105
106
	/**
107
     * @var int marge_basse
108
     */
109
	public $marge_basse;
110
111
	/**
112
	 * Issuer
113
	 * @var Societe object that emits
114
	 */
115
	public $emetteur;
116
117
118
	/**
119
	 *	Constructor
120
	 *
121
	 *  @param	DoliDB		$db      	Database handler
122
	 */
123
	public function __construct($db)
124
	{
125
		global $conf, $langs, $mysoc;
126
127
		// Load translation files required by the page
128
		$langs->loadLangs(array("main", "bills"));
129
130
		$this->db = $db;
131
		$this->name = "muscadet";
132
		$this->description = $langs->trans('SuppliersCommandModel');
133
134
		// Dimension page pour format A4
135
		$this->type = 'pdf';
136
		$formatarray=pdf_getFormat();
137
		$this->page_largeur = $formatarray['width'];
138
		$this->page_hauteur = $formatarray['height'];
139
		$this->format = array($this->page_largeur,$this->page_hauteur);
140
		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
141
		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
142
		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
143
		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
144
145
		$this->option_logo = 1;                    // Affiche logo
146
		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
147
		$this->option_modereg = 1;                 // Affiche mode reglement
148
		$this->option_condreg = 1;                 // Affiche conditions reglement
149
		$this->option_codeproduitservice = 1;      // Affiche code produit-service
150
		$this->option_multilang = 1;               // Dispo en plusieurs langues
151
		$this->option_escompte = 0;                // Affiche si il y a eu escompte
152
		$this->option_credit_note = 0;             // Support credit notes
153
		$this->option_freetext = 1;				   // Support add of a personalised text
154
		$this->option_draft_watermark = 1;		   // Support add of a watermark on drafts
155
156
		$this->franchise=!$mysoc->tva_assuj;
157
158
        // Get source company
159
		$this->emetteur=$mysoc;
160
		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang, -2);    // By default, if was not defined
161
162
		// Define position of columns
163
		$this->posxdesc=$this->marge_gauche+1;
164
		$this->posxdiscount=162;
165
		$this->postotalht=174;
166
167
		if ($conf->global->PRODUCT_USE_UNITS)
168
		{
169
			$this->posxtva=95;
170
			$this->posxup=114;
171
			$this->posxqty=132;
172
			$this->posxunit=147;
173
		} else {
174
			$this->posxtva=110;
175
			$this->posxup=126;
176
			$this->posxqty=145;
177
			$this->posxunit=162;
178
		}
179
180
		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxup = $this->posxtva; // posxtva is picture position reference
181
		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
182
		if ($this->page_largeur < 210) // To work with US executive format
183
		{
184
			$this->posxpicture-=20;
185
			$this->posxtva-=20;
186
			$this->posxup-=20;
187
			$this->posxqty-=20;
188
			$this->posxunit-=20;
189
			$this->posxdiscount-=20;
190
			$this->postotalht-=20;
191
		}
192
193
		$this->tva=array();
194
        $this->localtax1=array();
195
        $this->localtax2=array();
196
        $this->atleastoneratenotnull=0;
197
		$this->atleastonediscount=0;
198
	}
199
200
201
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
202
    /**
203
     *  Function to build pdf onto disk
204
     *
205
     *  @param		CommandeFournisseur	$object				Id of object to generate
206
     *  @param		Translate			$outputlangs		Lang output object
207
     *  @param		string				$srctemplatepath	Full path of source filename for generator using a template file
208
     *  @param		int					$hidedetails		Do not show line details
209
     *  @param		int					$hidedesc			Do not show desc
210
     *  @param		int					$hideref			Do not show ref
211
     *  @return		int										1=OK, 0=KO
212
     */
213
    public function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
214
	{
215
        // phpcs:enable
216
		global $user,$langs,$conf,$hookmanager,$mysoc,$nblines;
217
218
		if (! is_object($outputlangs)) $outputlangs=$langs;
219
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
220
		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
221
222
		// Load translation files required by the page
223
		$outputlangs->loadLangs(array("main", "orders", "companies", "bills", "dict", "products"));
224
225
		$nblines = count($object->lines);
226
227
		// Loop on each lines to detect if there is at least one image to show
228
		$realpatharray=array();
229
		if (! empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE))
230
		{
231
			for ($i = 0 ; $i < $nblines ; $i++)
232
			{
233
				if (empty($object->lines[$i]->fk_product)) continue;
234
235
				$objphoto = new Product($this->db);
236
				$objphoto->fetch($object->lines[$i]->fk_product);
237
238
				if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
239
				{
240
					$pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product') . $object->lines[$i]->fk_product ."/photos/";
241
					$dir = $conf->product->dir_output.'/'.$pdir;
242
				}
243
				else
244
				{
245
					$pdir = get_exdir(0, 2, 0, 0, $objphoto, 'product') . dol_sanitizeFileName($objphoto->ref).'/';
246
					$dir = $conf->product->dir_output.'/'.$pdir;
247
				}
248
249
				$realpath='';
250
				foreach ($objphoto->liste_photos($dir, 1) as $key => $obj)
251
				{
252
					$filename=$obj['photo'];
253
					//if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
254
					$realpath = $dir.$filename;
255
					break;
256
				}
257
258
				if ($realpath) $realpatharray[$i]=$realpath;
259
			}
260
		}
261
		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
262
263
		if ($conf->fournisseur->commande->dir_output)
264
		{
265
			$object->fetch_thirdparty();
266
267
			$deja_regle = 0;
268
			$amount_credit_notes_included = 0;
269
			$amount_deposits_included = 0;
270
			//$amount_credit_notes_included = $object->getSumCreditNotesUsed();
271
            //$amount_deposits_included = $object->getSumDepositsUsed();
272
273
			// Definition of $dir and $file
274
			if ($object->specimen)
275
			{
276
				$dir = $conf->fournisseur->commande->dir_output;
277
				$file = $dir . "/SPECIMEN.pdf";
278
			}
279
			else
280
			{
281
				$objectref = dol_sanitizeFileName($object->ref);
282
				$objectrefsupplier = dol_sanitizeFileName($object->ref_supplier);
283
				$dir = $conf->fournisseur->commande->dir_output . '/'. $objectref;
284
				$file = $dir . "/" . $objectref . ".pdf";
285
				if (! empty($conf->global->SUPPLIER_REF_IN_NAME)) $file = $dir . "/" . $objectref . ($objectrefsupplier?"_".$objectrefsupplier:"").".pdf";
286
			}
287
288
			if (! file_exists($dir))
289
			{
290
				if (dol_mkdir($dir) < 0)
291
				{
292
					$this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
293
					return 0;
294
				}
295
			}
296
297
			if (file_exists($dir))
298
			{
299
				// Add pdfgeneration hook
300
				if (! is_object($hookmanager))
301
				{
302
					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
303
					$hookmanager=new HookManager($this->db);
304
				}
305
				$hookmanager->initHooks(array('pdfgeneration'));
306
				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
307
				global $action;
308
				$reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
309
310
				$nblines = count($object->lines);
311
312
                $pdf=pdf_getInstance($this->format);
313
                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
314
                $heightforinfotot = 50;	// Height reserved to output the info and total part
315
		        $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
316
	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
317
	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
318
                $pdf->SetAutoPageBreak(1, 0);
319
320
                if (class_exists('TCPDF'))
321
                {
322
                    $pdf->setPrintHeader(false);
323
                    $pdf->setPrintFooter(false);
324
                }
325
                $pdf->SetFont(pdf_getPDFFont($outputlangs));
326
                // Set path to the background PDF File
327
                if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
328
                {
329
                    $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
330
                    $tplidx = $pdf->importPage(1);
331
                }
332
333
				$pdf->Open();
334
				$pagenb=0;
335
				$pdf->SetDrawColor(128, 128, 128);
336
337
				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
338
				$pdf->SetSubject($outputlangs->transnoentities("Order"));
339
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
340
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
341
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
342
				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
343
344
				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
345
346
				// Positionne $this->atleastonediscount si on a au moins une remise
347
				for ($i = 0 ; $i < $nblines ; $i++)
348
				{
349
					if ($object->lines[$i]->remise_percent)
350
					{
351
						$this->atleastonediscount++;
352
					}
353
				}
354
				if (empty($this->atleastonediscount))
355
				{
356
				    $delta = ($this->postotalht - $this->posxdiscount);
357
				    $this->posxpicture+=$delta;
358
				    $this->posxtva+=$delta;
359
				    $this->posxup+=$delta;
360
				    $this->posxqty+=$delta;
361
				    $this->posxunit+=$delta;
362
				    $this->posxdiscount+=$delta;
363
				    // post of fields after are not modified, stay at same position
364
				}
365
366
				// New page
367
				$pdf->AddPage();
368
				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
369
				$pagenb++;
370
				$top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs);
371
				$pdf->SetFont('', '', $default_font_size - 1);
372
				$pdf->MultiCell(0, 3, '');		// Set interline to 3
373
				$pdf->SetTextColor(0, 0, 0);
374
375
				$tab_top = 90+$top_shift;
376
				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10);
377
378
				// Incoterm
379
				if ($conf->incoterm->enabled)
380
				{
381
					$desc_incoterms = $object->getIncotermsForPDF();
382
					if ($desc_incoterms)
383
					{
384
						$tab_top -= 2;
385
386
						$pdf->SetFont('', '', $default_font_size - 1);
387
						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
388
						$nexY = $pdf->GetY();
389
						$height_incoterms=$nexY-$tab_top;
390
391
						// Rect prend une longueur en 3eme param
392
						$pdf->SetDrawColor(192, 192, 192);
393
						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
394
395
						$tab_top = $nexY+6;
396
					}
397
				}
398
399
				// Affiche notes
400
				if (! empty($object->note_public))
401
				{
402
					$tab_top -= 2;
403
404
					$pdf->SetFont('', '', $default_font_size - 1);
405
					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($object->note_public), 0, 1);
406
					$nexY = $pdf->GetY();
407
					$height_note=$nexY-$tab_top;
408
409
					// Rect prend une longueur en 3eme param
410
					$pdf->SetDrawColor(192, 192, 192);
411
					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
412
413
					$tab_top = $nexY+6;
414
				}
415
416
				$iniY = $tab_top + 7;
417
				$curY = $tab_top + 7;
418
				$nexY = $tab_top + 7;
419
420
				// Loop on each lines
421
				for ($i = 0 ; $i < $nblines ; $i++)
422
				{
423
					$curY = $nexY;
424
					$pdf->SetFont('', '', $default_font_size - 1);   // Into loop to work with multipage
425
					$pdf->SetTextColor(0, 0, 0);
426
427
					// Define size of image if we need it
428
					$imglinesize=array();
429
					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
430
431
					$pdf->setTopMargin($tab_top_newpage);
432
					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
433
					$pageposbefore=$pdf->getPage();
434
435
					$showpricebeforepagebreak=1;
436
					$posYAfterImage=0;
437
					$posYAfterDescription=0;
438
439
					// We start with Photo of product line
440
					if (!empty($imglinesize['width']) && !empty($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
441
					{
442
						$pdf->AddPage('', '', true);
443
						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
444
						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
445
						$pdf->setPage($pageposbefore+1);
446
447
						$curY = $tab_top_newpage;
448
						$showpricebeforepagebreak=0;
449
					}
450
451
					if (!empty($imglinesize['width']) && !empty($imglinesize['height']))
452
					{
453
						$curX = $this->posxpicture-1;
454
						$pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
455
						// $pdf->Image does not increase value return by getY, so we save it manually
456
						$posYAfterImage=$curY+$imglinesize['height'];
457
					}
458
					// Description of product line
459
					$curX = $this->posxdesc-1;
460
					$showpricebeforepagebreak=1;
461
462
					$pdf->startTransaction();
463
					if ($posYAfterImage > 0)
464
					{
465
						$descWidth = $this->posxpicture-$curX;
466
					}
467
					else
468
					{
469
						$descWidth = $this->posxtva-$curX;
470
					}
471
					pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
472
473
					$pageposafter=$pdf->getPage();
474
					if ($pageposafter > $pageposbefore)	// There is a pagebreak
475
					{
476
						$pdf->rollbackTransaction(true);
477
						$pageposafter=$pageposbefore;
478
						//print $pageposafter.'-'.$pageposbefore;exit;
479
						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
480
						pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
481
						$posyafter=$pdf->GetY();
482
						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
483
						{
484
							if ($i == ($nblines-1))	// No more lines, and no space left to show total, so we create a new page
485
							{
486
								$pdf->AddPage('', '', true);
487
								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
488
								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
489
								$pdf->setPage($pageposafter+1);
490
							}
491
						}
492
						else
493
						{
494
							// We found a page break
495
							$showpricebeforepagebreak=0;
496
						}
497
					}
498
					else	// No pagebreak
499
					{
500
						$pdf->commitTransaction();
501
					}
502
503
					$nexY = $pdf->GetY();
504
                    $pageposafter=$pdf->getPage();
505
					$pdf->setPage($pageposbefore);
506
					$pdf->setTopMargin($this->marge_haute);
507
					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
508
509
					// We suppose that a too long description is moved completely on next page
510
					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
511
						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
512
					}
513
514
					$pdf->SetFont('', '', $default_font_size - 1);   // On repositionne la police par defaut
515
516
					// VAT Rate
517
					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
518
					{
519
						$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
520
						$pdf->SetXY($this->posxtva, $curY);
521
						$pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
522
					}
523
524
					// Unit price before discount
525
					$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
526
					$pdf->SetXY($this->posxup, $curY);
527
					$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
528
529
					// Quantity
530
					$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
531
					$pdf->SetXY($this->posxqty, $curY);
532
					$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');  // Enough for 6 chars
533
534
					// Unit
535
					if($conf->global->PRODUCT_USE_UNITS)
536
					{
537
						$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
538
						$pdf->SetXY($this->posxunit, $curY);
539
						$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
540
					}
541
542
					// Discount on line
543
					$pdf->SetXY($this->posxdiscount, $curY);
544
					if ($object->lines[$i]->remise_percent)
545
					{
546
					    $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
547
						$pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $remise_percent, 0, 'R');
548
					}
549
550
					// Total HT line
551
                    $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs);
552
					$pdf->SetXY($this->postotalht, $curY);
553
					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
554
555
					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
556
					if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
557
					else $tvaligne=$object->lines[$i]->total_tva;
558
559
					$localtax1ligne=$object->lines[$i]->total_localtax1;
560
					$localtax2ligne=$object->lines[$i]->total_localtax2;
561
					$localtax1_rate=$object->lines[$i]->localtax1_tx;
562
					$localtax2_rate=$object->lines[$i]->localtax2_tx;
563
					$localtax1_type=$object->lines[$i]->localtax1_type;
564
					$localtax2_type=$object->lines[$i]->localtax2_type;
565
566
					if (! empty($object->remise_percent)) $tvaligne-=($tvaligne*$object->remise_percent)/100;
567
					if (! empty($object->remise_percent)) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
568
					if (! empty($object->remise_percent)) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
569
570
					$vatrate=(string) $object->lines[$i]->tva_tx;
571
572
					// Retrieve type from database for backward compatibility with old records
573
					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
574
					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
575
					{
576
						$localtaxtmp_array=getLocalTaxesFromRate($vatrate, 0, $mysoc, $object->thirdparty);
577
						$localtax1_type = $localtaxtmp_array[0];
578
						$localtax2_type = $localtaxtmp_array[2];
579
					}
580
581
				    // retrieve global local tax
582
					if ($localtax1_type && $localtax1ligne != 0)
583
						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
584
					if ($localtax2_type && $localtax2ligne != 0)
585
						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
586
587
					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
588
					if (! isset($this->tva[$vatrate])) 				$this->tva[$vatrate]=0;
589
					$this->tva[$vatrate] += $tvaligne;
590
591
					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
592
593
					// Add line
594
					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
595
					{
596
						$pdf->setPage($pageposafter);
597
						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
598
						//$pdf->SetDrawColor(190,190,200);
599
						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
600
						$pdf->SetLineStyle(array('dash'=>0));
601
					}
602
603
					$nexY+=2;    // Add space between lines
604
605
					// Detect if some page were added automatically and output _tableau for past pages
606
					while ($pagenb < $pageposafter)
607
					{
608
						$pdf->setPage($pagenb);
609
						if ($pagenb == 1)
610
						{
611
							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
612
						}
613
						else
614
						{
615
							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
616
						}
617
						$this->_pagefoot($pdf, $object, $outputlangs, 1);
618
						$pagenb++;
619
						$pdf->setPage($pagenb);
620
						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
621
						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
622
					}
623
					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
624
					{
625
						if ($pagenb == 1)
626
						{
627
							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
628
						}
629
						else
630
						{
631
							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
632
						}
633
						$this->_pagefoot($pdf, $object, $outputlangs, 1);
634
						// New page
635
						$pdf->AddPage();
636
						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
637
						$pagenb++;
638
						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
639
					}
640
				}
641
642
				// Show square
643
				if ($pagenb == 1)
644
				{
645
					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
646
					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
647
				}
648
				else
649
				{
650
					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
651
					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
652
				}
653
654
				// Affiche zone infos
655
				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
656
657
				// Affiche zone totaux
658
				$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
659
660
				// Affiche zone versements
661
				if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
662
				{
663
					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
664
				}
665
666
                // Pied de page
667
				$this->_pagefoot($pdf, $object, $outputlangs);
668
				if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
669
670
				$pdf->Close();
671
672
				$pdf->Output($file, 'F');
673
674
				// Add pdfgeneration hook
675
				$hookmanager->initHooks(array('pdfgeneration'));
676
				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
677
				global $action;
678
				$reshook=$hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
679
				if ($reshook < 0)
680
				{
681
				    $this->error = $hookmanager->error;
682
				    $this->errors = $hookmanager->errors;
683
				}
684
685
				if (! empty($conf->global->MAIN_UMASK))
686
				@chmod($file, octdec($conf->global->MAIN_UMASK));
687
688
				$this->result = array('fullpath'=>$file);
689
690
				return 1;   // Pas d'erreur
691
			}
692
			else
693
			{
694
				$this->error=$langs->trans("ErrorCanNotCreateDir", $dir);
695
				return 0;
696
			}
697
		}
698
		else
699
		{
700
			$this->error=$langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
701
			return 0;
702
		}
703
	}
704
705
706
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
707
	/**
708
	 *  Show payments table
709
	 *
710
	 *  @param	PDF			$pdf     		Object PDF
711
	 *  @param  CommandeFournisseur		$object			Object order
712
	 *	@param	int			$posy			Position y in PDF
713
	 *	@param	Translate	$outputlangs	Object langs for output
714
	 *	@return int							<0 if KO, >0 if OK
715
	 */
716
	private function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
717
	{
718
        // phpcs:enable
719
	}
720
721
722
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
723
	/**
724
	 *   Show miscellaneous information (payment mode, payment term, ...)
725
	 *
726
	 *   @param		PDF			$pdf     		Object PDF
727
	 *   @param		CommandeFournisseur		$object			Object to show
728
	 *   @param		int			$posy			Y
729
	 *   @param		Translate	$outputlangs	Langs object
730
	 *   @return	integer
731
	 */
732
	private function _tableau_info(&$pdf, $object, $posy, $outputlangs)
733
	{
734
        // phpcs:enable
735
	    global $conf;
736
	    $default_font_size = pdf_getPDFFontSize($outputlangs);
737
738
        // If France, show VAT mention if not applicable
739
		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
740
		{
741
			$pdf->SetFont('', 'B', $default_font_size - 2);
742
			$pdf->SetXY($this->marge_gauche, $posy);
743
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
744
745
			$posy=$pdf->GetY()+4;
746
		}
747
748
		$posxval=52;
749
750
	    // Show payments conditions
751
	    if (!empty($object->cond_reglement_code) || $object->cond_reglement)
752
	    {
753
	        $pdf->SetFont('', 'B', $default_font_size - 2);
754
	        $pdf->SetXY($this->marge_gauche, $posy);
755
	        $titre = $outputlangs->transnoentities("PaymentConditions").':';
756
	        $pdf->MultiCell(80, 4, $titre, 0, 'L');
757
758
			$pdf->SetFont('', '', $default_font_size - 2);
759
			$pdf->SetXY($posxval, $posy);
760
			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement);
761
			$lib_condition_paiement=str_replace('\n', "\n", $lib_condition_paiement);
762
			$pdf->MultiCell(80, 4, $lib_condition_paiement, 0, 'L');
763
764
	        $posy=$pdf->GetY()+3;
765
	    }
766
767
      	// Show payment mode
768
        if (!empty($object->mode_reglement_code))
769
        {
770
        	$pdf->SetFont('', 'B', $default_font_size - 2);
771
        	$pdf->SetXY($this->marge_gauche, $posy);
772
        	$titre = $outputlangs->transnoentities("PaymentMode").':';
773
        	$pdf->MultiCell(80, 5, $titre, 0, 'L');
774
775
        	$pdf->SetFont('', '', $default_font_size - 2);
776
        	$pdf->SetXY($posxval, $posy);
777
        	$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
778
        	$pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
779
780
        	$posy=$pdf->GetY()+2;
781
        }
782
783
784
		return $posy;
785
	}
786
787
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
788
	/**
789
	 *  Show total to pay
790
	 *
791
	 *  @param	PDF			$pdf           Object PDF
792
	 *	@param  Facture		$object         Object invoice
793
	 *	@param  int			$deja_regle     Montant deja regle
794
	 *	@param	int			$posy			Position depart
795
	 *	@param	Translate	$outputlangs	Objet langs
796
	 *	@return int							Position pour suite
797
	 */
798
	private function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
799
	{
800
        // phpcs:enable
801
		global $conf,$mysoc;
802
803
		$default_font_size = pdf_getPDFFontSize($outputlangs);
804
805
        $tab2_top = $posy;
806
		$tab2_hl = 4;
807
		$pdf->SetFont('', '', $default_font_size - 1);
808
809
		// Tableau total
810
		$col1x = 120; $col2x = 170;
811
		if ($this->page_largeur < 210) // To work with US executive format
812
		{
813
			$col2x-=20;
814
		}
815
		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
816
817
		$useborder=0;
818
		$index = 0;
819
820
		// Total HT
821
		$pdf->SetFillColor(255, 255, 255);
822
		$pdf->SetXY($col1x, $tab2_top + 0);
823
		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
824
825
		$total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
826
		$pdf->SetXY($col2x, $tab2_top + 0);
827
		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0)), 0, 'R', 1);
828
829
		// Show VAT by rates and total
830
		$pdf->SetFillColor(248, 248, 248);
831
832
		$this->atleastoneratenotnull=0;
833
		foreach($this->tva as $tvakey => $tvaval)
834
		{
835
			if ($tvakey > 0)    // On affiche pas taux 0
836
			{
837
				$this->atleastoneratenotnull++;
838
839
				$index++;
840
				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
841
842
				$tvacompl='';
843
844
				if (preg_match('/\*/', $tvakey))
845
				{
846
					$tvakey=str_replace('*', '', $tvakey);
847
					$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
848
				}
849
850
				$totalvat =$outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
851
				$totalvat.=vatrate($tvakey, 1).$tvacompl;
852
				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
853
854
				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
855
				$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
856
			}
857
		}
858
		if (! $this->atleastoneratenotnull) // If no vat at all
859
		{
860
			$index++;
861
			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
862
			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
863
864
			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
865
			$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
866
867
			// Total LocalTax1
868
			if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
869
			{
870
				$index++;
871
				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
872
				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
873
				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
874
				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
875
			}
876
877
			// Total LocalTax2
878
			if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
879
			{
880
				$index++;
881
				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
882
				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
883
				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
884
				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
885
			}
886
		}
887
		else
888
		{
889
			//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
890
			//{
891
    			//Local tax 1
892
			foreach($this->localtax1 as $localtax_type => $localtax_rate)
893
			{
894
				if (in_array((string) $localtax_type, array('2','4','6'))) continue;
895
896
				foreach($localtax_rate as $tvakey => $tvaval)
897
				{
898
					if ($tvakey != 0)    // On affiche pas taux 0
899
					{
900
						//$this->atleastoneratenotnull++;
901
902
						$index++;
903
						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
904
905
						$tvacompl='';
906
						if (preg_match('/\*/', $tvakey))
907
						{
908
							$tvakey=str_replace('*', '', $tvakey);
909
							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
910
						}
911
						$totalvat =$outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).' ';
912
						$totalvat.=vatrate(abs($tvakey), 1).$tvacompl;
913
						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
914
915
						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
916
						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
917
					}
918
				}
919
			}
920
921
			//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
922
			//{
923
    			//Local tax 2
924
			foreach($this->localtax2 as $localtax_type => $localtax_rate)
925
			{
926
				if (in_array((string) $localtax_type, array('2','4','6'))) continue;
927
928
				foreach($localtax_rate as $tvakey => $tvaval)
929
				{
930
					if ($tvakey != 0)    // On affiche pas taux 0
931
					{
932
						//$this->atleastoneratenotnull++;
933
934
						$index++;
935
						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
936
937
						$tvacompl='';
938
						if (preg_match('/\*/', $tvakey))
939
						{
940
							$tvakey=str_replace('*', '', $tvakey);
941
							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
942
						}
943
						$totalvat =$outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
944
						$totalvat.=vatrate(abs($tvakey), 1).$tvacompl;
945
						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
946
947
						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
948
						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
949
					}
950
				}
951
			}
952
		}
953
954
		// Total TTC
955
		$index++;
956
		$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
957
		$pdf->SetTextColor(0, 0, 60);
958
		$pdf->SetFillColor(224, 224, 224);
959
		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
960
961
		$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
962
		$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
963
		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1);
964
		$pdf->SetFont('', '', $default_font_size - 1);
965
		$pdf->SetTextColor(0, 0, 0);
966
967
        $creditnoteamount=0;
968
        $depositsamount=0;
969
		//$creditnoteamount=$object->getSumCreditNotesUsed();
970
		//$depositsamount=$object->getSumDepositsUsed();
971
		//print "x".$creditnoteamount."-".$depositsamount;exit;
972
		$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
973
		if (! empty($object->paye)) $resteapayer=0;
974
975
		if ($deja_regle > 0)
976
		{
977
			// Already paid + Deposits
978
		    $index++;
979
980
			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
981
			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
982
			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
983
			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
984
985
			$index++;
986
			$pdf->SetTextColor(0, 0, 60);
987
			$pdf->SetFillColor(224, 224, 224);
988
			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
989
			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
990
991
			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
992
			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
993
994
			$pdf->SetFont('', '', $default_font_size - 1);
995
			$pdf->SetTextColor(0, 0, 0);
996
		}
997
998
		$index++;
999
		return ($tab2_top + ($tab2_hl * $index));
1000
	}
1001
1002
    /**
1003
	 *   Show table for lines
1004
	 *
1005
	 *   @param		PDF			$pdf     		Object PDF
1006
	 *   @param		string		$tab_top		Top position of table
1007
	 *   @param		string		$tab_height		Height of table (rectangle)
1008
	 *   @param		int			$nexY			Y (not used)
1009
	 *   @param		Translate	$outputlangs	Langs object
1010
	 *   @param		int			$hidetop		Hide top bar of array
1011
	 *   @param		int			$hidebottom		Hide bottom bar of array
1012
	 *   @param		string		$currency		Currency code
1013
	 *   @return	void
1014
	 */
1015
	private function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '')
1016
	{
1017
		global $conf;
1018
1019
		// Force to disable hidetop and hidebottom
1020
		$hidebottom=0;
1021
		if ($hidetop) $hidetop=-1;
1022
1023
		$currency = !empty($currency) ? $currency : $conf->currency;
1024
		$default_font_size = pdf_getPDFFontSize($outputlangs);
1025
1026
        // Amount in (at tab_top - 1)
1027
		$pdf->SetTextColor(0, 0, 0);
1028
		$pdf->SetFont('', '', $default_font_size - 2);
1029
1030
		if (empty($hidetop))
1031
		{
1032
			$titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
1033
			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1034
			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1035
1036
			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1037
			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));
1038
		}
1039
1040
		$pdf->SetDrawColor(128, 128, 128);
1041
		$pdf->SetFont('', '', $default_font_size - 1);
1042
1043
		// Output Rect
1044
		$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
1045
1046
		if (empty($hidetop))
1047
		{
1048
			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);	// line prend une position y en 2eme param et 4eme param
1049
1050
			$pdf->SetXY($this->posxdesc-1, $tab_top+1);
1051
			$pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
1052
		}
1053
1054
        if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1055
        {
1056
    		$pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1057
			if (empty($hidetop))
1058
			{
1059
    			$pdf->SetXY($this->posxtva-3, $tab_top+1);
1060
    			$pdf->MultiCell($this->posxup-$this->posxtva+3, 2, $outputlangs->transnoentities("VAT"), '', 'C');
1061
			}
1062
        }
1063
1064
		$pdf->line($this->posxup, $tab_top, $this->posxup, $tab_top + $tab_height);
1065
		if (empty($hidetop))
1066
		{
1067
			$pdf->SetXY($this->posxup-1, $tab_top+1);
1068
			$pdf->MultiCell($this->posxqty-$this->posxup-1, 2, $outputlangs->transnoentities("PriceUHT"), '', 'C');
1069
		}
1070
1071
		$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1072
		if (empty($hidetop))
1073
		{
1074
			$pdf->SetXY($this->posxqty-1, $tab_top+1);
1075
			$pdf->MultiCell($this->posxunit-$this->posxqty-1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
1076
		}
1077
1078
		if($conf->global->PRODUCT_USE_UNITS) {
1079
			$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1080
			if (empty($hidetop)) {
1081
				$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1082
				$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', 'C');
1083
			}
1084
		}
1085
1086
		$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1087
		if (empty($hidetop))
1088
		{
1089
			if ($this->atleastonediscount)
1090
			{
1091
				$pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1092
				$pdf->MultiCell($this->postotalht-$this->posxdiscount+1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
1093
			}
1094
		}
1095
1096
		if ($this->atleastonediscount)
1097
		{
1098
			$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1099
		}
1100
		if (empty($hidetop))
1101
		{
1102
			$pdf->SetXY($this->postotalht-1, $tab_top+1);
1103
			$pdf->MultiCell(30, 2, $outputlangs->transnoentities("TotalHTShort"), '', 'C');
1104
		}
1105
	}
1106
1107
	/**
1108
	 *  Show top header of page.
1109
	 *
1110
	 *  @param	PDF			$pdf     		Object PDF
1111
	 *  @param  CommandeFournisseur		$object     	Object to show
1112
	 *  @param  int	    	$showaddress    0=no, 1=yes
1113
	 *  @param  Translate	$outputlangs	Object lang for output
1114
	 *  @return	void
1115
	 */
1116
	private function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1117
	{
1118
		global $langs, $conf, $mysoc;
1119
1120
		// Load translation files required by the page
1121
		$outputlangs->loadLangs(array("main", "orders", "companies", "bills", "sendings"));
1122
1123
		$default_font_size = pdf_getPDFFontSize($outputlangs);
1124
1125
		// Do not add the BACKGROUND as this is for suppliers
1126
		//pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1127
1128
		//Affiche le filigrane brouillon - Print Draft Watermark
1129
		/*if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
1130
		{
1131
            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
1132
		}*/
1133
		//Print content
1134
1135
		$pdf->SetTextColor(0, 0, 60);
1136
		$pdf->SetFont('', 'B', $default_font_size + 3);
1137
1138
		$posx=$this->page_largeur-$this->marge_droite-100;
1139
		$posy=$this->marge_haute;
1140
1141
		$pdf->SetXY($this->marge_gauche, $posy);
1142
1143
		// Logo
1144
		$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1145
		if ($this->emetteur->logo)
1146
		{
1147
			if (is_readable($logo))
1148
			{
1149
			    $height=pdf_getHeightForLogo($logo);
1150
			    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1151
			}
1152
			else
1153
			{
1154
				$pdf->SetTextColor(200, 0, 0);
1155
				$pdf->SetFont('', 'B', $default_font_size - 2);
1156
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
1157
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
1158
			}
1159
		}
1160
		else
1161
		{
1162
			$text=$this->emetteur->name;
1163
			$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1164
		}
1165
1166
		$pdf->SetFont('', 'B', $default_font_size + 3);
1167
		$pdf->SetXY($posx, $posy);
1168
		$pdf->SetTextColor(0, 0, 60);
1169
		$title=$outputlangs->transnoentities("SupplierOrder")." ".$outputlangs->convToOutputCharset($object->ref);
1170
		$pdf->MultiCell(100, 3, $title, '', 'R');
1171
		$posy+=1;
1172
1173
		if ($object->ref_supplier)
1174
		{
1175
			$posy+=4;
1176
			$pdf->SetFont('', 'B', $default_font_size);
1177
			$pdf->SetXY($posx, $posy);
1178
			$pdf->SetTextColor(0, 0, 60);
1179
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefSupplier")." : " . $outputlangs->convToOutputCharset($object->ref_supplier), '', 'R');
1180
			$posy+=1;
1181
		}
1182
1183
		$pdf->SetFont('', '', $default_font_size -1);
1184
1185
		if (! empty($conf->global->PDF_SHOW_PROJECT))
1186
		{
1187
			$object->fetch_projet();
1188
			if (! empty($object->project->ref))
1189
			{
1190
				$posy+=4;
1191
				$pdf->SetXY($posx, $posy);
1192
				$langs->load("projects");
1193
				$pdf->SetTextColor(0, 0, 60);
1194
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project")." : " . (empty($object->project->ref)?'':$object->projet->ref), '', 'R');
1195
			}
1196
		}
1197
1198
		if (! empty($object->date_commande))
1199
		{
1200
			$posy+=5;
1201
			$pdf->SetXY($posx, $posy);
1202
			$pdf->SetTextColor(0, 0, 60);
1203
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date_commande, "day", false, $outputlangs, true), '', 'R');
1204
		}
1205
		else
1206
		{
1207
			$posy+=5;
1208
			$pdf->SetXY($posx, $posy);
1209
			$pdf->SetTextColor(255, 0, 0);
1210
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderToProcess"), '', 'R');
1211
		}
1212
1213
		$pdf->SetTextColor(0, 0, 60);
1214
		$usehourmin='day';
1215
		if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin='dayhour';
1216
		if (! empty($object->date_livraison))
1217
		{
1218
			$posy+=4;
1219
			$pdf->SetXY($posx-90, $posy);
1220
			$pdf->MultiCell(190, 3, $outputlangs->transnoentities("DateDeliveryPlanned")." : " . dol_print_date($object->date_livraison, $usehourmin, false, $outputlangs, true), '', 'R');
1221
		}
1222
1223
		if ($object->thirdparty->code_fournisseur)
1224
		{
1225
			$posy+=4;
1226
			$pdf->SetXY($posx, $posy);
1227
			$pdf->SetTextColor(0, 0, 60);
1228
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R');
1229
		}
1230
1231
		// Get contact
1232
		if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
1233
		{
1234
    		$arrayidcontact=$object->getIdContact('internal', 'SALESREPFOLL');
1235
    		if (count($arrayidcontact) > 0)
1236
    		{
1237
    		    $usertmp=new User($this->db);
1238
    		    $usertmp->fetch($arrayidcontact[0]);
1239
                $posy+=4;
1240
                $pdf->SetXY($posx, $posy);
1241
    		    $pdf->SetTextColor(0, 0, 60);
1242
    		    $pdf->MultiCell(100, 3, $langs->trans("BuyerName")." : ".$usertmp->getFullName($langs), '', 'R');
1243
    		}
1244
		}
1245
1246
		$posy+=1;
1247
		$pdf->SetTextColor(0, 0, 60);
1248
1249
		$top_shift = 0;
1250
		// Show list of linked objects
1251
		$current_y = $pdf->getY();
1252
		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
1253
		if ($current_y < $pdf->getY())
1254
		{
1255
			$top_shift = $pdf->getY() - $current_y;
1256
		}
1257
1258
		if ($showaddress)
1259
		{
1260
		    // Sender properties
1261
		    $carac_emetteur='';
1262
		    // Add internal contact of proposal if defined
1263
		    $arrayidcontact=$object->getIdContact('internal', 'SALESREPFOLL');
1264
		    if (count($arrayidcontact) > 0)
1265
		    {
1266
		        $object->fetch_user($arrayidcontact[0]);
1267
		        $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1268
		    }
1269
1270
			$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1271
1272
			// Show sender
1273
			$posy=42+$top_shift;
1274
			$posx=$this->marge_gauche;
1275
			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1276
			$hautcadre=40;
1277
1278
			// Show sender frame
1279
			$pdf->SetTextColor(0, 0, 0);
1280
			$pdf->SetFont('', '', $default_font_size - 2);
1281
			$pdf->SetXY($posx, $posy-5);
1282
			$pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1283
			$pdf->SetXY($posx, $posy);
1284
			$pdf->SetFillColor(230, 230, 230);
1285
			$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1286
			$pdf->SetTextColor(0, 0, 60);
1287
1288
			// Show sender name
1289
			$pdf->SetXY($posx+2, $posy+3);
1290
			$pdf->SetFont('', 'B', $default_font_size);
1291
			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1292
			$posy=$pdf->getY();
1293
1294
			// Show sender information
1295
			$pdf->SetXY($posx+2, $posy);
1296
			$pdf->SetFont('', '', $default_font_size - 1);
1297
			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1298
1299
1300
			// If CUSTOMER contact defined on order, we use it. Note: Even if this is a supplier object, the code for external contat that follow order is 'CUSTOMER'
1301
			$usecontact=false;
1302
			$arrayidcontact=$object->getIdContact('external', 'CUSTOMER');
1303
			if (count($arrayidcontact) > 0)
1304
			{
1305
				$usecontact=true;
1306
				$result=$object->fetch_contact($arrayidcontact[0]);
1307
			}
1308
1309
			//Recipient name
1310
			// On peut utiliser le nom de la societe du contact
1311
			if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1312
				$thirdparty = $object->contact;
1313
			} else {
1314
				$thirdparty = $object->thirdparty;
1315
			}
1316
1317
			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1318
1319
			$carac_client=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact?$object->contact:''), $usecontact, 'target', $object);
1320
1321
			// Show recipient
1322
			$widthrecbox=100;
1323
			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1324
			$posy=42+$top_shift;
1325
			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1326
			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1327
1328
			// Show recipient frame
1329
			$pdf->SetTextColor(0, 0, 0);
1330
			$pdf->SetFont('', '', $default_font_size - 2);
1331
			$pdf->SetXY($posx+2, $posy-5);
1332
			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1333
			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1334
1335
			// Show recipient name
1336
			$pdf->SetXY($posx+2, $posy+3);
1337
			$pdf->SetFont('', 'B', $default_font_size);
1338
			$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1339
1340
			$posy = $pdf->getY();
1341
1342
			// Show recipient information
1343
			$pdf->SetFont('', '', $default_font_size - 1);
1344
			$pdf->SetXY($posx+2, $posy);
1345
			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1346
		}
1347
1348
		return $top_shift;
1349
	}
1350
1351
	/**
1352
	 *  Show footer of page. Need this->emetteur object
1353
     *
1354
	 *  @param	PDF			$pdf     			PDF
1355
	 *  @param	CommandeFournisseur		$object				Object to show
1356
	 *  @param	Translate	$outputlangs		Object lang for output
1357
	 *  @param	int			$hidefreetext		1=Hide free text
1358
	 *  @return	int								Return height of bottom margin including footer text
1359
	 */
1360
	private function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1361
	{
1362
		global $conf;
1363
		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1364
		return pdf_pagefoot($pdf, $outputlangs, 'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);
1365
	}
1366
}
1367