Passed
Pull Request — master (#109)
by
unknown
02:02
created

ActionsSubtotal::getTotalLineFromObject()   C

Complexity

Conditions 8
Paths 10

Size

Total Lines 35
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 10
Bugs 1 Features 0
Metric Value
cc 8
eloc 23
c 10
b 1
f 0
nc 10
nop 4
dl 0
loc 35
rs 5.3846
1
<?php
2
class ActionsSubtotal
3
{
4
5
	function __construct($db)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
53
    {
54
      	global $langs,$db,$user, $conf;
55
56
		$langs->load('subtotal@subtotal');
57
58
		$contexts = explode(':',$parameters['context']);
59
60
		if(in_array('ordercard',$contexts) || in_array('ordersuppliercard',$contexts) || in_array('propalcard',$contexts) || in_array('supplier_proposalcard',$contexts) || in_array('invoicecard',$contexts) || in_array('invoicesuppliercard',$contexts) || in_array('invoicereccard',$contexts)) {
61
62
			$createRight = $user->rights->{$object->element}->creer;
63
			if($object->element == 'facturerec' )
64
			{
65
				$object->statut = 0; // hack for facture rec
66
				$createRight = $user->rights->facture->creer;
67
			} elseif($object->element == 'order_supplier' )
68
			{
69
			    $createRight = $user->rights->fournisseur->commande->creer;
70
			} elseif($object->element == 'invoice_supplier' )
71
			{
72
			    $createRight = $user->rights->fournisseur->facture->creer;
73
			}
74
75
			if ($object->statut == 0  && $createRight) {
76
77
78
				if($object->element=='facture')$idvar = 'facid';
79
				else $idvar='id';
80
81
				if(in_array($action, array('add_title_line', 'add_total_line', 'add_subtitle_line', 'add_subtotal_line', 'add_free_text')) )
82
				{
83
					$level = GETPOST('level', 'int'); //New avec SUBTOTAL_USE_NEW_FORMAT
0 ignored issues
show
Bug introduced by
The function GETPOST was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

83
					$level = /** @scrutinizer ignore-call */ GETPOST('level', 'int'); //New avec SUBTOTAL_USE_NEW_FORMAT
Loading history...
84
85
					if($action=='add_title_line') {
86
						$title = GETPOST('title');
87
						if(empty($title)) $title = $langs->trans('title');
88
						$qty = $level<1 ? 1 : $level ;
89
					}
90
					else if($action=='add_free_text') {
91
						$title = GETPOST('title');
92
93
						if (empty($title)) {
94
							$free_text = GETPOST('free_text', 'int');
95
							if (!empty($free_text)) {
96
								$TFreeText = getTFreeText();
97
								if (!empty($TFreeText[$free_text])) {
98
									$title = $TFreeText[$free_text]->content;
99
								}
100
							}
101
						}
102
						if(empty($title)) $title = $langs->trans('subtotalAddLineDescription');
103
						$qty = 50;
104
					}
105
					else if($action=='add_subtitle_line') {
106
						$title = GETPOST('title');
107
						if(empty($title)) $title = $langs->trans('subtitle');
108
						$qty = 2;
109
					}
110
					else if($action=='add_subtotal_line') {
111
						$title = $langs->trans('SubSubTotal');
112
						$qty = 98;
113
					}
114
					else {
115
						$title = GETPOST('title') ? GETPOST('title') : $langs->trans('SubTotal');
116
						$qty = $level ? 100-$level : 99;
117
					}
118
					dol_include_once('/subtotal/class/subtotal.class.php');
0 ignored issues
show
Bug introduced by
The function dol_include_once was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

118
					/** @scrutinizer ignore-call */ 
119
     dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
119
120
					if (!empty($conf->global->SUBTOTAL_AUTO_ADD_SUBTOTAL_ON_ADDING_NEW_TITLE) && $qty < 10) TSubtotal::addSubtotalMissing($object, $qty);
121
122
	    			TSubtotal::addSubTotalLine($object, $title, $qty);
123
				}
124
				else if($action==='ask_deleteallline') {
125
						$form=new Form($db);
0 ignored issues
show
Bug introduced by
The type Form was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
126
127
						$lineid = GETPOST('lineid','integer');
128
						$TIdForGroup = $this->getArrayOfLineForAGroup($object, $lineid);
129
130
						$nbLines = count($TIdForGroup);
131
132
						$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('deleteWithAllLines'), $langs->trans('ConfirmDeleteAllThisLines',$nbLines), 'confirm_delete_all_lines','',0,1);
133
						print $formconfirm;
134
				}
135
136
				if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE))
137
				{
138
					$this->showSelectTitleToAdd($object);
139
				}
140
141
142
				if($action!='editline') {
143
					// New format is for 3.8
144
					$this->printNewFormat($object, $conf, $langs, $idvar);
145
				}
146
			}
147
		}
148
		elseif ((!empty($parameters['currentcontext']) && $parameters['currentcontext'] == 'orderstoinvoice') || in_array('orderstoinvoice',$contexts))
149
		{
150
			?>
151
			<script type="text/javascript">
152
				$(function() {
153
					var tr = $("<tr><td><?php echo $langs->trans('subtotal_add_title_bloc_from_orderstoinvoice'); ?></td><td><input type='checkbox' value='1' name='subtotal_add_title_bloc_from_orderstoinvoice' checked='checked' /></td></tr>")
154
					$("textarea[name=note]").closest('tr').after(tr);
155
				});
156
			</script>
157
			<?php
158
159
		}
160
161
		return 0;
162
	}
163
164
	function printNewFormat(&$object, &$conf, &$langs, $idvar)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
165
	{
166
		if (empty($conf->global->SUBTOTAL_ALLOW_ADD_BLOCK)) return false;
167
		if (!empty($object->situation_cycle_ref) && $object->situation_counter > 1) return false; // Si facture de situation
168
		?>
169
		 	<script type="text/javascript">
170
				$(document).ready(function() {
171
					$('div.fiche div.tabsAction').append('<br />');
172
173
					$('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_title_line" rel="add_title_line" href="javascript:;" class="butAction"><?php echo  $langs->trans('AddTitle' )?></a></div>');
174
					$('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_total_line" rel="add_total_line" href="javascript:;" class="butAction"><?php echo  $langs->trans('AddSubTotal')?></a></div>');
175
					$('div.fiche div.tabsAction').append('<div class="inline-block divButAction"><a id="add_free_text" rel="add_free_text" href="javascript:;" class="butAction"><?php echo  $langs->trans('AddFreeText')?></a></div>');
176
177
178
					function updateAllMessageForms(){
179
				         for (instance in CKEDITOR.instances) {
180
				             CKEDITOR.instances[instance].updateElement();
181
				         }
182
				    }
183
184
					function promptSubTotal(action, titleDialog, label, url_to, url_ajax, params, use_textarea, show_free_text, show_under_title) {
185
					     $( "#dialog-prompt-subtotal" ).remove();
186
187
						 var dialog_html = '<div id="dialog-prompt-subtotal" '+(action == 'addSubtotal' ? 'class="center"' : '')+' >';
188
189
						 if (typeof show_under_title != 'undefined' && show_under_title)
190
						 {
191
							 var selectUnderTitle = <?php echo json_encode(getHtmlSelectTitle($object, true)); ?>;
192
							 dialog_html += selectUnderTitle + '<br /><br />';
193
						 }
194
195
						if (action == 'addTitle' || action == 'addFreeTxt')
196
						{
197
							if (typeof show_free_text != 'undefined' && show_free_text)
198
							{
199
							   var selectFreeText = <?php echo json_encode(getHtmlSelectFreeText()); ?>;
200
							   dialog_html += selectFreeText + ' <?php echo $langs->transnoentities('subtotalFreeTextOrDesc'); ?><br />';
201
							}
202
203
							if (typeof use_textarea != 'undefined' && use_textarea) dialog_html += '<textarea id="sub-total-title" rows="<?php echo ROWS_8; ?>" cols="80" placeholder="'+label+'"></textarea>';
0 ignored issues
show
Bug introduced by
The constant ROWS_8 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
204
							else dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />';
205
						}
206
207
						if (action == 'addTitle' || action == 'addSubtotal')
208
						{
209
							if (action == 'addSubtotal') dialog_html += '<input id="sub-total-title" size="30" value="" placeholder="'+label+'" />';
210
211
							dialog_html += "&nbsp;<select name='subtotal_line_level'>";
212
							for (var i=1;i<10;i++)
213
							{
214
								dialog_html += "<option value="+i+"><?php echo $langs->trans('Level'); ?> "+i+"</option>";
215
							}
216
							dialog_html += "</select>";
217
						}
218
219
						 dialog_html += '</div>';
220
221
						$('body').append(dialog_html);
222
223
						<?php
224
						$editorTool = empty($conf->global->FCKEDITOR_EDITORNAME)?'ckeditor':$conf->global->FCKEDITOR_EDITORNAME;
225
						$editorConf = empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?false:$conf->global->FCKEDITOR_ENABLE_DETAILS;
226
						if($editorConf && in_array($editorTool,array('textarea','ckeditor'))){
227
						?>
228
						if (action == 'addTitle' || action == 'addFreeTxt')
229
						{
230
							if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" )
231
							{
232
								 CKEDITOR.replace( 'sub-total-title', {toolbar: 'dolibarr_details', toolbarStartupExpanded: false} );
233
							}
234
						}
235
						<?php } ?>
236
237
					     $( "#dialog-prompt-subtotal" ).dialog({
238
	                        resizable: false,
239
							height: 'auto',
240
							width: 'auto',
241
	                        modal: true,
242
	                        title: titleDialog,
243
	                        buttons: {
244
	                            "Ok": function() {
245
	                            	if (typeof use_textarea != 'undefined' && use_textarea && typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" ){ updateAllMessageForms(); }
246
									params.title = params.title = (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && "sub-total-title" in CKEDITOR.instances ? CKEDITOR.instances["sub-total-title"].getData() : $(this).find('#sub-total-title').val());
247
									params.under_title = $(this).find('select[name=under_title]').val();
248
									params.free_text = $(this).find('select[name=free_text]').val();
249
									params.level = $(this).find('select[name=subtotal_line_level]').val();
250
251
									$.ajax({
252
										url: url_ajax
253
										,type: 'POST'
254
										,data: params
255
									}).done(function() {
256
										document.location.href=url_to;
257
									});
258
259
                                    $( this ).dialog( "close" );
260
	                            },
261
	                            "<?php echo $langs->trans('Cancel') ?>": function() {
262
	                                $( this ).dialog( "close" );
263
	                            }
264
	                        }
265
	                     });
266
					}
267
268
					$('a[rel=add_title_line]').click(function()
269
					{
270
						promptSubTotal('addTitle'
271
							 , "<?php echo $langs->trans('YourTitleLabel') ?>"
272
							 , "<?php echo $langs->trans('title'); ?>"
273
							 , '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
274
							 , '<?php echo $_SERVER['PHP_SELF']; ?>'
275
							 , {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_title_line'}
276
						);
277
					});
278
279
					$('a[rel=add_total_line]').click(function()
280
					{
281
						promptSubTotal('addSubtotal'
282
							, '<?php echo $langs->trans('YourSubtotalLabel') ?>'
283
							, '<?php echo $langs->trans('subtotal'); ?>'
284
							, '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
285
							, '<?php echo $_SERVER['PHP_SELF']; ?>'
286
							, {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_total_line'}
287
							/*,false,false, <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?>*/
288
						);
289
					});
290
291
					$('a[rel=add_free_text]').click(function()
292
					{
293
						promptSubTotal('addFreeTxt'
294
							, "<?php echo $langs->transnoentitiesnoconv('YourTextLabel') ?>"
295
							, "<?php echo $langs->trans('subtotalAddLineDescription'); ?>"
296
							, '?<?php echo $idvar ?>=<?php echo $object->id; ?>'
297
							, '<?php echo $_SERVER['PHP_SELF']; ?>'
298
							, {<?php echo $idvar; ?>: <?php echo (int) $object->id; ?>, action:'add_free_text'}
299
							, true
300
							, true
301
							, <?php echo !empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) ? 'true' : 'false'; ?>
302
						);
303
					});
304
				});
305
		 	</script>
306
		 <?php
307
	}
308
309
	function showSelectTitleToAdd(&$object)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
310
	{
311
		global $langs;
312
313
		dol_include_once('/subtotal/class/subtotal.class.php');
0 ignored issues
show
Bug introduced by
The function dol_include_once was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

313
		/** @scrutinizer ignore-call */ 
314
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
314
		dol_include_once('/subtotal/lib/subtotal.lib.php');
315
		$TTitle = TSubtotal::getAllTitleFromDocument($object);
0 ignored issues
show
Unused Code introduced by
The assignment to $TTitle is dead and can be removed.
Loading history...
316
317
		?>
318
		<script type="text/javascript">
319
			$(function() {
320
				var add_button = $("#addline");
321
322
				if (add_button.length > 0)
323
				{
324
					add_button.closest('tr').prev('tr.liste_titre').children('td:last').addClass('center').text("<?php echo $langs->trans('subtotal_title_to_add_under_title'); ?>");
325
					var select_title = $(<?php echo json_encode(getHtmlSelectTitle($object)); ?>);
326
327
					add_button.before(select_title);
328
				}
329
			});
330
		</script>
331
		<?php
332
	}
333
334
335
	function formBuilddocOptions($parameters) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
336
	/* Réponse besoin client */
337
338
		global $conf, $langs, $bc;
339
340
		$action = GETPOST('action');
0 ignored issues
show
Unused Code introduced by
The assignment to $action is dead and can be removed.
Loading history...
Bug introduced by
The function GETPOST was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
409
    {
410
411
    	if (in_array('invoicecard',explode(':',$parameters['context'])))
412
        {
413
414
        }
415
416
        return 0;
417
    }
418
419
	function ODTSubstitutionLine(&$parameters, &$object, $action, $hookmanager) {
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed. ( Ignorable by Annotation )

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
463
464
		if (
465
				in_array('invoicecard',explode(':',$parameters['context']))
466
		        || in_array('invoicesuppliercard',explode(':',$parameters['context']))
467
				|| in_array('propalcard',explode(':',$parameters['context']))
468
		        || in_array('supplier_proposalcard',explode(':',$parameters['context']))
469
				|| in_array('ordercard',explode(':',$parameters['context']))
470
		        || in_array('ordersuppliercard',explode(':',$parameters['context']))
471
				|| in_array('invoicereccard',explode(':',$parameters['context']))
472
		) {
473
474
			global $db;
475
476
			$objFrom = $parameters['objFrom'];
477
478
			foreach($objFrom->lines as $k=> &$lineOld) {
479
480
					if($lineOld->product_type == 9 && $lineOld->info_bits > 0 ) {
481
482
							$line = & $object->lines[$k];
483
484
							$idLine = (int) ($line->id ? $line->id : $line->rowid);
485
486
							$db->query("UPDATE ".MAIN_DB_PREFIX.$line->table_element."
0 ignored issues
show
Bug introduced by
The constant MAIN_DB_PREFIX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
487
							SET info_bits=".(int)$lineOld->info_bits."
488
							WHERE rowid = ".$idLine."
489
							");
490
491
					}
492
493
494
			}
495
496
497
		}
498
499
	}
500
501
	function doActions($parameters, &$object, $action, $hookmanager)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

Loading history...
502
	{
503
		global $db, $conf, $langs,$user;
504
505
		dol_include_once('/subtotal/class/subtotal.class.php');
0 ignored issues
show
Bug introduced by
The function dol_include_once was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

505
		/** @scrutinizer ignore-call */ 
506
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
506
		dol_include_once('/subtotal/lib/subtotal.lib.php');
507
		require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
0 ignored issues
show
Bug introduced by
The constant DOL_DOCUMENT_ROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
508
509
		$showBlockExtrafields = GETPOST('showBlockExtrafields');
0 ignored issues
show
Bug introduced by
The function GETPOST was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

509
		$showBlockExtrafields = /** @scrutinizer ignore-call */ GETPOST('showBlockExtrafields');
Loading history...
510
511
		if($object->element=='facture') $idvar = 'facid';
512
		else $idvar = 'id';
513
514
		if ($action == 'updateligne' || $action == 'updateline')
515
		{
516
			$found = false;
517
			$lineid = GETPOST('lineid', 'int');
518
			foreach ($object->lines as &$line)
519
			{
520
521
				if ($line->id == $lineid && TSubtotal::isModSubtotalLine($line))
522
				{
523
					$found = true;
524
					if(TSubtotal::isTitle($line) && !empty($showBlockExtrafields)) {
525
						$extrafieldsline = new ExtraFields($db);
0 ignored issues
show
Bug introduced by
The type ExtraFields was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
683
		return 0;
684
	}
685
686
	function getArrayOfLineForAGroup(&$object, $lineid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

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

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

Loading history...
739
740
		$rang = $line->rang;
741
		$qty_line = $line->qty;
742
743
		$total = 0;
744
		$total_tva = 0;
745
		$total_ttc = 0;
746
		$TTotal_tva = array();
747
748
		dol_include_once('/subtotal/class/subtotal.class.php');
0 ignored issues
show
Bug introduced by
The function dol_include_once was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

748
		/** @scrutinizer ignore-call */ 
749
  dol_include_once('/subtotal/class/subtotal.class.php');
Loading history...
749
		foreach($object->lines as $l) {
750
			//print $l->rang.'>='.$rang.' '.$total.'<br/>';
751
			if($l->rang>=$rang) {
752
				//echo 'return!<br>';
753
				if (!$return_all) return $total;
754
				else return array($total, $total_tva, $total_ttc, $TTotal_tva);
755
			}
756
			else if(TSubtotal::isTitle($l, 100 - $qty_line))
757
		  	{
758
				$total = 0;
759
				$total_tva = 0;
760
				$total_ttc = 0;
761
				$TTotal_tva = array();
762
			}
763
			elseif(!TSubtotal::isTitle($l) && !TSubtotal::isSubtotal($l)) {
764
				$total += $l->total_ht;
765
				$total_tva += $l->total_tva;
766
				$TTotal_tva[$l->tva_tx] += $l->total_tva;
767
				$total_ttc += $l->total_ttc;
768
			}
769
770
		}
771
		if (!$return_all) return $total;
772
		else return array($total, $total_tva, $total_ttc, $TTotal_tva);
773
	}
774
775
	/*
776
	 * Get the sum of situation invoice for last column
777
	 */
778
	function getTotalToPrintSituation(&$object, &$line) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
779
780
		$rang = $line->rang;
781
		$total = 0;
782
		foreach($object->lines as $l) {
783
			if($l->rang>=$rang) {
784
				return price($total);
0 ignored issues
show
Bug introduced by
The function price was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

784
				return /** @scrutinizer ignore-call */ price($total);
Loading history...
785
			}
786
                        if (TSubtotal::isSubtotal($l)){
787
                            $total = 0;
788
                        } else  if ($l->situation_percent > 0 ){
789
790
791
		 	$prev_progress = $l->get_prev_progress($object->id);
792
		 	$progress = ($l->situation_percent - $prev_progress) /100;
793
                        $total += ($l->total_ht/($l->situation_percent/100)) * $progress;
794
795
                    }
796
                }
797
798
		return price($total);
799
	}
800
801
	/**
802
	 * @param $pdf          TCPDF               PDF object
0 ignored issues
show
Bug introduced by
The type TCPDF was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
803
	 * @param $object       CommonObject        dolibarr object
0 ignored issues
show
Bug introduced by
The type CommonObject was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
804
	 * @param $line         CommonObjectLine    dolibarr object line
0 ignored issues
show
Bug introduced by
The type CommonObjectLine was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
805
	 * @param $label        string
806
	 * @param $description  string
807
	 * @param $posx         float               horizontal position
808
	 * @param $posy         float               vertical position
809
	 * @param $w            float               width
810
	 * @param $h            float               height
811
	 */
812
	function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

Loading history...
813
		global $conf,$subtotal_last_title_posy;
814
815
		$hideInnerLines = (int)GETPOST('hideInnerLines');
0 ignored issues
show
Bug introduced by
The function GETPOST was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

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

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

862
			$total_to_print = /** @scrutinizer ignore-call */ price($line->total);
Loading history...
863
864
			if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS))
865
			{
866
				$TTitle = TSubtotal::getAllTitleFromLine($line);
867
				foreach ($TTitle as &$line_title)
868
				{
869
					if (!empty($line_title->array_options['options_subtotal_nc']))
870
					{
871
						$total_to_print = ''; // TODO Gestion "Compris/Non compris", voir si on affiche une annotation du genre "NC"
872
						break;
873
					}
874
				}
875
			}
876
877
			if($total_to_print) {
878
879
				if (GETPOST('hideInnerLines'))
880
				{
881
					// Dans le cas des lignes cachés, le calcul est déjà fait dans la méthode beforePDFCreation et les lignes de sous-totaux sont déjà renseignés
882
//					$line->TTotal_tva
883
//					$line->total_ht
884
//					$line->total_tva
885
//					$line->total
886
//					$line->total_ttc
887
				}
888
				else
889
				{
890
					list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1);
891
                                        if(get_class($object) == 'Facture' && $object->type==Facture::TYPE_SITUATION){//Facture de situation
0 ignored issues
show
Bug introduced by
The type Facture was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
892
                                                $total_to_print = $this->getTotalToPrintSituation($object, $line);
893
                                        } else {
894
                                            	$total_to_print = price($total);
895
                                        }
896
897
					$line->total_ht = $total;
898
					$line->total = $total;
899
					$line->total_tva = $total_tva;
900
					$line->total_ttc = $total_ttc;
901
				}
902
			}
903
904
			$pdf->SetXY($pdf->postotalht, $posy);
905
			if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $bMargin does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $pageBreakOriginalValue does not seem to be defined for all execution paths leading up to this point.
Loading history...
906
			$pdf->MultiCell($pdf->page_largeur-$pdf->marge_droite-$pdf->postotalht, 3, $total_to_print, 0, 'R', 0);
907
		}
908
		else{
909
			if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin);
910
		}
911
912
		$posy = $posy + $cell_height;
913
		$pdf->SetXY($posx, $posy);
914
915
916
	}
917
918
	/**
919
	 * @param $pdf          TCPDF               PDF object
920
	 * @param $object       CommonObject        dolibarr object
921
	 * @param $line         CommonObjectLine    dolibarr object line
922
	 * @param $label        string
923
	 * @param $description  string
924
	 * @param $posx         float               horizontal position
925
	 * @param $posy         float               vertical position
926
	 * @param $w            float               width
927
	 * @param $h            float               height
928
	 */
929
	function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

Loading history...
930
931
		global $db,$conf,$subtotal_last_title_posy;
932
933
		$subtotal_last_title_posy = $posy;
934
		$pdf->SetXY ($posx, $posy);
935
936
		$hideInnerLines = (int)GETPOST('hideInnerLines');
0 ignored issues
show
Bug introduced by
The function GETPOST was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

936
		$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
937
938
939
940
		$style = ($line->qty==1) ? 'BU' : 'BUI';
941
		if (!empty($conf->global->SUBTOTAL_TITLE_STYLE)) $style = $conf->global->SUBTOTAL_TITLE_STYLE;
942
943
		if($hideInnerLines) {
944
			if($line->qty==1)$pdf->SetFont('', $style, 9);
945
			else
946
			{
947
				if (!empty($conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES)) $style = $conf->global->SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES;
948
				$pdf->SetFont('', $style, 9);
949
			}
950
		}
951
		else {
952
953
			if($line->qty==1)$pdf->SetFont('', $style, 9); //TODO if super utile
954
			else $pdf->SetFont('', $style, 9);
955
956
		}
957
958
		if ($label === strip_tags($label) && $label === dol_html_entity_decode($label, ENT_QUOTES)) $pdf->MultiCell($w, $h, $label, 0, 'L'); // Pas de HTML dans la chaine
0 ignored issues
show
Bug introduced by
The function dol_html_entity_decode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

958
		if ($label === strip_tags($label) && $label === /** @scrutinizer ignore-call */ dol_html_entity_decode($label, ENT_QUOTES)) $pdf->MultiCell($w, $h, $label, 0, 'L'); // Pas de HTML dans la chaine
Loading history...
959
		else $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'J',true); // et maintenant avec du HTML
960
961
		if($description && !$hidedesc) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $hidedesc seems to be never defined.
Loading history...
962
			$posy = $pdf->GetY();
963
964
			$pdf->SetFont('', '', 8);
965
966
			$pdf->writeHTMLCell($w, $h, $posx, $posy, $description, 0, 1, false, true, 'J',true);
967
968
		}
969
970
	}
971
972
	function pdf_writelinedesc_ref($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
973
	// ultimate PDF hook O_o
974
975
		return $this->pdf_writelinedesc($parameters,$object,$action);
976
977
	}
978
979
	function isModSubtotalLine(&$parameters, &$object) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

Loading history...
980
981
		if(is_array($parameters)) {
982
			$i = & $parameters['i'];
983
		}
984
		else {
985
			$i = (int)$parameters;
986
		}
987
988
989
		if($object->lines[$i]->special_code == $this->module_number && $object->lines[$i]->product_type == 9) {
990
			return true;
991
		}
992
993
		return false;
994
995
	}
996
997
	function pdf_getlineqty($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

Loading history...
998
		global $conf,$hideprices;
999
1000
		if($this->isModSubtotalLine($parameters,$object) ){
1001
1002
			$this->resprints = ' ';
0 ignored issues
show
Bug Best Practice introduced by
The property resprints does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1003
1004
			if((float)DOL_VERSION<=3.6) {
0 ignored issues
show
Bug introduced by
The constant DOL_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1005
				return '';
1006
			}
1007
			else if((float)DOL_VERSION>=3.8) {
1008
				return 1;
1009
			}
1010
1011
		}
1012
		elseif(!empty($hideprices)) {
1013
			$this->resprints = $object->lines[$parameters['i']]->qty;
1014
			return 1;
1015
		}
1016
		elseif (!empty($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY))
1017
		{
1018
			$hideInnerLines = (int)GETPOST('hideInnerLines');
0 ignored issues
show
Bug introduced by
The function GETPOST was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

1018
			$hideInnerLines = (int)/** @scrutinizer ignore-call */ GETPOST('hideInnerLines');
Loading history...
1019
			$hidedetails = (int)GETPOST('hidedetails');
1020
			if (empty($hideInnerLines) && !empty($hidedetails))
1021
			{
1022
				$this->resprints = $object->lines[$parameters['i']]->qty;
1023
			}
1024
		}
1025
1026
		if(is_array($parameters)) $i = & $parameters['i'];
1027
		else $i = (int)$parameters;
1028
1029
		if (empty($object->lines[$i])) return 0; // hideInnerLines => override $object->lines et Dolibarr ne nous permet pas de mettre à jour la variable qui conditionne la boucle sur les lignes (PR faite pour 6.0)
1030
1031
		$object->lines[$i]->fetch_optionals();
1032
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1033
		{
1034
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1035
			{
1036
				$this->resprints = ' ';
1037
				return 1;
1038
			}
1039
		}
1040
1041
		return 0;
1042
	}
1043
1044
	function pdf_getlinetotalexcltax($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

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

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

1086
		    $this->resprints = /** @scrutinizer ignore-call */ price($object->lines[$i]->total_ht);
Loading history...
1087
		}
1088
		if (!empty($hideprices)
1089
		    || (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $i does not seem to be defined for all execution paths leading up to this point.
Loading history...
1090
		    )
1091
		{
1092
		    if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1093
		    {
1094
		        $this->resprints = ' ';
1095
		        return 1;
1096
		    }
1097
		}
1098
1099
		return 0;
1100
	}
1101
1102
	function pdf_getlinetotalwithtax($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Unused Code introduced by
The parameter $action is not used and could be removed. ( Ignorable by Annotation )

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

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

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

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

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

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

1132
	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...
1133
		global $conf;
1134
1135
		if($this->isModSubtotalLine($parameters,$object) ){
1136
			$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...
1137
1138
			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...
1139
				return '';
1140
			}
1141
			else if((float)DOL_VERSION>=3.8) {
1142
				return 1;
1143
			}
1144
		}
1145
1146
		if(is_array($parameters)) $i = & $parameters['i'];
1147
		else $i = (int)$parameters;
1148
1149
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1150
		{
1151
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1152
			{
1153
				$this->resprints = ' ';
1154
				return 1;
1155
			}
1156
		}
1157
1158
		return 0;
1159
	}
1160
1161
	function pdf_getlineupexcltax($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

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

1191
	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...
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...
1192
		global $conf,$hideprices;
1193
1194
		if($this->isModSubtotalLine($parameters,$object) ){
1195
			$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...
1196
			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...
1197
				return '';
1198
			}
1199
			else if((float)DOL_VERSION>=3.8) {
1200
				return 1;
1201
			}
1202
		}
1203
1204
		if(is_array($parameters)) $i = & $parameters['i'];
1205
		else $i = (int)$parameters;
1206
1207
		if (!empty($hideprices)
1208
				|| (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1209
		)
1210
		{
1211
			if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1212
			{
1213
				$this->resprints = ' ';
1214
				return 1;
1215
			}
1216
		}
1217
1218
		return 0;
1219
	}
1220
1221
	function pdf_getlinevatrate($parameters=array(), &$object, &$action='') {
0 ignored issues
show
Unused Code introduced by
The parameter $action is not used and could be removed. ( Ignorable by Annotation )

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

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

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

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

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

Loading history...
1222
		global $conf;
1223
1224
		if($this->isModSubtotalLine($parameters,$object) ){
1225
			$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...
1226
1227
			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...
1228
				return '';
1229
			}
1230
			else if((float)DOL_VERSION>=3.8) {
1231
				return 1;
1232
			}
1233
		}
1234
1235
		if(is_array($parameters)) $i = & $parameters['i'];
1236
		else $i = (int)$parameters;
1237
1238
		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)
1239
1240
		$object->lines[$i]->fetch_optionals();
1241
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) )
1242
		{
1243
			if (!in_array(__FUNCTION__, explode(',', $conf->global->SUBTOTAL_TFIELD_TO_KEEP_WITH_NC)))
1244
			{
1245
				$this->resprints = ' ';
1246
				return 1;
1247
			}
1248
		}
1249
1250
		return 0;
1251
	}
1252
1253
	function pdf_getlineprogress($parameters=array(), &$object, &$action) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

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

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

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

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

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

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

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

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

Loading history...
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1882
								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...
1883
							}
1884
							else{
1885
								print '<span class="subtotal_label classfortooltip '.$titleStyleItalic.$titleStyleBold.$titleStyleUnderline.'" title="'.$line->description.'">'.$line->label.'</span>';
1886
							}
1887
1888
						 }
1889
						if($line->qty>90) print ' : ';
1890
						if($line->info_bits > 0) echo img_picto($langs->trans('Pagebreak'), 'pagebreak@subtotal');
1891
1892
1893
1894
1895
					}
1896
			?></td>
1897
1898
			<?php
1899
				if($line->qty>90) {
1900
					/* Total */
1901
					$total_line = $this->getTotalLineFromObject($object, $line, '');
1902
					echo '<td class="nowrap liencolht" align="right" style="font-weight:bold;" rel="subtotal_total">'.price($total_line).'</td>';
0 ignored issues
show
Bug introduced by
The function price was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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