accountingaccount.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  7. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  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. * \file htdocs/accountancy/class/accountingaccount.class.php
  24. * \ingroup Advanced accountancy
  25. * \brief File of class to manage accounting accounts
  26. */
  27. /**
  28. * Class to manage accounting accounts
  29. */
  30. class AccountingAccount extends CommonObject
  31. {
  32. /**
  33. * @var string Name of element
  34. */
  35. public $element='accounting_account';
  36. /**
  37. * @var string Name of table without prefix where object is stored
  38. */
  39. public $table_element='accounting_account';
  40. /**
  41. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  42. */
  43. public $picto = 'billr';
  44. /**
  45. * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
  46. * @var int
  47. */
  48. public $ismultientitymanaged = 1;
  49. /**
  50. * 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
  51. * @var integer
  52. */
  53. public $restrictiononfksoc = 1;
  54. /**
  55. * @var DoliDB Database handler.
  56. */
  57. public $db;
  58. /**
  59. * @var int ID
  60. */
  61. public $id;
  62. /**
  63. * @var int ID
  64. */
  65. public $rowid;
  66. /**
  67. * @var string Creation date
  68. */
  69. public $datec;
  70. /**
  71. * @var string pcg version
  72. */
  73. public $fk_pcg_version;
  74. /**
  75. * @var string pcg type
  76. */
  77. public $pcg_type;
  78. /**
  79. * @var string pcg subtype
  80. */
  81. public $pcg_subtype;
  82. /**
  83. * @var string account number
  84. */
  85. public $account_number;
  86. /**
  87. * @var int ID parent account
  88. */
  89. public $account_parent;
  90. /**
  91. * @var int ID category account
  92. */
  93. public $account_category;
  94. /**
  95. * @var int Status
  96. */
  97. public $status;
  98. /**
  99. * @var string Label of account
  100. */
  101. public $label;
  102. /**
  103. * @var int ID
  104. */
  105. public $fk_user_author;
  106. /**
  107. * @var int ID
  108. */
  109. public $fk_user_modif;
  110. /**
  111. * @var int active (duplicate with status)
  112. */
  113. public $active;
  114. /**
  115. * Constructor
  116. *
  117. * @param DoliDB $db Database handle
  118. */
  119. function __construct($db)
  120. {
  121. global $conf;
  122. $this->db = $db;
  123. $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
  124. }
  125. /**
  126. * Load record in memory
  127. *
  128. * @param int $rowid Id
  129. * @param string $account_number Account number
  130. * @param int $limittocurrentchart 1=Do not load record if it is into another accounting system
  131. * @return int <0 if KO, 0 if not found, Id of record if OK and found
  132. */
  133. function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0)
  134. {
  135. global $conf;
  136. if ($rowid || $account_number) {
  137. $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";
  138. $sql .= ", ca.label as category_label";
  139. $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a";
  140. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid";
  141. $sql .= " WHERE";
  142. if ($rowid) {
  143. $sql .= " a.rowid = " . (int) $rowid;
  144. } elseif ($account_number) {
  145. $sql .= " a.account_number = '" . $this->db->escape($account_number) . "'";
  146. }
  147. if (! empty($limittocurrentchart)) {
  148. $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $this->db->escape($conf->global->CHARTOFACCOUNTS) . ')';
  149. }
  150. dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
  151. $result = $this->db->query($sql);
  152. if ($result) {
  153. $obj = $this->db->fetch_object($result);
  154. if ($obj) {
  155. $this->id = $obj->rowid;
  156. $this->rowid = $obj->rowid;
  157. $this->ref = $obj->account_number;
  158. $this->datec = $obj->datec;
  159. $this->tms = $obj->tms;
  160. $this->fk_pcg_version = $obj->fk_pcg_version;
  161. $this->pcg_type = $obj->pcg_type;
  162. $this->pcg_subtype = $obj->pcg_subtype;
  163. $this->account_number = $obj->account_number;
  164. $this->account_parent = $obj->account_parent;
  165. $this->label = $obj->label;
  166. $this->account_category = $obj->fk_accounting_category;
  167. $this->account_category_label = $obj->category_label;
  168. $this->fk_user_author = $obj->fk_user_author;
  169. $this->fk_user_modif = $obj->fk_user_modif;
  170. $this->active = $obj->active;
  171. $this->status = $obj->active;
  172. return $this->id;
  173. } else {
  174. return 0;
  175. }
  176. } else {
  177. $this->error = "Error " . $this->db->lasterror();
  178. $this->errors[] = "Error " . $this->db->lasterror();
  179. }
  180. }
  181. return -1;
  182. }
  183. /**
  184. * Insert new accounting account in chart of accounts
  185. *
  186. * @param User $user User making action
  187. * @param int $notrigger Disable triggers
  188. * @return int <0 if KO, >0 if OK
  189. */
  190. function create($user, $notrigger = 0)
  191. {
  192. global $conf;
  193. $error = 0;
  194. $now = dol_now();
  195. // Clean parameters
  196. if (isset($this->fk_pcg_version))
  197. $this->fk_pcg_version = trim($this->fk_pcg_version);
  198. if (isset($this->pcg_type))
  199. $this->pcg_type = trim($this->pcg_type);
  200. if (isset($this->pcg_subtype))
  201. $this->pcg_subtype = trim($this->pcg_subtype);
  202. if (isset($this->account_number))
  203. $this->account_number = trim($this->account_number);
  204. if (isset($this->account_parent))
  205. $this->account_parent = trim($this->account_parent);
  206. if (isset($this->label))
  207. $this->label = trim($this->label);
  208. if (isset($this->account_category))
  209. $this->account_category = trim($this->account_category);
  210. if (isset($this->fk_user_author))
  211. $this->fk_user_author = trim($this->fk_user_author);
  212. if (isset($this->active))
  213. $this->active = trim($this->active);
  214. if (empty($this->pcg_type) || $this->pcg_type == '-1')
  215. {
  216. $this->pcg_type = 'XXXXXX';
  217. }
  218. if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1')
  219. {
  220. $this->pcg_subtype = 'XXXXXX';
  221. }
  222. // Check parameters
  223. // Put here code to add control on parameters values
  224. // Insert request
  225. $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account(";
  226. $sql .= "datec";
  227. $sql .= ", entity";
  228. $sql .= ", fk_pcg_version";
  229. $sql .= ", pcg_type";
  230. $sql .= ", pcg_subtype";
  231. $sql .= ", account_number";
  232. $sql .= ", account_parent";
  233. $sql .= ", label";
  234. $sql .= ", fk_accounting_category";
  235. $sql .= ", fk_user_author";
  236. $sql .= ", active";
  237. $sql .= ") VALUES (";
  238. $sql .= " '" . $this->db->idate($now) . "'";
  239. $sql .= ", " . $conf->entity;
  240. $sql .= ", " . (empty($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'");
  241. $sql .= ", " . (empty($this->pcg_type) ? 'NULL' : "'" . $this->db->escape($this->pcg_type) . "'");
  242. $sql .= ", " . (empty($this->pcg_subtype) ? 'NULL' : "'" . $this->db->escape($this->pcg_subtype) . "'");
  243. $sql .= ", " . (empty($this->account_number) ? 'NULL' : "'" . $this->db->escape($this->account_number) . "'");
  244. $sql .= ", " . (empty($this->account_parent) ? 0 : (int) $this->account_parent);
  245. $sql .= ", " . (empty($this->label) ? "''" : "'" . $this->db->escape($this->label) . "'");
  246. $sql .= ", " . (empty($this->account_category) ? 0 : (int) $this->account_category);
  247. $sql .= ", " . $user->id;
  248. $sql .= ", " . (int) $this->active;
  249. $sql .= ")";
  250. $this->db->begin();
  251. dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
  252. $resql = $this->db->query($sql);
  253. if (! $resql) {
  254. $error++;
  255. $this->errors[] = "Error " . $this->db->lasterror();
  256. }
  257. if (! $error) {
  258. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_account");
  259. // if (! $notrigger) {
  260. // Uncomment this and change MYOBJECT to your own tag if you
  261. // want this action calls a trigger.
  262. // // Call triggers
  263. // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  264. // $interface=new Interfaces($this->db);
  265. // $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
  266. // if ($result < 0) { $error++; $this->errors=$interface->errors; }
  267. // // End call triggers
  268. // }
  269. }
  270. // Commit or rollback
  271. if ($error) {
  272. foreach ($this->errors as $errmsg) {
  273. dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR);
  274. $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
  275. }
  276. $this->db->rollback();
  277. return -1 * $error;
  278. } else {
  279. $this->db->commit();
  280. return $this->id;
  281. }
  282. }
  283. /**
  284. * Update record
  285. *
  286. * @param User $user Use making update
  287. * @return int <0 if KO, >0 if OK
  288. */
  289. function update($user)
  290. {
  291. // Check parameters
  292. if (empty($this->pcg_type) || $this->pcg_type == '-1')
  293. {
  294. $this->pcg_type = 'XXXXXX';
  295. }
  296. if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1')
  297. {
  298. $this->pcg_subtype = 'XXXXXX';
  299. }
  300. $this->db->begin();
  301. $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
  302. $sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null");
  303. $sql .= " , pcg_type = " . ($this->pcg_type ? "'" . $this->db->escape($this->pcg_type) . "'" : "null");
  304. $sql .= " , pcg_subtype = " . ($this->pcg_subtype ? "'" . $this->db->escape($this->pcg_subtype) . "'" : "null");
  305. $sql .= " , account_number = '" . $this->db->escape($this->account_number) . "'";
  306. $sql .= " , account_parent = " . (int) $this->account_parent;
  307. $sql .= " , label = " . ($this->label ? "'" . $this->db->escape($this->label) . "'" : "''");
  308. $sql .= " , fk_accounting_category = " . (empty($this->account_category) ? 0 : (int) $this->account_category);
  309. $sql .= " , fk_user_modif = " . $user->id;
  310. $sql .= " , active = " . (int) $this->active;
  311. $sql .= " WHERE rowid = " . $this->id;
  312. dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG);
  313. $result = $this->db->query($sql);
  314. if ($result) {
  315. $this->db->commit();
  316. return 1;
  317. } else {
  318. $this->error = $this->db->lasterror();
  319. $this->db->rollback();
  320. return - 1;
  321. }
  322. }
  323. /**
  324. * Check usage of accounting code
  325. *
  326. * @return int <0 if KO, >0 if OK
  327. */
  328. function checkUsage()
  329. {
  330. global $langs;
  331. $sql = "(SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facturedet";
  332. $sql.= " WHERE fk_code_ventilation=" . $this->id . ")";
  333. $sql.= "UNION";
  334. $sql.= " (SELECT fk_code_ventilation FROM " . MAIN_DB_PREFIX . "facture_fourn_det";
  335. $sql.= " WHERE fk_code_ventilation=" . $this->id . ")";
  336. dol_syslog(get_class($this) . "::checkUsage sql=" . $sql, LOG_DEBUG);
  337. $resql = $this->db->query($sql);
  338. if ($resql) {
  339. $num = $this->db->num_rows($resql);
  340. if ($num > 0) {
  341. $this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse');
  342. return 0;
  343. } else {
  344. return 1;
  345. }
  346. } else {
  347. $this->error = $this->db->lasterror();
  348. return - 1;
  349. }
  350. }
  351. /**
  352. * Delete object in database
  353. *
  354. * @param User $user User that deletes
  355. * @param int $notrigger 0=triggers after, 1=disable triggers
  356. * @return int <0 if KO, >0 if OK
  357. */
  358. function delete($user, $notrigger = 0)
  359. {
  360. $error = 0;
  361. $result = $this->checkUsage();
  362. if ($result > 0) {
  363. $this->db->begin();
  364. // if (! $error) {
  365. // if (! $notrigger) {
  366. // Uncomment this and change MYOBJECT to your own tag if you
  367. // want this action calls a trigger.
  368. // // Call triggers
  369. // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  370. // $interface=new Interfaces($this->db);
  371. // $result=$interface->run_triggers('ACCOUNTANCY_ACCOUNT_DELETE',$this,$user,$langs,$conf);
  372. // if ($result < 0) { $error++; $this->errors=$interface->errors; }
  373. // // End call triggers
  374. // }
  375. // }
  376. if (! $error) {
  377. $sql = "DELETE FROM " . MAIN_DB_PREFIX . "accounting_account";
  378. $sql .= " WHERE rowid=" . $this->id;
  379. dol_syslog(get_class($this) . "::delete sql=" . $sql);
  380. $resql = $this->db->query($sql);
  381. if (! $resql) {
  382. $error ++;
  383. $this->errors[] = "Error " . $this->db->lasterror();
  384. }
  385. }
  386. // Commit or rollback
  387. if ($error) {
  388. foreach ( $this->errors as $errmsg ) {
  389. dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
  390. $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
  391. }
  392. $this->db->rollback();
  393. return - 1 * $error;
  394. } else {
  395. $this->db->commit();
  396. return 1;
  397. }
  398. } else {
  399. return - 1;
  400. }
  401. }
  402. /**
  403. * Return clicable name (with picto eventually)
  404. *
  405. * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
  406. * @param int $withlabel 0=No label, 1=Include label of account
  407. * @param int $nourl 1=Disable url
  408. * @param string $moretitle Add more text to title tooltip
  409. * @param int $notooltip 1=Disable tooltip
  410. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  411. * @return string String with URL
  412. */
  413. function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1)
  414. {
  415. global $langs, $conf, $user;
  416. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  417. if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
  418. $result = '';
  419. $url = DOL_URL_ROOT . '/accountancy/admin/card.php?id=' . $this->id;
  420. // Add param to save lastsearch_values or not
  421. $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
  422. if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
  423. if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
  424. $picto = 'billr';
  425. $label='';
  426. $label = '<u>' . $langs->trans("ShowAccountingAccount") . '</u>';
  427. if (! empty($this->account_number))
  428. $label .= '<br><b>'.$langs->trans('AccountAccounting') . ':</b> ' . length_accountg($this->account_number);
  429. if (! empty($this->label))
  430. $label .= '<br><b>'.$langs->trans('Label') . ':</b> ' . $this->label;
  431. if ($moretitle) $label.=' - '.$moretitle;
  432. $linkclose='';
  433. if (empty($notooltip))
  434. {
  435. if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  436. {
  437. $label=$langs->trans("ShowAccoutingAccount");
  438. $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
  439. }
  440. $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
  441. $linkclose.=' class="classfortooltip"';
  442. }
  443. $linkstart='<a href="'.$url.'"';
  444. $linkstart.=$linkclose.'>';
  445. $linkend='</a>';
  446. if ($nourl)
  447. {
  448. $linkstart = '';
  449. $linkclose = '';
  450. $linkend = '';
  451. }
  452. $label_link = length_accountg($this->account_number);
  453. if ($withlabel) $label_link .= ' - ' . $this->label;
  454. if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
  455. if ($withpicto && $withpicto != 2) $result .= ' ';
  456. if ($withpicto != 2) $result.=$linkstart . $label_link . $linkend;
  457. return $result;
  458. }
  459. /**
  460. * Information on record
  461. *
  462. * @param int $id of record
  463. * @return void
  464. */
  465. function info($id)
  466. {
  467. $sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms';
  468. $sql .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as a';
  469. $sql .= ' WHERE a.rowid = ' . $id;
  470. dol_syslog(get_class($this) . '::info sql=' . $sql);
  471. $result = $this->db->query($sql);
  472. if ($result) {
  473. if ($this->db->num_rows($result)) {
  474. $obj = $this->db->fetch_object($result);
  475. $this->id = $obj->rowid;
  476. if ($obj->fk_user_author) {
  477. $cuser = new User($this->db);
  478. $cuser->fetch($obj->fk_user_author);
  479. $this->user_creation = $cuser;
  480. }
  481. if ($obj->fk_user_modif) {
  482. $muser = new User($this->db);
  483. $muser->fetch($obj->fk_user_modif);
  484. $this->user_modification = $muser;
  485. }
  486. $this->date_creation = $this->db->jdate($obj->datec);
  487. $this->date_modification = $this->db->jdate($obj->tms);
  488. }
  489. $this->db->free($result);
  490. } else {
  491. dol_print_error($this->db);
  492. }
  493. }
  494. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  495. /**
  496. * Account deactivated
  497. *
  498. * @param int $id Id
  499. * @return int <0 if KO, >0 if OK
  500. */
  501. function account_desactivate($id)
  502. {
  503. // phpcs:enable
  504. $result = $this->checkUsage();
  505. if ($result > 0) {
  506. $this->db->begin();
  507. $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
  508. $sql .= "SET active = '0'";
  509. $sql .= " WHERE rowid = " . $this->db->escape($id);
  510. dol_syslog(get_class($this) . "::desactivate sql=" . $sql, LOG_DEBUG);
  511. $result = $this->db->query($sql);
  512. if ($result) {
  513. $this->db->commit();
  514. return 1;
  515. } else {
  516. $this->error = $this->db->lasterror();
  517. $this->db->rollback();
  518. return - 1;
  519. }
  520. } else {
  521. return - 1;
  522. }
  523. }
  524. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  525. /**
  526. * Account activated
  527. *
  528. * @param int $id Id
  529. * @return int <0 if KO, >0 if OK
  530. */
  531. function account_activate($id)
  532. {
  533. // phpcs:enable
  534. $this->db->begin();
  535. $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account ";
  536. $sql .= "SET active = '1'";
  537. $sql .= " WHERE rowid = " . $this->db->escape($id);
  538. dol_syslog(get_class($this) . "::activate sql=" . $sql, LOG_DEBUG);
  539. $result = $this->db->query($sql);
  540. if ($result) {
  541. $this->db->commit();
  542. return 1;
  543. } else {
  544. $this->error = $this->db->lasterror();
  545. $this->db->rollback();
  546. return - 1;
  547. }
  548. }
  549. /**
  550. * Retourne le libelle du statut d'un user (actif, inactif)
  551. *
  552. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  553. * @return string Label of status
  554. */
  555. function getLibStatut($mode = 0)
  556. {
  557. return $this->LibStatut($this->status,$mode);
  558. }
  559. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  560. /**
  561. * Renvoi le libelle d'un statut donne
  562. *
  563. * @param int $statut Id statut
  564. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  565. * @return string Label of status
  566. */
  567. function LibStatut($statut, $mode = 0)
  568. {
  569. // phpcs:enable
  570. global $langs;
  571. $langs->loadLangs(array("users"));
  572. if ($mode == 0)
  573. {
  574. $prefix='';
  575. if ($statut == 1) return $langs->trans('Enabled');
  576. if ($statut == 0) return $langs->trans('Disabled');
  577. }
  578. elseif ($mode == 1)
  579. {
  580. if ($statut == 1) return $langs->trans('Enabled');
  581. if ($statut == 0) return $langs->trans('Disabled');
  582. }
  583. elseif ($mode == 2)
  584. {
  585. if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
  586. if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
  587. }
  588. elseif ($mode == 3)
  589. {
  590. if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4');
  591. if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5');
  592. }
  593. elseif ($mode == 4)
  594. {
  595. if ($statut == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
  596. if ($statut == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
  597. }
  598. elseif ($mode == 5)
  599. {
  600. if ($statut == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
  601. if ($statut == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
  602. }
  603. }
  604. }