NEW : conf TIMESPENT_ALWAYS_UPDATE_THM, when it's on we always check current thm of user to update it in task time line

This commit is contained in:
Gauthier PC portable 024 2022-08-02 10:49:34 +02:00
parent 6b5fac432f
commit da196b868c

View File

@ -1724,7 +1724,9 @@ class Task extends CommonObjectLine
$ret = -1; $ret = -1;
} }
if ($ret == 1 && ($this->timespent_old_duration != $this->timespent_duration)) { if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) || !empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM))) {
if($this->timespent_old_duration != $this->timespent_duration) {
// Recalculate amount of time spent for task and update denormalized field // Recalculate amount of time spent for task and update denormalized field
$sql = "UPDATE " . MAIN_DB_PREFIX . "projet_task"; $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) . ")"; $sql .= " SET duration_effective = (SELECT SUM(task_duration) FROM " . MAIN_DB_PREFIX . "projet_task_time as ptt where ptt.fk_task = " . ((int)$this->id) . ")";
@ -1739,11 +1741,15 @@ class Task extends CommonObjectLine
$this->db->rollback(); $this->db->rollback();
$ret = -2; $ret = -2;
} }
}
// Update hourly rate of this time spent entry, but only if it was not set initialy // 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 = "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 .= " 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); $sql .= " WHERE rowid = ".((int) $this->timespent_id);
if(empty($conf->global->TIMESPENT_ALWAYS_UPDATE_THM)) { // then if not empty we always update, in case of new thm for user, or change user of task time line
$sql .= " AND (thm IS NULL OR thm = 0)";
}
dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG); dol_syslog(get_class($this)."::addTimeSpent", LOG_DEBUG);
if (!$this->db->query($sql)) { if (!$this->db->query($sql)) {