NEW Show line "other filtered task" when using filter on timesheet.

This commit is contained in:
Laurent Destailleur 2017-11-16 22:55:04 +01:00
parent f153d9c9ff
commit e06087888b
7 changed files with 218 additions and 64 deletions

View File

@ -113,15 +113,15 @@ function parseTime(timeStr, dt)
function updateTotal(days,mode) function updateTotal(days,mode)
{ {
console.log('updateTotal days='+days+' mode='+mode); console.log('updateTotal days='+days+' mode='+mode);
if(mode=="hours") if (mode=="hours")
{ {
var total = new Date(0); var total = new Date(0);
total.setHours(0); total.setHours(0);
total.setMinutes(0); total.setMinutes(0);
var nbline = document.getElementById('numberOfLines').value; var nbline = document.getElementById('numberOfLines').value;
for (var i=0;i<nbline;i++) for (var i=-1; i<nbline; i++)
{ {
var id='timespent['+i+']['+days+']'; var id='timespent['+i+']['+days+']';
var taskTime= new Date(0); var taskTime= new Date(0);
var element=document.getElementById(id); var element=document.getElementById(id);
if(element) if(element)
@ -223,7 +223,7 @@ function updateTotal(days,mode)
{ {
var total =0; var total =0;
var nbline = document.getElementById('numberOfLines').value; var nbline = document.getElementById('numberOfLines').value;
for (var i=0;i<nbline;i++) for (var i=-1; i<nbline; i++)
{ {
var id='timespent['+i+']['+days+']'; var id='timespent['+i+']['+days+']';
var taskTime= new Date(0); var taskTime= new Date(0);

View File

@ -590,7 +590,7 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
* @param int $preselectedday Preselected day * @param int $preselectedday Preselected day
* @param array $isavailable Array with data that say if user is available for several days for morning and afternoon * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
* @param int $oldprojectforbreak Old project id of last project break * @param int $oldprojectforbreak Old project id of last project break
* @return $inc * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
*/ */
function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak=0) function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak=0)
{ {
@ -598,6 +598,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr
global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic; global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
$lastprojectid=0; $lastprojectid=0;
$totalforeachday=array();
$workloadforid=array(); $workloadforid=array();
$lineswithoutlevel0=array(); $lineswithoutlevel0=array();
@ -774,6 +775,8 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr
print '<td align="center" class="duration'.($cssonholiday?' '.$cssonholiday:'').'">'; print '<td align="center" class="duration'.($cssonholiday?' '.$cssonholiday:'').'">';
$dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id]; $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id];
$totalforeachday[$preselectedday]+=$dayWorkLoad;
$alreadyspent=''; $alreadyspent='';
if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin'); if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
@ -822,8 +825,17 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr
$level++; $level++;
if ($lines[$i]->id > 0) if ($lines[$i]->id > 0)
{ {
if ($parent == 0) projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak); //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
else projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak); //var_dump($totalforeachday);
$ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak);
//var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
//var_dump($ret);
foreach($ret as $key => $val)
{
$totalforeachday[$key]+=$val;
}
//var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
//var_dump($totalforeachday);
} }
$level--; $level--;
} }
@ -833,7 +845,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr
} }
} }
return $inc; return $totalforeachday;
} }
@ -852,7 +864,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr
* @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
* @param array $isavailable Array with data that say if user is available for several days for morning and afternoon * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
* @param int $oldprojectforbreak Old project id of last project break * @param int $oldprojectforbreak Old project id of last project break
* @return $inc * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
*/ */
function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak=0) function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak=0)
{ {
@ -863,6 +875,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
$lastprojectid=0; $lastprojectid=0;
$workloadforid=array(); $workloadforid=array();
$totalforeachday=array();
$lineswithoutlevel0=array(); $lineswithoutlevel0=array();
// Create a smaller array with sublevels only to be used later. This increase dramatically performances. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
@ -1037,6 +1050,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];
$totalforeachday[$tmpday]+=$dayWorkLoad;
$alreadyspent=''; $alreadyspent='';
if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin'); if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
@ -1078,8 +1092,17 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
$level++; $level++;
if ($lines[$i]->id > 0) if ($lines[$i]->id > 0)
{ {
if ($parent == 0) projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak); //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
else projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak); //var_dump($totalforeachday);
$ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak);
//var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
//var_dump($ret);
foreach($ret as $key => $val)
{
$totalforeachday[$key]+=$val;
}
//var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
//var_dump($totalforeachday);
} }
$level--; $level--;
} }
@ -1089,7 +1112,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$
} }
} }
return $inc; return $totalforeachday;
} }

View File

@ -897,3 +897,4 @@ NbComments=Number of comments
CommentPage=Comments space CommentPage=Comments space
CommentAdded=Comment added CommentAdded=Comment added
CommentDeleted=Comment deleted CommentDeleted=Comment deleted
Everybody=Everybody

View File

@ -21,7 +21,7 @@ OnlyOpenedProject=Only open projects are visible (projects in draft or closed st
ClosedProjectsAreHidden=Closed projects are not visible. ClosedProjectsAreHidden=Closed projects are not visible.
TasksPublicDesc=This view presents all projects and tasks you are allowed to read. TasksPublicDesc=This view presents all projects and tasks you are allowed to read.
TasksDesc=This view presents all projects and tasks (your user permissions grant you permission to view everything). TasksDesc=This view presents all projects and tasks (your user permissions grant you permission to view everything).
AllTaskVisibleButEditIfYouAreAssigned=All tasks for qualified projects are visible, but you can enter time only for task assigned to you. Assign task to yourself if you need to enter time on it. AllTaskVisibleButEditIfYouAreAssigned=All tasks for qualified projects are visible, but you can enter time only for task assigned to selected user. Assign task if you need to enter time on it.
OnlyYourTaskAreVisible=Only tasks assigned to you are visible. Assign task to yourself if it is not visible and you need to enter time on it. OnlyYourTaskAreVisible=Only tasks assigned to you are visible. Assign task to yourself if it is not visible and you need to enter time on it.
ImportDatasetTasks=Tasks of projects ImportDatasetTasks=Tasks of projects
ProjectCategories=Project tags/categories ProjectCategories=Project tags/categories
@ -211,6 +211,7 @@ OppStatusLOST=Lost
Budget=Budget Budget=Budget
LatestProjects=Latest %s projects LatestProjects=Latest %s projects
LatestModifiedProjects=Latest %s modified projects LatestModifiedProjects=Latest %s modified projects
OtherFilteredTasks=Other filtered tasks
# Comments trans # Comments trans
AllowCommentOnTask=Allow user comments on tasks AllowCommentOnTask=Allow user comments on tasks
AllowCommentOnProject=Allow user comments on projects AllowCommentOnProject=Allow user comments on projects

View File

@ -59,9 +59,9 @@ $nowday=$nowtmp['mday'];
$nowmonth=$nowtmp['mon']; $nowmonth=$nowtmp['mon'];
$nowyear=$nowtmp['year']; $nowyear=$nowtmp['year'];
$year=GETPOST('reyear')?GETPOST('reyear'):(GETPOST("year","int")?GETPOST("year","int"):date("Y")); $year=GETPOST('reyear')?GETPOST('reyear'):(GETPOST("year","int")?GETPOST("year","int"):(GETPOST("addtimeyear","int")?GETPOST("addtimeyear","int"):date("Y")));
$month=GETPOST('remonth')?GETPOST('remonth'):(GETPOST("month","int")?GETPOST("month","int"):date("m")); $month=GETPOST('remonth')?GETPOST('remonth'):(GETPOST("month","int")?GETPOST("month","int"):(GETPOST("addtimemonth","int")?GETPOST("addtimemonth","int"):date("m")));
$day=GETPOST('reday')?GETPOST('reday'):(GETPOST("day","int")?GETPOST("day","int"):date("d")); $day=GETPOST('reday')?GETPOST('reday'):(GETPOST("day","int")?GETPOST("day","int"):(GETPOST("addtimeday","int")?GETPOST("addtimeday","int"):date("d")));
$day = (int) $day; $day = (int) $day;
$week=GETPOST("week","int")?GETPOST("week","int"):date("W"); $week=GETPOST("week","int")?GETPOST("week","int"):date("W");
@ -80,6 +80,7 @@ $daytoparse = $now;
if ($yearofday && $monthofday && $dayofday) $daytoparse=dol_mktime(0, 0, 0, $monthofday, $dayofday, $yearofday); // xxxofday is value of day after submit action 'addtime' if ($yearofday && $monthofday && $dayofday) $daytoparse=dol_mktime(0, 0, 0, $monthofday, $dayofday, $yearofday); // xxxofday is value of day after submit action 'addtime'
else if ($year && $month && $day) $daytoparse=dol_mktime(0, 0, 0, $month, $day, $year); // this are value submited after submit of action 'submitdateselect' else if ($year && $month && $day) $daytoparse=dol_mktime(0, 0, 0, $month, $day, $year); // this are value submited after submit of action 'submitdateselect'
if (empty($search_usertoprocessid) || $search_usertoprocessid == $user->id) if (empty($search_usertoprocessid) || $search_usertoprocessid == $user->id)
{ {
$usertoprocess=$user; $usertoprocess=$user;
@ -121,7 +122,10 @@ if (GETPOST("button_search_x",'alpha') || GETPOST("button_search.x",'alpha') ||
if (GETPOST('submitdateselect')) if (GETPOST('submitdateselect'))
{ {
$daytoparse = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); if (GETPOST('remonth','int') && GETPOST('reday','int') && GETPOST('reyear','int'))
{
$daytoparse = dol_mktime(0, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int'));
}
$action = ''; $action = '';
} }
@ -238,7 +242,7 @@ if ($action == 'addtime' && $user->rights->projet->lire)
$object->fetch($key); $object->fetch($key);
$object->progress = GETPOST($key.'progress', 'int'); $object->progress = GETPOST($key.'progress', 'int');
$object->timespent_duration = $val; $object->timespent_duration = $val;
$object->timespent_fk_user = $user->id; $object->timespent_fk_user = $usertoprocess->id;
$object->timespent_note = GETPOST($key.'note'); $object->timespent_note = GETPOST($key.'note');
if (GETPOST($key."hour") != '' && GETPOST($key."hour") >= 0) // If hour was entered if (GETPOST($key."hour") != '' && GETPOST($key."hour") >= 0) // If hour was entered
{ {
@ -329,6 +333,10 @@ if ($search_task_label) $morewherefilter.=natural_search(array("t.ref", "t.label
if ($search_thirdparty) $morewherefilter.=natural_search("s.nom", $search_thirdparty); if ($search_thirdparty) $morewherefilter.=natural_search("s.nom", $search_thirdparty);
$tasksarray=$taskstatic->getTasksArray(0, 0, ($project->id?$project->id:0), $socid, 0, $search_project_ref, $onlyopenedproject, $morewherefilter, ($search_usertoprocessid?$search_usertoprocessid:0)); // We want to see all task of opened project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later. $tasksarray=$taskstatic->getTasksArray(0, 0, ($project->id?$project->id:0), $socid, 0, $search_project_ref, $onlyopenedproject, $morewherefilter, ($search_usertoprocessid?$search_usertoprocessid:0)); // We want to see all task of opened project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later.
if ($morewherefilter) // Get all task with no filter so we can show total of time spent for not visible tasks
{
$tasksarraywithoutfilter=$taskstatic->getTasksArray(0, 0, ($project->id?$project->id:0), $socid, 0, '', $onlyopenedproject, '', ($search_usertoprocessid?$search_usertoprocessid:0)); // We want to see all task of opened project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later.
}
$projectsrole=$taskstatic->getUserRolesForProjectsOrTasks($usertoprocess, 0, ($project->id?$project->id:0), 0, $onlyopenedproject); $projectsrole=$taskstatic->getUserRolesForProjectsOrTasks($usertoprocess, 0, ($project->id?$project->id:0), 0, $onlyopenedproject);
$tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, ($project->id?$project->id:0), 0, $onlyopenedproject); $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, ($project->id?$project->id:0), 0, $onlyopenedproject);
//var_dump($tasksarray); //var_dump($tasksarray);
@ -342,7 +350,7 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorde
$param=''; $param='';
$param.=($mode?'&mode='.$mode:''); $param.=($mode?'&mode='.$mode:'');
$param.=($search_project_ref?'&search_project_ref='.$search_project_ref:''); $param.=($search_project_ref?'&search_project_ref='.$search_project_ref:'');
$param.=($search_userassignedid > 0?'&search_userassignedid='.$search_usertoprocessid:''); $param.=($search_usertoprocessid?'&search_usertoprocessid='.$search_usertoprocessid:'');
$param.=($search_thirdparty?'&search_thirdparty='.$search_thirdparty:''); $param.=($search_thirdparty?'&search_thirdparty='.$search_thirdparty:'');
$param.=($search_task_ref?'&search_task_ref='.$search_task_ref:''); $param.=($search_task_ref?'&search_task_ref='.$search_task_ref:'');
$param.=($search_task_label?'&search_task_label='.$search_task_label:''); $param.=($search_task_label?'&search_task_label='.$search_task_label:'');
@ -473,7 +481,7 @@ print '<td align="right" class="maxwidth100">'.$langs->trans("ProgressDeclared")
if ($usertoprocess->id == $user->id) print '<td align="right" class="maxwidth100">'.$langs->trans("TimeSpentByYou").'</td>'; if ($usertoprocess->id == $user->id) print '<td align="right" class="maxwidth100">'.$langs->trans("TimeSpentByYou").'</td>';
else print '<td align="right" class="maxwidth100">'.$langs->trans("TimeSpentByUser").'</td>';*/ else print '<td align="right" class="maxwidth100">'.$langs->trans("TimeSpentByUser").'</td>';*/
print '<td align="right" class="maxwidth100">'.$langs->trans("TimeSpent").'<br>('.$langs->trans("Everybody").')</td>'; print '<td align="right" class="maxwidth100">'.$langs->trans("TimeSpent").'<br>('.$langs->trans("Everybody").')</td>';
print '<td align="right" class="maxwidth100">'.$langs->trans("TimeSpent").'</td>'; print '<td align="right" class="maxwidth100">'.$langs->trans("TimeSpent").($usertoprocess->firstname?'<br>('.$usertoprocess->firstname.')':'').'</td>';
print '<td align="center">'.$langs->trans("HourStart").'</td>'; print '<td align="center">'.$langs->trans("HourStart").'</td>';
print '<td align="center">'.$langs->trans("Duration").'</td>'; print '<td align="center">'.$langs->trans("Duration").'</td>';
print '<td align="center">'.$langs->trans("Note").'</td>'; print '<td align="center">'.$langs->trans("Note").'</td>';
@ -494,11 +502,62 @@ $isavailable[$daytoparse]=$isavailablefordayanduser; // in projectLinesPerWeek
if (count($tasksarray) > 0) if (count($tasksarray) > 0)
{ {
$j=0; $j=0;
projectLinesPerDay($j, 0, $usertoprocess, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $daytoparse, $isavailable); $totalforvisibletasks = projectLinesPerDay($j, 0, $usertoprocess, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $daytoparse, $isavailable, 0);
//var_dump($totalforvisibletasks);
// Show total for all other tasks
// Calculate total for all tasks
$listofdistinctprojectid=array(); // List of all distinct projects
if (is_array($tasksarraywithoutfilter) && count($tasksarraywithoutfilter))
{
foreach($tasksarraywithoutfilter as $tmptask)
{
$listofdistinctprojectid[$tmptask->fk_project]=$tmptask->fk_project;
}
}
//var_dump($listofdistinctprojectid);
$totalforeachday=array();
foreach($listofdistinctprojectid as $tmpprojectid)
{
$lineother='';
$projectstatic->id=$tmpprojectid;
$projectstatic->loadTimeSpent($daytoparse, 0, $usertoprocess->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
for ($idw = 0; $idw < 7; $idw++)
{
$tmpday=dol_time_plus_duree($daytoparse, $idw, 'd');
$totalforeachday[$tmpday]+=$projectstatic->weekWorkLoad[$tmpday];
}
}
$lineother='';
//var_dump($totalforeachday);
$colspan = 8; $colspan = 8;
print '<tr class="liste_total"> // There is a diff between total shown on screen and total spent by user, so we add a line with all other cumulated time of user
if (count($totalforeachday))
{
print '<tr class="oddeven">';
print '<td colspan="'.$colspan.'">';
print $langs->trans("OtherFilteredTasks");
print '</td>';
print '<td align="center">';
$timeonothertasks=($totalforeachday[$daytoparse] - $totalforvisibletasks[$daytoparse]);
//if ($timeonothertasks)
//{
print '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center" size="2" disabled="" id="timespent[-1][0]" name="task[-1][0]" value="';
if ($timeonothertasks) print convertSecondToTime($timeonothertasks,'allhourmin');
print '"></span>';
//}
print '</td>';
print ' <td class="liste_total"></td>';
print ' <td class="liste_total"></td>';
print '</tr>';
}
if ($conf->use_javascript_ajax)
{
print '<tr class="liste_total">
<td class="liste_total" colspan="'.$colspan.'">'; <td class="liste_total" colspan="'.$colspan.'">';
print $langs->trans("Total"); print $langs->trans("Total");
//print ' - '.$langs->trans("ExpectedWorkedHours").': <strong>'.price($usertoprocess->weeklyhours, 1, $langs, 0, 0).'</strong>'; //print ' - '.$langs->trans("ExpectedWorkedHours").': <strong>'.price($usertoprocess->weeklyhours, 1, $langs, 0, 0).'</strong>';
@ -507,6 +566,7 @@ if (count($tasksarray) > 0)
<td class="liste_total"></td> <td class="liste_total"></td>
<td class="liste_total"></td> <td class="liste_total"></td>
</tr>'; </tr>';
}
} }
else else
{ {
@ -525,22 +585,24 @@ print '</form>';
$modeinput='hours'; $modeinput='hours';
print "\n<!-- JS CODE TO ENABLE Tooltips on all object with class classfortooltip -->\n"; if ($conf->use_javascript_ajax)
print '<script type="text/javascript">'."\n"; {
print "jQuery(document).ready(function () {\n"; print "\n<!-- JS CODE TO ENABLE Tooltips on all object with class classfortooltip -->\n";
print ' jQuery(".timesheetalreadyrecorded").tooltip({ print '<script type="text/javascript">'."\n";
show: { collision: "flipfit", effect:\'toggle\', delay:50 }, print "jQuery(document).ready(function () {\n";
hide: { effect:\'toggle\', delay: 50 }, print ' jQuery(".timesheetalreadyrecorded").tooltip({
tooltipClass: "mytooltip", show: { collision: "flipfit", effect:\'toggle\', delay:50 },
content: function () { hide: { effect:\'toggle\', delay: 50 },
return \''.dol_escape_js($langs->trans("TimeAlreadyRecorded", $usertoprocess->getFullName($langs))).'\'; tooltipClass: "mytooltip",
} content: function () {
});'."\n"; return \''.dol_escape_js($langs->trans("TimeAlreadyRecorded", $usertoprocess->getFullName($langs))).'\';
}
print ' updateTotal(0,\''.$modeinput.'\');'; });'."\n";
print "\n});\n";
print '</script>';
print ' updateTotal(0,\''.$modeinput.'\');';
print "\n});\n";
print '</script>';
}
llxFooter(); llxFooter();

View File

@ -286,7 +286,9 @@ if ($action == 'addtime' && $user->rights->projet->lire)
$param=''; $param='';
$param.=($mode?'&mode='.$mode:''); $param.=($mode?'&mode='.$mode:'');
$param.=($projectid?'id='.$projectid:'').($search_usertoprocessid?'&search_usertoprocessid='.$search_usertoprocessid:'').($day?'&day='.$day:'').($month?'&month='.$month:'').($year?'&year='.$year:''); $param.=($projectid?'id='.$projectid:'');
$param.=($search_usertoprocessid?'&search_usertoprocessid='.$search_usertoprocessid:'');
$param.=($day?'&day='.$day:'').($month?'&month='.$month:'').($year?'&year='.$year:'');
$param.=($search_project_ref?'&search_project_ref='.$search_project_ref:''); $param.=($search_project_ref?'&search_project_ref='.$search_project_ref:'');
$param.=($search_usertoprocessid > 0?'&search_usertoprocessid='.$search_usertoprocessid:''); $param.=($search_usertoprocessid > 0?'&search_usertoprocessid='.$search_usertoprocessid:'');
$param.=($search_thirdparty?'&search_thirdparty='.$search_thirdparty:''); $param.=($search_thirdparty?'&search_thirdparty='.$search_thirdparty:'');
@ -333,6 +335,10 @@ if ($search_task_label) $morewherefilter.=natural_search(array("t.ref", "t.label
if ($search_thirdparty) $morewherefilter.=natural_search("s.nom", $search_thirdparty); if ($search_thirdparty) $morewherefilter.=natural_search("s.nom", $search_thirdparty);
$tasksarray=$taskstatic->getTasksArray(0, 0, ($project->id?$project->id:0), $socid, 0, $search_project_ref, $onlyopenedproject, $morewherefilter, ($search_usertoprocessid?$search_usertoprocessid:0)); // We want to see all task of opened project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later. $tasksarray=$taskstatic->getTasksArray(0, 0, ($project->id?$project->id:0), $socid, 0, $search_project_ref, $onlyopenedproject, $morewherefilter, ($search_usertoprocessid?$search_usertoprocessid:0)); // We want to see all task of opened project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later.
if ($morewherefilter) // Get all task with no filter so we can show total of time spent for not visible tasks
{
$tasksarraywithoutfilter=$taskstatic->getTasksArray(0, 0, ($project->id?$project->id:0), $socid, 0, '', $onlyopenedproject, '', ($search_usertoprocessid?$search_usertoprocessid:0)); // We want to see all task of opened project i am allowed to see and that match filter, not only my tasks. Later only mine will be editable later.
}
$projectsrole=$taskstatic->getUserRolesForProjectsOrTasks($usertoprocess, 0, ($project->id?$project->id:0), 0, $onlyopenedproject); $projectsrole=$taskstatic->getUserRolesForProjectsOrTasks($usertoprocess, 0, ($project->id?$project->id:0), 0, $onlyopenedproject);
$tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, ($project->id?$project->id:0), 0, $onlyopenedproject); $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0, $usertoprocess, ($project->id?$project->id:0), 0, $onlyopenedproject);
//var_dump($tasksarray); //var_dump($tasksarray);
@ -478,7 +484,7 @@ print '<td align="right" class="maxwidth75">'.$langs->trans("ProgressDeclared").
if ($usertoprocess->id == $user->id) print '<td align="right" class="maxwidth75">'.$langs->trans("TimeSpentByYou").'</td>'; if ($usertoprocess->id == $user->id) print '<td align="right" class="maxwidth75">'.$langs->trans("TimeSpentByYou").'</td>';
else print '<td align="right" class="maxwidth75">'.$langs->trans("TimeSpentByUser").'</td>';*/ else print '<td align="right" class="maxwidth75">'.$langs->trans("TimeSpentByUser").'</td>';*/
print '<td align="right" class="maxwidth75">'.$langs->trans("TimeSpent").'<br>('.$langs->trans("Everybody").')</td>'; print '<td align="right" class="maxwidth75">'.$langs->trans("TimeSpent").'<br>('.$langs->trans("Everybody").')</td>';
print '<td align="right" class="maxwidth75">'.$langs->trans("TimeSpent").'</td>'; print '<td align="right" class="maxwidth75">'.$langs->trans("TimeSpent").($usertoprocess->firstname?'<br>('.$usertoprocess->firstname.')':'').'</td>';
$startday=dol_mktime(12, 0, 0, $startdayarray['first_month'], $startdayarray['first_day'], $startdayarray['first_year']); $startday=dol_mktime(12, 0, 0, $startdayarray['first_month'], $startdayarray['first_day'], $startdayarray['first_year']);
@ -515,11 +521,65 @@ if (count($tasksarray) > 0)
$j=0; $j=0;
$level=0; $level=0;
projectLinesPerWeek($j, $firstdaytoshow, $usertoprocess, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $isavailable); $totalforvisibletasks = projectLinesPerWeek($j, $firstdaytoshow, $usertoprocess, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask, $isavailable, 0);
//var_dump($totalforvisibletasks);
// Show total for all other tasks
// Calculate total for all tasks
$listofdistinctprojectid=array(); // List of all distinct projects
if (is_array($tasksarraywithoutfilter) && count($tasksarraywithoutfilter))
{
foreach($tasksarraywithoutfilter as $tmptask)
{
$listofdistinctprojectid[$tmptask->fk_project]=$tmptask->fk_project;
}
}
//var_dump($listofdistinctprojectid);
$totalforeachday=array();
foreach($listofdistinctprojectid as $tmpprojectid)
{
$lineother='';
$projectstatic->id=$tmpprojectid;
$projectstatic->loadTimeSpent($firstdaytoshow, 0, $usertoprocess->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
for ($idw = 0; $idw < 7; $idw++)
{
$tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd');
$totalforeachday[$tmpday]+=$projectstatic->weekWorkLoad[$tmpday];
}
}
$lineother='';
//var_dump($totalforeachday);
$colspan=7; $colspan=7;
print '<tr class="liste_total"> // There is a diff between total shown on screen and total spent by user, so we add a line with all other cumulated time of user
if (count($totalforeachday))
{
print '<tr class="oddeven">';
print '<td colspan="'.$colspan.'">';
print $langs->trans("OtherFilteredTasks");
print '</td>';
for ($idw = 0; $idw < 7; $idw++)
{
print '<td align="center">';
$tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd');
$timeonothertasks=($totalforeachday[$tmpday] - $totalforvisibletasks[$tmpday]);
if ($timeonothertasks)
{
print '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled="" id="timespent[-1]['.$idw.']" name="task[-1]['.$idw.']" value="';
print convertSecondToTime($timeonothertasks,'allhourmin');
print '"></span>';
}
print '</td>';
}
print ' <td class="liste_total"></td>';
print '</tr>';
}
if ($conf->use_javascript_ajax)
{
print '<tr class="liste_total">
<td class="liste_total" colspan="'.$colspan.'">'; <td class="liste_total" colspan="'.$colspan.'">';
print $langs->trans("Total"); print $langs->trans("Total");
print ' - '.$langs->trans("ExpectedWorkedHours").': <strong>'.price($usertoprocess->weeklyhours, 1, $langs, 0, 0).'</strong>'; print ' - '.$langs->trans("ExpectedWorkedHours").': <strong>'.price($usertoprocess->weeklyhours, 1, $langs, 0, 0).'</strong>';
@ -532,7 +592,8 @@ if (count($tasksarray) > 0)
<td class="liste_total hide5" align="center"><div id="totalDay[5]">&nbsp;</div></td> <td class="liste_total hide5" align="center"><div id="totalDay[5]">&nbsp;</div></td>
<td class="liste_total hide6" align="center"><div id="totalDay[6]">&nbsp;</div></td> <td class="liste_total hide6" align="center"><div id="totalDay[6]">&nbsp;</div></td>
<td class="liste_total"></td> <td class="liste_total"></td>
</tr>'; </tr>';
}
} }
else else
{ {
@ -551,25 +612,29 @@ print '</form>'."\n\n";
$modeinput='hours'; $modeinput='hours';
print "\n<!-- JS CODE TO ENABLE Tooltips on all object with class classfortooltip -->\n"; if ($conf->use_javascript_ajax)
print '<script type="text/javascript">'."\n";
print "jQuery(document).ready(function () {\n";
print ' jQuery(".timesheetalreadyrecorded").tooltip({
show: { collision: "flipfit", effect:\'toggle\', delay:50 },
hide: { effect:\'toggle\', delay: 50 },
tooltipClass: "mytooltip",
content: function () {
return \''.dol_escape_js($langs->trans("TimeAlreadyRecorded", $usertoprocess->getFullName($langs))).'\';
}
});'."\n";
$i=0;
while ($i < 7)
{ {
print ' updateTotal('.$i.',\''.$modeinput.'\');'; print "\n<!-- JS CODE TO ENABLE Tooltips on all object with class classfortooltip -->\n";
$i++; print '<script type="text/javascript">'."\n";
print "jQuery(document).ready(function () {\n";
print ' jQuery(".timesheetalreadyrecorded").tooltip({
show: { collision: "flipfit", effect:\'toggle\', delay:50 },
hide: { effect:\'toggle\', delay: 50 },
tooltipClass: "mytooltip",
content: function () {
return \''.dol_escape_js($langs->trans("TimeAlreadyRecorded", $usertoprocess->getFullName($langs))).'\';
}
});'."\n";
$i=0;
while ($i < 7)
{
print ' updateTotal('.$i.',\''.$modeinput.'\');';
$i++;
}
print "\n});\n";
print '</script>';
} }
print "\n});\n";
print '</script>';
llxFooter(); llxFooter();

View File

@ -1652,7 +1652,8 @@ class Project extends CommonObject
/** /**
* Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTask for all day of a week of project * Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTask for all day of a week of project.
* Note: array weekWorkLoad and weekWorkLoadPerTask are reset and filled at each call.
* *
* @param int $datestart First day of week (use dol_get_first_day to find this date) * @param int $datestart First day of week (use dol_get_first_day to find this date)
* @param int $taskid Filter on a task id * @param int $taskid Filter on a task id
@ -1663,9 +1664,12 @@ class Project extends CommonObject
{ {
$error=0; $error=0;
$this->weekWorkLoad=array();
$this->weekWorkLoadPerTask=array();
if (empty($datestart)) dol_print_error('','Error datestart parameter is empty'); if (empty($datestart)) dol_print_error('','Error datestart parameter is empty');
$sql = "SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.fk_task"; $sql = "SELECT ptt.rowid as taskid, ptt.task_duration, ptt.task_date, ptt.task_datehour, ptt.fk_task";
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt"; $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt";
$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;
@ -1678,8 +1682,6 @@ 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(); $daylareadyfound=array();
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
@ -1688,7 +1690,7 @@ class Project extends CommonObject
while ($i < $num) while ($i < $num)
{ {
$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); // task_date is date without hours
if (empty($daylareadyfound[$day])) if (empty($daylareadyfound[$day]))
{ {
$this->weekWorkLoad[$day] = $obj->task_duration; $this->weekWorkLoad[$day] = $obj->task_duration;