Completed
Push — master ( d63371...9ce9eb )
by Alexis
21s queued 19s
created

ActionsSubtotal::getArrayOfLineForAGroup()   C

Complexity

Conditions 11
Paths 21

Size

Total Lines 33
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 11
eloc 15
c 3
b 1
f 0
nc 21
nop 2
dl 0
loc 33
rs 5.2653

How to fix   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
				$hideprices= isset( $_SESSION['subtotal_hideprices_'.$parameters['modulepart']] ) ?  $_SESSION['subtotal_hideprices_'.$parameters['modulepart']] : 0;
354
				
355
				$var=false;
356
		     	$out.= '<tr '.$bc[$var].'>
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $out seems to be never defined.
Loading history...
357
		     			<td colspan="4" align="right">
358
		     				<label for="hideInnerLines">'.$langs->trans('HideInnerLines').'</label>
359
		     				<input type="checkbox" onclick="if($(this).is(\':checked\')) { $(\'#hidedetails\').prop(\'checked\', \'checked\')  }" id="hideInnerLines" name="hideInnerLines" value="1" '.(( $hideInnerLines ) ? 'checked="checked"' : '' ).' />
360
		     			</td>
361
		     			</tr>';
362
				
363
		     	$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always false.
Loading history...
364
		     	$out.= '<tr '.$bc[$var].'>
365
		     			<td colspan="4" align="right">
366
		     				<label for="hidedetails">'.$langs->trans('SubTotalhidedetails').'</label>
367
		     				<input type="checkbox" id="hidedetails" name="hidedetails" value="1" '.(( $hidedetails ) ? 'checked="checked"' : '' ).' />
368
		     			</td>
369
		     			</tr>';
370
		     	
371
		     	$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always true.
Loading history...
372
		     	$out.= '<tr '.$bc[$var].'>
373
		     			<td colspan="4" align="right">
374
		     				<label for="hidedetails">'.$langs->trans('SubTotalhidePrice').'</label>
375
		     				<input type="checkbox" id="hideprices" name="hideprices" value="1" '.(( $hideprices ) ? 'checked="checked"' : '' ).' />
376
		     			</td>
377
		     			</tr>';
378
		     	
379
		     	
380
				 
381
				if ( 
382
					(in_array('propalcard',$TContext) && !empty($conf->global->SUBTOTAL_PROPAL_ADD_RECAP))
383
					|| (in_array('ordercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP))
384
				    || (in_array('ordersuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP))
385
					|| (in_array('invoicecard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP))
386
				    || (in_array('invoicesuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP))
387
					|| (in_array('invoicereccard',$TContext)  && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP ))
388
				)
389
				{
390
					$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always false.
Loading history...
391
					$out.= '
392
						<tr '.$bc[$var].'>
393
							<td colspan="4" align="right">
394
								<label for="subtotal_add_recap">'.$langs->trans('subtotal_add_recap').'</label>
395
								<input type="checkbox" id="subtotal_add_recap" name="subtotal_add_recap" value="1" '.( GETPOST('subtotal_add_recap') ? 'checked="checked"' : '' ).' />
396
							</td>
397
						</tr>';
398
				}
399
				
400
				
401
				$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...
402
			}
403
			
404
		
405
        return 1;
406
	} 
407
	 
408
    function formEditProductOptions($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

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

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

408
    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...
409
    {
410
		
411
    	if (in_array('invoicecard',explode(':',$parameters['context'])))
412
        {
413
        	
414
        }
415
		
416
        return 0;
417
    }
418
	
419
	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

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

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

462
	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

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

501
	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...
502
	{
503
		global $db, $conf, $langs,$user;
504
		
505
		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

505
		/** @scrutinizer ignore-call */ 
506
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
506
		dol_include_once('/subtotal/lib/subtotal.lib.php');
507
		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...
508
		
509
		$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

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

671
			if ($nbDuplicate > 0) /** @scrutinizer ignore-call */ setEventMessage($langs->trans('subtotal_duplicate_success', $nbDuplicate));
Loading history...
672
			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...
673
			else setEventMessage($langs->trans('subtotal_duplicate_error'), 'errors');
674
			
675
			header('Location: ?id='.$object->id);
676
			exit;
677
		}
678
		
679
		return 0;
680
	}
681
	
682
	function formAddObjectLine ($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

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

682
	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

682
	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

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

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

Loading history...
Unused Code introduced by
The parameter $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

738
	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...
739
		
740
		$rang = $line->rang;
741
		$qty_line = $line->qty;
742
		
743
		$total = 0;
744
		$total_tva = 0;
745
		$total_ttc = 0;
746
		$TTotal_tva = array();
747
		
748
		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

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

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

812
	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...
813
		global $conf,$subtotal_last_title_posy;
814
		
815
		$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

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

862
			$total_to_print = /** @scrutinizer ignore-call */ price($line->total);
Loading history...
863
			
864
			if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS))
865
			{
866
				$TTitle = TSubtotal::getAllTitleFromLine($line);
867
				foreach ($TTitle as &$line_title)
868
				{
869
					if (!empty($line_title->array_options['options_subtotal_nc']))
870
					{
871
						$total_to_print = ''; // TODO Gestion "Compris/Non compris", voir si on affiche une annotation du genre "NC"
872
						break;
873
					}
874
				}
875
			}
876
			
877
			if($total_to_print) {
878
				
879
				if (GETPOST('hideInnerLines'))
880
				{
881
					// 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
882
//					$line->TTotal_tva
883
//					$line->total_ht
884
//					$line->total_tva
885
//					$line->total
886
//					$line->total_ttc
887
				}
888
				else
889
				{
890
					list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
891
                                        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...
892
                                                $total_to_print = $this->getTotalToPrintSituation($object, $line);
893
                                        } else {
894
                                            	$total_to_print = price($total);
895
                                        }
896
                                            
897
					$line->total_ht = $total;
898
					$line->total = $total;
899
					$line->total_tva = $total_tva;
900
					$line->total_ttc = $total_ttc;
901
				}
902
			}
903
904
			$pdf->SetXY($pdf->postotalht, $posy);
905
			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...
906
			$pdf->MultiCell($pdf->page_largeur-$pdf->marge_droite-$pdf->postotalht, 3, $total_to_print, 0, 'R', 0);
907
		}
908
		else{
909
			if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin);
910
		}
911
		
912
		$posy = $posy + $cell_height;
913
		$pdf->SetXY($posx, $posy); 
914
			
915
		
916
	}
917
918
	/**
919
	 * @param $pdf          TCPDF               PDF object
920
	 * @param $object       CommonObject        dolibarr object
921
	 * @param $line         CommonObjectLine    dolibarr object line
922
	 * @param $label        string
923
	 * @param $description  string
924
	 * @param $posx         float               horizontal position
925
	 * @param $posy         float               vertical position
926
	 * @param $w            float               width
927
	 * @param $h            float               height
928
	 */
929
	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

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

936
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
937
		
938
		
939
 
940
		$style = ($line->qty==1) ? 'BU' : 'BUI';
941
		if (!empty($conf->global->SUBTOTAL_TITLE_STYLE)) $style = $conf->global->SUBTOTAL_TITLE_STYLE;
942
		
943
		if($hideInnerLines) {
944
			if($line->qty==1)$pdf->SetFont('', $style, 9);
945
			else 
946
			{
947
				if (!empty($conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES)) $style = $conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES;
948
				$pdf->SetFont('', $style, 9);
949
			}
950
		}
951
		else {
952
953
			if($line->qty==1)$pdf->SetFont('', $style, 9); //TODO if super utile
954
			else $pdf->SetFont('', $style, 9);
955
			
956
		}
957
		
958
		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

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

997
	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...
998
		global $conf,$hideprices;
999
		
1000
		if($this->isModSubtotalLine($parameters,$object) ){
1001
			
1002
			$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...
1003
			
1004
			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...
1005
				return '';
1006
			}
1007
			else if((float)DOL_VERSION>=3.8) {
1008
				return 1;
1009
			}
1010
			
1011
		}
1012
		elseif(!empty($hideprices)) {
1013
			$this->resprints = $object->lines[$parameters['i']]->qty;
1014
			return 1;
1015
		}
1016
		elseif (!empty($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY))
1017
		{
1018
			$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

1018
			$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1019
			$hidedetails = (int)GETPOST('hidedetails');
1020
			if (empty($hideInnerLines) && !empty($hidedetails))
1021
			{
1022
				$this->resprints = $object->lines[$parameters['i']]->qty;
1023
			}
1024
		}
1025
		
1026
		if(is_array($parameters)) $i = & $parameters['i'];
1027
		else $i = (int)$parameters;
1028
1029
		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)
1030
		
1031
		if(empty($object->lines[$i]->array_options)) $object->lines[$i]->fetch_optionals();
1032
1033
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1034
		{
1035
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1036
			{
1037
				$this->resprints = ' ';
1038
				return 1;
1039
			}
1040
		}
1041
		
1042
		return 0;
1043
	}
1044
	
1045
	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...
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

1045
	function pdf_getlinetotalexcltax($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...
1046
		global $conf, $hideprices;
1047
		
1048
		if($this->isModSubtotalLine($parameters,$object) ){
1049
			
1050
			$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...
1051
			
1052
			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...
1053
				return '';
1054
			}
1055
			else if((float)DOL_VERSION>=3.8) {
1056
				return 1;
1057
			}
1058
			
1059
		}
1060
		elseif (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS))
1061
		{
1062
			if(is_array($parameters)) $i = & $parameters['i'];
1063
			else $i = (int)$parameters;
1064
			
1065
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1066
			{
1067
				if (!empty($object->lines[$i]->array_options['options_subtotal_nc'])) 
1068
				{
1069
					$this->resprints = ' ';
1070
					return 1;
1071
				}
1072
1073
				$TTitle = TSubtotal::getAllTitleFromLine($object->lines[$i]);
1074
				foreach ($TTitle as &$line_title)
1075
				{
1076
					if (!empty($line_title->array_options['options_subtotal_nc']))
1077
					{
1078
						$this->resprints = ' ';
1079
						return 1;
1080
					}
1081
				}
1082
			}
1083
		}
1084
		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

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

1087
		    $this->resprints = /** @scrutinizer ignore-call */ price($object->lines[$i]->total_ht);
Loading history...
1088
		}
1089
		if (!empty($hideprices)
1090
		    || (!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...
1091
		    )
1092
		{
1093
		    if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1094
		    {
1095
		        $this->resprints = ' ';
1096
		        return 1;
1097
		    }
1098
		}
1099
        
1100
		return 0;
1101
	}
1102
	
1103
	function pdf_getlinetotalwithtax($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

1103
	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...
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...
1104
		global $conf;
1105
		
1106
		if($this->isModSubtotalLine($parameters,$object) ){
1107
			
1108
			$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...
1109
		
1110
			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...
1111
				return '';
1112
			}
1113
			else if((float)DOL_VERSION>=3.8) {
1114
				return 1;
1115
			}
1116
		}
1117
		
1118
		if(is_array($parameters)) $i = & $parameters['i'];
1119
		else $i = (int)$parameters;
1120
		
1121
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) 
1122
		{
1123
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1124
			{
1125
				$this->resprints = ' ';
1126
				return 1;
1127
			}
1128
		}
1129
		
1130
		return 0;
1131
	}
1132
	
1133
	function pdf_getlineunit($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

1133
	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...
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...
1134
		global $conf;
1135
		
1136
		if($this->isModSubtotalLine($parameters,$object) ){
1137
			$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...
1138
		
1139
			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...
1140
				return '';
1141
			}
1142
			else if((float)DOL_VERSION>=3.8) {
1143
				return 1;
1144
			}
1145
		}
1146
		
1147
		if(is_array($parameters)) $i = & $parameters['i'];
1148
		else $i = (int)$parameters;
1149
			
1150
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1151
		{
1152
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1153
			{
1154
				$this->resprints = ' ';
1155
				return 1;
1156
			}
1157
		}
1158
		
1159
		return 0;
1160
	}
1161
	
1162
	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

1162
	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...
1163
		global $conf,$hideprices;
1164
1165
		if($this->isModSubtotalLine($parameters,$object) ){
1166
			$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...
1167
		
1168
			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...
1169
				return '';
1170
			}
1171
			else if((float)DOL_VERSION>=3.8) {
1172
				return 1;
1173
			}
1174
		}
1175
		if(is_array($parameters)) $i = & $parameters['i'];
1176
		else $i = (int)$parameters;
1177
		
1178
		if (!empty($hideprices) 
1179
				|| (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1180
		)
1181
		{
1182
			if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1183
			{
1184
				$this->resprints = ' ';
1185
				return 1;
1186
			}
1187
		}
1188
		
1189
		return 0;
1190
	}
1191
	
1192
	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

1192
	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...
1193
		global $conf,$hideprices;
1194
		
1195
		if($this->isModSubtotalLine($parameters,$object) ){
1196
			$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...
1197
			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...
1198
				return '';
1199
			}
1200
			else if((float)DOL_VERSION>=3.8) {
1201
				return 1;
1202
			}
1203
		}
1204
		
1205
		if(is_array($parameters)) $i = & $parameters['i'];
1206
		else $i = (int)$parameters;
1207
			
1208
		if (!empty($hideprices)
1209
				|| (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1210
		)
1211
		{
1212
			if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1213
			{
1214
				$this->resprints = ' ';
1215
				return 1;
1216
			}
1217
		}
1218
		
1219
		return 0;
1220
	}
1221
	
1222
	function pdf_getlinevatrate($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

1222
	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...
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...
1223
		global $conf;
1224
		
1225
		if($this->isModSubtotalLine($parameters,$object) ){
1226
			$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...
1227
			
1228
			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...
1229
				return '';
1230
			}
1231
			else if((float)DOL_VERSION>=3.8) {
1232
				return 1;
1233
			}
1234
		}
1235
		
1236
		if(is_array($parameters)) $i = & $parameters['i'];
1237
		else $i = (int)$parameters;
1238
		
1239
		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)
1240
1241
		$object->lines[$i]->fetch_optionals();
1242
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1243
		{
1244
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1245
			{
1246
				$this->resprints = ' ';
1247
				return 1;
1248
			}
1249
		}
1250
		
1251
		return 0;
1252
	}
1253
		
1254
	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

1254
	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...
1255
		global $conf;
1256
		
1257
		if($this->isModSubtotalLine($parameters,$object) ){
1258
			$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...
1259
			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...
1260
				return '';
1261
			}
1262
			else if((float)DOL_VERSION>=3.8) {
1263
				return 1;
1264
			}
1265
		}
1266
		
1267
		if(is_array($parameters)) $i = & $parameters['i'];
1268
		else $i = (int)$parameters;
1269
			
1270
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1271
		{
1272
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1273
			{
1274
				$this->resprints = ' ';
1275
				return 1;
1276
			}
1277
		}
1278
		
1279
		return 0;
1280
	}
1281
	
1282
	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...
1283
		global $conf;
1284
		
1285
		if(!empty($conf->global->SUBTOTAL_USE_NUMEROTATION)) {
1286
		
1287
			$TLevelTitre = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $TLevelTitre is dead and can be removed.
Loading history...
1288
			$prevlevel = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $prevlevel is dead and can be removed.
Loading history...
1289
		
1290
			foreach($object->lines as $k=>&$line) 
1291
			{
1292
				if ($line->id > 0 && $this->isModSubtotalLine($k, $object) && $line->qty <= 10)
1293
				{
1294
					$TLineTitle[] = &$line;
1295
				}
1296
			}
1297
			
1298
			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...
1299
		}
1300
		
1301
	}
1302
1303
	// TODO ne gère pas encore la numération des lignes "Totaux"
1304
	private function formatNumerotation(&$TLineTitle, $line_reference='', $level=1, $prefix_num=0)
1305
	{
1306
		$TTitle = array();
1307
		
1308
		$i=1;
1309
		$j=0;
1310
		foreach ($TLineTitle as $k => &$line)
1311
		{
1312
			if (!empty($line_reference) && $line->rang <= $line_reference->rang) continue;
1313
			if (!empty($line_reference) && $line->qty <= $line_reference->qty) break;
1314
			
1315
			if ($line->qty == $level)
1316
			{
1317
				$TTitle[$j]['numerotation'] = ($prefix_num == 0) ? $i : $prefix_num.'.'.$i;
1318
				//var_dump('Prefix == '.$prefix_num.' // '.$line->desc.' ==> numerotation == '.$TTitle[$j]['numerotation'].'   ###    '.$line->qty .'=='. $level);
1319
				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...
1320
				{
1321
					$line->label = !empty($line->desc) ? $line->desc : $line->description;
1322
					$line->desc = $line->description = '';
1323
				}
1324
				
1325
				$line->label = $TTitle[$j]['numerotation'].' '.$line->label;
1326
				$TTitle[$j]['line'] = &$line;
1327
				
1328
				$deep_level = $line->qty;
1329
				do {
1330
					$deep_level++;
1331
					$TTitle[$j]['children'] = $this->formatNumerotation($TLineTitle, $line, $deep_level, $TTitle[$j]['numerotation']);
1332
				} 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
1333
				// Rappel on peux avoir jusqu'a 10 niveau de titre
1334
				
1335
				$i++;
1336
				$j++;
1337
			}
1338
		}
1339
1340
		return $TTitle;
1341
	}
1342
	
1343
	function setDocTVA(&$pdf, &$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...
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

1343
	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

1343
	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...
1344
		
1345
		$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

1345
		$hidedetails = (int)/** @scrutinizer ignore-call */ GETPOST('hidedetails');
Loading history...
1346
		
1347
		if(empty($hidedetails)) return false;
1348
		
1349
		// TODO can't add VAT to document without lines... :-/
1350
		
1351
		return true;
1352
	}
1353
	
1354
	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

1354
	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...
1355
	{
1356
		/**
1357
		 * @var $pdf    TCPDF
1358
		 */
1359
		global $pdf,$conf, $langs;
1360
1361
		// var_dump($object->lines);
1362
		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

1362
		/** @scrutinizer ignore-call */ 
1363
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
1363
1364
		foreach($parameters as $key=>$value) {
1365
			${$key} = $value;
1366
		}
1367
		
1368
		$this->setDocTVA($pdf, $object);
1369
		
1370
		$this->add_numerotation($object);	
1371
		
1372
		
1373
		$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

1373
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1374
		$hidedetails = (int)GETPOST('hidedetails');
1375
		
1376
		if ($hideInnerLines) { // si c une ligne de titre
1377
	    	$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...
1378
			$TLines =array();
1379
		
1380
			$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...
1381
		    $TTvas = array(); // tableau de tva
1382
		    
1383
			foreach($object->lines as $k=>&$line) 
1384
			{
1385
			    
1386
				if($line->product_type==9 && $line->rowid>0) 
1387
				{
1388
					$fk_parent_line = $line->rowid;
1389
					
1390
					// 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
1391
					if(TSubtotal::isSubtotal($line)) 
1392
					{
1393
						/*$total = $this->getTotalLineFromObject($object, $line, '');
1394
						
1395
						$line->total_ht = $total;
1396
						$line->total = $total;
1397
						*/
1398
						list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
1399
						
1400
						if (TSubtotal::getNiveau($line) == 1) $line->TTotal_tva = $TTotal_tva;
1401
						$line->total_ht = $total;
1402
						$line->total_tva = $total_tva;
1403
						$line->total = $line->total_ht;
1404
						$line->total_ttc = $total_ttc;
1405
					} 
1406
						
1407
				} 
1408
			
1409
				if ($hideInnerLines)
1410
				{
1411
				    if(!empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES))
1412
				    {
1413
				        if($line->tva_tx != '0.000' && $line->product_type!=9){
1414
				            
1415
    				        // on remplit le tableau de tva pour substituer les lignes cachées
1416
    				        $TTvas[$line->tva_tx]['total_tva'] += $line->total_tva;
1417
    				        $TTvas[$line->tva_tx]['total_ht'] += $line->total_ht;
1418
    				        $TTvas[$line->tva_tx]['total_ttc'] += $line->total_ttc; 
1419
    				    }
1420
    					if($line->product_type==9 && $line->rowid>0)
1421
    					{
1422
    					    //Cas où je doit cacher les produits et afficher uniquement les sous-totaux avec les titres
1423
    					    // génère des lignes d'affichage des montants HT soumis à tva
1424
    					    $nbtva = count($TTvas);
1425
    					    if(!empty($nbtva)){
1426
    					        foreach ($TTvas as $tx =>$val){
1427
    					            $l = clone $line;
1428
    					            $l->product_type = 1;
1429
    					            $l->special_code = '';
1430
    					            $l->qty = 1;
1431
    					            $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

1431
    					            $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), /** @scrutinizer ignore-call */ price($tx));
Loading history...
1432
    					            $l->tva_tx = $tx;
1433
    					            $l->total_ht = $val['total_ht'];
1434
    					            $l->total_tva = $val['total_tva'];
1435
    					            $l->total = $line->total_ht;
1436
    					            $l->total_ttc = $val['total_ttc'];
1437
    					            $TLines[] = $l;
1438
    					            array_shift($TTvas);
1439
    					       }
1440
    					    }
1441
    					    
1442
    					    // ajoute la ligne de sous-total
1443
    					    $TLines[] = $line; 
1444
    					}
1445
				    } else {
1446
				        
1447
				        if($line->product_type==9 && $line->rowid>0)
1448
				        {
1449
				            // ajoute la ligne de sous-total
1450
				            $TLines[] = $line; 
1451
				        }
1452
				    }
1453
				    
1454
					
1455
				}
1456
				elseif ($hidedetails)
1457
				{
1458
					$TLines[] = $line; //Cas où je cache uniquement les prix des produits	
1459
				}
1460
				
1461
				if ($line->product_type != 9) { // jusqu'au prochain titre ou total
1462
					//$line->fk_parent_line = $fk_parent_line;
1463
					
1464
				}
1465
			
1466
				/*if($hideTotal) {
1467
					$line->total = 0;
1468
					$line->subprice= 0;
1469
				}*/
1470
				
1471
			}
1472
			
1473
			// cas incongru où il y aurait des produits en dessous du dernier sous-total
1474
			$nbtva = count($TTvas);
1475
			if(!empty($nbtva) && $hideInnerLines && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES))
1476
			{
1477
			    foreach ($TTvas as $tx =>$val){
1478
			        $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 1383. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
1479
			        $l->product_type = 1;
1480
			        $l->special_code = '';
1481
			        $l->qty = 1;
1482
			        $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx));
1483
			        $l->tva_tx = $tx;
1484
			        $l->total_ht = $val['total_ht'];
1485
			        $l->total_tva = $val['total_tva'];
1486
			        $l->total = $line->total_ht;
1487
			        $l->total_ttc = $val['total_ttc'];
1488
			        $TLines[] = $l;
1489
			        array_shift($TTvas);
1490
			    }
1491
			}
1492
			
1493
			global $nblignes;
1494
			$nblignes=count($TLines);
1495
1496
			$object->lines = $TLines;
1497
			
1498
			if($i>count($object->lines)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $i seems to be never defined.
Loading history...
1499
				$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...
1500
				return 0;
1501
			}
1502
	    }
1503
		
1504
		return 0;
1505
	}
1506
1507
	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

1507
	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...
1508
	{
1509
		/**
1510
		 * @var $pdf    TCPDF
1511
		 */
1512
		global $pdf,$conf;
1513
1514
		foreach($parameters as $key=>$value) {
1515
			${$key} = $value;
1516
		}
1517
		
1518
		$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

1518
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1519
		$hidedetails = (int)GETPOST('hidedetails');
0 ignored issues
show
Unused Code introduced by
The assignment to $hidedetails is dead and can be removed.
Loading history...
1520
		
1521
		if($this->isModSubtotalLine($parameters,$object) ){			
1522
		
1523
				global $hideprices;
1524
				
1525
				if(!empty($hideprices)) {
1526
					foreach($object->lines as &$line) {
1527
						if($line->fk_product_type!=9) $line->fk_parent_line = -1;	
1528
					}
1529
				}
1530
			
1531
				$line = &$object->lines[$i];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $i seems to be never defined.
Loading history...
1532
				
1533
				if($line->info_bits>0) { // PAGE BREAK
1534
					$pdf->addPage();
1535
					$posy = $pdf->GetY();
1536
				}
1537
				
1538
				$label = $line->label;
1539
				$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...
1540
				
1541
				if(empty($label)) {
1542
					$label = $description;
1543
					$description='';
1544
				}
1545
				
1546
				if($line->qty>90) {
1547
					
1548
					if ($conf->global->SUBTOTAL_USE_NEW_FORMAT)	$label .= ' '.$this->getTitle($object, $line);
1549
					
1550
					$pageBefore = $pdf->getPage();
1551
					$this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $h seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $w seems to be never defined.
Loading history...
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 $posx seems to be never defined.
Loading history...
1552
					$pageAfter = $pdf->getPage();	
1553
1554
					if($pageAfter>$pageBefore) {
1555
						//print "ST $pageAfter>$pageBefore<br>";
1556
						$pdf->rollbackTransaction(true);	
1557
						$pdf->addPage('','', true);
1558
						$posy = $pdf->GetY();
1559
						$this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
1560
						$posy = $pdf->GetY();
0 ignored issues
show
Unused Code introduced by
The assignment to $posy is dead and can be removed.
Loading history...
1561
						//print 'add ST'.$pdf->getPage().'<br />';
1562
					}
1563
				
1564
					$posy = $pdf->GetY();
1565
					return 1;
1566
				}	
1567
				else if ($line->qty < 10) {
1568
					$pageBefore = $pdf->getPage();
0 ignored issues
show
Unused Code introduced by
The assignment to $pageBefore is dead and can be removed.
Loading history...
1569
1570
					$this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); 
1571
					$pageAfter = $pdf->getPage();	
0 ignored issues
show
Unused Code introduced by
The assignment to $pageAfter is dead and can be removed.
Loading history...
1572
1573
					
1574
					/*if($pageAfter>$pageBefore) {
1575
						print "T $pageAfter>$pageBefore<br>";
1576
						$pdf->rollbackTransaction(true);
1577
						$pdf->addPage('','', true);
1578
						print 'add T'.$pdf->getPage().' '.$line->rowid.' '.$pdf->GetY().' '.$posy.'<br />';
1579
						
1580
						$posy = $pdf->GetY();
1581
						$this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
1582
						$posy = $pdf->GetY();
1583
					}
1584
				*/
1585
					$posy = $pdf->GetY();
1586
					return 1;
1587
				}
1588
//	if($line->rowid==47) exit;
1589
			
1590
			return 0;
1591
		}
1592
		elseif (empty($object->lines[$parameters['i']]))
1593
		{
1594
			$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...
1595
		}
1596
1597
		/* TODO je desactive parce que je comprends pas PH Style, mais à test
1598
		else {
1599
			
1600
			if($hideInnerLines) {
1601
				$pdf->rollbackTransaction(true);
1602
			}
1603
			else {
1604
				$labelproductservice=pdf_getlinedesc($object, $i, $outputlangs, $hideref, $hidedesc, $issupplierline);
1605
				$pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1);
1606
			}
1607
			
1608
		}*/
1609
1610
1611
		
1612
	}
1613
1614
	/**
1615
	 * Permet de récupérer le titre lié au sous-total
1616
	 * 
1617
	 * @return string
1618
	 */
1619
	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...
1620
	{
1621
		$res = '';
1622
		
1623
		foreach ($object->lines as $line)
1624
		{
1625
			if ($line->id == $currentLine->id) break;
1626
			
1627
			$qty_search = 100 - $currentLine->qty;
1628
			
1629
			if ($line->product_type == 9 && $line->special_code == $this->module_number && $line->qty == $qty_search) 
1630
			{
1631
				$res = ($line->label) ? $line->label : (($line->description) ? $line->description : $line->desc);
1632
			}
1633
		}
1634
		
1635
		return $res;
1636
	}
1637
	
1638
	/**
1639
	 * @param $parameters   array
1640
	 * @param $object       CommonObject
1641
	 * @param $action       string
1642
	 * @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...
1643
	 * @return int
1644
	 */
1645
	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...
1646
		
1647
		global $conf,$langs,$user,$db,$bc;
1648
		
1649
		$num = &$parameters['num'];
1650
		$line = &$parameters['line'];
1651
		$i = &$parameters['i'];
1652
		
1653
		$var = &$parameters['var'];
1654
1655
		$contexts = explode(':',$parameters['context']);
1656
1657
		$createRight = $user->rights->{$object->element}->creer;
1658
		if($object->element == 'facturerec' )
1659
		{
1660
			$object->statut = 0; // hack for facture rec
1661
			$createRight = $user->rights->facture->creer;
1662
		}
1663
		elseif($object->element == 'order_supplier' )
1664
		{
1665
		    $createRight = $user->rights->fournisseur->commande->creer;
1666
		}
1667
		elseif($object->element == 'invoice_supplier' )
1668
		{
1669
		    $createRight = $user->rights->fournisseur->facture->creer;
1670
		}
1671
		
1672
		if($line->special_code!=$this->module_number || $line->product_type!=9) {
1673
			null;
1674
		}	
1675
		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)) 
1676
        {
1677
			if($object->element=='facture')$idvar = 'facid';
1678
			else $idvar='id';
1679
			
1680
			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...
1681
			{
1682
				?>
1683
				<script type="text/javascript">
1684
					$(document).ready(function() {
1685
						$('#tablelines tr[rel=subtotal]').mouseleave(function() {
1686
1687
							id_line =$(this).attr('id');
1688
1689
							$(this).find('td[rel=subtotal_total]').each(function() {
1690
								$.get(document.location.href, function(data) {
1691
									var total = $(data).find('#tablelines tr#'+id_line+' td[rel=subtotal_total]').html();
1692
1693
									$('#tablelines tr#'+id_line+' td[rel=subtotal_total]').html(total);
1694
1695
								});
1696
							});
1697
						});
1698
					});
1699
1700
				</script>
1701
				<?php
1702
			}
1703
			
1704
			if(empty($line->description)) $line->description = $line->desc;
1705
			
1706
			$colspan = 5;
1707
			if($object->element == 'facturerec' ) $colspan = 3;
1708
			if($object->element == 'order_supplier') $colspan = 3;
1709
			if($object->element == 'invoice_supplier') $colspan = 4;
1710
			if($object->element == 'supplier_proposal') $colspan = 4;
1711
			if(!empty($conf->multicurrency->enabled)) $colspan+=2;
1712
			if($object->element == 'commande' && $object->statut < 3 && !empty($conf->shippableorder->enabled)) $colspan++;
1713
			if(!empty($conf->margin->enabled)) $colspan++;
1714
			if(!empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
1715
			if(!empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
1716
			if($object->element == 'facture' && !empty($conf->global->INVOICE_USE_SITUATION) && $object->type == Facture::TYPE_SITUATION) $colspan++;
1717
			if(!empty($conf->global->PRODUCT_USE_UNITS)) $colspan++;
1718
					
1719
			/* Titre */
1720
			//var_dump($line);
1721
            
1722
			// HTML 5 data for js
1723
            $data = $this->_getHtmlData($parameters, $object, $action, $hookmanager);
1724
            
1725
			
1726
			?>
1727
			<tr <?php echo $bc[$var]; $var=!$var; echo $data; ?> rel="subtotal" id="row-<?php echo $line->id ?>" style="<?php
1728
					if (!empty($conf->global->SUBTOTAL_USE_NEW_FORMAT))
1729
					{
1730
						if($line->qty==99) print 'background:#adadcf';
1731
						else if($line->qty==98) print 'background:#ddddff;';
1732
						else if($line->qty<=97 && $line->qty>=91) print 'background:#eeeeff;';
1733
						else if($line->qty==1) print 'background:#adadcf;';
1734
						else if($line->qty==2) print 'background:#ddddff;';
1735
						else if($line->qty==50) print '';
1736
						else print 'background:#eeeeff;';
1737
1738
						//A compléter si on veux plus de nuances de couleurs avec les niveau 4,5,6,7,8 et 9
1739
					}
1740
					else 
1741
					{
1742
						if($line->qty==99) print 'background:#ddffdd';
1743
						else if($line->qty==98) print 'background:#ddddff;';
1744
						else if($line->qty==2) print 'background:#eeeeff; ';
1745
						else if($line->qty==50) print '';
1746
						else print 'background:#eeffee;' ;
1747
					}
1748
1749
			?>;">
1750
			
1751
				<td colspan="<?php echo $colspan; ?>" style="<?php TSubtotal::isFreeText($line) ? '' : 'font-weight:bold;'; ?>  <?php echo ($line->qty>90)?'text-align:right':'' ?> "><?php
1752
					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

1752
					if($action=='editline' && /** @scrutinizer ignore-call */ GETPOST('lineid') == $line->id && TSubtotal::isModSubtotalLine($line) ) {
Loading history...
1753
1754
						$params=array('line'=>$line);
1755
						$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...
1756
						
1757
						echo '<div id="line_'.$line->id.'"></div>'; // Imitation Dolibarr
1758
						echo '<input type="hidden" value="'.$line->id.'" name="lineid">';
1759
						echo '<input id="product_type" type="hidden" value="'.$line->product_type.'" name="type">';
1760
						echo '<input id="product_id" type="hidden" value="'.$line->fk_product.'" name="type">';
1761
						echo '<input id="special_code" type="hidden" value="'.$line->special_code.'" name="type">';
1762
1763
						$isFreeText=false;
1764
						if (TSubtotal::isTitle($line))
1765
						{
1766
							$qty_displayed = $line->qty;
1767
							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

1767
							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...
1768
							
1769
						}
1770
						else if (TSubtotal::isSubtotal($line))
1771
						{
1772
							$qty_displayed = 100 - $line->qty;
1773
							print img_picto('', 'subsubtotal2@subtotal').'<span style="font-size:9px;margin-left:-1px;color:#0075DE;">'.$qty_displayed.'</span>&nbsp;&nbsp;';
1774
						}
1775
						else
1776
						{
1777
							$isFreeText = true;
1778
						}
1779
						
1780
						if ($object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
1781
						    $line->label = !empty($line->description) ? $line->description : $line->desc;
1782
						    $line->description = '';
1783
						}
1784
						$newlabel = $line->label;
1785
						if($line->label=='' && !$isFreeText) {
1786
							if(TSubtotal::isSubtotal($line)) {
1787
								$newlabel = $line->description.' '.$this->getTitle($object, $line);
1788
								$line->description='';
1789
							} elseif( (float)DOL_VERSION < 6 ) {
1790
								$newlabel= $line->description;
1791
								$line->description='';
1792
							}
1793
						}
1794
1795
						$readonlyForSituation = '';
1796
						if (!empty($object->situation_cycle_ref) && $object->situation_counter > 1) $readonlyForSituation = 'readonly';
1797
						
1798
						if (!$isFreeText) echo '<input type="text" name="line-title" id-line="'.$line->id.'" value="'.$newlabel.'" size="80" '.$readonlyForSituation.'/>&nbsp;';
1799
						
1800
						if (!empty($conf->global->SUBTOTAL_USE_NEW_FORMAT) && (TSubtotal::isTitle($line) || TSubtotal::isSubtotal($line)) )
1801
						{
1802
							$select = '<select name="subtotal_level">';
1803
							for ($j=1; $j<10; $j++)
1804
							{
1805
								if (!empty($readonlyForSituation)) {
1806
									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...
1807
								} else $select .= '<option '.($qty_displayed == $j ? 'selected="selected"' : '').' value="'.$j.'">'.$langs->trans('Level').' '.$j.'</option>';
1808
							}
1809
							$select .= '</select>&nbsp;';
1810
1811
							echo $select;
1812
						}
1813
						
1814
1815
						echo '<div class="subtotal_underline" style="margin-left:24px;">';
1816
							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;';
1817
1818
							if (TSubtotal::isTitle($line))
1819
							{
1820
								$form = new Form($db);
1821
								echo '<label for="subtotal_tva_tx">'.$form->textwithpicto($langs->trans('subtotal_apply_default_tva'), $langs->trans('subtotal_apply_default_tva_help')).'</label>';
1822
								echo '<select id="subtotal_tva_tx" name="subtotal_tva_tx" class="flat"><option selected="selected" value="">-</option>';
1823
								if (empty($readonlyForSituation)) echo str_replace('selected', '', $form->load_tva('subtotal_tva_tx', '', $parameters['seller'], $parameters['buyer'], 0, 0, '', true));
1824
								echo '</select>&nbsp;&nbsp;';
1825
								
1826
								if (!empty($conf->global->INVOICE_USE_SITUATION) && $object->element == 'facture' && $object->type == Facture::TYPE_SITUATION)
1827
								{
1828
									echo '<label for="subtotal_progress">'.$langs->trans('subtotal_apply_progress').'</label> <input id="subtotal_progress" name="subtotal_progress" value="" size="1" />%';
1829
								}
1830
							}
1831
							else if ($isFreeText) echo TSubtotal::getFreeTextHtml($line, (bool) $readonlyForSituation);
1832
						echo '</div>';
1833
1834
						if($line->qty<10) {
1835
							// WYSIWYG editor
1836
							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...
1837
							$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...
1838
							$cked_enabled = (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
1839
							if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
1840
								$nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
1841
							}
1842
							$toolbarname = 'dolibarr_details';
1843
							if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) {
1844
								$toolbarname = 'dolibarr_notes';
1845
							}
1846
							$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...
1847
								false, true, $cked_enabled, $nbrows, '98%', (bool) $readonlyForSituation);
1848
							$doleditor->Create();
1849
						}
1850
						
1851
					}
1852
					else {
1853
1854
						 if ($conf->global->SUBTOTAL_USE_NEW_FORMAT)
1855
						 {
1856
							if(TSubtotal::isTitle($line) || TSubtotal::isSubtotal($line)) 
1857
							{
1858
								echo str_repeat('&nbsp;&nbsp;&nbsp;', $line->qty-1);
1859
								
1860
								if (TSubtotal::isTitle($line)) print img_picto('', 'subtotal@subtotal').'<span style="font-size:9px;margin-left:-3px;">'.$line->qty.'</span>&nbsp;&nbsp;';
1861
								else print img_picto('', 'subtotal2@subtotal').'<span style="font-size:9px;margin-left:-1px;">'.(100-$line->qty).'</span>&nbsp;&nbsp;';
1862
							}
1863
						 }
1864
						 else 
1865
						 {
1866
							if($line->qty<=1) print img_picto('', 'subtotal@subtotal');
1867
							else if($line->qty==2) print img_picto('', 'subsubtotal@subtotal').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; 
1868
						 }
1869
						 
1870
						 
1871
						 // Get display styles and apply them
1872
						 $titleStyleItalic = strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'I') === false ? '' : ' font-style: italic;';
1873
						 $titleStyleBold =  strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'B') === false ? '' : ' font-weight:bold;';
1874
						 $titleStyleUnderline =  strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'U') === false ? '' : ' text-decoration: underline;';
1875
						 
1876
						 if (empty($line->label)) {
1877
							if ($line->qty >= 91 && $line->qty <= 99 && $conf->global->SUBTOTAL_USE_NEW_FORMAT) print  $line->description.' '.$this->getTitle($object, $line);
1878
							else print  $line->description;
1879
						 } 
1880
						 else {
1881
1882
							if (! empty($conf->global->PRODUIT_DESC_IN_FORM) && !empty($line->description)) {
1883
								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

1883
								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...
1884
							}
1885
							else{
1886
								print '<span class="subtotal_label classfortooltip '.$titleStyleItalic.$titleStyleBold.$titleStyleUnderline.'" title="'.$line->description.'">'.$line->label.'</span>';    
1887
							}
1888
1889
						 } 
1890
						if($line->qty>90) print ' : ';
1891
						if($line->info_bits > 0) echo img_picto($langs->trans('Pagebreak'), 'pagebreak@subtotal');
1892
1893
						 
1894
1895
1896
					}
1897
			?></td>
1898
					 
1899
			<?php
1900
				if($line->qty>90) {
1901
					/* Total */
1902
					$total_line = $this->getTotalLineFromObject($object, $line, '');
1903
					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

1903
					echo '<td class="nowrap liencolht" align="right" style="font-weight:bold;" rel="subtotal_total">'./** @scrutinizer ignore-call */ price($total_line).'</td>';
Loading history...
1904
				} else {
1905
					echo '<td class="liencolht movetitleblock" >&nbsp;</td>';
1906
				}	
1907
			?>
1908
					
1909
			<td align="center" class="nowrap linecoledit">
1910
				<?php
1911
				if ($action != 'selectlines') {
1912
				
1913
					if($action=='editline' && GETPOST('lineid') == $line->id && TSubtotal::isModSubtotalLine($line) ) {
1914
						?>
1915
						<input id="savelinebutton" class="button" type="submit" name="save" value="<?php echo $langs->trans('Save') ?>" />
1916
						<br />
1917
						<input class="button" type="button" name="cancelEditlinetitle" value="<?php echo $langs->trans('Cancel') ?>" />
1918
						<script type="text/javascript">
1919
							$(document).ready(function() {
1920
								$('input[name=cancelEditlinetitle]').click(function () {
1921
									document.location.href="<?php echo '?'.$idvar.'='.$object->id ?>";
1922
								});
1923
							});
1924
1925
						</script>
1926
						<?php
1927
						
1928
					}
1929
					else{
1930
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_DUPLICATE_BLOCK) && $object->element !== 'invoice_supplier')
1931
						{
1932
							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>';
1933
						}
1934
1935
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_EDIT_BLOCK)) 
1936
						{
1937
							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

1937
							echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=editline&lineid='.$line->id.'">'./** @scrutinizer ignore-call */ img_edit().'</a>';
Loading history...
1938
						}								
1939
					}
1940
					
1941
				}
1942
					
1943
				?>
1944
			</td>
1945
1946
			<td align="center" nowrap="nowrap" class="linecoldelete">	
1947
				<?php
1948
1949
				if ($action != 'editline' && $action != 'selectlines') {
1950
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_REMOVE_BLOCK))
1951
						{
1952
1953
							if ($object->situation_counter == 1 || !$object->situation_cycle_ref)
1954
							{
1955
								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

1955
								echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=ask_deleteline&lineid='.$line->id.'">'./** @scrutinizer ignore-call */ img_delete().'</a>';
Loading history...
1956
							}
1957
1958
							if(TSubtotal::isTitle($line) && ($object->situation_counter == 1 || !$object->situation_cycle_ref) )
1959
							{
1960
								$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');
1961
								echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=ask_deleteallline&lineid='.$line->id.'">'.$img_delete.'</a>';
1962
							}
1963
						}
1964
					}
1965
				?>
1966
			</td>
1967
			
1968
			<?php 
1969
			if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && TSubtotal::isTitle($line) && $action != 'editline')
1970
			{
1971
				echo '<td class="subtotal_nc">';
1972
				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"' : '').' />';
1973
				echo '</td>';
1974
			}
1975
			
1976
			if ($num > 1 && empty($conf->browser->phone)) { ?>
1977
			<td align="center" class="tdlineupdown">
1978
			</td>
1979
			<?php } else { ?>
1980
			<td align="center"<?php echo ((empty($conf->browser->phone) && ($object->statut == 0  && $createRight ))?' class="tdlineupdown"':''); ?>></td>
1981
			<?php } ?>
1982
1983
			<?php  if($action == 'selectlines'){ // dolibarr 8 ?>
1984
			<td class="linecolcheck" align="center"><input type="checkbox" class="linecheckbox" name="line_checkbox[<?php echo $i+1; ?>]" value="<?php echo $line->id; ?>" ></td>
1985
			<?php } ?>
1986
1987
			</tr>
1988
			<?php
1989
			
1990
			
1991
			// Affichage des extrafields à la Dolibarr (car sinon non affiché sur les titres)
1992
			if(TSubtotal::isTitle($line) && !empty($conf->global->SUBTOTAL_ALLOW_EXTRAFIELDS_ON_TITLE)) {
1993
				
1994
				require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
1995
				
1996
				// Extrafields
1997
				$extrafieldsline = new ExtraFields($db);
1998
				$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...
1999
				
2000
				$colspan+=3; $mode = 'view';
2001
				if($action === 'editline' && $line->rowid == GETPOST('lineid')) $mode = 'edit';
2002
				
2003
				$ex_element = $line->element;
2004
				$line->element = 'tr_extrafield_title '.$line->element; // Pour pouvoir manipuler ces tr
2005
				print $line->showOptionals($extrafieldsline, $mode, array('style'=>' style="background:#eeffee;" ','colspan'=>$colspan));
2006
				$isExtraSelected = false;
2007
				foreach($line->array_options as $option) {
2008
					if(!empty($option) && $option != "-1") {
2009
						$isExtraSelected = true;
2010
						break;
2011
					}
2012
				}
2013
				
2014
				if($mode === 'edit') {
2015
					?>
2016
					<script>
2017
						$(document).ready(function(){
2018
2019
							var all_tr_extrafields = $("tr.tr_extrafield_title");
2020
							<?php 
2021
							// Si un extrafield est rempli alors on affiche directement les extrafields
2022
							if(!$isExtraSelected) {
2023
								echo 'all_tr_extrafields.hide();';
2024
								echo 'var trad = "'.$langs->trans('showExtrafields').'";';
2025
								echo 'var extra = 0;';
2026
							} else {
2027
								echo 'all_tr_extrafields.show();';
2028
								echo 'var trad = "'.$langs->trans('hideExtrafields').'";';
2029
								echo 'var extra = 1;';
2030
							}
2031
							?>
2032
							
2033
							$("div .subtotal_underline").append(
2034
									'<a id="printBlocExtrafields" onclick="return false;" href="#">' + trad + '</a>'
2035
									+ '<input type="hidden" name="showBlockExtrafields" id="showBlockExtrafields" value="'+ extra +'" />');
2036
2037
							$(document).on('click', "#printBlocExtrafields", function() {
2038
								var btnShowBlock = $("#showBlockExtrafields");
2039
								var val = btnShowBlock.val();
2040
								if(val == '0') {
2041
									btnShowBlock.val('1');
2042
									$("#printBlocExtrafields").html("<?php print $langs->trans('hideExtrafields'); ?>");
2043
									$(all_tr_extrafields).show();
2044
								} else {
2045
									btnShowBlock.val('0');
2046
									$("#printBlocExtrafields").html("<?php print $langs->trans('showExtrafields'); ?>");
2047
									$(all_tr_extrafields).hide();
2048
								}
2049
							});
2050
						});
2051
					</script>
2052
					<?php
2053
				}
2054
				$line->element = $ex_element;
2055
				
2056
			}
2057
			
2058
			return 1;	
2059
			
2060
		}
2061
		
2062
		return 0;
2063
2064
	}
2065
2066
	
2067
	function addMoreActionsButtons($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

2067
	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

2067
	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...
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...
2068
		global $conf,$langs;
2069
		 
2070
		if ($object->statut == 0 && !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && $action != 'editline')
2071
		{
2072
			$TSubNc = array();
2073
			foreach ($object->lines as &$l)
2074
			{
2075
				$TSubNc[$l->id] = (int) $l->array_options['options_subtotal_nc'];
2076
			}
2077
			
2078
			$form = new Form($db);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $db seems to be never defined.
Loading history...
2079
			?>
2080
			<script type="text/javascript">
2081
				$(function() {
2082
					var subtotal_TSubNc = <?php echo json_encode($TSubNc); ?>;
2083
					$("#tablelines tbody > tr").each(function(i, item) {
2084
						if ($(item).children('.subtotal_nc').length == 0)
2085
						{
2086
							var id = $(item).attr('id');
2087
							
2088
							if ((typeof id != 'undefined' && id.indexOf('row-') >= 0) || $(item).hasClass('liste_titre'))
2089
							{
2090
								$(item).children('td:last-child').before('<td class="subtotal_nc"></td>');
2091
								
2092
								if ($(item).attr('rel') != 'subtotal' && typeof $(item).attr('id') != 'undefined')
2093
								{
2094
									var idSplit = $(item).attr('id').split('-');
2095
									$(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"' : '')+' />'));
2096
								}
2097
							}
2098
							else 
2099
							{
2100
								$(item).append('<td class="subtotal_nc"></td>');
2101
							}
2102
						}
2103
					});
2104
					
2105
					$('#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'))); ?>);
2106
					
2107
					function callAjaxUpdateLineNC(set, lineid, subtotal_nc)
2108
					{
2109
						$.ajax({
2110
							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

2110
							url: '<?php echo /** @scrutinizer ignore-call */ dol_buildpath('/subtotal/script/interface.php', 1); ?>'
Loading history...
2111
							,type: 'POST'
2112
							,data: {
2113
								json:1
2114
								,set: set
2115
								,element: '<?php echo $object->element; ?>'
2116
								,elementid: <?php echo (int) $object->id; ?>
2117
								,lineid: lineid
2118
								,subtotal_nc: subtotal_nc
2119
							}
2120
						}).done(function(response) {
2121
							window.location.href = window.location.pathname + '?id=<?php echo $object->id; ?>&page_y=' + window.pageYOffset;
2122
						});
2123
					}
2124
					
2125
					$(".subtotal_nc_chkbx").change(function(event) {
2126
						var lineid = $(this).data('lineid');
2127
						var subtotal_nc = 0 | $(this).is(':checked'); // Renvoi 0 ou 1 
2128
						
2129
						callAjaxUpdateLineNC('updateLineNC', lineid, subtotal_nc);
2130
					});
2131
					
2132
				});
2133
2134
			</script>
2135
			<?php
2136
		}
2137
		
2138
		$this->_ajax_block_order_js($object);
2139
	}
2140
	
2141
	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

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

2141
	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...
2142
	{
2143
		global $conf;
2144
		
2145
		$object = $parameters['object'];
2146
		
2147
		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'))
2148
		{
2149
			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

2149
			if (/** @scrutinizer ignore-call */ GETPOST('subtotal_add_recap')) {
Loading history...
2150
				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

2150
				/** @scrutinizer ignore-call */ 
2151
    dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
2151
				TSubtotal::addRecapPage($parameters, $pdf);
2152
			}
2153
		}
2154
	}
2155
	
2156
	// HTML 5 data for js
2157
	private function _getHtmlData($parameters, &$object, &$action, $hookmanager)
2158
	{
2159
		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

2159
		/** @scrutinizer ignore-call */ 
2160
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
2160
2161
	    $line = &$parameters['line'];
2162
	    
2163
	    $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...
2164
	    $ThtmlData['data-product_type'] = $line->product_type;
2165
	    $ThtmlData['data-qty']          = 0; //$line->qty;
2166
	    $ThtmlData['data-level']        = TSubtotal::getNiveau($line);
2167
	    
2168
	    if(TSubtotal::isTitle($line)){
2169
	        $ThtmlData['data-issubtotal'] = 'title';
2170
	    }elseif(TSubtotal::isSubtotal($line)){
2171
	        $ThtmlData['data-issubtotal'] = 'subtotal';
2172
	    }
2173
	    else{
2174
	        $ThtmlData['data-issubtotal'] = 'freetext';
2175
	    }
2176
	    
2177
	    
2178
	    // Change or add data  from hooks
2179
	    $parameters = array_replace($parameters , array(  'ThtmlData' => $ThtmlData )  );
2180
	    
2181
	    // hook 
2182
	    $reshook = $hookmanager->executeHooks('subtotalLineHtmlData',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
2183
	    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

2183
	    if ($reshook < 0) /** @scrutinizer ignore-call */ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
Loading history...
2184
	    if ($reshook>0)
2185
	    {
2186
	        $ThtmlData = $hookmanager->resArray;
2187
	    }
2188
2189
	    return $this->implodeHtmlData($ThtmlData);
2190
	
2191
	}
2192
	
2193
	
2194
	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...
2195
	{
2196
	    $data = '';
2197
	    foreach($ThtmlData as $k => $h )
2198
	    {
2199
	        if(is_array($h))
2200
	        {
2201
	            $h = json_encode($h);
2202
	        }
2203
	        
2204
	        $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

2204
	        $data .= $k . '="'./** @scrutinizer ignore-call */ dol_htmlentities($h, ENT_QUOTES).'" ';
Loading history...
2205
	    }
2206
	    
2207
	    return $data;
2208
	}
2209
	
2210
	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...
2211
	{
2212
	    global $conf,$tagidfortablednd,$filepath,$langs;
2213
	    
2214
	    /*
2215
	     * this part of js is base on dolibarr htdocs/core/tpl/ajaxrow.tpl.php 
2216
	     * for compatibility reasons we don't use tableDnD but jquery sortable
2217
	     */
2218
	    
2219
	    $id=$object->id;
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
2220
	    $nboflines=(isset($object->lines)?count($object->lines):0);
2221
	    $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...
2222
	    
2223
	    $id=$object->id;
2224
	    $fk_element=$object->fk_element;
2225
	    $table_element_line=$object->table_element_line;
2226
	    $nboflines=(isset($object->lines)?count($object->lines):(empty($nboflines)?0:$nboflines));
2227
	    $tagidfortablednd=(empty($tagidfortablednd)?'tablelines':$tagidfortablednd);
2228
	    $filepath=(empty($filepath)?'':$filepath);
2229
	    
2230
	    
2231
	    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

2231
	    if (/** @scrutinizer ignore-call */ GETPOST('action','aZ09') != 'editline' && $nboflines > 1)
Loading history...
2232
	    {
2233
	        
2234
	        ?>
2235
		
2236
		
2237
			<script type="text/javascript">
2238
			$(document).ready(function(){
2239
2240
				// target some elements
2241
				var titleRow = $('tr[data-issubtotal="title"]');
2242
				var lastTitleCol = titleRow.find('td:last-child');
2243
				var moveBlockCol= titleRow.find('td.liencolht');
2244
2245
				
2246
				moveBlockCol.disableSelection(); // prevent selection
2247
<?php if ($object->statut == 0) { ?>
2248
				// apply some graphical stuff
2249
				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

2249
				moveBlockCol.css("background-image",'url(<?php echo /** @scrutinizer ignore-call */ dol_buildpath('subtotal/img/grip_all.png',2);  ?>)');
Loading history...
2250
				moveBlockCol.css("background-repeat","no-repeat");
2251
				moveBlockCol.css("background-position","center center");
2252
				moveBlockCol.css("cursor","move");
2253
				titleRow.attr('title', '<?php echo html_entity_decode($langs->trans('MoveTitleBlock')); ?>');
2254
			
2255
2256
 				$( "#<?php echo $tagidfortablednd; ?>" ).sortable({
2257
			    	  cursor: "move",
2258
			    	  handle: ".movetitleblock",
2259
			    	  items: 'tr:not(.nodrag,.nodrop,.noblockdrop)',
2260
			    	  delay: 150, //Needed to prevent accidental drag when trying to select
2261
			    	  opacity: 0.8,
2262
			    	  axis: "y", // limit y axis
2263
			    	  placeholder: "ui-state-highlight",
2264
			    	  start: function( event, ui ) {
2265
			    	      //console.log('X:' + e.screenX, 'Y:' + e.screenY);
2266
			    		  //console.log(ui.item);
2267
			    		  var colCount = ui.item.children().length;
2268
   						  ui.placeholder.html('<td colspan="'+colCount+'">&nbsp;</td>');
2269
   		
2270
			    		  var TcurrentChilds = getSubtotalTitleChilds(ui.item);
2271
			    		  ui.item.data('childrens',TcurrentChilds); // store data
2272
				    		
2273
			    		  for (var key in TcurrentChilds) {
2274
			    			  $('#'+ TcurrentChilds[key]).addClass('noblockdrop');//'#row-'+ 
2275
			    			  $('#'+ TcurrentChilds[key]).fadeOut();//'#row-'+ 
2276
			    		  }
2277
2278
			    		  $(this).sortable("refresh");	// "refresh" of source sortable is required to make "disable" work!
2279
			    	      
2280
			    	    },
2281
				    	stop: function (event, ui) {
2282
							// call we element is droped
2283
				    	  	$('.noblockdrop').removeClass('noblockdrop');
2284
2285
				    	  	var TcurrentChilds = ui.item.data('childrens'); // reload child list from data and not attr to prevent load error
2286
2287
							for (var i =TcurrentChilds.length ; i >= 0; i--) {
2288
				    			  $('#'+ TcurrentChilds[i]).insertAfter(ui.item); //'#row-'+ 
2289
				    			  $('#'+ TcurrentChilds[i]).fadeIn(); //'#row-'+ 
2290
							}
2291
							console.log('onstop');
2292
							console.log(cleanSerialize($(this).sortable('serialize')));
2293
							
2294
							$.ajax({
2295
			    	            data: {
2296
									objet_id: <?php print $object->id; ?>,
2297
							    	roworder: cleanSerialize($(this).sortable('serialize')),
2298
									table_element_line: "<?php echo $table_element_line; ?>",
2299
									fk_element: "<?php echo $fk_element; ?>",
2300
									element_id: "<?php echo $id; ?>",
2301
									filepath: "<?php echo urlencode($filepath); ?>"
2302
								},
2303
			    	            type: 'POST',
2304
			    	            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...
2305
			    	            success: function(data) {
2306
			    	                console.log(data);
2307
			    	            },
2308
			    	        });
2309
			    	        
2310
			    	  },
2311
			    	  update: function (event, ui) {
2312
				    	  
2313
			    	        // POST to server using $.post or $.ajax
2314
				    	  	$('.noblockdrop').removeClass('noblockdrop');
2315
							//console.log('onupdate');
2316
			    	        //console.log(cleanSerialize($(this).sortable('serialize')));
2317
			    	    }
2318
			    });
2319
 				<?php } ?>
2320
2321
				function getSubtotalTitleChilds(item)
2322
				{
2323
		    		var TcurrentChilds = []; // = JSON.parse(item.attr('data-childrens'));
2324
		    		var level = item.data('level');
2325
2326
		    		var indexOfFirstSubtotal = -1;
2327
		    		var indexOfFirstTitle = -1;
2328
		    		
2329
		    		item.nextAll('[id^="row-"]').each(function(index){
2330
2331
						var dataLevel = $(this).attr('data-level');
2332
						var dataIsSubtotal = $(this).attr('data-issubtotal');
2333
						
2334
						if(dataIsSubtotal != 'undefined' && dataLevel != 'undefined' )
2335
						{
2336
2337
							if(dataLevel <=  level && indexOfFirstSubtotal < 0 && dataIsSubtotal == 'subtotal' )
2338
							{
2339
								indexOfFirstSubtotal = index;
2340
								if(indexOfFirstTitle < 0)
2341
								{
2342
									TcurrentChilds.push($(this).attr('id'));
2343
								}
2344
							}
2345
							
2346
							if(dataLevel <=  level && indexOfFirstSubtotal < 0 && indexOfFirstTitle < 0 && dataIsSubtotal == 'title' )
2347
							{
2348
								indexOfFirstTitle = index;
2349
							}
2350
						}
2351
2352
						if(indexOfFirstTitle < 0 && indexOfFirstSubtotal < 0)
2353
						{
2354
							TcurrentChilds.push($(this).attr('id'));
2355
2356
							// Add extraffield support for dolibarr > 7
2357
							var thisId = $(this).attr('data-id');
2358
							var thisElement = $(this).attr('data-element');
2359
							if(thisId != undefined && thisElement != undefined )
2360
							{
2361
								$('[data-targetid="' + thisId + '"][data-element="extrafield"][data-targetelement="'+ thisElement +'"]').each(function(index){
2362
									TcurrentChilds.push($(this).attr('id'));
2363
								});
2364
							}
2365
							
2366
						}
2367
2368
		    		});
2369
		    		return TcurrentChilds;
2370
				}
2371
				
2372
			});
2373
			</script>
2374
			<style type="text/css" >
2375
         
2376
            tr.ui-state-highlight td{
2377
            	border: 1px solid #dad55e;
2378
            	background: #fffa90;
2379
            	color: #777620;
2380
            }
2381
            </style>
2382
		<?php
2383
		
2384
		} 
2385
	
2386
		
2387
		
2388
	}
2389
	
2390
}
2391