From 3793ae323a8bf3ad7521cd272db6f3e8ba2d3f23 Mon Sep 17 00:00:00 2001
From: gauthier <gauthier.verdol@atm-consulting.fr>
Date: Thu, 19 Oct 2017 09:46:19 +0200
Subject: [PATCH] FIX : wrong personnal project time spent

---
 htdocs/core/lib/project.lib.php    | 2 +-
 htdocs/projet/class/task.class.php | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php
index fa3967284d9..b70e037cbf4 100644
--- a/htdocs/core/lib/project.lib.php
+++ b/htdocs/core/lib/project.lib.php
@@ -762,7 +762,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
 
 				// Time spent by user
 				print '<td align="right">';
-				$tmptimespent=$taskstatic->getSummaryOfTimeSpent();
+				$tmptimespent=$taskstatic->getSummaryOfTimeSpent('', $fuser->id);
 				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
 				else print '--:--';
 				print "</td>\n";
diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php
index ca8ed73e10d..ae257d6eff4 100644
--- a/htdocs/projet/class/task.class.php
+++ b/htdocs/projet/class/task.class.php
@@ -911,9 +911,10 @@ class Task extends CommonObject
      *  Calculate total of time spent for task
      *
      *  @param	int		$id 		Id of object (here task)
+     *  @param	int		$user_id	Filter on user time
      *  @return array		        Array of info for task array('min_date', 'max_date', 'total_duration')
      */
-    function getSummaryOfTimeSpent($id='')
+    function getSummaryOfTimeSpent($id='', $user_id='')
     {
         global $langs;
 
@@ -927,6 +928,7 @@ class Task extends CommonObject
         $sql.= " SUM(t.task_duration) as total_duration";
         $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
         $sql.= " WHERE t.fk_task = ".$id;
+        if(!empty($user_id)) $sql.= " AND t.fk_user = ".$user_id;
 
         dol_syslog(get_class($this)."::getSummaryOfTimeSpent", LOG_DEBUG);
         $resql=$this->db->query($sql);
-- 
GitLab