26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $module =
'asset';
43 public $element =
'assetmodel';
48 public $table_element =
'asset_model';
54 public $ismultientitymanaged = 1;
59 public $isextrafieldmanaged = 1;
64 public $picto =
'asset';
67 const STATUS_DRAFT = 0;
68 const STATUS_VALIDATED = 1;
69 const STATUS_CANCELED = 9;
103 public $fields=array(
104 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>1,
'notnull'=>1,
'visible'=>0,
'noteditable'=>
'1',
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
105 'ref' => array(
'type'=>
'varchar(128)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>20,
'notnull'=>1,
'visible'=>1,
'index'=>1,
'searchall'=>1,
'showoncombobox'=>
'1',
'validate'=>
'1'),
106 'label' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>
'1',
'position'=>30,
'notnull'=>1,
'visible'=>1,
'searchall'=>1,
'css'=>
'minwidth300',
'cssview'=>
'wordbreak',
'showoncombobox'=>
'2',
'validate'=>
'1',),
107 'asset_type' => array(
'type'=>
'smallint',
'label'=>
'AssetType',
'enabled'=>
'1',
'position'=>40,
'notnull'=>1,
'visible'=>1,
'arrayofkeyval'=>array(
'0'=>
'AssetTypeIntangible',
'1'=>
'AssetTypeTangible',
'2'=>
'AssetTypeInProgress',
'3'=>
'AssetTypeFinancial'),
'validate'=>
'1',),
108 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>
'1',
'position'=>300,
'notnull'=>0,
'visible'=>0,
'validate'=>
'1',),
109 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>
'1',
'position'=>301,
'notnull'=>0,
'visible'=>0,
'validate'=>
'1',),
110 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>500,
'notnull'=>1,
'visible'=>-2,),
111 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>
'1',
'position'=>501,
'notnull'=>0,
'visible'=>-2,),
112 'fk_user_creat' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>
'1',
'position'=>510,
'notnull'=>1,
'visible'=>-2,
'foreignkey'=>
'user.rowid',),
113 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>-2,),
114 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>-1,
'visible'=>-2,),
115 'status' => array(
'type'=>
'smallint',
'label'=>
'Status',
'enabled'=>
'1',
'position'=>1000,
'notnull'=>1,
'default'=>
'0',
'visible'=>2,
'index'=>1,
'arrayofkeyval'=>array(
'0'=>
'Draft',
'1'=>
'Enabled',
'9'=>
'Disabled'),
'validate'=>
'1',),
122 public $note_private;
123 public $date_creation;
125 public $fk_user_creat;
126 public $fk_user_modif;
127 public $last_main_doc;
131 public $asset_depreciation_options;
156 global $conf, $langs;
161 $this->fields[
'rowid'][
'visible'] = 0;
163 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
164 $this->fields[
'entity'][
'enabled'] = 0;
168 foreach ($this->fields as $key => $val) {
169 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
170 unset($this->fields[$key]);
175 if (is_object($langs)) {
176 foreach ($this->fields as $key => $val) {
177 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
178 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
179 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
197 return $resultcreate;
209 global $langs, $extrafields;
214 $object =
new self($this->db);
219 $result = $object->fetchCommon($fromid);
220 if ($result > 0 && !empty($object->table_element_line)) {
221 $object->fetchLines();
230 unset($object->fk_user_creat);
231 unset($object->import_key);
234 if (property_exists($object,
'ref')) {
235 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
237 if (property_exists($object,
'label')) {
238 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
240 if (property_exists($object,
'status')) {
241 $object->status = self::STATUS_DRAFT;
243 if (property_exists($object,
'date_creation')) {
244 $object->date_creation =
dol_now();
246 if (property_exists($object,
'date_modification')) {
247 $object->date_modification =
null;
251 if (is_array($object->array_options) && count($object->array_options) > 0) {
252 $extrafields->fetch_name_optionals_label($this->table_element);
253 foreach ($object->array_options as $key => $option) {
254 $shortkey = preg_replace(
'/options_/',
'', $key);
255 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
257 unset($object->array_options[$key]);
263 $object->context[
'createfromclone'] =
'createfromclone';
264 $result = $object->createCommon($user);
267 $this->error = $object->error;
268 $this->errors = $object->errors;
280 if (property_exists($this,
'fk_soc') && $this->fk_soc == $object->socid) {
287 unset($object->context[
'createfromclone']);
294 $this->db->rollback();
306 public function fetch($id, $ref =
null)
309 if ($result > 0 && !empty($this->table_element_line)) {
322 $this->lines = array();
339 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
349 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
350 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
351 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
353 $sql .=
" WHERE 1 = 1";
357 if (count($filter) > 0) {
358 foreach ($filter as $key => $value) {
359 if ($key ==
't.rowid') {
360 $sqlwhere[] = $key.
" = ".((int) $value);
361 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
362 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
363 } elseif ($key ==
'customsql') {
364 $sqlwhere[] = $value;
365 } elseif (strpos($value,
'%') ===
false) {
366 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
368 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
372 if (count($sqlwhere) > 0) {
373 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
376 if (!empty($sortfield)) {
377 $sql .= $this->db->order($sortfield, $sortorder);
379 if (!empty($limit)) {
380 $sql .= $this->db->plimit($limit, $offset);
383 $resql = $this->db->query($sql);
385 $num = $this->db->num_rows($resql);
387 while ($i < ($limit ? min($limit, $num) : $num)) {
388 $obj = $this->db->fetch_object($resql);
390 $record =
new self($this->db);
391 $record->setVarsFromFetchObj($obj);
393 $records[$record->id] = $record;
397 $this->db->free($resql);
401 $this->errors[] =
'Error '.$this->db->lasterror();
402 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
427 public function delete(
User $user, $notrigger =
false)
443 global $conf, $langs;
448 if ($this->
status == self::STATUS_VALIDATED) {
449 dol_syslog(get_class($this) .
"::validate action abandonned: already validated", LOG_WARNING);
458 $sql =
"UPDATE " . MAIN_DB_PREFIX . $this->table_element;
459 $sql .=
" SET status = " . self::STATUS_VALIDATED;
460 if (!empty($this->fields[
'date_validation'])) {
461 $sql .=
", date_validation = '" . $this->db->idate($now) .
"'";
463 if (!empty($this->fields[
'fk_user_valid'])) {
464 $sql .=
", fk_user_valid = " . ((int) $user->id);
466 $sql .=
" WHERE rowid = " . ((int) $this->
id);
468 dol_syslog(get_class($this) .
"::validate()", LOG_DEBUG);
469 $resql = $this->db->query($sql);
472 $this->error = $this->db->lasterror();
476 if (!$error && !$notrigger) {
478 $result = $this->
call_trigger(
'ASSETMODEL_VALIDATE', $user);
487 $this->
status = self::STATUS_VALIDATED;
494 $this->db->rollback();
510 if ($this->
status <= self::STATUS_DRAFT) {
514 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'ASSETMODEL_UNVALIDATE');
524 public function cancel($user, $notrigger = 0)
527 if ($this->
status != self::STATUS_VALIDATED) {
531 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'ASSETMODEL_CANCEL');
541 public function reopen($user, $notrigger = 0)
544 if ($this->
status != self::STATUS_CANCELED) {
548 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'ASSETMODEL_REOPEN');
561 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
563 global $conf, $langs, $hookmanager;
565 if (!empty($conf->dol_no_mouse_hover)) {
571 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"AssetModel").
'</u>';
572 if (isset($this->
status)) {
573 $label .=
' '.$this->getLibStatut(5);
576 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
578 $url =
dol_buildpath(
'/asset/model/card.php', 1).
'?id='.$this->id;
580 if ($option !=
'nolink') {
582 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
583 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
584 $add_save_lastsearch_values = 1;
586 if ($add_save_lastsearch_values) {
587 $url .=
'&save_lastsearch_values=1';
592 if (empty($notooltip)) {
594 $label = $langs->trans(
"ShowAssetModel");
595 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
597 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
598 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
600 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
603 if ($option ==
'nolink') {
604 $linkstart =
'<span';
606 $linkstart =
'<a href="'.$url.
'"';
608 $linkstart .= $linkclose.
'>';
609 if ($option ==
'nolink') {
610 $linkend =
'</span>';
615 $result .= $linkstart;
617 if (empty($this->showphoto_on_popup)) {
619 $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);
623 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
625 list($class, $module) = explode(
'@', $this->picto);
628 $filename = $filearray[0][
'name'];
629 if (!empty($filename)) {
630 $pospoint = strpos($filearray[0][
'name'],
'.');
632 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
634 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.
'" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div></div>';
636 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div>';
641 $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);
646 if ($withpicto != 2) {
647 $result .= $this->ref;
653 global $action, $hookmanager;
654 $hookmanager->initHooks(array(
'assetmodeldao'));
655 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
656 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
658 $result = $hookmanager->resPrint;
660 $result .= $hookmanager->resPrint;
699 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
702 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
703 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
704 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
705 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
706 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
707 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
710 $statusType =
'status'.$status;
712 if ($status == self::STATUS_CANCELED) {
713 $statusType =
'status6';
716 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
727 $sql =
"SELECT rowid, date_creation as datec, tms as datem,";
728 $sql .=
" fk_user_creat, fk_user_modif";
729 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
730 $sql .=
" WHERE t.rowid = ".((int) $id);
732 $result = $this->db->query($sql);
734 if ($this->db->num_rows($result)) {
735 $obj = $this->db->fetch_object($result);
737 $this->
id = $obj->rowid;
739 $this->user_creation_id = $obj->fk_user_creat;
740 $this->user_modification_id = $obj->fk_user_modif;
741 $this->date_creation = $this->db->jdate($obj->datec);
742 $this->date_modification = $this->db->jdate($obj->datem);
745 $this->db->free($result);
773 $this->lines = array();
787 global $conf, $langs;
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
reopen($user, $notrigger=0)
Set back to validated status.
getLabelStatus($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the status.
setDraft($user, $notrigger=0)
Set draft status.
fetch($id, $ref=null)
Load object in memory from the database.
__construct(DoliDB $db)
Constructor.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getLibStatut($mode=0)
Return the label of the status.
createFromClone(User $user, $fromid)
Clone an object into another one.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
info($id)
Load the info information in the object.
update(User $user, $notrigger=false)
Update object into database.
validate($user, $notrigger=0)
Validate object.
create(User $user, $notrigger=false)
Create object into database.
cancel($user, $notrigger=0)
Set cancel status.
getLinesArray()
Create an array of lines.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
fetchLines()
Load object lines in memory from the database.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.