Merge branch '14.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur
2021-07-13 13:21:50 +02:00
12 changed files with 125 additions and 36 deletions

View File

@@ -116,6 +116,7 @@ class Task extends CommonObject
public $timespent_datehour; // More accurate start date (same than timespent_date but includes hours, minutes and seconds)
public $timespent_withhour; // 1 = we entered also start hours for timesheet line
public $timespent_fk_user;
public $timespent_thm;
public $timespent_note;
public $comments = array();
@@ -1224,6 +1225,7 @@ class Task extends CommonObject
$ret = -2;
}
// Update hourly rate of this time spent entry
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time";
$sql .= " SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".((int) $this->timespent_fk_user).")"; // set average hour rate of user
$sql .= " WHERE rowid = ".((int) $tasktime_id);
@@ -1437,6 +1439,7 @@ class Task extends CommonObject
$sql .= " ptt.task_duration,";
$sql .= " ptt.fk_user,";
$sql .= " ptt.note,";
$sql .= " ptt.thm,";
$sql .= " pt.rowid as task_id,";
$sql .= " pt.ref as task_ref,";
$sql .= " pt.label as task_label,";
@@ -1447,7 +1450,7 @@ class Task extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as ptt, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet as p";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
$sql .= " WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid";
$sql .= " AND ptt.fk_user = ".$userobj->id;
$sql .= " AND ptt.fk_user = ".((int) $userobj->id);
$sql .= " AND pt.entity IN (".getEntity('project').")";
if ($morewherefilter) {
$sql .= $morewherefilter;
@@ -1483,6 +1486,7 @@ class Task extends CommonObject
$newobj->timespent_withhour = $obj->task_date_withhour;
$newobj->timespent_duration = $obj->task_duration;
$newobj->timespent_fk_user = $obj->fk_user;
$newobj->timespent_thm = $obj->thm; // hourly rate
$newobj->timespent_note = $obj->note;
$arrayres[] = $newobj;
@@ -1575,10 +1579,12 @@ class Task extends CommonObject
}
if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration)) {
$newDuration = $this->timespent_duration - $this->timespent_old_duration;
// Recalculate amount of time spent for task and update denormalized field
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
$sql .= " SET duration_effective = (SELECT SUM(task_duration) FROM ".MAIN_DB_PREFIX."projet_task_time as ptt where ptt.fk_task = ".((int) $this->id).")";
if (isset($this->progress)) {
$sql .= ", progress = ".((float) $this->progress); // Do not overwrite value if not provided
}
$sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::updateTimeSpent", LOG_DEBUG);
@@ -1587,6 +1593,17 @@ class Task extends CommonObject
$this->db->rollback();
$ret = -2;
}
// Update hourly rate of this time spent entry, but only if it was not set initialy
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time";
$sql .= " SET thm = (SELECT thm FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".((int) $this->timespent_fk_user).")"; // set average hour rate of user
$sql .= " WHERE (thm IS NULL OR thm = 0) AND rowid = ".((int) $this->timespent_id);
dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
if (!$this->db->query($sql)) {
$this->error = $this->db->lasterror();
$ret = -2;
}
}
if ($ret >= 0) {