Passed
Branch develop (5cbde9)
by
unknown
26:38
created

PaymentVarious::create()   F

Complexity

Conditions 26
Paths 1596

Size

Total Lines 163
Code Lines 104

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 26
eloc 104
c 0
b 0
f 0
nc 1596
nop 1
dl 0
loc 163
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* Copyright (C) 2017-2019  Alexandre Spangaro      <[email protected]>
3
 * Copyright (C) 2018       Frédéric France         <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
/**
20
 *  \file		htdocs/compta/bank/class/paymentvarious.class.php
21
 *  \ingroup	bank
22
 *  \brief		Class for various payment
23
 */
24
25
// Put here all includes required by your class file
26
require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
27
28
29
/**
30
 *  Class to manage various payments
31
 */
32
class PaymentVarious extends CommonObject
33
{
34
	/**
35
	 * @var string ID to identify managed object
36
	 */
37
	public $element='variouspayment';
38
39
	/**
40
	 * @var string Name of table without prefix where object is stored
41
	 */
42
	public $table_element='payment_various';
43
44
	/**
45
	 * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
46
	 */
47
	public $picto = 'payment';
48
49
	/**
50
	 * @var int ID
51
	 */
52
	public $id;
53
54
	/**
55
	 * @var string Ref
56
	 */
57
	public $ref;
58
59
	public $tms;
60
	public $datep;
61
	public $datev;
62
	public $sens;
63
	public $amount;
64
	public $type_payment;
65
	public $num_payment;
66
    public $category_transaction;
67
68
	/**
69
     * @var string various payments label
70
     */
71
    public $label;
72
73
	public $accountancy_code;
74
75
    public $subledger_account;
76
77
	/**
78
     * @var int ID
79
     */
80
	public $fk_project;
81
82
	/**
83
     * @var int ID
84
     */
85
	public $fk_bank;
86
87
	/**
88
     * @var int ID
89
     */
90
	public $fk_user_author;
91
92
	/**
93
     * @var int ID
94
     */
95
	public $fk_user_modif;
96
97
98
	/**
99
	 *	Constructor
100
	 *
101
	 *  @param		DoliDB		$db      Database handler
102
	 */
103
    public function __construct($db)
104
	{
105
		$this->db = $db;
106
		$this->element = 'payment_various';
107
		$this->table_element = 'payment_various';
108
	}
109
110
	/**
111
	 * Update database
112
	 *
113
	 * @param   User	$user        	User that modify
114
	 * @param   int		$notrigger      0=no, 1=yes (no update trigger)
115
	 * @return  int         			<0 if KO, >0 if OK
116
	 */
117
    public function update($user = null, $notrigger = 0)
118
	{
119
		global $conf, $langs;
120
121
		$error=0;
122
123
		// Clean parameters
124
		$this->amount=trim($this->amount);
125
		$this->label=trim($this->label);
126
		$this->note=trim($this->note);
1 ignored issue
show
Deprecated Code introduced by
The property CommonObject::$note has been deprecated. ( Ignorable by Annotation )

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

126
		/** @scrutinizer ignore-deprecated */ $this->note=trim($this->note);
Loading history...
127
		$this->fk_bank = (int) $this->fk_bank;
128
		$this->fk_user_author = (int) $this->fk_user_author;
129
		$this->fk_user_modif = (int) $this->fk_user_modif;
130
131
		$this->db->begin();
132
133
		// Update request
134
		$sql = "UPDATE ".MAIN_DB_PREFIX."payment_various SET";
135
		if ($this->tms) $sql.= " tms='".$this->db->idate($this->tms)."',";
136
		$sql.= " datep='".$this->db->idate($this->datep)."',";
137
		$sql.= " datev='".$this->db->idate($this->datev)."',";
138
		$sql.= " sens=".$this->sens.",";
139
		$sql.= " amount=".price2num($this->amount).",";
140
		$sql.= " fk_typepayment=".$this->fk_typepayment."',";
0 ignored issues
show
Bug introduced by
The property fk_typepayment does not exist on PaymentVarious. Did you mean fk_type?
Loading history...
141
		$sql.= " num_payment='".$this->db->escape($this->num_payment)."',";
142
		$sql.= " label='".$this->db->escape($this->label)."',";
143
		$sql.= " note='".$this->db->escape($this->note)."',";
1 ignored issue
show
Deprecated Code introduced by
The property CommonObject::$note has been deprecated. ( Ignorable by Annotation )

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

143
		$sql.= " note='".$this->db->escape(/** @scrutinizer ignore-deprecated */ $this->note)."',";
Loading history...
144
		$sql.= " accountancy_code='".$this->db->escape($this->accountancy_code)."',";
145
        $sql.= " subledger_account='".$this->db->escape($this->subledger_account)."',";
146
		$sql.= " fk_projet='".$this->db->escape($this->fk_project)."',";
147
		$sql.= " fk_bank=".($this->fk_bank > 0 ? $this->fk_bank:"null").",";
148
		$sql.= " fk_user_author=".$this->fk_user_author.",";
149
		$sql.= " fk_user_modif=".$this->fk_user_modif;
150
		$sql.= " WHERE rowid=".$this->id;
151
152
		dol_syslog(get_class($this)."::update", LOG_DEBUG);
153
		$resql = $this->db->query($sql);
154
		if (! $resql)
155
		{
156
			$this->error="Error ".$this->db->lasterror();
157
			return -1;
158
		}
159
160
		if (! $notrigger)
161
		{
162
			// Call trigger
163
			$result=$this->call_trigger('PAYMENT_VARIOUS_MODIFY', $user);
164
			if ($result < 0) $error++;
165
			// End call triggers
166
		}
167
168
		if (! $error)
169
		{
170
			$this->db->commit();
171
			return 1;
172
		}
173
		else
174
		{
175
			$this->db->rollback();
176
			return -1;
177
		}
178
	}
179
180
181
	/**
182
	 *  Load object in memory from database
183
	 *
184
	 *  @param	int		$id         id object
185
	 *  @param  User	$user       User that load
186
	 *  @return int         		<0 if KO, >0 if OK
187
	 */
188
    public function fetch($id, $user = null)
189
	{
190
		global $langs;
191
		$sql = "SELECT";
192
		$sql.= " v.rowid,";
193
		$sql.= " v.tms,";
194
		$sql.= " v.datep,";
195
		$sql.= " v.datev,";
196
		$sql.= " v.sens,";
197
		$sql.= " v.amount,";
198
		$sql.= " v.fk_typepayment,";
199
		$sql.= " v.num_payment,";
200
		$sql.= " v.label,";
201
		$sql.= " v.note,";
202
		$sql.= " v.accountancy_code,";
203
		$sql.= " v.subledger_account,";
204
		$sql.= " v.fk_projet as fk_project,";
205
		$sql.= " v.fk_bank,";
206
		$sql.= " v.fk_user_author,";
207
		$sql.= " v.fk_user_modif,";
208
		$sql.= " b.fk_account,";
209
		$sql.= " b.fk_type,";
210
		$sql.= " b.rappro";
211
		$sql.= " FROM ".MAIN_DB_PREFIX."payment_various as v";
212
		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
213
		$sql.= " WHERE v.rowid = ".$id;
214
215
		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
216
		$resql=$this->db->query($sql);
217
		if ($resql)
218
		{
219
			if ($this->db->num_rows($resql))
220
			{
221
				$obj = $this->db->fetch_object($resql);
222
223
				$this->id                   = $obj->rowid;
224
				$this->ref                  = $obj->rowid;
225
				$this->tms                  = $this->db->jdate($obj->tms);
226
				$this->datep                = $this->db->jdate($obj->datep);
227
				$this->datev                = $this->db->jdate($obj->datev);
228
				$this->sens                 = $obj->sens;
229
				$this->amount               = $obj->amount;
230
				$this->type_payment         = $obj->fk_typepayment;
231
				$this->num_payment          = $obj->num_payment;
232
				$this->label                = $obj->label;
233
				$this->note                 = $obj->note;
234
				$this->subledger_account    = $obj->subledger_account;
235
				$this->accountancy_code     = $obj->accountancy_code;
236
				$this->fk_project           = $obj->fk_project;
237
				$this->fk_bank              = $obj->fk_bank;
238
				$this->fk_user_author       = $obj->fk_user_author;
239
				$this->fk_user_modif        = $obj->fk_user_modif;
240
				$this->fk_account           = $obj->fk_account;
241
				$this->fk_type              = $obj->fk_type;
242
				$this->rappro               = $obj->rappro;
243
			}
244
			$this->db->free($resql);
245
246
			return 1;
247
		}
248
		else
249
		{
250
			$this->error="Error ".$this->db->lasterror();
251
			return -1;
252
		}
253
	}
254
255
256
	/**
257
	 *  Delete object in database
258
	 *
259
	 *	@param	User	$user       User that delete
260
	 *	@return	int					<0 if KO, >0 if OK
261
	 */
262
    public function delete($user)
263
	{
264
		global $conf, $langs;
265
266
		$error=0;
267
268
		// Call trigger
269
		$result=$this->call_trigger('PAYMENT_VARIOUS_DELETE', $user);
270
		if ($result < 0) return -1;
271
		// End call triggers
272
273
274
		$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_various";
275
		$sql.= " WHERE rowid=".$this->id;
276
277
		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
278
		$resql = $this->db->query($sql);
279
		if (! $resql)
280
		{
281
			$this->error="Error ".$this->db->lasterror();
282
			return -1;
283
		}
284
285
		return 1;
286
	}
287
288
289
	/**
290
	 *  Initialise an instance with random values.
291
	 *  Used to build previews or test instances.
292
	 *	id must be 0 if object instance is a specimen.
293
	 *
294
	 *  @return	void
295
	 */
296
    public function initAsSpecimen()
297
	{
298
		$this->id=0;
299
300
		$this->tms='';
301
		$this->datep='';
302
		$this->datev='';
303
		$this->sens='';
304
		$this->amount='';
305
		$this->label='';
306
		$this->accountancy_code='';
307
        $this->subledger_account='';
308
		$this->note='';
1 ignored issue
show
Deprecated Code introduced by
The property CommonObject::$note has been deprecated. ( Ignorable by Annotation )

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

308
		/** @scrutinizer ignore-deprecated */ $this->note='';
Loading history...
309
		$this->fk_bank='';
1 ignored issue
show
Documentation Bug introduced by
The property $fk_bank was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
310
		$this->fk_user_author='';
1 ignored issue
show
Documentation Bug introduced by
The property $fk_user_author was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
311
		$this->fk_user_modif='';
1 ignored issue
show
Documentation Bug introduced by
The property $fk_user_modif was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
312
	}
313
314
	/**
315
	 *  Create in database
316
	 *
317
	 *  @param   User   $user   User that create
318
	 *  @return  int            <0 if KO, >0 if OK
319
	 */
320
    public function create($user)
321
	{
322
		global $conf,$langs;
323
324
		$error=0;
325
		$now=dol_now();
326
327
		// Clean parameters
328
		$this->amount=price2num(trim($this->amount));
329
		$this->label=trim($this->label);
330
		$this->note=trim($this->note);
1 ignored issue
show
Deprecated Code introduced by
The property CommonObject::$note has been deprecated. ( Ignorable by Annotation )

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

330
		/** @scrutinizer ignore-deprecated */ $this->note=trim($this->note);
Loading history...
331
		$this->fk_bank = (int) $this->fk_bank;
332
		$this->fk_user_author = (int) $this->fk_user_author;
333
		$this->fk_user_modif = (int) $this->fk_user_modif;
334
335
		// Check parameters
336
		if (! $this->label)
337
		{
338
			$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
339
			return -3;
340
		}
341
		if ($this->amount < 0 || $this->amount == '')
342
		{
343
			$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
344
			return -5;
345
		}
346
		if (! empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
0 ignored issues
show
Bug Best Practice introduced by
The property accountid does not exist on PaymentVarious. Did you maybe forget to declare it?
Loading history...
347
		{
348
			$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
349
			return -6;
350
		}
351
		if (! empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
352
		{
353
			$this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
354
			return -7;
355
		}
356
357
		$this->db->begin();
358
359
		// Insert into llx_payment_various
360
		$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_various (";
361
		$sql.= " datep";
362
		$sql.= ", datev";
363
		$sql.= ", sens";
364
		$sql.= ", amount";
365
		$sql.= ", fk_typepayment";
366
		$sql.= ", num_payment";
367
		if ($this->note) $sql.= ", note";
1 ignored issue
show
Deprecated Code introduced by
The property CommonObject::$note has been deprecated. ( Ignorable by Annotation )

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

367
		if (/** @scrutinizer ignore-deprecated */ $this->note) $sql.= ", note";
Loading history...
368
		$sql.= ", label";
369
		$sql.= ", accountancy_code";
370
		$sql.= ", subledger_account";
371
		$sql.= ", fk_projet";
372
		$sql.= ", fk_user_author";
373
		$sql.= ", datec";
374
		$sql.= ", fk_bank";
375
		$sql.= ", entity";
376
		$sql.= ")";
377
		$sql.= " VALUES (";
378
		$sql.= "'".$this->db->idate($this->datep)."'";
379
		$sql.= ", '".$this->db->idate($this->datev)."'";
380
		$sql.= ", '".$this->db->escape($this->sens)."'";
381
		$sql.= ", ".$this->amount;
382
		$sql.= ", '".$this->db->escape($this->type_payment)."'";
383
		$sql.= ", '".$this->db->escape($this->num_payment)."'";
384
		if ($this->note) $sql.= ", '".$this->db->escape($this->note)."'";
1 ignored issue
show
Deprecated Code introduced by
The property CommonObject::$note has been deprecated. ( Ignorable by Annotation )

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

384
		if (/** @scrutinizer ignore-deprecated */ $this->note) $sql.= ", '".$this->db->escape($this->note)."'";
Loading history...
385
		$sql.= ", '".$this->db->escape($this->label)."'";
386
		$sql.= ", '".$this->db->escape($this->accountancy_code)."'";
387
		$sql.= ", '".$this->db->escape($this->subledger_account)."'";
388
		$sql.= ", ".($this->fk_project > 0? $this->fk_project : 0);
389
		$sql.= ", ".$user->id;
390
		$sql.= ", '".$this->db->idate($now)."'";
391
		$sql.= ", NULL";
392
		$sql.= ", ".$conf->entity;
393
		$sql.= ")";
394
395
		dol_syslog(get_class($this)."::create", LOG_DEBUG);
396
		$result = $this->db->query($sql);
397
		if ($result)
398
		{
399
			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_various");
400
			$this->ref = $this->id;
401
402
			if ($this->id > 0)
403
			{
404
				if (! empty($conf->banque->enabled) && ! empty($this->amount))
405
				{
406
					// Insert into llx_bank
407
					require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
408
409
					$acc = new Account($this->db);
410
					$result=$acc->fetch($this->accountid);
411
					if ($result <= 0) dol_print_error($this->db);
412
413
					// Insert payment into llx_bank
414
					// Add link 'payment_various' in bank_url between payment and bank transaction
415
					$sign=1;
416
					if ($this->sens == '0') $sign=-1;
417
418
                    $bank_line_id = $acc->addline(
419
						$this->datep,
420
						$this->type_payment,
421
						$this->label,
422
						$sign * abs($this->amount),
423
						$this->num_payment,
424
                        ($this->category_transaction > 0 ? $this->category_transaction : 0),
425
						$user
426
					);
427
428
					// Update fk_bank into llx_paiement.
429
					// So we know the payment which has generate the banking ecriture
430
					if ($bank_line_id > 0)
431
					{
432
						$this->update_fk_bank($bank_line_id);
433
					}
434
					else
435
					{
436
						$this->error=$acc->error;
437
						$error++;
438
					}
439
440
					if (! $error)
441
					{
442
						// Add link 'payment_various' in bank_url between payment and bank transaction
443
						$url=DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id=';
444
445
						$result=$acc->add_url_line($bank_line_id, $this->id, $url, "(VariousPayment)", "payment_various");
446
						if ($result <= 0)
447
						{
448
							$this->error=$acc->error;
449
							$error++;
450
						}
451
					}
452
453
					if ($result <= 0)
454
					{
455
						$this->error=$acc->error;
456
						$error++;
457
					}
458
				}
459
460
				// Call trigger
461
				$result=$this->call_trigger('PAYMENT_VARIOUS_CREATE', $user);
462
				if ($result < 0) $error++;
463
				// End call triggers
464
			}
465
			else $error++;
466
467
			if (! $error)
468
			{
469
				$this->db->commit();
470
				return $this->id;
471
			}
472
			else
473
			{
474
				$this->db->rollback();
475
				return -2;
476
			}
477
		}
478
		else
479
		{
480
			$this->error=$this->db->error();
481
			$this->db->rollback();
482
			return -1;
483
		}
484
	}
485
486
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
487
	/**
488
	 *  Update link between payment various and line generate into llx_bank
489
	 *
490
	 *  @param  int     $id_bank    Id bank account
491
	 *	@return int                 <0 if KO, >0 if OK
492
	 */
493
    public function update_fk_bank($id_bank)
494
	{
495
        // phpcs:enable
496
		$sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_various SET fk_bank = '.$id_bank;
497
		$sql.= ' WHERE rowid = '.$this->id;
498
		$result = $this->db->query($sql);
499
		if ($result)
500
		{
501
			return 1;
502
		}
503
		else
504
		{
505
			dol_print_error($this->db);
506
			return -1;
507
		}
508
	}
509
510
511
	/**
512
	 * Retourne le libelle du statut
513
	 *
514
	 * @param	int		$mode   	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
515
	 * @return  string   		   	Libelle
516
	 */
517
    public function getLibStatut($mode = 0)
518
	{
519
		return $this->LibStatut($this->statut, $mode);
520
	}
521
522
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
523
	/**
524
	 *  Renvoi le libelle d'un statut donne
525
	 *
526
	 *  @param	int		$statut     Id status
527
	 *  @param  int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
528
	 *  @return string      		Libelle
529
	 */
530
    public function LibStatut($statut, $mode = 0)
531
	{
532
        // phpcs:enable
533
		global $langs;
534
535
		if ($mode == 0)
536
		{
537
			return $langs->trans($this->statuts[$statut]);
0 ignored issues
show
Bug introduced by
The property statuts does not exist on PaymentVarious. Did you mean statut?
Loading history...
538
		}
539
		elseif ($mode == 1)
540
		{
541
			return $langs->trans($this->statuts_short[$statut]);
0 ignored issues
show
Bug introduced by
The property statuts_short does not exist on PaymentVarious. Did you mean statut?
Loading history...
542
		}
543
		elseif ($mode == 2)
544
		{
545
			if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0').' '.$langs->trans($this->statuts_short[$statut]);
546
			elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4').' '.$langs->trans($this->statuts_short[$statut]);
547
			elseif ($statut==2) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6').' '.$langs->trans($this->statuts_short[$statut]);
548
		}
549
		elseif ($mode == 3)
550
		{
551
			if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0');
552
			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4');
553
			elseif ($statut==2 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6');
554
		}
555
		elseif ($mode == 4)
556
		{
557
			if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut0').' '.$langs->trans($this->statuts[$statut]);
558
			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4').' '.$langs->trans($this->statuts[$statut]);
559
			elseif ($statut==2 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut6').' '.$langs->trans($this->statuts[$statut]);
560
		}
561
		elseif ($mode == 5)
562
		{
563
			if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]), 'statut0');
564
			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]), 'statut4');
565
			elseif ($statut==2 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]), 'statut6');
566
		}
567
	}
568
569
570
	/**
571
	 *	Send name clicable (with possibly the picto)
572
	 *
573
	 *	@param  int		$withpicto					0=No picto, 1=Include picto into link, 2=Only picto
574
	 *	@param  string	$option						link option
575
	 *  @param  int     $save_lastsearch_value	 	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
576
     *  @param	int  	$notooltip		 			1=Disable tooltip
577
	 *	@return string								String with URL
578
	 */
579
    public function getNomUrl($withpicto = 0, $option = '', $save_lastsearch_value = -1, $notooltip = 0)
580
	{
581
		global $db, $conf, $langs, $hookmanager;
582
		global $langs;
583
584
		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
585
586
		$result='';
587
588
		$label='<u>'.$langs->trans("ShowVariousPayment").'</u>';
589
		$label.= '<br>';
590
		$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
591
592
		$url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$this->id;
593
594
		if ($option != 'nolink')
595
		{
596
			// Add param to save lastsearch_values or not
597
			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
598
			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
599
			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
600
		}
601
602
		$linkclose='';
603
		if (empty($notooltip))
604
		{
605
			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
606
			{
607
				$label=$langs->trans("ShowMyObject");
608
				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
609
			}
610
			$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
611
			$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $morecss seems to be never defined.
Loading history...
612
613
			/*
614
			 $hookmanager->initHooks(array('myobjectdao'));
615
			 $parameters=array('id'=>$this->id);
616
			 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
617
			 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
618
			 */
619
		}
620
		else $linkclose = ($morecss?' class="'.$morecss.'"':'');
621
622
		$linkstart = '<a href="'.$url.'"';
623
		$linkstart.=$linkclose.'>';
624
		$linkend='</a>';
625
626
		$result .= $linkstart;
627
		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
628
		if ($withpicto != 2) $result.= $this->ref;
629
		$result .= $linkend;
630
		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
631
632
		global $action;
633
		$hookmanager->initHooks(array('variouspayment'));
634
		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
635
		$reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
636
		if ($reshook > 0) $result = $hookmanager->resPrint;
637
		else $result .= $hookmanager->resPrint;
638
639
		return $result;
640
	}
641
642
	/**
643
	 * Information on record
644
	 *
645
	 * @param  int      $id      Id of record
646
	 * @return void
647
	 */
648
    public function info($id)
649
    {
650
		$sql = 'SELECT v.rowid, v.datec, v.fk_user_author';
651
		$sql.= ' FROM '.MAIN_DB_PREFIX.'payment_various as v';
652
		$sql.= ' WHERE v.rowid = '.$id;
653
654
		dol_syslog(get_class($this).'::info', LOG_DEBUG);
655
		$result = $this->db->query($sql);
656
657
		if ($result)
658
		{
659
			if ($this->db->num_rows($result))
660
			{
661
				$obj = $this->db->fetch_object($result);
662
				$this->id = $obj->rowid;
663
				if ($obj->fk_user_author)
664
				{
665
					$cuser = new User($this->db);
666
					$cuser->fetch($obj->fk_user_author);
667
					$this->user_creation = $cuser;
668
				}
669
				$this->date_creation = $this->db->jdate($obj->datec);
670
				if ($obj->fk_user_modif)
671
				{
672
					$muser = new User($this->db);
673
					$muser->fetch($obj->fk_user_modif);
674
					$this->user_modif = $muser;
675
				}
676
				$this->date_modif = $this->db->jdate($obj->tms);
677
			}
678
			$this->db->free($result);
679
		}
680
		else
681
		{
682
			dol_print_error($this->db);
683
		}
684
	}
685
}
686