companypaymentmode.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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'=>'Stripe card ref', 'enabled'=>1, 'visible'=>-2, 'position'=>170),
  106. 'stripe_account' =>array('type'=>'varchar(128)', 'label'=>'Stripe account', 'enabled'=>1, 'visible'=>-2, 'position'=>171),
  107. 'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175),
  108. 'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180),
  109. 'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185),
  110. 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20),
  111. 'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25),
  112. 'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105),
  113. //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185),
  114. );
  115. /**
  116. * @var int ID
  117. */
  118. public $rowid;
  119. /**
  120. * @var int Thirdparty ID
  121. */
  122. public $fk_soc;
  123. /**
  124. * @var string company payment mode label
  125. */
  126. public $label;
  127. public $bank;
  128. public $code_banque;
  129. public $code_guichet;
  130. public $number;
  131. public $cle_rib;
  132. public $bic;
  133. public $iban_prefix;
  134. public $domiciliation;
  135. public $proprio;
  136. public $owner_address;
  137. public $default_rib;
  138. public $rum;
  139. public $date_rum;
  140. public $frstrecur;
  141. public $type;
  142. public $last_four;
  143. public $card_type;
  144. public $cvn;
  145. public $exp_date_month;
  146. public $exp_date_year;
  147. public $country_code;
  148. public $approved;
  149. public $email;
  150. public $max_total_amount_of_all_payments;
  151. public $preapproval_key;
  152. public $total_amount_of_all_payments;
  153. public $stripe_card_ref;
  154. public $stripe_account;
  155. /**
  156. * @var int Status
  157. */
  158. public $status;
  159. public $starting_date;
  160. public $ending_date;
  161. /**
  162. * Date creation record (datec)
  163. *
  164. * @var integer
  165. */
  166. public $datec;
  167. /**
  168. * Date modification record (tms)
  169. *
  170. * @var integer
  171. */
  172. public $tms;
  173. public $import_key;
  174. // END MODULEBUILDER PROPERTIES
  175. // If this object has a subtable with lines
  176. /**
  177. * @var string Name of subtable line
  178. */
  179. //public $table_element_line = 'companypaymentmodedet';
  180. /**
  181. * @var string Field with ID of parent key if this field has a parent
  182. */
  183. //public $fk_element = 'fk_companypaymentmode';
  184. /**
  185. * @var string Name of subtable class that manage subtable lines
  186. */
  187. //public $class_element_line = 'CompanyPaymentModeline';
  188. /**
  189. * @var array List of child tables. To test if we can delete object.
  190. */
  191. //protected $childtables=array();
  192. /**
  193. * @var CompanyPaymentModeLine[] Array of subtable lines
  194. */
  195. //public $lines = array();
  196. /**
  197. * Constructor
  198. *
  199. * @param DoliDb $db Database handler
  200. */
  201. public function __construct(DoliDB $db)
  202. {
  203. global $conf;
  204. $this->db = $db;
  205. if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
  206. $this->fields['rowid']['visible'] = 0;
  207. }
  208. if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
  209. $this->fields['entity']['enabled'] = 0;
  210. }
  211. }
  212. /**
  213. * Create object into database
  214. *
  215. * @param User $user User that creates
  216. * @param bool $notrigger false=launch triggers after, true=disable triggers
  217. * @return int <0 if KO, Id of created object if OK
  218. */
  219. public function create(User $user, $notrigger = false)
  220. {
  221. $idpayment = $this->createCommon($user, $notrigger);
  222. return $idpayment;
  223. }
  224. /**
  225. * Clone and object into another one
  226. *
  227. * @param User $user User that creates
  228. * @param int $fromid Id of object to clone
  229. * @return mixed New object created, <0 if KO
  230. */
  231. public function createFromClone(User $user, $fromid)
  232. {
  233. global $hookmanager, $langs;
  234. $error = 0;
  235. dol_syslog(__METHOD__, LOG_DEBUG);
  236. $object = new self($this->db);
  237. $this->db->begin();
  238. // Load source object
  239. $object->fetchCommon($fromid);
  240. // Reset some properties
  241. unset($object->id);
  242. unset($object->fk_user_creat);
  243. unset($object->import_key);
  244. // Clear fields
  245. $object->ref = "copy_of_".$object->ref;
  246. $object->title = $langs->trans("CopyOf")." ".$object->title;
  247. // ...
  248. // Create clone
  249. $object->context['createfromclone'] = 'createfromclone';
  250. $result = $object->createCommon($user);
  251. if ($result < 0) {
  252. $error++;
  253. $this->error = $object->error;
  254. $this->errors = $object->errors;
  255. }
  256. unset($object->context['createfromclone']);
  257. // End
  258. if (!$error) {
  259. $this->db->commit();
  260. return $object;
  261. } else {
  262. $this->db->rollback();
  263. return -1;
  264. }
  265. }
  266. /**
  267. * Load object in memory from the database
  268. *
  269. * @param int $id Id object
  270. * @param string $ref Ref
  271. * @param int $socid Id of company to get first default payment mode
  272. * @param string $type Filter on type ('ban', 'card', ...)
  273. * @param string $morewhere More SQL filters (' AND ...')
  274. * @return int <0 if KO, 0 if not found, >0 if OK
  275. */
  276. public function fetch($id, $ref = null, $socid = 0, $type = '', $morewhere = '')
  277. {
  278. if ($socid) {
  279. $morewhere .= " AND fk_soc = ".((int) $socid)." AND default_rib = 1";
  280. }
  281. if ($type) {
  282. $morewhere .= " AND type = '".$this->db->escape($type)."'";
  283. }
  284. $result = $this->fetchCommon($id, $ref, $morewhere);
  285. // For backward compatibility
  286. $this->iban = $this->iban_prefix;
  287. //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
  288. return $result;
  289. }
  290. /**
  291. * Load object lines in memory from the database
  292. *
  293. * @return int <0 if KO, 0 if not found, >0 if OK
  294. */
  295. /*public function fetchLines()
  296. {
  297. $this->lines=array();
  298. // Load lines with object CompanyPaymentModeLine
  299. return count($this->lines)?1:0;
  300. }*/
  301. /**
  302. * Update object into database
  303. *
  304. * @param User $user User that modifies
  305. * @param bool $notrigger false=launch triggers after, true=disable triggers
  306. * @return int <0 if KO, >0 if OK
  307. */
  308. public function update(User $user, $notrigger = false)
  309. {
  310. return $this->updateCommon($user, $notrigger);
  311. }
  312. /**
  313. * Delete object in database
  314. *
  315. * @param User $user User that deletes
  316. * @param bool $notrigger false=launch triggers after, true=disable triggers
  317. * @return int <0 if KO, >0 if OK
  318. */
  319. public function delete(User $user, $notrigger = false)
  320. {
  321. return $this->deleteCommon($user, $notrigger);
  322. }
  323. /**
  324. * Return a link to the object card (with optionaly the picto)
  325. *
  326. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  327. * @param string $option On what the link point to ('nolink', ...)
  328. * @param int $notooltip 1=Disable tooltip
  329. * @param string $morecss Add more css on link
  330. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  331. * @return string String with URL
  332. */
  333. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  334. {
  335. global $db, $conf, $langs;
  336. global $dolibarr_main_authentication, $dolibarr_main_demo;
  337. global $menumanager;
  338. if (!empty($conf->dol_no_mouse_hover)) {
  339. $notooltip = 1; // Force disable tooltips
  340. }
  341. $result = '';
  342. $companylink = '';
  343. $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>';
  344. $label .= '<br>';
  345. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  346. $url = '';
  347. if ($option != 'nolink') {
  348. // Add param to save lastsearch_values or not
  349. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  350. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  351. $add_save_lastsearch_values = 1;
  352. }
  353. if ($add_save_lastsearch_values) {
  354. $url .= '&save_lastsearch_values=1';
  355. }
  356. }
  357. $linkclose = '';
  358. if (empty($notooltip)) {
  359. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  360. $label = $langs->trans("ShowCompanyPaymentMode");
  361. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  362. }
  363. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  364. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  365. } else {
  366. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  367. }
  368. $linkstart = '<a href="'.$url.'"';
  369. $linkstart .= $linkclose.'>';
  370. $linkend = '</a>';
  371. $result .= $linkstart;
  372. if ($withpicto) {
  373. $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);
  374. }
  375. if ($withpicto != 2) {
  376. $result .= $this->ref;
  377. }
  378. $result .= $linkend;
  379. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  380. return $result;
  381. }
  382. /**
  383. * Set a Payment mode as Default
  384. *
  385. * @param int $id Payment mode ID
  386. * @param string $alltypes 1=The default is for all payment types instead of per type
  387. * @return int 0 if KO, 1 if OK
  388. */
  389. public function setAsDefault($id = 0, $alltypes = 0)
  390. {
  391. $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
  392. $sql1 .= " WHERE rowid = ".($id ? $id : $this->id);
  393. dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
  394. $result1 = $this->db->query($sql1);
  395. if ($result1) {
  396. if ($this->db->num_rows($result1) == 0) {
  397. return 0;
  398. } else {
  399. $obj = $this->db->fetch_object($result1);
  400. $type = '';
  401. if (empty($alltypes)) {
  402. $type = $obj->type;
  403. }
  404. $this->db->begin();
  405. $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0, tms = tms";
  406. $sql2 .= " WHERE default_rib <> 0 AND fk_soc = ".((int) $obj->fk_soc);
  407. if ($type) {
  408. $sql2 .= " AND type = '".$this->db->escape($type)."'";
  409. }
  410. dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
  411. $result2 = $this->db->query($sql2);
  412. $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
  413. $sql3 .= " WHERE rowid = ".((int) $obj->id);
  414. if ($type) {
  415. $sql3 .= " AND type = '".$this->db->escape($type)."'";
  416. }
  417. dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
  418. $result3 = $this->db->query($sql3);
  419. if (!$result2 || !$result3) {
  420. dol_print_error($this->db);
  421. $this->db->rollback();
  422. return -1;
  423. } else {
  424. $this->db->commit();
  425. return 1;
  426. }
  427. }
  428. } else {
  429. dol_print_error($this->db);
  430. return -1;
  431. }
  432. }
  433. /**
  434. * Return label of the status
  435. *
  436. * @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
  437. * @return string Label of status
  438. */
  439. public function getLibStatut($mode = 0)
  440. {
  441. return $this->LibStatut($this->status, $mode);
  442. }
  443. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  444. /**
  445. * Return the status
  446. *
  447. * @param int $status Id status
  448. * @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
  449. * @return string Label of status
  450. */
  451. public function LibStatut($status, $mode = 0)
  452. {
  453. // phpcs:enable
  454. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  455. global $langs;
  456. //$langs->load("mymodule");
  457. $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
  458. $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
  459. $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
  460. $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled');
  461. }
  462. $statusType = 'status5';
  463. if ($status == self::STATUS_ENABLED) {
  464. $statusType = 'status4';
  465. }
  466. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  467. }
  468. /**
  469. * Load the info information in the object
  470. *
  471. * @param int $id Id of object
  472. * @return void
  473. */
  474. public function info($id)
  475. {
  476. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  477. $sql .= ' fk_user_creat, fk_user_modif';
  478. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  479. $sql .= ' WHERE t.rowid = '.((int) $id);
  480. $result = $this->db->query($sql);
  481. if ($result) {
  482. if ($this->db->num_rows($result)) {
  483. $obj = $this->db->fetch_object($result);
  484. $this->id = $obj->rowid;
  485. $this->user_creation_id = $obj->fk_user_creat;
  486. $this->user_modification_id = $obj->fk_user_modif;
  487. $this->date_creation = $this->db->jdate($obj->datec);
  488. $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
  489. }
  490. $this->db->free($result);
  491. } else {
  492. dol_print_error($this->db);
  493. }
  494. }
  495. /**
  496. * Initialise object with example values
  497. * Id must be 0 if object instance is a specimen
  498. *
  499. * @return void
  500. */
  501. public function initAsSpecimen()
  502. {
  503. $this->initAsSpecimenCommon();
  504. }
  505. }