25 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 public $element =
'asset';
40 public $table_element =
'asset';
45 public $ismultientitymanaged = 0;
50 public $isextrafieldmanaged = 1;
55 public $picto =
'asset';
58 const STATUS_DRAFT = 0;
59 const STATUS_VALIDATED = 1;
82 public $fields = array(
83 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-1,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id",),
84 'ref' => array(
'type'=>
'varchar(10)',
'label'=>
'Ref',
'visible'=>1,
'enabled'=>1,
'position'=>10,
'notnull'=>1,
'index'=>1,
'searchall'=>1,
'comment'=>
"Reference of object",
'showoncombobox'=>1),
85 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
86 'label' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'visible'=>1,
'enabled'=>1,
'position'=>30,
'notnull'=>-1,
'searchall'=>1),
87 'fk_asset_type' => array(
'type'=>
'integer:AssetType:asset/class/asset_type.class.php',
'label'=>
'AssetsType',
'visible'=>1,
'enabled'=>1,
'position'=>35,
'notnull'=>1,
'index'=>1,
'searchall'=>1),
88 'amount_ht' => array(
'type'=>
'double(24,8)',
'label'=>
'AmountHTShort',
'visible'=>1,
'enabled'=>1,
'position'=>40,
'notnull'=>-1,
'isameasure'=>
'1',
'help'=>
"Help text",),
89 'amount_vat' => array(
'type'=>
'double(24,8)',
'label'=>
'AmountVAT',
'visible'=>1,
'enabled'=>1,
'position'=>41,
'notnull'=>-1,
'isameasure'=>
'1',
'help'=>
"Help text",),
90 'description' => array(
'type'=>
'text',
'label'=>
'Description',
'visible'=>-1,
'enabled'=>1,
'position'=>90,
'notnull'=>-1,),
91 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'visible'=>-1,
'enabled'=>1,
'position'=>91,
'notnull'=>-1,),
92 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'visible'=>-1,
'enabled'=>1,
'position'=>92,
'notnull'=>-1,),
93 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'visible'=>-2,
'enabled'=>1,
'position'=>500,
'notnull'=>1,),
94 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'visible'=>-2,
'enabled'=>1,
'position'=>501,
'notnull'=>1,),
95 'fk_user_creat' => array(
'type'=>
'integer',
'label'=>
'UserAuthor',
'visible'=>-2,
'enabled'=>1,
'position'=>510,
'notnull'=>1,),
96 'fk_user_modif' => array(
'type'=>
'integer',
'label'=>
'UserModif',
'visible'=>-2,
'enabled'=>1,
'position'=>511,
'notnull'=>-1,),
97 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'visible'=>-2,
'enabled'=>1,
'position'=>1000,
'notnull'=>-1,),
98 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'visible'=>1,
'enabled'=>1,
'position'=>1000,
'notnull'=>1,
'index'=>1,
'arrayofkeyval'=>array(
'0'=>
'Draft',
'1'=>
'Active',
'-1'=>
'Cancel')),
136 public $date_creation;
144 public $fk_user_creat;
149 public $fk_user_modif;
173 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->
fields[
'rowid'][
'visible'] = 0;
174 if (empty($conf->multicompany->enabled)) $this->
fields[
'entity'][
'enabled'] = 0;
198 global $hookmanager, $langs;
203 $object =
new self($this->db);
208 $object->fetchCommon($fromid);
211 unset($object->fk_user_creat);
212 unset($object->import_key);
215 $object->ref =
"copy_of_".$object->ref;
216 $object->title = $langs->trans(
"CopyOf").
" ".$object->title;
219 $object->context[
'createfromclone'] =
'createfromclone';
220 $result = $object->createCommon($user);
223 $this->error = $object->error;
224 $this->errors = $object->errors;
227 unset($object->context[
'createfromclone']);
234 $this->
db->rollback();
246 public function fetch($id, $ref = null)
286 public function delete(
User $user, $notrigger =
false)
301 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
303 global $db, $conf, $langs;
304 global $dolibarr_main_authentication, $dolibarr_main_demo;
307 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
312 $label =
'<u>'.$langs->trans(
"Asset").
'</u>';
314 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
318 if ($option !=
'nolink')
321 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
322 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
323 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
327 if (empty($notooltip))
329 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
331 $label = $langs->trans(
"ShowAssets");
332 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
334 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
335 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
336 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
338 $linkstart =
'<a href="'.$url.
'"';
339 $linkstart .= $linkclose.
'>';
342 $result .= $linkstart;
343 if ($withpicto) $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);
344 if ($withpicto != 2) $result .= $this->ref;
359 return $this->
LibStatut($this->status, $mode);
375 $langs->load(
"contracts");
376 $labelStatus = array();
377 $labelStatus[self::STATUS_DRAFT] = $langs->trans(
'Disabled');
378 $labelStatus[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
379 $labelStatusShort = array();
380 $labelStatusShort[self::STATUS_DRAFT] = $langs->trans(
'Disabled');
381 $labelStatusShort[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
383 $statusType =
'status0';
384 if ($status == self::STATUS_VALIDATED) $statusType =
'status4';
386 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode);
397 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
398 $sql .=
' fk_user_creat, fk_user_modif';
399 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
400 $sql .=
' WHERE t.rowid = '.$id;
401 $result = $this->
db->query($sql);
404 if ($this->
db->num_rows($result))
406 $obj = $this->
db->fetch_object($result);
407 $this->
id = $obj->rowid;
408 if ($obj->fk_user_author)
410 $cuser =
new User($this->
db);
411 $cuser->fetch($obj->fk_user_author);
412 $this->user_creation = $cuser;
415 if ($obj->fk_user_valid)
417 $vuser =
new User($this->
db);
418 $vuser->fetch($obj->fk_user_valid);
419 $this->user_validation = $vuser;
422 if ($obj->fk_user_cloture)
424 $cluser =
new User($this->
db);
425 $cluser->fetch($obj->fk_user_cloture);
426 $this->user_cloture = $cluser;
429 $this->date_creation = $this->
db->jdate($obj->datec);
430 $this->date_modification = $this->
db->jdate($obj->datem);
431 $this->date_validation = $this->
db->jdate($obj->datev);
434 $this->
db->free($result);
460 global $conf, $langs;
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
Class to manage Dolibarr users.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Class to manage Dolibarr database access.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
createCommon(User $user, $notrigger=false)
Create object into database.
info($id)
Load info into asset object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
fetch($id, $ref=null)
Load object in memory from the database.
getLibStatut($mode=0)
Retourne le libelle du status d'un user (actif, inactif)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
updateCommon(User $user, $notrigger=false)
Update object into database.
print $_SERVER["PHP_SELF"]
Edit parameters.
update(User $user, $notrigger=false)
Load object lines in memory from the database.
createFromClone(User $user, $fromid)
Clone and object into another one.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
static LibStatut($status, $mode=0)
Return the status.
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.
create(User $user, $notrigger=false)
Create object into database.