Fix time spent counted twice

This commit is contained in:
Laurent Destailleur 2017-11-16 19:41:31 +01:00
parent 0d192df1fd
commit f153d9c9ff
3 changed files with 32 additions and 5 deletions

View File

@ -899,11 +899,15 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
$projectstatic->id = $lines[$i]->fk_project; $projectstatic->id = $lines[$i]->fk_project;
} }
//var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
//var_dump($projectstatic->weekWorkLoadPerTask);
if (empty($workloadforid[$projectstatic->id])) if (empty($workloadforid[$projectstatic->id]))
{ {
$projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
$workloadforid[$projectstatic->id]=1; $workloadforid[$projectstatic->id]=1;
} }
//var_dump($projectstatic->weekWorkLoadPerTask);
//var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
$projectstatic->id=$lines[$i]->fk_project; $projectstatic->id=$lines[$i]->fk_project;
$projectstatic->ref=$lines[$i]->projectref; $projectstatic->ref=$lines[$i]->projectref;
@ -1033,6 +1037,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
$tmparray=dol_getdate($tmpday); $tmparray=dol_getdate($tmpday);
$dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id]; $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
$alreadyspent=''; $alreadyspent='';
if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin'); if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
$alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']); $alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']);

View File

@ -1670,7 +1670,7 @@ class Project extends CommonObject
$sql.= " WHERE ptt.fk_task = pt.rowid"; $sql.= " WHERE ptt.fk_task = pt.rowid";
$sql.= " AND pt.fk_projet = ".$this->id; $sql.= " AND pt.fk_projet = ".$this->id;
$sql.= " AND (ptt.task_date >= '".$this->db->idate($datestart)."' "; $sql.= " AND (ptt.task_date >= '".$this->db->idate($datestart)."' ";
$sql.= " AND ptt.task_date <= '".$this->db->idate($datestart + (7 * 24 * 3600) - 1)."')"; $sql.= " AND ptt.task_date <= '".$this->db->idate(dol_time_plus_duree($datestart, 1, 'w') - 1)."')";
if ($task_id) $sql.= " AND ptt.fk_task=".$taskid; if ($task_id) $sql.= " AND ptt.fk_task=".$taskid;
if (is_numeric($userid)) $sql.= " AND ptt.fk_user=".$userid; if (is_numeric($userid)) $sql.= " AND ptt.fk_user=".$userid;
@ -1678,6 +1678,9 @@ class Project extends CommonObject
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
//unset($this->weekWorkLoad[$day]);
//unset($this->weekWorkLoadPerTask[$day]);
$daylareadyfound=array();
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
@ -1686,8 +1689,17 @@ class Project extends CommonObject
{ {
$obj=$this->db->fetch_object($resql); $obj=$this->db->fetch_object($resql);
$day=$this->db->jdate($obj->task_date); $day=$this->db->jdate($obj->task_date);
if (empty($daylareadyfound[$day]))
{
$this->weekWorkLoad[$day] = $obj->task_duration;
$this->weekWorkLoadPerTask[$day][$obj->fk_task] = $obj->task_duration;
}
else
{
$this->weekWorkLoad[$day] += $obj->task_duration; $this->weekWorkLoad[$day] += $obj->task_duration;
$this->weekWorkLoadPerTask[$day][$obj->fk_task] += $obj->task_duration; $this->weekWorkLoadPerTask[$day][$obj->fk_task] += $obj->task_duration;
}
$daylareadyfound[$day]=1;
$i++; $i++;
} }
$this->db->free($resql); $this->db->free($resql);

View File

@ -474,6 +474,16 @@ if ($id > 0 || ! empty($ref))
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Task parent
print '<tr><td>'.$langs->trans("ChildOfTask").'</td><td>';
if ($object->fk_task_parent > 0)
{
$tasktmp=new Task($db);
$tasktmp->fetch($object->fk_task_parent);
print $tasktmp->getNomUrl(1);
}
print '</td></tr>';
// Date start - Date end // Date start - Date end
print '<tr><td class="titlefield">'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td colspan="3">'; print '<tr><td class="titlefield">'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td colspan="3">';
$start = dol_print_date($object->date_start,'dayhour'); $start = dol_print_date($object->date_start,'dayhour');