Passed
Branch develop (a7390e)
by
unknown
25:38
created

AccountingAccount::getLibStatut()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
/* Copyright (C) 2013-2014  Olivier Geffroy      <[email protected]>
3
 * Copyright (C) 2013-2016  Alexandre Spangaro   <[email protected]>
4
 * Copyright (C) 2013-2014  Florian Henry        <[email protected]>
5
 * Copyright (C) 2014       Juanjo Menent        <[email protected]>
6
 * Copyright (C) 2015       Ari Elbaz (elarifr)  <[email protected]>
7
 * Copyright (C) 2018       Frédéric France         <[email protected]>
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
/**
24
 *  \file       htdocs/accountancy/class/accountingaccount.class.php
25
 *  \ingroup    Accountancy (Double entries)
26
 *  \brief      File of class to manage accounting accounts
27
 */
28
29
/**
30
 * Class to manage accounting accounts
31
 */
32
class AccountingAccount extends CommonObject
33
{
34
	/**
35
	 * @var string Name of element
36
	 */
37
	public $element='accounting_account';
38
39
	/**
40
	 * @var string Name of table without prefix where object is stored
41
	 */
42
	public $table_element='accounting_account';
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 = 'billr';
48
49
	/**
50
	 * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
51
	 * @var int
52
	 */
53
	public $ismultientitymanaged = 1;
54
55
	/**
56
	 * 0=Default, 1=View may be restricted to sales representative only if no permission to see all or to company of external user if external user
57
	 * @var integer
58
	 */
59
	public $restrictiononfksoc = 1;
60
61
	/**
62
	 * @var DoliDB Database handler.
63
	 */
64
	public $db;
65
66
	/**
67
	 * @var int ID
68
	 */
69
	public $id;
70
71
	/**
72
	 * @var int ID
73
	 */
74
	public $rowid;
75
76
	/**
77
     * Date creation record (datec)
78
     *
79
     * @var integer
80
     */
81
    public $datec;
82
83
	/**
84
     * @var string pcg version
85
     */
86
	public $fk_pcg_version;
87
88
    /**
89
     * @var string pcg type
90
     */
91
	public $pcg_type;
92
93
    /**
94
     * @var string pcg subtype
95
     */
96
	public $pcg_subtype;
97
98
    /**
99
     * @var string account number
100
     */
101
	public $account_number;
102
103
    /**
104
     * @var int ID parent account
105
     */
106
	public $account_parent;
107
108
    /**
109
     * @var int ID category account
110
     */
111
	public $account_category;
112
113
	/**
114
	 * @var int Status
115
	 */
116
	public $status;
117
118
    /**
119
     * @var string Label of account
120
     */
121
    public $label;
122
123
    /**
124
     * @var int ID
125
     */
126
    public $fk_user_author;
127
128
    /**
129
     * @var int ID
130
     */
131
    public $fk_user_modif;
132
133
	/**
134
	 * @var int active (duplicate with status)
135
	 */
136
    public $active;
137
138
	/**
139
	 * Constructor
140
	 *
141
	 * @param DoliDB $db Database handle
142
	 */
143
    public function __construct($db)
144
    {
145
		global $conf;
146
147
		$this->db = $db;
148
		$this->next_prev_filter='fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')';		// Used to add a filter in Form::showrefnav method
149
    }
150
151
	/**
152
	 * Load record in memory
153
	 *
154
	 * @param 	int 	       $rowid 				    Id
155
	 * @param 	string 	       $account_number 	        Account number
156
	 * @param 	int|boolean    $limittocurrentchart     1 or true=Load record only if it is into current active char of account
157
	 * @param   string         $limittoachartaccount    'ABC'=Load record only if it is into chart account with code 'ABC'.
158
	 * @return 	int                                     <0 if KO, 0 if not found, Id of record if OK and found
159
	 */
160
    public function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0, $limittoachartaccount = '')
161
	{
162
		global $conf;
163
164
		if ($rowid || $account_number) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $rowid of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
165
			$sql  = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active";
166
			$sql .= ", ca.label as category_label";
167
			$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a";
168
			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid";
169
			$sql .= " WHERE";
170
			if ($rowid) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $rowid of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
171
				$sql .= " a.rowid = " . (int) $rowid;
172
			} elseif ($account_number) {
173
				$sql .= " a.account_number = '" . $this->db->escape($account_number) . "'";
174
			}
175
			if (! empty($limittocurrentchart)) {
176
				$sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $this->db->escape($conf->global->CHARTOFACCOUNTS) . ')';
177
			}
178
			if (! empty($limittoachartaccount)) {
179
			    $sql .= " AND a.fk_pcg_version = '".$this->db->escape($limittoachartaccount)."'";
180
			}
181
182
			dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
183
			$result = $this->db->query($sql);
184
			if ($result) {
185
				$obj = $this->db->fetch_object($result);
186
187
				if ($obj) {
188
					$this->id = $obj->rowid;
189
					$this->rowid = $obj->rowid;
190
					$this->ref = $obj->account_number;
191
					$this->datec = $obj->datec;
192
					$this->tms = $obj->tms;
193
					$this->fk_pcg_version = $obj->fk_pcg_version;
194
					$this->pcg_type = $obj->pcg_type;
195
					$this->pcg_subtype = $obj->pcg_subtype;
196
					$this->account_number = $obj->account_number;
197
					$this->account_parent = $obj->account_parent;
198
					$this->label = $obj->label;
199
					$this->account_category = $obj->fk_accounting_category;
200
					$this->account_category_label = $obj->category_label;
201
					$this->fk_user_author = $obj->fk_user_author;
202
					$this->fk_user_modif = $obj->fk_user_modif;
203
					$this->active = $obj->active;
204
					$this->status = $obj->active;
205
206
					return $this->id;
207
				} else {
208
					return 0;
209
				}
210
			} else {
211
				$this->error = "Error " . $this->db->lasterror();
212
				$this->errors[] = "Error " . $this->db->lasterror();
213
			}
214
		}
215
		return -1;
216
	}
217
218
	/**
219
	 * Insert new accounting account in chart of accounts
220
	 *
221
	 * @param  User    $user       User making action
222
	 * @param  int     $notrigger  Disable triggers
223
	 * @return int                 <0 if KO, >0 if OK
224
	 */
225
    public function create($user, $notrigger = 0)
226
    {
227
		global $conf;
228
		$error = 0;
229
		$now = dol_now();
230
231
		// Clean parameters
232
		if (isset($this->fk_pcg_version))
233
			$this->fk_pcg_version = trim($this->fk_pcg_version);
234
		if (isset($this->pcg_type))
235
			$this->pcg_type = trim($this->pcg_type);
236
		if (isset($this->pcg_subtype))
237
			$this->pcg_subtype = trim($this->pcg_subtype);
238
		if (isset($this->account_number))
239
			$this->account_number = trim($this->account_number);
240
		if (isset($this->label))
241
			$this->label = trim($this->label);
242
243
		if (empty($this->pcg_type) || $this->pcg_type == '-1')
244
		{
245
			$this->pcg_type = 'XXXXXX';
246
		}
247
		if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1')
248
		{
249
			$this->pcg_subtype = 'XXXXXX';
250
		}
251
		// Check parameters
252
		// Put here code to add control on parameters values
253
254
		// Insert request
255
		$sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account(";
256
		$sql .= "datec";
257
		$sql .= ", entity";
258
		$sql .= ", fk_pcg_version";
259
		$sql .= ", pcg_type";
260
		$sql .= ", pcg_subtype";
261
		$sql .= ", account_number";
262
		$sql .= ", account_parent";
263
		$sql .= ", label";
264
		$sql .= ", fk_accounting_category";
265
		$sql .= ", fk_user_author";
266
		$sql .= ", active";
267
		$sql .= ") VALUES (";
268
		$sql .= " '" . $this->db->idate($now) . "'";
269
		$sql .= ", " . $conf->entity;
270
		$sql .= ", " . (empty($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'");
271
		$sql .= ", " . (empty($this->pcg_type) ? 'NULL' : "'" . $this->db->escape($this->pcg_type) . "'");
272
		$sql .= ", " . (empty($this->pcg_subtype) ? 'NULL' : "'" . $this->db->escape($this->pcg_subtype) . "'");
273
		$sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->db->escape($this->account_number) . "'");
274
		$sql .= ", " . (empty($this->account_parent) ? 0 : (int) $this->account_parent);
275
		$sql .= ", " . (empty($this->label) ? "''" : "'" . $this->db->escape($this->label) . "'");
276
		$sql .= ", " . (empty($this->account_category) ? 0 : (int) $this->account_category);
277
		$sql .= ", " . $user->id;
278
		$sql .= ", " . (int) $this->active;
279
		$sql .= ")";
280
281
		$this->db->begin();
282
283
		dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
284
		$resql = $this->db->query($sql);
285
		if (! $resql) {
286
			$error++;
287
			$this->errors[] = "Error " . $this->db->lasterror();
288
		}
289
290
		if (! $error) {
291
			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_account");
292
293
			// if (! $notrigger) {
294
			// Uncomment this and change MYOBJECT to your own tag if you
295
			// want this action calls a trigger.
296
297
			// // Call triggers
298
			// include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
299
			// $interface=new Interfaces($this->db);
300
			// $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
301
			// if ($result < 0) { $error++; $this->errors=$interface->errors; }
302
			// // End call triggers
303
			// }
304
		}
305
306
		// Commit or rollback
307
		if ($error) {
308
			foreach ($this->errors as $errmsg) {
309
				dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR);
310
				$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
311
			}
312
			$this->db->rollback();
313
			return -1 * $error;
314
		} else {
315
			$this->db->commit();
316
			return $this->id;
317
		}
318
    }
319
320
	/**
321
	 * Update record
322
	 *
323
	 * @param  User $user      Use making update
324
	 * @return int             <0 if KO, >0 if OK
325
	 */
326
	public function update($user)
327
	{
328
		// Check parameters
329
		if (empty($this->pcg_type) || $this->pcg_type == '-1')
330
		{
331
			$this->pcg_type = 'XXXXXX';
332
		}
333
		if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1')
334
		{
335
			$this->pcg_subtype = 'XXXXXX';
336
		}
337
338
		$this->db->begin();
339
340
		$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
341
		$sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null");
342
		$sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null");
343
		$sql .= " , pcg_subtype = " . ($this->pcg_subtype ? "'" . $this->db->escape($this->pcg_subtype) . "'" : "null");
344
		$sql .= " , account_number = '" . $this->db->escape($this->account_number) . "'";
345
		$sql .= " , account_parent = " . (int) $this->account_parent;
346
		$sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "''");
347
		$sql .= " , fk_accounting_category = " . (empty($this->account_category) ? 0 : (int) $this->account_category);
348
		$sql .= " , fk_user_modif = " . $user->id;
349
		$sql .= " , active = " . (int) $this->active;
350
		$sql .= " WHERE rowid = " . $this->id;
351
352
		dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
353
		$result = $this->db->query($sql);
354
		if ($result) {
355
			$this->db->commit();
356
			return 1;
357
		} else {
358
			$this->error = $this->db->lasterror();
359
			$this->db->rollback();
360
			return - 1;
361
		}
362
	}
363
364
	/**
365
	 * Check usage of accounting code
366
	 *
367
	 * @return int <0 if KO, >0 if OK
368
	 */
369
    public function checkUsage()
370
    {
371
		global $langs;
372
373
		$sql = "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facturedet";
374
		$sql.= " WHERE fk_code_ventilation=" . $this->id . ")";
375
		$sql.= "UNION";
376
		$sql.= " (SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facture_fourn_det";
377
		$sql.= " WHERE fk_code_ventilation=" . $this->id . ")";
378
379
		dol_syslog(get_class($this) . "::checkUsage sql=" . $sql, LOG_DEBUG);
380
		$resql = $this->db->query($sql);
381
382
		if ($resql) {
383
			$num = $this->db->num_rows($resql);
384
			if ($num > 0) {
385
				$this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse');
386
				return 0;
387
			} else {
388
				return 1;
389
			}
390
		} else {
391
			$this->error = $this->db->lasterror();
392
			return - 1;
393
		}
394
	}
395
396
	/**
397
	 * Delete object in database
398
	 *
399
	 * @param User $user User that deletes
400
	 * @param int $notrigger 0=triggers after, 1=disable triggers
401
	 * @return int <0 if KO, >0 if OK
402
	 */
403
    public function delete($user, $notrigger = 0)
404
    {
405
		$error = 0;
406
407
		$result = $this->checkUsage();
408
409
		if ($result > 0) {
410
411
			$this->db->begin();
412
413
			// if (! $error) {
414
			// if (! $notrigger) {
415
			// Uncomment this and change MYOBJECT to your own tag if you
416
			// want this action calls a trigger.
417
418
			// // Call triggers
419
			// include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
420
			// $interface=new Interfaces($this->db);
421
			// $result=$interface->run_triggers('ACCOUNTANCY_ACCOUNT_DELETE',$this,$user,$langs,$conf);
422
			// if ($result < 0) { $error++; $this->errors=$interface->errors; }
423
			// // End call triggers
424
			// }
425
			// }
426
427
			if (! $error) {
428
				$sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_account";
429
				$sql .= " WHERE rowid=" . $this->id;
430
431
				dol_syslog(get_class($this) . "::delete sql=" . $sql);
432
				$resql = $this->db->query($sql);
433
				if (! $resql) {
434
					$error ++;
435
					$this->errors[] = "Error " . $this->db->lasterror();
436
				}
437
			}
438
439
			// Commit or rollback
440
			if ($error) {
441
				foreach ($this->errors as $errmsg) {
442
					dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
443
					$this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
444
				}
445
				$this->db->rollback();
446
				return - 1 * $error;
447
			} else {
448
				$this->db->commit();
449
				return 1;
450
			}
451
		} else {
452
			return - 1;
453
		}
454
    }
455
456
    /**
457
	 * Return clicable name (with picto eventually)
458
	 *
459
	 * @param	int		$withpicto					0=No picto, 1=Include picto into link, 2=Only picto
460
	 * @param	int		$withlabel					0=No label, 1=Include label of account
461
	 * @param	int  	$nourl						1=Disable url
462
	 * @param	string  $moretitle					Add more text to title tooltip
463
	 * @param	int  	$notooltip					1=Disable tooltip
464
     * @param	int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
465
	 * @return  string	String with URL
466
	 */
467
    public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1)
468
    {
469
		global $langs, $conf, $user;
470
		require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
471
472
		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
473
474
		$result = '';
475
476
		$url = DOL_URL_ROOT . '/accountancy/admin/card.php?id=' . $this->id;
477
478
		// Add param to save lastsearch_values or not
479
		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
480
		if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
481
		if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
482
483
		$picto = 'billr';
484
		$label='';
485
486
		$label = '<u>' . $langs->trans("ShowAccountingAccount") . '</u>';
487
		if (! empty($this->account_number))
488
			$label .= '<br><b>'.$langs->trans('AccountAccounting') . ':</b> ' . length_accountg($this->account_number);
489
		if (! empty($this->label))
490
			$label .= '<br><b>'.$langs->trans('Label') . ':</b> ' . $this->label;
491
		if ($moretitle) $label.=' - '.$moretitle;
492
493
		$linkclose='';
494
		if (empty($notooltip))
495
		{
496
			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
497
			{
498
				$label=$langs->trans("ShowAccoutingAccount");
499
				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
500
			}
501
			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
502
			$linkclose.=' class="classfortooltip"';
503
		}
504
505
		$linkstart='<a href="'.$url.'"';
506
		$linkstart.=$linkclose.'>';
507
		$linkend='</a>';
508
509
		if ($nourl)
510
		{
511
			$linkstart = '';
512
			$linkclose = '';
513
			$linkend = '';
514
		}
515
516
		$label_link = length_accountg($this->account_number);
517
		if ($withlabel) $label_link .= ' - ' . $this->label;
518
519
		if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
520
		if ($withpicto && $withpicto != 2) $result .= ' ';
521
		if ($withpicto != 2) $result.=$linkstart . $label_link . $linkend;
522
		return $result;
523
    }
524
525
	/**
526
	 * Information on record
527
	 *
528
	 * @param int $id of record
529
	 * @return void
530
	 */
531
    public function info($id)
532
    {
533
		$sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms';
534
		$sql .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as a';
535
		$sql .= ' WHERE a.rowid = ' . $id;
536
537
		dol_syslog(get_class($this) . '::info sql=' . $sql);
538
		$result = $this->db->query($sql);
539
540
		if ($result) {
541
			if ($this->db->num_rows($result)) {
542
				$obj = $this->db->fetch_object($result);
543
				$this->id = $obj->rowid;
544
				if ($obj->fk_user_author) {
545
					$cuser = new User($this->db);
546
					$cuser->fetch($obj->fk_user_author);
547
					$this->user_creation = $cuser;
548
				}
549
				if ($obj->fk_user_modif) {
550
					$muser = new User($this->db);
551
					$muser->fetch($obj->fk_user_modif);
552
					$this->user_modification = $muser;
553
				}
554
				$this->date_creation = $this->db->jdate($obj->datec);
555
				$this->date_modification = $this->db->jdate($obj->tms);
556
			}
557
			$this->db->free($result);
558
		} else {
559
			dol_print_error($this->db);
560
		}
561
	}
562
563
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
564
	/**
565
	 * Account deactivated
566
	 *
567
	 * @param  int  $id         Id
568
	 * @return int              <0 if KO, >0 if OK
569
	 */
570
    public function account_desactivate($id)
571
    {
572
        // phpcs:enable
573
		$result = $this->checkUsage();
574
575
		if ($result > 0) {
576
			$this->db->begin();
577
578
			$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
579
			$sql .= "SET active = '0'";
580
			$sql .= " WHERE rowid = " . $this->db->escape($id);
581
582
			dol_syslog(get_class($this) . "::desactivate sql=" . $sql, LOG_DEBUG);
583
			$result = $this->db->query($sql);
584
585
			if ($result) {
586
				$this->db->commit();
587
				return 1;
588
			} else {
589
				$this->error = $this->db->lasterror();
590
				$this->db->rollback();
591
				return - 1;
592
			}
593
		} else {
594
			return - 1;
595
		}
596
	}
597
598
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
599
	/**
600
	 * Account activated
601
	 *
602
	 * @param  int  $id         Id
603
	 * @return int              <0 if KO, >0 if OK
604
	 */
605
    public function account_activate($id)
606
    {
607
        // phpcs:enable
608
		$this->db->begin();
609
610
		$sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
611
		$sql .= "SET active = '1'";
612
		$sql .= " WHERE rowid = " . $this->db->escape($id);
613
614
		dol_syslog(get_class($this) . "::activate sql=" . $sql, LOG_DEBUG);
615
		$result = $this->db->query($sql);
616
        if ($result) {
617
			$this->db->commit();
618
			return 1;
619
        } else {
620
			$this->error = $this->db->lasterror();
621
			$this->db->rollback();
622
			return - 1;
623
        }
624
    }
625
626
627
	/**
628
	 *  Retourne le libelle du statut d'un user (actif, inactif)
629
	 *
630
	 *  @param  int     $mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
631
	 *  @return string              Label of status
632
	 */
633
	public function getLibStatut($mode = 0)
634
	{
635
		return $this->LibStatut($this->status, $mode);
636
	}
637
638
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
639
	/**
640
	 *  Renvoi le libelle d'un statut donne
641
	 *
642
	 *  @param  int     $statut     Id statut
643
	 *  @param  int     $mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
644
	 *  @return string              Label of status
645
	 */
646
	public function LibStatut($statut, $mode = 0)
647
	{
648
        // phpcs:enable
649
		global $langs;
650
		$langs->loadLangs(array("users"));
651
652
		if ($mode == 0)
653
		{
654
			$prefix='';
655
			if ($statut == 1) return $langs->trans('Enabled');
656
			elseif ($statut == 0) return $langs->trans('Disabled');
657
		}
658
		elseif ($mode == 1)
659
		{
660
			if ($statut == 1) return $langs->trans('Enabled');
661
			elseif ($statut == 0) return $langs->trans('Disabled');
662
		}
663
		elseif ($mode == 2)
664
		{
665
			if ($statut == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
666
			elseif ($statut == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
667
		}
668
		elseif ($mode == 3)
669
		{
670
			if ($statut == 1) return img_picto($langs->trans('Enabled'), 'statut4');
671
			elseif ($statut == 0) return img_picto($langs->trans('Disabled'), 'statut5');
672
		}
673
		elseif ($mode == 4)
674
		{
675
			if ($statut == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
676
			elseif ($statut == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
677
		}
678
		elseif ($mode == 5)
679
		{
680
			if ($statut == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
681
			elseif ($statut == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
682
		}
683
	}
684
}
685