Completed
Push — master ( d40ffe...95e549 )
by Alexis
14s queued 11s
created

ActionsSubtotal::pdf_getlinetotalexcltax()   F

Complexity

Conditions 25
Paths 240

Size

Total Lines 96
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 14
Bugs 3 Features 0
Metric Value
cc 25
eloc 46
c 14
b 3
f 0
nc 240
nop 3
dl 0
loc 96
rs 3.7013

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
class ActionsSubtotal
3
{
4
	
5
	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...
6
	{
7
		global $langs;
8
		
9
		$this->db = $db;
0 ignored issues
show
Bug Best Practice introduced by
The property db does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
10
		$langs->load('subtotal@subtotal');
11
		
12
		$this->allow_move_block_lines = true;
0 ignored issues
show
Bug Best Practice introduced by
The property allow_move_block_lines does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
13
	}
14
	
15
	
16
	function createDictionaryFieldlist($parameters, &$object, &$action, $hookmanager)
0 ignored issues
show
Unused Code introduced by
The parameter $action 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

16
	function createDictionaryFieldlist($parameters, &$object, /** @scrutinizer ignore-unused */ &$action, $hookmanager)

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...
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 $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

16
	function createDictionaryFieldlist($parameters, /** @scrutinizer ignore-unused */ &$object, &$action, $hookmanager)

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 $hookmanager 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

16
	function createDictionaryFieldlist($parameters, &$object, &$action, /** @scrutinizer ignore-unused */ $hookmanager)

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...
17
	{
18
		global $conf;
19
		
20
		if ($parameters['tabname'] == MAIN_DB_PREFIX.'c_subtotal_free_text' && empty($conf->global->FCKEDITOR_ENABLE_DETAILS))
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...
21
		{
22
			// Le CKEditor est forcé sur la page dictionnaire, pas possible de mettre une valeur custom
23
			// petit js qui supprimer le wysiwyg et affiche le textarea si la conf (FCKEDITOR_ENABLE_DETAILS) n'est pas active
24
			?>
25
			<script type="text/javascript">
26
				$(function() {
27
					CKEDITOR.on('instanceReady', function(ev) {
28
						var editor = ev.editor;
29
30
						if (editor.name == 'content') // Mon champ en bdd s'appel "content", pas le choix si je veux avoir un textarea sur une page de dictionnaire
31
						{
32
							editor.element.show();
33
							editor.destroy();
34
						}
35
					});
36
				});
37
			</script>
38
			<?php
39
		}
40
	}
41
	
42
	/** Overloading the doActions function : replacing the parent's function with the one below
43
	 * @param      $parameters  array           meta datas of the hook (context, etc...)
44
	 * @param      $object      CommonObject    the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
45
	 * @param      $action      string          current action (if set). Generally create or edit or null
46
	 * @param      $hookmanager HookManager     current hook manager
47
	 * @return     void
48
	 */
49
    
50
    var $module_number = 104777;
51
    
52
    function formObjectOptions($parameters, &$object, &$action, $hookmanager) 
0 ignored issues
show
Unused Code introduced by
The parameter $hookmanager 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

52
    function formObjectOptions($parameters, &$object, &$action, /** @scrutinizer ignore-unused */ $hookmanager) 

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...
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...
53
    {
54
      	global $langs,$db,$user, $conf;
55
		
56
		$langs->load('subtotal@subtotal');
57
		
58
		$contexts = explode(':',$parameters['context']);
59
		
60
		if(in_array('ordercard',$contexts) || in_array('ordersuppliercard',$contexts) || in_array('propalcard',$contexts) || in_array('supplier_proposalcard',$contexts) || in_array('invoicecard',$contexts) || in_array('invoicesuppliercard',$contexts) || in_array('invoicereccard',$contexts)) {
61
			
62
			$createRight = $user->rights->{$object->element}->creer;
63
			if($object->element == 'facturerec' )
64
			{
65
				$object->statut = 0; // hack for facture rec
66
				$createRight = $user->rights->facture->creer;
67
			} elseif($object->element == 'order_supplier' )
68
			{
69
			    $createRight = $user->rights->fournisseur->commande->creer;
70
			} elseif($object->element == 'invoice_supplier' )
71
			{
72
			    $createRight = $user->rights->fournisseur->facture->creer;
73
			}
74
			
75
			if ($object->statut == 0  && $createRight) {
76
			
77
78
				if($object->element=='facture')$idvar = 'facid';
79
				else $idvar='id';
80
				
81
				if(in_array($action, array('add_title_line', 'add_total_line', 'add_subtitle_line', 'add_subtotal_line', 'add_free_text')) )
82
				{
83
					$level = GETPOST('level', 'int'); //New avec SUBTOTAL_USE_NEW_FORMAT
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

83
					$level = /** @scrutinizer ignore-call */ GETPOST('level', 'int'); //New avec SUBTOTAL_USE_NEW_FORMAT
Loading history...
84
					
85
					if($action=='add_title_line') {
86
						$title = GETPOST('title');
87
						if(empty($title)) $title = $langs->trans('title');
88
						$qty = $level<1 ? 1 : $level ;
89
					}
90
					else if($action=='add_free_text') {
91
						$title = GETPOST('title');
92
93
						if (empty($title)) {
94
							$free_text = GETPOST('free_text', 'int');
95
							if (!empty($free_text)) {
96
								$TFreeText = getTFreeText();
97
								if (!empty($TFreeText[$free_text])) {
98
									$title = $TFreeText[$free_text]->content;
99
								}
100
							}
101
						}
102
						if(empty($title)) $title = $langs->trans('subtotalAddLineDescription');
103
						$qty = 50;
104
					}
105
					else if($action=='add_subtitle_line') {
106
						$title = GETPOST('title');
107
						if(empty($title)) $title = $langs->trans('subtitle');
108
						$qty = 2;
109
					}
110
					else if($action=='add_subtotal_line') {
111
						$title = $langs->trans('SubSubTotal');
112
						$qty = 98;
113
					}
114
					else {
115
						$title = GETPOST('title') ? GETPOST('title') : $langs->trans('SubTotal');
116
						$qty = $level ? 100-$level : 99;
117
					}
118
					dol_include_once('/subtotal/class/subtotal.class.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

118
					/** @scrutinizer ignore-call */ 
119
     dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
119
					
120
					if (!empty($conf->global->SUBTOTAL_AUTO_ADD_SUBTOTAL_ON_ADDING_NEW_TITLE) && $qty < 10) TSubtotal::addSubtotalMissing($object, $qty);
121
					
122
	    			TSubtotal::addSubTotalLine($object, $title, $qty);
123
				}
124
				else if($action==='ask_deleteallline') {
125
						$form=new Form($db);
0 ignored issues
show
Bug introduced by
The type Form 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
						
127
						$lineid = GETPOST('lineid','integer');
128
						$TIdForGroup = $this->getArrayOfLineForAGroup($object, $lineid);
129
					
130
						$nbLines = count($TIdForGroup);
131
					
132
						$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('deleteWithAllLines'), $langs->trans('ConfirmDeleteAllThisLines',$nbLines), 'confirm_delete_all_lines','',0,1);
133
						print $formconfirm;
134
				}
135
136
				if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE))
137
				{
138
					$this->showSelectTitleToAdd($object);
139
				}
140
141
				
142
				if($action!='editline') {
143
					// New format is for 3.8
144
					$this->printNewFormat($object, $conf, $langs, $idvar);
145
				}
146
			}
147
		}
148
		elseif ((!empty($parameters['currentcontext']) && $parameters['currentcontext'] == 'orderstoinvoice') || in_array('orderstoinvoice',$contexts))
149
		{
150
			?>
151
			<script type="text/javascript">
152
				$(function() {
153
					var tr = $("<tr><td><?php echo $langs->trans('subtotal_add_title_bloc_from_orderstoinvoice'); ?></td><td><input type='checkbox' value='1' name='subtotal_add_title_bloc_from_orderstoinvoice' checked='checked' /></td></tr>")
154
					$("textarea[name=note]").closest('tr').after(tr);
155
				});
156
			</script>
157
			<?php
158
			
159
		}
160
161
		return 0;
162
	}
163
     
164
	function printNewFormat(&$object, &$conf, &$langs, $idvar)
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...
165
	{
166
		if (empty($conf->global->SUBTOTAL_ALLOW_ADD_BLOCK)) return false;
167
		if (!empty($object->situation_cycle_ref) && $object->situation_counter > 1) return false; // Si facture de situation
168
		?>
169
		 	<script type="text/javascript">
170
				$(document).ready(function() {
171
					$('div.fiche div.tabsAction').append('<br />');
172
					
173
					$('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_title_line" rel="add_title_line" href="javascript:;" class="butAction"><?php echo  $langs->trans('AddTitle' )?></a></div>');
174
					$('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_total_line" rel="add_total_line" href="javascript:;" class="butAction"><?php echo  $langs->trans('AddSubTotal')?></a></div>');
175
					$('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_free_text" rel="add_free_text" href="javascript:;" class="butAction"><?php echo  $langs->trans('AddFreeText')?></a></div>');
176
177
178
					function updateAllMessageForms(){
179
				         for (instance in CKEDITOR.instances) {
180
				             CKEDITOR.instances[instance].updateElement();
181
				         }
182
				    }
183
					
184
					function promptSubTotal(action, titleDialog, label, url_to, url_ajax, params, use_textarea, show_free_text, show_under_title) {
185
					     $( "#dialog-prompt-subtotal" ).remove();
186
						 
187
						 var dialog_html = '<div id="dialog-prompt-subtotal" '+(action == 'addSubtotal' ? 'class="center"' : '')+' >';
188
						 
189
						 if (typeof show_under_title != 'undefined' && show_under_title)
190
						 {
191
							 var selectUnderTitle = <?php echo json_encode(getHtmlSelectTitle($object, true)); ?>;
192
							 dialog_html += selectUnderTitle + '<br /><br />';
193
						 }
194
						
195
						if (action == 'addTitle' || action == 'addFreeTxt')
196
						{
197
							if (typeof show_free_text != 'undefined' && show_free_text)
198
							{
199
							   var selectFreeText = <?php echo json_encode(getHtmlSelectFreeText()); ?>;
200
							   dialog_html += selectFreeText + ' <?php echo $langs->transnoentities('subtotalFreeTextOrDesc'); ?><br />';
201
							}
202
						 
203
							if (typeof use_textarea != 'undefined' && use_textarea) dialog_html += '<textarea id="sub-total-title" rows="<?php echo ROWS_8; ?>" cols="80" placeholder="'+label+'"></textarea>';
0 ignored issues
show
Bug introduced by
The constant ROWS_8 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
204
							else dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />';
205
						}
206
						 
207
						if (action == 'addTitle' || action == 'addSubtotal')
208
						{
209
							if (action == 'addSubtotal') dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />';
210
							
211
							dialog_html += "&nbsp;<select name='subtotal_line_level'>";
212
							for (var i=1;i<10;i++)
213
							{
214
								dialog_html += "<option value="+i+"><?php echo $langs->trans('Level'); ?> "+i+"</option>";
215
							}
216
							dialog_html += "</select>";
217
						}
218
						 
219
						 dialog_html += '</div>';
220
					    
221
						$('body').append(dialog_html);
222
223
						<?php 
224
						$editorTool = empty($conf->global->FCKEDITOR_EDITORNAME)?'ckeditor':$conf->global->FCKEDITOR_EDITORNAME;
225
						$editorConf = empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?false:$conf->global->FCKEDITOR_ENABLE_DETAILS;
226
						if($editorConf && in_array($editorTool,array('textarea','ckeditor'))){ 
227
						?>
228
						if (action == 'addTitle' || action == 'addFreeTxt')
229
						{
230
							if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" )
231
							{
232
								 CKEDITOR.replace( 'sub-total-title', {toolbar: 'dolibarr_details', toolbarStartupExpanded: false} );
233
							}
234
						}
235
						<?php } ?>
236
						
237
					     $( "#dialog-prompt-subtotal" ).dialog({
238
	                        resizable: false,
239
							height: 'auto',
240
							width: 'auto',
241
	                        modal: true,
242
	                        title: titleDialog,
243
	                        buttons: {
244
	                            "Ok": function() {
245
	                            	if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" ){ updateAllMessageForms(); }
246
									params.title = params.title = (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && "sub-total-title" in CKEDITOR.instances ? CKEDITOR.instances["sub-total-title"].getData() : $(this).find('#sub-total-title').val());
247
									params.under_title = $(this).find('select[name=under_title]').val();
248
									params.free_text = $(this).find('select[name=free_text]').val();
249
									params.level = $(this).find('select[name=subtotal_line_level]').val();
250
									
251
									$.ajax({
252
										url: url_ajax
253
										,type: 'POST'
254
										,data: params
255
									}).done(function() {
256
										document.location.href=url_to;
257
									});
258
									
259
                                    $( this ).dialog( "close" );
260
	                            },
261
	                            "<?php echo $langs->trans('Cancel') ?>": function() {
262
	                                $( this ).dialog( "close" );
263
	                            }
264
	                        }
265
	                     });
266
					}
267
					
268
					$('a[rel=add_title_line]').click(function() 
269
					{
270
						promptSubTotal('addTitle'
271
							 , "<?php echo $langs->trans('YourTitleLabel') ?>"
272
							 , "<?php echo $langs->trans('title'); ?>"
273
							 , '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
274
							 , '<?php echo $_SERVER['PHP_SELF']; ?>'
275
							 , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_title_line'}
276
						);
277
					});
278
					
279
					$('a[rel=add_total_line]').click(function()
280
					{
281
						promptSubTotal('addSubtotal'
282
							, '<?php echo $langs->trans('YourSubtotalLabel') ?>'
283
							, '<?php echo $langs->trans('subtotal'); ?>'
284
							, '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
285
							, '<?php echo $_SERVER['PHP_SELF']; ?>'
286
							, {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_total_line'}
287
							/*,false,false, <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?>*/
288
						);
289
					});
290
					
291
					$('a[rel=add_free_text]').click(function() 
292
					{
293
						promptSubTotal('addFreeTxt'
294
							, "<?php echo $langs->transnoentitiesnoconv('YourTextLabel') ?>"
295
							, "<?php echo $langs->trans('subtotalAddLineDescription'); ?>"
296
							, '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
297
							, '<?php echo $_SERVER['PHP_SELF']; ?>'
298
							, {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_free_text'}
299
							, true
300
							, true
301
							, <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?>
302
						);
303
					});
304
				});
305
		 	</script>
306
		 <?php
307
	}	 
308
	 
309
	function showSelectTitleToAdd(&$object)
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...
310
	{
311
		global $langs;
312
		
313
		dol_include_once('/subtotal/class/subtotal.class.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

313
		/** @scrutinizer ignore-call */ 
314
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
314
		dol_include_once('/subtotal/lib/subtotal.lib.php');
315
		$TTitle = TSubtotal::getAllTitleFromDocument($object);
0 ignored issues
show
Unused Code introduced by
The assignment to $TTitle is dead and can be removed.
Loading history...
316
		
317
		?>
318
		<script type="text/javascript">
319
			$(function() {
320
				var add_button = $("#addline");
321
				
322
				if (add_button.length > 0)
323
				{
324
					add_button.closest('tr').prev('tr.liste_titre').children('td:last').addClass('center').text("<?php echo $langs->trans('subtotal_title_to_add_under_title'); ?>");
325
					var select_title = $(<?php echo json_encode(getHtmlSelectTitle($object)); ?>);
326
					
327
					add_button.before(select_title);
328
				}
329
			});
330
		</script>
331
		<?php
332
	}
333
	
334
	
335
	function formBuilddocOptions($parameters) {
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...
336
	/* Réponse besoin client */		
337
			
338
		global $conf, $langs, $bc;
339
			
340
		$action = GETPOST('action');	
0 ignored issues
show
Unused Code introduced by
The assignment to $action is dead and can be removed.
Loading history...
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

340
		$action = /** @scrutinizer ignore-call */ GETPOST('action');	
Loading history...
341
		$TContext = explode(':',$parameters['context']);
342
		if (
343
				in_array('invoicecard',$TContext)
344
		        || in_array('invoicesuppliercard',$TContext)
345
				|| in_array('propalcard',$TContext)
346
				|| in_array('ordercard',$TContext)
347
		        || in_array('ordersuppliercard',$TContext)
348
				|| in_array('invoicereccard',$TContext)
349
			)
350
	        {	
351
				$hideInnerLines	= isset( $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']] ) ?  $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']] : 0;
352
				$hidedetails	= isset( $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']] ) ?  $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']] : 0;
353
				$hidepricesDefaultConf = !empty($conf->global->SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED)?$conf->global->SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED:0;
354
				$hideprices= isset( $_SESSION['subtotal_hideprices_'.$parameters['modulepart']] ) ?  $_SESSION['subtotal_hideprices_'.$parameters['modulepart']] : $hidepricesDefaultConf;
355
				
356
				$var=false;
357
		     	$out.= '<tr '.$bc[$var].'>
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $out seems to be never defined.
Loading history...
358
		     			<td colspan="4" align="right">
359
		     				<label for="hideInnerLines">'.$langs->trans('HideInnerLines').'</label>
360
		     				<input type="checkbox" onclick="if($(this).is(\':checked\')) { $(\'#hidedetails\').prop(\'checked\', \'checked\')  }" id="hideInnerLines" name="hideInnerLines" value="1" '.(( $hideInnerLines ) ? 'checked="checked"' : '' ).' />
361
		     			</td>
362
		     			</tr>';
363
				
364
		     	$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always false.
Loading history...
365
		     	$out.= '<tr '.$bc[$var].'>
366
		     			<td colspan="4" align="right">
367
		     				<label for="hidedetails">'.$langs->trans('SubTotalhidedetails').'</label>
368
		     				<input type="checkbox" id="hidedetails" name="hidedetails" value="1" '.(( $hidedetails ) ? 'checked="checked"' : '' ).' />
369
		     			</td>
370
		     			</tr>';
371
		     	
372
		     	$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always true.
Loading history...
373
		     	$out.= '<tr '.$bc[$var].'>
374
		     			<td colspan="4" align="right">
375
		     				<label for="hidedetails">'.$langs->trans('SubTotalhidePrice').'</label>
376
		     				<input type="checkbox" id="hideprices" name="hideprices" value="1" '.(( $hideprices ) ? 'checked="checked"' : '' ).' />
377
		     			</td>
378
		     			</tr>';
379
		     	
380
		     	
381
				 
382
				if ( 
383
					(in_array('propalcard',$TContext) && !empty($conf->global->SUBTOTAL_PROPAL_ADD_RECAP))
384
					|| (in_array('ordercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP))
385
				    || (in_array('ordersuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP))
386
					|| (in_array('invoicecard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP))
387
				    || (in_array('invoicesuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP))
388
					|| (in_array('invoicereccard',$TContext)  && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP ))
389
				)
390
				{
391
					$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always false.
Loading history...
392
					$out.= '
393
						<tr '.$bc[$var].'>
394
							<td colspan="4" align="right">
395
								<label for="subtotal_add_recap">'.$langs->trans('subtotal_add_recap').'</label>
396
								<input type="checkbox" id="subtotal_add_recap" name="subtotal_add_recap" value="1" '.( GETPOST('subtotal_add_recap') ? 'checked="checked"' : '' ).' />
397
							</td>
398
						</tr>';
399
				}
400
				
401
				
402
				$this->resprints = $out;	
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
403
			}
404
			
405
		
406
        return 1;
407
	} 
408
	 
409
    function formEditProductOptions($parameters, &$object, &$action, $hookmanager) 
0 ignored issues
show
Unused Code introduced by
The parameter $hookmanager 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

409
    function formEditProductOptions($parameters, &$object, &$action, /** @scrutinizer ignore-unused */ $hookmanager) 

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 $action 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

409
    function formEditProductOptions($parameters, &$object, /** @scrutinizer ignore-unused */ &$action, $hookmanager) 

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...
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 $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

409
    function formEditProductOptions($parameters, /** @scrutinizer ignore-unused */ &$object, &$action, $hookmanager) 

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...
410
    {
411
		
412
    	if (in_array('invoicecard',explode(':',$parameters['context'])))
413
        {
414
        	
415
        }
416
		
417
        return 0;
418
    }
419
	
420
	function ODTSubstitutionLine(&$parameters, &$object, $action, $hookmanager) {
0 ignored issues
show
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

420
	function ODTSubstitutionLine(&$parameters, /** @scrutinizer ignore-unused */ &$object, $action, $hookmanager) {

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...
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 $hookmanager 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

420
	function ODTSubstitutionLine(&$parameters, &$object, $action, /** @scrutinizer ignore-unused */ $hookmanager) {

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...
421
		global $conf;
422
		
423
		if($action === 'builddoc') {
424
			
425
			$line = &$parameters['line'];
426
			$object = &$parameters['object'];
427
			$substitutionarray = &$parameters['substitutionarray'];
428
			
429
			if($line->product_type == 9 && $line->special_code == $this->module_number) {
430
				$substitutionarray['line_modsubtotal'] = 1;	
431
				
432
				$substitutionarray['line_price_ht']
433
					 = $substitutionarray['line_price_vat'] 
434
					 = $substitutionarray['line_price_ttc']
435
					 = $substitutionarray['line_vatrate']
436
					 = $substitutionarray['line_qty']
437
					 = $substitutionarray['line_up'] 
438
					 = '';
439
				
440
				if($line->qty>90) {
441
					$substitutionarray['line_modsubtotal_total'] = true;
442
					
443
					list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
444
					
445
					$substitutionarray['line_price_ht'] = $total;
446
					$substitutionarray['line_price_vat'] = $total_tva;
447
					$substitutionarray['line_price_ttc'] = $total_ttc;
448
				} else {
449
					$substitutionarray['line_modsubtotal_title'] = true;
450
				}
451
				
452
				
453
			}	
454
			else{
455
				$substitutionarray['line_not_modsubtotal'] = true;
456
				$substitutionarray['line_modsubtotal'] = 0;
457
			}
458
			
459
		}
460
		
461
	}
462
	
463
	function createFrom($parameters, &$object, $action, $hookmanager) {
0 ignored issues
show
Unused Code introduced by
The parameter $action 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

463
	function createFrom($parameters, &$object, /** @scrutinizer ignore-unused */ $action, $hookmanager) {

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 $hookmanager 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

463
	function createFrom($parameters, &$object, $action, /** @scrutinizer ignore-unused */ $hookmanager) {

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...
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...
464
	
465
		if (
466
				in_array('invoicecard',explode(':',$parameters['context']))
467
		        || in_array('invoicesuppliercard',explode(':',$parameters['context']))
468
				|| in_array('propalcard',explode(':',$parameters['context']))
469
		        || in_array('supplier_proposalcard',explode(':',$parameters['context']))
470
				|| in_array('ordercard',explode(':',$parameters['context']))
471
		        || in_array('ordersuppliercard',explode(':',$parameters['context']))
472
				|| in_array('invoicereccard',explode(':',$parameters['context']))
473
		) {
474
			
475
			global $db;
476
			
477
			$objFrom = $parameters['objFrom'];
478
			
479
			foreach($objFrom->lines as $k=> &$lineOld) {
480
				
481
					if($lineOld->product_type == 9 && $lineOld->info_bits > 0 ) {
482
							
483
							$line = & $object->lines[$k];
484
				
485
							$idLine = (int) ($line->id ? $line->id : $line->rowid); 
486
				
487
							$db->query("UPDATE ".MAIN_DB_PREFIX.$line->table_element."
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...
488
							SET info_bits=".(int)$lineOld->info_bits."
489
							WHERE rowid = ".$idLine."
490
							");
491
						
492
					}
493
				
494
				
495
			}
496
			
497
			
498
		}
499
		
500
	}
501
	
502
	function doActions($parameters, &$object, $action, $hookmanager)
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 $hookmanager 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

502
	function doActions($parameters, &$object, $action, /** @scrutinizer ignore-unused */ $hookmanager)

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...
503
	{
504
		global $db, $conf, $langs,$user;
505
		
506
		dol_include_once('/subtotal/class/subtotal.class.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

506
		/** @scrutinizer ignore-call */ 
507
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
507
		dol_include_once('/subtotal/lib/subtotal.lib.php');
508
		require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.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...
509
		
510
		$showBlockExtrafields = GETPOST('showBlockExtrafields');
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

510
		$showBlockExtrafields = /** @scrutinizer ignore-call */ GETPOST('showBlockExtrafields');
Loading history...
511
		
512
		if($object->element=='facture') $idvar = 'facid';
513
		else $idvar = 'id';
514
			
515
		if ($action == 'updateligne' || $action == 'updateline')
516
		{
517
			$found = false;
518
			$lineid = GETPOST('lineid', 'int');
519
			foreach ($object->lines as &$line)
520
			{
521
				
522
				if ($line->id == $lineid && TSubtotal::isModSubtotalLine($line))
523
				{
524
					$found = true;
525
					if(TSubtotal::isTitle($line) && !empty($showBlockExtrafields)) {
526
						$extrafieldsline = new ExtraFields($db);
0 ignored issues
show
Bug introduced by
The type ExtraFields 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...
527
						$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
528
						$extrafieldsline->setOptionalsFromPost($extralabelsline, $line);
529
					}
530
					_updateSubtotalLine($object, $line);
531
					_updateSubtotalBloc($object, $line);
532
					
533
					TSubtotal::generateDoc($object);
534
					break;
535
				}
536
			}
537
			
538
			if ($found)
539
			{
540
				header('Location: '.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id);
541
				exit; // Surtout ne pas laisser Dolibarr faire du traitement sur le updateligne sinon ça plante les données de la ligne
542
			}
543
		}
544
		else if($action === 'builddoc') {
545
			
546
			if (
547
				in_array('invoicecard',explode(':',$parameters['context']))
548
				|| in_array('propalcard',explode(':',$parameters['context']))
549
				|| in_array('ordercard',explode(':',$parameters['context']))
550
			    || in_array('ordersuppliercard',explode(':',$parameters['context']))
551
			    || in_array('invoicesuppliercard',explode(':',$parameters['context']))
552
			    || in_array('supplier_proposalcard',explode(':',$parameters['context']))
553
			)
554
	        {								
555
				if(in_array('invoicecard',explode(':',$parameters['context']))) {
556
					$sessname = 'subtotal_hideInnerLines_facture';	
557
					$sessname2 = 'subtotal_hidedetails_facture';
558
					$sessname3 = 'subtotal_hideprices_facture';
559
				}
560
				elseif(in_array('invoicesuppliercard',explode(':',$parameters['context']))) {
561
				    $sessname = 'subtotal_hideInnerLines_facture_fournisseur';
562
				    $sessname2 = 'subtotal_hidedetails_facture_fournisseur';
563
				    $sessname3 = 'subtotal_hideprices_facture_fournisseur';
564
				}
565
				elseif(in_array('propalcard',explode(':',$parameters['context']))) {
566
					$sessname = 'subtotal_hideInnerLines_propal';
567
					$sessname2 = 'subtotal_hidedetails_propal';	
568
					$sessname3 = 'subtotal_hideprices_propal';
569
				}
570
				elseif(in_array('supplier_proposalcard',explode(':',$parameters['context']))) {
571
				    $sessname = 'subtotal_hideInnerLines_supplier_proposal';
572
				    $sessname2 = 'subtotal_hidedetails_supplier_proposal';
573
				    $sessname3 = 'subtotal_hideprices_supplier_proposal';
574
				}
575
				elseif(in_array('ordercard',explode(':',$parameters['context']))) {
576
					$sessname = 'subtotal_hideInnerLines_commande';
577
					$sessname2 = 'subtotal_hidedetails_commande';	
578
					$sessname3 = 'subtotal_hideprices_commande';
579
				}
580
				elseif(in_array('ordersuppliercard',explode(':',$parameters['context']))) {
581
				    $sessname = 'subtotal_hideInnerLines_commande_fournisseur';
582
				    $sessname2 = 'subtotal_hidedetails_commande_fournisseur';
583
				    $sessname3 = 'subtotal_hideprices_commande_fournisseur';
584
				}
585
				else {
586
					$sessname = 'subtotal_hideInnerLines_unknown';
587
					$sessname2 = 'subtotal_hidedetails_unknown';
588
					$sessname3 = 'subtotal_hideprices_unknown';
589
				}
590
					
591
				global $hideprices;
592
				
593
				$hideInnerLines = (int)GETPOST('hideInnerLines');
594
				$_SESSION[$sessname] = $hideInnerLines;		
595
				
596
				$hidedetails= (int)GETPOST('hidedetails');
597
				$_SESSION[$sessname2] = $hidedetails;
598
				
599
				$hideprices= (int)GETPOST('hideprices');
600
				$_SESSION[$sessname3] = $hideprices;
601
				
602
				foreach($object->lines as &$line) {
603
					if ($line->product_type == 9 && $line->special_code == $this->module_number) {
604
					    
605
                        if($line->qty>=90) {
606
                            $line->modsubtotal_total = 1;
607
                        }
608
                        else{
609
                            $line->modsubtotal_title = 1;
610
                        }
611
                        
612
						$line->total_ht = $this->getTotalLineFromObject($object, $line, '');
613
					}
614
	        	}
615
	        }
616
			
617
		}
618
		else if($action === 'confirm_delete_all_lines' && GETPOST('confirm')=='yes') {
619
			
620
			$Tab = $this->getArrayOfLineForAGroup($object, GETPOST('lineid'));
621
			
622
			foreach($Tab as $idLine) {
623
				/**
624
				 * @var $object Facture
625
				 */
626
				if($object->element=='facture') $object->deleteline($idLine);
627
				/**
628
				 * @var $object Facture fournisseur
629
				 */
630
				else if($object->element=='invoice_supplier')
631
				{
632
				    $object->deleteline($idLine);
633
				}
634
				/**
635
				 * @var $object Propal
636
				 */
637
				else if($object->element=='propal') $object->deleteline($idLine);
638
				/**
639
				 * @var $object Propal Fournisseur
640
				 */
641
				else if($object->element=='supplier_proposal') $object->deleteline($idLine);
642
				/**
643
				 * @var $object Commande
644
				 */
645
				else if($object->element=='commande') 
646
				{
647
					if ((float) DOL_VERSION >= 5.0) $object->deleteline($user, $idLine);
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...
648
					else $object->deleteline($idLine);
649
				}
650
				/**
651
				 * @var $object Commande fournisseur
652
				 */
653
				else if($object->element=='order_supplier')
654
				{
655
				    $object->deleteline($idLine);
656
				}
657
				/**
658
				 * @var $object Facturerec
659
				 */
660
				else if($object->element=='facturerec') $object->deleteline($idLine);
661
			}
662
			
663
			header('location:?id='.$object->id);
664
			exit;
665
			
666
		}
667
		else if ($action == 'duplicate')
668
		{
669
			$lineid = GETPOST('lineid', 'int');
670
			$nbDuplicate = TSubtotal::duplicateLines($object, $lineid, true);
671
			
672
			if ($nbDuplicate > 0) setEventMessage($langs->trans('subtotal_duplicate_success', $nbDuplicate));
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

672
			if ($nbDuplicate > 0) /** @scrutinizer ignore-call */ setEventMessage($langs->trans('subtotal_duplicate_success', $nbDuplicate));
Loading history...
673
			elseif ($nbDuplicate == 0) setEventMessage($langs->trans('subtotal_duplicate_lineid_not_found'), 'warnings');
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $nbDuplicate of type null|integer to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
674
			else setEventMessage($langs->trans('subtotal_duplicate_error'), 'errors');
675
			
676
			header('Location: ?id='.$object->id);
677
			exit;
678
		}
679
		
680
		return 0;
681
	}
682
	
683
	function formAddObjectLine ($parameters, &$object, &$action, $hookmanager) {
0 ignored issues
show
Unused Code introduced by
The parameter $hookmanager 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

683
	function formAddObjectLine ($parameters, &$object, &$action, /** @scrutinizer ignore-unused */ $hookmanager) {

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 $action 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

683
	function formAddObjectLine ($parameters, &$object, /** @scrutinizer ignore-unused */ &$action, $hookmanager) {

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 $parameters 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

683
	function formAddObjectLine (/** @scrutinizer ignore-unused */ $parameters, &$object, &$action, $hookmanager) {

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...
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 $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

683
	function formAddObjectLine ($parameters, /** @scrutinizer ignore-unused */ &$object, &$action, $hookmanager) {

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...
684
		return 0;
685
	}
686
687
	function getArrayOfLineForAGroup(&$object, $lineid) {
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...
688
		$rang = $line->rang;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $line does not exist. Did you maybe mean $lineid?
Loading history...
Unused Code introduced by
The assignment to $rang is dead and can be removed.
Loading history...
689
		$qty_line = $line->qty;
0 ignored issues
show
Unused Code introduced by
The assignment to $qty_line is dead and can be removed.
Loading history...
690
		
691
		$qty_line = 0;
692
		
693
		$found = false;
694
695
		$Tab= array();
696
		
697
		foreach($object->lines as $l) {
698
		
699
		    $lid = (!empty($l->rowid) ? $l->rowid : $l->id);
700
			if($lid == $lineid) {
701
702
				$found = true;
703
				$qty_line = $l->qty;
704
			}
705
			
706
			if($found) {
707
				
708
			    $Tab[] = (!empty($l->rowid) ? $l->rowid : $l->id);
709
				
710
				if($l->special_code==$this->module_number && (($l->qty==99 && $qty_line==1) || ($l->qty==98 && $qty_line==2))   ) {
711
					break; // end of story
712
				}
713
			}
714
			
715
			
716
		}
717
		
718
		
719
		return $Tab;
720
		
721
	}
722
723
	/**
724
	 *  TODO le calcul est faux dans certains cas,  exemple :
725
	 *	T1
726
	 *		|_ l1 => 50 €
727
	 *		|_ l2 => 40 €
728
	 *		|_ T2
729
	 *			|_l3 => 100 €
730
	 *		|_ ST2
731
	 *		|_ l4 => 23 €
732
	 *	|_ ST1
733
	 * 
734
	 * On obtiens ST2 = 100 ET ST1 = 123 €
735
	 * Alors qu'on devrais avoir ST2 = 100 ET ST1 = 213 €
736
	 * 
737
	 * @param	$use_level		isn't used anymore
0 ignored issues
show
Documentation Bug introduced by
The doc comment isn't at position 0 could not be parsed: Unknown type name 'isn't' at position 0 in isn't.
Loading history...
738
	 */
739
	function getTotalLineFromObject(&$object, &$line, $use_level=false, $return_all=0) {
0 ignored issues
show
Unused Code introduced by
The parameter $use_level 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

739
	function getTotalLineFromObject(&$object, &$line, /** @scrutinizer ignore-unused */ $use_level=false, $return_all=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...
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...
740
		
741
		$rang = $line->rang;
742
		$qty_line = $line->qty;
743
		
744
		$total = 0;
745
		$total_tva = 0;
746
		$total_ttc = 0;
747
		$TTotal_tva = array();
748
		
749
		dol_include_once('/subtotal/class/subtotal.class.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

749
		/** @scrutinizer ignore-call */ 
750
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
750
		foreach($object->lines as $l) {
751
			//print $l->rang.'>='.$rang.' '.$total.'<br/>';
752
			if($l->rang>=$rang) {
753
				//echo 'return!<br>';
754
				if (!$return_all) return $total;
755
				else return array($total, $total_tva, $total_ttc, $TTotal_tva);
756
			}
757
			else if(TSubtotal::isTitle($l, 100 - $qty_line)) 
758
		  	{
759
				$total = 0;
760
				$total_tva = 0;
761
				$total_ttc = 0;
762
				$TTotal_tva = array();
763
			}
764
			elseif(!TSubtotal::isTitle($l) && !TSubtotal::isSubtotal($l)) {
765
				$total += $l->total_ht;
766
				$total_tva += $l->total_tva;
767
				$TTotal_tva[$l->tva_tx] += $l->total_tva;
768
				$total_ttc += $l->total_ttc;
769
			}
770
			
771
		}
772
		if (!$return_all) return $total;
773
		else return array($total, $total_tva, $total_ttc, $TTotal_tva);
774
	}
775
776
	/*
777
	 * Get the sum of situation invoice for last column
778
	 */
779
	function getTotalToPrintSituation(&$object, &$line) {
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...
780
		
781
		$rang = $line->rang;
782
		$total = 0;
783
		foreach($object->lines as $l) {
784
			if($l->rang>=$rang) {
785
				return price($total);
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

785
				return /** @scrutinizer ignore-call */ price($total);
Loading history...
786
			}
787
                        if (TSubtotal::isSubtotal($l)){
788
                            $total = 0;
789
                        } else  if ($l->situation_percent > 0 ){
790
                           
791
        	
792
		 	$prev_progress = $l->get_prev_progress($object->id);
793
		 	$progress = ($l->situation_percent - $prev_progress) /100;
794
                        $total += ($l->total_ht/($l->situation_percent/100)) * $progress;
795
                        
796
                    }
797
                }
798
                
799
		return price($total);
800
	}
801
802
	/**
803
	 * @param $pdf          TCPDF               PDF object
0 ignored issues
show
Bug introduced by
The type TCPDF 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...
804
	 * @param $object       CommonObject        dolibarr object
0 ignored issues
show
Bug introduced by
The type CommonObject 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...
805
	 * @param $line         CommonObjectLine    dolibarr object line
0 ignored issues
show
Bug introduced by
The type CommonObjectLine 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...
806
	 * @param $label        string
807
	 * @param $description  string
808
	 * @param $posx         float               horizontal position
809
	 * @param $posy         float               vertical position
810
	 * @param $w            float               width
811
	 * @param $h            float               height
812
	 */
813
	function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) {
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 $description 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

813
	function pdf_add_total(&$pdf,&$object, &$line, $label, /** @scrutinizer ignore-unused */ $description,$posx, $posy, $w, $h) {

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...
814
		global $conf,$subtotal_last_title_posy;
815
		
816
		$hideInnerLines = (int)GETPOST('hideInnerLines');
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

816
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
817
		if (!empty($conf->global->SUBTOTAL_ONE_LINE_IF_HIDE_INNERLINES) && $hideInnerLines && !empty($subtotal_last_title_posy))
818
		{
819
			$posy = $subtotal_last_title_posy;
820
			$subtotal_last_title_posy = null;
821
		}
822
		
823
		$hidePriceOnSubtotalLines = (int) GETPOST('hide_price_on_subtotal_lines');
824
		
825
		$set_pagebreak_margin = false;
826
		if(method_exists('Closure','bind')) {
827
			$pageBreakOriginalValue = $pdf->AcceptPageBreak();
828
			$sweetsThief = function ($pdf) {
829
		    		return $pdf->bMargin ;
830
			};
831
			$sweetsThief = Closure::bind($sweetsThief, null, $pdf);
832
	
833
			$bMargin  = $sweetsThief($pdf);
834
	
835
			$pdf->SetAutoPageBreak( false );
836
837
			$set_pagebreak_margin = true;			
838
		}
839
		
840
			
841
		if($line->qty==99)
842
			$pdf->SetFillColor(220,220,220);
843
		elseif ($line->qty==98)
844
			$pdf->SetFillColor(230,230,230);
845
		else
846
			$pdf->SetFillColor(240,240,240);
847
		
848
		$style = 'B';
849
		if (!empty($conf->global->SUBTOTAL_SUBTOTAL_STYLE)) $style = $conf->global->SUBTOTAL_SUBTOTAL_STYLE;
850
		
851
		$pdf->SetFont('', $style, 9);
852
		
853
		$pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'R',true);
854
//		var_dump($bMargin);
855
		$pageAfter = $pdf->getPage();
0 ignored issues
show
Unused Code introduced by
The assignment to $pageAfter is dead and can be removed.
Loading history...
856
		
857
		//Print background
858
		$cell_height = $pdf->getStringHeight($w, $label);
859
		$pdf->SetXY($posx, $posy);
860
		$pdf->MultiCell($pdf->page_largeur - $pdf->marge_droite, $cell_height, '', 0, '', 1);
861
		
862
		if (!$hidePriceOnSubtotalLines) {
863
			$total_to_print = price($line->total);
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

863
			$total_to_print = /** @scrutinizer ignore-call */ price($line->total);
Loading history...
864
			
865
			if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS))
866
			{
867
				$TTitle = TSubtotal::getAllTitleFromLine($line);
868
				foreach ($TTitle as &$line_title)
869
				{
870
					if (!empty($line_title->array_options['options_subtotal_nc']))
871
					{
872
						$total_to_print = ''; // TODO Gestion "Compris/Non compris", voir si on affiche une annotation du genre "NC"
873
						break;
874
					}
875
				}
876
			}
877
			
878
			if($total_to_print) {
879
				
880
				if (GETPOST('hideInnerLines'))
881
				{
882
					// Dans le cas des lignes cachés, le calcul est déjà fait dans la méthode beforePDFCreation et les lignes de sous-totaux sont déjà renseignés
883
//					$line->TTotal_tva
884
//					$line->total_ht
885
//					$line->total_tva
886
//					$line->total
887
//					$line->total_ttc
888
				}
889
				else
890
				{
891
					list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
892
                                        if(get_class($object) == 'Facture' && $object->type==Facture::TYPE_SITUATION){//Facture de situation
0 ignored issues
show
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...
893
                                                $total_to_print = $this->getTotalToPrintSituation($object, $line);
894
                                        } else {
895
                                            	$total_to_print = price($total);
896
                                        }
897
                                            
898
					$line->total_ht = $total;
899
					$line->total = $total;
900
					$line->total_tva = $total_tva;
901
					$line->total_ttc = $total_ttc;
902
				}
903
			}
904
905
			$pdf->SetXY($pdf->postotalht, $posy);
906
			if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $bMargin does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $pageBreakOriginalValue does not seem to be defined for all execution paths leading up to this point.
Loading history...
907
			$pdf->MultiCell($pdf->page_largeur-$pdf->marge_droite-$pdf->postotalht, 3, $total_to_print, 0, 'R', 0);
908
		}
909
		else{
910
			if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin);
911
		}
912
		
913
		$posy = $posy + $cell_height;
914
		$pdf->SetXY($posx, $posy); 
915
			
916
		
917
	}
918
919
	/**
920
	 * @param $pdf          TCPDF               PDF object
921
	 * @param $object       CommonObject        dolibarr object
922
	 * @param $line         CommonObjectLine    dolibarr object line
923
	 * @param $label        string
924
	 * @param $description  string
925
	 * @param $posx         float               horizontal position
926
	 * @param $posy         float               vertical position
927
	 * @param $w            float               width
928
	 * @param $h            float               height
929
	 */
930
	function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) {
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 $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

930
	function pdf_add_title(&$pdf,/** @scrutinizer ignore-unused */ &$object, &$line, $label, $description,$posx, $posy, $w, $h) {

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...
931
		
932
		global $db,$conf,$subtotal_last_title_posy;
933
		
934
		$subtotal_last_title_posy = $posy;
935
		$pdf->SetXY ($posx, $posy);
936
		
937
		$hideInnerLines = (int)GETPOST('hideInnerLines');
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

937
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
938
		
939
		
940
 
941
		$style = ($line->qty==1) ? 'BU' : 'BUI';
942
		if (!empty($conf->global->SUBTOTAL_TITLE_STYLE)) $style = $conf->global->SUBTOTAL_TITLE_STYLE;
943
		
944
		if($hideInnerLines) {
945
			if($line->qty==1)$pdf->SetFont('', $style, 9);
946
			else 
947
			{
948
				if (!empty($conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES)) $style = $conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES;
949
				$pdf->SetFont('', $style, 9);
950
			}
951
		}
952
		else {
953
954
			if($line->qty==1)$pdf->SetFont('', $style, 9); //TODO if super utile
955
			else $pdf->SetFont('', $style, 9);
956
			
957
		}
958
		
959
		if ($label === strip_tags($label) && $label === dol_html_entity_decode($label, ENT_QUOTES)) $pdf->MultiCell($w, $h, $label, 0, 'L'); // Pas de HTML dans la chaine
0 ignored issues
show
Bug introduced by
The function dol_html_entity_decode 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

959
		if ($label === strip_tags($label) && $label === /** @scrutinizer ignore-call */ dol_html_entity_decode($label, ENT_QUOTES)) $pdf->MultiCell($w, $h, $label, 0, 'L'); // Pas de HTML dans la chaine
Loading history...
960
		else $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'J',true); // et maintenant avec du HTML
961
		
962
		if($description && !$hidedesc) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $hidedesc seems to be never defined.
Loading history...
963
			$posy = $pdf->GetY();
964
			
965
			$pdf->SetFont('', '', 8);
966
			
967
			$pdf->writeHTMLCell($w, $h, $posx, $posy, $description, 0, 1, false, true, 'J',true);
968
969
		}
970
		
971
	}
972
973
	function pdf_writelinedesc_ref($parameters=array(), &$object, &$action='') {
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...
974
	// ultimate PDF hook O_o
975
		
976
		return $this->pdf_writelinedesc($parameters,$object,$action);
977
		
978
	}
979
980
	function isModSubtotalLine(&$parameters, &$object) {
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...
981
		
982
		if(is_array($parameters)) {
983
			$i = & $parameters['i'];	
984
		}
985
		else {
986
			$i = (int)$parameters;
987
		}
988
		
989
		
990
		if($object->lines[$i]->special_code == $this->module_number && $object->lines[$i]->product_type == 9) {
991
			return true;
992
		}
993
		
994
		return false;
995
		
996
	}
997
998
	function pdf_getlineqty($parameters=array(), &$object, &$action='') {
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 $action 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

998
	function pdf_getlineqty($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action='') {

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...
999
		global $conf,$hideprices;
1000
		
1001
		if($this->isModSubtotalLine($parameters,$object) ){
1002
			
1003
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1004
			
1005
			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...
1006
				return '';
1007
			}
1008
			else if((float)DOL_VERSION>=3.8) {
1009
				return 1;
1010
			}
1011
			
1012
		}
1013
		elseif(!empty($hideprices)) {
1014
			$this->resprints = $object->lines[$parameters['i']]->qty;
1015
			return 1;
1016
		}
1017
		elseif (!empty($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY))
1018
		{
1019
			$hideInnerLines = (int)GETPOST('hideInnerLines');
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

1019
			$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1020
			$hidedetails = (int)GETPOST('hidedetails');
1021
			if (empty($hideInnerLines) && !empty($hidedetails))
1022
			{
1023
				$this->resprints = $object->lines[$parameters['i']]->qty;
1024
			}
1025
		}
1026
		
1027
		if(is_array($parameters)) $i = & $parameters['i'];
1028
		else $i = (int)$parameters;
1029
1030
		if (empty($object->lines[$i])) return 0; // hideInnerLines => override $object->lines et Dolibarr ne nous permet pas de mettre à jour la variable qui conditionne la boucle sur les lignes (PR faite pour 6.0)
1031
		
1032
		if(empty($object->lines[$i]->array_options)) $object->lines[$i]->fetch_optionals();
1033
1034
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1035
		{
1036
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1037
			{
1038
				$this->resprints = ' ';
1039
				return 1;
1040
			}
1041
		}
1042
		
1043
		return 0;
1044
	}
1045
	
1046
	function pdf_getlinetotalexcltax($parameters=array(), &$object, &$action='') {
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...
1047
	    global $conf, $hideprices, $hookmanager;
1048
		
1049
		if($this->isModSubtotalLine($parameters,$object) ){
1050
			
1051
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1052
			
1053
			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...
1054
				return '';
1055
			}
1056
			else if((float)DOL_VERSION>=3.8) {
1057
				return 1;
1058
			}
1059
			
1060
		}
1061
		elseif (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS))
1062
		{
1063
			if(is_array($parameters)) $i = & $parameters['i'];
1064
			else $i = (int)$parameters;
1065
			
1066
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1067
			{
1068
				if (!empty($object->lines[$i]->array_options['options_subtotal_nc'])) 
1069
				{
1070
					$this->resprints = ' ';
1071
					return 1;
1072
				}
1073
1074
				$TTitle = TSubtotal::getAllTitleFromLine($object->lines[$i]);
1075
				foreach ($TTitle as &$line_title)
1076
				{
1077
					if (!empty($line_title->array_options['options_subtotal_nc']))
1078
					{
1079
						$this->resprints = ' ';
1080
						return 1;
1081
					}
1082
				}
1083
			}
1084
		}
1085
		if ((int)GETPOST('hideInnerLines') && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)){
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

1085
		if ((int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines') && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)){
Loading history...
1086
		    if(is_array($parameters)) $i = & $parameters['i'];
1087
		    else $i = (int)$parameters;
1088
		    $this->resprints = price($object->lines[$i]->total_ht);
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

1088
		    $this->resprints = /** @scrutinizer ignore-call */ price($object->lines[$i]->total_ht);
Loading history...
1089
		}
1090
		if (!empty($hideprices)
1091
		    || (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $i does not seem to be defined for all execution paths leading up to this point.
Loading history...
1092
		    )
1093
		{
1094
		    if (!empty($hideprices))
1095
		    {
1096
		        
1097
		        if(is_array($parameters)) $i = & $parameters['i'];
1098
		        else $i = (int)$parameters;
1099
		        
1100
		        // Check if a title exist for this line && if the title have subtotal
1101
		        $lineTitle = TSubtotal::getParentTitleOfLine($object, $i);
1102
		        if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, $lineTitle, true))
0 ignored issues
show
Bug introduced by
It seems like $lineTitle can also be of type false; however, parameter $title_line of TSubtotal::titleHasTotalLine() does only seem to accept OrderLine|PropaleLigne|FactureLigne, 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

1102
		        if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, /** @scrutinizer ignore-type */ $lineTitle, true))
Loading history...
1103
		        {
1104
		            
1105
		            $this->resprints = ' ';
1106
		            
1107
		            $reshook=$hookmanager->executeHooks('subtotalHidePrices',$parameters,$object,$action);
1108
		            
1109
		            if ($reshook < 0)
1110
		            {
1111
		                setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
0 ignored issues
show
Bug introduced by
The function setEventMessages 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

1111
		                /** @scrutinizer ignore-call */ 
1112
                  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
Loading history...
1112
		                return -1;
1113
		            }
1114
		            elseif (empty($reshook))
1115
		            {
1116
		                $this->resprints .= $hookmanager->resprints;
1117
		            }
1118
		            else
1119
		            {
1120
		                $this->resprints = $hookmanager->resprints;
1121
		                
1122
		                // override return (use  $this->results['overrideReturn'] or $this->resArray['overrideReturn'] in other module action_xxxx.class.php )
1123
		                if(isset($hookmanager->resArray['overrideReturn']))
1124
		                {
1125
		                    return $hookmanager->resArray['overrideReturn'];
1126
		                }
1127
		            }
1128
		            
1129
		            return 1;
1130
		            
1131
		            
1132
		        }
1133
		    }
1134
		    elseif (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1135
		    {
1136
		        $this->resprints = ' ';
1137
		        return 1;
1138
		    }
1139
		}
1140
        
1141
		return 0;
1142
	}
1143
	
1144
	function pdf_getlinetotalwithtax($parameters=array(), &$object, &$action='') {
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 $action 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

1144
	function pdf_getlinetotalwithtax($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action='') {

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...
1145
		global $conf;
1146
		
1147
		if($this->isModSubtotalLine($parameters,$object) ){
1148
			
1149
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1150
		
1151
			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...
1152
				return '';
1153
			}
1154
			else if((float)DOL_VERSION>=3.8) {
1155
				return 1;
1156
			}
1157
		}
1158
		
1159
		if(is_array($parameters)) $i = & $parameters['i'];
1160
		else $i = (int)$parameters;
1161
		
1162
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) 
1163
		{
1164
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1165
			{
1166
				$this->resprints = ' ';
1167
				return 1;
1168
			}
1169
		}
1170
		
1171
		return 0;
1172
	}
1173
	
1174
	function pdf_getlineunit($parameters=array(), &$object, &$action='') {
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 $action 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

1174
	function pdf_getlineunit($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action='') {

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...
1175
		global $conf;
1176
		
1177
		if($this->isModSubtotalLine($parameters,$object) ){
1178
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1179
		
1180
			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...
1181
				return '';
1182
			}
1183
			else if((float)DOL_VERSION>=3.8) {
1184
				return 1;
1185
			}
1186
		}
1187
		
1188
		if(is_array($parameters)) $i = & $parameters['i'];
1189
		else $i = (int)$parameters;
1190
			
1191
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1192
		{
1193
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1194
			{
1195
				$this->resprints = ' ';
1196
				return 1;
1197
			}
1198
		}
1199
		
1200
		return 0;
1201
	}
1202
	
1203
	function pdf_getlineupexcltax($parameters=array(), &$object, &$action='') {
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 $action 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

1203
	function pdf_getlineupexcltax($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action='') {

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...
1204
		global $conf,$hideprices;
1205
1206
		if($this->isModSubtotalLine($parameters,$object) ){
1207
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1208
		
1209
			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...
1210
				return '';
1211
			}
1212
			else if((float)DOL_VERSION>=3.8) {
1213
				return 1;
1214
			}
1215
		}
1216
		if(is_array($parameters)) $i = & $parameters['i'];
1217
		else $i = (int)$parameters;
1218
		
1219
		if (!empty($hideprices) 
1220
				|| (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1221
		)
1222
		{
1223
			if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1224
			{
1225
				$this->resprints = ' ';
1226
				return 1;
1227
			}
1228
		}
1229
		
1230
		return 0;
1231
	}
1232
	
1233
	function pdf_getlineupwithtax($parameters=array(), &$object, &$action='') {
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 $action 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

1233
	function pdf_getlineupwithtax($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action='') {

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...
1234
		global $conf,$hideprices;
1235
		
1236
		if($this->isModSubtotalLine($parameters,$object) ){
1237
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1238
			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...
1239
				return '';
1240
			}
1241
			else if((float)DOL_VERSION>=3.8) {
1242
				return 1;
1243
			}
1244
		}
1245
		
1246
		if(is_array($parameters)) $i = & $parameters['i'];
1247
		else $i = (int)$parameters;
1248
			
1249
		if (!empty($hideprices)
1250
				|| (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1251
		)
1252
		{
1253
			if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1254
			{
1255
				$this->resprints = ' ';
1256
				return 1;
1257
			}
1258
		}
1259
		
1260
		return 0;
1261
	}
1262
	
1263
	function pdf_getlinevatrate($parameters=array(), &$object, &$action='') {
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 $action 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

1263
	function pdf_getlinevatrate($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action='') {

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...
1264
		global $conf;
1265
		
1266
		if($this->isModSubtotalLine($parameters,$object) ){
1267
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1268
			
1269
			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...
1270
				return '';
1271
			}
1272
			else if((float)DOL_VERSION>=3.8) {
1273
				return 1;
1274
			}
1275
		}
1276
		
1277
		if(is_array($parameters)) $i = & $parameters['i'];
1278
		else $i = (int)$parameters;
1279
		
1280
		if (empty($object->lines[$i])) return 0; // hideInnerLines => override $object->lines et Dolibarr ne nous permet pas de mettre à jour la variable qui conditionne la boucle sur les lignes (PR faite pour 6.0)
1281
1282
		$object->lines[$i]->fetch_optionals();
1283
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1284
		{
1285
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1286
			{
1287
				$this->resprints = ' ';
1288
				return 1;
1289
			}
1290
		}
1291
		
1292
		return 0;
1293
	}
1294
		
1295
	function pdf_getlineprogress($parameters=array(), &$object, &$action) {
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 $action 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

1295
	function pdf_getlineprogress($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action) {

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...
1296
		global $conf;
1297
		
1298
		if($this->isModSubtotalLine($parameters,$object) ){
1299
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1300
			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...
1301
				return '';
1302
			}
1303
			else if((float)DOL_VERSION>=3.8) {
1304
				return 1;
1305
			}
1306
		}
1307
		
1308
		if(is_array($parameters)) $i = & $parameters['i'];
1309
		else $i = (int)$parameters;
1310
			
1311
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1312
		{
1313
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1314
			{
1315
				$this->resprints = ' ';
1316
				return 1;
1317
			}
1318
		}
1319
		
1320
		return 0;
1321
	}
1322
	
1323
	function add_numerotation(&$object) {
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...
1324
		global $conf;
1325
		
1326
		if(!empty($conf->global->SUBTOTAL_USE_NUMEROTATION)) {
1327
		
1328
			$TLevelTitre = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $TLevelTitre is dead and can be removed.
Loading history...
1329
			$prevlevel = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $prevlevel is dead and can be removed.
Loading history...
1330
		
1331
			foreach($object->lines as $k=>&$line) 
1332
			{
1333
				if ($line->id > 0 && $this->isModSubtotalLine($k, $object) && $line->qty <= 10)
1334
				{
1335
					$TLineTitle[] = &$line;
1336
				}
1337
			}
1338
			
1339
			if (!empty($TLineTitle)) $TTitleNumeroted = $this->formatNumerotation($TLineTitle);
0 ignored issues
show
Unused Code introduced by
The assignment to $TTitleNumeroted is dead and can be removed.
Loading history...
1340
		}
1341
		
1342
	}
1343
1344
	// TODO ne gère pas encore la numération des lignes "Totaux"
1345
	private function formatNumerotation(&$TLineTitle, $line_reference='', $level=1, $prefix_num=0)
1346
	{
1347
		$TTitle = array();
1348
		
1349
		$i=1;
1350
		$j=0;
1351
		foreach ($TLineTitle as $k => &$line)
1352
		{
1353
			if (!empty($line_reference) && $line->rang <= $line_reference->rang) continue;
1354
			if (!empty($line_reference) && $line->qty <= $line_reference->qty) break;
1355
			
1356
			if ($line->qty == $level)
1357
			{
1358
				$TTitle[$j]['numerotation'] = ($prefix_num == 0) ? $i : $prefix_num.'.'.$i;
1359
				//var_dump('Prefix == '.$prefix_num.' // '.$line->desc.' ==> numerotation == '.$TTitle[$j]['numerotation'].'   ###    '.$line->qty .'=='. $level);
1360
				if (empty($line->label) && (float)DOL_VERSION < 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...
1361
				{
1362
					$line->label = !empty($line->desc) ? $line->desc : $line->description;
1363
					$line->desc = $line->description = '';
1364
				}
1365
				
1366
				$line->label = $TTitle[$j]['numerotation'].' '.$line->label;
1367
				$TTitle[$j]['line'] = &$line;
1368
				
1369
				$deep_level = $line->qty;
1370
				do {
1371
					$deep_level++;
1372
					$TTitle[$j]['children'] = $this->formatNumerotation($TLineTitle, $line, $deep_level, $TTitle[$j]['numerotation']);
1373
				} while (empty($TTitle[$j]['children']) && $deep_level <= 10); // Exemple si un bloc Titre lvl 1 contient pas de sous lvl 2 mais directement un sous lvl 5
1374
				// Rappel on peux avoir jusqu'a 10 niveau de titre
1375
				
1376
				$i++;
1377
				$j++;
1378
			}
1379
		}
1380
1381
		return $TTitle;
1382
	}
1383
	
1384
	function setDocTVA(&$pdf, &$object) {
0 ignored issues
show
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

1384
	function setDocTVA(&$pdf, /** @scrutinizer ignore-unused */ &$object) {

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

1384
	function setDocTVA(/** @scrutinizer ignore-unused */ &$pdf, &$object) {

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...
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...
1385
		
1386
		$hidedetails = (int)GETPOST('hidedetails');
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

1386
		$hidedetails = (int)/** @scrutinizer ignore-call */ GETPOST('hidedetails');
Loading history...
1387
		
1388
		if(empty($hidedetails)) return false;
1389
		
1390
		// TODO can't add VAT to document without lines... :-/
1391
		
1392
		return true;
1393
	}
1394
	
1395
	function beforePDFCreation($parameters=array(), &$object, &$action)
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 $action 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

1395
	function beforePDFCreation($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action)

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...
1396
	{
1397
		/**
1398
		 * @var $pdf    TCPDF
1399
		 */
1400
		global $pdf,$conf, $langs;
1401
1402
		// var_dump($object->lines);
1403
		dol_include_once('/subtotal/class/subtotal.class.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

1403
		/** @scrutinizer ignore-call */ 
1404
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
1404
1405
		foreach($parameters as $key=>$value) {
1406
			${$key} = $value;
1407
		}
1408
		
1409
		$this->setDocTVA($pdf, $object);
1410
		
1411
		$this->add_numerotation($object);	
1412
		
1413
		
1414
		$hideInnerLines = (int)GETPOST('hideInnerLines');
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

1414
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1415
		$hidedetails = (int)GETPOST('hidedetails');
1416
		
1417
		if ($hideInnerLines) { // si c une ligne de titre
1418
	    	$fk_parent_line=0;
0 ignored issues
show
Unused Code introduced by
The assignment to $fk_parent_line is dead and can be removed.
Loading history...
1419
			$TLines =array();
1420
		
1421
			$original_count=count($object->lines);
0 ignored issues
show
Unused Code introduced by
The assignment to $original_count is dead and can be removed.
Loading history...
1422
		    $TTvas = array(); // tableau de tva
1423
		    
1424
			foreach($object->lines as $k=>&$line) 
1425
			{
1426
			    
1427
				if($line->product_type==9 && $line->rowid>0) 
1428
				{
1429
					$fk_parent_line = $line->rowid;
1430
					
1431
					// Fix tk7201 - si on cache le détail, la TVA est renseigné au niveau du sous-total, l'erreur c'est s'il y a plusieurs sous-totaux pour les même lignes, ça va faire la somme
1432
					if(TSubtotal::isSubtotal($line)) 
1433
					{
1434
						/*$total = $this->getTotalLineFromObject($object, $line, '');
1435
						
1436
						$line->total_ht = $total;
1437
						$line->total = $total;
1438
						*/
1439
						list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
1440
						
1441
						if (TSubtotal::getNiveau($line) == 1) $line->TTotal_tva = $TTotal_tva;
1442
						$line->total_ht = $total;
1443
						$line->total_tva = $total_tva;
1444
						$line->total = $line->total_ht;
1445
						$line->total_ttc = $total_ttc;
1446
					} 
1447
						
1448
				} 
1449
			
1450
				if ($hideInnerLines)
1451
				{
1452
				    if(!empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES))
1453
				    {
1454
				        if($line->tva_tx != '0.000' && $line->product_type!=9){
1455
				            
1456
    				        // on remplit le tableau de tva pour substituer les lignes cachées
1457
    				        $TTvas[$line->tva_tx]['total_tva'] += $line->total_tva;
1458
    				        $TTvas[$line->tva_tx]['total_ht'] += $line->total_ht;
1459
    				        $TTvas[$line->tva_tx]['total_ttc'] += $line->total_ttc; 
1460
    				    }
1461
    					if($line->product_type==9 && $line->rowid>0)
1462
    					{
1463
    					    //Cas où je doit cacher les produits et afficher uniquement les sous-totaux avec les titres
1464
    					    // génère des lignes d'affichage des montants HT soumis à tva
1465
    					    $nbtva = count($TTvas);
1466
    					    if(!empty($nbtva)){
1467
    					        foreach ($TTvas as $tx =>$val){
1468
    					            $l = clone $line;
1469
    					            $l->product_type = 1;
1470
    					            $l->special_code = '';
1471
    					            $l->qty = 1;
1472
    					            $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx));
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

1472
    					            $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), /** @scrutinizer ignore-call */ price($tx));
Loading history...
1473
    					            $l->tva_tx = $tx;
1474
    					            $l->total_ht = $val['total_ht'];
1475
    					            $l->total_tva = $val['total_tva'];
1476
    					            $l->total = $line->total_ht;
1477
    					            $l->total_ttc = $val['total_ttc'];
1478
    					            $TLines[] = $l;
1479
    					            array_shift($TTvas);
1480
    					       }
1481
    					    }
1482
    					    
1483
    					    // ajoute la ligne de sous-total
1484
    					    $TLines[] = $line; 
1485
    					}
1486
				    } else {
1487
				        
1488
				        if($line->product_type==9 && $line->rowid>0)
1489
				        {
1490
				            // ajoute la ligne de sous-total
1491
				            $TLines[] = $line; 
1492
				        }
1493
				    }
1494
				    
1495
					
1496
				}
1497
				elseif ($hidedetails)
1498
				{
1499
					$TLines[] = $line; //Cas où je cache uniquement les prix des produits	
1500
				}
1501
				
1502
				if ($line->product_type != 9) { // jusqu'au prochain titre ou total
1503
					//$line->fk_parent_line = $fk_parent_line;
1504
					
1505
				}
1506
			
1507
				/*if($hideTotal) {
1508
					$line->total = 0;
1509
					$line->subprice= 0;
1510
				}*/
1511
				
1512
			}
1513
			
1514
			// cas incongru où il y aurait des produits en dessous du dernier sous-total
1515
			$nbtva = count($TTvas);
1516
			if(!empty($nbtva) && $hideInnerLines && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES))
1517
			{
1518
			    foreach ($TTvas as $tx =>$val){
1519
			        $l = clone $line;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $line seems to be defined by a foreach iteration on line 1424. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
1520
			        $l->product_type = 1;
1521
			        $l->special_code = '';
1522
			        $l->qty = 1;
1523
			        $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx));
1524
			        $l->tva_tx = $tx;
1525
			        $l->total_ht = $val['total_ht'];
1526
			        $l->total_tva = $val['total_tva'];
1527
			        $l->total = $line->total_ht;
1528
			        $l->total_ttc = $val['total_ttc'];
1529
			        $TLines[] = $l;
1530
			        array_shift($TTvas);
1531
			    }
1532
			}
1533
			
1534
			global $nblignes;
1535
			$nblignes=count($TLines);
1536
1537
			$object->lines = $TLines;
1538
			
1539
			if($i>count($object->lines)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $i seems to be never defined.
Loading history...
1540
				$this->resprints = '';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1541
				return 0;
1542
			}
1543
	    }
1544
		
1545
		return 0;
1546
	}
1547
1548
	function pdf_writelinedesc($parameters=array(), &$object, &$action)
0 ignored issues
show
Unused Code introduced by
The parameter $action 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

1548
	function pdf_writelinedesc($parameters=array(), &$object, /** @scrutinizer ignore-unused */ &$action)

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...
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...
1549
	{
1550
		/**
1551
		 * @var $pdf    TCPDF
1552
		 */
1553
		global $pdf,$conf;
1554
1555
		foreach($parameters as $key=>$value) {
1556
			${$key} = $value;
1557
		}
1558
		
1559
		$hideInnerLines = (int)GETPOST('hideInnerLines');
0 ignored issues
show
Unused Code introduced by
The assignment to $hideInnerLines is dead and can be removed.
Loading history...
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

1559
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1560
		$hidedetails = (int)GETPOST('hidedetails');
0 ignored issues
show
Unused Code introduced by
The assignment to $hidedetails is dead and can be removed.
Loading history...
1561
		
1562
		if($this->isModSubtotalLine($parameters,$object) ){			
1563
		
1564
				global $hideprices;
1565
				
1566
				if(!empty($hideprices)) {
1567
					foreach($object->lines as &$line) {
1568
						if($line->fk_product_type!=9) $line->fk_parent_line = -1;	
1569
					}
1570
				}
1571
			
1572
				$line = &$object->lines[$i];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $i seems to be never defined.
Loading history...
1573
				
1574
				if($line->info_bits>0) { // PAGE BREAK
1575
					$pdf->addPage();
1576
					$posy = $pdf->GetY();
1577
				}
1578
				
1579
				$label = $line->label;
1580
				$description= !empty($line->desc) ? $outputlangs->convToOutputCharset($line->desc) : $outputlangs->convToOutputCharset($line->description);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $outputlangs seems to be never defined.
Loading history...
1581
				
1582
				if(empty($label)) {
1583
					$label = $description;
1584
					$description='';
1585
				}
1586
				
1587
				if($line->qty>90) {
1588
					
1589
					if ($conf->global->SUBTOTAL_USE_NEW_FORMAT)	$label .= ' '.$this->getTitle($object, $line);
1590
					
1591
					$pageBefore = $pdf->getPage();
1592
					$this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $posy does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $w seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $h seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $posx seems to be never defined.
Loading history...
1593
					$pageAfter = $pdf->getPage();	
1594
1595
					if($pageAfter>$pageBefore) {
1596
						//print "ST $pageAfter>$pageBefore<br>";
1597
						$pdf->rollbackTransaction(true);	
1598
						$pdf->addPage('','', true);
1599
						$posy = $pdf->GetY();
1600
						$this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
1601
						$posy = $pdf->GetY();
0 ignored issues
show
Unused Code introduced by
The assignment to $posy is dead and can be removed.
Loading history...
1602
						//print 'add ST'.$pdf->getPage().'<br />';
1603
					}
1604
				
1605
					$posy = $pdf->GetY();
1606
					return 1;
1607
				}	
1608
				else if ($line->qty < 10) {
1609
					$pageBefore = $pdf->getPage();
0 ignored issues
show
Unused Code introduced by
The assignment to $pageBefore is dead and can be removed.
Loading history...
1610
1611
					$this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); 
1612
					$pageAfter = $pdf->getPage();	
0 ignored issues
show
Unused Code introduced by
The assignment to $pageAfter is dead and can be removed.
Loading history...
1613
1614
					
1615
					/*if($pageAfter>$pageBefore) {
1616
						print "T $pageAfter>$pageBefore<br>";
1617
						$pdf->rollbackTransaction(true);
1618
						$pdf->addPage('','', true);
1619
						print 'add T'.$pdf->getPage().' '.$line->rowid.' '.$pdf->GetY().' '.$posy.'<br />';
1620
						
1621
						$posy = $pdf->GetY();
1622
						$this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
1623
						$posy = $pdf->GetY();
1624
					}
1625
				*/
1626
					$posy = $pdf->GetY();
1627
					return 1;
1628
				}
1629
//	if($line->rowid==47) exit;
1630
			
1631
			return 0;
1632
		}
1633
		elseif (empty($object->lines[$parameters['i']]))
1634
		{
1635
			$this->resprints = -1;
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1636
		}
1637
1638
		/* TODO je desactive parce que je comprends pas PH Style, mais à test
1639
		else {
1640
			
1641
			if($hideInnerLines) {
1642
				$pdf->rollbackTransaction(true);
1643
			}
1644
			else {
1645
				$labelproductservice=pdf_getlinedesc($object, $i, $outputlangs, $hideref, $hidedesc, $issupplierline);
1646
				$pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1);
1647
			}
1648
			
1649
		}*/
1650
1651
1652
		
1653
	}
1654
1655
	/**
1656
	 * Permet de récupérer le titre lié au sous-total
1657
	 * 
1658
	 * @return string
1659
	 */
1660
	function getTitle(&$object, &$currentLine)
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...
1661
	{
1662
		$res = '';
1663
		
1664
		foreach ($object->lines as $line)
1665
		{
1666
			if ($line->id == $currentLine->id) break;
1667
			
1668
			$qty_search = 100 - $currentLine->qty;
1669
			
1670
			if ($line->product_type == 9 && $line->special_code == $this->module_number && $line->qty == $qty_search) 
1671
			{
1672
				$res = ($line->label) ? $line->label : (($line->description) ? $line->description : $line->desc);
1673
			}
1674
		}
1675
		
1676
		return $res;
1677
	}
1678
	
1679
	/**
1680
	 * @param $parameters   array
1681
	 * @param $object       CommonObject
1682
	 * @param $action       string
1683
	 * @param $hookmanager  HookManager
0 ignored issues
show
Bug introduced by
The type HookManager 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...
1684
	 * @return int
1685
	 */
1686
	function printObjectLine ($parameters, &$object, &$action, $hookmanager){
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...
1687
		
1688
		global $conf,$langs,$user,$db,$bc;
1689
		
1690
		$num = &$parameters['num'];
1691
		$line = &$parameters['line'];
1692
		$i = &$parameters['i'];
1693
		
1694
		$var = &$parameters['var'];
1695
1696
		$contexts = explode(':',$parameters['context']);
1697
1698
		$createRight = $user->rights->{$object->element}->creer;
1699
		if($object->element == 'facturerec' )
1700
		{
1701
			$object->statut = 0; // hack for facture rec
1702
			$createRight = $user->rights->facture->creer;
1703
		}
1704
		elseif($object->element == 'order_supplier' )
1705
		{
1706
		    $createRight = $user->rights->fournisseur->commande->creer;
1707
		}
1708
		elseif($object->element == 'invoice_supplier' )
1709
		{
1710
		    $createRight = $user->rights->fournisseur->facture->creer;
1711
		}
1712
		
1713
		if($line->special_code!=$this->module_number || $line->product_type!=9) {
1714
			null;
1715
		}	
1716
		else if (in_array('invoicecard',$contexts) || in_array('invoicesuppliercard',$contexts) || in_array('propalcard',$contexts) || in_array('supplier_proposalcard',$contexts) || in_array('ordercard',$contexts) || in_array('ordersuppliercard',$contexts) || in_array('invoicereccard',$contexts)) 
1717
        {
1718
			if($object->element=='facture')$idvar = 'facid';
1719
			else $idvar='id';
1720
			
1721
			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...
1722
			{
1723
				?>
1724
				<script type="text/javascript">
1725
					$(document).ready(function() {
1726
						$('#tablelines tr[rel=subtotal]').mouseleave(function() {
1727
1728
							id_line =$(this).attr('id');
1729
1730
							$(this).find('td[rel=subtotal_total]').each(function() {
1731
								$.get(document.location.href, function(data) {
1732
									var total = $(data).find('#tablelines tr#'+id_line+' td[rel=subtotal_total]').html();
1733
1734
									$('#tablelines tr#'+id_line+' td[rel=subtotal_total]').html(total);
1735
1736
								});
1737
							});
1738
						});
1739
					});
1740
1741
				</script>
1742
				<?php
1743
			}
1744
			
1745
			if(empty($line->description)) $line->description = $line->desc;
1746
			
1747
			$colspan = 5;
1748
			if($object->element == 'facturerec' ) $colspan = 3;
1749
			if($object->element == 'order_supplier') $colspan = 3;
1750
			if($object->element == 'invoice_supplier') $colspan = 4;
1751
			if($object->element == 'supplier_proposal') $colspan = 4;
1752
			if(!empty($conf->multicurrency->enabled)) $colspan+=2;
1753
			if($object->element == 'commande' && $object->statut < 3 && !empty($conf->shippableorder->enabled)) $colspan++;
1754
			if(!empty($conf->margin->enabled)) $colspan++;
1755
			if(!empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
1756
			if(!empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
1757
			if($object->element == 'facture' && !empty($conf->global->INVOICE_USE_SITUATION) && $object->type == Facture::TYPE_SITUATION) $colspan++;
1758
			if(!empty($conf->global->PRODUCT_USE_UNITS)) $colspan++;
1759
					
1760
			/* Titre */
1761
			//var_dump($line);
1762
            
1763
			// HTML 5 data for js
1764
            $data = $this->_getHtmlData($parameters, $object, $action, $hookmanager);
1765
            
1766
			
1767
			?>
1768
			<tr <?php echo $bc[$var]; $var=!$var; echo $data; ?> rel="subtotal" id="row-<?php echo $line->id ?>" style="<?php
1769
					if (!empty($conf->global->SUBTOTAL_USE_NEW_FORMAT))
1770
					{
1771
						if($line->qty==99) print 'background:#adadcf';
1772
						else if($line->qty==98) print 'background:#ddddff;';
1773
						else if($line->qty<=97 && $line->qty>=91) print 'background:#eeeeff;';
1774
						else if($line->qty==1) print 'background:#adadcf;';
1775
						else if($line->qty==2) print 'background:#ddddff;';
1776
						else if($line->qty==50) print '';
1777
						else print 'background:#eeeeff;';
1778
1779
						//A compléter si on veux plus de nuances de couleurs avec les niveau 4,5,6,7,8 et 9
1780
					}
1781
					else 
1782
					{
1783
						if($line->qty==99) print 'background:#ddffdd';
1784
						else if($line->qty==98) print 'background:#ddddff;';
1785
						else if($line->qty==2) print 'background:#eeeeff; ';
1786
						else if($line->qty==50) print '';
1787
						else print 'background:#eeffee;' ;
1788
					}
1789
1790
			?>;">
1791
			
1792
				<td colspan="<?php echo $colspan; ?>" style="<?php TSubtotal::isFreeText($line) ? '' : 'font-weight:bold;'; ?>  <?php echo ($line->qty>90)?'text-align:right':'' ?> "><?php
1793
					if($action=='editline' && GETPOST('lineid') == $line->id && TSubtotal::isModSubtotalLine($line) ) {
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

1793
					if($action=='editline' && /** @scrutinizer ignore-call */ GETPOST('lineid') == $line->id && TSubtotal::isModSubtotalLine($line) ) {
Loading history...
1794
1795
						$params=array('line'=>$line);
1796
						$reshook=$hookmanager->executeHooks('formEditProductOptions',$params,$object,$action);
0 ignored issues
show
Unused Code introduced by
The assignment to $reshook is dead and can be removed.
Loading history...
1797
						
1798
						echo '<div id="line_'.$line->id.'"></div>'; // Imitation Dolibarr
1799
						echo '<input type="hidden" value="'.$line->id.'" name="lineid">';
1800
						echo '<input id="product_type" type="hidden" value="'.$line->product_type.'" name="type">';
1801
						echo '<input id="product_id" type="hidden" value="'.$line->fk_product.'" name="type">';
1802
						echo '<input id="special_code" type="hidden" value="'.$line->special_code.'" name="type">';
1803
1804
						$isFreeText=false;
1805
						if (TSubtotal::isTitle($line))
1806
						{
1807
							$qty_displayed = $line->qty;
1808
							print img_picto('', 'subsubtotal@subtotal').'<span style="font-size:9px;margin-left:-3px;color:#0075DE;">'.$qty_displayed.'</span>&nbsp;&nbsp;';
0 ignored issues
show
Bug introduced by
The function img_picto 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

1808
							print /** @scrutinizer ignore-call */ img_picto('', 'subsubtotal@subtotal').'<span style="font-size:9px;margin-left:-3px;color:#0075DE;">'.$qty_displayed.'</span>&nbsp;&nbsp;';
Loading history...
1809
							
1810
						}
1811
						else if (TSubtotal::isSubtotal($line))
1812
						{
1813
							$qty_displayed = 100 - $line->qty;
1814
							print img_picto('', 'subsubtotal2@subtotal').'<span style="font-size:9px;margin-left:-1px;color:#0075DE;">'.$qty_displayed.'</span>&nbsp;&nbsp;';
1815
						}
1816
						else
1817
						{
1818
							$isFreeText = true;
1819
						}
1820
						
1821
						if ($object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
1822
						    $line->label = !empty($line->description) ? $line->description : $line->desc;
1823
						    $line->description = '';
1824
						}
1825
						$newlabel = $line->label;
1826
						if($line->label=='' && !$isFreeText) {
1827
							if(TSubtotal::isSubtotal($line)) {
1828
								$newlabel = $line->description.' '.$this->getTitle($object, $line);
1829
								$line->description='';
1830
							} elseif( (float)DOL_VERSION < 6 ) {
1831
								$newlabel= $line->description;
1832
								$line->description='';
1833
							}
1834
						}
1835
1836
						$readonlyForSituation = '';
1837
						if (!empty($object->situation_cycle_ref) && $object->situation_counter > 1) $readonlyForSituation = 'readonly';
1838
						
1839
						if (!$isFreeText) echo '<input type="text" name="line-title" id-line="'.$line->id.'" value="'.$newlabel.'" size="80" '.$readonlyForSituation.'/>&nbsp;';
1840
						
1841
						if (!empty($conf->global->SUBTOTAL_USE_NEW_FORMAT) && (TSubtotal::isTitle($line) || TSubtotal::isSubtotal($line)) )
1842
						{
1843
							$select = '<select name="subtotal_level">';
1844
							for ($j=1; $j<10; $j++)
1845
							{
1846
								if (!empty($readonlyForSituation)) {
1847
									if ($qty_displayed == $j) $select .= '<option selected="selected" value="'.$j.'">'.$langs->trans('Level').' '.$j.'</option>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $qty_displayed does not seem to be defined for all execution paths leading up to this point.
Loading history...
1848
								} else $select .= '<option '.($qty_displayed == $j ? 'selected="selected"' : '').' value="'.$j.'">'.$langs->trans('Level').' '.$j.'</option>';
1849
							}
1850
							$select .= '</select>&nbsp;';
1851
1852
							echo $select;
1853
						}
1854
						
1855
1856
						echo '<div class="subtotal_underline" style="margin-left:24px;">';
1857
							echo '<label for="subtotal-pagebreak">'.$langs->trans('AddBreakPageBefore').'</label> <input style="vertical-align:sub;"  type="checkbox" name="line-pagebreak" id="subtotal-pagebreak" value="8" '.(($line->info_bits > 0) ? 'checked="checked"' : '') .' />&nbsp;&nbsp;';
1858
1859
							if (TSubtotal::isTitle($line))
1860
							{
1861
								$form = new Form($db);
1862
								echo '<label for="subtotal_tva_tx">'.$form->textwithpicto($langs->trans('subtotal_apply_default_tva'), $langs->trans('subtotal_apply_default_tva_help')).'</label>';
1863
								echo '<select id="subtotal_tva_tx" name="subtotal_tva_tx" class="flat"><option selected="selected" value="">-</option>';
1864
								if (empty($readonlyForSituation)) echo str_replace('selected', '', $form->load_tva('subtotal_tva_tx', '', $parameters['seller'], $parameters['buyer'], 0, 0, '', true));
1865
								echo '</select>&nbsp;&nbsp;';
1866
								
1867
								if (!empty($conf->global->INVOICE_USE_SITUATION) && $object->element == 'facture' && $object->type == Facture::TYPE_SITUATION)
1868
								{
1869
									echo '<label for="subtotal_progress">'.$langs->trans('subtotal_apply_progress').'</label> <input id="subtotal_progress" name="subtotal_progress" value="" size="1" />%';
1870
								}
1871
							}
1872
							else if ($isFreeText) echo TSubtotal::getFreeTextHtml($line, (bool) $readonlyForSituation);
1873
						echo '</div>';
1874
1875
						if($line->qty<10) {
1876
							// WYSIWYG editor
1877
							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...
1878
							$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...
1879
							$cked_enabled = (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
1880
							if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
1881
								$nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
1882
							}
1883
							$toolbarname = 'dolibarr_details';
1884
							if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) {
1885
								$toolbarname = 'dolibarr_notes';
1886
							}
1887
							$doleditor = new DolEditor('line-description', $line->description, '', 100, $toolbarname, '',
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...
1888
								false, true, $cked_enabled, $nbrows, '98%', (bool) $readonlyForSituation);
1889
							$doleditor->Create();
1890
						}
1891
						
1892
					}
1893
					else {
1894
1895
						 if ($conf->global->SUBTOTAL_USE_NEW_FORMAT)
1896
						 {
1897
							if(TSubtotal::isTitle($line) || TSubtotal::isSubtotal($line)) 
1898
							{
1899
								echo str_repeat('&nbsp;&nbsp;&nbsp;', $line->qty-1);
1900
								
1901
								if (TSubtotal::isTitle($line)) print img_picto('', 'subtotal@subtotal').'<span style="font-size:9px;margin-left:-3px;">'.$line->qty.'</span>&nbsp;&nbsp;';
1902
								else print img_picto('', 'subtotal2@subtotal').'<span style="font-size:9px;margin-left:-1px;">'.(100-$line->qty).'</span>&nbsp;&nbsp;';
1903
							}
1904
						 }
1905
						 else 
1906
						 {
1907
							if($line->qty<=1) print img_picto('', 'subtotal@subtotal');
1908
							else if($line->qty==2) print img_picto('', 'subsubtotal@subtotal').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; 
1909
						 }
1910
						 
1911
						 
1912
						 // Get display styles and apply them
1913
						 $titleStyleItalic = strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'I') === false ? '' : ' font-style: italic;';
1914
						 $titleStyleBold =  strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'B') === false ? '' : ' font-weight:bold;';
1915
						 $titleStyleUnderline =  strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'U') === false ? '' : ' text-decoration: underline;';
1916
						 
1917
						 if (empty($line->label)) {
1918
							if ($line->qty >= 91 && $line->qty <= 99 && $conf->global->SUBTOTAL_USE_NEW_FORMAT) print  $line->description.' '.$this->getTitle($object, $line);
1919
							else print  $line->description;
1920
						 } 
1921
						 else {
1922
1923
							if (! empty($conf->global->PRODUIT_DESC_IN_FORM) && !empty($line->description)) {
1924
								print '<span class="subtotal_label" style="'.$titleStyleItalic.$titleStyleBold.$titleStyleUnderline.'" >'.$line->label.'</span><br><div class="subtotal_desc">'.dol_htmlentitiesbr($line->description).'</div>';
0 ignored issues
show
Bug introduced by
The function dol_htmlentitiesbr 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

1924
								print '<span class="subtotal_label" style="'.$titleStyleItalic.$titleStyleBold.$titleStyleUnderline.'" >'.$line->label.'</span><br><div class="subtotal_desc">'./** @scrutinizer ignore-call */ dol_htmlentitiesbr($line->description).'</div>';
Loading history...
1925
							}
1926
							else{
1927
								print '<span class="subtotal_label classfortooltip '.$titleStyleItalic.$titleStyleBold.$titleStyleUnderline.'" title="'.$line->description.'">'.$line->label.'</span>';    
1928
							}
1929
1930
						 } 
1931
						if($line->qty>90) print ' : ';
1932
						if($line->info_bits > 0) echo img_picto($langs->trans('Pagebreak'), 'pagebreak@subtotal');
1933
1934
						 
1935
1936
1937
					}
1938
			?></td>
1939
					 
1940
			<?php
1941
				if($line->qty>90) {
1942
					/* Total */
1943
					$total_line = $this->getTotalLineFromObject($object, $line, '');
1944
					echo '<td class="nowrap liencolht" align="right" style="font-weight:bold;" rel="subtotal_total">'.price($total_line).'</td>';
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

1944
					echo '<td class="nowrap liencolht" align="right" style="font-weight:bold;" rel="subtotal_total">'./** @scrutinizer ignore-call */ price($total_line).'</td>';
Loading history...
1945
				} else {
1946
					echo '<td class="liencolht movetitleblock" >&nbsp;</td>';
1947
				}	
1948
			?>
1949
					
1950
			<td align="center" class="nowrap linecoledit">
1951
				<?php
1952
				if ($action != 'selectlines') {
1953
				
1954
					if($action=='editline' && GETPOST('lineid') == $line->id && TSubtotal::isModSubtotalLine($line) ) {
1955
						?>
1956
						<input id="savelinebutton" class="button" type="submit" name="save" value="<?php echo $langs->trans('Save') ?>" />
1957
						<br />
1958
						<input class="button" type="button" name="cancelEditlinetitle" value="<?php echo $langs->trans('Cancel') ?>" />
1959
						<script type="text/javascript">
1960
							$(document).ready(function() {
1961
								$('input[name=cancelEditlinetitle]').click(function () {
1962
									document.location.href="<?php echo '?'.$idvar.'='.$object->id ?>";
1963
								});
1964
							});
1965
1966
						</script>
1967
						<?php
1968
						
1969
					}
1970
					else{
1971
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_DUPLICATE_BLOCK) && $object->element !== 'invoice_supplier')
1972
						{
1973
							if(TSubtotal::isTitle($line) && ($object->situation_counter == 1 || !$object->situation_cycle_ref) ) echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=duplicate&lineid='.$line->id.'">'. img_picto($langs->trans('Duplicate'), 'duplicate@subtotal').'</a>';
1974
						}
1975
1976
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_EDIT_BLOCK)) 
1977
						{
1978
							echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=editline&lineid='.$line->id.'">'.img_edit().'</a>';
0 ignored issues
show
Bug introduced by
The function img_edit 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

1978
							echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=editline&lineid='.$line->id.'">'./** @scrutinizer ignore-call */ img_edit().'</a>';
Loading history...
1979
						}								
1980
					}
1981
					
1982
				}
1983
					
1984
				?>
1985
			</td>
1986
1987
			<td align="center" nowrap="nowrap" class="linecoldelete">	
1988
				<?php
1989
1990
				if ($action != 'editline' && $action != 'selectlines') {
1991
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_REMOVE_BLOCK))
1992
						{
1993
1994
							if ($object->situation_counter == 1 || !$object->situation_cycle_ref)
1995
							{
1996
								echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=ask_deleteline&lineid='.$line->id.'">'.img_delete().'</a>';
0 ignored issues
show
Bug introduced by
The function img_delete 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

1996
								echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=ask_deleteline&lineid='.$line->id.'">'./** @scrutinizer ignore-call */ img_delete().'</a>';
Loading history...
1997
							}
1998
1999
							if(TSubtotal::isTitle($line) && ($object->situation_counter == 1 || !$object->situation_cycle_ref) )
2000
							{
2001
								$img_delete = ((float) DOL_VERSION >= 3.8) ? img_picto($langs->trans('deleteWithAllLines'), 'delete_all.3.8@subtotal') : img_picto($langs->trans('deleteWithAllLines'), 'delete_all@subtotal');
2002
								echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=ask_deleteallline&lineid='.$line->id.'">'.$img_delete.'</a>';
2003
							}
2004
						}
2005
					}
2006
				?>
2007
			</td>
2008
			
2009
			<?php 
2010
			if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && TSubtotal::isTitle($line) && $action != 'editline')
2011
			{
2012
				echo '<td class="subtotal_nc">';
2013
				echo '<input id="subtotal_nc-'.$line->id.'" class="subtotal_nc_chkbx" data-lineid="'.$line->id.'" type="checkbox" name="subtotal_nc" value="1" '.(!empty($line->array_options['options_subtotal_nc']) ? 'checked="checked"' : '').' />';
2014
				echo '</td>';
2015
			}
2016
			
2017
			if ($num > 1 && empty($conf->browser->phone)) { ?>
2018
			<td align="center" class="tdlineupdown">
2019
			</td>
2020
			<?php } else { ?>
2021
			<td align="center"<?php echo ((empty($conf->browser->phone) && ($object->statut == 0  && $createRight ))?' class="tdlineupdown"':''); ?>></td>
2022
			<?php } ?>
2023
2024
			<?php  if($action == 'selectlines'){ // dolibarr 8 ?>
2025
			<td class="linecolcheck" align="center"><input type="checkbox" class="linecheckbox" name="line_checkbox[<?php echo $i+1; ?>]" value="<?php echo $line->id; ?>" ></td>
2026
			<?php } ?>
2027
2028
			</tr>
2029
			<?php
2030
			
2031
			
2032
			// Affichage des extrafields à la Dolibarr (car sinon non affiché sur les titres)
2033
			if(TSubtotal::isTitle($line) && !empty($conf->global->SUBTOTAL_ALLOW_EXTRAFIELDS_ON_TITLE)) {
2034
				
2035
				require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
2036
				
2037
				// Extrafields
2038
				$extrafieldsline = new ExtraFields($db);
2039
				$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
0 ignored issues
show
Unused Code introduced by
The assignment to $extralabelsline is dead and can be removed.
Loading history...
2040
				
2041
				$colspan+=3; $mode = 'view';
2042
				if($action === 'editline' && $line->rowid == GETPOST('lineid')) $mode = 'edit';
2043
				
2044
				$ex_element = $line->element;
2045
				$line->element = 'tr_extrafield_title '.$line->element; // Pour pouvoir manipuler ces tr
2046
				print $line->showOptionals($extrafieldsline, $mode, array('style'=>' style="background:#eeffee;" ','colspan'=>$colspan));
2047
				$isExtraSelected = false;
2048
				foreach($line->array_options as $option) {
2049
					if(!empty($option) && $option != "-1") {
2050
						$isExtraSelected = true;
2051
						break;
2052
					}
2053
				}
2054
				
2055
				if($mode === 'edit') {
2056
					?>
2057
					<script>
2058
						$(document).ready(function(){
2059
2060
							var all_tr_extrafields = $("tr.tr_extrafield_title");
2061
							<?php 
2062
							// Si un extrafield est rempli alors on affiche directement les extrafields
2063
							if(!$isExtraSelected) {
2064
								echo 'all_tr_extrafields.hide();';
2065
								echo 'var trad = "'.$langs->trans('showExtrafields').'";';
2066
								echo 'var extra = 0;';
2067
							} else {
2068
								echo 'all_tr_extrafields.show();';
2069
								echo 'var trad = "'.$langs->trans('hideExtrafields').'";';
2070
								echo 'var extra = 1;';
2071
							}
2072
							?>
2073
							
2074
							$("div .subtotal_underline").append(
2075
									'<a id="printBlocExtrafields" onclick="return false;" href="#">' + trad + '</a>'
2076
									+ '<input type="hidden" name="showBlockExtrafields" id="showBlockExtrafields" value="'+ extra +'" />');
2077
2078
							$(document).on('click', "#printBlocExtrafields", function() {
2079
								var btnShowBlock = $("#showBlockExtrafields");
2080
								var val = btnShowBlock.val();
2081
								if(val == '0') {
2082
									btnShowBlock.val('1');
2083
									$("#printBlocExtrafields").html("<?php print $langs->trans('hideExtrafields'); ?>");
2084
									$(all_tr_extrafields).show();
2085
								} else {
2086
									btnShowBlock.val('0');
2087
									$("#printBlocExtrafields").html("<?php print $langs->trans('showExtrafields'); ?>");
2088
									$(all_tr_extrafields).hide();
2089
								}
2090
							});
2091
						});
2092
					</script>
2093
					<?php
2094
				}
2095
				$line->element = $ex_element;
2096
				
2097
			}
2098
			
2099
			return 1;	
2100
			
2101
		}
2102
		
2103
		return 0;
2104
2105
	}
2106
2107
	
2108
	function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager) {
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 $hookmanager 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

2108
	function addMoreActionsButtons($parameters, &$object, &$action, /** @scrutinizer ignore-unused */ $hookmanager) {

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 $parameters 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

2108
	function addMoreActionsButtons(/** @scrutinizer ignore-unused */ $parameters, &$object, &$action, $hookmanager) {

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...
2109
		global $conf,$langs;
2110
		 
2111
		if ($object->statut == 0 && !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && $action != 'editline')
2112
		{
2113
		    
2114
		    if($object->element == 'invoice_supplier' || $object->element == 'order_supplier')
2115
		    {
2116
		        foreach ($object->lines as $line)
2117
		        {
2118
		            // fetch optionals attributes and labels
2119
		            require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.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...
2120
		            $extrafields=new ExtraFields($this->db);
2121
		            $extralabels=$extrafields->fetch_name_optionals_label($object->table_element_line,true);
2122
		            $line->fetch_optionals($line->id,$extralabels);
2123
		        }
2124
		    }
2125
		    
2126
			$TSubNc = array();
2127
			foreach ($object->lines as &$l)
2128
			{
2129
				$TSubNc[$l->id] = (int) $l->array_options['options_subtotal_nc'];
2130
			}
2131
			
2132
			$form = new Form($db);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $db seems to be never defined.
Loading history...
2133
			?>
2134
			<script type="text/javascript">
2135
				$(function() {
2136
					var subtotal_TSubNc = <?php echo json_encode($TSubNc); ?>;
2137
					$("#tablelines tbody > tr").each(function(i, item) {
2138
						if ($(item).children('.subtotal_nc').length == 0)
2139
						{
2140
							var id = $(item).attr('id');
2141
							
2142
							if ((typeof id != 'undefined' && id.indexOf('row-') >= 0) || $(item).hasClass('liste_titre'))
2143
							{
2144
								$(item).children('td:last-child').before('<td class="subtotal_nc"></td>');
2145
								
2146
								if ($(item).attr('rel') != 'subtotal' && typeof $(item).attr('id') != 'undefined')
2147
								{
2148
									var idSplit = $(item).attr('id').split('-');
2149
									$(item).children('td.subtotal_nc').append($('<input type="checkbox" id="subtotal_nc-'+idSplit[1]+'" class="subtotal_nc_chkbx" data-lineid="'+idSplit[1]+'" value="1" '+(typeof subtotal_TSubNc[idSplit[1]] != 'undefined' && subtotal_TSubNc[idSplit[1]] == 1 ? 'checked="checked"' : '')+' />'));
2150
								}
2151
							}
2152
							else 
2153
							{
2154
								$(item).append('<td class="subtotal_nc"></td>');
2155
							}
2156
						}
2157
					});
2158
					
2159
					$('#tablelines tbody tr.liste_titre:first .subtotal_nc').html(<?php echo json_encode($form->textwithtooltip($langs->trans('subtotal_nc_title'), $langs->trans('subtotal_nc_title_help'))); ?>);
2160
					
2161
					function callAjaxUpdateLineNC(set, lineid, subtotal_nc)
2162
					{
2163
						$.ajax({
2164
							url: '<?php echo dol_buildpath('/subtotal/script/interface.php', 1); ?>'
0 ignored issues
show
Bug introduced by
The function dol_buildpath 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

2164
							url: '<?php echo /** @scrutinizer ignore-call */ dol_buildpath('/subtotal/script/interface.php', 1); ?>'
Loading history...
2165
							,type: 'POST'
2166
							,data: {
2167
								json:1
2168
								,set: set
2169
								,element: '<?php echo $object->element; ?>'
2170
								,elementid: <?php echo (int) $object->id; ?>
2171
								,lineid: lineid
2172
								,subtotal_nc: subtotal_nc
2173
							}
2174
						}).done(function(response) {
2175
							window.location.href = window.location.pathname + '?id=<?php echo $object->id; ?>&page_y=' + window.pageYOffset;
2176
						});
2177
					}
2178
					
2179
					$(".subtotal_nc_chkbx").change(function(event) {
2180
						var lineid = $(this).data('lineid');
2181
						var subtotal_nc = 0 | $(this).is(':checked'); // Renvoi 0 ou 1 
2182
						
2183
						callAjaxUpdateLineNC('updateLineNC', lineid, subtotal_nc);
2184
					});
2185
					
2186
				});
2187
2188
			</script>
2189
			<?php
2190
		}
2191
		
2192
		$this->_ajax_block_order_js($object);
2193
	}
2194
	
2195
	function afterPDFCreation($parameters, &$pdf, &$action, $hookmanager)
0 ignored issues
show
Unused Code introduced by
The parameter $action 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

2195
	function afterPDFCreation($parameters, &$pdf, /** @scrutinizer ignore-unused */ &$action, $hookmanager)

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 $hookmanager 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

2195
	function afterPDFCreation($parameters, &$pdf, &$action, /** @scrutinizer ignore-unused */ $hookmanager)

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...
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...
2196
	{
2197
		global $conf;
2198
		
2199
		$object = $parameters['object'];
2200
		
2201
		if ((!empty($conf->global->SUBTOTAL_PROPAL_ADD_RECAP) && $object->element == 'propal') || (!empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP) && $object->element == 'commande') || (!empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP) && $object->element == 'facture'))
2202
		{
2203
			if (GETPOST('subtotal_add_recap')) {
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

2203
			if (/** @scrutinizer ignore-call */ GETPOST('subtotal_add_recap')) {
Loading history...
2204
				dol_include_once('/subtotal/class/subtotal.class.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

2204
				/** @scrutinizer ignore-call */ 
2205
    dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
2205
				TSubtotal::addRecapPage($parameters, $pdf);
2206
			}
2207
		}
2208
	}
2209
	
2210
	// HTML 5 data for js
2211
	private function _getHtmlData($parameters, &$object, &$action, $hookmanager)
2212
	{
2213
		dol_include_once('/subtotal/class/subtotal.class.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

2213
		/** @scrutinizer ignore-call */ 
2214
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
2214
2215
	    $line = &$parameters['line'];
2216
	    
2217
	    $ThtmlData['data-id']           = $line->id;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$ThtmlData was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ThtmlData = array(); before regardless.
Loading history...
2218
	    $ThtmlData['data-product_type'] = $line->product_type;
2219
	    $ThtmlData['data-qty']          = 0; //$line->qty;
2220
	    $ThtmlData['data-level']        = TSubtotal::getNiveau($line);
2221
	    
2222
	    if(TSubtotal::isTitle($line)){
2223
	        $ThtmlData['data-issubtotal'] = 'title';
2224
	    }elseif(TSubtotal::isSubtotal($line)){
2225
	        $ThtmlData['data-issubtotal'] = 'subtotal';
2226
	    }
2227
	    else{
2228
	        $ThtmlData['data-issubtotal'] = 'freetext';
2229
	    }
2230
	    
2231
	    
2232
	    // Change or add data  from hooks
2233
	    $parameters = array_replace($parameters , array(  'ThtmlData' => $ThtmlData )  );
2234
	    
2235
	    // hook 
2236
	    $reshook = $hookmanager->executeHooks('subtotalLineHtmlData',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
2237
	    if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
0 ignored issues
show
Bug introduced by
The function setEventMessages 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

2237
	    if ($reshook < 0) /** @scrutinizer ignore-call */ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
Loading history...
2238
	    if ($reshook>0)
2239
	    {
2240
	        $ThtmlData = $hookmanager->resArray;
2241
	    }
2242
2243
	    return $this->implodeHtmlData($ThtmlData);
2244
	
2245
	}
2246
	
2247
	
2248
	function implodeHtmlData($ThtmlData = array())
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...
2249
	{
2250
	    $data = '';
2251
	    foreach($ThtmlData as $k => $h )
2252
	    {
2253
	        if(is_array($h))
2254
	        {
2255
	            $h = json_encode($h);
2256
	        }
2257
	        
2258
	        $data .= $k . '="'.dol_htmlentities($h, ENT_QUOTES).'" ';
0 ignored issues
show
Bug introduced by
The function dol_htmlentities 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

2258
	        $data .= $k . '="'./** @scrutinizer ignore-call */ dol_htmlentities($h, ENT_QUOTES).'" ';
Loading history...
2259
	    }
2260
	    
2261
	    return $data;
2262
	}
2263
	
2264
	function _ajax_block_order_js($object)
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...
2265
	{
2266
	    global $conf,$tagidfortablednd,$filepath,$langs;
2267
	    
2268
	    /*
2269
	     * this part of js is base on dolibarr htdocs/core/tpl/ajaxrow.tpl.php 
2270
	     * for compatibility reasons we don't use tableDnD but jquery sortable
2271
	     */
2272
	    
2273
	    $id=$object->id;
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
2274
	    $nboflines=(isset($object->lines)?count($object->lines):0);
2275
	    $forcereloadpage=empty($conf->global->MAIN_FORCE_RELOAD_PAGE)?0:1;
0 ignored issues
show
Unused Code introduced by
The assignment to $forcereloadpage is dead and can be removed.
Loading history...
2276
	    
2277
	    $id=$object->id;
2278
	    $fk_element=$object->fk_element;
2279
	    $table_element_line=$object->table_element_line;
2280
	    $nboflines=(isset($object->lines)?count($object->lines):(empty($nboflines)?0:$nboflines));
2281
	    $tagidfortablednd=(empty($tagidfortablednd)?'tablelines':$tagidfortablednd);
2282
	    $filepath=(empty($filepath)?'':$filepath);
2283
	    
2284
	    
2285
	    if (GETPOST('action','aZ09') != 'editline' && $nboflines > 1)
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

2285
	    if (/** @scrutinizer ignore-call */ GETPOST('action','aZ09') != 'editline' && $nboflines > 1)
Loading history...
2286
	    {
2287
	        
2288
	        ?>
2289
		
2290
		
2291
			<script type="text/javascript">
2292
			$(document).ready(function(){
2293
2294
				// target some elements
2295
				var titleRow = $('tr[data-issubtotal="title"]');
2296
				var lastTitleCol = titleRow.find('td:last-child');
2297
				var moveBlockCol= titleRow.find('td.liencolht');
2298
2299
				
2300
				moveBlockCol.disableSelection(); // prevent selection
2301
<?php if ($object->statut == 0) { ?>
2302
				// apply some graphical stuff
2303
				moveBlockCol.css("background-image",'url(<?php echo dol_buildpath('subtotal/img/grip_all.png',2);  ?>)');
0 ignored issues
show
Bug introduced by
The function dol_buildpath 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

2303
				moveBlockCol.css("background-image",'url(<?php echo /** @scrutinizer ignore-call */ dol_buildpath('subtotal/img/grip_all.png',2);  ?>)');
Loading history...
2304
				moveBlockCol.css("background-repeat","no-repeat");
2305
				moveBlockCol.css("background-position","center center");
2306
				moveBlockCol.css("cursor","move");
2307
				titleRow.attr('title', '<?php echo html_entity_decode($langs->trans('MoveTitleBlock')); ?>');
2308
			
2309
2310
 				$( "#<?php echo $tagidfortablednd; ?>" ).sortable({
2311
			    	  cursor: "move",
2312
			    	  handle: ".movetitleblock",
2313
			    	  items: 'tr:not(.nodrag,.nodrop,.noblockdrop)',
2314
			    	  delay: 150, //Needed to prevent accidental drag when trying to select
2315
			    	  opacity: 0.8,
2316
			    	  axis: "y", // limit y axis
2317
			    	  placeholder: "ui-state-highlight",
2318
			    	  start: function( event, ui ) {
2319
			    	      //console.log('X:' + e.screenX, 'Y:' + e.screenY);
2320
			    		  //console.log(ui.item);
2321
			    		  var colCount = ui.item.children().length;
2322
   						  ui.placeholder.html('<td colspan="'+colCount+'">&nbsp;</td>');
2323
   		
2324
			    		  var TcurrentChilds = getSubtotalTitleChilds(ui.item);
2325
			    		  ui.item.data('childrens',TcurrentChilds); // store data
2326
				    		
2327
			    		  for (var key in TcurrentChilds) {
2328
			    			  $('#'+ TcurrentChilds[key]).addClass('noblockdrop');//'#row-'+ 
2329
			    			  $('#'+ TcurrentChilds[key]).fadeOut();//'#row-'+ 
2330
			    		  }
2331
2332
			    		  $(this).sortable("refresh");	// "refresh" of source sortable is required to make "disable" work!
2333
			    	      
2334
			    	    },
2335
				    	stop: function (event, ui) {
2336
							// call we element is droped
2337
				    	  	$('.noblockdrop').removeClass('noblockdrop');
2338
2339
				    	  	var TcurrentChilds = ui.item.data('childrens'); // reload child list from data and not attr to prevent load error
2340
2341
							for (var i =TcurrentChilds.length ; i >= 0; i--) {
2342
				    			  $('#'+ TcurrentChilds[i]).insertAfter(ui.item); //'#row-'+ 
2343
				    			  $('#'+ TcurrentChilds[i]).fadeIn(); //'#row-'+ 
2344
							}
2345
							console.log('onstop');
2346
							console.log(cleanSerialize($(this).sortable('serialize')));
2347
							
2348
							$.ajax({
2349
			    	            data: {
2350
									objet_id: <?php print $object->id; ?>,
2351
							    	roworder: cleanSerialize($(this).sortable('serialize')),
2352
									table_element_line: "<?php echo $table_element_line; ?>",
2353
									fk_element: "<?php echo $fk_element; ?>",
2354
									element_id: "<?php echo $id; ?>",
2355
									filepath: "<?php echo urlencode($filepath); ?>"
2356
								},
2357
			    	            type: 'POST',
2358
			    	            url: '<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php',
0 ignored issues
show
Bug introduced by
The constant DOL_URL_ROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
2359
			    	            success: function(data) {
2360
			    	                console.log(data);
2361
			    	            },
2362
			    	        });
2363
			    	        
2364
			    	  },
2365
			    	  update: function (event, ui) {
2366
				    	  
2367
			    	        // POST to server using $.post or $.ajax
2368
				    	  	$('.noblockdrop').removeClass('noblockdrop');
2369
							//console.log('onupdate');
2370
			    	        //console.log(cleanSerialize($(this).sortable('serialize')));
2371
			    	    }
2372
			    });
2373
 				<?php } ?>
2374
2375
				function getSubtotalTitleChilds(item)
2376
				{
2377
		    		var TcurrentChilds = []; // = JSON.parse(item.attr('data-childrens'));
2378
		    		var level = item.data('level');
2379
2380
		    		var indexOfFirstSubtotal = -1;
2381
		    		var indexOfFirstTitle = -1;
2382
		    		
2383
		    		item.nextAll('[id^="row-"]').each(function(index){
2384
2385
						var dataLevel = $(this).attr('data-level');
2386
						var dataIsSubtotal = $(this).attr('data-issubtotal');
2387
						
2388
						if(dataIsSubtotal != 'undefined' && dataLevel != 'undefined' )
2389
						{
2390
2391
							if(dataLevel <=  level && indexOfFirstSubtotal < 0 && dataIsSubtotal == 'subtotal' )
2392
							{
2393
								indexOfFirstSubtotal = index;
2394
								if(indexOfFirstTitle < 0)
2395
								{
2396
									TcurrentChilds.push($(this).attr('id'));
2397
								}
2398
							}
2399
							
2400
							if(dataLevel <=  level && indexOfFirstSubtotal < 0 && indexOfFirstTitle < 0 && dataIsSubtotal == 'title' )
2401
							{
2402
								indexOfFirstTitle = index;
2403
							}
2404
						}
2405
2406
						if(indexOfFirstTitle < 0 && indexOfFirstSubtotal < 0)
2407
						{
2408
							TcurrentChilds.push($(this).attr('id'));
2409
2410
							// Add extraffield support for dolibarr > 7
2411
							var thisId = $(this).attr('data-id');
2412
							var thisElement = $(this).attr('data-element');
2413
							if(thisId != undefined && thisElement != undefined )
2414
							{
2415
								$('[data-targetid="' + thisId + '"][data-element="extrafield"][data-targetelement="'+ thisElement +'"]').each(function(index){
2416
									TcurrentChilds.push($(this).attr('id'));
2417
								});
2418
							}
2419
							
2420
						}
2421
2422
		    		});
2423
		    		return TcurrentChilds;
2424
				}
2425
				
2426
			});
2427
			</script>
2428
			<style type="text/css" >
2429
         
2430
            tr.ui-state-highlight td{
2431
            	border: 1px solid #dad55e;
2432
            	background: #fffa90;
2433
            	color: #777620;
2434
            }
2435
            </style>
2436
		<?php
2437
		
2438
		} 
2439
	
2440
		
2441
		
2442
	}
2443
	
2444
}
2445