Skip to content

Commit

Permalink
Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
eldy committed Feb 8, 2020
2 parents aed3ea2 + 3dfe716 commit 3852ba0
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 123 deletions.
134 changes: 67 additions & 67 deletions htdocs/asset/class/asset_type.class.php
Expand Up @@ -68,9 +68,9 @@ class AssetType extends CommonObject
public $note;

/** @var array Array of asset */
public $asset=array();
public $asset = array();

public $fields=array(
public $fields = array(
'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15, 'index'=>1),
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20),
Expand Down Expand Up @@ -104,30 +104,30 @@ public function create($user, $notrigger = 0)
{
global $conf;

$error=0;
$error = 0;

$this->label=trim($this->label);
$this->label = trim($this->label);
$this->accountancy_code_asset = trim($this->accountancy_code_asset);
$this->accountancy_code_depreciation_asset = trim($this->accountancy_code_depreciation_asset);
$this->accountancy_code_depreciation_expense = trim($this->accountancy_code_depreciation_expense);

$this->db->begin();

$sql = "INSERT INTO ".MAIN_DB_PREFIX."asset_type (";
$sql.= "label";
$sql.= ", accountancy_code_asset";
$sql.= ", accountancy_code_depreciation_asset";
$sql.= ", accountancy_code_depreciation_expense";
$sql.= ", note";
$sql.= ", entity";
$sql.= ") VALUES (";
$sql.= "'".$this->db->escape($this->label)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_asset)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_depreciation_asset)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_depreciation_expense)."'";
$sql.= ", '".$this->db->escape($this->note)."'";
$sql.= ", ".$conf->entity;
$sql.= ")";
$sql .= "label";
$sql .= ", accountancy_code_asset";
$sql .= ", accountancy_code_depreciation_asset";
$sql .= ", accountancy_code_depreciation_expense";
$sql .= ", note";
$sql .= ", entity";
$sql .= ") VALUES (";
$sql .= "'".$this->db->escape($this->label)."'";
$sql .= ", '".$this->db->escape($this->accountancy_code_asset)."'";
$sql .= ", '".$this->db->escape($this->accountancy_code_depreciation_asset)."'";
$sql .= ", '".$this->db->escape($this->accountancy_code_depreciation_expense)."'";
$sql .= ", '".$this->db->escape($this->note)."'";
$sql .= ", ".$conf->entity;
$sql .= ")";

dol_syslog("Asset_type::create", LOG_DEBUG);
$result = $this->db->query($sql);
Expand All @@ -142,15 +142,15 @@ public function create($user, $notrigger = 0)
return -3;
}

if (! $notrigger)
if (!$notrigger)
{
// Call trigger
$result=$this->call_trigger('ASSET_TYPE_CREATE', $user);
$result = $this->call_trigger('ASSET_TYPE_CREATE', $user);
if ($result < 0) { $error++; }
// End call triggers
}

if (! $error)
if (!$error)
{
$this->db->commit();
return $this->id;
Expand All @@ -164,7 +164,7 @@ public function create($user, $notrigger = 0)
}
else
{
$this->error=$this->db->lasterror();
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
}
Expand All @@ -181,45 +181,45 @@ public function update($user, $notrigger = 0)
{
global $conf, $hookmanager;

$error=0;
$error = 0;

$this->label=trim($this->label);
$this->label = trim($this->label);

$this->db->begin();

$sql = "UPDATE ".MAIN_DB_PREFIX."asset_type ";
$sql.= "SET ";
$sql.= "label = '".$this->db->escape($this->label) ."',";
$sql.= "accountancy_code_asset = '".$this->db->escape($this->accountancy_code_asset)."',";
$sql.= "accountancy_code_depreciation_asset = '".$this->db->escape($this->accountancy_code_depreciation_asset)."',";
$sql.= "accountancy_code_depreciation_expense = '".$this->db->escape($this->accountancy_code_depreciation_expense)."',";
$sql.= "note = '".$this->db->escape($this->note) ."'";
$sql.= " WHERE rowid =".$this->id;
$sql .= "SET ";
$sql .= "label = '".$this->db->escape($this->label)."',";
$sql .= "accountancy_code_asset = '".$this->db->escape($this->accountancy_code_asset)."',";
$sql .= "accountancy_code_depreciation_asset = '".$this->db->escape($this->accountancy_code_depreciation_asset)."',";
$sql .= "accountancy_code_depreciation_expense = '".$this->db->escape($this->accountancy_code_depreciation_expense)."',";
$sql .= "note = '".$this->db->escape($this->note)."'";
$sql .= " WHERE rowid =".$this->id;

$result = $this->db->query($sql);
if ($result)
{
$action='update';
$action = 'update';

// Actions on extra fields
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
$result = $this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}

if (! $error && ! $notrigger)
if (!$error && !$notrigger)
{
// Call trigger
$result=$this->call_trigger('ASSET_TYPE_MODIFY', $user);
$result = $this->call_trigger('ASSET_TYPE_MODIFY', $user);
if ($result < 0) { $error++; }
// End call triggers
}

if (! $error)
if (!$error)
{
$this->db->commit();
return 1;
Expand All @@ -233,7 +233,7 @@ public function update($user, $notrigger = 0)
}
else
{
$this->error=$this->db->lasterror();
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
}
Expand All @@ -251,13 +251,13 @@ public function delete()
$error = 0;

$sql = "DELETE FROM ".MAIN_DB_PREFIX."asset_type";
$sql.= " WHERE rowid = ".$this->id;
$sql .= " WHERE rowid = ".$this->id;

$resql=$this->db->query($sql);
$resql = $this->db->query($sql);
if ($resql)
{
// Call trigger
$result=$this->call_trigger('ASSET_TYPE_DELETE', $user);
$result = $this->call_trigger('ASSET_TYPE_DELETE', $user);
if ($result < 0) { $error++; $this->db->rollback(); return -2; }
// End call triggers

Expand All @@ -267,7 +267,7 @@ public function delete()
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
$this->error = $this->db->lasterror();
return -1;
}
}
Expand All @@ -286,7 +286,7 @@ public function fetch($rowid)

dol_syslog("Asset_type::fetch", LOG_DEBUG);

$resql=$this->db->query($sql);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
Expand All @@ -306,7 +306,7 @@ public function fetch($rowid)
}
else
{
$this->error=$this->db->lasterror();
$this->error = $this->db->lasterror();
return -1;
}
}
Expand All @@ -320,15 +320,15 @@ public function fetch($rowid)
public function liste_array()
{
// phpcs:enable
global $conf,$langs;
global $conf, $langs;

$assettypes = array();

$sql = "SELECT rowid, label as label";
$sql.= " FROM ".MAIN_DB_PREFIX."asset_type";
$sql.= " WHERE entity IN (".getEntity('asset_type').")";
$sql .= " FROM ".MAIN_DB_PREFIX."asset_type";
$sql .= " WHERE entity IN (".getEntity('asset_type').")";

$resql=$this->db->query($sql);
$resql = $this->db->query($sql);
if ($resql)
{
$nump = $this->db->num_rows($resql);
Expand Down Expand Up @@ -365,45 +365,45 @@ public function listAssetForAssetType($excludefilter = '', $mode = 0)
{
global $conf, $user;

$ret=array();
$ret = array();

$sql = "SELECT a.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."asset as a";
$sql.= " WHERE a.entity IN (".getEntity('asset').")";
$sql.= " AND a.fk_asset_type = ".$this->id;
if (! empty($excludefilter)) $sql.=' AND ('.$excludefilter.')';
$sql .= " FROM ".MAIN_DB_PREFIX."asset as a";
$sql .= " WHERE a.entity IN (".getEntity('asset').")";
$sql .= " AND a.fk_asset_type = ".$this->id;
if (!empty($excludefilter)) $sql .= ' AND ('.$excludefilter.')';

dol_syslog(get_class($this)."::listAssetsForGroup", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
while ($obj = $this->db->fetch_object($resql))
{
if (! array_key_exists($obj->rowid, $ret))
if (!array_key_exists($obj->rowid, $ret))
{
if ($mode < 2)
{
$assetstatic=new Asset($this->db);
$assetstatic = new Asset($this->db);
if ($mode == 1) {
$assetstatic->fetch($obj->rowid, '', '', '', false, false);
} else {
$assetstatic->fetch($obj->rowid);
}
$ret[$obj->rowid]=$assetstatic;
$ret[$obj->rowid] = $assetstatic;
}
else $ret[$obj->rowid]=$obj->rowid;
else $ret[$obj->rowid] = $obj->rowid;
}
}

$this->db->free($resql);

$this->asset=$ret;
$this->asset = $ret;

return $ret;
}
else
{
$this->error=$this->db->lasterror();
$this->error = $this->db->lasterror();
return -1;
}
}
Expand All @@ -420,15 +420,15 @@ public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0)
{
global $langs;

$result='';
$label=$langs->trans("ShowTypeCard", $this->label);
$result = '';
$label = $langs->trans("ShowTypeCard", $this->label);

$linkstart = '<a href="'.DOL_URL_ROOT.'/asset/type.php?rowid='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend='</a>';
$linkend = '</a>';

$result .= $linkstart;
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);
if ($withpicto != 2) $result.= ($maxlen?dol_trunc($this->label, $maxlen):$this->label);
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);
if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->label, $maxlen) : $this->label);
$result .= $linkend;

return $result;
Expand All @@ -448,13 +448,13 @@ public function initAsSpecimen()
// Initialize parameters
$this->id = 0;
$this->ref = 'ATSPEC';
$this->specimen=1;
$this->specimen = 1;

$this->label='ASSET TYPE SPECIMEN';
$this->note='This is a note';
$this->label = 'ASSET TYPE SPECIMEN';
$this->note = 'This is a note';

// Assets of this asset type is just me
$this->asset=array(
$this->asset = array(
$user->id => $user
);
}
Expand Down
16 changes: 8 additions & 8 deletions htdocs/asset/list.php
Expand Up @@ -412,7 +412,7 @@ function init_myfunc()
// Fields title label
// --------------------------------------------------------------------
print '<tr class="liste_titre">';
foreach($object->fields as $key => $val)
foreach ($object->fields as $key => $val)
{
$cssforfield = (empty($val['css']) ? '' : $val['css']);
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
Expand All @@ -427,16 +427,16 @@ function init_myfunc()
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields
$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Action column
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ')."\n";
print '</tr>'."\n";


// Detect if we need a fetch on each output line
$needToFetchEachLine=0;
$needToFetchEachLine = 0;
if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
{
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
Expand All @@ -448,19 +448,19 @@ function init_myfunc()

// Loop on record
// --------------------------------------------------------------------
$i=0;
$totalarray=array();
$i = 0;
$totalarray = array();
while ($i < ($limit ? min($num, $limit) : $num))
{
$obj = $db->fetch_object($resql);
if (empty($obj)) break; // Should not happen
if (empty($obj)) break; // Should not happen

// Store properties in $object
$object->setVarsFromFetchObj($obj);

// Show here line of result
print '<tr class="oddeven">';
foreach($object->fields as $key => $val)
foreach ($object->fields as $key => $val)
{
$cssforfield = (empty($val['css']) ? '' : $val['css']);
if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
Expand Down

0 comments on commit 3852ba0

Please sign in to comment.