Fix: management of time spent in task card

Fix: Update time spent in seconds
This commit is contained in:
Regis Houssin 2010-03-02 07:28:59 +00:00
parent d9fabf962f
commit e51a002c10
2 changed files with 14 additions and 13 deletions

View File

@ -59,6 +59,7 @@ class Task extends CommonObject
var $timespent_id; var $timespent_id;
var $timespent_duration; var $timespent_duration;
var $timespent_old_duration;
var $timespent_date; var $timespent_date;
var $timespent_fk_user; var $timespent_fk_user;
var $timespent_note; var $timespent_note;
@ -597,8 +598,6 @@ class Task extends CommonObject
$ret = 0; $ret = 0;
// Clean parameters // Clean parameters
$this->timespent_duration = intval($this->timespent_duration)+(($this->timespent_duration-intval($this->timespent_duration))*(1+2/3));
$this->timespent_duration = price2num($this->timespent_duration);
if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note); if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (";
@ -713,8 +712,6 @@ class Task extends CommonObject
$ret = 0; $ret = 0;
// Clean parameters // Clean parameters
$this->timespent_duration = intval($this->timespent_duration)+(($this->timespent_duration-intval($this->timespent_duration))*(1+2/3));
$this->timespent_duration = price2num($this->timespent_duration);
if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note); if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note);
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET";
@ -744,14 +741,16 @@ class Task extends CommonObject
dol_syslog(get_class($this)."::updateTimeSpent error -1 ".$this->error,LOG_ERR); dol_syslog(get_class($this)."::updateTimeSpent error -1 ".$this->error,LOG_ERR);
$ret = -1; $ret = -1;
} }
/*
if ($ret >= 0) if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration))
{ {
$newDuration = $this->timespent_duration - $this->timespent_old_duration;
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
$sql.= " SET duration_effective = duration_effective + '".price2num($this->timespent_duration)."'"; $sql.= " SET duration_effective = duration_effective + '".$newDuration."'";
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::updateTimeSpent sql=".$sql, LOG_DEBUG);
if (! $this->db->query($sql) ) if (! $this->db->query($sql) )
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
@ -759,7 +758,7 @@ class Task extends CommonObject
$ret = -2; $ret = -2;
} }
} }
*/
return $ret; return $ret;
} }
@ -800,7 +799,7 @@ class Task extends CommonObject
if (! $error) if (! $error)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
$sql.= " SET duration_effective = duration_effective - '".price2num($this->timespent_duration)."'"; $sql.= " SET duration_effective = duration_effective - '".$this->timespent_duration."'";
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::delTimeSpent sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::delTimeSpent sql=".$sql, LOG_DEBUG);

View File

@ -79,7 +79,7 @@ if ($_POST["action"] == 'updateline' && ! $_POST["cancel"] && $user->rights->pro
{ {
$error=0; $error=0;
if (empty($_POST["timespent_duration_linehour"]) && empty($_POST["timespent_duration_linemin"])) if (empty($_POST["new_durationhour"]) && empty($_POST["new_durationmin"]))
{ {
$mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Duration")).'</div>'; $mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Duration")).'</div>';
$error++; $error++;
@ -88,11 +88,13 @@ if ($_POST["action"] == 'updateline' && ! $_POST["cancel"] && $user->rights->pro
if (! $error) if (! $error)
{ {
$task = new Task($db); $task = new Task($db);
$task->fetch($_POST["id"]);
$task->timespent_id = $_POST["lineid"]; $task->timespent_id = $_POST["lineid"];
$task->timespent_note = $_POST["timespent_note_line"]; $task->timespent_note = $_POST["timespent_note_line"];
$task->timespent_duration = $_POST["timespent_duration_linehour"]*60*60; // We store duration in seconds $task->timespent_old_duration = $_POST["old_duration"];
$task->timespent_duration+= $_POST["timespent_duration_linemin"]*60; // We store duration in seconds $task->timespent_duration = $_POST["new_durationhour"]*60*60; // We store duration in seconds
$task->timespent_duration+= $_POST["new_durationmin"]*60; // We store duration in seconds
$task->timespent_date = dol_mktime(12,0,0,$_POST["timelinemonth"],$_POST["timelineday"],$_POST["timelineyear"]); $task->timespent_date = dol_mktime(12,0,0,$_POST["timelinemonth"],$_POST["timelineday"],$_POST["timelineyear"]);
$task->timespent_fk_user = $_POST["userid_line"]; $task->timespent_fk_user = $_POST["userid_line"];