Completed
Push — master ( a34d33...77ae4e )
by
unknown
18s queued 12s
created

TSubtotal::duplicateLines()   F

Complexity

Conditions 25
Paths 516

Size

Total Lines 125
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 1 Features 0
Metric Value
cc 25
eloc 60
c 7
b 1
f 0
nc 516
nop 3
dl 0
loc 125
rs 0.6722

How to fix   Long Method    Complexity   

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:

1
<?php
2
3
4
class TSubtotal {
5
	
6
	static $module_number = 104777;
7
	
8
	static function addSubTotalLine(&$object, $label, $qty, $rang=-1) {
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...
9
		
10
		$res = 0;
11
		
12
		if( (float)DOL_VERSION <= 3.4 ) {
0 ignored issues
show
Bug introduced by
The constant DOL_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
13
			/**
14
			 * @var $object Facture
15
			 */
16
			if($object->element=='facture') $res =  $object->addline($object->id, $label, 0,$qty,0,0,0,0,0,'','',0,0,'','HT',0,9,-1, TSubtotal::$module_number);
17
			/**
18
			 * @var $object Propal
19
			 */
20
			else if($object->element=='propal') $res =  $object->addline($object->id,$label, 0,$qty,0,0,0,0,0,'HT',0,0,9,-1, TSubtotal::$module_number);
21
			/**
22
			 * @var $object Commande
23
			 */
24
			else if($object->element=='commande') $res =  $object->addline($object->id,$label, 0,$qty,0,0,0,0,0,0,0,'HT',0,'','',9,-1, TSubtotal::$module_number);
25
26
		}
27
		else {
28
			$desc = '';
29
			
30
			$TNotElements = array ('invoice_supplier', 'order_supplier');
31
			if ((float) DOL_VERSION < 6  || $qty==50 && !in_array($object->element, $TNotElements) ) {
32
				$desc = $label;
33
				$label = '';
34
			}
35
			
36
			/**
37
			 * @var $object Facture
38
			 */
39
			if($object->element=='facture') $res =  $object->addline($desc, 0,$qty,0,0,0,0,0,'','',0,0,'','HT',0,9,$rang, TSubtotal::$module_number, '', 0, 0, null, 0, $label);
40
			/**
41
			 * @var $object Facture fournisseur
42
			 */
43
			else if($object->element=='invoice_supplier') {
44
			    $object->special_code = TSubtotal::$module_number;
45
			    $rang = $object->line_max() + 1;
46
			    $res = $object->addline($label,0,0,0,0,$qty,0,0,'','',0,0,'HT',9,$rang);
47
			}
48
			/**
49
			 * @var $object Propal
50
			 */
51
			else if($object->element=='propal') $res = $object->addline($desc, 0,$qty,0,0,0,0,0,'HT',0,0,9,$rang, TSubtotal::$module_number, 0, 0, 0, $label);
52
			/**
53
			 * @var $object Propal Fournisseur
54
			 */
55
			else if($object->element=='supplier_proposal') $res = $object->addline($desc, 0,$qty,0,0,0,0,0,'HT',0,0,9,$rang, TSubtotal::$module_number, 0, 0, 0, $label);
56
			
57
			/**
58
			 * @var $object Commande
59
			 */
60
			else if($object->element=='commande') $res =  $object->addline($desc, 0,$qty,0,0,0,0,0,0,0,'HT',0,'','',9,$rang, TSubtotal::$module_number, 0, null, 0, $label);
61
			/**
62
			 * @var $object Commande fournisseur
63
			 */
64
			else if($object->element=='order_supplier') {
65
			    $object->special_code = TSubtotal::$module_number;
66
			    $res = $object->addline($label, 0,$qty,0,0,0,0,0,'',0,'HT', 0, 9);
67
			}
68
			/**
69
			 * @var $object Facturerec
70
			 */
71
			else if($object->element=='facturerec') $res =  $object->addline($desc, 0,$qty, 0, 0, 0, 0, 0, 'HT', 0, '', 0, 9, $rang, TSubtotal::$module_number,$label); 
72
			
73
		}
74
	
75
		self::generateDoc($object);
76
		
77
		return $res;
78
	}
79
80
	public static function generateDoc(&$object)
81
	{
82
		global $conf,$langs,$db;
83
		
84
		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
85
		{
86
			$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
0 ignored issues
show
Bug introduced by
The function GETPOST was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

86
			$hidedetails = (/** @scrutinizer ignore-call */ GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
Loading history...
87
			$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
88
			$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
89
			
90
			// Define output language
91
			$outputlangs = $langs;
92
			$newlang = GETPOST('lang_id', 'alpha');
93
			if (! empty($conf->global->MAIN_MULTILANGS) && empty($newlang))
94
				$newlang = !empty($object->client) ? $object->client->default_lang : $object->thirdparty->default_lang;
95
			if (! empty($newlang)) {
96
				$outputlangs = new Translate("", $conf);
0 ignored issues
show
Bug introduced by
The type Translate was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
97
				$outputlangs->setDefaultLang($newlang);
98
			}
99
100
			$ret = $object->fetch($object->id); // Reload to get new records
0 ignored issues
show
Unused Code introduced by
The assignment to $ret is dead and can be removed.
Loading history...
101
			if ((float) DOL_VERSION <= 3.6)
0 ignored issues
show
Bug introduced by
The constant DOL_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
102
			{
103
				if ($object->element == 'propal') propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
0 ignored issues
show
Bug introduced by
The function propale_pdf_create was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

103
				if ($object->element == 'propal') /** @scrutinizer ignore-call */ propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
Loading history...
104
				elseif ($object->element == 'commande') commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
0 ignored issues
show
Bug introduced by
The function commande_pdf_create was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

104
				elseif ($object->element == 'commande') /** @scrutinizer ignore-call */ commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
Loading history...
105
				elseif ($object->element == 'facture') facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
0 ignored issues
show
Bug introduced by
The function facture_pdf_create was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

105
				elseif ($object->element == 'facture') /** @scrutinizer ignore-call */ facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
Loading history...
106
			}
107
			else
108
			{
109
				if ($object->element!= 'facturerec') $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
110
			}
111
		}
112
	}
113
	
114
	/**
115
	 * Permet de mettre à jour les rangs afin de décaler des lignes pour une insertion en milieu de document
116
	 * 
117
	 * @param type $object
118
	 * @param type $rang_start
119
	 * @param type $move_to
120
	 */
121
	public static function updateRang(&$object, $rang_start, $move_to=1)
122
	{
123
		if (!class_exists('GenericObject')) require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
0 ignored issues
show
Bug introduced by
The constant DOL_DOCUMENT_ROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
124
		
125
		$row=new GenericObject($object->db);
0 ignored issues
show
Bug introduced by
The type GenericObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
126
		$row->table_element_line = $object->table_element_line;
127
		$row->fk_element = $object->fk_element;
128
		$row->id = $object->id;
129
		
130
		foreach ($object->lines as &$line)
131
		{
132
			if ($line->rang < $rang_start) continue;
133
			
134
			$row->updateRangOfLine($line->id, $line->rang+$move_to);
135
		}
136
	}
137
	
138
	/**
139
	 * Méthode qui se charge de faire les ajouts de sous-totaux manquant afin de fermer les titres ouvert lors de l'ajout d'un nouveau titre
140
	 * 
141
	 * @global type $langs
142
	 * @param type $object
143
	 * @param type $level_new_title
144
	 */
145
	public static function addSubtotalMissing(&$object, $level_new_title)
146
	{
147
		global $langs;
148
		$TTitle = self::getAllTitleWithoutTotalFromDocument($object);
149
		// Reverse - Pour partir de la fin et remonter dans les titres pour me permettre de m'arrêter quand je trouve un titre avec un niveau inférieur à celui qui a était ajouté
150
		$TTitle_reverse = array_reverse($TTitle);
151
		
152
		foreach ($TTitle_reverse as $k => $title_line)
153
		{
154
			$title_niveau = self::getNiveau($title_line);
155
			if ($title_niveau < $level_new_title) break;
156
			
157
			$rang_to_add = self::titleHasTotalLine($object, $title_line, true, true);
158
			
159
			if (is_numeric($rang_to_add)) 
160
			{
161
				if ($rang_to_add != -1) self::updateRang($object, $rang_to_add);
162
				
163
				self::addSubTotalLine($object, $langs->trans('SubTotal'), 100-$title_niveau, $rang_to_add);
164
				
165
				$object->lines[] = $object->line; // ajout de la ligne dans le tableau de ligne (Dolibarr ne le fait pas)
166
				if ($rang_to_add != -1) 
167
				{
168
					if (method_exists($object, 'fetch_lines')) $object->fetch_lines();
169
					else $object->fetch($object->id);
170
				}
171
			}
172
		}
173
	}
174
	
175
	public static function addTitle(&$object, $label, $level, $rang=-1)
176
	{
177
		self::addSubTotalLine($object, $label, $level, $rang);
178
	}
179
	
180
	public static function addTotal(&$object, $label, $level, $rang=-1)
181
	{
182
		self::addSubTotalLine($object, $label, (100-$level), $rang);
183
	}
184
185
	/**
186
	 * Récupère la liste des lignes de titre qui n'ont pas de sous-total
187
	 * 
188
	 * @param Propal|Commande|Facture				$object
0 ignored issues
show
Bug introduced by
The type Commande was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type Propal was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type Facture was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
189
	 * @param boolean								$get_block_total
190
	 * 
191
	 * @return array
192
	 */
193
	public static function getAllTitleWithoutTotalFromDocument(&$object, $get_block_total=false)
194
	{
195
		$TTitle = self::getAllTitleFromDocument($object, $get_block_total);
196
		
197
		foreach ($TTitle as $k => $title_line)
198
		{
199
			if (self::titleHasTotalLine($object, $title_line)) unset($TTitle[$k]);
200
		}
201
		
202
		return $TTitle;
203
	}
204
	
205
	/**
206
	 * Est-ce que mon titre ($title_line) a un sous-total ?
207
	 * 
208
	 * @param Propal|Commande|Facture				$object
209
	 * @param PropaleLigne|OrderLine|FactureLigne	$title_line
0 ignored issues
show
Bug introduced by
The type PropaleLigne was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type OrderLine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type FactureLigne was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
210
	 * @param boolean								$strict_mode			si true alors un titre doit avoir un sous-total de même niveau; si false un titre possède un sous-total à partir du moment où l'on trouve un titre de niveau égale ou inférieur
211
	 * @param boolean								$return_rang_on_false	si true alors renvoi le rang où devrait ce trouver le sous-total
212
	 * @return boolean
213
	 */
214
	public static function titleHasTotalLine(&$object, &$title_line, $strict_mode=false, $return_rang_on_false=false)
215
	{
216
		if (empty($object->lines) || !is_array($object->lines)) return false;
217
		
218
		$title_niveau = self::getNiveau($title_line);
219
		foreach ($object->lines as &$line)
220
		{
221
			if ($line->rang <= $title_line->rang) continue;
222
			if (self::isTitle($line) && self::getNiveau($line) <= $title_niveau) return false; // Oups on croise un titre d'un niveau inférieur ou égale (exemple : je croise un titre niveau 2 alors que je suis sur un titre de niveau 3) pas lieu de continuer car un nouveau bloc commence
223
			if (!self::isSubtotal($line)) continue;
224
			
225
			$subtotal_niveau = self::getNiveau($line);
226
			
227
			// Comparaison du niveau de la ligne de sous-total avec celui du titre
228
			if ($subtotal_niveau == $title_niveau) return true; // niveau égale => Ok mon titre a un sous-total
229
			elseif ($subtotal_niveau < $title_niveau) // niveau inférieur trouvé (exemple : sous-total de niveau 1 contre mon titre de niveau 3)
230
			{
231
				if ($strict_mode) return ($return_rang_on_false) ? $line->rang : false; // mode strict niveau pas égale donc faux
232
				else return true; // mode libre => OK je considère que mon titre à un sous-total
233
			}
234
		}
235
		
236
		// Sniff, j'ai parcouru toutes les lignes et pas de sous-total pour ce titre
237
		return ($return_rang_on_false) ? -1 : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $return_rang_on_false ? -1 : false also could return the type integer which is incompatible with the documented return type boolean.
Loading history...
238
	}
239
	
240
	public static function getAllTitleFromDocument(&$object, $get_block_total=false)
241
	{
242
		$TRes = array();
243
		if (!empty($object->lines))
244
		{
245
			foreach ($object->lines as $k => &$line)
246
			{
247
				if (self::isTitle($line))
248
				{
249
					if ($get_block_total)
250
					{
251
						$TTot = self::getTotalBlockFromTitle($object, $line);
252
						
253
						$line->total_pa_ht = $TTot['total_pa_ht'];
254
						$line->total_options = $TTot['total_options'];
255
						$line->total_ht = $TTot['total_ht'];
256
						$line->total_tva = $TTot['total_tva'];
257
						$line->total_ttc = $TTot['total_ttc'];
258
						$line->TTotal_tva = $TTot['TTotal_tva'];
259
						$line->multicurrency_total_ht = $TTot['multicurrency_total_ht'];
260
						$line->multicurrency_total_tva = $TTot['multicurrency_total_tva'];
261
						$line->multicurrency_total_ttc = $TTot['multicurrency_total_ttc'];
262
						$line->TTotal_tva_multicurrency = $TTot['TTotal_tva_multicurrency'];
263
					}
264
					
265
					$TRes[] = $line;
266
				}
267
			}
268
		}
269
		
270
		return $TRes;
271
	}
272
	
273
	public static function getTotalBlockFromTitle(&$object, &$line, $breakOnTitle = false)
274
	{
275
		dol_include_once('/core/lib/price.lib.php');
0 ignored issues
show
Bug introduced by
The function dol_include_once was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

275
		/** @scrutinizer ignore-call */ 
276
  dol_include_once('/core/lib/price.lib.php');
Loading history...
276
		$TTot = array('total_pa_ht' => 0, 'total_options' => 0, 'total_ht' => 0, 'total_tva' => 0, 'total_ttc' => 0, 'TTotal_tva' => array(), 'multicurrency_total_ht' => 0, 'multicurrency_total_tva' => 0, 'multicurrency_total_ttc' => 0, 'TTotal_tva_multicurrency' => array());
277
		
278
		foreach ($object->lines as &$l)
279
		{
280
			if ($l->rang <= $line->rang) continue;
281
			elseif (self::isSubtotal($l) && self::getNiveau($l) <= self::getNiveau($line)) break;
282
			elseif ($breakOnTitle && self::isTitle($l) && self::getNiveau($l) <= self::getNiveau($line)) break;
283
			
284
			if (!empty($l->array_options['options_subtotal_nc']))
285
			{
286
				$tabprice = calcul_price_total($l->qty, $l->subprice, $l->remise_percent, $l->tva_tx, $l->localtax1_tx, $l->localtax2_tx, 0, 'HT', $l->info_bits, $l->product_type);
0 ignored issues
show
Bug introduced by
The function calcul_price_total was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

286
				$tabprice = /** @scrutinizer ignore-call */ calcul_price_total($l->qty, $l->subprice, $l->remise_percent, $l->tva_tx, $l->localtax1_tx, $l->localtax2_tx, 0, 'HT', $l->info_bits, $l->product_type);
Loading history...
287
				$TTot['total_options'] += $tabprice[0]; // total ht
288
			}
289
			else
290
			{
291
				$TTot['total_pa_ht'] += $l->pa_ht * $l->qty;
292
				$TTot['total_subprice'] += $l->subprice * $l->qty;
293
				$TTot['total_ht'] += $l->total_ht;
294
				$TTot['total_tva'] += $l->total_tva;
295
				$TTot['total_ttc'] += $l->total_ttc;
296
				$TTot['TTotal_tva'][$l->tva_tx] += $l->total_tva;
297
				$TTot['multicurrency_total_ht'] += $l->multicurrency_total_ht;
298
				$TTot['multicurrency_total_tva'] += $l->multicurrency_total_tva;
299
				$TTot['multicurrency_total_ttc'] += $l->multicurrency_total_ttc;
300
				$TTot['TTotal_tva_multicurrency'][$l->tva_tx] += $l->multicurrency_total_tva;
301
			}
302
		}
303
		
304
		return $TTot;
305
	}
306
307
	public static function getOrderIdFromLineId(&$db, $fk_commandedet)
308
	{
309
		if (empty($fk_commandedet)) return false;
310
		
311
		$sql = 'SELECT fk_commande FROM '.MAIN_DB_PREFIX.'commandedet WHERE rowid = '.$fk_commandedet;
0 ignored issues
show
Bug introduced by
The constant MAIN_DB_PREFIX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
312
		$resql = $db->query($sql);
313
		
314
		if ($resql && ($row = $db->fetch_object($resql))) return $row->fk_commande;
315
		else return false;
316
	}
317
	
318
	public static function getLastLineOrderId(&$db, $fk_commande)
319
	{
320
		if (empty($fk_commande)) return false;
321
		
322
		$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commandedet WHERE fk_commande = '.$fk_commande.' ORDER BY rang DESC LIMIT 1';
0 ignored issues
show
Bug introduced by
The constant MAIN_DB_PREFIX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
323
		$resql = $db->query($sql);
324
		
325
		if ($resql && ($row = $db->fetch_object($resql))) return $row->rowid;
326
		else return false;
327
	}
328
	
329
	public static function getParentTitleOfLine(&$object, $i)
330
	{
331
		if ($i <= 0) return false;
332
		
333
		$skip_title = 0;
334
		// Je parcours les lignes précédentes
335
		while ($i--)
336
		{
337
			$line = &$object->lines[$i];
338
			// S'il s'agit d'un titre
339
			if ($line->product_type == 9 && $line->qty <= 10 && $line->qty >= 1)
340
			{
341
				if ($skip_title)
342
				{
343
					$skip_title--;
344
					continue;
345
				}
346
				
347
				//@INFO J'ai ma ligne titre qui contient ma ligne, par contre je check pas s'il y a un sous-total
348
				return $line;
349
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
350
			}
351
			elseif ($line->product_type == 9 && $line->qty >= 90 && $line->qty <= 99)
352
			{
353
				// Il s'agit d'un sous-total, ça veut dire que le prochain titre théoriquement doit être ignorer (je travail avec un incrément au cas ou je croise plusieurs sous-totaux)
354
				$skip_title++;
355
			}
356
		}
357
358
		return false;
359
	}
360
	
361
	public static function isTitle(&$line, $level=-1)
362
	{
363
		$res = $line->special_code == self::$module_number && $line->product_type == 9 && $line->qty <= 9;
364
		if($res && $level > -1) {
365
			return $line->qty == $level;
366
		} else return $res;
367
		
368
	}
369
	
370
	public static function isSubtotal(&$line, $level=-1)
371
	{
372
	    $res = $line->special_code == self::$module_number && $line->product_type == 9 && $line->qty >= 90;
373
	    if($res && $level > -1) {
374
	        return self::getNiveau($line) == $level;
375
	    } else return $res;
376
	}
377
	
378
	public static function isFreeText(&$line)
379
	{
380
		return $line->special_code == self::$module_number && $line->product_type == 9 && $line->qty == 50;
381
	}
382
	
383
	public static function isModSubtotalLine(&$line)
384
	{
385
		return self::isTitle($line) || self::isSubtotal($line) || self::isFreeText($line);
386
	}
387
388
	public static function getFreeTextHtml(&$line, $readonly=0)
389
	{
390
		global $conf;
391
		
392
		// Copie du fichier "objectline_edit.tpl.php"
393
		// editeur wysiwyg
394
		require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
0 ignored issues
show
Bug introduced by
The constant DOL_DOCUMENT_ROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
395
		$nbrows=ROWS_2;
0 ignored issues
show
Bug introduced by
The constant ROWS_2 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
396
		if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
397
		$enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
398
		$toolbarname='dolibarr_details';
399
		if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes';
400
		$text = !empty($line->description)?$line->description:$line->label;
401
		$doleditor=new DolEditor('line-description',$text,'',164,$toolbarname,'',false,true,$enable,$nbrows,'98%', $readonly);
0 ignored issues
show
Bug introduced by
The type DolEditor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
402
		return $doleditor->Create(1);
403
	}
404
	
405
	public static function duplicateLines(&$object, $lineid, $withBlockLine=false)
406
	{
407
		global $db,$user,$conf;
408
409
		$createRight = $user->rights->{$object->element}->creer;
410
		if($object->element == 'facturerec' )
411
		{
412
		    $object->statut = 0; // hack for facture rec
413
		    $createRight = $user->rights->facture->creer;
414
		}
415
		elseif($object->element == 'order_supplier' )
416
		{
417
		    $createRight = $user->rights->fournisseur->commande->creer;
418
		}
419
		elseif($object->element == 'invoice_supplier' )
420
		{
421
		    $createRight = $user->rights->fournisseur->facture->creer;
422
		}
423
		
424
		if ($object->statut == 0  && $createRight && (!empty($conf->global->SUBTOTAL_ALLOW_DUPLICATE_BLOCK) || !empty($conf->global->SUBTOTAL_ALLOW_DUPLICATE_LINE)))
425
		{
426
			dol_include_once('/subtotal/lib/subtotal.lib.php');
0 ignored issues
show
Bug introduced by
The function dol_include_once was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

426
			/** @scrutinizer ignore-call */ 
427
   dol_include_once('/subtotal/lib/subtotal.lib.php');
Loading history...
427
428
            if(!empty($object->lines)) {
429
                foreach($object->lines as $line) {
430
                    if($line->id == $lineid) $duplicateLine = $line;
431
                }
432
            }
433
            if(!empty($duplicateLine) && !self::isModSubtotalLine($duplicateLine)) $TLine = array($duplicateLine);
434
            else $TLine = self::getLinesFromTitleId($object, $lineid, $withBlockLine);
435
436
			if (!empty($TLine))
437
			{
438
				$object->db->begin();
439
				$res = 1;
440
441
				$TLineAdded = array();
442
				foreach ($TLine as $line)
443
				{
444
					// TODO refactore avec un doAddLine sur le même schéma que le doUpdateLine
445
					switch ($object->element) {
446
						case 'propal':
447
							//$desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$date_start='', $date_end='',$array_options=0, $fk_unit=null, $origin='', $origin_id=0)
448
							$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, 'HT', 0, $line->info_bits, $line->product_type, -1, $line->special_code, 0, 0, $line->pa_ht, $line->label, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->origin, $line->origin_id);
449
							break;
450
							
451
						case 'supplier_proposal':
452
						    $res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, 'HT', 0, $line->info_bits, $line->product_type, -1, $line->special_code, 0, 0, $line->pa_ht, $line->label, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->origin, $line->origin_id);
453
						    break;
454
							
455
						case 'commande':
456
							//$desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_options=0, $fk_unit=null, $origin='', $origin_id=0)
457
							$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->info_bits, $line->fk_remise_except, 'HT', 0, $line->date_start, $line->date_end, $line->product_type, -1, $line->special_code, 0, 0, $line->pa_ht, $line->label, $line->array_options, $line->fk_unit, $line->origin, $line->origin_id);
458
							break;
459
							
460
						case 'order_supplier':
461
						    $object->line = $line;
462
						    $object->line->fk_commande = $object->id;
463
						    $object->line->rang = $object->line_max() +1;
464
						    $res = $object->line->insert(1);
465
							break;
466
							
467
						case 'facture':
468
							//$desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null
469
							$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->date_start, $line->date_end, 0, $line->info_bits, $line->fk_remise_except, 'HT', 0, $line->product_type, -1, $line->special_code, $line->origin, $line->origin_id, $line->fk_parent_line, $line->fk_fournprice, $line->pa_ht, $line->label, $line->array_options, $line->situation_percent, $line->fk_prev_id, $line->fk_unit);
470
							break;
471
						/*	Totally useless on invoice supplier
472
						case 'invoice_supplier':
473
						    //var_dump($line); exit;
474
						    $rang = $object->line_max() +1;
475
						    $object->special_code = $line->special_code;
476
						    if (TSubtotal::isModSubtotalLine($line)) {
477
						        $object->line = $line;
478
						        $object->line->desc = $line->description;
479
						        $object->line->description = $line->description;
480
						        $object->line->fk_facture_fourn = $object->id;
481
						        $object->line->rang = $rang;
482
						        //var_dump($object->line); exit;
483
    						    $res = $object->line->insert(1);
484
						        break;
485
						        //var_dump($line->desc, $line->label, $line->description); exit;
486
						    }
487
						    $res = $object->addline($line->desc, $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, $line->fk_product, $line->remise_percent, $line->date_start, $line->date_end, 0, $line->info_bits, 'HT', $line->product_type, $rang);
488
						    break;
489
							*/
490
						case 'facturerec':
491
							//$desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null
492
							$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->date_start, $line->date_end, 0, $line->info_bits, $line->fk_remise_except, 'HT', 0, $line->product_type, -1, $line->special_code, $line->origin, $line->origin_id, $line->fk_parent_line, $line->fk_fournprice, $line->pa_ht, $line->label, $line->array_options, $line->situation_percent, $line->fk_prev_id, $line->fk_unit);
493
							break;
494
					}
495
496
					$TLineAdded[] = $object->line;
497
					// Error from addline
498
					if ($res <= 0) break;
499
					else
500
					{
501
						$object->line_from = $line;
502
						// Call trigger
503
						$result=$object->call_trigger('LINE_DUPLICATE',$user); // $object->line
504
						if ($result < 0)
505
						{
506
							$object->db->rollback();
507
							return -2;
508
						}
509
					}
510
				}
511
				
512
				if ($res > 0)
513
				{
514
					$object->db->commit();
515
					foreach ($TLineAdded as &$line)
516
					{
517
					    // ça peut paraitre non optimisé de déclancher la fonction sur toutes les lignes mais ceci est nécessaire pour réappliquer l'état exact de chaque ligne
518
					    _updateLineNC($object->element, $object->id, $line->id, $line->array_options['options_subtotal_nc']);
519
					}
520
					return count($TLineAdded);
521
				}
522
				else
523
				{
524
					$object->db->rollback();
525
					return -1;
526
				}
527
			}
528
529
			return 0;
530
		}
531
	}
532
	
533
	public static function getLinesFromTitle(&$object, $key_trad, $level=1, $under_title='', $withBlockLine=false, $key_is_id=false)
534
	{
535
		global $langs;
536
		
537
		// Besoin de comparer sur les 2 formes d'écriture
538
		if (!$key_is_id) $TTitle_search = array($langs->trans($key_trad), $langs->transnoentitiesnoconv($key_trad));
539
		
540
		$TTitle_under_search = array();
541
		if (!empty($under_title)) $TTitle_under_search = array($langs->trans($under_title), $langs->transnoentitiesnoconv($under_title));
542
		
543
		$TLine = array();
544
		$add_line = false;
545
		$under_title_found=false;
546
		
547
		foreach ($object->lines as $key => &$line)
548
		{
549
			if (!$under_title_found && !empty($TTitle_under_search))
550
			{
551
				if ($line->product_type == 9 && (in_array($line->desc, $TTitle_under_search) || in_array($line->label, $TTitle_under_search)) ) $under_title_found = true;
552
			}
553
			else
554
			{
555
				if ( ($key_is_id && $line->id == $key_trad) || (!$key_is_id && $line->product_type == 9 && $line->qty == $level && (in_array($line->desc, $TTitle_search) || in_array($line->label, $TTitle_search) )))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $TTitle_search does not seem to be defined for all execution paths leading up to this point.
Loading history...
556
				{
557
					if ($key_is_id) $level = $line->qty;
558
					
559
					$add_line = true;
560
					if ($withBlockLine) $TLine[] = $line;
561
					continue;
562
				}
563
				elseif ($add_line && TSubtotal::isModSubtotalLine($line) && TSubtotal::getNiveau($line) == $level) // Si on tombe sur un sous-total, il faut que ce soit un du même niveau que le titre
564
				{
565
					if ($withBlockLine) $TLine[] = $line;
566
					break;
567
				}
568
				
569
				if ($add_line)
570
				{
571
					if (!$withBlockLine && (self::isTitle($line) || self::isSubtotal($line)) ) continue;
572
					else $TLine[] = $line;
573
				}
574
			}
575
		}
576
		
577
		return $TLine;
578
	}
579
	
580
	public static function getLinesFromTitleId(&$object, $lineid, $withBlockLine=false)
581
	{
582
		return self::getLinesFromTitle($object, $lineid, '', '', $withBlockLine, true);
583
	}
584
	
585
	public static function doUpdateLine(&$object, $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $type, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0, $fk_unit = null, $notrigger = 0)
586
	{
587
		$res = 0;
588
		$object->db->begin();
589
		
590
		switch ($object->element) 
591
		{
592
		    case 'propal':
593
		        $res = $object->updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $desc, $price_base_type, $info_bits, $special_code, $fk_parent_line, $skip_update_total, $fk_fournprice, $pa_ht, $label, $type, $date_start, $date_end, $array_options, $fk_unit, 0, $notrigger);
594
		        break;
595
		        
596
		    case 'supplier_proposal':
597
		        $res = $object->updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $desc, $price_base_type, $info_bits, $special_code, $fk_parent_line, $skip_update_total, $fk_fournprice, $pa_ht, $label, $type, $array_options,'', $fk_unit);
598
		        break;
599
		        
600
			case 'commande':
601
				$res = $object->updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $date_start, $date_end, $type, $fk_parent_line, $skip_update_total, $fk_fournprice, $pa_ht, $label, $special_code, $array_options, $fk_unit, 0, $notrigger);
602
				break;
603
				
604
			case 'order_supplier':
605
			    $object->special_code = SELF::$module_number;
606
			    if (empty($desc)) $desc = $label;
607
			    $res = $object->updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $type, 0, $date_start, $date_end, $array_options, $fk_unit);
608
			    break;
609
			
610
			case 'facture':
611
				$res = $object->updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $type, $fk_parent_line, $skip_update_total, $fk_fournprice, $pa_ht, $label, $special_code, $array_options, $situation_percent, $fk_unit, 0, $notrigger);
612
				break;
613
				
614
			case 'invoice_supplier':
615
			    $object->special_code = SELF::$module_number;
616
			    if (empty($desc)) $desc = $label;
617
			    $res = $object->updateline($rowid, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, 0, $price_base_type, $info_bits, $type, $remise_percent, 0, $date_start, $date_end, $array_options, $fk_unit);
618
			    break;
619
				
620
			case 'facturerec':
621
				// Add extrafields and get rang
622
				$factureRecLine = new FactureLigneRec($object->db);
0 ignored issues
show
Bug introduced by
The type FactureLigneRec was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
623
				$factureRecLine->fetch($rowid);
624
				$factureRecLine->array_options = $array_options;
625
				$factureRecLine->insertExtraFields();
626
				$rang=$factureRecLine->rang;
627
				
628
				$fk_product=0; $fk_remise_except=''; $pu_ttc=0;	
629
				$res = $object->updateline($rowid, $desc, $pu, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $price_base_type, $info_bits, $fk_remise_except, $pu_ttc, $type, $rang, $special_code, $label, $fk_unit);
630
				break;
631
		}
632
		
633
		if ($res <= 0) $object->db->rollback();
634
		else $object->db->commit();
635
		
636
		return $res;
637
	}
638
	
639
	public static function getAllTitleFromLine(&$origin_line, $reverse = false)
640
	{
641
		global $db, $object;
642
		
643
		$TTitle = array();
644
		if(! empty($object->id) && in_array($object->element, array('propal', 'commande', 'facture'))) {}
645
		else {
646
			if ($origin_line->element == 'propaldet')
647
			{
648
				$object = new Propal($db);
649
				$object->fetch($origin_line->fk_propal);
650
			}
651
			else if ($origin_line->element == 'commandedet')
652
			{
653
				$object = new Commande($db);
654
				$object->fetch($origin_line->fk_commande);
655
			}
656
			else if ($origin_line->element == 'facturedet')
657
			{
658
				$object = new Facture($db);
659
				$object->fetch($origin_line->fk_facture);
660
			}
661
			else
662
			{
663
				return $TTitle;
664
			}
665
		}
666
		
667
		// Récupération de la position de la ligne
668
		$i = 0;
669
		foreach ($object->lines as &$line)
670
		{
671
			if ($origin_line->id == $line->id) break;
672
			else $i++;
673
		}
674
		
675
		$i--; // Skip la ligne d'origine
676
		
677
		// Si elle n'est pas en 1ère position, alors on cherche des titres au dessus
678
		if ($i >= 0)
679
		{
680
			$next_title_lvl_to_skip = 0;
681
			for ($y = $i; $y >= 0; $y--)
682
			{
683
				// Si je tombe sur un sous-total, je récupère son niveau pour savoir quel est le prochain niveau de titre que doit ignorer
684
				if (self::isSubtotal($object->lines[$y]))
685
				{
686
					$next_title_lvl_to_skip = self::getNiveau($object->lines[$y]);
687
				}
688
				elseif (self::isTitle($object->lines[$y]))
689
				{
690
					if ($object->lines[$y]->qty == $next_title_lvl_to_skip)
691
					{
692
						$next_title_lvl_to_skip = 0;
693
						continue;
694
					}
695
					else
696
					{
697
						if (empty($object->lines[$y]->array_options)) $object->lines[$y]->fetch_optionals();
698
						$TTitle[$object->lines[$y]->id] = $object->lines[$y];
699
						
700
						if ($object->lines[$y]->qty == 1) break;
701
					}
702
				}
703
			}
704
		}
705
		
706
		if ($reverse) $TTitle = array_reverse($TTitle, true);
707
		
708
		return $TTitle;
709
	}
710
	
711
	public static function getNiveau(&$line)
712
	{
713
		if (self::isTitle($line)) return $line->qty;
714
		elseif (self::isSubtotal($line)) return 100 - $line->qty;
715
		else return 0;
716
	}
717
	
718
	/**
719
	 * Ajoute une page de récap à la génération du PDF
720
	 * Le tableau total en bas du document se base sur les totaux des titres niveau 1 pour le moment
721
	 */
722
	public static function addRecapPage(&$parameters, &$origin_pdf)
723
	{
724
		global $user,$conf,$langs;
725
		
726
		$origin_file = $parameters['file'];
727
		$outputlangs = $parameters['outputlangs'];
728
		$object = $parameters['object'];
729
		
730
		$outputlangs->load('subtotal@subtotal');
731
		
732
		$objmarge = new stdClass();
733
		$objmarge->page_hauteur = 297;
734
		$objmarge->page_largeur = 210;
735
		$objmarge->marge_gauche = 10;
736
		$objmarge->marge_haute = 10;
737
		$objmarge->marge_droite = 10;
738
		
739
		$objectref = dol_sanitizeFileName($object->ref);
0 ignored issues
show
Bug introduced by
The function dol_sanitizeFileName was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

739
		$objectref = /** @scrutinizer ignore-call */ dol_sanitizeFileName($object->ref);
Loading history...
740
		if ($object->element == 'propal') $dir = $conf->propal->dir_output . '/' . $objectref;
741
		elseif ($object->element == 'commande') $dir = $conf->commande->dir_output . '/' . $objectref;
742
		elseif ($object->element == 'facture') $dir = $conf->facture->dir_output . '/' . $objectref;
743
		elseif ($object->element == 'facturerec') return; // no PDF for facturerec
744
		else
745
		{
746
			setEventMessage($langs->trans('warning_subtotal_recap_object_element_unknown', $object->element), 'warnings');
0 ignored issues
show
Bug introduced by
The function setEventMessage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

746
			/** @scrutinizer ignore-call */ 
747
   setEventMessage($langs->trans('warning_subtotal_recap_object_element_unknown', $object->element), 'warnings');
Loading history...
747
			return -1;
748
		}
749
		$file = $dir . '/' . $objectref . '_recap.pdf';
750
751
//		$pdf=pdf_getInstance($origin_pdf->format);
752
		$pdf=pdf_getInstance(array(210, 297)); // Format A4 Portrait
0 ignored issues
show
Bug introduced by
array(210, 297) 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

752
		$pdf=pdf_getInstance(/** @scrutinizer ignore-type */ array(210, 297)); // Format A4 Portrait
Loading history...
753
		$default_font_size = pdf_getPDFFontSize($outputlangs);	// Must be after pdf_getInstance
754
		$pdf->SetAutoPageBreak(1,0);
755
	             
756
		if (class_exists('TCPDF'))
757
		{
758
			$pdf->setPrintHeader(false);
759
			$pdf->setPrintFooter(false);
760
		}
761
		$pdf->SetFont(pdf_getPDFFont($outputlangs));
762
		// Set path to the background PDF File
763
		if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
764
		{
765
			$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...
766
			$tplidx = $pdf->importPage(1);
767
		}
768
769
		$pdf->Open();
770
		$pagenb=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $pagenb is dead and can be removed.
Loading history...
771
		$pdf->SetDrawColor(128,128,128);
772
773
		$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
774
		$pdf->SetSubject($outputlangs->transnoentities("subtotalRecap"));
775
		$pdf->SetCreator("Dolibarr ".DOL_VERSION);
0 ignored issues
show
Bug introduced by
The constant DOL_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
776
		$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
777
		$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("subtotalRecap")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
778
		if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
779
780
		$pdf->SetMargins($objmarge->marge_gauche, $objmarge->marge_haute, $objmarge->marge_droite);   // Left, Top, Right
781
782
		$pagenb=0;
783
		$pdf->SetDrawColor(128,128,128);
784
785
			
786
		// New page
787
		$pdf->AddPage();
788
		if (! empty($tplidx)) $pdf->useTemplate($tplidx);
789
		$pagenb++;
790
		
791
		
792
		self::pagehead($objmarge, $pdf, $object, 1, $outputlangs);
793
		$pdf->SetFont('','', $default_font_size - 1);
794
		$pdf->MultiCell(0, 3, '');		// Set interline to 3
795
		$pdf->SetTextColor(0,0,0);
796
		
797
		$heightforinfotot = 25;	// Height reserved to output the info and total part
798
		$heightforfooter = $objmarge->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
799
		
800
		$posx_designation = 25;
801
		$posx_options = 150;
802
		$posx_montant = 170;
803
		
804
		$tab_top = 72;
805
		$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?72:20); // TODO à vérifier
806
		
807
		$TTot = array('total_ht' => 0, 'total_ttc' => 0, 'TTotal_tva' => array());
808
		
809
		$TLine = self::getAllTitleFromDocument($object, true);
810
		if (!empty($TLine))
811
		{
812
			$hidetop = 0;
813
				
814
			$iniY = $tab_top + 10;
0 ignored issues
show
Unused Code introduced by
The assignment to $iniY is dead and can be removed.
Loading history...
815
			$curY = $tab_top + 10;
0 ignored issues
show
Unused Code introduced by
The assignment to $curY is dead and can be removed.
Loading history...
816
			$nexY = $tab_top + 10;
817
			
818
			$nblignes = count($TLine);
819
			foreach($TLine as $i => &$line)
820
			{
821
				$curY = $nexY;
822
				
823
				if (self::getNiveau($line) == 1) 
824
				{
825
					$pdf->SetFont('','B', $default_font_size - 1);   // Into loop to work with multipage
826
					$curY+=2;
827
					
828
					$TTot['total_ht'] += $line->total_ht;
829
					$TTot['total_tva'] += $line->total_tva;
830
					$TTot['total_ttc'] += $line->total_ttc;
831
					$TTot['multicurrency_total_ht'] += $line->multicurrency_total_ht;
832
					$TTot['multicurrency_total_tva'] += $line->multicurrency_total_tva;
833
					$TTot['multicurrency_total_ttc'] += $line->multicurrency_total_ttc;
834
					
835
					foreach ($line->TTotal_tva as $tx => $amount)
836
					{
837
						$TTot['TTotal_tva'][$tx] += $amount;
838
					}
839
					
840
					foreach ($line->TTotal_tva_multicurrency as $tx => $amount)
841
					{
842
						$TTot['TTotal_tva_multicurrency'][$tx] += $amount;
843
					}	
844
				}
845
				else $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
846
				
847
				$pdf->SetTextColor(0,0,0);
848
				
849
				$pdf->setTopMargin($tab_top_newpage + 10);
850
				$pdf->setPageOrientation('', 1, $heightforfooter+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
851
				$pageposbefore=$pdf->getPage();
852
				
853
				$showpricebeforepagebreak=1;
854
				
855
				$decalage = (self::getNiveau($line) - 1) * 2;
856
				
857
				// Print: Designation
858
				$label = $line->label;
859
				if( (float)DOL_VERSION < 6 ) {
860
					$label = !empty($line->label) ? $line->label : $line->desc;
861
				}
862
				
863
				
864
				$pdf->startTransaction();
865
				$pdf->writeHTMLCell($posx_options-$posx_designation-$decalage, 3, $posx_designation+$decalage, $curY, $outputlangs->convToOutputCharset($label), 0, 1, false, true, 'J',true);
866
				$pageposafter=$pdf->getPage();
867
				if ($pageposafter > $pageposbefore)	// There is a pagebreak
868
				{
869
					$pdf->rollbackTransaction(true);
870
					$pageposafter=$pageposbefore;
0 ignored issues
show
Unused Code introduced by
The assignment to $pageposafter is dead and can be removed.
Loading history...
871
					//print $pageposafter.'-'.$pageposbefore;exit;
872
					$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
873
					$pdf->writeHTMLCell($posx_options-$posx_designation-$decalage, 3, $posx_designation+$decalage, $curY, $outputlangs->convToOutputCharset($label), 0, 1, false, true, 'J',true);
874
875
					$pageposafter=$pdf->getPage();
876
					$posyafter=$pdf->GetY();
877
					//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
878
					if ($posyafter > ($objmarge->page_hauteur - ($heightforfooter+$heightforinfotot)))	// There is no space left for total+free text
879
					{
880
						if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
881
						{
882
							$pdf->AddPage('','',true);
883
							if (! empty($tplidx)) $pdf->useTemplate($tplidx);
884
							if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) self::pagehead($objmarge, $pdf, $object, 0, $outputlangs);
885
							$pdf->setPage($pageposafter+1);
886
						}
887
					}
888
					else
889
					{
890
						// We found a page break
891
						$showpricebeforepagebreak=0;
892
					}
893
				}
894
				else	// No pagebreak
895
				{
896
					$pdf->commitTransaction();
897
				}
898
				$posYAfterDescription=$pdf->GetY();
0 ignored issues
show
Unused Code introduced by
The assignment to $posYAfterDescription is dead and can be removed.
Loading history...
899
900
				$nexY = $pdf->GetY();
901
				$pageposafter=$pdf->getPage();
902
903
				$pdf->setPage($pageposbefore);
904
				$pdf->setTopMargin($objmarge->marge_haute);
905
				$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
906
907
				// We suppose that a too long description or photo were moved completely on next page
908
				if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
909
					$pdf->setPage($pageposafter); $curY = $tab_top_newpage + 10;
910
				}
911
				
912
				self::printLevel($objmarge, $pdf, $line, $curY, $posx_designation);
913
				
914
				// Print: Options
915
				if (!empty($line->total_options))
916
				{
917
					$pdf->SetXY($posx_options, $curY);
918
					$pdf->MultiCell($posx_montant-$posx_options-0.8, 3, price($line->total_options, 0, $outputlangs), 0, 'R', 0);
0 ignored issues
show
Bug introduced by
The function price was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

918
					$pdf->MultiCell($posx_montant-$posx_options-0.8, 3, /** @scrutinizer ignore-call */ price($line->total_options, 0, $outputlangs), 0, 'R', 0);
Loading history...
919
				}
920
				
921
				// Print: Montant
922
				$pdf->SetXY($posx_montant, $curY);
923
				$pdf->MultiCell($objmarge->page_largeur-$objmarge->marge_droite-$posx_montant-0.8, 3, price($line->total_ht, 0, $outputlangs), 0, 'R', 0);
924
				
925
				$nexY+=2;    // Passe espace entre les lignes
926
927
				// Detect if some page were added automatically and output _tableau for past pages
928
				while ($pagenb < $pageposafter)
929
				{
930
					$pdf->setPage($pagenb);
931
					if ($pagenb == 1)
932
					{
933
						self::tableau($objmarge, $pdf, $posx_designation, $posx_options, $posx_montant, $tab_top, $objmarge->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
934
					}
935
					else
936
					{
937
						self::tableau($objmarge, $pdf, $posx_designation, $posx_options, $posx_montant, $tab_top_newpage, $objmarge->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code);
938
					}
939
					
940
					$pagenb++;
941
					$pdf->setPage($pagenb);
942
					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
943
					if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) self::pagehead($objmarge, $pdf, $object, 0, $outputlangs);
944
				}
945
			}
946
		}
947
		
948
		// Show square
949
		if ($pagenb == 1)
950
		{
951
			self::tableau($objmarge, $pdf, $posx_designation, $posx_options, $posx_montant, $tab_top, $objmarge->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
952
			$bottomlasttab=$objmarge->page_hauteur - $heightforinfotot - $heightforfooter + 1;
953
		}
954
		else
955
		{
956
			self::tableau($objmarge, $pdf, $posx_designation, $posx_options, $posx_montant, $tab_top_newpage, $objmarge->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $hidetop does not seem to be defined for all execution paths leading up to this point.
Loading history...
957
			$bottomlasttab=$objmarge->page_hauteur - $heightforinfotot - $heightforfooter + 1;
958
		}
959
		
960
		// Affiche zone totaux
961
		$posy=self::tableau_tot($objmarge, $pdf, $object, $bottomlasttab, $outputlangs, $TTot);
0 ignored issues
show
Unused Code introduced by
The assignment to $posy is dead and can be removed.
Loading history...
962
		
963
		$pdf->Close();
964
		$pdf->Output($file,'F');
965
		
966
		$pagecount = self::concat($outputlangs, array($origin_file, $file), $origin_file);
967
		
968
		if (empty($conf->global->SUBTOTAL_KEEP_RECAP_FILE)) unlink($file);
969
	}
970
	
971
	private static function printLevel($objmarge, $pdf, $line, $curY, $posx_designation)
972
	{
973
		$level = $line->qty; // TODO à améliorer
974
		
975
		$pdf->SetXY($objmarge->marge_gauche, $curY);
976
		$pdf->MultiCell($posx_designation-$objmarge->marge_gauche-0.8, 5, $level, 0, 'L', 0);
977
	}
978
	
979
	/**
980
	 *  Show top header of page.
981
	 *
982
	 *  @param	PDF			$pdf     		Object PDF
983
	 *  @param  Object		$object     	Object to show
984
	 *  @param  int	    	$showdetail    0=no, 1=yes
985
	 *  @param  Translate	$outputlangs	Object lang for output
986
	 *  @return	void
987
	 */
988
	private static function pagehead(&$objmarge, &$pdf, &$object, $showdetail, $outputlangs)
989
	{
990
		global $conf,$mysoc;
991
992
		$default_font_size = pdf_getPDFFontSize($outputlangs);
993
994
		pdf_pagehead($pdf,$outputlangs,$objmarge->page_hauteur);
995
996
		$pdf->SetTextColor(0,0,60);
997
		$pdf->SetFont('','B', $default_font_size + 3);
998
999
		$posy=$objmarge->marge_haute;
1000
		$posx=$objmarge->page_largeur-$objmarge->marge_droite-100;
0 ignored issues
show
Unused Code introduced by
The assignment to $posx is dead and can be removed.
Loading history...
1001
		
1002
		$pdf->SetXY($objmarge->marge_gauche,$posy);
1003
1004
		$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
1005
		if ($mysoc->logo)
1006
		{
1007
			if (is_readable($logo))
1008
			{
1009
			    $height=pdf_getHeightForLogo($logo);
1010
			    $pdf->Image($logo, $objmarge->marge_gauche, $posy, 0, $height);	// width=0 (auto)
1011
			}
1012
			else
1013
			{
1014
				$pdf->SetTextColor(200,0,0);
1015
				$pdf->SetFont('','B',$default_font_size - 2);
1016
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
1017
				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
1018
			}
1019
			
1020
			$posy+=35;
1021
		}
1022
		else
1023
		{
1024
			$text=$mysoc->name;
1025
			$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
1026
			
1027
			$posy+=15;
1028
		}
1029
		
1030
		
1031
		$pdf->SetTextColor(0,0,0);
1032
		$pdf->SetFont('','B', $default_font_size + 2);
1033
		$pdf->SetXY($objmarge->marge_gauche,$posy);
1034
		
1035
		$key = 'subtotalPropalTitle';
1036
		if ($object->element == 'commande') $key = 'subtotalCommandeTitle';
1037
		elseif ($object->element == 'facture') $key = 'subtotalInvoiceTitle';
1038
		elseif ($object->element == 'facturerec') $key = 'subtotalInvoiceTitle';
1039
		
1040
		$pdf->MultiCell(150, 4, $outputlangs->transnoentities($key, $object->ref, $object->thirdparty->name), '', 'L');
1041
		
1042
		$pdf->SetFont('','', $default_font_size);
1043
		$pdf->SetXY($objmarge->page_largeur-$objmarge->marge_droite-40,$posy);
1044
		$pdf->MultiCell(40, 4, dol_print_date($object->date, 'daytext'), '', 'R');
0 ignored issues
show
Bug introduced by
The function dol_print_date was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

1044
		$pdf->MultiCell(40, 4, /** @scrutinizer ignore-call */ dol_print_date($object->date, 'daytext'), '', 'R');
Loading history...
1045
		
1046
		$posy += 8;
1047
			
1048
		$pdf->SetFont('','B', $default_font_size + 2);
1049
		$pdf->SetXY($objmarge->marge_gauche,$posy);
1050
		$pdf->MultiCell(70, 4, $outputlangs->transnoentities('subtotalRecapLot'), '', 'L');
1051
		
1052
	}
1053
	
1054
	/**
1055
	 *   Show table for lines
1056
	 *
1057
	 *   @param		PDF			$pdf     		Object PDF
1058
	 *   @param		string		$tab_top		Top position of table
1059
	 *   @param		string		$tab_height		Height of table (rectangle)
1060
	 *   @param		int			$nexY			Y (not used)
1061
	 *   @param		Translate	$outputlangs	Langs object
1062
	 *   @param		int			$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1063
	 *   @param		int			$hidebottom		Hide bottom bar of array
1064
	 *   @param		string		$currency		Currency code
1065
	 *   @return	void
1066
	 */
1067
	private static function tableau(&$objmarge, &$pdf, $posx_designation, $posx_options, $posx_montant, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
1068
	{
1069
		global $conf;
1070
		
1071
		// Force to disable hidetop and hidebottom
1072
		$hidebottom=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $hidebottom is dead and can be removed.
Loading history...
1073
		if ($hidetop) $hidetop=-1;
1074
1075
		$currency = !empty($currency) ? $currency : $conf->currency;
1076
		$default_font_size = pdf_getPDFFontSize($outputlangs);
1077
1078
		// Amount in (at tab_top - 1)
1079
		$pdf->SetTextColor(0,0,0);
1080
		$pdf->SetFont('','',$default_font_size);
1081
1082
		if (empty($hidetop))
1083
		{
1084
			$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
1085
			$pdf->SetXY($objmarge->page_largeur - $objmarge->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4.5);
1086
			$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1087
			
1088
			if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($objmarge->marge_gauche, $tab_top, $objmarge->page_largeur-$objmarge->marge_droite-$objmarge->marge_gauche, 8, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1089
			
1090
			
1091
			$pdf->line($objmarge->marge_gauche, $tab_top, $objmarge->page_largeur-$objmarge->marge_droite, $tab_top);	// line prend une position y en 2eme param et 4eme param
1092
1093
			$pdf->SetXY($posx_designation, $tab_top+2);
1094
			$pdf->MultiCell($posx_options - $posx_designation,2, $outputlangs->transnoentities("Designation"),'','L');
1095
			$pdf->SetXY($posx_options, $tab_top+2);
1096
			$pdf->MultiCell($posx_montant - $posx_options,2, $outputlangs->transnoentities("Options"),'','R');
1097
			$pdf->SetXY($posx_montant, $tab_top+2);
1098
			$pdf->MultiCell($objmarge->page_largeur - $objmarge->marge_droite - $posx_montant,2, $outputlangs->transnoentities("Amount"),'','R');
1099
			
1100
			$pdf->line($objmarge->marge_gauche, $tab_top+8, $objmarge->page_largeur-$objmarge->marge_droite, $tab_top+8);	// line prend une position y en 2eme param et 4eme param
1101
		}
1102
		else
1103
		{
1104
			$pdf->line($objmarge->marge_gauche, $tab_top-2, $objmarge->page_largeur-$objmarge->marge_droite, $tab_top-2);	// line prend une position y en 2eme param et 4eme param
1105
		}
1106
		
1107
	}
1108
	
1109
	private static function tableau_tot(&$objmarge, &$pdf, $object, $posy, $outputlangs, $TTot)
1110
	{
1111
		global $conf;
1112
		
1113
		$pdf->line($objmarge->marge_gauche, $posy, $objmarge->page_largeur-$objmarge->marge_droite, $posy);	// line prend une position y en 2eme param et 4eme param
1114
		
1115
		$default_font_size = pdf_getPDFFontSize($outputlangs);
1116
		
1117
		$tab2_top = $posy+2;
1118
		$tab2_hl = 4;
1119
		$pdf->SetFont('','', $default_font_size - 1);
1120
1121
		// Tableau total
1122
		$col1x = 120; $col2x = 170;
1123
		if ($objmarge->page_largeur < 210) // To work with US executive format
1124
		{
1125
			$col2x-=20;
1126
		}
1127
		$largcol2 = ($objmarge->page_largeur - $objmarge->marge_droite - $col2x);
1128
1129
		$useborder=0;
1130
		$index = 0;
1131
1132
		// Total HT
1133
		$pdf->SetFillColor(255,255,255);
1134
		$pdf->SetXY($col1x, $tab2_top + 0);
1135
		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
1136
1137
		// $total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1) ? $TTot['multicurrency_total_ht'] : $TTot['total_ht'];
1138
		$total_ht = $TTot['total_ht'];
1139
		$pdf->SetXY($col2x, $tab2_top + 0);
1140
		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht, 0, $outputlangs), 0, 'R', 1);
0 ignored issues
show
Bug introduced by
The function price was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

1140
		$pdf->MultiCell($largcol2, $tab2_hl, /** @scrutinizer ignore-call */ price($total_ht, 0, $outputlangs), 0, 'R', 1);
Loading history...
1141
1142
		// Show VAT by rates and total
1143
		$pdf->SetFillColor(248,248,248);
1144
		
1145
		$atleastoneratenotnull=0;
1146
		foreach($TTot['TTotal_tva'] as $tvakey => $tvaval)
1147
		{
1148
			if ($tvakey != 0)    // On affiche pas taux 0
1149
			{
1150
				$atleastoneratenotnull++;
1151
1152
				$index++;
1153
				$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1154
1155
				$tvacompl='';
1156
				if (preg_match('/\*/',$tvakey))
1157
				{
1158
					$tvakey=str_replace('*','',$tvakey);
1159
					$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
1160
				}
1161
				$totalvat =$outputlangs->transnoentities("TotalVAT").' ';
1162
				$totalvat.=vatrate($tvakey,1).$tvacompl;
0 ignored issues
show
Bug introduced by
The function vatrate was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

1162
				$totalvat.=/** @scrutinizer ignore-call */ vatrate($tvakey,1).$tvacompl;
Loading history...
1163
				$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
1164
1165
				$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1166
				$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
1167
			}
1168
		}
1169
		
1170
		// Total TTC
1171
		$index++;
1172
		$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1173
		$pdf->SetTextColor(0,0,60);
1174
		$pdf->SetFillColor(224,224,224);
1175
		$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
1176
1177
		// $total_ttc = ($conf->multicurrency->enabled && $object->multiccurency_tx != 1) ? $TTot['multicurrency_total_ttc'] : $TTot['total_ttc'];
1178
		$total_ttc = $TTot['total_ttc'];
1179
		$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1180
		$pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
1181
1182
		$pdf->SetTextColor(0,0,0);
1183
				
1184
		$index++;
1185
		return ($tab2_top + ($tab2_hl * $index));
1186
		
1187
	}
1188
	
1189
	/**
1190
	 * Rect pdf
1191
	 *
1192
	 * @param	PDF		$pdf			Object PDF
1193
	 * @param	float	$x				Abscissa of first point
1194
	 * @param	float	$y		        Ordinate of first point
1195
	 * @param	float	$l				??
1196
	 * @param	float	$h				??
1197
	 * @param	int		$hidetop		1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
1198
	 * @param	int		$hidebottom		Hide bottom
1199
	 * @return	void
1200
	 */
1201
    private static function printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
1202
    {
1203
	    if (empty($hidetop) || $hidetop==-1) $pdf->line($x, $y, $x+$l, $y);
1204
	    $pdf->line($x+$l, $y, $x+$l, $y+$h);
1205
	    if (empty($hidebottom)) $pdf->line($x+$l, $y+$h, $x, $y+$h);
1206
	    $pdf->line($x, $y+$h, $x, $y);
1207
    }
1208
	
1209
	
1210
	public static function concat(&$outputlangs, $files, $fileoutput='')
1211
	{
1212
		global $conf;
1213
		
1214
		if (empty($fileoutput)) $fileoutput = $file[0];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $file does not exist. Did you maybe mean $files?
Loading history...
1215
		
1216
		$pdf=pdf_getInstance();
1217
        if (class_exists('TCPDF'))
1218
        {
1219
            $pdf->setPrintHeader(false);
1220
            $pdf->setPrintFooter(false);
1221
        }
1222
        $pdf->SetFont(pdf_getPDFFont($outputlangs));
1223
1224
        if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
1225
1226
		
1227
		foreach($files as $file)
1228
		{
1229
			$pagecount = $pdf->setSourceFile($file);
1230
			for ($i = 1; $i <= $pagecount; $i++)
1231
			{
1232
				$tplidx = $pdf->ImportPage($i);
1233
				$s = $pdf->getTemplatesize($tplidx);
1234
				$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
1235
				$pdf->useTemplate($tplidx);
1236
			}
1237
		}
1238
		
1239
		$pdf->Output($fileoutput,'F');
1240
		if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK));
0 ignored issues
show
Bug introduced by
It seems like octdec($conf->global->MAIN_UMASK) can also be of type double; however, parameter $mode 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

1240
		if (! empty($conf->global->MAIN_UMASK)) @chmod($file, /** @scrutinizer ignore-type */ octdec($conf->global->MAIN_UMASK));
Loading history...
Comprehensibility Best Practice introduced by
The variable $file seems to be defined by a foreach iteration on line 1227. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
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

1240
		if (! empty($conf->global->MAIN_UMASK)) /** @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...
1241
1242
		return $pagecount;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $pagecount seems to be defined by a foreach iteration on line 1227. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
1243
	}
1244
	
1245
	/**
1246
	 * Méthode pour savoir si une ligne fait partie d'un bloc Compris/Non Compris
1247
	 * 
1248
	 * @param PropaleLigne|OrderLine|FactureLigne	$line
1249
	 * @return	true or false
1250
	 */
1251
	public static function hasNcTitle(&$line)
1252
	{
1253
		if(isset($line->has_nc_title)) return $line->has_nc_title;
1254
1255
		$TTitle = self::getAllTitleFromLine($line);
1256
		foreach ($TTitle as &$line_title)
1257
		{
1258
			if (!empty($line_title->array_options['options_subtotal_nc']))
1259
			{
1260
				$line->has_nc_title = true;
1261
				return true;
1262
			}
1263
		}
1264
		
1265
		$line->has_nc_title = false;
1266
		return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type true.
Loading history...
1267
	}
1268
	
1269
	/**
1270
	 * Méthode pour récupérer le titre de la ligne
1271
	 * 
1272
	 * @param PropaleLigne|OrderLine|FactureLigne	$line
1273
	 * @return	string
1274
	 */
1275
	public static function getTitleLabel($line)
1276
	{
1277
		$title = $line->label;
1278
		if (empty($title)) $title = !empty($line->description) ? $line->description : $line->desc;
1279
		return $title;
1280
	}
1281
}
1282