28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
 
   40  public $module = 
'asset';
 
   45  public $element = 
'assetmodel';
 
   50  public $table_element = 
'asset_model';
 
   55  public $picto = 
'asset';
 
   58  const STATUS_DRAFT = 0;
 
   59  const STATUS_VALIDATED = 1;
 
   60  const STATUS_CANCELED = 9;
 
   94  public $fields = array(
 
   95    'rowid' => array(
'type' => 
'integer', 
'label' => 
'TechnicalID', 
'enabled' => 1, 
'position' => 1, 
'notnull' => 1, 
'visible' => 0, 
'noteditable' => 1, 
'index' => 1, 
'css' => 
'left', 
'comment' => 
"Id"),
 
   96    'ref' => array(
'type' => 
'varchar(128)', 
'label' => 
'Ref', 
'enabled' => 1, 
'position' => 20, 
'notnull' => 1, 
'visible' => 1, 
'index' => 1, 
'searchall' => 1, 
'showoncombobox' => 1, 
'validate' => 1),
 
   97    'ref_ext' => array(
'type' => 
'varchar(255)', 
'label' => 
'RefExt', 
'enabled' => 1, 
'position' => 25, 
'notnull' => 0, 
'visible' => 0),
 
   98    '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,),
 
   99    '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,),
 
  100    'note_public' => array(
'type' => 
'html', 
'label' => 
'NotePublic', 
'enabled' => 1, 
'position' => 300, 
'notnull' => 0, 
'visible' => 0, 
'validate' => 1,),
 
  101    'note_private' => array(
'type' => 
'html', 
'label' => 
'NotePrivate', 
'enabled' => 1, 
'position' => 301, 
'notnull' => 0, 
'visible' => 0, 
'validate' => 1,),
 
  102    'date_creation' => array(
'type' => 
'datetime', 
'label' => 
'DateCreation', 
'enabled' => 1, 
'position' => 500, 
'notnull' => 1, 
'visible' => -2,),
 
  103    'tms' => array(
'type' => 
'timestamp', 
'label' => 
'DateModification', 
'enabled' => 1, 
'position' => 501, 
'notnull' => 0, 
'visible' => -2,),
 
  104    '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',),
 
  105    'fk_user_modif' => array(
'type' => 
'integer:User:user/class/user.class.php', 
'label' => 
'UserModif', 
'enabled' => 1, 
'position' => 511, 
'notnull' => -1, 
'visible' => -2,),
 
  106    'import_key' => array(
'type' => 
'varchar(14)', 
'label' => 
'ImportId', 
'enabled' => 1, 
'position' => 1000, 
'notnull' => -1, 
'visible' => -2,),
 
  107    'status' => array(
'type' => 
'smallint', 
'label' => 
'Status', 
'enabled' => 1, 
'position' => 1000, 
'notnull' => 1, 
'default' => 
'1', 
'visible' => 1, 
'index' => 1, 
'arrayofkeyval' => array(0 => 
'Draft', 1 => 
'Enabled', 9 => 
'Disabled'), 
'validate' => 1,),
 
  132  public $note_private;
 
  136  public $fk_user_creat;
 
  140  public $fk_user_modif;
 
  144  public $last_main_doc;
 
  160  public $asset_depreciation_options;
 
  164  public $asset_accountancy_codes;
 
  189    global 
$conf, $langs;
 
  193    $this->ismultientitymanaged = 1;
 
  195    $this->isextrafieldmanaged = 1;
 
  198      $this->fields[
'rowid'][
'visible'] = 0;
 
  200    if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
 
  201      $this->fields[
'entity'][
'enabled'] = 0;
 
  205    foreach ($this->fields as $key => $val) {
 
  206      if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
 
  207        unset($this->fields[$key]);
 
  212    if (is_object($langs)) {
 
  213      foreach ($this->fields as $key => $val) {
 
  214        if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
 
  215          foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
 
  216            $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
 
 
  234    if ($resultcreate > 0 && !empty($this->asset_depreciation_options)) {
 
  235      $this->asset_depreciation_options->setDeprecationOptionsFromPost(1);
 
  236      $this->asset_depreciation_options->updateDeprecationOptions($user, 0, $resultcreate);
 
  239    if ($resultcreate > 0 && !empty($this->asset_accountancy_codes)) {
 
  240      $this->asset_accountancy_codes->setAccountancyCodesFromPost();
 
  241      $this->asset_accountancy_codes->updateAccountancyCodes($user, 0, $resultcreate);
 
  244    return $resultcreate;
 
 
  256    global $langs, $extrafields;
 
  266    $result = 
$object->fetchCommon($fromid);
 
  274    if (property_exists(
$object, 
'ref')) {
 
  276      $object->ref = empty($this->fields[
'ref'][
'default']) ? 
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
 
  278    if (property_exists(
$object, 
'label')) {
 
  280      $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".
$object->label : $this->fields[
'label'][
'default'];
 
  282    if (property_exists(
$object, 
'status')) {
 
  283      $object->status = self::STATUS_DRAFT;
 
  285    if (property_exists(
$object, 
'date_creation')) {
 
  288    if (property_exists(
$object, 
'date_modification')) {
 
  289      $object->date_modification = 
null;
 
  293    if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
 
  294      $extrafields->fetch_name_optionals_label($this->table_element);
 
  295      foreach (
$object->array_options as $key => $option) {
 
  296        $shortkey = preg_replace(
'/options_/', 
'', $key);
 
  297        if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
 
  299          unset(
$object->array_options[$key]);
 
  305    $object->context[
'createfromclone'] = 
'createfromclone';
 
  306    $result = 
$object->createCommon($user);
 
  310      $this->errors = 
$object->errors;
 
  322      if (property_exists($this, 
'fk_soc') && $this->fk_soc == 
$object->socid) {
 
  329    unset(
$object->context[
'createfromclone']);
 
  336      $this->db->rollback();
 
 
  348  public function fetch($id, $ref = 
null)
 
 
  367  public function fetchAll($sortorder = 
'', $sortfield = 
'', $limit = 0, $offset = 0, $filter = 
'', $filtermode = 
'AND')
 
  375    $sql .= 
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
 
  376    if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
 
  377      $sql .= 
" WHERE t.entity IN (".getEntity($this->element).
")";
 
  379      $sql .= 
" WHERE 1 = 1";
 
  386      $this->errors[] = $errormessage;
 
  387      dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
 
  391    if (!empty($sortfield)) {
 
  392      $sql .= $this->db->order($sortfield, $sortorder);
 
  394    if (!empty($limit)) {
 
  395      $sql .= $this->db->plimit($limit, $offset);
 
  398    $resql = $this->db->query($sql);
 
  400      $num = $this->db->num_rows($resql);
 
  402      while ($i < ($limit ? min($limit, $num) : $num)) {
 
  403        $obj = $this->db->fetch_object($resql);
 
  405        $record = 
new self($this->db);
 
  406        $record->setVarsFromFetchObj($obj);
 
  408        $records[$record->id] = $record;
 
  412      $this->db->free($resql);
 
  416      $this->errors[] = 
'Error '.$this->db->lasterror();
 
  417      dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
 
 
  434    if ($resultupdate > 0 && !empty($this->asset_depreciation_options)) {
 
  435      $this->asset_depreciation_options->setDeprecationOptionsFromPost(1);
 
  436      $this->asset_depreciation_options->updateDeprecationOptions($user, 0, $resultupdate);
 
  439    if ($resultupdate > 0 && !empty($this->asset_accountancy_codes)) {
 
  440      $this->asset_accountancy_codes->setAccountancyCodesFromPost();
 
  441      $this->asset_accountancy_codes->updateAccountancyCodes($user, 0, $resultupdate);
 
  444    return $resultupdate;
 
 
  454  public function delete(
User $user, $notrigger = 0)
 
 
  470    global 
$conf, $langs;
 
  475    if ($this->
status == self::STATUS_VALIDATED) {
 
  476      dol_syslog(get_class($this) . 
"::validate action abandoned: already validated", LOG_WARNING);
 
  485    $sql = 
"UPDATE " . MAIN_DB_PREFIX . $this->table_element;
 
  486    $sql .= 
" SET status = " . self::STATUS_VALIDATED;
 
  487    if (!empty($this->fields[
'date_validation'])) {
 
  488      $sql .= 
", date_validation = '" . $this->db->idate($now) . 
"'";
 
  490    if (!empty($this->fields[
'fk_user_valid'] ?? 
null)) {
 
  491      $sql .= 
", fk_user_valid = " . ((int) $user->id);
 
  493    $sql .= 
" WHERE rowid = " . ((int) $this->
id);
 
  495    dol_syslog(get_class($this) . 
"::validate()", LOG_DEBUG);
 
  496    $resql = $this->db->query($sql);
 
  499      $this->error = $this->db->lasterror();
 
  503    if (!$error && !$notrigger) {
 
  505      $result = $this->
call_trigger(
'ASSETMODEL_VALIDATE', $user);
 
  514      $this->
status = self::STATUS_VALIDATED;
 
  521      $this->db->rollback();
 
 
  537    if ($this->
status <= self::STATUS_DRAFT) {
 
  541    return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 
'ASSETMODEL_UNVALIDATE');
 
 
  551  public function cancel($user, $notrigger = 0)
 
  554    if ($this->
status != self::STATUS_VALIDATED) {
 
  558    return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 
'ASSETMODEL_CANCEL');
 
 
  568  public function reopen($user, $notrigger = 0)
 
  571    if ($this->
status != self::STATUS_CANCELED) {
 
  575    return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 
'ASSETMODEL_REOPEN');
 
 
  588  public function getNomUrl($withpicto = 0, $option = 
'', $notooltip = 0, $morecss = 
'', $save_lastsearch_value = -1)
 
  590    global 
$conf, $langs, $hookmanager;
 
  592    if (!empty(
$conf->dol_no_mouse_hover)) {
 
  598    $label = 
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"AssetModel").
'</u>';
 
  599    if (isset($this->
status)) {
 
  600      $label .= 
' '.$this->getLibStatut(5);
 
  603    $label .= 
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
 
  605    $url = 
dol_buildpath(
'/asset/model/card.php', 1).
'?id='.$this->id;
 
  607    if ($option != 
'nolink') {
 
  609      $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
 
  610      if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
 
  611        $add_save_lastsearch_values = 1;
 
  613      if ($add_save_lastsearch_values) {
 
  614        $url .= 
'&save_lastsearch_values=1';
 
  619    if (empty($notooltip)) {
 
  621        $label = $langs->trans(
"ShowAssetModel");
 
  622        $linkclose .= 
' alt="'.dol_escape_htmltag($label, 1).
'"';
 
  624      $linkclose .= 
' title="'.dol_escape_htmltag($label, 1).
'"';
 
  625      $linkclose .= 
' class="classfortooltip'.($morecss ? 
' '.$morecss : 
'').
'"';
 
  627      $linkclose = ($morecss ? 
' class="'.$morecss.
'"' : 
'');
 
  630    if ($option == 
'nolink') {
 
  631      $linkstart = 
'<span';
 
  633      $linkstart = 
'<a href="'.$url.
'"';
 
  635    $linkstart .= $linkclose.
'>';
 
  636    if ($option == 
'nolink') {
 
  637      $linkend = 
'</span>';
 
  642    $result .= $linkstart;
 
  644    if (empty($this->showphoto_on_popup)) {
 
  646        $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);
 
  650        require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
 
  652        list($class, $module) = explode(
'@', $this->picto);
 
  655        $filename = $filearray[0][
'name'];
 
  656        if (!empty($filename)) {
 
  657          $pospoint = strpos($filearray[0][
'name'], 
'.');
 
  659          $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
 
  661            $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>';
 
  663            $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>';
 
  668          $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);
 
  673    if ($withpicto != 2) {
 
  674      $result .= $this->ref;
 
  680    global $action, $hookmanager;
 
  681    $hookmanager->initHooks(array(
'assetmodeldao'));
 
  682    $parameters = array(
'id' => $this->
id, 
'getnomurl' => $result);
 
  683    $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action); 
 
  685      $result = $hookmanager->resPrint;
 
  687      $result .= $hookmanager->resPrint;
 
 
  726    if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
 
  729      $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
 
  730      $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
 
  731      $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
 
  732      $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
 
  733      $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Enabled');
 
  734      $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Disabled');
 
  737    $statusType = 
'status'.$status;
 
  739    if ($status == self::STATUS_CANCELED) {
 
  740      $statusType = 
'status6';
 
  743    return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], 
'', $statusType, $mode);
 
 
  754    $sql = 
"SELECT rowid, date_creation as datec, tms as datem,";
 
  755    $sql .= 
" fk_user_creat, fk_user_modif";
 
  756    $sql .= 
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
 
  757    $sql .= 
" WHERE t.rowid = ".((int) $id);
 
  759    $result = $this->db->query($sql);
 
  761      if ($this->db->num_rows($result)) {
 
  762        $obj = $this->db->fetch_object($result);
 
  764        $this->
id = $obj->rowid;
 
  766        $this->user_creation_id = $obj->fk_user_creat;
 
  767        $this->user_modification_id = $obj->fk_user_modif;
 
  768        $this->date_creation     = $this->db->jdate($obj->datec);
 
  769        $this->date_modification = $this->db->jdate($obj->datem);
 
  772      $this->db->free($result);
 
 
 
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
 
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.
 
create(User $user, $notrigger=0)
Create object into database.
 
info($id)
Load the info information in the object.
 
validate($user, $notrigger=0)
Validate object.
 
cancel($user, $notrigger=0)
Set cancel status.
 
update(User $user, $notrigger=0)
Update object into database.
 
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
 
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
 
Parent class of all other business classes (invoices, contracts, proposals, orders,...
 
createCommon(User $user, $notrigger=0)
Create object in the database.
 
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
 
updateCommon(User $user, $notrigger=0)
Update object into database.
 
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.
 
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
 
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
 
call_trigger($triggerName, $user)
Call trigger based on this instance.
 
Class to manage Dolibarr database access.
 
Class to manage Dolibarr users.
 
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
 
dol_dir_list($utf8_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.
 
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
 
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
 
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
 
dol_now($mode='auto')
Return date for now.
 
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
 
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.
 
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
 
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...