companypaymentmode.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file class/companypaymentmode.class.php
  20. * \ingroup company
  21. * \brief This file is a CRUD class file for CompanyPaymentMode (Create/Read/Update/Delete)
  22. */
  23. // Put here all includes required by your class file
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  25. //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  26. //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  27. /**
  28. * Class for CompanyPaymentMode
  29. */
  30. class CompanyPaymentMode extends CommonObject
  31. {
  32. /**
  33. * @var string ID to identify managed object
  34. */
  35. public $element = 'companypaymentmode';
  36. /**
  37. * @var string Name of table without prefix where object is stored
  38. */
  39. public $table_element = 'societe_rib';
  40. /**
  41. * @var int Does this object support multicompany module ?
  42. * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
  43. */
  44. public $ismultientitymanaged = 'fk_soc@societe';
  45. /**
  46. * @var int Does companypaymentmode support extrafields ? 0=No, 1=Yes
  47. */
  48. public $isextrafieldmanaged = 0;
  49. /**
  50. * @var string String with name of icon for companypaymentmode. Must be the part after the 'object_' into object_companypaymentmode.png
  51. */
  52. public $picto = 'generic';
  53. const STATUS_ENABLED = 1;
  54. const STATUS_CANCELED = 0;
  55. /**
  56. * 'type' if the field format.
  57. * 'label' the translation key.
  58. * 'enabled' is a condition when the field must be managed.
  59. * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
  60. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  61. * 'index' if we want an index in database.
  62. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  63. * 'position' is the sort order of field.
  64. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  65. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
  66. * 'help' is a string visible as a tooltip on field
  67. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  68. * 'default' is a default value for creation (can still be replaced by the global setup of default values)
  69. * 'showoncombobox' if field must be shown into the label of combobox
  70. */
  71. // BEGIN MODULEBUILDER PROPERTIES
  72. /**
  73. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  74. */
  75. public $fields = array(
  76. 'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10),
  77. 'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15),
  78. 'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30),
  79. 'bank' =>array('type'=>'varchar(255)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-2, 'position'=>35),
  80. 'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-2, 'position'=>40),
  81. 'code_guichet' =>array('type'=>'varchar(6)', 'label'=>'Code guichet', 'enabled'=>1, 'visible'=>-2, 'position'=>45),
  82. 'number' =>array('type'=>'varchar(255)', 'label'=>'Number', 'enabled'=>1, 'visible'=>-2, 'position'=>50),
  83. 'cle_rib' =>array('type'=>'varchar(5)', 'label'=>'Cle rib', 'enabled'=>1, 'visible'=>-2, 'position'=>55),
  84. 'bic' =>array('type'=>'varchar(20)', 'label'=>'Bic', 'enabled'=>1, 'visible'=>-2, 'position'=>60),
  85. 'iban_prefix' =>array('type'=>'varchar(34)', 'label'=>'Iban prefix', 'enabled'=>1, 'visible'=>-2, 'position'=>65),
  86. 'domiciliation' =>array('type'=>'varchar(255)', 'label'=>'Domiciliation', 'enabled'=>1, 'visible'=>-2, 'position'=>70),
  87. 'proprio' =>array('type'=>'varchar(60)', 'label'=>'Proprio', 'enabled'=>1, 'visible'=>-2, 'position'=>75),
  88. 'owner_address' =>array('type'=>'text', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-2, 'position'=>80),
  89. 'default_rib' =>array('type'=>'tinyint(4)', 'label'=>'Default rib', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>85),
  90. 'rum' =>array('type'=>'varchar(32)', 'label'=>'Rum', 'enabled'=>1, 'visible'=>-2, 'position'=>90),
  91. 'date_rum' =>array('type'=>'date', 'label'=>'Date rum', 'enabled'=>1, 'visible'=>-2, 'position'=>95),
  92. 'frstrecur' =>array('type'=>'varchar(16)', 'label'=>'Frstrecur', 'enabled'=>1, 'visible'=>-2, 'position'=>100),
  93. 'type' =>array('type'=>'varchar(32)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-2, 'position'=>110),
  94. 'last_four' =>array('type'=>'varchar(4)', 'label'=>'Last four', 'enabled'=>1, 'visible'=>-2, 'position'=>115),
  95. 'card_type' =>array('type'=>'varchar(255)', 'label'=>'Card type', 'enabled'=>1, 'visible'=>-2, 'position'=>120),
  96. 'cvn' =>array('type'=>'varchar(255)', 'label'=>'Cvn', 'enabled'=>1, 'visible'=>-2, 'position'=>125),
  97. 'exp_date_month' =>array('type'=>'integer', 'label'=>'Exp date month', 'enabled'=>1, 'visible'=>-2, 'position'=>130),
  98. 'exp_date_year' =>array('type'=>'integer', 'label'=>'Exp date year', 'enabled'=>1, 'visible'=>-2, 'position'=>135),
  99. 'country_code' =>array('type'=>'varchar(10)', 'label'=>'Country code', 'enabled'=>1, 'visible'=>-2, 'position'=>140),
  100. 'approved' =>array('type'=>'integer', 'label'=>'Approved', 'enabled'=>1, 'visible'=>-2, 'position'=>145),
  101. 'email' =>array('type'=>'varchar(255)', 'label'=>'Email', 'enabled'=>1, 'visible'=>-2, 'position'=>150),
  102. 'max_total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Max total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>155),
  103. 'preapproval_key' =>array('type'=>'varchar(255)', 'label'=>'Preapproval key', 'enabled'=>1, 'visible'=>-2, 'position'=>160),
  104. 'total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>165),
  105. 'stripe_card_ref' =>array('type'=>'varchar(128)', 'label'=>'ExternalSystemID', 'enabled'=>1, 'visible'=>-2, 'position'=>170, 'help'=>'IDOfPaymentInAnExternalSystem'),
  106. 'stripe_account' =>array('type'=>'varchar(128)', 'label'=>'ExternalSystemCustomerAccount', 'enabled'=>1, 'visible'=>-2, 'position'=>171, 'help'=>'IDOfCustomerInAnExternalSystem'),
  107. 'ext_payment_site' =>array('type'=>'varchar(128)', 'label'=>'ExternalSystem', 'enabled'=>1, 'visible'=>-2, 'position'=>172, 'help'=>'NameOfExternalSystem'),
  108. 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175),
  109. 'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180),
  110. 'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185),
  111. 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20),
  112. 'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25),
  113. 'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105),
  114. //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185),
  115. );
  116. /**
  117. * @var int ID
  118. */
  119. public $rowid;
  120. /**
  121. * @var int Thirdparty ID
  122. */
  123. public $fk_soc;
  124. /**
  125. * @var string company payment mode label
  126. */
  127. public $label;
  128. public $bank;
  129. public $code_banque;
  130. public $code_guichet;
  131. public $number;
  132. public $cle_rib;
  133. public $bic;
  134. /**
  135. * @var string iban
  136. * @deprecated
  137. * @see $iban_prefix
  138. */
  139. public $iban;
  140. /**
  141. * iban_prefix
  142. * @var string
  143. */
  144. public $iban_prefix;
  145. public $domiciliation;
  146. public $proprio;
  147. public $owner_address;
  148. public $default_rib;
  149. public $rum;
  150. public $date_rum;
  151. public $frstrecur;
  152. public $type;
  153. public $last_four;
  154. public $card_type;
  155. public $cvn;
  156. public $exp_date_month;
  157. public $exp_date_year;
  158. public $country_code;
  159. public $approved;
  160. public $email;
  161. public $max_total_amount_of_all_payments;
  162. public $preapproval_key;
  163. public $total_amount_of_all_payments;
  164. public $stripe_card_ref; // External system payment mode ID
  165. public $stripe_account; // External system customer ID
  166. public $ext_payment_site; // External system 'StripeLive', 'StripeTest', 'StancerLive', 'StancerTest', ...
  167. /**
  168. * @var int Status
  169. */
  170. public $status;
  171. public $starting_date;
  172. public $ending_date;
  173. /**
  174. * Date creation record (datec)
  175. *
  176. * @var integer
  177. */
  178. public $datec;
  179. /**
  180. * Date modification record (tms)
  181. *
  182. * @var integer
  183. */
  184. public $tms;
  185. public $import_key;
  186. // END MODULEBUILDER PROPERTIES
  187. /**
  188. * Constructor
  189. *
  190. * @param DoliDb $db Database handler
  191. */
  192. public function __construct(DoliDB $db)
  193. {
  194. global $conf;
  195. $this->db = $db;
  196. if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
  197. $this->fields['rowid']['visible'] = 0;
  198. }
  199. if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
  200. $this->fields['entity']['enabled'] = 0;
  201. }
  202. }
  203. /**
  204. * Create object into database
  205. *
  206. * @param User $user User that creates
  207. * @param bool $notrigger false=launch triggers after, true=disable triggers
  208. * @return int <0 if KO, Id of created object if OK
  209. */
  210. public function create(User $user, $notrigger = false)
  211. {
  212. $idpayment = $this->createCommon($user, $notrigger);
  213. return $idpayment;
  214. }
  215. /**
  216. * Clone and object into another one
  217. *
  218. * @param User $user User that creates
  219. * @param int $fromid Id of object to clone
  220. * @return mixed New object created, <0 if KO
  221. */
  222. public function createFromClone(User $user, $fromid)
  223. {
  224. global $hookmanager, $langs;
  225. $error = 0;
  226. dol_syslog(__METHOD__, LOG_DEBUG);
  227. $object = new self($this->db);
  228. $this->db->begin();
  229. // Load source object
  230. $object->fetchCommon($fromid);
  231. // Reset some properties
  232. unset($object->id);
  233. unset($object->fk_user_creat);
  234. unset($object->import_key);
  235. // Clear fields
  236. $object->ref = "copy_of_".$object->ref;
  237. // $object->title = $langs->trans("CopyOf")." ".$object->title;
  238. // Create clone
  239. $object->context['createfromclone'] = 'createfromclone';
  240. $result = $object->createCommon($user);
  241. if ($result < 0) {
  242. $error++;
  243. $this->error = $object->error;
  244. $this->errors = $object->errors;
  245. }
  246. unset($object->context['createfromclone']);
  247. // End
  248. if (!$error) {
  249. $this->db->commit();
  250. return $object;
  251. } else {
  252. $this->db->rollback();
  253. return -1;
  254. }
  255. }
  256. /**
  257. * Load object in memory from the database
  258. *
  259. * @param int $id Id object
  260. * @param string $ref Ref
  261. * @param int $socid Id of company to get first default payment mode
  262. * @param string $type Filter on type ('ban', 'card', ...)
  263. * @param string $morewhere More SQL filters (' AND ...')
  264. * @return int <0 if KO, 0 if not found, >0 if OK
  265. */
  266. public function fetch($id, $ref = null, $socid = 0, $type = '', $morewhere = '')
  267. {
  268. if ($socid) {
  269. $morewhere .= " AND fk_soc = ".((int) $socid)." AND default_rib = 1";
  270. }
  271. if ($type) {
  272. $morewhere .= " AND type = '".$this->db->escape($type)."'";
  273. }
  274. $result = $this->fetchCommon($id, $ref, $morewhere);
  275. // For backward compatibility
  276. $this->iban = $this->iban_prefix;
  277. //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
  278. return $result;
  279. }
  280. /**
  281. * Load object lines in memory from the database
  282. *
  283. * @return int <0 if KO, 0 if not found, >0 if OK
  284. */
  285. /*public function fetchLines()
  286. {
  287. $this->lines=array();
  288. // Load lines with object CompanyPaymentModeLine
  289. return count($this->lines)?1:0;
  290. }*/
  291. /**
  292. * Update object into database
  293. *
  294. * @param User $user User that modifies
  295. * @param bool $notrigger false=launch triggers after, true=disable triggers
  296. * @return int <0 if KO, >0 if OK
  297. */
  298. public function update(User $user, $notrigger = false)
  299. {
  300. return $this->updateCommon($user, $notrigger);
  301. }
  302. /**
  303. * Delete object in database
  304. *
  305. * @param User $user User that deletes
  306. * @param bool $notrigger false=launch triggers after, true=disable triggers
  307. * @return int <0 if KO, >0 if OK
  308. */
  309. public function delete(User $user, $notrigger = false)
  310. {
  311. return $this->deleteCommon($user, $notrigger);
  312. }
  313. /**
  314. * Return a link to the object card (with optionaly the picto)
  315. *
  316. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  317. * @param string $option On what the link point to ('nolink', ...)
  318. * @param int $notooltip 1=Disable tooltip
  319. * @param string $morecss Add more css on link
  320. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  321. * @return string String with URL
  322. */
  323. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  324. {
  325. global $db, $conf, $langs;
  326. global $dolibarr_main_authentication, $dolibarr_main_demo;
  327. global $menumanager;
  328. if (!empty($conf->dol_no_mouse_hover)) {
  329. $notooltip = 1; // Force disable tooltips
  330. }
  331. $result = '';
  332. $companylink = '';
  333. $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>';
  334. $label .= '<br>';
  335. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  336. $url = '';
  337. if ($option != 'nolink') {
  338. // Add param to save lastsearch_values or not
  339. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  340. if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  341. $add_save_lastsearch_values = 1;
  342. }
  343. if ($add_save_lastsearch_values) {
  344. $url .= '&save_lastsearch_values=1';
  345. }
  346. }
  347. $linkclose = '';
  348. if (empty($notooltip)) {
  349. if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
  350. $label = $langs->trans("ShowCompanyPaymentMode");
  351. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  352. }
  353. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  354. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  355. } else {
  356. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  357. }
  358. $linkstart = '<a href="'.$url.'"';
  359. $linkstart .= $linkclose.'>';
  360. $linkend = '</a>';
  361. $result .= $linkstart;
  362. if ($withpicto) {
  363. $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);
  364. }
  365. if ($withpicto != 2) {
  366. $result .= $this->ref;
  367. }
  368. $result .= $linkend;
  369. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  370. return $result;
  371. }
  372. /**
  373. * Set a Payment mode as Default
  374. *
  375. * @param int $id Payment mode ID
  376. * @param string $alltypes 1=The default is for all payment types instead of per type
  377. * @return int 0 if KO, 1 if OK
  378. */
  379. public function setAsDefault($id = 0, $alltypes = 0)
  380. {
  381. $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
  382. $sql1 .= " WHERE rowid = ".($id ? $id : $this->id);
  383. dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
  384. $result1 = $this->db->query($sql1);
  385. if ($result1) {
  386. if ($this->db->num_rows($result1) == 0) {
  387. return 0;
  388. } else {
  389. $obj = $this->db->fetch_object($result1);
  390. $type = '';
  391. if (empty($alltypes)) {
  392. $type = $obj->type;
  393. }
  394. $this->db->begin();
  395. $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0, tms = tms";
  396. $sql2 .= " WHERE default_rib <> 0 AND fk_soc = ".((int) $obj->fk_soc);
  397. if ($type) {
  398. $sql2 .= " AND type = '".$this->db->escape($type)."'";
  399. }
  400. dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
  401. $result2 = $this->db->query($sql2);
  402. $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
  403. $sql3 .= " WHERE rowid = ".((int) $obj->id);
  404. if ($type) {
  405. $sql3 .= " AND type = '".$this->db->escape($type)."'";
  406. }
  407. dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
  408. $result3 = $this->db->query($sql3);
  409. if (!$result2 || !$result3) {
  410. dol_print_error($this->db);
  411. $this->db->rollback();
  412. return -1;
  413. } else {
  414. $this->db->commit();
  415. return 1;
  416. }
  417. }
  418. } else {
  419. dol_print_error($this->db);
  420. return -1;
  421. }
  422. }
  423. /**
  424. * Return label of the status
  425. *
  426. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  427. * @return string Label of status
  428. */
  429. public function getLibStatut($mode = 0)
  430. {
  431. return $this->LibStatut($this->status, $mode);
  432. }
  433. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  434. /**
  435. * Return the status
  436. *
  437. * @param int $status Id status
  438. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  439. * @return string Label of status
  440. */
  441. public function LibStatut($status, $mode = 0)
  442. {
  443. // phpcs:enable
  444. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  445. global $langs;
  446. //$langs->load("mymodule");
  447. $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
  448. $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
  449. $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
  450. $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
  451. }
  452. $statusType = 'status5';
  453. if ($status == self::STATUS_ENABLED) {
  454. $statusType = 'status4';
  455. }
  456. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  457. }
  458. /**
  459. * Load the info information in the object
  460. *
  461. * @param int $id Id of object
  462. * @return void
  463. */
  464. public function info($id)
  465. {
  466. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  467. $sql .= ' fk_user_creat, fk_user_modif';
  468. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  469. $sql .= ' WHERE t.rowid = '.((int) $id);
  470. $result = $this->db->query($sql);
  471. if ($result) {
  472. if ($this->db->num_rows($result)) {
  473. $obj = $this->db->fetch_object($result);
  474. $this->id = $obj->rowid;
  475. $this->user_creation_id = $obj->fk_user_creat;
  476. $this->user_modification_id = $obj->fk_user_modif;
  477. $this->date_creation = $this->db->jdate($obj->datec);
  478. $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
  479. }
  480. $this->db->free($result);
  481. } else {
  482. dol_print_error($this->db);
  483. }
  484. }
  485. /**
  486. * Initialise object with example values
  487. * Id must be 0 if object instance is a specimen
  488. *
  489. * @return void
  490. */
  491. public function initAsSpecimen()
  492. {
  493. $this->initAsSpecimenCommon();
  494. }
  495. }