pdf_azur_subtotal   F
last analyzed

Complexity

Total Complexity 225

Size/Duplication

Total Lines 1494
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 770
dl 0
loc 1494
rs 1.83
c 2
b 0
f 0
wmc 225

8 Methods

Rating   Name   Duplication   Size   Complexity  
F write_file() 0 607 118
C _tableau() 0 89 15
D _tableau_info() 0 166 29
F _tableau_tot() 0 260 34
D _pagehead() 0 188 17
C __construct() 0 64 9
A _tableau_versements() 0 2 1
A _pagefoot() 0 5 2

How to fix   Complexity   

Complex Class

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

1
<?php
2
/* Copyright (C) 2004-2014 Laurent Destailleur  <[email protected]>
3
 * Copyright (C) 2005-2012 Regis Houssin        <[email protected]>
4
 * Copyright (C) 2008      Raphael Bertrand     <[email protected]>
5
 * Copyright (C) 2010-2015 Juanjo Menent	    <[email protected]>
6
 * Copyright (C) 2012      Christophe Battarel   <[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/propale/doc/pdf_azur.modules.php
25
 *	\ingroup    propale
26
 *	\brief      Fichier de la classe permettant de generer les propales au modele Azur
27
 */
28
require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
29
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
30
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
32
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
33
34
35
/**
36
 *	Class to generate PDF proposal Azur
37
 */
38
class pdf_azur_subtotal extends ModelePDFPropales
39
{
40
	var $db;
41
	var $name;
42
	var $description;
43
	var $type;
44
45
	var $phpmin = array(4,3,0); // Minimum version of PHP required by module
46
	var $version = 'dolibarr';
47
48
	var $page_largeur;
49
	var $page_hauteur;
50
	var $format;
51
	var $marge_gauche;
52
	var	$marge_droite;
53
	var	$marge_haute;
54
	var	$marge_basse;
55
56
	var $emetteur;	// Objet societe qui emet
57
58
59
	/**
60
	 *	Constructor
61
	 *
62
	 *  @param		DoliDB		$db      Database handler
63
	 */
64
	function __construct($db)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
65
	{
66
		global $conf,$langs,$mysoc;
67
68
		$langs->load("main");
69
		$langs->load("bills");
70
71
		$this->db = $db;
72
		$this->name = "azur_subtotal";
73
		// J'ajoute l'annotation "déprécié" mais à garder... des fois qu'un client avec une vieille version utilise les modèles PDF custom
74
		$this->description = 'Modèle de proposition commerciale incluant des spécificités du module sous-total. (déprécié)';
75
76
		// Dimension page pour format A4
77
		$this->type = 'pdf';
78
		$formatarray=pdf_getFormat();
79
		$this->page_largeur = $formatarray['width'];
80
		$this->page_hauteur = $formatarray['height'];
81
		$this->format = array($this->page_largeur,$this->page_hauteur);
82
		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
83
		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
84
		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
85
		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
86
87
		$this->option_logo = 1;                    // Affiche logo
0 ignored issues
show
Bug Best Practice introduced by
The property option_logo does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
88
		$this->option_tva = 1;                     // Gere option tva FACTURE_TVAOPTION
0 ignored issues
show
Bug Best Practice introduced by
The property option_tva does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
89
		$this->option_modereg = 1;                 // Affiche mode reglement
0 ignored issues
show
Bug Best Practice introduced by
The property option_modereg does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
90
		$this->option_condreg = 1;                 // Affiche conditions reglement
0 ignored issues
show
Bug Best Practice introduced by
The property option_condreg does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
91
		$this->option_codeproduitservice = 1;      // Affiche code produit-service
0 ignored issues
show
Bug Best Practice introduced by
The property option_codeproduitservice does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
92
		$this->option_multilang = 1;               // Dispo en plusieurs langues
0 ignored issues
show
Bug Best Practice introduced by
The property option_multilang does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
93
		$this->option_escompte = 1;                // Affiche si il y a eu escompte
0 ignored issues
show
Bug Best Practice introduced by
The property option_escompte does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
94
		$this->option_credit_note = 1;             // Support credit notes
0 ignored issues
show
Bug Best Practice introduced by
The property option_credit_note does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
95
		$this->option_freetext = 1;				   // Support add of a personalised text
0 ignored issues
show
Bug Best Practice introduced by
The property option_freetext does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
96
		$this->option_draft_watermark = 1;		   //Support add of a watermark on drafts
0 ignored issues
show
Bug Best Practice introduced by
The property option_draft_watermark does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
97
98
		$this->franchise=!$mysoc->tva_assuj;
0 ignored issues
show
Bug Best Practice introduced by
The property franchise does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
99
100
		// Get source company
101
		$this->emetteur=$mysoc;
102
		if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default, if was not defined
103
104
		// Define position of columns
105
		$this->posxdesc=$this->marge_gauche+1;
0 ignored issues
show
Bug Best Practice introduced by
The property posxdesc does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
106
		$this->posxtva=112;
0 ignored issues
show
Bug Best Practice introduced by
The property posxtva does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
107
		$this->posxup=126;
0 ignored issues
show
Bug Best Practice introduced by
The property posxup does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
108
		$this->posxqty=145;
0 ignored issues
show
Bug Best Practice introduced by
The property posxqty does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
109
		$this->posxdiscount=162;
0 ignored issues
show
Bug Best Practice introduced by
The property posxdiscount does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
110
		$this->postotalht=174;
0 ignored issues
show
Bug Best Practice introduced by
The property postotalht does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
111
		if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup;
112
		$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
0 ignored issues
show
Bug Best Practice introduced by
The property posxpicture does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
113
		if ($this->page_largeur < 210) // To work with US executive format
114
		{
115
			$this->posxpicture-=20;
116
			$this->posxtva-=20;
117
			$this->posxup-=20;
118
			$this->posxqty-=20;
119
			$this->posxdiscount-=20;
120
			$this->postotalht-=20;
121
		}
122
123
		$this->tva=array();
0 ignored issues
show
Bug Best Practice introduced by
The property tva does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
124
		$this->localtax1=array();
0 ignored issues
show
Bug Best Practice introduced by
The property localtax1 does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
125
		$this->localtax2=array();
0 ignored issues
show
Bug Best Practice introduced by
The property localtax2 does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
126
		$this->atleastoneratenotnull=0;
0 ignored issues
show
Bug Best Practice introduced by
The property atleastoneratenotnull does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
127
		$this->atleastonediscount=0;
0 ignored issues
show
Bug Best Practice introduced by
The property atleastonediscount does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
128
	}
129
130
	/**
131
     *  Function to build pdf onto disk
132
     *
133
     *  @param		Object		$object				Object to generate
134
     *  @param		Translate	$outputlangs		Lang output object
135
     *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
136
     *  @param		int			$hidedetails		Do not show line details
137
     *  @param		int			$hidedesc			Do not show desc
138
     *  @param		int			$hideref			Do not show ref
139
     *  @return     int             				1=OK, 0=KO
140
	 */
141
	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Unused Code introduced by
The parameter $srctemplatepath is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

141
	function write_file($object,$outputlangs,/** @scrutinizer ignore-unused */ $srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
142
	{
143
		global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes;
144
145
		if (! is_object($outputlangs)) $outputlangs=$langs;
146
		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
147
		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
148
149
		$outputlangs->load("main");
150
		$outputlangs->load("dict");
151
		$outputlangs->load("companies");
152
		$outputlangs->load("bills");
153
		$outputlangs->load("propal");
154
		$outputlangs->load("products");
155
156
		$nblignes = count($object->lines);
157
158
		// Loop on each lines to detect if there is at least one image to show
159
		$realpatharray=array();
160
		if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
161
		{
162
			$objphoto = new Product($this->db);
163
164
			for ($i = 0 ; $i < $nblignes ; $i++)
165
			{
166
				if (empty($object->lines[$i]->fk_product)) continue;
167
168
				$objphoto->fetch($object->lines[$i]->fk_product);
169
170
				if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
171
				{
172
					$pdir[0] = get_exdir($objphoto->id,2) . $objphoto->id ."/photos/";
0 ignored issues
show
Bug introduced by
The call to get_exdir() has too few arguments starting with alpha. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
					$pdir[0] = /** @scrutinizer ignore-call */ get_exdir($objphoto->id,2) . $objphoto->id ."/photos/";

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
173
					$pdir[1] = dol_sanitizeFileName($objphoto->ref).'/';
174
				}
175
				else
176
				{
177
					$pdir[0] = dol_sanitizeFileName($objphoto->ref).'/';
178
					$pdir[1] = get_exdir($objphoto->id,2) . $objphoto->id ."/photos/";
179
				}
180
181
				$arephoto = false;
182
				foreach ($pdir as $midir)
183
				{
184
					if (! $arephoto)
185
					{
186
						$dir = $conf->product->dir_output.'/'.$midir;
187
188
						foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
189
						{
190
							if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))		// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
191
							{
192
								if ($obj['photo_vignette'])
193
								{
194
									$filename= $obj['photo_vignette'];
195
								}
196
								else
197
								{
198
									$filename=$obj['photo'];
199
								}
200
							}
201
							else
202
							{
203
								$filename=$obj['photo'];
204
							}
205
206
							$realpath = $dir.$filename;
207
							$arephoto = true;
208
						}
209
					}
210
				}
211
212
				if ($realpath && $arephoto) $realpatharray[$i]=$realpath;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $realpath does not seem to be defined for all execution paths leading up to this point.
Loading history...
213
			}
214
		}
215
216
		if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva;
0 ignored issues
show
Bug Best Practice introduced by
The property posxpicture does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
217
218
		if ($conf->propal->dir_output)
219
		{
220
			$object->fetch_thirdparty();
221
			if(!empty($object->client) ){
222
				$object->thirdparty = $object->client;
223
			}
224
			// $deja_regle = 0;
225
226
			// Definition of $dir and $file
227
			if ($object->specimen)
228
			{
229
				$dir = $conf->propal->dir_output;
230
				$file = $dir . "/SPECIMEN.pdf";
231
			}
232
			else
233
			{
234
				$objectref = dol_sanitizeFileName($object->ref);
235
				$dir = $conf->propal->dir_output . "/" . $objectref;
236
				$file = $dir . "/" . $objectref . ".pdf";
237
			}
238
239
			if (! file_exists($dir))
240
			{
241
				if (dol_mkdir($dir) < 0)
242
				{
243
					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
244
					return 0;
245
				}
246
			}
247
248
			if (file_exists($dir))
249
			{
250
				// Add pdfgeneration hook
251
				if (! is_object($hookmanager))
252
				{
253
					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
254
					$hookmanager=new HookManager($this->db);
255
				}
256
				$hookmanager->initHooks(array('pdfgeneration'));
257
				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
258
				global $action;
259
				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
0 ignored issues
show
Unused Code introduced by
The assignment to $reshook is dead and can be removed.
Loading history...
260
261
				// Create pdf instance
262
                $pdf=pdf_getInstance($this->format);
0 ignored issues
show
Bug introduced by
$this->format of type array<integer,integer> is incompatible with the type string expected by parameter $format of pdf_getInstance(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

262
                $pdf=pdf_getInstance(/** @scrutinizer ignore-type */ $this->format);
Loading history...
263
                $default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
264
                $heightforinfotot = 50;	// Height reserved to output the info and total part
265
		        $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
266
	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
267
                $pdf->SetAutoPageBreak(1,0);
268
269
                if (class_exists('TCPDF'))
270
                {
271
                    $pdf->setPrintHeader(false);
272
                    $pdf->setPrintFooter(false);
273
                }
274
                $pdf->SetFont(pdf_getPDFFont($outputlangs));
275
                // Set path to the background PDF File
276
                if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
277
                {
278
                    $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
0 ignored issues
show
Unused Code introduced by
The assignment to $pagecount is dead and can be removed.
Loading history...
279
                    $tplidx = $pdf->importPage(1);
280
                }
281
282
				$pdf->Open();
283
				$pagenb=0;
284
				$pdf->SetDrawColor(128,128,128);
285
286
				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
287
				$pdf->SetSubject($outputlangs->transnoentities("CommercialProposal"));
288
				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
289
				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
290
				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("CommercialProposal"));
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
				// Positionne $this->atleastonediscount si on a au moins une remise
296
				for ($i = 0 ; $i < $nblignes ; $i++)
297
				{
298
					if ($object->lines[$i]->remise_percent)
299
					{
300
						$this->atleastonediscount++;
301
					}
302
				}
303
				if (empty($this->atleastonediscount))
304
				{
305
					$this->posxpicture+=($this->postotalht - $this->posxdiscount);
306
					$this->posxtva+=($this->postotalht - $this->posxdiscount);
307
					$this->posxup+=($this->postotalht - $this->posxdiscount);
308
					$this->posxqty+=($this->postotalht - $this->posxdiscount);
309
					$this->posxdiscount+=($this->postotalht - $this->posxdiscount);
310
					//$this->postotalht;
311
				}
312
313
				// New page
314
				$pdf->AddPage();
315
				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
316
				$pagenb++;
317
				$this->_pagehead($pdf, $object, 1, $outputlangs);
318
				$pdf->SetFont('','', $default_font_size - 1);
319
				$pdf->MultiCell(0, 3, '');		// Set interline to 3
320
				$pdf->SetTextColor(0,0,0);
321
322
				$tab_top = 90;
323
				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
324
				$tab_height = 130;
325
				$tab_height_newpage = 150;
0 ignored issues
show
Unused Code introduced by
The assignment to $tab_height_newpage is dead and can be removed.
Loading history...
326
327
				// Affiche notes
328
				$notetoshow=empty($object->note_public)?'':$object->note_public;
329
				if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE))
330
				{
331
					// Get first sale rep
332
					if (is_object($object->thirdparty))
333
					{
334
						$salereparray=$object->thirdparty->getSalesRepresentatives($user);
335
						$salerepobj=new User($this->db);
336
						$salerepobj->fetch($salereparray[0]['id']);
337
						if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature);
338
					}
339
				}
340
				if ($notetoshow)
341
				{
342
					$tab_top = 88;
343
344
					$pdf->SetFont('','', $default_font_size - 1);
345
					$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
346
					$nexY = $pdf->GetY();
347
					$height_note=$nexY-$tab_top;
348
349
					// Rect prend une longueur en 3eme param
350
					$pdf->SetDrawColor(192,192,192);
351
					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
352
353
					$tab_height = $tab_height - $height_note;
0 ignored issues
show
Unused Code introduced by
The assignment to $tab_height is dead and can be removed.
Loading history...
354
					$tab_top = $nexY+6;
355
				}
356
				else
357
				{
358
					$height_note=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $height_note is dead and can be removed.
Loading history...
359
				}
360
361
				$iniY = $tab_top + 7;
0 ignored issues
show
Unused Code introduced by
The assignment to $iniY is dead and can be removed.
Loading history...
362
				$curY = $tab_top + 7;
0 ignored issues
show
Unused Code introduced by
The assignment to $curY is dead and can be removed.
Loading history...
363
				$nexY = $tab_top + 7;
364
365
				$inPackage = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $inPackage is dead and can be removed.
Loading history...
366
				$TPackageInfos = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $TPackageInfos is dead and can be removed.
Loading history...
367
				$TChilds = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $TChilds is dead and can be removed.
Loading history...
368
				$package_qty = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $package_qty is dead and can be removed.
Loading history...
369
				$TStack = array();
370
				
371
				// Loop on each lines
372
				for ($i = 0 ; $i < $nblignes ; $i++)
373
				{
374
					$package_qty = $TStack[count($TStack) - 1]['package_qty'];
375
					$inPackage = count($TStack) > 0;
376
					
377
					// Ligne de titre
378
					if ($object->lines[$i]->product_type == 9 && $object->lines[$i]->qty < 97 && $object->lines[$i]->fk_product > 0) {
379
						$inPackage = true;
380
						
381
						if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) {
382
							if (!empty($object->lines[$i]->fk_product)) {
383
								$product = new Product($db);
384
								$product->fetch($object->lines[$i]->fk_product);
385
								
386
								$TChilds = $product->getChildsArbo($product->id);
387
								
388
								$TStack[count($TStack)] = array(
389
									'childs' => $TChilds,
390
									'package' => array(),
391
									'package_qty' => 0
392
								);
393
								
394
								// Si on se trouvait déjà dans un package, on rajoute ce produit à la liste des produits
395
								// du précédent package
396
								if (count($TStack) > 1) {
397
									$TStack[count($TStack) - 2]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty;
398
								}
399
							}
400
						}
401
					}
402
					
403
					if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) {
404
						if ($inPackage && $object->lines[$i]->product_type != 9 && $object->lines[$i]->fk_product > 0) {
405
							$TStack[count($TStack) - 1]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty;
406
						}
407
					}
408
						
409
					// Ligne de sous-total
410
					if ($inPackage && $object->lines[$i]->product_type == 9 && $object->lines[$i]->qty >= 97) {
411
						if (count($TStack) <= 1) {
412
							$inPackage = false;
413
						}
414
						
415
						if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) {
416
							// Comparaison pour déterminer la quantité de package
417
							$TProducts = array_keys($TStack[count($TStack) - 1]['package']);
418
							$TProductsChilds = array_keys($TStack[count($TStack) - 1]['childs']);
419
							
420
							if ($TProductsChilds == $TProducts) {
421
								// Il s'agit d'un package
422
								// On récupére la quantité
423
								$first_child_id = $TProducts[0];
424
								$document_qty = $TStack[count($TStack) - 1]['package'][$first_child_id];
425
								$base_qty = $TStack[count($TStack) - 1]['childs'][$first_child_id][1];
426
								
427
								$TStack[count($TStack) - 1]['package_qty'] = $document_qty / $base_qty;
428
								$package_qty = $TStack[count($TStack) - 1]['package_qty'];
429
							}
430
							
431
							array_pop($TStack);
432
						}
433
					}
434
					
435
					$curY = $nexY;
436
					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
437
					$pdf->SetTextColor(0,0,0);
438
439
					// Define size of image if we need it
440
					$imglinesize=array();
441
					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
442
443
					$pdf->setTopMargin($tab_top_newpage);
444
					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
445
					$pageposbefore=$pdf->getPage();
446
447
					$showpricebeforepagebreak=1;
448
					$posYAfterImage=0;
449
					$posYAfterDescription=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $posYAfterDescription is dead and can be removed.
Loading history...
450
451
					// We start with Photo of product line
452
					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
453
					{
454
						$pdf->AddPage('','',true);
455
						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
456
						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
457
						$pdf->setPage($pageposbefore+1);
458
459
						$curY = $tab_top_newpage;
460
						$showpricebeforepagebreak=0;
461
					}
462
463
					if (isset($imglinesize['width']) && isset($imglinesize['height']))
464
					{
465
						$curX = $this->posxpicture-1;
466
						$pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
467
						// $pdf->Image does not increase value return by getY, so we save it manually
468
						$posYAfterImage=$curY+$imglinesize['height'];
469
					}
470
471
					// Description of product line
472
					$curX = $this->posxdesc-1;
473
474
					$pdf->startTransaction();
475
					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
476
477
					$pageposafter=$pdf->getPage();
478
					if ($pageposafter > $pageposbefore)	// There is a pagebreak
479
					{
480
						$pdf->rollbackTransaction(true);
481
						$pageposafter=$pageposbefore;
0 ignored issues
show
Unused Code introduced by
The assignment to $pageposafter is dead and can be removed.
Loading history...
482
						//print $pageposafter.'-'.$pageposbefore;exit;
483
						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
484
						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
485
486
						$pageposafter=$pdf->getPage();
487
						$posyafter=$pdf->GetY();
488
						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
489
						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
490
						{
491
							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
492
							{
493
								$pdf->AddPage('','',true);
494
								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
495
								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
496
								$pdf->setPage($pageposafter+1);
497
							}
498
						}
499
						else
500
						{
501
							// We found a page break
502
							$showpricebeforepagebreak=0;
503
						}
504
					}
505
					else	// No pagebreak
506
					{
507
						$pdf->commitTransaction();
508
					}
509
					$posYAfterDescription=$pdf->GetY();
510
511
					$nexY = $pdf->GetY();
512
					$pageposafter=$pdf->getPage();
513
514
					$pdf->setPage($pageposbefore);
515
					$pdf->setTopMargin($this->marge_haute);
516
					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
517
518
					// We suppose that a too long description or photo were moved completely on next page
519
					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
520
						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
521
					}
522
523
					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
524
525
					// VAT Rate
526
					if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
527
					{
528
						// Si on ne doit masquer que les sous-produits
529
						if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) {
530
							$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, 0);
531
						} else {
532
							$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
533
						}
534
						
535
						$pdf->SetXY($this->posxtva, $curY);
536
						$pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R');
537
					}
538
539
					// Unit price before discount
540
					if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) {
541
						$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, 0);
542
					} else {
543
						$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
544
					}
545
					
546
					$pdf->SetXY($this->posxup, $curY);
547
					$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
548
549
					// Booléen pour déterminer s'il s'agit d'une ligne de titre ou non
550
					$isTitle = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $isTitle is dead and can be removed.
Loading history...
551
					
552
					// Quantity
553
					// Affichage de la quantité sur les lignes de total si la conf l'indique
554
			
555
					// Récupération de la quantité à afficher
556
					if ($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY) {
557
						if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) {
558
							$qty = $package_qty;
559
						} else {
560
							$qty = pdf_getlineqty($object, $i, $outputlangs, 0);
561
						}
562
					} else {
563
						if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) {
564
							$qty = $package_qty;
565
						} else {
566
							$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
567
						}
568
					}
569
					
570
					$pdf->SetXY($this->posxqty, $curY);
571
					$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R');	// Enough for 6 chars
572
573
					// Discount on line
574
					if ($object->lines[$i]->remise_percent)
575
					{
576
						$pdf->SetXY($this->posxdiscount-2, $curY);
577
						$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
578
						$pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
579
					}
580
581
					// Total HT line
582
					if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) {
583
						$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, 0);
584
					} else {
585
						$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
586
					}
587
					
588
					$pdf->SetXY($this->postotalht, $curY);
589
					$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
590
591
					// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
592
					$tvaligne=$object->lines[$i]->total_tva;
593
					$localtax1ligne=$object->lines[$i]->total_localtax1;
594
					$localtax2ligne=$object->lines[$i]->total_localtax2;
595
					$localtax1_rate=$object->lines[$i]->localtax1_tx;
596
					$localtax2_rate=$object->lines[$i]->localtax2_tx;
597
					$localtax1_type=$object->lines[$i]->localtax1_type;
598
					$localtax2_type=$object->lines[$i]->localtax2_type;
599
600
					if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
601
					if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
602
					if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
603
604
					$vatrate=(string) $object->lines[$i]->tva_tx;
605
606
					// Retrieve type from database for backward compatibility with old records
607
					if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
608
					&& (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
609
					{
610
						$localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
611
						$localtax1_type = $localtaxtmp_array[0];
612
						$localtax2_type = $localtaxtmp_array[2];
613
					}
614
615
				    // retrieve global local tax
616
					if ($localtax1_type && $localtax1ligne != 0)
617
						$this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
618
					if ($localtax2_type && $localtax2ligne != 0)
619
						$this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
620
621
					if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
622
					if (! isset($this->tva[$vatrate]))				$this->tva[$vatrate]=0;
0 ignored issues
show
Bug Best Practice introduced by
The property tva does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
623
624
					if (!empty($object->lines[$i]->TTotal_tva))
625
					{
626
						foreach ($object->lines[$i]->TTotal_tva as $vatrate => $tvaligne)
627
						{
628
							$this->tva[$vatrate] += $tvaligne;
629
						}
630
					}
631
					else {
632
						// standard
633
						if(!empty($tvaligne)) $this->tva[$vatrate] += $tvaligne;
634
					}
635
636
					if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
637
638
					// Add line
639
					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
640
					{
641
						$pdf->setPage($pageposafter);
642
						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(210,210,210)));
643
						//$pdf->SetDrawColor(190,190,200);
644
						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
645
						$pdf->SetLineStyle(array('dash'=>0));
646
					}
647
648
					$nexY+=2;    // Passe espace entre les lignes
649
650
					// Detect if some page were added automatically and output _tableau for past pages
651
					while ($pagenb < $pageposafter)
652
					{
653
						$pdf->setPage($pagenb);
654
						if ($pagenb == 1)
655
						{
656
							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
657
						}
658
						else
659
						{
660
							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
661
						}
662
						$this->_pagefoot($pdf,$object,$outputlangs,1);
663
						$pagenb++;
664
						$pdf->setPage($pagenb);
665
						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
666
						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
667
					}
668
					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
669
					{
670
						if ($pagenb == 1)
671
						{
672
							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
673
						}
674
						else
675
						{
676
							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
677
						}
678
						$this->_pagefoot($pdf,$object,$outputlangs,1);
679
						// New page
680
						$pdf->AddPage();
681
						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
682
						$pagenb++;
683
						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
684
					}
685
				}
686
687
				// Show square
688
				if ($pagenb == 1)
689
				{
690
					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
691
					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
692
				}
693
				else
694
				{
695
					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
696
					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
697
				}
698
699
				// Affiche zone infos
700
				$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $posy is correct as $this->_tableau_info($pd...mlasttab, $outputlangs) targeting pdf_azur_subtotal::_tableau_info() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
The assignment to $posy is dead and can be removed.
Loading history...
701
702
				if (!$conf->global->SUBTOTAL_HIDE_DOCUMENT_TOTAL) {
703
					// Affiche zone totaux
704
					$posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
705
				}
706
707
				// Affiche zone versements
708
				/*
709
				if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
710
				{
711
					$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
712
				}
713
				*/
714
715
				// Pied de page
716
				$this->_pagefoot($pdf,$object,$outputlangs);
717
				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
718
719
				$pdf->Close();
720
721
				$pdf->Output($file,'F');
722
723
				//Add pdfgeneration hook
724
				$hookmanager->initHooks(array('pdfgeneration'));
725
				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
726
				global $action;
727
				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
728
729
				if (! empty($conf->global->MAIN_UMASK))
730
				@chmod($file, octdec($conf->global->MAIN_UMASK));
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for chmod(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

730
				/** @scrutinizer ignore-unhandled */ @chmod($file, octdec($conf->global->MAIN_UMASK));

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
It seems like octdec($conf->global->MAIN_UMASK) can also be of type double; however, parameter $permissions of chmod() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

730
				@chmod($file, /** @scrutinizer ignore-type */ octdec($conf->global->MAIN_UMASK));
Loading history...
731
732
				return 1;   // Pas d'erreur
733
			}
734
			else
735
			{
736
				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
737
				return 0;
738
			}
739
		}
740
		else
741
		{
742
			$this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR");
743
			return 0;
744
		}
745
746
		$this->error=$langs->trans("ErrorUnknown");
0 ignored issues
show
Unused Code introduced by
$this->error = $langs->trans('ErrorUnknown') is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
747
		return 0;   // Erreur par defaut
748
	}
749
750
	/**
751
	 *  Show payments table
752
	 *
753
     *  @param	PDF			$pdf           Object PDF
754
     *  @param  Object		$object         Object proposal
755
     *  @param  int			$posy           Position y in PDF
756
     *  @param  Translate	$outputlangs    Object langs for output
757
     *  @return int             			<0 if KO, >0 if OK
758
	 */
759
	function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Unused Code introduced by
The parameter $posy is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

759
	function _tableau_versements(&$pdf, $object, /** @scrutinizer ignore-unused */ $posy, $outputlangs)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $pdf is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

759
	function _tableau_versements(/** @scrutinizer ignore-unused */ &$pdf, $object, $posy, $outputlangs)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

759
	function _tableau_versements(&$pdf, /** @scrutinizer ignore-unused */ $object, $posy, $outputlangs)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $outputlangs is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

759
	function _tableau_versements(&$pdf, $object, $posy, /** @scrutinizer ignore-unused */ $outputlangs)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
760
	{
761
762
	}
763
764
765
	/**
766
	 *   Show miscellaneous information (payment mode, payment term, ...)
767
	 *
768
	 *   @param		PDF			$pdf     		Object PDF
769
	 *   @param		Object		$object			Object to show
770
	 *   @param		int			$posy			Y
771
	 *   @param		Translate	$outputlangs	Langs object
772
	 *   @return	void
773
	 */
774
	function _tableau_info(&$pdf, $object, $posy, $outputlangs)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
775
	{
776
		global $conf;
777
		$default_font_size = pdf_getPDFFontSize($outputlangs);
778
779
		$pdf->SetFont('','', $default_font_size - 1);
780
781
		// If France, show VAT mention if not applicable
782
		if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
783
		{
784
			$pdf->SetFont('','B', $default_font_size - 2);
785
			$pdf->SetXY($this->marge_gauche, $posy);
786
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
787
788
			$posy=$pdf->GetY()+4;
789
		}
790
791
		$posxval=52;
792
793
        // Show shipping date
794
        if (! empty($object->date_livraison))
795
		{
796
            $outputlangs->load("sendings");
797
			$pdf->SetFont('','B', $default_font_size - 2);
798
			$pdf->SetXY($this->marge_gauche, $posy);
799
			$titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
800
			$pdf->MultiCell(80, 4, $titre, 0, 'L');
801
			$pdf->SetFont('','', $default_font_size - 2);
802
			$pdf->SetXY($posxval, $posy);
803
			$dlp=dol_print_date($object->date_livraison,"daytext",false,$outputlangs,true);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $tzoutput of dol_print_date(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

803
			$dlp=dol_print_date($object->date_livraison,"daytext",/** @scrutinizer ignore-type */ false,$outputlangs,true);
Loading history...
804
			$pdf->MultiCell(80, 4, $dlp, 0, 'L');
805
806
            $posy=$pdf->GetY()+1;
807
		}
808
        elseif ($object->availability_code || $object->availability)    // Show availability conditions
809
		{
810
			$pdf->SetFont('','B', $default_font_size - 2);
811
			$pdf->SetXY($this->marge_gauche, $posy);
812
			$titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
813
			$pdf->MultiCell(80, 4, $titre, 0, 'L');
814
			$pdf->SetTextColor(0,0,0);
815
			$pdf->SetFont('','', $default_font_size - 2);
816
			$pdf->SetXY($posxval, $posy);
817
			$lib_availability=$outputlangs->transnoentities("AvailabilityType".$object->availability_code)!=('AvailabilityType'.$object->availability_code)?$outputlangs->transnoentities("AvailabilityType".$object->availability_code):$outputlangs->convToOutputCharset($object->availability);
818
			$lib_availability=str_replace('\n',"\n",$lib_availability);
819
			$pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
820
821
			$posy=$pdf->GetY()+1;
822
		}
823
824
		// Show payments conditions
825
		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement))
826
		{
827
			$pdf->SetFont('','B', $default_font_size - 2);
828
			$pdf->SetXY($this->marge_gauche, $posy);
829
			$titre = $outputlangs->transnoentities("PaymentConditions").':';
830
			$pdf->MultiCell(80, 4, $titre, 0, 'L');
831
832
			$pdf->SetFont('','', $default_font_size - 2);
833
			$pdf->SetXY($posxval, $posy);
834
			$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_doc);
835
			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
836
			$pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
837
838
			$posy=$pdf->GetY()+3;
839
		}
840
841
		if (empty($conf->global->PROPALE_PDF_HIDE_PAYMENTTERMCOND))
842
		{
843
			// Check a payment mode is defined
844
			/* Not required on a proposal
845
			if (empty($object->mode_reglement_code)
846
			&& ! $conf->global->FACTURE_CHQ_NUMBER
847
			&& ! $conf->global->FACTURE_RIB_NUMBER)
848
			{
849
				$pdf->SetXY($this->marge_gauche, $posy);
850
				$pdf->SetTextColor(200,0,0);
851
				$pdf->SetFont('','B', $default_font_size - 2);
852
				$pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
853
				$pdf->SetTextColor(0,0,0);
854
855
				$posy=$pdf->GetY()+1;
856
			}
857
			*/
858
859
			// Show payment mode
860
			if ($object->mode_reglement_code
861
			&& $object->mode_reglement_code != 'CHQ'
862
			&& $object->mode_reglement_code != 'VIR')
863
			{
864
				$pdf->SetFont('','B', $default_font_size - 2);
865
				$pdf->SetXY($this->marge_gauche, $posy);
866
				$titre = $outputlangs->transnoentities("PaymentMode").':';
867
				$pdf->MultiCell(80, 5, $titre, 0, 'L');
868
				$pdf->SetFont('','', $default_font_size - 2);
869
				$pdf->SetXY($posxval, $posy);
870
				$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);
871
				$pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
872
873
				$posy=$pdf->GetY()+2;
874
			}
875
876
			// Show payment mode CHQ
877
			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
878
			{
879
				// Si mode reglement non force ou si force a CHQ
880
				if (! empty($conf->global->FACTURE_CHQ_NUMBER))
881
				{
882
					$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
883
884
					if ($conf->global->FACTURE_CHQ_NUMBER > 0)
885
					{
886
						$account = new Account($this->db);
887
						$account->fetch($conf->global->FACTURE_CHQ_NUMBER);
888
889
						$pdf->SetXY($this->marge_gauche, $posy);
890
						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
891
						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0);
892
						$posy=$pdf->GetY()+1;
893
894
			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
895
			            {
896
							$pdf->SetXY($this->marge_gauche, $posy);
897
							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
898
							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
899
							$posy=$pdf->GetY()+2;
900
			            }
901
					}
902
					if ($conf->global->FACTURE_CHQ_NUMBER == -1)
903
					{
904
						$pdf->SetXY($this->marge_gauche, $posy);
905
						$pdf->SetFont('','B', $default_font_size - $diffsizetitle);
906
						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0);
907
						$posy=$pdf->GetY()+1;
908
909
			            if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS))
910
			            {
911
							$pdf->SetXY($this->marge_gauche, $posy);
912
							$pdf->SetFont('','', $default_font_size - $diffsizetitle);
913
							$pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
914
							$posy=$pdf->GetY()+2;
915
			            }
916
					}
917
				}
918
			}
919
920
			// If payment mode not forced or forced to VIR, show payment with BAN
921
			if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
922
			{
923
				if (! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER))
924
				{
925
					$bankid=(empty($object->fk_bank)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_bank);
926
					$account = new Account($this->db);
927
					$account->fetch($bankid);
928
929
					$curx=$this->marge_gauche;
930
					$cury=$posy;
931
932
					$posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
933
934
					$posy+=2;
935
				}
936
			}
937
		}
938
939
		return $posy;
940
	}
941
942
943
	/**
944
	 *	Show total to pay
945
	 *
946
	 *	@param	PDF			$pdf            Object PDF
947
	 *	@param  Facture		$object         Object invoice
948
	 *	@param  int			$deja_regle     Montant deja regle
949
	 *	@param	int			$posy			Position depart
950
	 *	@param	Translate	$outputlangs	Objet langs
951
	 *	@return int							Position pour suite
952
	 */
953
	function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
954
	{
955
		global $conf,$mysoc;
956
		$default_font_size = pdf_getPDFFontSize($outputlangs);
957
958
		$tab2_top = $posy;
959
		$tab2_hl = 4;
960
		$pdf->SetFont('','', $default_font_size - 1);
961
962
		// Tableau total
963
		$col1x = 120; $col2x = 170;
964
		if ($this->page_largeur < 210) // To work with US executive format
965
		{
966
			$col2x-=20;
967
		}
968
		$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
969
970
		$useborder=0;
971
		$index = 0;
972
973
		// Total HT
974
		$pdf->SetFillColor(255,255,255);
975
		$pdf->SetXY($col1x, $tab2_top + 0);
976
		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
977
978
		$pdf->SetXY($col2x, $tab2_top + 0);
979
		$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
0 ignored issues
show
Bug introduced by
The property remise does not exist on Facture. Did you mean remise_percent?
Loading history...
980
981
		// Show VAT by rates and total
982
		$pdf->SetFillColor(248,248,248);
983
984
		$this->atleastoneratenotnull=0;
0 ignored issues
show
Bug Best Practice introduced by
The property atleastoneratenotnull does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
985
		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
986
		{
987
			$tvaisnull=((! empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
988
			if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_ISNULL) && $tvaisnull)
989
			{
990
				// Nothing to do
991
			}
992
			else
993
			{
994
				//Local tax 1 before VAT
995
				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
996
				//{
997
					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
998
					{
999
						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1000
1001
						foreach( $localtax_rate as $tvakey => $tvaval )
1002
						{
1003
							if ($tvakey!=0)    // On affiche pas taux 0
1004
							{
1005
								//$this->atleastoneratenotnull++;
1006
1007
								$index++;
1008
								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1009
1010
								$tvacompl='';
1011
								if (preg_match('/\*/',$tvakey))
1012
								{
1013
									$tvakey=str_replace('*','',$tvakey);
1014
									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1015
								}
1016
								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1017
								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1018
								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1019
1020
								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1021
								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1022
							}
1023
						}
1024
					}
1025
	      		//}
1026
				//Local tax 2 before VAT
1027
				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1028
				//{
1029
					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1030
					{
1031
						if (in_array((string) $localtax_type, array('1','3','5'))) continue;
1032
1033
						foreach( $localtax_rate as $tvakey => $tvaval )
1034
						{
1035
							if ($tvakey!=0)    // On affiche pas taux 0
1036
							{
1037
								//$this->atleastoneratenotnull++;
1038
1039
1040
1041
								$index++;
1042
								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1043
1044
								$tvacompl='';
1045
								if (preg_match('/\*/',$tvakey))
1046
								{
1047
									$tvakey=str_replace('*','',$tvakey);
1048
									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1049
								}
1050
								$totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).' ';
1051
								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1052
								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1053
1054
								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1055
								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1056
1057
							}
1058
						}
1059
					}
1060
				//}
1061
				// VAT
1062
				foreach($this->tva as $tvakey => $tvaval)
1063
				{
1064
					if ($tvakey > 0)    // On affiche pas taux 0
1065
					{
1066
						$this->atleastoneratenotnull++;
1067
1068
						$index++;
1069
						$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1070
1071
						$tvacompl='';
1072
						if (preg_match('/\*/',$tvakey))
1073
						{
1074
							$tvakey=str_replace('*','',$tvakey);
1075
							$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1076
						}
1077
						$totalvat =$outputlangs->transnoentities("TotalVAT").' ';
1078
						$totalvat.=vatrate($tvakey,1).$tvacompl;
1079
						$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1080
1081
						$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1082
						$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1083
					}
1084
				}
1085
1086
				//Local tax 1 after VAT
1087
				//if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
1088
				//{
1089
					foreach( $this->localtax1 as $localtax_type => $localtax_rate )
1090
					{
1091
						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1092
1093
						foreach( $localtax_rate as $tvakey => $tvaval )
1094
						{
1095
							if ($tvakey != 0)    // On affiche pas taux 0
1096
							{
1097
								//$this->atleastoneratenotnull++;
1098
1099
								$index++;
1100
								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1101
1102
								$tvacompl='';
1103
								if (preg_match('/\*/',$tvakey))
1104
								{
1105
									$tvakey=str_replace('*','',$tvakey);
1106
									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1107
								}
1108
								$totalvat = $outputlangs->transcountrynoentities("TotalLT1",$mysoc->country_code).' ';
1109
1110
								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1111
								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1112
								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1113
								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1114
							}
1115
						}
1116
					}
1117
	      		//}
1118
				//Local tax 2 after VAT
1119
				//if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
1120
				//{
1121
					foreach( $this->localtax2 as $localtax_type => $localtax_rate )
1122
					{
1123
						if (in_array((string) $localtax_type, array('2','4','6'))) continue;
1124
1125
						foreach( $localtax_rate as $tvakey => $tvaval )
1126
						{
1127
						    // retrieve global local tax
1128
							if ($tvakey != 0)    // On affiche pas taux 0
1129
							{
1130
								//$this->atleastoneratenotnull++;
1131
1132
								$index++;
1133
								$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1134
1135
								$tvacompl='';
1136
								if (preg_match('/\*/',$tvakey))
1137
								{
1138
									$tvakey=str_replace('*','',$tvakey);
1139
									$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1140
								}
1141
								$totalvat = $outputlangs->transcountrynoentities("TotalLT2",$mysoc->country_code).' ';
1142
1143
								$totalvat.=vatrate(abs($tvakey),1).$tvacompl;
1144
								$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1145
1146
								$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1147
								$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1148
							}
1149
						}
1150
					}
1151
				//}
1152
1153
				// Total TTC
1154
				$index++;
1155
				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1156
				$pdf->SetTextColor(0,0,60);
1157
				$pdf->SetFillColor(224,224,224);
1158
				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1159
1160
				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1161
				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1162
			}
1163
		}
1164
1165
		$pdf->SetTextColor(0,0,0);
1166
1167
		/*
1168
		$resteapayer = $object->total_ttc - $deja_regle;
1169
		if (! empty($object->paye)) $resteapayer=0;
1170
		*/
1171
1172
		if ($deja_regle > 0)
1173
		{
1174
			$index++;
1175
1176
			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1177
			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
1178
1179
			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1180
			$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
1181
1182
			/*
1183
			if ($object->close_code == 'discount_vat')
1184
			{
1185
				$index++;
1186
				$pdf->SetFillColor(255,255,255);
1187
1188
				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1189
				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOffered"), $useborder, 'L', 1);
1190
1191
				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1192
				$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
1193
1194
				$resteapayer=0;
1195
			}
1196
			*/
1197
1198
			$index++;
1199
			$pdf->SetTextColor(0,0,60);
1200
			$pdf->SetFillColor(224,224,224);
1201
			$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1202
			$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
1203
1204
			$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1205
			$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $resteapayer seems to be never defined.
Loading history...
1206
1207
			$pdf->SetFont('','', $default_font_size - 1);
1208
			$pdf->SetTextColor(0,0,0);
1209
		}
1210
1211
		$index++;
1212
		return ($tab2_top + ($tab2_hl * $index));
1213
	}
1214
1215
	/**
1216
	 *   Show table for lines
1217
	 *
1218
	 *   @param		PDF			$pdf     		Object PDF
1219
	 *   @param		string		$tab_top		Top position of table
1220
	 *   @param		string		$tab_height		Height of table (rectangle)
1221
	 *   @param		int			$nexY			Y (not used)
1222
	 *   @param		Translate	$outputlangs	Langs object
1223
	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1224
	 *   @param		int			$hidebottom		Hide bottom bar of array
1225
	 *   @return	void
1226
	 */
1227
	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Unused Code introduced by
The parameter $nexY is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1227
	function _tableau(&$pdf, $tab_top, $tab_height, /** @scrutinizer ignore-unused */ $nexY, $outputlangs, $hidetop=0, $hidebottom=0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $hidebottom is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1227
	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, /** @scrutinizer ignore-unused */ $hidebottom=0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1228
	{
1229
		global $conf;
1230
1231
		// Force to disable hidetop and hidebottom
1232
		$hidebottom=0;
1233
		if ($hidetop) $hidetop=-1;
1234
1235
		$default_font_size = pdf_getPDFFontSize($outputlangs);
1236
1237
		// Amount in (at tab_top - 1)
1238
		$pdf->SetTextColor(0,0,0);
1239
		$pdf->SetFont('','',$default_font_size - 2);
1240
1241
		if (empty($hidetop))
1242
		{
1243
			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->currency));
1244
			$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
1245
			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1246
1247
			//$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
1248
			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));
1249
		}
1250
1251
		$pdf->SetDrawColor(128,128,128);
1252
		$pdf->SetFont('','',$default_font_size - 1);
1253
1254
		// Output Rect
1255
		$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
0 ignored issues
show
Bug introduced by
$tab_top of type string is incompatible with the type double expected by parameter $y of CommonDocGenerator::printRect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1255
		$this->printRect($pdf,$this->marge_gauche, /** @scrutinizer ignore-type */ $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
Loading history...
Bug introduced by
$tab_height of type string is incompatible with the type double expected by parameter $h of CommonDocGenerator::printRect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1255
		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, /** @scrutinizer ignore-type */ $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
Loading history...
1256
1257
		if (empty($hidetop))
1258
		{
1259
			$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
1260
1261
			$pdf->SetXY($this->posxdesc-1, $tab_top+1);
1262
			$pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
1263
		}
1264
1265
		if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE))
1266
		{
1267
			$pdf->line($this->posxpicture-1, $tab_top, $this->posxpicture-1, $tab_top + $tab_height);
1268
			if (empty($hidetop))
1269
			{
1270
				//$pdf->SetXY($this->posxpicture-1, $tab_top+1);
1271
				//$pdf->MultiCell($this->posxtva-$this->posxpicture-1,2, $outputlangs->transnoentities("Photo"),'','C');
1272
			}
1273
		}
1274
1275
		if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
1276
		{
1277
			$pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
1278
			if (empty($hidetop))
1279
			{
1280
				$pdf->SetXY($this->posxtva-3, $tab_top+1);
1281
				$pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
1282
			}
1283
		}
1284
1285
		$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
1286
		if (empty($hidetop))
1287
		{
1288
			$pdf->SetXY($this->posxup-1, $tab_top+1);
1289
			$pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
1290
		}
1291
1292
		$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
1293
		if (empty($hidetop))
1294
		{
1295
			$pdf->SetXY($this->posxqty-1, $tab_top+1);
1296
			$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
1297
		}
1298
1299
		$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
1300
		if (empty($hidetop))
1301
		{
1302
			if ($this->atleastonediscount)
1303
			{
1304
				$pdf->SetXY($this->posxdiscount-1, $tab_top+1);
1305
				$pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
1306
			}
1307
		}
1308
		if ($this->atleastonediscount)
1309
		{
1310
			$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1311
		}
1312
		if (empty($hidetop))
1313
		{
1314
			$pdf->SetXY($this->postotalht-1, $tab_top+1);
1315
			$pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
1316
		}
1317
	}
1318
1319
	/**
1320
	 *  Show top header of page.
1321
	 *
1322
	 *  @param	PDF			$pdf     		Object PDF
1323
	 *  @param  Object		$object     	Object to show
1324
	 *  @param  int	    	$showaddress    0=no, 1=yes
1325
	 *  @param  Translate	$outputlangs	Object lang for output
1326
	 *  @return	void
1327
	 */
1328
	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1329
	{
1330
		global $conf,$langs;
1331
1332
		$outputlangs->load("main");
1333
		$outputlangs->load("bills");
1334
		$outputlangs->load("propal");
1335
		$outputlangs->load("companies");
1336
1337
		$default_font_size = pdf_getPDFFontSize($outputlangs);
1338
1339
		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
1340
1341
		//  Show Draft Watermark
1342
		if($object->statut==0 && (! empty($conf->global->PROPALE_DRAFT_WATERMARK)) )
1343
		{
1344
            pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->PROPALE_DRAFT_WATERMARK);
1345
		}
1346
1347
		$pdf->SetTextColor(0,0,60);
1348
		$pdf->SetFont('','B', $default_font_size + 3);
1349
1350
		$posy=$this->marge_haute;
1351
		$posx=$this->page_largeur-$this->marge_droite-100;
1352
1353
		$pdf->SetXY($this->marge_gauche,$posy);
1354
1355
		// Logo
1356
		$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
1357
		if ($this->emetteur->logo)
1358
		{
1359
			if (is_readable($logo))
1360
			{
1361
			    $height=pdf_getHeightForLogo($logo);
1362
			    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1363
			}
1364
			else
1365
			{
1366
				$pdf->SetTextColor(200,0,0);
1367
				$pdf->SetFont('','B',$default_font_size - 2);
1368
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1369
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1370
			}
1371
		}
1372
		else
1373
		{
1374
			$text=$this->emetteur->name;
1375
			$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1376
		}
1377
1378
		$pdf->SetFont('','B',$default_font_size + 3);
1379
		$pdf->SetXY($posx,$posy);
1380
		$pdf->SetTextColor(0,0,60);
1381
		$title=$outputlangs->transnoentities("CommercialProposal");
1382
		$pdf->MultiCell(100, 4, $title, '', 'R');
1383
1384
		$pdf->SetFont('','B',$default_font_size);
1385
1386
		$posy+=5;
1387
		$pdf->SetXY($posx,$posy);
1388
		$pdf->SetTextColor(0,0,60);
1389
		$pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
1390
1391
		$posy+=1;
1392
		$pdf->SetFont('','', $default_font_size - 2);
1393
1394
		if ($object->ref_client)
1395
		{
1396
			$posy+=4;
1397
			$pdf->SetXY($posx,$posy);
1398
			$pdf->SetTextColor(0,0,60);
1399
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
1400
		}
1401
1402
		$posy+=4;
1403
		$pdf->SetXY($posx,$posy);
1404
		$pdf->SetTextColor(0,0,60);
1405
		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",false,$outputlangs,true), '', 'R');
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $tzoutput of dol_print_date(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1405
		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date")." : " . dol_print_date($object->date,"day",/** @scrutinizer ignore-type */ false,$outputlangs,true), '', 'R');
Loading history...
1406
1407
		$posy+=4;
1408
		$pdf->SetXY($posx,$posy);
1409
		$pdf->SetTextColor(0,0,60);
1410
		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : " . dol_print_date($object->fin_validite,"day",false,$outputlangs,true), '', 'R');
1411
		if ($object->thirdparty->code_client)
1412
		{
1413
			$posy+=4;
1414
			$pdf->SetXY($posx,$posy);
1415
			$pdf->SetTextColor(0,0,60);
1416
			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
1417
		}
1418
1419
		$posy+=2;
1420
1421
		// Show list of linked objects
1422
		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
0 ignored issues
show
Unused Code introduced by
The assignment to $posy is dead and can be removed.
Loading history...
Bug introduced by
'R' of type string is incompatible with the type integer expected by parameter $align of pdf_writeLinkedObjects(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1422
		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, /** @scrutinizer ignore-type */ 'R', $default_font_size);
Loading history...
1423
1424
		if ($showaddress)
1425
		{
1426
			// Sender properties
1427
			$carac_emetteur='';
1428
		 	// Add internal contact of proposal if defined
1429
			$arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
1430
		 	if (count($arrayidcontact) > 0)
1431
		 	{
1432
		 		$object->fetch_user($arrayidcontact[0]);
1433
		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1434
		 	}
1435
1436
		 	$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
1437
1438
			// Show sender
1439
			$posy=42;
1440
		 	$posx=$this->marge_gauche;
1441
			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1442
			$hautcadre=40;
1443
1444
			// Show sender frame
1445
			$pdf->SetTextColor(0,0,0);
1446
			$pdf->SetFont('','', $default_font_size - 2);
1447
			$pdf->SetXY($posx,$posy-5);
1448
			$pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
1449
			$pdf->SetXY($posx,$posy);
1450
			$pdf->SetFillColor(230,230,230);
1451
			$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
1452
			$pdf->SetTextColor(0,0,60);
1453
1454
			// Show sender name
1455
			$pdf->SetXY($posx+2,$posy+3);
1456
			$pdf->SetFont('','B', $default_font_size);
1457
			$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1458
			$posy=$pdf->getY();
1459
1460
			// Show sender information
1461
			$pdf->SetXY($posx+2,$posy);
1462
			$pdf->SetFont('','', $default_font_size - 1);
1463
			$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
1464
1465
1466
			// If CUSTOMER contact defined, we use it
1467
			$usecontact=false;
1468
			$arrayidcontact=$object->getIdContact('external','CUSTOMER');
1469
			if (count($arrayidcontact) > 0)
1470
			{
1471
				$usecontact=true;
1472
				$result=$object->fetch_contact($arrayidcontact[0]);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
1473
			}
1474
1475
			// Recipient name
1476
			if (! empty($usecontact))
1477
			{
1478
				// On peut utiliser le nom de la societe du contact
1479
				if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname;
1480
				else $socname = $object->thirdparty->name;
1481
				$carac_client_name=$outputlangs->convToOutputCharset($socname);
1482
			}
1483
			else
1484
			{
1485
				$carac_client_name=$outputlangs->convToOutputCharset($object->thirdparty->name);
1486
			}
1487
1488
			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,'target');
0 ignored issues
show
Bug introduced by
It seems like $usecontact ? $object->contact : '' can also be of type string; however, parameter $targetcontact of pdf_build_address() does only seem to accept Contact, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1488
			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,/** @scrutinizer ignore-type */ ($usecontact?$object->contact:''),$usecontact,'target');
Loading history...
Bug introduced by
'target' of type string is incompatible with the type integer expected by parameter $mode of pdf_build_address(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1488
			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),$usecontact,/** @scrutinizer ignore-type */ 'target');
Loading history...
Bug introduced by
$usecontact of type boolean is incompatible with the type integer expected by parameter $usecontact of pdf_build_address(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1488
			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,($usecontact?$object->contact:''),/** @scrutinizer ignore-type */ $usecontact,'target');
Loading history...
1489
1490
			// Show recipient
1491
			$widthrecbox=100;
1492
			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1493
			$posy=42;
1494
			$posx=$this->page_largeur-$this->marge_droite-$widthrecbox;
1495
			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1496
1497
			// Show recipient frame
1498
			$pdf->SetTextColor(0,0,0);
1499
			$pdf->SetFont('','', $default_font_size - 2);
1500
			$pdf->SetXY($posx+2,$posy-5);
1501
			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo").":", 0, 'L');
1502
			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1503
1504
			// Show recipient name
1505
			$pdf->SetXY($posx+2,$posy+3);
1506
			$pdf->SetFont('','B', $default_font_size);
1507
			$pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
1508
1509
			// Show recipient information
1510
			$pdf->SetFont('','', $default_font_size - 1);
1511
			$pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($carac_client_name,50)*4));
1512
			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1513
		}
1514
1515
		$pdf->SetTextColor(0,0,0);
1516
	}
1517
1518
	/**
1519
	 *   	Show footer of page. Need this->emetteur object
1520
     *
1521
	 *   	@param	PDF			$pdf     			PDF
1522
	 * 		@param	Object		$object				Object to show
1523
	 *      @param	Translate	$outputlangs		Object lang for output
1524
	 *      @param	int			$hidefreetext		1=Hide free text
1525
	 *      @return	int								Return height of bottom margin including footer text
1526
	 */
1527
	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1528
	{
1529
		$showdetails=0;
1530
		$free_text = (float)DOL_VERSION > 3.8 ? 'PROPOSAL_FREE_TEXT' : 'PROPALE_FREE_TEXT';
1531
		return pdf_pagefoot($pdf,$outputlangs,$free_text,$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1532
	}
1533
1534
}
1535
1536