accountingaccount.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2020 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 <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/accountancy/class/accountingaccount.class.php
  24. * \ingroup Accountancy (Double entries)
  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. * Date creation record (datec)
  68. *
  69. * @var integer
  70. */
  71. public $datec;
  72. /**
  73. * @var string pcg version
  74. */
  75. public $fk_pcg_version;
  76. /**
  77. * @var string pcg type
  78. */
  79. public $pcg_type;
  80. /**
  81. * @var string account number
  82. */
  83. public $account_number;
  84. /**
  85. * @var int ID parent account
  86. */
  87. public $account_parent;
  88. /**
  89. * @var int ID category account
  90. */
  91. public $account_category;
  92. /**
  93. * @var int Status
  94. */
  95. public $status;
  96. /**
  97. * @var string Label of account
  98. */
  99. public $label;
  100. /**
  101. * @var string Label short of account
  102. */
  103. public $labelshort;
  104. /**
  105. * @var int ID
  106. */
  107. public $fk_user_author;
  108. /**
  109. * @var int ID
  110. */
  111. public $fk_user_modif;
  112. /**
  113. * @var int active (duplicate with status)
  114. */
  115. public $active;
  116. /**
  117. * @var int reconcilable
  118. */
  119. public $reconcilable;
  120. /**
  121. * Constructor
  122. *
  123. * @param DoliDB $db Database handle
  124. */
  125. public function __construct($db)
  126. {
  127. global $conf;
  128. $this->db = $db;
  129. $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
  130. }
  131. /**
  132. * Load record in memory
  133. *
  134. * @param int $rowid Id
  135. * @param string $account_number Account number
  136. * @param int|boolean $limittocurrentchart 1 or true=Load record only if it is into current active char of account
  137. * @param string $limittoachartaccount 'ABC'=Load record only if it is into chart account with code 'ABC' (better and faster than previous parameter if you have chart of account code).
  138. * @return int <0 if KO, 0 if not found, Id of record if OK and found
  139. */
  140. public function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0, $limittoachartaccount = '')
  141. {
  142. global $conf;
  143. if ($rowid || $account_number) {
  144. $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active, a.reconcilable";
  145. $sql .= ", ca.label as category_label";
  146. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as a";
  147. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid";
  148. $sql .= " WHERE";
  149. if ($rowid) {
  150. $sql .= " a.rowid = ".(int) $rowid;
  151. } elseif ($account_number) {
  152. $sql .= " a.account_number = '".$this->db->escape($account_number)."'";
  153. $sql .= " AND a.entity = ".$conf->entity;
  154. }
  155. if (!empty($limittocurrentchart)) {
  156. $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid='.$this->db->escape($conf->global->CHARTOFACCOUNTS).')';
  157. }
  158. if (!empty($limittoachartaccount)) {
  159. $sql .= " AND a.fk_pcg_version = '".$this->db->escape($limittoachartaccount)."'";
  160. }
  161. dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
  162. $result = $this->db->query($sql);
  163. if ($result) {
  164. $obj = $this->db->fetch_object($result);
  165. if ($obj) {
  166. $this->id = $obj->rowid;
  167. $this->rowid = $obj->rowid;
  168. $this->ref = $obj->account_number;
  169. $this->datec = $obj->datec;
  170. $this->tms = $obj->tms;
  171. $this->fk_pcg_version = $obj->fk_pcg_version;
  172. $this->pcg_type = $obj->pcg_type;
  173. $this->account_number = $obj->account_number;
  174. $this->account_parent = $obj->account_parent;
  175. $this->label = $obj->label;
  176. $this->labelshort = $obj->labelshort;
  177. $this->account_category = $obj->fk_accounting_category;
  178. $this->account_category_label = $obj->category_label;
  179. $this->fk_user_author = $obj->fk_user_author;
  180. $this->fk_user_modif = $obj->fk_user_modif;
  181. $this->active = $obj->active;
  182. $this->status = $obj->active;
  183. $this->reconcilable = $obj->reconcilable;
  184. return $this->id;
  185. } else {
  186. return 0;
  187. }
  188. } else {
  189. $this->error = "Error ".$this->db->lasterror();
  190. $this->errors[] = "Error ".$this->db->lasterror();
  191. }
  192. }
  193. return -1;
  194. }
  195. /**
  196. * Insert new accounting account in chart of accounts
  197. *
  198. * @param User $user User making action
  199. * @param int $notrigger Disable triggers
  200. * @return int <0 if KO, >0 if OK
  201. */
  202. public function create($user, $notrigger = 0)
  203. {
  204. global $conf;
  205. $error = 0;
  206. $now = dol_now();
  207. // Clean parameters
  208. if (isset($this->fk_pcg_version))
  209. $this->fk_pcg_version = trim($this->fk_pcg_version);
  210. if (isset($this->pcg_type))
  211. $this->pcg_type = trim($this->pcg_type);
  212. if (isset($this->account_number))
  213. $this->account_number = trim($this->account_number);
  214. if (isset($this->label))
  215. $this->label = trim($this->label);
  216. if (isset($this->labelshort))
  217. $this->labelshort = trim($this->labelshort);
  218. if (empty($this->pcg_type) || $this->pcg_type == '-1')
  219. {
  220. $this->pcg_type = '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 .= ", account_number";
  231. $sql .= ", account_parent";
  232. $sql .= ", label";
  233. $sql .= ", labelshort";
  234. $sql .= ", fk_accounting_category";
  235. $sql .= ", fk_user_author";
  236. $sql .= ", active";
  237. $sql .= ", reconcilable";
  238. $sql .= ") VALUES (";
  239. $sql .= " '".$this->db->idate($now)."'";
  240. $sql .= ", ".$conf->entity;
  241. $sql .= ", ".(empty($this->fk_pcg_version) ? 'NULL' : "'".$this->db->escape($this->fk_pcg_version)."'");
  242. $sql .= ", ".(empty($this->pcg_type) ? 'NULL' : "'".$this->db->escape($this->pcg_type)."'");
  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->labelshort) ? "''" : "'".$this->db->escape($this->labelshort)."'");
  247. $sql .= ", ".(empty($this->account_category) ? 0 : (int) $this->account_category);
  248. $sql .= ", ".$user->id;
  249. $sql .= ", ".(int) $this->active;
  250. $sql .= ", ".(int) $this->reconcilable;
  251. $sql .= ")";
  252. $this->db->begin();
  253. dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
  254. $resql = $this->db->query($sql);
  255. if (!$resql) {
  256. $error++;
  257. $this->errors[] = "Error ".$this->db->lasterror();
  258. }
  259. if (!$error) {
  260. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_account");
  261. // Uncomment this and change MYOBJECT to your own tag if you
  262. // want this action to call a trigger.
  263. //if (! $error && ! $notrigger) {
  264. // // Call triggers
  265. // $result=$this->call_trigger('MYOBJECT_CREATE',$user);
  266. // if ($result < 0) $error++;
  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. public 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. $this->db->begin();
  297. $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account ";
  298. $sql .= " SET fk_pcg_version = ".($this->fk_pcg_version ? "'".$this->db->escape($this->fk_pcg_version)."'" : "null");
  299. $sql .= " , pcg_type = ".($this->pcg_type ? "'".$this->db->escape($this->pcg_type)."'" : "null");
  300. $sql .= " , account_number = '".$this->db->escape($this->account_number)."'";
  301. $sql .= " , account_parent = ".(int) $this->account_parent;
  302. $sql .= " , label = ".($this->label ? "'".$this->db->escape($this->label)."'" : "''");
  303. $sql .= " , labelshort = ".($this->labelshort ? "'".$this->db->escape($this->labelshort)."'" : "''");
  304. $sql .= " , fk_accounting_category = ".(empty($this->account_category) ? 0 : (int) $this->account_category);
  305. $sql .= " , fk_user_modif = ".$user->id;
  306. $sql .= " , active = ".(int) $this->active;
  307. $sql .= " , reconcilable = ".(int) $this->reconcilable;
  308. $sql .= " WHERE rowid = ".$this->id;
  309. dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
  310. $result = $this->db->query($sql);
  311. if ($result) {
  312. $this->db->commit();
  313. return 1;
  314. } else {
  315. $this->error = $this->db->lasterror();
  316. $this->db->rollback();
  317. return -1;
  318. }
  319. }
  320. /**
  321. * Check usage of accounting code
  322. *
  323. * @return int <0 if KO, >0 if OK
  324. */
  325. public function checkUsage()
  326. {
  327. global $langs;
  328. $sql = "(SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX."facturedet";
  329. $sql .= " WHERE fk_code_ventilation=".$this->id.")";
  330. $sql .= "UNION";
  331. $sql .= " (SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX."facture_fourn_det";
  332. $sql .= " WHERE fk_code_ventilation=".$this->id.")";
  333. dol_syslog(get_class($this)."::checkUsage sql=".$sql, LOG_DEBUG);
  334. $resql = $this->db->query($sql);
  335. if ($resql) {
  336. $num = $this->db->num_rows($resql);
  337. if ($num > 0) {
  338. $this->error = $langs->trans('ErrorAccountancyCodeIsAlreadyUse');
  339. return 0;
  340. } else {
  341. return 1;
  342. }
  343. } else {
  344. $this->error = $this->db->lasterror();
  345. return -1;
  346. }
  347. }
  348. /**
  349. * Delete object in database
  350. *
  351. * @param User $user User that deletes
  352. * @param int $notrigger 0=triggers after, 1=disable triggers
  353. * @return int <0 if KO, >0 if OK
  354. */
  355. public function delete($user, $notrigger = 0)
  356. {
  357. $error = 0;
  358. $result = $this->checkUsage();
  359. if ($result > 0) {
  360. $this->db->begin();
  361. if (!$error) {
  362. $sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_account";
  363. $sql .= " WHERE rowid=".$this->id;
  364. dol_syslog(get_class($this)."::delete sql=".$sql);
  365. $resql = $this->db->query($sql);
  366. if (!$resql) {
  367. $error++;
  368. $this->errors[] = "Error ".$this->db->lasterror();
  369. }
  370. }
  371. // Commit or rollback
  372. if ($error) {
  373. foreach ($this->errors as $errmsg) {
  374. dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
  375. $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
  376. }
  377. $this->db->rollback();
  378. return -1 * $error;
  379. } else {
  380. $this->db->commit();
  381. return 1;
  382. }
  383. } else {
  384. return -1;
  385. }
  386. }
  387. /**
  388. * Return clicable name (with picto eventually)
  389. *
  390. * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
  391. * @param int $withlabel 0=No label, 1=Include label of account
  392. * @param int $nourl 1=Disable url
  393. * @param string $moretitle Add more text to title tooltip
  394. * @param int $notooltip 1=Disable tooltip
  395. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  396. * @param int $withcompletelabel 0=Short label (field short label), 1=Complete label (field label)
  397. * @return string String with URL
  398. */
  399. public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1, $withcompletelabel = 0)
  400. {
  401. global $langs, $conf, $user;
  402. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  403. if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
  404. $result = '';
  405. $url = DOL_URL_ROOT.'/accountancy/admin/card.php?id='.$this->id;
  406. // Add param to save lastsearch_values or not
  407. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  408. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
  409. if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
  410. $picto = 'billr';
  411. $label = '';
  412. if (empty($this->labelshort) || $withcompletelabel == 1)
  413. {
  414. $labeltoshow = $this->label;
  415. } else {
  416. $labeltoshow = $this->labelshort;
  417. }
  418. $label = '<u>'.$langs->trans("ShowAccountingAccount").'</u>';
  419. if (!empty($this->account_number))
  420. $label .= '<br><b>'.$langs->trans('AccountAccounting').':</b> '.length_accountg($this->account_number);
  421. if (!empty($labeltoshow))
  422. $label .= '<br><b>'.$langs->trans('Label').':</b> '.$labeltoshow;
  423. if ($moretitle) $label .= ' - '.$moretitle;
  424. $linkclose = '';
  425. if (empty($notooltip))
  426. {
  427. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
  428. {
  429. $label = $langs->trans("ShowAccoutingAccount");
  430. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  431. }
  432. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  433. $linkclose .= ' class="classfortooltip"';
  434. }
  435. $linkstart = '<a href="'.$url.'"';
  436. $linkstart .= $linkclose.'>';
  437. $linkend = '</a>';
  438. if ($nourl)
  439. {
  440. $linkstart = '';
  441. $linkclose = '';
  442. $linkend = '';
  443. }
  444. $label_link = length_accountg($this->account_number);
  445. if ($withlabel) $label_link .= ' - '.($nourl ? '<span class="opacitymedium">' : '').$labeltoshow.($nourl ? '</span>' : '');
  446. if ($withpicto) $result .= ($linkstart.img_object(($notooltip ? '' : $label), $picto, ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
  447. if ($withpicto && $withpicto != 2) $result .= ' ';
  448. if ($withpicto != 2) $result .= $linkstart.$label_link.$linkend;
  449. return $result;
  450. }
  451. /**
  452. * Information on record
  453. *
  454. * @param int $id of record
  455. * @return void
  456. */
  457. public function info($id)
  458. {
  459. $sql = 'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms';
  460. $sql .= ' FROM '.MAIN_DB_PREFIX.'accounting_account as a';
  461. $sql .= ' WHERE a.rowid = '.$id;
  462. dol_syslog(get_class($this).'::info sql='.$sql);
  463. $result = $this->db->query($sql);
  464. if ($result) {
  465. if ($this->db->num_rows($result)) {
  466. $obj = $this->db->fetch_object($result);
  467. $this->id = $obj->rowid;
  468. if ($obj->fk_user_author) {
  469. $cuser = new User($this->db);
  470. $cuser->fetch($obj->fk_user_author);
  471. $this->user_creation = $cuser;
  472. }
  473. if ($obj->fk_user_modif) {
  474. $muser = new User($this->db);
  475. $muser->fetch($obj->fk_user_modif);
  476. $this->user_modification = $muser;
  477. }
  478. $this->date_creation = $this->db->jdate($obj->datec);
  479. $this->date_modification = $this->db->jdate($obj->tms);
  480. }
  481. $this->db->free($result);
  482. } else {
  483. dol_print_error($this->db);
  484. }
  485. }
  486. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  487. /**
  488. * Account deactivated
  489. *
  490. * @param int $id Id
  491. * @param int $mode 0=field active, 1=field active_customer_list, 2=field_active_supplier_list
  492. * @return int <0 if KO, >0 if OK
  493. */
  494. public function account_desactivate($id, $mode = 0)
  495. {
  496. // phpcs:enable
  497. $result = $this->checkUsage();
  498. if ($mode == 0)
  499. {
  500. $fieldtouse = 'active';
  501. }
  502. elseif ($mode == 1)
  503. {
  504. $fieldtouse = 'reconcilable';
  505. }
  506. if ($result > 0) {
  507. $this->db->begin();
  508. $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account ";
  509. $sql .= "SET ".$fieldtouse." = '0'";
  510. $sql .= " WHERE rowid = ".$this->db->escape($id);
  511. dol_syslog(get_class($this)."::account_desactivate ".$fieldtouse." sql=".$sql, LOG_DEBUG);
  512. $result = $this->db->query($sql);
  513. if ($result) {
  514. $this->db->commit();
  515. return 1;
  516. } else {
  517. $this->error = $this->db->lasterror();
  518. $this->db->rollback();
  519. return -1;
  520. }
  521. } else {
  522. return -1;
  523. }
  524. }
  525. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  526. /**
  527. * Account activated
  528. *
  529. * @param int $id Id
  530. * @param int $mode 0=field active, 1=field reconcilable
  531. * @return int <0 if KO, >0 if OK
  532. */
  533. public function account_activate($id, $mode = 0)
  534. {
  535. // phpcs:enable
  536. $this->db->begin();
  537. if ($mode == 0)
  538. {
  539. $fieldtouse = 'active';
  540. }
  541. elseif ($mode == 1)
  542. {
  543. $fieldtouse = 'reconcilable';
  544. }
  545. $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account ";
  546. $sql .= "SET ".$fieldtouse." = '1'";
  547. $sql .= " WHERE rowid = ".$this->db->escape($id);
  548. dol_syslog(get_class($this)."::account_activate ".$fieldtouse." sql=".$sql, LOG_DEBUG);
  549. $result = $this->db->query($sql);
  550. if ($result) {
  551. $this->db->commit();
  552. return 1;
  553. } else {
  554. $this->error = $this->db->lasterror();
  555. $this->db->rollback();
  556. return -1;
  557. }
  558. }
  559. /**
  560. * Retourne le libelle du statut d'un user (actif, inactif)
  561. *
  562. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  563. * @return string Label of status
  564. */
  565. public function getLibStatut($mode = 0)
  566. {
  567. return $this->LibStatut($this->status, $mode);
  568. }
  569. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  570. /**
  571. * Renvoi le libelle d'un statut donne
  572. *
  573. * @param int $status Id status
  574. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  575. * @return string Label of status
  576. */
  577. public function LibStatut($status, $mode = 0)
  578. {
  579. // phpcs:enable
  580. global $langs;
  581. $langs->loadLangs(array("users"));
  582. if ($mode == 0)
  583. {
  584. if ($status == 1) return $langs->trans('Enabled');
  585. elseif ($status == 0) return $langs->trans('Disabled');
  586. }
  587. elseif ($mode == 1)
  588. {
  589. if ($status == 1) return $langs->trans('Enabled');
  590. elseif ($status == 0) return $langs->trans('Disabled');
  591. }
  592. elseif ($mode == 2)
  593. {
  594. if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
  595. elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
  596. }
  597. elseif ($mode == 3)
  598. {
  599. if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4');
  600. elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5');
  601. }
  602. elseif ($mode == 4)
  603. {
  604. if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
  605. elseif ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
  606. }
  607. elseif ($mode == 5)
  608. {
  609. if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
  610. elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
  611. }
  612. }
  613. }