Passed
Push — master ( 21f027...66b259 )
by
unknown
04:58
created

ActionsSubtotal::getTotalToPrintSituation()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 5
eloc 12
c 2
b 1
f 0
nc 5
nop 2
dl 0
loc 21
rs 9.5555
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
	function printFieldListSelect($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

15
	function printFieldListSelect($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 $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

15
	function printFieldListSelect($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 $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

15
	function printFieldListSelect($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...
16
		
17
		global $type_element, $where;
18
		
19
		$contexts = explode(':',$parameters['context']);
20
		
21
		if(in_array('consumptionthirdparty',$contexts) && in_array($type_element, array('propal', 'order', 'invoice', 'supplier_order', 'supplier_invoice', 'supplier_proposal'))) {
22
			$mod_num = TSubtotal::$module_number;
23
			
24
			// Not a title (can't use TSubtotal class methods in sql)
25
			$where.= ' AND (d.special_code != '.$mod_num.' OR d.product_type != 9 OR d.qty > 9)';
26
			// Not a subtotal (can't use TSubtotal class methods in sql)
27
			$where.= ' AND (d.special_code != '.$mod_num.' OR d.product_type != 9 OR d.qty < 90)';
28
			// Not a free line text (can't use TSubtotal class methods in sql)
29
			$where.= ' AND (d.special_code != '.$mod_num.' OR d.product_type != 9 OR d.qty != 50)';
30
			
31
		}
32
		
33
	}
34
	
35
	
36
	function createDictionaryFieldlist($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

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

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

36
	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...
37
	{
38
		global $conf;
39
40
		if ($parameters['tabname'] == MAIN_DB_PREFIX.'c_subtotal_free_text')
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...
41
		{
42
			// Merci Dolibarr de remplacer les textarea par un input text
43
			if ((float) DOL_VERSION >= 6.0)
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...
44
			{
45
				$value = '';
46
				$sql = 'SELECT content FROM '.MAIN_DB_PREFIX.'c_subtotal_free_text WHERE rowid = '.GETPOST('rowid');
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

46
				$sql = 'SELECT content FROM '.MAIN_DB_PREFIX.'c_subtotal_free_text WHERE rowid = './** @scrutinizer ignore-call */ GETPOST('rowid');
Loading history...
47
				$resql = $this->db->query($sql);
48
				if ($resql && ($obj = $this->db->fetch_object($resql))) $value = $obj->content;
49
			}
50
			
51
			?>
52
			<script type="text/javascript">
53
				$(function() {
54
					
55
					<?php if ((float) DOL_VERSION >= 6.0) { ?>
56
							if ($('input[name=content]').length > 0)
57
							{
58
								$('input[name=content]').each(function(i,item) {
59
									var value = '';
60
									// Le dernier item correspond à l'édition
61
									if (i == $('input[name=content]').length) value = <?php echo json_encode($value); ?>;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value does not seem to be defined for all execution paths leading up to this point.
Loading history...
62
									$(item).replaceWith($('<textarea name="content">'+value+'</textarea>'));
63
								});
64
								
65
								<?php if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
66
								$('textarea[name=content]').each(function(i, item) {
67
									CKEDITOR.replace(item, {
68
										toolbar: 'dolibarr_notes'
69
										,customConfig : ckeditorConfig
70
									});
71
								});
72
								<?php } ?>
73
							}
74
					<?php } else { ?>
75
						// <= 5.0
76
						// Le CKEditor est forcé sur la page dictionnaire, pas possible de mettre une valeur custom
77
						// petit js qui supprimer le wysiwyg et affiche le textarea car avant la version 6.0 le wysiwyg sur une page de dictionnaire est inexploitable
78
						<?php if (!empty($conf->fckeditor->enabled)) { ?>
79
							CKEDITOR.on('instanceReady', function(ev) {
80
								var editor = ev.editor;
81
82
								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
83
								{
84
									editor.element.show();
85
									editor.destroy();
86
								}
87
							});
88
						<?php } ?>
89
					<?php } ?>
90
				});
91
			</script>
92
			<?php
93
		}
94
	}
95
	
96
	/** Overloading the doActions function : replacing the parent's function with the one below
97
	 * @param      $parameters  array           meta datas of the hook (context, etc...)
98
	 * @param      $object      CommonObject    the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
99
	 * @param      $action      string          current action (if set). Generally create or edit or null
100
	 * @param      $hookmanager HookManager     current hook manager
101
	 * @return     void
102
	 */
103
    
104
    var $module_number = 104777;
105
    
106
    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

106
    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...
107
    {
108
      	global $langs,$db,$user, $conf;
109
		
110
		$langs->load('subtotal@subtotal');
111
		
112
		$contexts = explode(':',$parameters['context']);
113
		
114
		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)) {
115
			
116
			$createRight = $user->rights->{$object->element}->creer;
117
			if($object->element == 'facturerec' )
118
			{
119
				$object->statut = 0; // hack for facture rec
120
				$createRight = $user->rights->facture->creer;
121
			} elseif($object->element == 'order_supplier' )
122
			{
123
			    $createRight = $user->rights->fournisseur->commande->creer;
124
			} elseif($object->element == 'invoice_supplier' )
125
			{
126
			    $createRight = $user->rights->fournisseur->facture->creer;
127
			}
128
			
129
			if ($object->statut == 0  && $createRight) {
130
			
131
132
				if($object->element=='facture')$idvar = 'facid';
133
				else $idvar='id';
134
				
135
				if(in_array($action, array('add_title_line', 'add_total_line', 'add_subtitle_line', 'add_subtotal_line', 'add_free_text')) )
136
				{
137
					$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

137
					$level = /** @scrutinizer ignore-call */ GETPOST('level', 'int'); //New avec SUBTOTAL_USE_NEW_FORMAT
Loading history...
138
					
139
					if($action=='add_title_line') {
140
						$title = GETPOST('title');
141
						if(empty($title)) $title = $langs->trans('title');
142
						$qty = $level<1 ? 1 : $level ;
143
					}
144
					else if($action=='add_free_text') {
145
						$title = GETPOST('title');
146
147
						if (empty($title)) {
148
							$free_text = GETPOST('free_text', 'int');
149
							if (!empty($free_text)) {
150
								$TFreeText = getTFreeText();
151
								if (!empty($TFreeText[$free_text])) {
152
									$title = $TFreeText[$free_text]->content;
153
								}
154
							}
155
						}
156
						if(empty($title)) $title = $langs->trans('subtotalAddLineDescription');
157
						$qty = 50;
158
					}
159
					else if($action=='add_subtitle_line') {
160
						$title = GETPOST('title');
161
						if(empty($title)) $title = $langs->trans('subtitle');
162
						$qty = 2;
163
					}
164
					else if($action=='add_subtotal_line') {
165
						$title = $langs->trans('SubSubTotal');
166
						$qty = 98;
167
					}
168
					else {
169
						$title = GETPOST('title') ? GETPOST('title') : $langs->trans('SubTotal');
170
						$qty = $level ? 100-$level : 99;
171
					}
172
					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

172
					/** @scrutinizer ignore-call */ 
173
     dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
173
					
174
					if (!empty($conf->global->SUBTOTAL_AUTO_ADD_SUBTOTAL_ON_ADDING_NEW_TITLE) && $qty < 10) TSubtotal::addSubtotalMissing($object, $qty);
175
					
176
	    			TSubtotal::addSubTotalLine($object, $title, $qty);
177
				}
178
				else if($action==='ask_deleteallline') {
179
						$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...
180
						
181
						$lineid = GETPOST('lineid','integer');
182
						$TIdForGroup = $this->getArrayOfLineForAGroup($object, $lineid);
183
					
184
						$nbLines = count($TIdForGroup);
185
					
186
						$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('deleteWithAllLines'), $langs->trans('ConfirmDeleteAllThisLines',$nbLines), 'confirm_delete_all_lines','',0,1);
187
						print $formconfirm;
188
				}
189
190
				if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE))
191
				{
192
					$this->showSelectTitleToAdd($object);
193
				}
194
195
				
196
				if($action!='editline') {
197
					// New format is for 3.8
198
					$this->printNewFormat($object, $conf, $langs, $idvar);
199
				}
200
			}
201
		}
202
		elseif ((!empty($parameters['currentcontext']) && $parameters['currentcontext'] == 'orderstoinvoice') || in_array('orderstoinvoice',$contexts))
203
		{
204
			?>
205
			<script type="text/javascript">
206
				$(function() {
207
					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>")
208
					$("textarea[name=note]").closest('tr').after(tr);
209
				});
210
			</script>
211
			<?php
212
			
213
		}
214
215
		return 0;
216
	}
217
     
218
	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...
219
	{
220
		if (empty($conf->global->SUBTOTAL_ALLOW_ADD_BLOCK)) return false;
221
		if (!empty($object->situation_cycle_ref) && $object->situation_counter > 1) return false; // Si facture de situation
222
		?>
223
		 	<script type="text/javascript">
224
				$(document).ready(function() {
225
					$('div.fiche div.tabsAction').append('<br />');
226
					
227
					$('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>');
228
					$('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>');
229
					$('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>');
230
231
232
					function updateAllMessageForms(){
233
				         for (instance in CKEDITOR.instances) {
234
				             CKEDITOR.instances[instance].updateElement();
235
				         }
236
				    }
237
					
238
					function promptSubTotal(action, titleDialog, label, url_to, url_ajax, params, use_textarea, show_free_text, show_under_title) {
239
					     $( "#dialog-prompt-subtotal" ).remove();
240
						 
241
						 var dialog_html = '<div id="dialog-prompt-subtotal" '+(action == 'addSubtotal' ? 'class="center"' : '')+' >';
242
						 
243
						 if (typeof show_under_title != 'undefined' && show_under_title)
244
						 {
245
							 var selectUnderTitle = <?php echo json_encode(getHtmlSelectTitle($object, true)); ?>;
246
							 dialog_html += selectUnderTitle + '<br /><br />';
247
						 }
248
						
249
						if (action == 'addTitle' || action == 'addFreeTxt')
250
						{
251
							if (typeof show_free_text != 'undefined' && show_free_text)
252
							{
253
							   var selectFreeText = <?php echo json_encode(getHtmlSelectFreeText()); ?>;
254
							   dialog_html += selectFreeText + ' <?php echo $langs->transnoentities('subtotalFreeTextOrDesc'); ?><br />';
255
							}
256
						 
257
							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...
258
							else dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />';
259
						}
260
						 
261
						if (action == 'addTitle' || action == 'addSubtotal')
262
						{
263
							if (action == 'addSubtotal') dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />';
264
							
265
							dialog_html += "&nbsp;<select name='subtotal_line_level'>";
266
							for (var i=1;i<10;i++)
267
							{
268
								dialog_html += "<option value="+i+"><?php echo $langs->trans('Level'); ?> "+i+"</option>";
269
							}
270
							dialog_html += "</select>";
271
						}
272
						 
273
						 dialog_html += '</div>';
274
					    
275
						$('body').append(dialog_html);
276
277
						<?php 
278
						$editorTool = empty($conf->global->FCKEDITOR_EDITORNAME)?'ckeditor':$conf->global->FCKEDITOR_EDITORNAME;
279
						$editorConf = empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?false:$conf->global->FCKEDITOR_ENABLE_DETAILS;
280
						if($editorConf && in_array($editorTool,array('textarea','ckeditor'))){ 
281
						?>
282
						if (action == 'addTitle' || action == 'addFreeTxt')
283
						{
284
							if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" )
285
							{
286
								 CKEDITOR.replace( 'sub-total-title', {toolbar: 'dolibarr_details', toolbarStartupExpanded: false} );
287
							}
288
						}
289
						<?php } ?>
290
						
291
					     $( "#dialog-prompt-subtotal" ).dialog({
292
	                        resizable: false,
293
							height: 'auto',
294
							width: 'auto',
295
	                        modal: true,
296
	                        title: titleDialog,
297
	                        buttons: {
298
	                            "Ok": function() {
299
	                            	if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" ){ updateAllMessageForms(); }
300
									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());
301
									params.under_title = $(this).find('select[name=under_title]').val();
302
									params.free_text = $(this).find('select[name=free_text]').val();
303
									params.level = $(this).find('select[name=subtotal_line_level]').val();
304
									
305
									$.ajax({
306
										url: url_ajax
307
										,type: 'POST'
308
										,data: params
309
									}).done(function() {
310
										document.location.href=url_to;
311
									});
312
									
313
                                    $( this ).dialog( "close" );
314
	                            },
315
	                            "<?php echo $langs->trans('Cancel') ?>": function() {
316
	                                $( this ).dialog( "close" );
317
	                            }
318
	                        }
319
	                     });
320
					}
321
					
322
					$('a[rel=add_title_line]').click(function() 
323
					{
324
						promptSubTotal('addTitle'
325
							 , "<?php echo $langs->trans('YourTitleLabel') ?>"
326
							 , "<?php echo $langs->trans('title'); ?>"
327
							 , '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
328
							 , '<?php echo $_SERVER['PHP_SELF']; ?>'
329
							 , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_title_line'}
330
						);
331
					});
332
					
333
					$('a[rel=add_total_line]').click(function()
334
					{
335
						promptSubTotal('addSubtotal'
336
							, '<?php echo $langs->trans('YourSubtotalLabel') ?>'
337
							, '<?php echo $langs->trans('subtotal'); ?>'
338
							, '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
339
							, '<?php echo $_SERVER['PHP_SELF']; ?>'
340
							, {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_total_line'}
341
							/*,false,false, <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?>*/
342
						);
343
					});
344
					
345
					$('a[rel=add_free_text]').click(function() 
346
					{
347
						promptSubTotal('addFreeTxt'
348
							, "<?php echo $langs->transnoentitiesnoconv('YourTextLabel') ?>"
349
							, "<?php echo $langs->trans('subtotalAddLineDescription'); ?>"
350
							, '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
351
							, '<?php echo $_SERVER['PHP_SELF']; ?>'
352
							, {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_free_text'}
353
							, true
354
							, true
355
							, <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?>
356
						);
357
					});
358
				});
359
		 	</script>
360
		 <?php
361
	}	 
362
	 
363
	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...
364
	{
365
		global $langs;
366
		
367
		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

367
		/** @scrutinizer ignore-call */ 
368
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
368
		dol_include_once('/subtotal/lib/subtotal.lib.php');
369
		$TTitle = TSubtotal::getAllTitleFromDocument($object);
0 ignored issues
show
Unused Code introduced by
The assignment to $TTitle is dead and can be removed.
Loading history...
370
		
371
		?>
372
		<script type="text/javascript">
373
			$(function() {
374
				var add_button = $("#addline");
375
				
376
				if (add_button.length > 0)
377
				{
378
					add_button.closest('tr').prev('tr.liste_titre').children('td:last').addClass('center').text("<?php echo $langs->trans('subtotal_title_to_add_under_title'); ?>");
379
					var select_title = $(<?php echo json_encode(getHtmlSelectTitle($object)); ?>);
380
					
381
					add_button.before(select_title);
382
				}
383
			});
384
		</script>
385
		<?php
386
	}
387
	
388
	
389
	function formBuilddocOptions($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...
390
	/* Réponse besoin client */		
391
			
392
		global $conf, $langs, $bc;
393
			
394
		$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

394
		$action = /** @scrutinizer ignore-call */ GETPOST('action');	
Loading history...
395
		$TContext = explode(':',$parameters['context']);
396
		if (
397
				in_array('invoicecard',$TContext)
398
		        || in_array('invoicesuppliercard',$TContext)
399
				|| in_array('propalcard',$TContext)
400
				|| in_array('ordercard',$TContext)
401
		        || in_array('ordersuppliercard',$TContext)
402
				|| in_array('invoicereccard',$TContext)
403
			)
404
	        {	
405
	            $hideInnerLines	= isset( $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']][$object->id] ) ?  $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']][$object->id] : 0;
406
	            $hidedetails	= isset( $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']][$object->id] ) ?  $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']][$object->id] : 0;
407
				$hidepricesDefaultConf = !empty($conf->global->SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED)?$conf->global->SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED:0;
408
				$hideprices= isset( $_SESSION['subtotal_hideprices_'.$parameters['modulepart']][$object->id] ) ?  $_SESSION['subtotal_hideprices_'.$parameters['modulepart']][$object->id] : $hidepricesDefaultConf;
409
				
410
				$var=false;
411
		     	$out.= '<tr '.$bc[$var].'>
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $out seems to be never defined.
Loading history...
412
		     			<td colspan="4" align="right">
413
		     				<label for="hideInnerLines">'.$langs->trans('HideInnerLines').'</label>
414
		     				<input type="checkbox" onclick="if($(this).is(\':checked\')) { $(\'#hidedetails\').prop(\'checked\', \'checked\')  }" id="hideInnerLines" name="hideInnerLines" value="1" '.(( $hideInnerLines ) ? 'checked="checked"' : '' ).' />
415
		     			</td>
416
		     			</tr>';
417
				
418
		     	$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always false.
Loading history...
419
		     	$out.= '<tr '.$bc[$var].'>
420
		     			<td colspan="4" align="right">
421
		     				<label for="hidedetails">'.$langs->trans('SubTotalhidedetails').'</label>
422
		     				<input type="checkbox" id="hidedetails" name="hidedetails" value="1" '.(( $hidedetails ) ? 'checked="checked"' : '' ).' />
423
		     			</td>
424
		     			</tr>';
425
		     	
426
		     	$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always true.
Loading history...
427
		     	$out.= '<tr '.$bc[$var].'>
428
		     			<td colspan="4" align="right">
429
		     				<label for="hideprices">'.$langs->trans('SubTotalhidePrice').'</label>
430
		     				<input type="checkbox" id="hideprices" name="hideprices" value="1" '.(( $hideprices ) ? 'checked="checked"' : '' ).' />
431
		     			</td>
432
		     			</tr>';
433
		     	
434
		     	
435
				 
436
				if ( 
437
					(in_array('propalcard',$TContext) && !empty($conf->global->SUBTOTAL_PROPAL_ADD_RECAP))
438
					|| (in_array('ordercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP))
439
				    || (in_array('ordersuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_COMMANDE_ADD_RECAP))
440
					|| (in_array('invoicecard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP))
441
				    || (in_array('invoicesuppliercard',$TContext) && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP))
442
					|| (in_array('invoicereccard',$TContext)  && !empty($conf->global->SUBTOTAL_INVOICE_ADD_RECAP ))
443
				)
444
				{
445
					$var=!$var;
0 ignored issues
show
introduced by
The condition $var is always false.
Loading history...
446
					$out.= '
447
						<tr '.$bc[$var].'>
448
							<td colspan="4" align="right">
449
								<label for="subtotal_add_recap">'.$langs->trans('subtotal_add_recap').'</label>
450
								<input type="checkbox" id="subtotal_add_recap" name="subtotal_add_recap" value="1" '.( GETPOST('subtotal_add_recap') ? 'checked="checked"' : '' ).' />
451
							</td>
452
						</tr>';
453
				}
454
				
455
				
456
				$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...
457
			}
458
			
459
		
460
        return 1;
461
	} 
462
	 
463
    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

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

463
    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...
Unused Code introduced by
The parameter $hookmanager is not used and could be removed. ( Ignorable by Annotation )

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

463
    function 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...
464
    {
465
		
466
    	if (in_array('invoicecard',explode(':',$parameters['context'])))
467
        {
468
        	
469
        }
470
		
471
        return 0;
472
    }
473
	
474
	function ODTSubstitutionLine(&$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

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

474
	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...
475
		global $conf;
476
		
477
		if($action === 'builddoc') {
478
			
479
			$line = &$parameters['line'];
480
			$object = &$parameters['object'];
481
			$substitutionarray = &$parameters['substitutionarray'];
482
			
483
			if($line->product_type == 9 && $line->special_code == $this->module_number) {
484
				$substitutionarray['line_modsubtotal'] = 1;	
485
				
486
				$substitutionarray['line_price_ht']
487
					 = $substitutionarray['line_price_vat'] 
488
					 = $substitutionarray['line_price_ttc']
489
					 = $substitutionarray['line_vatrate']
490
					 = $substitutionarray['line_qty']
491
					 = $substitutionarray['line_up'] 
492
					 = '';
493
				
494
				if($line->qty>90) {
495
					$substitutionarray['line_modsubtotal_total'] = true;
496
					
497
					list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
498
					
499
					$substitutionarray['line_price_ht'] = $total;
500
					$substitutionarray['line_price_vat'] = $total_tva;
501
					$substitutionarray['line_price_ttc'] = $total_ttc;
502
				} else {
503
					$substitutionarray['line_modsubtotal_title'] = true;
504
				}
505
				
506
				
507
			}	
508
			else{
509
				$substitutionarray['line_not_modsubtotal'] = true;
510
				$substitutionarray['line_modsubtotal'] = 0;
511
			}
512
			
513
		}
514
		
515
	}
516
	
517
	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

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

517
	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...
518
	
519
		if (
520
				in_array('invoicecard',explode(':',$parameters['context']))
521
		        || in_array('invoicesuppliercard',explode(':',$parameters['context']))
522
				|| in_array('propalcard',explode(':',$parameters['context']))
523
		        || in_array('supplier_proposalcard',explode(':',$parameters['context']))
524
				|| in_array('ordercard',explode(':',$parameters['context']))
525
		        || in_array('ordersuppliercard',explode(':',$parameters['context']))
526
				|| in_array('invoicereccard',explode(':',$parameters['context']))
527
		) {
528
			
529
			global $db;
530
			
531
			$objFrom = $parameters['objFrom'];
532
			
533
			foreach($objFrom->lines as $k=> &$lineOld) {
534
				
535
					if($lineOld->product_type == 9 && $lineOld->info_bits > 0 ) {
536
							
537
							$line = & $object->lines[$k];
538
				
539
							$idLine = (int) ($line->id ? $line->id : $line->rowid); 
540
				
541
							$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...
542
							SET info_bits=".(int)$lineOld->info_bits."
543
							WHERE rowid = ".$idLine."
544
							");
545
						
546
					}
547
				
548
				
549
			}
550
			
551
			
552
		}
553
		
554
	}
555
	
556
	function doActions($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

556
	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...
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...
557
	{
558
		global $db, $conf, $langs,$user;
559
		
560
		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

560
		/** @scrutinizer ignore-call */ 
561
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
561
		dol_include_once('/subtotal/lib/subtotal.lib.php');
562
		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...
563
		
564
		$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

564
		$showBlockExtrafields = /** @scrutinizer ignore-call */ GETPOST('showBlockExtrafields');
Loading history...
565
		
566
		if($object->element=='facture') $idvar = 'facid';
567
		else $idvar = 'id';
568
			
569
		if ($action == 'updateligne' || $action == 'updateline')
570
		{
571
			$found = false;
572
			$lineid = GETPOST('lineid', 'int');
573
			foreach ($object->lines as &$line)
574
			{
575
				
576
				if ($line->id == $lineid && TSubtotal::isModSubtotalLine($line))
577
				{
578
					$found = true;
579
					if(TSubtotal::isTitle($line) && !empty($showBlockExtrafields)) {
580
						$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...
581
						$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
582
						$extrafieldsline->setOptionalsFromPost($extralabelsline, $line);
583
					}
584
					_updateSubtotalLine($object, $line);
585
					_updateSubtotalBloc($object, $line);
586
					
587
					TSubtotal::generateDoc($object);
588
					break;
589
				}
590
			}
591
			
592
			if ($found)
593
			{
594
				header('Location: '.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id);
595
				exit; // Surtout ne pas laisser Dolibarr faire du traitement sur le updateligne sinon ça plante les données de la ligne
596
			}
597
		}
598
		else if($action === 'builddoc') {
599
			
600
			if (
601
				in_array('invoicecard',explode(':',$parameters['context']))
602
				|| in_array('propalcard',explode(':',$parameters['context']))
603
				|| in_array('ordercard',explode(':',$parameters['context']))
604
			    || in_array('ordersuppliercard',explode(':',$parameters['context']))
605
			    || in_array('invoicesuppliercard',explode(':',$parameters['context']))
606
			    || in_array('supplier_proposalcard',explode(':',$parameters['context']))
607
			)
608
	        {								
609
				if(in_array('invoicecard',explode(':',$parameters['context']))) {
610
					$sessname = 'subtotal_hideInnerLines_facture';	
611
					$sessname2 = 'subtotal_hidedetails_facture';
612
					$sessname3 = 'subtotal_hideprices_facture';
613
				}
614
				elseif(in_array('invoicesuppliercard',explode(':',$parameters['context']))) {
615
				    $sessname = 'subtotal_hideInnerLines_facture_fournisseur';
616
				    $sessname2 = 'subtotal_hidedetails_facture_fournisseur';
617
				    $sessname3 = 'subtotal_hideprices_facture_fournisseur';
618
				}
619
				elseif(in_array('propalcard',explode(':',$parameters['context']))) {
620
					$sessname = 'subtotal_hideInnerLines_propal';
621
					$sessname2 = 'subtotal_hidedetails_propal';	
622
					$sessname3 = 'subtotal_hideprices_propal';
623
				}
624
				elseif(in_array('supplier_proposalcard',explode(':',$parameters['context']))) {
625
				    $sessname = 'subtotal_hideInnerLines_supplier_proposal';
626
				    $sessname2 = 'subtotal_hidedetails_supplier_proposal';
627
				    $sessname3 = 'subtotal_hideprices_supplier_proposal';
628
				}
629
				elseif(in_array('ordercard',explode(':',$parameters['context']))) {
630
					$sessname = 'subtotal_hideInnerLines_commande';
631
					$sessname2 = 'subtotal_hidedetails_commande';	
632
					$sessname3 = 'subtotal_hideprices_commande';
633
				}
634
				elseif(in_array('ordersuppliercard',explode(':',$parameters['context']))) {
635
				    $sessname = 'subtotal_hideInnerLines_commande_fournisseur';
636
				    $sessname2 = 'subtotal_hidedetails_commande_fournisseur';
637
				    $sessname3 = 'subtotal_hideprices_commande_fournisseur';
638
				}
639
				else {
640
					$sessname = 'subtotal_hideInnerLines_unknown';
641
					$sessname2 = 'subtotal_hidedetails_unknown';
642
					$sessname3 = 'subtotal_hideprices_unknown';
643
				}
644
					
645
				global $hideprices;
646
				
647
				$hideInnerLines = (int)GETPOST('hideInnerLines');
648
				if(!empty($_SESSION[$sessname]) && !is_array($_SESSION[$sessname][$object->id]) ) $_SESSION[$sessname] = array(); // prevent old system
649
				$_SESSION[$sessname][$object->id] = $hideInnerLines;		
650
				
651
				$hidedetails= (int)GETPOST('hidedetails');
652
				if(!empty($_SESSION[$sessname2]) && !is_array($_SESSION[$sessname2][$object->id]) ) $_SESSION[$sessname2] = array(); // prevent old system
653
				$_SESSION[$sessname2][$object->id] = $hidedetails;
654
				
655
				$hideprices= (int)GETPOST('hideprices');
656
				if(!empty($_SESSION[$sessname3]) && !is_array($_SESSION[$sessname3][$object->id]) ) $_SESSION[$sessname3] = array(); // prevent old system
657
				$_SESSION[$sessname3][$object->id] = $hideprices;
658
				
659
				foreach($object->lines as &$line) {
660
					if ($line->product_type == 9 && $line->special_code == $this->module_number) {
661
					    
662
                        if($line->qty>=90) {
663
                            $line->modsubtotal_total = 1;
664
                        }
665
                        else{
666
                            $line->modsubtotal_title = 1;
667
                        }
668
                        
669
						$line->total_ht = $this->getTotalLineFromObject($object, $line, '');
670
					}
671
	        	}
672
	        }
673
			
674
		}
675
		else if($action === 'confirm_delete_all_lines' && GETPOST('confirm')=='yes') {
676
			
677
			$Tab = $this->getArrayOfLineForAGroup($object, GETPOST('lineid'));
678
			
679
			foreach($Tab as $idLine) {
680
				/**
681
				 * @var $object Facture
682
				 */
683
				if($object->element=='facture') $object->deleteline($idLine);
684
				/**
685
				 * @var $object Facture fournisseur
686
				 */
687
				else if($object->element=='invoice_supplier')
688
				{
689
				    $object->deleteline($idLine);
690
				}
691
				/**
692
				 * @var $object Propal
693
				 */
694
				else if($object->element=='propal') $object->deleteline($idLine);
695
				/**
696
				 * @var $object Propal Fournisseur
697
				 */
698
				else if($object->element=='supplier_proposal') $object->deleteline($idLine);
699
				/**
700
				 * @var $object Commande
701
				 */
702
				else if($object->element=='commande') 
703
				{
704
					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...
705
					else $object->deleteline($idLine);
706
				}
707
				/**
708
				 * @var $object Commande fournisseur
709
				 */
710
				else if($object->element=='order_supplier')
711
				{
712
				    $object->deleteline($idLine);
713
				}
714
				/**
715
				 * @var $object Facturerec
716
				 */
717
				else if($object->element=='facturerec') $object->deleteline($idLine);
718
			}
719
			
720
			header('location:?id='.$object->id);
721
			exit;
722
			
723
		}
724
		else if ($action == 'duplicate')
725
		{
726
			$lineid = GETPOST('lineid', 'int');
727
			$nbDuplicate = TSubtotal::duplicateLines($object, $lineid, true);
728
			
729
			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

729
			if ($nbDuplicate > 0) /** @scrutinizer ignore-call */ setEventMessage($langs->trans('subtotal_duplicate_success', $nbDuplicate));
Loading history...
730
			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...
731
			else setEventMessage($langs->trans('subtotal_duplicate_error'), 'errors');
732
			
733
			header('Location: ?id='.$object->id);
734
			exit;
735
		}
736
		
737
		return 0;
738
	}
739
	
740
	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

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

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

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

740
	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...
741
		return 0;
742
	}
743
	
744
	function changeRoundingMode($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

744
	function changeRoundingMode($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

744
	function changeRoundingMode($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...
745
	{
746
		global $conf;
747
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && !empty($object->table_element_line) && in_array($object->element, array('commande', 'facture', 'propal')))
748
		{
749
			if ($object->element == 'commande')
750
				$obj = new OrderLine($object->db);
0 ignored issues
show
Bug introduced by
The type OrderLine was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
751
			if ($object->element == 'propal')
752
				$obj = new PropaleLigne($object->db);
0 ignored issues
show
Bug introduced by
The type PropaleLigne was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
753
			if ($object->element == 'facture')
754
				$obj = new FactureLigne($object->db);
0 ignored issues
show
Bug introduced by
The type FactureLigne was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
755
			if (!empty($parameters['fk_element']))
756
			{
757
				
758
				if($obj->fetch($parameters['fk_element'])){
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $obj does not seem to be defined for all execution paths leading up to this point.
Loading history...
759
					$obj->id= $obj->rowid;
760
					if (empty($obj->array_options))
761
						$obj->fetch_optionals();
762
					if (!empty($obj->array_options['options_subtotal_nc']))
763
						return 1;
764
				}
765
			}
766
		}
767
768
		return 0;
769
	}
770
771
	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...
772
		$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...
773
		$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...
774
		
775
		$qty_line = 0;
776
		
777
		$found = false;
778
779
		$Tab= array();
780
		
781
		foreach($object->lines as $l) {
782
		
783
		    $lid = (!empty($l->rowid) ? $l->rowid : $l->id);
784
			if($lid == $lineid) {
785
786
				$found = true;
787
				$qty_line = $l->qty;
788
			}
789
			
790
			if($found) {
791
				
792
			    $Tab[] = (!empty($l->rowid) ? $l->rowid : $l->id);
793
				
794
				if($l->special_code==$this->module_number && (($l->qty==99 && $qty_line==1) || ($l->qty==98 && $qty_line==2))   ) {
795
					break; // end of story
796
				}
797
			}
798
			
799
			
800
		}
801
		
802
		
803
		return $Tab;
804
		
805
	}
806
807
	/**
808
	 *  TODO le calcul est faux dans certains cas,  exemple :
809
	 *	T1
810
	 *		|_ l1 => 50 €
811
	 *		|_ l2 => 40 €
812
	 *		|_ T2
813
	 *			|_l3 => 100 €
814
	 *		|_ ST2
815
	 *		|_ l4 => 23 €
816
	 *	|_ ST1
817
	 * 
818
	 * On obtiens ST2 = 100 ET ST1 = 123 €
819
	 * Alors qu'on devrais avoir ST2 = 100 ET ST1 = 213 €
820
	 * 
821
	 * @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...
822
	 */
823
	function getTotalLineFromObject(&$object, &$line, $use_level=false, $return_all=0) {
0 ignored issues
show
Unused Code introduced by
The parameter $use_level is not used and could be removed. ( Ignorable by Annotation )

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

823
	function getTotalLineFromObject(&$object, &$line, /** @scrutinizer ignore-unused */ $use_level=false, $return_all=0) {

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

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
824
		global $conf;
825
		
826
		$rang = $line->rang;
827
		$qty_line = $line->qty;
828
		
829
		$total = 0;
830
		$total_tva = 0;
831
		$total_ttc = 0;
832
		$TTotal_tva = array();
833
		
834
		$sign=1;
835
		if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
836
		
837
		if (GETPOST('action') == 'builddoc') $builddoc = true;
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

837
		if (/** @scrutinizer ignore-call */ GETPOST('action') == 'builddoc') $builddoc = true;
Loading history...
838
		else $builddoc = false;
839
		
840
		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

840
		/** @scrutinizer ignore-call */ 
841
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
841
		foreach($object->lines as $l) {
842
			//print $l->rang.'>='.$rang.' '.$total.'<br/>';
843
			if($l->rang>=$rang) {
844
				//echo 'return!<br>';
845
				if (!$return_all) return $total;
846
				else return array($total, $total_tva, $total_ttc, $TTotal_tva);
847
			}
848
			else if(TSubtotal::isTitle($l, 100 - $qty_line)) 
849
		  	{
850
				$total = 0;
851
				$total_tva = 0;
852
				$total_ttc = 0;
853
				$TTotal_tva = array();
854
			}
855
			elseif(!TSubtotal::isTitle($l) && !TSubtotal::isSubtotal($l)) {
856
				
857
				// TODO retirer le test avec $builddoc quand Dolibarr affichera le total progression sur la card et pas seulement dans le PDF
858
				if ($builddoc && $object->element == 'facture' && $object->type==Facture::TYPE_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...
859
				{
860
					if ($l->situation_percent > 0)
861
					{
862
						$prev_progress = 0;
863
						$progress = 1;
864
						if (method_exists($l, 'get_prev_progress'))
865
						{
866
							$prev_progress = $l->get_prev_progress($object->id);
867
							$progress = ($l->situation_percent - $prev_progress) / 100;
868
						}
869
						
870
						$result = $sign * ($l->total_ht / ($l->situation_percent / 100)) * $progress;
871
						$total+= $result;
872
						// TODO check si les 3 lignes du dessous sont corrects
873
						$total_tva += $sign * ($l->total_tva / ($l->situation_percent / 100)) * $progress;
874
						$TTotal_tva[$l->tva_tx] += $sign * ($l->total_tva / ($l->situation_percent / 100)) * $progress;
875
						$total_ttc += $sign * ($l->total_tva / ($l->total_ttc / 100)) * $progress;
876
					}
877
				}
878
				else
879
				{
880
					$total += $l->total_ht;
881
					$total_tva += $l->total_tva;
882
					$TTotal_tva[$l->tva_tx] += $l->total_tva;
883
					$total_ttc += $l->total_ttc;
884
				}
885
			}
886
			
887
		}
888
		if (!$return_all) return $total;
889
		else return array($total, $total_tva, $total_ttc, $TTotal_tva);
890
	}
891
892
	/**
893
	 * @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...
894
	 * @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...
895
	 * @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...
896
	 * @param $label        string
897
	 * @param $description  string
898
	 * @param $posx         float               horizontal position
899
	 * @param $posy         float               vertical position
900
	 * @param $w            float               width
901
	 * @param $h            float               height
902
	 */
903
	function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) {
0 ignored issues
show
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

903
	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...
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...
904
		global $conf,$subtotal_last_title_posy;
905
906
		$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

906
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
907
		if (!empty($conf->global->SUBTOTAL_ONE_LINE_IF_HIDE_INNERLINES) && $hideInnerLines && !empty($subtotal_last_title_posy))
908
		{
909
			$posy = $subtotal_last_title_posy;
910
			$subtotal_last_title_posy = null;
911
		}
912
		
913
		$hidePriceOnSubtotalLines = (int) GETPOST('hide_price_on_subtotal_lines');
914
		
915
		$set_pagebreak_margin = false;
916
		if(method_exists('Closure','bind')) {
917
			$pageBreakOriginalValue = $pdf->AcceptPageBreak();
918
			$sweetsThief = function ($pdf) {
919
		    		return $pdf->bMargin ;
920
			};
921
			$sweetsThief = Closure::bind($sweetsThief, null, $pdf);
922
	
923
			$bMargin  = $sweetsThief($pdf);
924
	
925
			$pdf->SetAutoPageBreak( false );
926
927
			$set_pagebreak_margin = true;			
928
		}
929
		
930
			
931
		if($line->qty==99)
932
			$pdf->SetFillColor(220,220,220);
933
		elseif ($line->qty==98)
934
			$pdf->SetFillColor(230,230,230);
935
		else
936
			$pdf->SetFillColor(240,240,240);
937
		
938
		$style = 'B';
939
		if (!empty($conf->global->SUBTOTAL_SUBTOTAL_STYLE)) $style = $conf->global->SUBTOTAL_SUBTOTAL_STYLE;
940
		
941
		$pdf->SetFont('', $style, 9);
942
		
943
		$pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'R',true);
944
//		var_dump($bMargin);
945
		$pageAfter = $pdf->getPage();
0 ignored issues
show
Unused Code introduced by
The assignment to $pageAfter is dead and can be removed.
Loading history...
946
		
947
		//Print background
948
		$cell_height = $pdf->getStringHeight($w, $label);
949
		$pdf->SetXY($posx, $posy);
950
		$pdf->MultiCell($pdf->page_largeur - $pdf->marge_droite, $cell_height, '', 0, '', 1);
951
		
952
		if (!$hidePriceOnSubtotalLines) {
953
			$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

953
			$total_to_print = /** @scrutinizer ignore-call */ price($line->total);
Loading history...
954
			
955
			if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS))
956
			{
957
				$TTitle = TSubtotal::getAllTitleFromLine($line);
958
				foreach ($TTitle as &$line_title)
959
				{
960
					if (!empty($line_title->array_options['options_subtotal_nc']))
961
					{
962
						$total_to_print = ''; // TODO Gestion "Compris/Non compris", voir si on affiche une annotation du genre "NC"
963
						break;
964
					}
965
				}
966
			}
967
			
968
			
969
			
970
			
971
			if($total_to_print !== '') {
972
				
973
				if (GETPOST('hideInnerLines'))
974
				{
975
					// 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
976
//					$line->TTotal_tva
977
//					$line->total_ht
978
//					$line->total_tva
979
//					$line->total
980
//					$line->total_ttc
981
				}
982
				else
983
				{
984
					list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
985
					$total_to_print = price($total);
986
					
987
                    $line->total_ht = $total;
988
					$line->total = $total;
989
					$line->total_tva = $total_tva;
990
					$line->total_ttc = $total_ttc;
991
				}
992
			}
993
994
			$pdf->SetXY($pdf->postotalht, $posy);
995
			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...
996
			$pdf->MultiCell($pdf->page_largeur-$pdf->marge_droite-$pdf->postotalht, 3, $total_to_print, 0, 'R', 0);
997
		}
998
		else{
999
			if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin);
1000
		}
1001
		
1002
		$posy = $posy + $cell_height;
1003
		$pdf->SetXY($posx, $posy); 
1004
			
1005
		
1006
	}
1007
1008
	/**
1009
	 * @param $pdf          TCPDF               PDF object
1010
	 * @param $object       CommonObject        dolibarr object
1011
	 * @param $line         CommonObjectLine    dolibarr object line
1012
	 * @param $label        string
1013
	 * @param $description  string
1014
	 * @param $posx         float               horizontal position
1015
	 * @param $posy         float               vertical position
1016
	 * @param $w            float               width
1017
	 * @param $h            float               height
1018
	 */
1019
	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

1019
	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...
1020
		
1021
		global $db,$conf,$subtotal_last_title_posy;
1022
		
1023
		$subtotal_last_title_posy = $posy;
1024
		$pdf->SetXY ($posx, $posy);
1025
		
1026
		$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

1026
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1027
		
1028
		
1029
 
1030
		$style = ($line->qty==1) ? 'BU' : 'BUI';
1031
		if (!empty($conf->global->SUBTOTAL_TITLE_STYLE)) $style = $conf->global->SUBTOTAL_TITLE_STYLE;
1032
		
1033
		if($hideInnerLines) {
1034
			if($line->qty==1)$pdf->SetFont('', $style, 9);
1035
			else 
1036
			{
1037
				if (!empty($conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES)) $style = $conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES;
1038
				$pdf->SetFont('', $style, 9);
1039
			}
1040
		}
1041
		else {
1042
1043
			if($line->qty==1)$pdf->SetFont('', $style, 9); //TODO if super utile
1044
			else $pdf->SetFont('', $style, 9);
1045
			
1046
		}
1047
		
1048
		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

1048
		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...
1049
		else $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'J',true); // et maintenant avec du HTML
1050
		
1051
		if($description && !$hidedesc) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $hidedesc seems to be never defined.
Loading history...
1052
			$posy = $pdf->GetY();
1053
			
1054
			$pdf->SetFont('', '', 8);
1055
			
1056
			$pdf->writeHTMLCell($w, $h, $posx, $posy, $description, 0, 1, false, true, 'J',true);
1057
1058
		}
1059
		
1060
	}
1061
1062
	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...
1063
	// ultimate PDF hook O_o
1064
		
1065
		return $this->pdf_writelinedesc($parameters,$object,$action);
1066
		
1067
	}
1068
1069
	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...
1070
		
1071
		if(is_array($parameters)) {
1072
			$i = & $parameters['i'];	
1073
		}
1074
		else {
1075
			$i = (int)$parameters;
1076
		}
1077
		
1078
		
1079
		if($object->lines[$i]->special_code == $this->module_number && $object->lines[$i]->product_type == 9) {
1080
			return true;
1081
		}
1082
		
1083
		return false;
1084
		
1085
	}
1086
1087
	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

1087
	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...
1088
		global $conf,$hideprices;
1089
		
1090
		if($this->isModSubtotalLine($parameters,$object) ){
1091
			
1092
			$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...
1093
			
1094
			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...
1095
				return '';
1096
			}
1097
			else if((float)DOL_VERSION>=3.8) {
1098
				return 1;
1099
			}
1100
			
1101
		}
1102
		elseif(!empty($hideprices)) {
1103
			$this->resprints = $object->lines[$parameters['i']]->qty;
1104
			return 1;
1105
		}
1106
		elseif (!empty($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY))
1107
		{
1108
			$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

1108
			$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1109
			$hidedetails = (int)GETPOST('hidedetails');
1110
			if (empty($hideInnerLines) && !empty($hidedetails))
1111
			{
1112
				$this->resprints = $object->lines[$parameters['i']]->qty;
1113
			}
1114
		}
1115
		
1116
		if(is_array($parameters)) $i = & $parameters['i'];
1117
		else $i = (int)$parameters;
1118
1119
		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)
1120
		
1121
		if(empty($object->lines[$i]->array_options)) $object->lines[$i]->fetch_optionals();
1122
1123
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1124
		{
1125
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1126
			{
1127
				$this->resprints = ' ';
1128
				return 1;
1129
			}
1130
		}
1131
		
1132
		return 0;
1133
	}
1134
	
1135
	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...
1136
	    global $conf, $hideprices, $hookmanager;
1137
		
1138
		if(is_array($parameters)) $i = & $parameters['i'];
1139
		else $i = (int)$parameters;
1140
			
1141
		if($this->isModSubtotalLine($parameters,$object) ){
1142
			
1143
			$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...
1144
			
1145
			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...
1146
				return '';
1147
			}
1148
			else if((float)DOL_VERSION>=3.8) {
1149
				return 1;
1150
			}
1151
			
1152
		}
1153
		elseif (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS))
1154
		{
1155
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1156
			{
1157
				if (!empty($object->lines[$i]->array_options['options_subtotal_nc'])) 
1158
				{
1159
					$this->resprints = ' ';
1160
					return 1;
1161
				}
1162
1163
				$TTitle = TSubtotal::getAllTitleFromLine($object->lines[$i]);
1164
				foreach ($TTitle as &$line_title)
1165
				{
1166
					if (!empty($line_title->array_options['options_subtotal_nc']))
1167
					{
1168
						$this->resprints = ' ';
1169
						return 1;
1170
					}
1171
				}
1172
			}
1173
		}
1174
		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

1174
		if ((int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines') && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES)){
Loading history...
1175
		    $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

1175
		    $this->resprints = /** @scrutinizer ignore-call */ price($object->lines[$i]->total_ht);
Loading history...
1176
		}
1177
		
1178
		// Si la gestion C/NC est active et que je suis sur un ligne dont l'extrafield est coché
1179
		if ( 
1180
			!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && 
1181
			(!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) 
1182
		)
1183
		{
1184
			// alors je dois vérifier si la méthode fait partie de la conf qui l'exclue
1185
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1186
			{
1187
				$this->resprints = ' ';
1188
				
1189
				// currentcontext à modifier celon l'appel
1190
				$params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinetotalexcltax', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i);
1191
				return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1)
1192
			}
1193
		}
1194
		// Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble
1195
		else if (!empty($hideprices))
1196
		{
1197
			// Check if a title exist for this line && if the title have subtotal
1198
			$lineTitle = TSubtotal::getParentTitleOfLine($object, $i);
1199
			if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, $lineTitle, true))
0 ignored issues
show
Bug introduced by
It seems like $lineTitle can also be of type false; however, parameter $title_line of TSubtotal::titleHasTotalLine() does only seem to accept FactureLigne|OrderLine|PropaleLigne, maybe add an additional type check? ( Ignorable by Annotation )

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

1199
			if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, /** @scrutinizer ignore-type */ $lineTitle, true))
Loading history...
1200
			{
1201
1202
				$this->resprints = ' ';
1203
				
1204
				// currentcontext à modifier celon l'appel
1205
				$params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinetotalexcltax', 'currentcontext'=>'subtotal_hideprices', 'i' => $i);
1206
				return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1)
1207
			}
1208
		}
1209
        
1210
		return 0;
1211
	}
1212
	
1213
	/**
1214
	 * Remplace le retour de la méthode qui l'appelle par un standard 1 ou autre chose celon le hook
1215
	 * @return int 1, 0, -1
1216
	 */
1217
	private function callHook(&$object, &$hookmanager, $action, $params, $defaultReturn = 1)
1218
	{
1219
		$reshook=$hookmanager->executeHooks('subtotalHidePrices',$params, $object, $action);
1220
		if ($reshook < 0)
1221
		{
1222
			$this->error = $hookmanager->error;
0 ignored issues
show
Bug Best Practice introduced by
The property error does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1223
			$this->errors = $hookmanager->errors;
0 ignored issues
show
Bug Best Practice introduced by
The property errors does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1224
			return -1;
1225
		}
1226
		elseif (empty($reshook))
1227
		{
1228
			$this->resprints .= $hookmanager->resprints;
1229
		}
1230
		else
1231
		{
1232
			$this->resprints = $hookmanager->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...
1233
1234
			// override return (use  $this->results['overrideReturn'] or $this->resArray['overrideReturn'] in other module action_xxxx.class.php )
1235
			if(isset($hookmanager->resArray['overrideReturn']))
1236
			{
1237
				return $hookmanager->resArray['overrideReturn'];
1238
			}
1239
		}
1240
1241
		return $defaultReturn;
1242
	}
1243
	
1244
	function pdf_getlinetotalwithtax($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

1244
	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...
1245
		global $conf;
1246
		
1247
		if($this->isModSubtotalLine($parameters,$object) ){
1248
			
1249
			$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...
1250
		
1251
			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...
1252
				return '';
1253
			}
1254
			else if((float)DOL_VERSION>=3.8) {
1255
				return 1;
1256
			}
1257
		}
1258
		
1259
		if(is_array($parameters)) $i = & $parameters['i'];
1260
		else $i = (int)$parameters;
1261
		
1262
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) 
1263
		{
1264
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1265
			{
1266
				$this->resprints = ' ';
1267
				return 1;
1268
			}
1269
		}
1270
		
1271
		return 0;
1272
	}
1273
	
1274
	function pdf_getlineunit($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

1274
	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...
1275
		global $conf;
1276
		
1277
		if($this->isModSubtotalLine($parameters,$object) ){
1278
			$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...
1279
		
1280
			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...
1281
				return '';
1282
			}
1283
			else if((float)DOL_VERSION>=3.8) {
1284
				return 1;
1285
			}
1286
		}
1287
		
1288
		if(is_array($parameters)) $i = & $parameters['i'];
1289
		else $i = (int)$parameters;
1290
			
1291
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1292
		{
1293
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1294
			{
1295
				$this->resprints = ' ';
1296
				return 1;
1297
			}
1298
		}
1299
		
1300
		return 0;
1301
	}
1302
	
1303
	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...
1304
	    global $conf,$hideprices,$hookmanager;
1305
1306
		if(is_array($parameters)) $i = & $parameters['i'];
1307
		else $i = (int)$parameters;
1308
1309
		if($this->isModSubtotalLine($parameters,$object) ) {
1310
			$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...
1311
1312
            $line = $object->lines[$i];
1313
1314
            // On récupère les montants du bloc pour les afficher dans la ligne de sous-total
1315
            if(TSubtotal::isSubtotal($line)) {
1316
                $parentTitle = TSubtotal::getParentTitleOfLine($object, $i);
1317
1318
                if(! empty($parentTitle->array_options['options_show_total_ht'])) {
1319
                    $TTotal = TSubtotal::getTotalBlockFromTitle($object, $parentTitle);
1320
                    $this->resprints = price($TTotal['total_subprice']);
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

1320
                    $this->resprints = /** @scrutinizer ignore-call */ price($TTotal['total_subprice']);
Loading history...
1321
                }
1322
            }
1323
		
1324
			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...
1325
				return '';
1326
			}
1327
			else if((float)DOL_VERSION>=3.8) {
1328
				return 1;
1329
			}
1330
		}
1331
		
1332
		// Si la gestion C/NC est active et que je suis sur un ligne dont l'extrafield est coché
1333
		if (
1334
		!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) &&
1335
		(!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i]))
1336
		)
1337
		{
1338
		    // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue
1339
		    if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1340
		    {
1341
		        $this->resprints = ' ';
1342
		        
1343
		        // currentcontext à modifier celon l'appel
1344
		        $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i);
1345
		        return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1)
1346
		        
1347
		    }
1348
		}
1349
		// Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble
1350
		else if (!empty($hideprices))
1351
		{
1352
		    
1353
		    // Check if a title exist for this line && if the title have subtotal
1354
		    $lineTitle = TSubtotal::getParentTitleOfLine($object, $i);
1355
		    if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, $lineTitle, true))
0 ignored issues
show
Bug introduced by
It seems like $lineTitle can also be of type false; however, parameter $title_line of TSubtotal::titleHasTotalLine() does only seem to accept FactureLigne|OrderLine|PropaleLigne, maybe add an additional type check? ( Ignorable by Annotation )

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

1355
		    if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, /** @scrutinizer ignore-type */ $lineTitle, true))
Loading history...
1356
		    {
1357
		        
1358
		        $this->resprints = ' ';
1359
		        
1360
		        // currentcontext à modifier celon l'appel
1361
		        $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext'=>'subtotal_hideprices', 'i' => $i);
1362
		        return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1)
1363
		    }
1364
		}
1365
		
1366
		return 0;
1367
	}
1368
	
1369
	function pdf_getlineremisepercent($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

1369
	function pdf_getlineremisepercent($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...
1370
	    global $conf,$hideprices,$hookmanager;
1371
1372
        if(is_array($parameters)) $i = & $parameters['i'];
1373
        else $i = (int) $parameters;
1374
1375
		if($this->isModSubtotalLine($parameters,$object) ) {
1376
			$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...
1377
1378
            $line = $object->lines[$i];
1379
1380
            // Affichage de la remise 
1381
            if(TSubtotal::isSubtotal($line)) {
1382
                $parentTitle = TSubtotal::getParentTitleOfLine($object, $i);
1383
1384
                if(! empty($parentTitle->array_options['options_show_reduc'])) {
1385
                    $TTotal = TSubtotal::getTotalBlockFromTitle($object, $parentTitle);
1386
                    $this->resprints = price($TTotal['total_ht'] / $TTotal['total_subprice']*100, 0, '', 1, 2, 2).'%';
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

1386
                    $this->resprints = /** @scrutinizer ignore-call */ price($TTotal['total_ht'] / $TTotal['total_subprice']*100, 0, '', 1, 2, 2).'%';
Loading history...
1387
                }
1388
            }
1389
		
1390
			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...
1391
				return '';
1392
			}
1393
			else if((float)DOL_VERSION>=3.8) {
1394
				return 1;
1395
			}
1396
		}
1397
		elseif (!empty($hideprices)
1398
		        || (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1399
		        )
1400
		    {
1401
		        if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1402
		        {
1403
		            $this->resprints = ' ';
1404
		            return 1;
1405
		        }
1406
		    }
1407
		
1408
		return 0;
1409
	}
1410
	
1411
	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

1411
	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...
1412
		global $conf,$hideprices;
1413
		
1414
		if($this->isModSubtotalLine($parameters,$object) ){
1415
			$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...
1416
			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...
1417
				return '';
1418
			}
1419
			else if((float)DOL_VERSION>=3.8) {
1420
				return 1;
1421
			}
1422
		}
1423
		
1424
		if(is_array($parameters)) $i = & $parameters['i'];
1425
		else $i = (int)$parameters;
1426
			
1427
		if (!empty($hideprices)
1428
				|| (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1429
		)
1430
		{
1431
			if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1432
			{
1433
				$this->resprints = ' ';
1434
				return 1;
1435
			}
1436
		}
1437
		
1438
		return 0;
1439
	}
1440
	
1441
	function pdf_getlinevatrate($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
1442
	    global $conf,$hideprices,$hookmanager;
1443
	    
1444
		if($this->isModSubtotalLine($parameters,$object) ){
1445
			$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...
1446
			
1447
			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...
1448
				return '';
1449
			}
1450
			else if((float)DOL_VERSION>=3.8) {
1451
				return 1;
1452
			}
1453
		}
1454
		
1455
		if(is_array($parameters)) $i = & $parameters['i'];
1456
		else $i = (int)$parameters;
1457
		
1458
		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)
1459
1460
		$object->lines[$i]->fetch_optionals();
1461
		// Si la gestion C/NC est active et que je suis sur un ligne dont l'extrafield est coché
1462
		if (
1463
		!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) &&
1464
		(!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i]))
1465
		)
1466
		{
1467
		    // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue
1468
		    if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1469
		    {
1470
		        $this->resprints = ' ';
1471
		        
1472
		        // currentcontext à modifier celon l'appel
1473
		        $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i);
1474
		        return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1)
1475
		    }
1476
		}
1477
		// Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble
1478
		else if (!empty($hideprices))
1479
		{
1480
		    
1481
		    // Check if a title exist for this line && if the title have subtotal
1482
		    $lineTitle = TSubtotal::getParentTitleOfLine($object, $i);
1483
		    if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, $lineTitle, true))
0 ignored issues
show
Bug introduced by
It seems like $lineTitle can also be of type false; however, parameter $title_line of TSubtotal::titleHasTotalLine() does only seem to accept FactureLigne|OrderLine|PropaleLigne, maybe add an additional type check? ( Ignorable by Annotation )

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

1483
		    if(TSubtotal::getParentTitleOfLine($object, $i) && TSubtotal::titleHasTotalLine($object, /** @scrutinizer ignore-type */ $lineTitle, true))
Loading history...
1484
		    {
1485
		        
1486
		        $this->resprints = ' ';
1487
		        
1488
		        // currentcontext à modifier celon l'appel
1489
		        $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hideprices', 'i' => $i);
1490
		        return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1)
1491
		    }
1492
		}
1493
		
1494
		return 0;
1495
	}
1496
		
1497
	function pdf_getlineprogress($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

1497
	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...
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...
1498
		global $conf;
1499
		
1500
		if($this->isModSubtotalLine($parameters,$object) ){
1501
			$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...
1502
			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...
1503
				return '';
1504
			}
1505
			else if((float)DOL_VERSION>=3.8) {
1506
				return 1;
1507
			}
1508
		}
1509
		
1510
		if(is_array($parameters)) $i = & $parameters['i'];
1511
		else $i = (int)$parameters;
1512
			
1513
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1514
		{
1515
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1516
			{
1517
				$this->resprints = ' ';
1518
				return 1;
1519
			}
1520
		}
1521
		
1522
		return 0;
1523
	}
1524
	
1525
	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...
1526
		global $conf;
1527
		
1528
		if(!empty($conf->global->SUBTOTAL_USE_NUMEROTATION)) {
1529
		
1530
			$TLevelTitre = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $TLevelTitre is dead and can be removed.
Loading history...
1531
			$prevlevel = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $prevlevel is dead and can be removed.
Loading history...
1532
		
1533
			foreach($object->lines as $k=>&$line) 
1534
			{
1535
				if ($line->id > 0 && $this->isModSubtotalLine($k, $object) && $line->qty <= 10)
1536
				{
1537
					$TLineTitle[] = &$line;
1538
				}
1539
			}
1540
			
1541
			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...
1542
		}
1543
		
1544
	}
1545
1546
	// TODO ne gère pas encore la numération des lignes "Totaux"
1547
	private function formatNumerotation(&$TLineTitle, $line_reference='', $level=1, $prefix_num=0)
1548
	{
1549
		$TTitle = array();
1550
		
1551
		$i=1;
1552
		$j=0;
1553
		foreach ($TLineTitle as $k => &$line)
1554
		{
1555
			if (!empty($line_reference) && $line->rang <= $line_reference->rang) continue;
1556
			if (!empty($line_reference) && $line->qty <= $line_reference->qty) break;
1557
			
1558
			if ($line->qty == $level)
1559
			{
1560
				$TTitle[$j]['numerotation'] = ($prefix_num == 0) ? $i : $prefix_num.'.'.$i;
1561
				//var_dump('Prefix == '.$prefix_num.' // '.$line->desc.' ==> numerotation == '.$TTitle[$j]['numerotation'].'   ###    '.$line->qty .'=='. $level);
1562
				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...
1563
				{
1564
					$line->label = !empty($line->desc) ? $line->desc : $line->description;
1565
					$line->desc = $line->description = '';
1566
				}
1567
				
1568
				$line->label = $TTitle[$j]['numerotation'].' '.$line->label;
1569
				$TTitle[$j]['line'] = &$line;
1570
				
1571
				$deep_level = $line->qty;
1572
				do {
1573
					$deep_level++;
1574
					$TTitle[$j]['children'] = $this->formatNumerotation($TLineTitle, $line, $deep_level, $TTitle[$j]['numerotation']);
1575
				} 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
1576
				// Rappel on peux avoir jusqu'a 10 niveau de titre
1577
				
1578
				$i++;
1579
				$j++;
1580
			}
1581
		}
1582
1583
		return $TTitle;
1584
	}
1585
	
1586
	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

1586
	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

1586
	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...
1587
		
1588
		$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

1588
		$hidedetails = (int)/** @scrutinizer ignore-call */ GETPOST('hidedetails');
Loading history...
1589
		
1590
		if(empty($hidedetails)) return false;
1591
		
1592
		// TODO can't add VAT to document without lines... :-/
1593
		
1594
		return true;
1595
	}
1596
	
1597
	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

1597
	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...
1598
	{
1599
		/**
1600
		 * @var $pdf    TCPDF
1601
		 */
1602
		global $pdf,$conf, $langs;
1603
1604
		// var_dump($object->lines);
1605
		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

1605
		/** @scrutinizer ignore-call */ 
1606
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
1606
1607
		foreach($parameters as $key=>$value) {
1608
			${$key} = $value;
1609
		}
1610
		
1611
		$this->setDocTVA($pdf, $object);
1612
		
1613
		$this->add_numerotation($object);	
1614
		
1615
        foreach($object->lines as $k => &$l) {
1616
            if(TSubtotal::isSubtotal($l)) {
1617
                $parentTitle = TSubtotal::getParentTitleOfLine($object, $k);
1618
                if(! empty($parentTitle->id) && ! empty($parentTitle->array_options['options_show_total_ht'])) {
1619
                    $l->remise_percent = 100;    // Affichage de la réduction sur la ligne de sous-total
1620
                }
1621
            }
1622
        }
1623
1624
		$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

1624
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1625
		$hidedetails = (int)GETPOST('hidedetails');
1626
1627
		if ($hideInnerLines) { // si c une ligne de titre
1628
	    	$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...
1629
			$TLines =array();
1630
		
1631
			$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...
1632
		    $TTvas = array(); // tableau de tva
1633
		    
1634
			foreach($object->lines as $k=>&$line) 
1635
			{
1636
			    
1637
				if($line->product_type==9 && $line->rowid>0) 
1638
				{
1639
					$fk_parent_line = $line->rowid;
1640
					
1641
					// 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
1642
					if(TSubtotal::isSubtotal($line)) 
1643
					{
1644
						/*$total = $this->getTotalLineFromObject($object, $line, '');
1645
						
1646
						$line->total_ht = $total;
1647
						$line->total = $total;
1648
						*/
1649
						list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
1650
						
1651
						if (TSubtotal::getNiveau($line) == 1) $line->TTotal_tva = $TTotal_tva;
1652
						$line->total_ht = $total;
1653
						$line->total_tva = $total_tva;
1654
						$line->total = $line->total_ht;
1655
						$line->total_ttc = $total_ttc;
1656
1657
//                        $TTitle = TSubtotal::getParentTitleOfLine($object, $k);
1658
//                        $parentTitle = array_shift($TTitle);
1659
//                        if(! empty($parentTitle->id) && ! empty($parentTitle->array_option['options_show_total_ht'])) {
1660
//                            exit('la?');
1661
//                            $line->remise_percent = 100;    // Affichage de la réduction sur la ligne de sous-total
1662
//                            $line->update();
1663
//                        }
1664
					} 
1665
//                    if(TSub)
1666
						
1667
				} 
1668
			
1669
				if ($hideInnerLines)
1670
				{
1671
				    if(!empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES))
1672
				    {
1673
				        if($line->tva_tx != '0.000' && $line->product_type!=9){
1674
				            
1675
    				        // on remplit le tableau de tva pour substituer les lignes cachées
1676
    				        $TTvas[$line->tva_tx]['total_tva'] += $line->total_tva;
1677
    				        $TTvas[$line->tva_tx]['total_ht'] += $line->total_ht;
1678
    				        $TTvas[$line->tva_tx]['total_ttc'] += $line->total_ttc; 
1679
    				    }
1680
    					if($line->product_type==9 && $line->rowid>0)
1681
    					{
1682
    					    //Cas où je doit cacher les produits et afficher uniquement les sous-totaux avec les titres
1683
    					    // génère des lignes d'affichage des montants HT soumis à tva
1684
    					    $nbtva = count($TTvas);
1685
    					    if(!empty($nbtva)){
1686
    					        foreach ($TTvas as $tx =>$val){
1687
    					            $l = clone $line;
1688
    					            $l->product_type = 1;
1689
    					            $l->special_code = '';
1690
    					            $l->qty = 1;
1691
    					            $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

1691
    					            $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), /** @scrutinizer ignore-call */ price($tx));
Loading history...
1692
    					            $l->tva_tx = $tx;
1693
    					            $l->total_ht = $val['total_ht'];
1694
    					            $l->total_tva = $val['total_tva'];
1695
    					            $l->total = $line->total_ht;
1696
    					            $l->total_ttc = $val['total_ttc'];
1697
    					            $TLines[] = $l;
1698
    					            array_shift($TTvas);
1699
    					       }
1700
    					    }
1701
    					    
1702
    					    // ajoute la ligne de sous-total
1703
    					    $TLines[] = $line; 
1704
    					}
1705
				    } else {
1706
				        
1707
				        if($line->product_type==9 && $line->rowid>0)
1708
				        {
1709
				            // ajoute la ligne de sous-total
1710
				            $TLines[] = $line; 
1711
				        }
1712
				    }
1713
				    
1714
					
1715
				}
1716
				elseif ($hidedetails)
1717
				{
1718
					$TLines[] = $line; //Cas où je cache uniquement les prix des produits	
1719
				}
1720
				
1721
				if ($line->product_type != 9) { // jusqu'au prochain titre ou total
1722
					//$line->fk_parent_line = $fk_parent_line;
1723
					
1724
				}
1725
			
1726
				/*if($hideTotal) {
1727
					$line->total = 0;
1728
					$line->subprice= 0;
1729
				}*/
1730
				
1731
			}
1732
			
1733
			// cas incongru où il y aurait des produits en dessous du dernier sous-total
1734
			$nbtva = count($TTvas);
1735
			if(!empty($nbtva) && $hideInnerLines && !empty($conf->global->SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES))
1736
			{
1737
			    foreach ($TTvas as $tx =>$val){
1738
			        $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 1634. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
1739
			        $l->product_type = 1;
1740
			        $l->special_code = '';
1741
			        $l->qty = 1;
1742
			        $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx));
1743
			        $l->tva_tx = $tx;
1744
			        $l->total_ht = $val['total_ht'];
1745
			        $l->total_tva = $val['total_tva'];
1746
			        $l->total = $line->total_ht;
1747
			        $l->total_ttc = $val['total_ttc'];
1748
			        $TLines[] = $l;
1749
			        array_shift($TTvas);
1750
			    }
1751
			}
1752
			
1753
			global $nblignes;
1754
			$nblignes=count($TLines);
1755
1756
			$object->lines = $TLines;
1757
			
1758
			if($i>count($object->lines)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $i seems to be never defined.
Loading history...
1759
				$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...
1760
				return 0;
1761
			}
1762
	    }
1763
		
1764
		return 0;
1765
	}
1766
1767
	function pdf_writelinedesc($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

1767
	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...
1768
	{
1769
		/**
1770
		 * @var $pdf    TCPDF
1771
		 */
1772
		global $pdf,$conf;
1773
1774
		foreach($parameters as $key=>$value) {
1775
			${$key} = $value;
1776
		}
1777
		
1778
		$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

1778
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1779
		$hidedetails = (int)GETPOST('hidedetails');
0 ignored issues
show
Unused Code introduced by
The assignment to $hidedetails is dead and can be removed.
Loading history...
1780
		
1781
		if($this->isModSubtotalLine($parameters,$object) ){			
1782
		
1783
				global $hideprices;
1784
				
1785
				if(!empty($hideprices)) {
1786
					foreach($object->lines as &$line) {
1787
						if($line->fk_product_type!=9) $line->fk_parent_line = -1;	
1788
					}
1789
				}
1790
			
1791
				$line = &$object->lines[$i];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $i seems to be never defined.
Loading history...
1792
				
1793
				if($line->info_bits>0) { // PAGE BREAK
1794
					$pdf->addPage();
1795
					$posy = $pdf->GetY();
1796
				}
1797
				
1798
				$label = $line->label;
1799
				$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...
1800
				
1801
				if(empty($label)) {
1802
					$label = $description;
1803
					$description='';
1804
				}
1805
				
1806
				if($line->qty>90) {
1807
					
1808
					if ($conf->global->SUBTOTAL_USE_NEW_FORMAT)	$label .= ' '.$this->getTitle($object, $line);
1809
					
1810
					$pageBefore = $pdf->getPage();
1811
					$this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $posx 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 $h seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $w seems to be never defined.
Loading history...
1812
					$pageAfter = $pdf->getPage();	
1813
1814
					if($pageAfter>$pageBefore) {
1815
						//print "ST $pageAfter>$pageBefore<br>";
1816
						$pdf->rollbackTransaction(true);	
1817
						$pdf->addPage('','', true);
1818
						$posy = $pdf->GetY();
1819
						$this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
1820
						$posy = $pdf->GetY();
0 ignored issues
show
Unused Code introduced by
The assignment to $posy is dead and can be removed.
Loading history...
1821
						//print 'add ST'.$pdf->getPage().'<br />';
1822
					}
1823
				
1824
					$posy = $pdf->GetY();
1825
					return 1;
1826
				}	
1827
				else if ($line->qty < 10) {
1828
					$pageBefore = $pdf->getPage();
0 ignored issues
show
Unused Code introduced by
The assignment to $pageBefore is dead and can be removed.
Loading history...
1829
1830
					$this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); 
1831
					$pageAfter = $pdf->getPage();	
0 ignored issues
show
Unused Code introduced by
The assignment to $pageAfter is dead and can be removed.
Loading history...
1832
1833
					
1834
					/*if($pageAfter>$pageBefore) {
1835
						print "T $pageAfter>$pageBefore<br>";
1836
						$pdf->rollbackTransaction(true);
1837
						$pdf->addPage('','', true);
1838
						print 'add T'.$pdf->getPage().' '.$line->rowid.' '.$pdf->GetY().' '.$posy.'<br />';
1839
						
1840
						$posy = $pdf->GetY();
1841
						$this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h);
1842
						$posy = $pdf->GetY();
1843
					}
1844
				*/
1845
					$posy = $pdf->GetY();
1846
					return 1;
1847
				}
1848
//	if($line->rowid==47) exit;
1849
			
1850
			return 0;
1851
		}
1852
		elseif (empty($object->lines[$parameters['i']]))
1853
		{
1854
			$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...
1855
		}
1856
1857
		/* TODO je desactive parce que je comprends pas PH Style, mais à test
1858
		else {
1859
			
1860
			if($hideInnerLines) {
1861
				$pdf->rollbackTransaction(true);
1862
			}
1863
			else {
1864
				$labelproductservice=pdf_getlinedesc($object, $i, $outputlangs, $hideref, $hidedesc, $issupplierline);
1865
				$pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1);
1866
			}
1867
			
1868
		}*/
1869
1870
1871
		
1872
	}
1873
1874
	/**
1875
	 * Permet de récupérer le titre lié au sous-total
1876
	 * 
1877
	 * @return string
1878
	 */
1879
	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...
1880
	{
1881
		$res = '';
1882
		
1883
		foreach ($object->lines as $line)
1884
		{
1885
			if ($line->id == $currentLine->id) break;
1886
			
1887
			$qty_search = 100 - $currentLine->qty;
1888
			
1889
			if ($line->product_type == 9 && $line->special_code == $this->module_number && $line->qty == $qty_search) 
1890
			{
1891
				$res = ($line->label) ? $line->label : (($line->description) ? $line->description : $line->desc);
1892
			}
1893
		}
1894
		
1895
		return $res;
1896
	}
1897
	
1898
	/**
1899
	 * @param $parameters   array
1900
	 * @param $object       CommonObject
1901
	 * @param $action       string
1902
	 * @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...
1903
	 * @return int
1904
	 */
1905
	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...
1906
		
1907
		global $conf,$langs,$user,$db,$bc;
1908
		
1909
		$num = &$parameters['num'];
1910
		$line = &$parameters['line'];
1911
		$i = &$parameters['i'];
1912
		
1913
		$var = &$parameters['var'];
1914
1915
		$contexts = explode(':',$parameters['context']);
1916
1917
		$createRight = $user->rights->{$object->element}->creer;
1918
		if($object->element == 'facturerec' )
1919
		{
1920
			$object->statut = 0; // hack for facture rec
1921
			$createRight = $user->rights->facture->creer;
1922
		}
1923
		elseif($object->element == 'order_supplier' )
1924
		{
1925
		    $createRight = $user->rights->fournisseur->commande->creer;
1926
		}
1927
		elseif($object->element == 'invoice_supplier' )
1928
		{
1929
		    $createRight = $user->rights->fournisseur->facture->creer;
1930
		}
1931
		
1932
		if($line->special_code!=$this->module_number || $line->product_type!=9) {
1933
			null;
1934
		}	
1935
		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)) 
1936
        {
1937
			if($object->element=='facture')$idvar = 'facid';
1938
			else $idvar='id';
1939
			
1940
			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...
1941
			{
1942
				?>
1943
				<script type="text/javascript">
1944
					$(document).ready(function() {
1945
						$('#tablelines tr[rel=subtotal]').mouseleave(function() {
1946
1947
							id_line =$(this).attr('id');
1948
1949
							$(this).find('td[rel=subtotal_total]').each(function() {
1950
								$.get(document.location.href, function(data) {
1951
									var total = $(data).find('#tablelines tr#'+id_line+' td[rel=subtotal_total]').html();
1952
1953
									$('#tablelines tr#'+id_line+' td[rel=subtotal_total]').html(total);
1954
1955
								});
1956
							});
1957
						});
1958
					});
1959
1960
				</script>
1961
				<?php
1962
			}
1963
			
1964
			if(empty($line->description)) $line->description = $line->desc;
1965
			
1966
			$colspan = 5;
1967
			if($object->element == 'facturerec' ) $colspan = 3;
1968
			if($object->element == 'order_supplier') $colspan = 3;
1969
			if($object->element == 'invoice_supplier') $colspan = 4;
1970
			if($object->element == 'supplier_proposal') $colspan = 4;
1971
			if(!empty($conf->multicurrency->enabled) && ((float) DOL_VERSION < 8.0 || $object->multicurrency_code != $conf->currency)) {
1972
				$colspan++; // Colonne PU Devise
1973
			}
1974
			if($object->element == 'commande' && $object->statut < 3 && !empty($conf->shippableorder->enabled)) $colspan++;
1975
			if(!empty($conf->margin->enabled)) $colspan++;
1976
			if(!empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
1977
			if(!empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
1978
			if($object->element == 'facture' && !empty($conf->global->INVOICE_USE_SITUATION) && $object->type == Facture::TYPE_SITUATION) $colspan++;
1979
			if(!empty($conf->global->PRODUCT_USE_UNITS)) $colspan++;
1980
					
1981
			/* Titre */
1982
			//var_dump($line);
1983
            
1984
			// HTML 5 data for js
1985
            $data = $this->_getHtmlData($parameters, $object, $action, $hookmanager);
1986
            
1987
			
1988
			?>
1989
			<tr <?php echo $bc[$var]; $var=!$var; echo $data; ?> rel="subtotal" id="row-<?php echo $line->id ?>" style="<?php
1990
					if (!empty($conf->global->SUBTOTAL_USE_NEW_FORMAT))
1991
					{
1992
						if($line->qty==99) print 'background:#adadcf';
1993
						else if($line->qty==98) print 'background:#ddddff;';
1994
						else if($line->qty<=97 && $line->qty>=91) print 'background:#eeeeff;';
1995
						else if($line->qty==1) print 'background:#adadcf;';
1996
						else if($line->qty==2) print 'background:#ddddff;';
1997
						else if($line->qty==50) print '';
1998
						else print 'background:#eeeeff;';
1999
2000
						//A compléter si on veux plus de nuances de couleurs avec les niveau 4,5,6,7,8 et 9
2001
					}
2002
					else 
2003
					{
2004
						if($line->qty==99) print 'background:#ddffdd';
2005
						else if($line->qty==98) print 'background:#ddddff;';
2006
						else if($line->qty==2) print 'background:#eeeeff; ';
2007
						else if($line->qty==50) print '';
2008
						else print 'background:#eeffee;' ;
2009
					}
2010
2011
			?>;">
2012
2013
				<?php if(! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { ?>
2014
				<td class="linecolnum"><?php echo $i + 1; ?></td>
2015
				<?php } ?>
2016
2017
				<td colspan="<?php echo $colspan; ?>" style="<?php TSubtotal::isFreeText($line) ? '' : 'font-weight:bold;'; ?>  <?php echo ($line->qty>90)?'text-align:right':'' ?> "><?php
2018
					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

2018
					if($action=='editline' && /** @scrutinizer ignore-call */ GETPOST('lineid') == $line->id && TSubtotal::isModSubtotalLine($line) ) {
Loading history...
2019
2020
						$params=array('line'=>$line);
2021
						$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...
2022
						
2023
						echo '<div id="line_'.$line->id.'"></div>'; // Imitation Dolibarr
2024
						echo '<input type="hidden" value="'.$line->id.'" name="lineid">';
2025
						echo '<input id="product_type" type="hidden" value="'.$line->product_type.'" name="type">';
2026
						echo '<input id="product_id" type="hidden" value="'.$line->fk_product.'" name="type">';
2027
						echo '<input id="special_code" type="hidden" value="'.$line->special_code.'" name="type">';
2028
2029
						$isFreeText=false;
2030
						if (TSubtotal::isTitle($line))
2031
						{
2032
							$qty_displayed = $line->qty;
2033
							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

2033
							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...
2034
							
2035
						}
2036
						else if (TSubtotal::isSubtotal($line))
2037
						{
2038
							$qty_displayed = 100 - $line->qty;
2039
							print img_picto('', 'subsubtotal2@subtotal').'<span style="font-size:9px;margin-left:-1px;color:#0075DE;">'.$qty_displayed.'</span>&nbsp;&nbsp;';
2040
						}
2041
						else
2042
						{
2043
							$isFreeText = true;
2044
						}
2045
						
2046
						if ($object->element == 'order_supplier' || $object->element == 'invoice_supplier') {
2047
						    $line->label = !empty($line->description) ? $line->description : $line->desc;
2048
						    $line->description = '';
2049
						}
2050
						$newlabel = $line->label;
2051
						if($line->label=='' && !$isFreeText) {
2052
							if(TSubtotal::isSubtotal($line)) {
2053
								$newlabel = $line->description.' '.$this->getTitle($object, $line);
2054
								$line->description='';
2055
							} elseif( (float)DOL_VERSION < 6 ) {
2056
								$newlabel= $line->description;
2057
								$line->description='';
2058
							}
2059
						}
2060
2061
						$readonlyForSituation = '';
2062
						if (!empty($object->situation_cycle_ref) && $object->situation_counter > 1) $readonlyForSituation = 'readonly';
2063
						
2064
						if (!$isFreeText) echo '<input type="text" name="line-title" id-line="'.$line->id.'" value="'.$newlabel.'" size="80" '.$readonlyForSituation.'/>&nbsp;';
2065
						
2066
						if (!empty($conf->global->SUBTOTAL_USE_NEW_FORMAT) && (TSubtotal::isTitle($line) || TSubtotal::isSubtotal($line)) )
2067
						{
2068
							$select = '<select name="subtotal_level">';
2069
							for ($j=1; $j<10; $j++)
2070
							{
2071
								if (!empty($readonlyForSituation)) {
2072
									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...
2073
								} else $select .= '<option '.($qty_displayed == $j ? 'selected="selected"' : '').' value="'.$j.'">'.$langs->trans('Level').' '.$j.'</option>';
2074
							}
2075
							$select .= '</select>&nbsp;';
2076
2077
							echo $select;
2078
						}
2079
						
2080
2081
						echo '<div class="subtotal_underline" style="margin-left:24px; line-height: 25px;">';
2082
                        echo '<div>';
2083
                        echo '<input style="vertical-align:sub;"  type="checkbox" name="line-pagebreak" id="subtotal-pagebreak" value="8" '.(($line->info_bits > 0) ? 'checked="checked"' : '') .' />&nbsp;';
2084
                        echo '<label for="subtotal-pagebreak">'.$langs->trans('AddBreakPageBefore').'</label>';
2085
                        echo '</div>';
2086
2087
                        if (TSubtotal::isTitle($line))
2088
                        {
2089
                            $form = new Form($db);
2090
                            echo '<div>';
2091
                            echo '<label for="subtotal_tva_tx">'.$form->textwithpicto($langs->trans('subtotal_apply_default_tva'), $langs->trans('subtotal_apply_default_tva_help')).'</label>';
2092
                            echo '<select id="subtotal_tva_tx" name="subtotal_tva_tx" class="flat"><option selected="selected" value="">-</option>';
2093
                            if (empty($readonlyForSituation)) echo str_replace('selected', '', $form->load_tva('subtotal_tva_tx', '', $parameters['seller'], $parameters['buyer'], 0, 0, '', true));
2094
                            echo '</select>';
2095
                            echo '</div>';
2096
2097
                            if (!empty($conf->global->INVOICE_USE_SITUATION) && $object->element == 'facture' && $object->type == Facture::TYPE_SITUATION)
2098
                            {
2099
                                echo '<div>';
2100
                                echo '<label for="subtotal_progress">'.$langs->trans('subtotal_apply_progress').'</label> <input id="subtotal_progress" name="subtotal_progress" value="" size="1" />%';
2101
                                echo '</div>';
2102
                            }
2103
                            echo '<div>';
2104
                            echo '<input style="vertical-align:sub;"  type="checkbox" name="line-showTotalHT" id="subtotal-showTotalHT" value="9" '.(($line->array_options['options_show_total_ht'] > 0) ? 'checked="checked"' : '') .' />&nbsp;';
2105
                            echo '<label for="subtotal-showTotalHT">'.$langs->trans('ShowTotalHTOnSubtotalBlock').'</label>';
2106
                            echo '</div>';
2107
2108
                            echo '<div>';
2109
                            echo '<input style="vertical-align:sub;"  type="checkbox" name="line-showReduc" id="subtotal-showReduc" value="1" '.(($line->array_options['options_show_reduc'] > 0) ? 'checked="checked"' : '') .' />&nbsp;';
2110
                            echo '<label for="subtotal-showReduc">'.$langs->trans('ShowReducOnSubtotalBlock').'</label>';
2111
                            echo '</div>';
2112
                        }
2113
                        else if ($isFreeText) echo TSubtotal::getFreeTextHtml($line, (bool) $readonlyForSituation);
2114
						echo '</div>';
2115
2116
						if($line->qty<10) {
2117
							// WYSIWYG editor
2118
							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...
2119
							$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...
2120
							$cked_enabled = (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
2121
							if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
2122
								$nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
2123
							}
2124
							$toolbarname = 'dolibarr_details';
2125
							if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) {
2126
								$toolbarname = 'dolibarr_notes';
2127
							}
2128
							$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...
2129
								false, true, $cked_enabled, $nbrows, '98%', (bool) $readonlyForSituation);
2130
							$doleditor->Create();
2131
						}
2132
						
2133
					}
2134
					else {
2135
2136
						 if ($conf->global->SUBTOTAL_USE_NEW_FORMAT)
2137
						 {
2138
							if(TSubtotal::isTitle($line) || TSubtotal::isSubtotal($line)) 
2139
							{
2140
								echo str_repeat('&nbsp;&nbsp;&nbsp;', $line->qty-1);
2141
								
2142
								if (TSubtotal::isTitle($line)) print img_picto('', 'subtotal@subtotal').'<span style="font-size:9px;margin-left:-3px;">'.$line->qty.'</span>&nbsp;&nbsp;';
2143
								else print img_picto('', 'subtotal2@subtotal').'<span style="font-size:9px;margin-left:-1px;">'.(100-$line->qty).'</span>&nbsp;&nbsp;';
2144
							}
2145
						 }
2146
						 else 
2147
						 {
2148
							if($line->qty<=1) print img_picto('', 'subtotal@subtotal');
2149
							else if($line->qty==2) print img_picto('', 'subsubtotal@subtotal').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; 
2150
						 }
2151
						 
2152
						 
2153
						 // Get display styles and apply them
2154
						 $titleStyleItalic = strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'I') === false ? '' : ' font-style: italic;';
2155
						 $titleStyleBold =  strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'B') === false ? '' : ' font-weight:bold;';
2156
						 $titleStyleUnderline =  strpos($conf->global->SUBTOTAL_TITLE_STYLE, 'U') === false ? '' : ' text-decoration: underline;';
2157
						 
2158
						 if (empty($line->label)) {
2159
							if ($line->qty >= 91 && $line->qty <= 99 && $conf->global->SUBTOTAL_USE_NEW_FORMAT) print  $line->description.' '.$this->getTitle($object, $line);
2160
							else print  $line->description;
2161
						 } 
2162
						 else {
2163
2164
							if (! empty($conf->global->PRODUIT_DESC_IN_FORM) && !empty($line->description)) {
2165
								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

2165
								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...
2166
							}
2167
							else{
2168
								print '<span class="subtotal_label classfortooltip '.$titleStyleItalic.$titleStyleBold.$titleStyleUnderline.'" title="'.$line->description.'">'.$line->label.'</span>';    
2169
							}
2170
2171
						 } 
2172
						if($line->qty>90) print ' : ';
2173
						if($line->info_bits > 0) echo img_picto($langs->trans('Pagebreak'), 'pagebreak@subtotal');
2174
2175
						 
2176
2177
2178
					}
2179
			?></td>
2180
					 
2181
			<?php
2182
				if($line->qty>90) {
2183
					/* Total */
2184
					$total_line = $this->getTotalLineFromObject($object, $line, '');
2185
					echo '<td class="linecolht nowrap" 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

2185
					echo '<td class="linecolht nowrap" align="right" style="font-weight:bold;" rel="subtotal_total">'./** @scrutinizer ignore-call */ price($total_line).'</td>';
Loading history...
2186
					if (!empty($conf->multicurrency->enabled) && ((float) DOL_VERSION < 8.0 || $object->multicurrency_code != $conf->currency)) {
2187
						echo '<td class="linecoltotalht_currency">&nbsp;</td>';
2188
					}
2189
				} else {
2190
					echo '<td class="linecolht movetitleblock">&nbsp;</td>';
2191
					if (!empty($conf->multicurrency->enabled) && ((float) DOL_VERSION < 8.0 || $object->multicurrency_code != $conf->currency)) {
2192
						echo '<td class="linecoltotalht_currency">&nbsp;</td>';
2193
					}
2194
				}	
2195
			?>
2196
					
2197
			<td align="center" class="nowrap linecoledit">
2198
				<?php
2199
				if ($action != 'selectlines') {
2200
				
2201
					if($action=='editline' && GETPOST('lineid') == $line->id && TSubtotal::isModSubtotalLine($line) ) {
2202
						?>
2203
						<input id="savelinebutton" class="button" type="submit" name="save" value="<?php echo $langs->trans('Save') ?>" />
2204
						<br />
2205
						<input class="button" type="button" name="cancelEditlinetitle" value="<?php echo $langs->trans('Cancel') ?>" />
2206
						<script type="text/javascript">
2207
							$(document).ready(function() {
2208
								$('input[name=cancelEditlinetitle]').click(function () {
2209
									document.location.href="<?php echo '?'.$idvar.'='.$object->id ?>";
2210
								});
2211
							});
2212
2213
						</script>
2214
						<?php
2215
						
2216
					}
2217
					else{
2218
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_DUPLICATE_BLOCK) && $object->element !== 'invoice_supplier')
2219
						{
2220
							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>';
2221
						}
2222
2223
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_EDIT_BLOCK)) 
2224
						{
2225
							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

2225
							echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=editline&lineid='.$line->id.'">'./** @scrutinizer ignore-call */ img_edit().'</a>';
Loading history...
2226
						}								
2227
					}
2228
					
2229
				}
2230
					
2231
				?>
2232
			</td>
2233
2234
			<td align="center" class="nowrap linecoldelete">	
2235
				<?php
2236
2237
				if ($action != 'editline' && $action != 'selectlines') {
2238
						if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_REMOVE_BLOCK))
2239
						{
2240
2241
							if ($object->situation_counter == 1 || !$object->situation_cycle_ref)
2242
							{
2243
								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

2243
								echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=ask_deleteline&lineid='.$line->id.'">'./** @scrutinizer ignore-call */ img_delete().'</a>';
Loading history...
2244
							}
2245
2246
							if(TSubtotal::isTitle($line) && ($object->situation_counter == 1 || !$object->situation_cycle_ref) )
2247
							{
2248
								if ((float) DOL_VERSION >= 8.0) {
2249
									$img_delete = img_delete($langs->trans('deleteWithAllLines'), ' class="pictodelete pictodeleteallline"');
2250
								} elseif ((float) DOL_VERSION >= 3.8) {
2251
									$img_delete = img_picto($langs->trans('deleteWithAllLines'), 'delete_all.3.8@subtotal',' class="pictodelete" ');
2252
								} else {
2253
									$img_delete = img_picto($langs->trans('deleteWithAllLines'), 'delete_all@subtotal');
2254
								}
2255
2256
								echo '<a href="'.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id.'&action=ask_deleteallline&lineid='.$line->id.'">'.$img_delete.'</a>';
2257
2258
								/* Depuis la 8.0, les icônes "standard" utilisent FontAwesome et sont préconfigurées selon la clé de l'image
2259
								 * Impossible d'en customiser par exemple la couleur, même en utilisant img_picto() directement
2260
								 */
2261
								if((float) DOL_VERSION >= 8.0) {
2262
								?>
2263
								<script>
2264
									$(document).ready(function () {
2265
										$("#row-<?php echo $line->id; ?> td.linecoldelete span.fa.fa-trash.pictodeleteallline").css({"color": "#be3535"});
2266
									});
2267
								</script>
2268
								<?php
2269
								}
2270
							}
2271
						}
2272
					}
2273
				?>
2274
			</td>
2275
			
2276
			<?php 
2277
			if ($object->statut == 0  && $createRight && !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && TSubtotal::isTitle($line) && $action != 'editline')
2278
			{
2279
				echo '<td class="subtotal_nc">';
2280
				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"' : '').' />';
2281
				echo '</td>';
2282
			}
2283
			
2284
			if ($num > 1 && empty($conf->browser->phone)) { ?>
2285
			<td align="center" class="linecolmove tdlineupdown">
2286
			</td>
2287
			<?php } else { ?>
2288
			<td align="center"<?php echo ((empty($conf->browser->phone) && ($object->statut == 0  && $createRight ))?' class="tdlineupdown"':''); ?>></td>
2289
			<?php } ?>
2290
2291
			<?php  if($action == 'selectlines'){ // dolibarr 8 ?>
2292
			<td class="linecolcheck" align="center"><input type="checkbox" class="linecheckbox" name="line_checkbox[<?php echo $i+1; ?>]" value="<?php echo $line->id; ?>" ></td>
2293
			<?php } ?>
2294
2295
			</tr>
2296
			<?php
2297
			
2298
			
2299
			// Affichage des extrafields à la Dolibarr (car sinon non affiché sur les titres)
2300
			if(TSubtotal::isTitle($line) && !empty($conf->global->SUBTOTAL_ALLOW_EXTRAFIELDS_ON_TITLE)) {
2301
				
2302
				require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
2303
				
2304
				// Extrafields
2305
				$extrafieldsline = new ExtraFields($db);
2306
				$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...
2307
				
2308
				$colspan+=3; $mode = 'view';
2309
				if($action === 'editline' && $line->rowid == GETPOST('lineid')) $mode = 'edit';
2310
				
2311
				$ex_element = $line->element;
2312
				$line->element = 'tr_extrafield_title '.$line->element; // Pour pouvoir manipuler ces tr
2313
				print $line->showOptionals($extrafieldsline, $mode, array('style'=>' style="background:#eeffee;" ','colspan'=>$colspan));
2314
				$isExtraSelected = false;
2315
				foreach($line->array_options as $option) {
2316
					if(!empty($option) && $option != "-1") {
2317
						$isExtraSelected = true;
2318
						break;
2319
					}
2320
				}
2321
				
2322
				if($mode === 'edit') {
2323
					?>
2324
					<script>
2325
						$(document).ready(function(){
2326
2327
							var all_tr_extrafields = $("tr.tr_extrafield_title");
2328
							<?php 
2329
							// Si un extrafield est rempli alors on affiche directement les extrafields
2330
							if(!$isExtraSelected) {
2331
								echo 'all_tr_extrafields.hide();';
2332
								echo 'var trad = "'.$langs->trans('showExtrafields').'";';
2333
								echo 'var extra = 0;';
2334
							} else {
2335
								echo 'all_tr_extrafields.show();';
2336
								echo 'var trad = "'.$langs->trans('hideExtrafields').'";';
2337
								echo 'var extra = 1;';
2338
							}
2339
							?>
2340
							
2341
							$("div .subtotal_underline").append(
2342
									'<a id="printBlocExtrafields" onclick="return false;" href="#">' + trad + '</a>'
2343
									+ '<input type="hidden" name="showBlockExtrafields" id="showBlockExtrafields" value="'+ extra +'" />');
2344
2345
							$(document).on('click', "#printBlocExtrafields", function() {
2346
								var btnShowBlock = $("#showBlockExtrafields");
2347
								var val = btnShowBlock.val();
2348
								if(val == '0') {
2349
									btnShowBlock.val('1');
2350
									$("#printBlocExtrafields").html("<?php print $langs->trans('hideExtrafields'); ?>");
2351
									$(all_tr_extrafields).show();
2352
								} else {
2353
									btnShowBlock.val('0');
2354
									$("#printBlocExtrafields").html("<?php print $langs->trans('showExtrafields'); ?>");
2355
									$(all_tr_extrafields).hide();
2356
								}
2357
							});
2358
						});
2359
					</script>
2360
					<?php
2361
				}
2362
				$line->element = $ex_element;
2363
				
2364
			}
2365
			
2366
			return 1;	
2367
			
2368
		}
2369
		
2370
		return 0;
2371
2372
	}
2373
2374
	
2375
	function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

2375
	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...
2376
		global $conf,$langs;
2377
		 
2378
		if ($object->statut == 0 && !empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && $action != 'editline')
2379
		{
2380
		    
2381
		    if($object->element == 'invoice_supplier' || $object->element == 'order_supplier')
2382
		    {
2383
		        foreach ($object->lines as $line)
2384
		        {
2385
		            // fetch optionals attributes and labels
2386
		            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...
2387
		            $extrafields=new ExtraFields($this->db);
2388
		            $extralabels=$extrafields->fetch_name_optionals_label($object->table_element_line,true);
2389
		            $line->fetch_optionals($line->id,$extralabels);
2390
		        }
2391
		    }
2392
		    
2393
			$TSubNc = array();
2394
			foreach ($object->lines as &$l)
2395
			{
2396
				$TSubNc[$l->id] = (int) $l->array_options['options_subtotal_nc'];
2397
			}
2398
			
2399
			$form = new Form($db);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $db seems to be never defined.
Loading history...
2400
			?>
2401
			<script type="text/javascript">
2402
				$(function() {
2403
					var subtotal_TSubNc = <?php echo json_encode($TSubNc); ?>;
2404
					$("#tablelines tbody > tr").each(function(i, item) {
2405
						if ($(item).children('.subtotal_nc').length == 0)
2406
						{
2407
							var id = $(item).attr('id');
2408
							
2409
							if ((typeof id != 'undefined' && id.indexOf('row-') >= 0) || $(item).hasClass('liste_titre'))
2410
							{
2411
								$(item).children('td:last-child').before('<td class="subtotal_nc"></td>');
2412
								
2413
								if ($(item).attr('rel') != 'subtotal' && typeof $(item).attr('id') != 'undefined')
2414
								{
2415
									var idSplit = $(item).attr('id').split('-');
2416
									$(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"' : '')+' />'));
2417
								}
2418
							}
2419
							else 
2420
							{
2421
								$(item).append('<td class="subtotal_nc"></td>');
2422
							}
2423
						}
2424
					});
2425
					
2426
					$('#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'))); ?>);
2427
					
2428
					function callAjaxUpdateLineNC(set, lineid, subtotal_nc)
2429
					{
2430
						$.ajax({
2431
							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

2431
							url: '<?php echo /** @scrutinizer ignore-call */ dol_buildpath('/subtotal/script/interface.php', 1); ?>'
Loading history...
2432
							,type: 'POST'
2433
							,data: {
2434
								json:1
2435
								,set: set
2436
								,element: '<?php echo $object->element; ?>'
2437
								,elementid: <?php echo (int) $object->id; ?>
2438
								,lineid: lineid
2439
								,subtotal_nc: subtotal_nc
2440
							}
2441
						}).done(function(response) {
2442
							window.location.href = window.location.pathname + '?id=<?php echo $object->id; ?>&page_y=' + window.pageYOffset;
2443
						});
2444
					}
2445
					
2446
					$(".subtotal_nc_chkbx").change(function(event) {
2447
						var lineid = $(this).data('lineid');
2448
						var subtotal_nc = 0 | $(this).is(':checked'); // Renvoi 0 ou 1 
2449
						
2450
						callAjaxUpdateLineNC('updateLineNC', lineid, subtotal_nc);
2451
					});
2452
					
2453
				});
2454
2455
			</script>
2456
			<?php
2457
		}
2458
		
2459
		$this->_ajax_block_order_js($object);
2460
	}
2461
	
2462
	function afterPDFCreation($parameters, &$pdf, &$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 $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

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

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

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

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

2462
	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...
2463
	{
2464
		global $conf;
2465
		
2466
		$object = $parameters['object'];
2467
		
2468
		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'))
2469
		{
2470
			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

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

2471
				/** @scrutinizer ignore-call */ 
2472
    dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
2472
				TSubtotal::addRecapPage($parameters, $pdf);
2473
			}
2474
		}
2475
	}
2476
	
2477
	// HTML 5 data for js
2478
	private function _getHtmlData($parameters, &$object, &$action, $hookmanager)
2479
	{
2480
		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

2480
		/** @scrutinizer ignore-call */ 
2481
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
2481
2482
	    $line = &$parameters['line'];
2483
	    
2484
	    $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...
2485
	    $ThtmlData['data-product_type'] = $line->product_type;
2486
	    $ThtmlData['data-qty']          = 0; //$line->qty;
2487
	    $ThtmlData['data-level']        = TSubtotal::getNiveau($line);
2488
	    
2489
	    if(TSubtotal::isTitle($line)){
2490
	        $ThtmlData['data-issubtotal'] = 'title';
2491
	    }elseif(TSubtotal::isSubtotal($line)){
2492
	        $ThtmlData['data-issubtotal'] = 'subtotal';
2493
	    }
2494
	    else{
2495
	        $ThtmlData['data-issubtotal'] = 'freetext';
2496
	    }
2497
	    
2498
	    
2499
	    // Change or add data  from hooks
2500
	    $parameters = array_replace($parameters , array(  'ThtmlData' => $ThtmlData )  );
2501
	    
2502
	    // hook 
2503
	    $reshook = $hookmanager->executeHooks('subtotalLineHtmlData',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
2504
	    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

2504
	    if ($reshook < 0) /** @scrutinizer ignore-call */ setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
Loading history...
2505
	    if ($reshook>0)
2506
	    {
2507
	        $ThtmlData = $hookmanager->resArray;
2508
	    }
2509
2510
	    return $this->implodeHtmlData($ThtmlData);
2511
	
2512
	}
2513
	
2514
	
2515
	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...
2516
	{
2517
	    $data = '';
2518
	    foreach($ThtmlData as $k => $h )
2519
	    {
2520
	        if(is_array($h))
2521
	        {
2522
	            $h = json_encode($h);
2523
	        }
2524
	        
2525
	        $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

2525
	        $data .= $k . '="'./** @scrutinizer ignore-call */ dol_htmlentities($h, ENT_QUOTES).'" ';
Loading history...
2526
	    }
2527
	    
2528
	    return $data;
2529
	}
2530
	
2531
	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...
2532
	{
2533
	    global $conf,$tagidfortablednd,$filepath,$langs;
2534
	    
2535
	    /*
2536
	     * this part of js is base on dolibarr htdocs/core/tpl/ajaxrow.tpl.php 
2537
	     * for compatibility reasons we don't use tableDnD but jquery sortable
2538
	     */
2539
	    
2540
	    $id=$object->id;
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
2541
	    $nboflines=(isset($object->lines)?count($object->lines):0);
2542
	    $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...
2543
	    
2544
	    $id=$object->id;
2545
	    $fk_element=$object->fk_element;
2546
	    $table_element_line=$object->table_element_line;
2547
	    $nboflines=(isset($object->lines)?count($object->lines):(empty($nboflines)?0:$nboflines));
2548
	    $tagidfortablednd=(empty($tagidfortablednd)?'tablelines':$tagidfortablednd);
2549
	    $filepath=(empty($filepath)?'':$filepath);
2550
	    
2551
	    
2552
	    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

2552
	    if (/** @scrutinizer ignore-call */ GETPOST('action','aZ09') != 'editline' && $nboflines > 1)
Loading history...
2553
	    {
2554
	        
2555
	        ?>
2556
		
2557
		
2558
			<script type="text/javascript">
2559
			$(document).ready(function(){
2560
2561
				// target some elements
2562
				var titleRow = $('tr[data-issubtotal="title"]');
2563
				var lastTitleCol = titleRow.find('td:last-child');
2564
				var moveBlockCol= titleRow.find('td.linecolht');
2565
2566
				
2567
				moveBlockCol.disableSelection(); // prevent selection
2568
<?php if ($object->statut == 0) { ?>
2569
				// apply some graphical stuff
2570
				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

2570
				moveBlockCol.css("background-image",'url(<?php echo /** @scrutinizer ignore-call */ dol_buildpath('subtotal/img/grip_all.png',2);  ?>)');
Loading history...
2571
				moveBlockCol.css("background-repeat","no-repeat");
2572
				moveBlockCol.css("background-position","center center");
2573
				moveBlockCol.css("cursor","move");
2574
				titleRow.attr('title', '<?php echo html_entity_decode($langs->trans('MoveTitleBlock')); ?>');
2575
			
2576
2577
 				$( "#<?php echo $tagidfortablednd; ?>" ).sortable({
2578
			    	  cursor: "move",
2579
			    	  handle: ".movetitleblock",
2580
			    	  items: 'tr:not(.nodrag,.nodrop,.noblockdrop)',
2581
			    	  delay: 150, //Needed to prevent accidental drag when trying to select
2582
			    	  opacity: 0.8,
2583
			    	  axis: "y", // limit y axis
2584
			    	  placeholder: "ui-state-highlight",
2585
			    	  start: function( event, ui ) {
2586
			    	      //console.log('X:' + e.screenX, 'Y:' + e.screenY);
2587
			    		  //console.log(ui.item);
2588
			    		  var colCount = ui.item.children().length;
2589
   						  ui.placeholder.html('<td colspan="'+colCount+'">&nbsp;</td>');
2590
   		
2591
			    		  var TcurrentChilds = getSubtotalTitleChilds(ui.item);
2592
			    		  ui.item.data('childrens',TcurrentChilds); // store data
2593
				    		
2594
			    		  for (var key in TcurrentChilds) {
2595
			    			  $('#'+ TcurrentChilds[key]).addClass('noblockdrop');//'#row-'+ 
2596
			    			  $('#'+ TcurrentChilds[key]).fadeOut();//'#row-'+ 
2597
			    		  }
2598
2599
			    		  $(this).sortable("refresh");	// "refresh" of source sortable is required to make "disable" work!
2600
			    	      
2601
			    	    },
2602
				    	stop: function (event, ui) {
2603
							// call we element is droped
2604
				    	  	$('.noblockdrop').removeClass('noblockdrop');
2605
2606
				    	  	var TcurrentChilds = ui.item.data('childrens'); // reload child list from data and not attr to prevent load error
2607
2608
							for (var i =TcurrentChilds.length ; i >= 0; i--) {
2609
				    			  $('#'+ TcurrentChilds[i]).insertAfter(ui.item); //'#row-'+ 
2610
				    			  $('#'+ TcurrentChilds[i]).fadeIn(); //'#row-'+ 
2611
							}
2612
							console.log('onstop');
2613
							console.log(cleanSerialize($(this).sortable('serialize')));
2614
							
2615
							$.ajax({
2616
			    	            data: {
2617
									objet_id: <?php print $object->id; ?>,
2618
							    	roworder: cleanSerialize($(this).sortable('serialize')),
2619
									table_element_line: "<?php echo $table_element_line; ?>",
2620
									fk_element: "<?php echo $fk_element; ?>",
2621
									element_id: "<?php echo $id; ?>",
2622
									filepath: "<?php echo urlencode($filepath); ?>"
2623
								},
2624
			    	            type: 'POST',
2625
			    	            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...
2626
			    	            success: function(data) {
2627
			    	                console.log(data);
2628
			    	            },
2629
			    	        });
2630
			    	        
2631
			    	  },
2632
			    	  update: function (event, ui) {
2633
				    	  
2634
			    	        // POST to server using $.post or $.ajax
2635
				    	  	$('.noblockdrop').removeClass('noblockdrop');
2636
							//console.log('onupdate');
2637
			    	        //console.log(cleanSerialize($(this).sortable('serialize')));
2638
			    	    }
2639
			    });
2640
 				<?php } ?>
2641
2642
				function getSubtotalTitleChilds(item)
2643
				{
2644
		    		var TcurrentChilds = []; // = JSON.parse(item.attr('data-childrens'));
2645
		    		var level = item.data('level');
2646
2647
		    		var indexOfFirstSubtotal = -1;
2648
		    		var indexOfFirstTitle = -1;
2649
		    		
2650
		    		item.nextAll('[id^="row-"]').each(function(index){
2651
2652
						var dataLevel = $(this).attr('data-level');
2653
						var dataIsSubtotal = $(this).attr('data-issubtotal');
2654
						
2655
						if(dataIsSubtotal != 'undefined' && dataLevel != 'undefined' )
2656
						{
2657
2658
							if(dataLevel <=  level && indexOfFirstSubtotal < 0 && dataIsSubtotal == 'subtotal' )
2659
							{
2660
								indexOfFirstSubtotal = index;
2661
								if(indexOfFirstTitle < 0)
2662
								{
2663
									TcurrentChilds.push($(this).attr('id'));
2664
								}
2665
							}
2666
							
2667
							if(dataLevel <=  level && indexOfFirstSubtotal < 0 && indexOfFirstTitle < 0 && dataIsSubtotal == 'title' )
2668
							{
2669
								indexOfFirstTitle = index;
2670
							}
2671
						}
2672
2673
						if(indexOfFirstTitle < 0 && indexOfFirstSubtotal < 0)
2674
						{
2675
							TcurrentChilds.push($(this).attr('id'));
2676
2677
							// Add extraffield support for dolibarr > 7
2678
							var thisId = $(this).attr('data-id');
2679
							var thisElement = $(this).attr('data-element');
2680
							if(thisId != undefined && thisElement != undefined )
2681
							{
2682
								$('[data-targetid="' + thisId + '"][data-element="extrafield"][data-targetelement="'+ thisElement +'"]').each(function(index){
2683
									TcurrentChilds.push($(this).attr('id'));
2684
								});
2685
							}
2686
							
2687
						}
2688
2689
		    		});
2690
		    		return TcurrentChilds;
2691
				}
2692
				
2693
			});
2694
			</script>
2695
			<style type="text/css" >
2696
         
2697
            tr.ui-state-highlight td{
2698
            	border: 1px solid #dad55e;
2699
            	background: #fffa90;
2700
            	color: #777620;
2701
            }
2702
            </style>
2703
		<?php
2704
		
2705
		} 
2706
	
2707
		
2708
		
2709
	}
2710
	
2711
}
2712