Add task 1300 : Add thm field on user and time spent to be able to calculate employee cost

This commit is contained in:
Maxime Kohlhaas 2014-03-16 14:31:02 +01:00
parent 4d48034ad1
commit 0083e529c7
3 changed files with 27 additions and 3 deletions

View File

@ -1064,4 +1064,8 @@ CREATE TABLE llx_payment_salary (
--New 1074 : Stock mouvement link to origin
ALTER TABLE llx_stock_mouvement ADD fk_origin INT NOT NULL ;
ALTER TABLE llx_stock_mouvement ADD origintype VARCHAR( 32 ) NOT NULL ;
ALTER TABLE llx_stock_mouvement ADD origintype VARCHAR( 32 ) NOT NULL ;
--NEw 1300 : Add THM on user
ALTER TABLE llx_user ADD thm FLOAT NOT NULL ;
ALTER TABLE llx_projet_task_time ADD thm FLOAT NOT NULL ;

View File

@ -767,8 +767,8 @@ class Task extends CommonObject
dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql) )
{
$task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time");
$ret = $task_id;
$tasktime_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time");
$ret = $tasktme_id;
if (! $notrigger)
{
@ -793,6 +793,21 @@ class Task extends CommonObject
$sql.= " SET duration_effective = duration_effective + '".price2num($this->timespent_duration)."'";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
if (! $this->db->query($sql) )
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::addTimeSpent error -2 ".$this->error, LOG_ERR);
$ret = -2;
}
}
if ($ret >= 0)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time";
$sql.= " SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".$this->timespent_fk_user.")";
$sql.= " WHERE rowid = ".$tasktime_id;
dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
if (! $this->db->query($sql) )
{

View File

@ -100,6 +100,7 @@ class User extends CommonObject
var $parentof; // To store an array of all parents for all ids.
var $accountancy_code; // Accountancy code in prevision of the complete accountancy module
var $thm; // Average cost of employee
/**
@ -154,6 +155,7 @@ class User extends CommonObject
$sql.= " u.photo as photo,";
$sql.= " u.openid as openid,";
$sql.= " u.accountancy_code,";
$sql.= " u.thm,";
$sql.= " u.ref_int, u.ref_ext";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
@ -216,6 +218,7 @@ class User extends CommonObject
$this->lang = $obj->lang;
$this->entity = $obj->entity;
$this->accountancy_code = $obj->accountancy_code;
$this->thm = $obj->thm;
$this->datec = $this->db->jdate($obj->datec);
$this->datem = $this->db->jdate($obj->datem);
@ -1135,6 +1138,7 @@ class User extends CommonObject
$this->zip = empty($this->zip)?'':$this->zip;
$this->town = empty($this->town)?'':$this->town;
$this->accountancy_code = trim($this->accountancy_code);
$this->thm = price2num($this->thm);
// Check parameters
if (! empty($conf->global->USER_MAIL_REQUIRED) && ! isValidEMail($this->email))
@ -1165,6 +1169,7 @@ class User extends CommonObject
$sql.= ", job = '".$this->db->escape($this->job)."'";
$sql.= ", signature = '".$this->db->escape($this->signature)."'";
$sql.= ", accountancy_code = '".$this->db->escape($this->accountancy_code)."'";
$sql.= ", thm = ".$this->thm;
$sql.= ", note = '".$this->db->escape($this->note)."'";
$sql.= ", photo = ".($this->photo?"'".$this->db->escape($this->photo)."'":"null");
$sql.= ", openid = ".($this->openid?"'".$this->db->escape($this->openid)."'":"null");