Completed
Branch develop (4833c2)
by
unknown
24:33
created

PaymentSalary::update()   C

Complexity

Conditions 12
Paths 101

Size

Total Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
nc 101
nop 2
dl 0
loc 81
rs 5.9812
c 0
b 0
f 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) 2011-2019 Alexandre Spangaro   <[email protected]>
3
 * Copyright (C) 2014      Juanjo Menent        <[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/salaries/class/paymentsalary.class.php
21
 *  \ingroup    salaries
22
 *  \brief      Class for salaries module 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 salary payments
31
 */
32
class PaymentSalary extends CommonObject
33
{
34
    /**
35
     * @var string ID to identify managed object
36
     */
37
    public $element='payment_salary';
38
39
    /**
40
     * @var string Name of table without prefix where object is stored
41
     */
42
    public $table_element='payment_salary';
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
    public $tms;
50
51
    /**
52
     * @var int User ID
53
     */
54
    public $fk_user;
55
56
    public $datep;
57
    public $datev;
58
    public $amount;
59
60
    /**
61
     * @var int ID
62
     */
63
    public $fk_project;
64
65
    public $type_payment;
66
    public $num_payment;
67
68
    /**
69
     * @var string salary payments label
70
     */
71
    public $label;
72
73
    public $datesp;
74
    public $dateep;
75
76
    /**
77
     * @var int ID
78
     */
79
    public $fk_bank;
80
81
    /**
82
     * @var int ID
83
     */
84
    public $fk_user_author;
85
86
    /**
87
     * @var int ID
88
     */
89
    public $fk_user_modif;
90
91
92
    /**
93
     *	Constructor
94
     *
95
     *  @param		DoliDB		$db      Database handler
96
     */
97
    public function __construct($db)
98
    {
99
        $this->db = $db;
100
        $this->element = 'payment_salary';
101
        $this->table_element = 'payment_salary';
102
    }
103
104
    /**
105
     * Update database
106
     *
107
     * @param   User	$user        	User that modify
108
     * @param	int		$notrigger	    0=no, 1=yes (no update trigger)
109
     * @return  int         			<0 if KO, >0 if OK
110
     */
111
    public function update($user = null, $notrigger = 0)
112
    {
113
        global $conf, $langs;
114
115
        $error=0;
116
117
        // Clean parameters
118
        $this->amount=trim($this->amount);
119
        $this->label=trim($this->label);
120
        $this->note=trim($this->note);
121
122
        // Check parameters
123
        if (empty($this->fk_user) || $this->fk_user < 0)
124
        {
125
            $this->error='ErrorBadParameter';
126
            return -1;
127
        }
128
129
        $this->db->begin();
130
131
        // Update request
132
        $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET";
133
134
        $sql.= " tms='".$this->db->idate($this->tms)."',";
135
        $sql.= " fk_user=".$this->fk_user.",";
136
        $sql.= " datep='".$this->db->idate($this->datep)."',";
137
        $sql.= " datev='".$this->db->idate($this->datev)."',";
138
        $sql.= " amount=".price2num($this->amount).",";
139
        $sql.= " fk_projet=".((int) $this->fk_project).",";
140
        $sql.= " fk_typepayment=".$this->fk_typepayment."',";
141
        $sql.= " num_payment='".$this->db->escape($this->num_payment)."',";
142
        $sql.= " label='".$this->db->escape($this->label)."',";
143
        $sql.= " datesp='".$this->db->idate($this->datesp)."',";
144
        $sql.= " dateep='".$this->db->idate($this->dateep)."',";
145
        $sql.= " note='".$this->db->escape($this->note)."',";
146
        $sql.= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").",";
147
        $sql.= " fk_user_author=".((int) $this->fk_user_author).",";
148
        $sql.= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : 'null');
149
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
        // Update extrafield
161
        if (! $error)
162
        {
163
            if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
164
            {
165
                $result=$this->insertExtraFields();
166
                if ($result < 0)
167
                {
168
                    $error++;
169
                }
170
            }
171
        }
172
173
        if (! $notrigger)
174
        {
175
            // Call trigger
176
            $result=$this->call_trigger('PAYMENT_SALARY_MODIFY', $user);
0 ignored issues
show
Bug introduced by
It seems like $user defined by parameter $user on line 111 can be null; however, CommonObject::call_trigger() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
177
            if ($result < 0) $error++;
178
            // End call triggers
179
        }
180
181
        if (! $error)
182
        {
183
            $this->db->commit();
184
            return 1;
185
        }
186
        else
187
        {
188
            $this->db->rollback();
189
            return -1;
190
        }
191
    }
192
193
194
    /**
195
     *  Load object in memory from database
196
     *
197
     *  @param	int		$id         id object
198
     *  @param  User	$user       User that load
199
     *  @return int         		<0 if KO, >0 if OK
200
     */
201
    public function fetch($id, $user = null)
202
    {
203
        global $langs;
204
        $sql = "SELECT";
205
        $sql.= " s.rowid,";
206
207
        $sql.= " s.tms,";
208
        $sql.= " s.fk_user,";
209
        $sql.= " s.datep,";
210
        $sql.= " s.datev,";
211
        $sql.= " s.amount,";
212
        $sql.= " s.fk_projet as fk_project,";
213
        $sql.= " s.fk_typepayment,";
214
        $sql.= " s.num_payment,";
215
        $sql.= " s.label,";
216
        $sql.= " s.datesp,";
217
        $sql.= " s.dateep,";
218
        $sql.= " s.note,";
219
        $sql.= " s.fk_bank,";
220
        $sql.= " s.fk_user_author,";
221
        $sql.= " s.fk_user_modif,";
222
        $sql.= " b.fk_account,";
223
        $sql.= " b.fk_type,";
224
        $sql.= " b.rappro";
225
226
        $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
227
        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
228
        $sql.= " WHERE s.rowid = ".$id;
229
230
        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
231
        $resql=$this->db->query($sql);
232
        if ($resql)
233
        {
234
            if ($this->db->num_rows($resql))
235
            {
236
                $obj = $this->db->fetch_object($resql);
237
238
                $this->id				= $obj->rowid;
239
                $this->ref				= $obj->rowid;
240
                $this->tms				= $this->db->jdate($obj->tms);
241
                $this->fk_user			= $obj->fk_user;
242
                $this->datep			= $this->db->jdate($obj->datep);
243
                $this->datev			= $this->db->jdate($obj->datev);
244
                $this->amount			= $obj->amount;
245
                $this->fk_project		= $obj->fk_project;
246
                $this->type_payement	= $obj->fk_typepayment;
247
                $this->num_payment		= $obj->num_payment;
248
                $this->label			= $obj->label;
249
                $this->datesp			= $this->db->jdate($obj->datesp);
250
                $this->dateep			= $this->db->jdate($obj->dateep);
251
                $this->note				= $obj->note;
252
                $this->fk_bank			= $obj->fk_bank;
253
                $this->fk_user_author	= $obj->fk_user_author;
254
                $this->fk_user_modif	= $obj->fk_user_modif;
255
                $this->fk_account		= $obj->fk_account;
256
                $this->fk_type			= $obj->fk_type;
257
                $this->rappro			= $obj->rappro;
258
259
                // Retreive all extrafield
260
                // fetch optionals attributes and labels
261
                $this->fetch_optionals();
262
            }
263
            $this->db->free($resql);
264
265
            return 1;
266
        }
267
        else
268
        {
269
            $this->error="Error ".$this->db->lasterror();
270
            return -1;
271
        }
272
    }
273
274
275
    /**
276
     *  Delete object in database
277
     *
278
     *	@param	User	$user       User that delete
279
     *	@return	int					<0 if KO, >0 if OK
280
     */
281
    public function delete($user)
282
    {
283
        global $conf, $langs;
284
285
        $error=0;
286
287
        // Call trigger
288
        $result=$this->call_trigger('PAYMENT_SALARY_DELETE', $user);
289
        if ($result < 0) return -1;
290
        // End call triggers
291
292
        // Delete donation
293
        if (! $error)
294
        {
295
            $sql = "DELETE FROM " . MAIN_DB_PREFIX . "payment_salary_extrafields";
296
            $sql.= " WHERE fk_object=" . $this->id;
297
298
            $resql = $this->db->query($sql);
299
            if (! $resql)
300
            {
301
                $this->errors[] = $this->db->lasterror();
302
                $error++;
303
            }
304
        }
305
306
        $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary";
307
        $sql.= " WHERE rowid=".$this->id;
308
309
        dol_syslog(get_class($this)."::delete", LOG_DEBUG);
310
        $resql = $this->db->query($sql);
311
        if (! $resql)
312
        {
313
            $this->error="Error ".$this->db->lasterror();
314
            return -1;
315
        }
316
317
        return 1;
318
    }
319
320
321
    /**
322
     *  Initialise an instance with random values.
323
     *  Used to build previews or test instances.
324
     *	id must be 0 if object instance is a specimen.
325
     *
326
     *  @return	void
327
     */
328
    public function initAsSpecimen()
329
    {
330
        $this->id=0;
331
332
        $this->tms='';
333
        $this->fk_user='';
334
        $this->datep='';
335
        $this->datev='';
336
        $this->amount='';
337
        $this->label='';
338
        $this->datesp='';
339
        $this->dateep='';
340
        $this->note='';
341
        $this->fk_bank='';
342
        $this->fk_user_author='';
343
        $this->fk_user_modif='';
344
    }
345
346
    /**
347
     *  Create in database
348
     *
349
     *  @param      User	$user       User that create
350
     *  @return     int      			<0 if KO, >0 if OK
351
     */
352
    public function create($user)
353
    {
354
        global $conf,$langs;
355
356
        $error=0;
357
        $now=dol_now();
358
359
        // Clean parameters
360
        $this->amount=price2num(trim($this->amount));
361
        $this->label=trim($this->label);
362
        $this->note=trim($this->note);
363
        $this->fk_bank=trim($this->fk_bank);
0 ignored issues
show
Documentation Bug introduced by
The property $fk_bank was declared of type integer, but trim($this->fk_bank) 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...
364
        $this->fk_user_author=trim($this->fk_user_author);
0 ignored issues
show
Documentation Bug introduced by
The property $fk_user_author was declared of type integer, but trim($this->fk_user_author) 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...
365
        $this->fk_user_modif=trim($this->fk_user_modif);
0 ignored issues
show
Documentation Bug introduced by
The property $fk_user_modif was declared of type integer, but trim($this->fk_user_modif) 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...
366
367
        // Check parameters
368
        if (! $this->label)
369
        {
370
            $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
371
            return -3;
372
        }
373
        if ($this->fk_user < 0 || $this->fk_user == '')
374
        {
375
            $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
376
            return -4;
377
        }
378
        if ($this->amount < 0 || $this->amount == '')
379
        {
380
            $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
381
            return -5;
382
        }
383
        if (! empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
384
        {
385
            $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
386
            return -6;
387
        }
388
        if (! empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
389
        {
390
            $this->error=$langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
391
            return -7;
392
        }
393
394
        $this->db->begin();
395
396
        // Insert into llx_payment_salary
397
        $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (fk_user";
398
        $sql.= ", datep";
399
        $sql.= ", datev";
400
        $sql.= ", amount";
401
        $sql.= ", fk_projet";
402
        $sql.= ", salary";
403
        $sql.= ", fk_typepayment";
404
        $sql.= ", num_payment";
405
        if ($this->note) $sql.= ", note";
406
        $sql.= ", label";
407
        $sql.= ", datesp";
408
        $sql.= ", dateep";
409
        $sql.= ", fk_user_author";
410
        $sql.= ", datec";
411
        $sql.= ", fk_bank";
412
        $sql.= ", entity";
413
        $sql.= ") ";
414
        $sql.= " VALUES (";
415
        $sql.= "'".$this->db->escape($this->fk_user)."'";
416
        $sql.= ", '".$this->db->idate($this->datep)."'";
417
        $sql.= ", '".$this->db->idate($this->datev)."'";
418
        $sql.= ", ".$this->amount;
419
        $sql.= ", ".($this->fk_project > 0? $this->fk_project : 0);
420
        $sql.= ", ".($this->salary > 0 ? $this->salary : "null");
421
        $sql.= ", ".$this->db->escape($this->type_payment);
422
        $sql.= ", '".$this->db->escape($this->num_payment)."'";
423
        if ($this->note) $sql.= ", '".$this->db->escape($this->note)."'";
424
        $sql.= ", '".$this->db->escape($this->label)."'";
425
        $sql.= ", '".$this->db->idate($this->datesp)."'";
426
        $sql.= ", '".$this->db->idate($this->dateep)."'";
427
        $sql.= ", '".$this->db->escape($user->id)."'";
428
        $sql.= ", '".$this->db->idate($now)."'";
429
        $sql.= ", NULL";
430
        $sql.= ", ".$conf->entity;
431
        $sql.= ")";
432
433
        dol_syslog(get_class($this)."::create", LOG_DEBUG);
434
        $result = $this->db->query($sql);
435
        if ($result)
436
        {
437
438
            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary");
439
440
            if ($this->id > 0)
441
            {
442
                if (! empty($conf->banque->enabled) && ! empty($this->amount))
443
                {
444
                    // Insert into llx_bank
445
                    require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
446
447
                    $acc = new Account($this->db);
448
                    $result=$acc->fetch($this->accountid);
449
                    if ($result <= 0) dol_print_error($this->db);
450
451
                    // Update extrafield
452
                    if (! $error) {
453
                        if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
454
                        {
455
                            $result=$this->insertExtraFields();
456
                            if ($result < 0)
457
                            {
458
                                $error++;
459
                            }
460
                        }
461
                    }
462
463
                    // Insert payment into llx_bank
464
                    // Add link 'payment_salary' in bank_url between payment and bank transaction
465
                    $bank_line_id = $acc->addline(
466
                        $this->datep,
467
                        $this->type_payment,
468
                        $this->label,
469
                        -abs($this->amount),
470
                        $this->num_payment,
471
                        '',
472
                        $user,
473
                        '',
474
                        '',
475
                        '',
476
                        $this->datev
477
                    );
478
479
                    // Update fk_bank into llx_paiement.
480
                    // So we know the payment which has generate the banking ecriture
481
                    if ($bank_line_id > 0)
482
                    {
483
                        $this->update_fk_bank($bank_line_id);
484
                    }
485
                    else
486
                    {
487
                        $this->error=$acc->error;
488
                        $error++;
489
                    }
490
491
                    if (! $error)
492
                    {
493
                        // Add link 'payment_salary' in bank_url between payment and bank transaction
494
                        $url=DOL_URL_ROOT.'/salaries/card.php?id=';
495
496
                        $result=$acc->add_url_line($bank_line_id, $this->id, $url, "(SalaryPayment)", "payment_salary");
497
                        if ($result <= 0)
498
                        {
499
                            $this->error=$acc->error;
500
                            $error++;
501
                        }
502
                    }
503
504
                    $fuser=new User($this->db);
505
                    $fuser->fetch($this->fk_user);
506
507
                    // Add link 'user' in bank_url between operation and bank transaction
508
                    $result=$acc->add_url_line(
509
                        $bank_line_id,
510
                        $this->fk_user,
511
                        DOL_URL_ROOT.'/user/card.php?id=',
512
                        $fuser->getFullName($langs),
513
                        // $langs->trans("SalaryPayment").' '.$fuser->getFullName($langs).' '.dol_print_date($this->datesp,'dayrfc').' '.dol_print_date($this->dateep,'dayrfc'),
514
                        'user'
515
                    );
516
517
                    if ($result <= 0)
518
                    {
519
                        $this->error=$acc->error;
520
                        $error++;
521
                    }
522
                }
523
524
                // Call trigger
525
                $result=$this->call_trigger('PAYMENT_SALARY_CREATE', $user);
526
                if ($result < 0) $error++;
527
                // End call triggers
528
            }
529
            else $error++;
530
531
            if (! $error)
532
            {
533
                $this->db->commit();
534
                return $this->id;
535
            }
536
            else
537
            {
538
                $this->db->rollback();
539
                return -2;
540
            }
541
        }
542
        else
543
        {
544
            $this->error=$this->db->error();
545
            $this->db->rollback();
546
            return -1;
547
        }
548
    }
549
550
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
551
    /**
552
     *  Update link between payment salary and line generate into llx_bank
553
     *
554
     *  @param	int		$id_bank    Id bank account
555
     *	@return	int					<0 if KO, >0 if OK
556
     */
557
    public function update_fk_bank($id_bank)
558
    {
559
        // phpcs:enable
560
        $sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_salary SET fk_bank = '.$id_bank;
561
        $sql.= ' WHERE rowid = '.$this->id;
562
        $result = $this->db->query($sql);
563
        if ($result)
564
        {
565
            return 1;
566
        }
567
        else
568
        {
569
            dol_print_error($this->db);
570
            return -1;
571
        }
572
    }
573
574
575
    /**
576
     *	Send name clicable (with possibly the picto)
577
     *
578
     *	@param	int		$withpicto					0=No picto, 1=Include picto into link, 2=Only picto
579
     *	@param	string	$option						link option
580
     *  @param	int  	$notooltip					1=Disable tooltip
581
     *  @param  string  $morecss            		Add more css on link
582
     *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
583
     *	@return	string								Chaine with URL
584
     */
585
    public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
586
    {
587
        global $db, $conf, $langs, $hookmanager;
588
        global $dolibarr_main_authentication, $dolibarr_main_demo;
589
        global $menumanager;
590
591
        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
592
593
        $result = '';
594
595
        $label = '<u>' . $langs->trans("ShowSalaryPayment") . '</u>';
596
        $label.= '<br>';
597
        $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
598
599
        $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id;
600
601
        if ($option != 'nolink')
602
        {
603
            // Add param to save lastsearch_values or not
604
            $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
605
            if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
606
            if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
607
        }
608
609
        $linkclose='';
610
        if (empty($notooltip))
611
        {
612
            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
613
            {
614
                $label=$langs->trans("ShowMyObject");
615
                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
616
            }
617
            $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
618
            $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
619
620
            /*
621
             $hookmanager->initHooks(array('myobjectdao'));
622
             $parameters=array('id'=>$this->id);
623
             $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
624
             if ($reshook > 0) $linkclose = $hookmanager->resPrint;
625
             */
626
        }
627
        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
628
629
        $linkstart = '<a href="'.$url.'"';
630
        $linkstart.=$linkclose.'>';
631
        $linkend='</a>';
632
633
        $result .= $linkstart;
634
        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);
635
        if ($withpicto != 2) $result.= $this->ref;
636
        $result .= $linkend;
637
        //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
638
639
        global $action,$hookmanager;
640
        $hookmanager->initHooks(array('salarypayment'));
641
        $parameters=array('id'=>$this->id, 'getnomurl'=>$result);
642
        $reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
643
        if ($reshook > 0) $result = $hookmanager->resPrint;
644
        else $result .= $hookmanager->resPrint;
645
646
        return $result;
647
    }
648
649
    /**
650
     * Information on record
651
     *
652
     * @param	int		$id      Id of record
653
     * @return	void
654
     */
655
    public function info($id)
656
    {
657
        $sql = 'SELECT ps.rowid, ps.datec, ps.fk_user_author';
658
        $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps';
659
        $sql.= ' WHERE ps.rowid = '.$id;
660
661
        dol_syslog(get_class($this).'::info', LOG_DEBUG);
662
        $result = $this->db->query($sql);
663
664
        if ($result)
665
        {
666
            if ($this->db->num_rows($result))
667
            {
668
                $obj = $this->db->fetch_object($result);
669
                $this->id = $obj->rowid;
670
                if ($obj->fk_user_author)
671
                {
672
                    $cuser = new User($this->db);
673
                    $cuser->fetch($obj->fk_user_author);
674
                    $this->user_creation = $cuser;
675
                }
676
                $this->date_creation     = $this->db->jdate($obj->datec);
677
            }
678
            $this->db->free($result);
679
        }
680
        else
681
        {
682
            dol_print_error($this->db);
683
        }
684
    }
685
686
687
    /**
688
     * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
689
     *
690
     * @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
691
     * @return  string				Libelle
692
     */
693
    public function getLibStatut($mode = 0)
694
    {
695
        return $this->LibStatut($this->statut, $mode);
696
    }
697
698
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
699
    /**
700
     * Renvoi le libelle d'un statut donne
701
     *
702
     * @param   int		$status     Statut
703
     * @param   int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
704
     * @return	string  		    Libelle du statut
705
     */
706
    public function LibStatut($status, $mode = 0)
707
    {
708
        // phpcs:enable
709
        global $langs;	// TODO Renvoyer le libelle anglais et faire traduction a affichage
710
711
        $langs->load('compta');
712
        /*if ($mode == 0)
713
        {
714
            if ($status == 0) return $langs->trans('ToValidate');
715
            if ($status == 1) return $langs->trans('Validated');
716
        }
717
        if ($mode == 1)
718
        {
719
            if ($status == 0) return $langs->trans('ToValidate');
720
            if ($status == 1) return $langs->trans('Validated');
721
        }
722
        if ($mode == 2)
723
        {
724
            if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
725
            if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
726
        }
727
        if ($mode == 3)
728
        {
729
            if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
730
            if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
731
        }
732
        if ($mode == 4)
733
        {
734
            if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
735
            if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
736
        }
737
        if ($mode == 5)
738
        {
739
            if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
740
            if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
741
        }
742
        if ($mode == 6)
743
        {
744
            if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
745
            if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
746
        }*/
747
        return '';
748
    }
749
}
750