Skip to content
Snippets Groups Projects
Commit 5d4d8151 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Work on new timesheet input pages.

parent c700d8a8
No related branches found
No related tags found
No related merge requests found
......@@ -122,7 +122,28 @@ function updateTotal(days,mode)
var nbline = document.getElementById('numberOfLines').value;
for (var i=0;i<nbline;i++)
{
var id='task['+i+']['+days+']';
var id='timespent['+i+']['+days+']';
var taskTime= new Date(0);
var element=document.getElementById(id);
if(element)
{
/* alert(element.value);*/
if (element.value)
{
result=parseTime(element.value,taskTime);
}
else
{
result=parseTime(element.innerHTML,taskTime);
}
if (result >= 0)
{
total.setHours(total.getHours()+taskTime.getHours());
total.setMinutes(total.getMinutes()+taskTime.getMinutes());
}
}
var id='timeadded['+i+']['+days+']';
var taskTime= new Date(0);
var element=document.getElementById(id);
if(element)
......@@ -152,7 +173,23 @@ function updateTotal(days,mode)
var nbline = document.getElementById('numberOfLines').value;
for (var i=0;i<nbline;i++)
{
var id='task['+i+']['+days+']';
var id='timespent['+i+']['+days+']';
var taskTime= new Date(0);
var element=document.getElementById(id);
if(element)
{
if (element.value)
{
total+=parseInt(element.value);
}
else
{
total+=parseInt(element.innerHTML);
}
}
var id='timeadded['+i+']['+days+']';
var taskTime= new Date(0);
var element=document.getElementById(id);
if(element)
......
......@@ -177,7 +177,15 @@ function project_timesheet_prepare_head($mode)
$h = 0;
if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERDAY))
if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK))
{
$head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($mode?'?mode='.$mode:'');
$head[$h][1] = $langs->trans("InputPerWeek");
$head[$h][2] = 'inputperweek';
$h++;
}
if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME))
{
$head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($mode?'?mode='.$mode:'');
$head[$h][1] = $langs->trans("InputPerDay");
......@@ -185,11 +193,11 @@ function project_timesheet_prepare_head($mode)
$h++;
}
if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME))
if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERACTION))
{
$head[$h][0] = DOL_URL_ROOT."/projet/activity/pertime.php".($mode?'?mode='.$mode:'');
$head[$h][1] = $langs->trans("InputPerTime");
$head[$h][2] = 'inputpertime';
$head[$h][0] = DOL_URL_ROOT."/projet/activity/peraction.php".($mode?'?mode='.$mode:'');
$head[$h][1] = $langs->trans("InputPerAction");
$head[$h][2] = 'inputperaction';
$h++;
}
......@@ -649,6 +657,8 @@ function projectLinesPerTime(&$inc, $parent, $lines, &$level, &$projectsrole, &$
* Output a task line into a perday intput mode
*
* @param string $inc Line number (start to 0, then increased by recursive call)
* @param int $firstdaytoshow First day to show
* @param User|null $fuser Restrict list to user if defined
* @param string $parent Id of parent project to show (0 to show all)
* @param Task[] $lines Array of lines
* @param int $level Level (start to 0, then increased/decrease by recursive call)
......@@ -658,7 +668,7 @@ function projectLinesPerTime(&$inc, $parent, $lines, &$level, &$projectsrole, &$
* @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
* @return $inc
*/
function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=0)
function projectLinesPerDay(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=0)
{
global $db, $user, $bc, $langs;
global $form, $formother, $projectstatic, $taskstatic;
......@@ -687,7 +697,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t
$lastprojectid=$lines[$i]->fk_project;
$projectstatic->id = $lines[$i]->fk_project;
$projectstatic->loadTimeSpent($datestart, $lines[$i]->id, $fuser->id);
$projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTaks for all day of a week
}
// If we want all or we have a role on task, we show it
......@@ -708,17 +718,18 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t
print '<td class="nowrap">';
$taskstatic->id=$lines[$i]->id;
$taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
print $taskstatic->getNomUrl(1);
print $taskstatic->getNomUrl(1, 'withproject', 'time');
print '</td>';
// Label task
print "<td>";
print '<!-- Task id = '.$lines[$i]->id.' -->';
for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
$taskstatic->id=$lines[$i]->id;
$taskstatic->ref=$lines[$i]->label;
$taskstatic->date_start=$lines[$i]->date_start;
$taskstatic->date_end=$lines[$i]->date_end;
print $taskstatic->getNomUrl(0);
print $taskstatic->getNomUrl(0, 'withproject', 'time');
//print "<br>";
//for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
//print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
......@@ -770,18 +781,22 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t
$disabledtask=1;
}
//var_dump($projectstatic->weekWorkLoad);
//var_dump($projectstatic->weekWorkLoadPerTask);
// Fields to show current time
$tableCell=''; $modeinput='hours';
for ($idw = 0; $idw < 7; $idw++)
{
$dayWorkLoad = 0;
$tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd');
$dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
$alreadyspent='';
if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
$tableCell ='<td align="center">';
$tableCell.='<span class="timesheetalreadyrecorded"><input type="text" class="center" size="2" disabled="disabled" value="'.convertSecondToTime($dayWorkLoad,'allhourmin').'"></span>+';
$tableCell.='<input type="text" class="center" size="2" id="task['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2" maxlength="5"';
$tableCell.='<span class="timesheetalreadyrecorded"><input type="text" class="center" size="2" disabled="disabled" id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
$tableCell.='+';
$tableCell.='<input type="text" class="center" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2" maxlength="5"';
$tableCell.=' onkeypress="return regexEvent(this,event,\'timeChar\')"';
$tableCell.= 'onblur="regexEvent(this,event,\''.$modeinput.'\');updateTotal('.$idw.',\''.$modeinput.'\')" />';
$tableCell.= 'onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
$tableCell.='</td>';
print $tableCell;
}
......@@ -790,7 +805,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t
$inc++;
$level++;
if ($lines[$i]->id) projectLinesPerDay($inc, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
if ($lines[$i]->id) projectLinesPerDay($inc, $firstdaytoshow, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
$level--;
}
else
......
......@@ -244,12 +244,12 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3700__+MAX_llx_menu__, 'project', '', 7__+MAX_llx_menu__, '/projet/activity/index.php?leftmenu=projects', 'Activities', 0, 'projects', '$user->rights->projet->lire', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3701__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/tasks.php?leftmenu=projects&amp;action=create', 'NewTask', 1, 'projects', '$user->rights->projet->creer', '', 2, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3702__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/tasks/index.php?leftmenu=projects', 'List', 1, 'projects', '$user->rights->projet->lire', '', 2, 2, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3703__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/activity/perday.php?leftmenu=projects', 'NewTimeSpent', 1, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3703__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/activity/perweek.php?leftmenu=projects', 'NewTimeSpent', 1, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3800__+MAX_llx_menu__, 'project', '', 7__+MAX_llx_menu__, '/projet/activity/index.php?leftmenu=projects&amp;mode=mine', 'MyActivities', 0, 'projects', '$user->rights->projet->lire', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3801__+MAX_llx_menu__, 'project', '', 3800__+MAX_llx_menu__, '/projet/tasks.php?leftmenu=projects&amp;action=create&amp;mode=mine', 'NewTask', 1, 'projects', '$user->rights->projet->creer', '', 2, 1, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3802__+MAX_llx_menu__, 'project', '', 3800__+MAX_llx_menu__, '/projet/tasks/index.php?leftmenu=projects&amp;mode=mine', 'List', 1, 'projects', '$user->rights->projet->lire', '', 2, 2, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3803__+MAX_llx_menu__, 'project', '', 3800__+MAX_llx_menu__, '/projet/activity/perday.php?leftmenu=projects&amp;mode=mine', 'NewTimeSpent', 1, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3803__+MAX_llx_menu__, 'project', '', 3800__+MAX_llx_menu__, '/projet/activity/perweek.php?leftmenu=projects&amp;mode=mine', 'NewTimeSpent', 1, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__);
-- Tools
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3900__+MAX_llx_menu__, 'tools', 'mailing', 8__+MAX_llx_menu__, '/comm/mailing/index.php?leftmenu=mailing', 'EMailings', 0, 'mails', '$user->rights->mailing->lire', '', 0, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->mailing->enabled', __HANDLER__, 'left', 3901__+MAX_llx_menu__, 'tools', '', 3900__+MAX_llx_menu__, '/comm/mailing/card.php?leftmenu=mailing&amp;action=create', 'NewMailing', 1, 'mails', '$user->rights->mailing->creer', '', 0, 0, __ENTITY__);
......
......@@ -1148,13 +1148,13 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
$newmenu->add("/projet/activity/index.php?mode=mine", $langs->trans("MyActivities"), 0, $user->rights->projet->lire);
$newmenu->add("/projet/tasks.php?action=create&mode=mine", $langs->trans("NewTask"), 1, $user->rights->projet->creer);
$newmenu->add("/projet/tasks/index.php?mode=mine", $langs->trans("List"), 1, $user->rights->projet->lire);
$newmenu->add("/projet/activity/perday.php?mode=mine", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer);
$newmenu->add("/projet/activity/perweek.php?mode=mine", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer);
// All project i have permission on
$newmenu->add("/projet/activity/index.php", $langs->trans("Activities"), 0, $user->rights->projet->lire && $user->rights->projet->lire);
$newmenu->add("/projet/tasks.php?action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
$newmenu->add("/projet/tasks/index.php", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire);
$newmenu->add("/projet/activity/perday.php", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
$newmenu->add("/projet/activity/perweek.php", $langs->trans("NewTimeSpent"), 1, $user->rights->projet->creer && $user->rights->projet->creer);
}
}
}
......
......@@ -27,6 +27,9 @@ ALTER TABLE llx_payment_salary ADD COLUMN salary real after datev;
UPDATE llx_projet_task_time SET task_datehour = task_date where task_datehour IS NULL;
ALTER TABLE llx_projet_task_time ADD COLUMN task_date_withhour integer DEFAULT 0 after task_datehour;
ALTER TABLE llx_projet_task MODIFY COLUMN duration_effective real DEFAULT 0 NULL;
ALTER TABLE llx_projet_task MODIFY COLUMN planned_workload real DEFAULT 0 NULL;
ALTER TABLE llx_commande_fournisseur MODIFY COLUMN date_livraison datetime;
......
......@@ -138,6 +138,7 @@ SearchAProject=Search a project
ProjectMustBeValidatedFirst=Project must be validated first
ProjectDraft=Draft projects
FirstAddRessourceToAllocateTime=Associate a ressource to allocate time
InputPerTime=Input per time
InputPerDay=Input per day
InputPerWeek=Input per week
InputPerAction=Input per action
TimeAlreadyRecorded=Time spent already recorded for this task/day and user %s
......@@ -19,9 +19,9 @@
*/
/**
* \file htdocs/projet/activity/pertime.php
* \file htdocs/projet/activity/perday.php
* \ingroup projet
* \brief List activities of tasks (per time entry)
* \brief List activities of tasks (per day entry)
*/
require ("../../main.inc.php");
......@@ -29,7 +29,6 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$langs->load('projects');
......@@ -48,13 +47,6 @@ $socid=0;
if ($user->societe_id > 0) $socid=$user->societe_id;
$result = restrictedArea($user, 'projet', $projectid);
$now=dol_now();
$year=GETPOST("year","int")?GETPOST("year","int"):date("Y");
$month=GETPOST("month","int")?GETPOST("month","int"):date("m");
$week=GETPOST("week","int")?GETPOST("week","int"):date("W");
$day=GETPOST("day","int")?GETPOST("day","int"):date("d");
/*
* Actions
......@@ -64,8 +56,68 @@ if ($action == 'addtime' && $user->rights->projet->creer)
{
$task = new Task($db);
$timespent_duration=array();
foreach($_POST as $key => $time)
{
if (intval($time) > 0)
{
// Hours or minutes of duration
if (preg_match("/([0-9]+)duration(hour|min)/",$key,$matches))
{
$id = $matches[1];
if ($id > 0)
{
// We store HOURS in seconds
if($matches[2]=='hour') $timespent_duration[$id] += $time*60*60;
// We store MINUTES in seconds
if($matches[2]=='min') $timespent_duration[$id] += $time*60;
}
}
}
}
if (count($timespent_duration) > 0)
{
foreach($timespent_duration as $key => $val)
{
$task->fetch($key);
$task->progress = GETPOST($key . 'progress', 'int');
$task->timespent_duration = $val;
$task->timespent_fk_user = $user->id;
if (GETPOST($key."hour") != '' && GETPOST($key."hour") >= 0) // If hour was entered
{
$task->timespent_date = dol_mktime(GETPOST($key."hour"),GETPOST($key."min"),0,GETPOST($key."month"),GETPOST($key."day"),GETPOST($key."year"));
$task->timespent_withhour = 1;
}
else
{
$task->timespent_date = dol_mktime(12,0,0,GETPOST($key."month"),GETPOST($key."day"),GETPOST($key."year"));
}
$result=$task->addTimeSpent($user);
if ($result < 0)
{
setEventMessages($task->error, $task->errors, 'errors');
$error++;
break;
}
}
if (! $error)
{
setEventMessage($langs->trans("RecordSaved"));
// Redirect to avoid submit twice on back
header('Location: '.$_SERVER["PHP_SELF"].($projectid?'?id='.$projectid:'?').($mode?'&mode='.$mode:''));
exit;
}
}
else
{
setEventMessage($langs->trans("ErrorTimeSpentIsEmpty"), 'errors');
}
}
......@@ -75,7 +127,6 @@ if ($action == 'addtime' && $user->rights->projet->creer)
*/
$form=new Form($db);
$formother=new FormOther($db);
$projectstatic=new Project($db);
$project = new Project($db);
$taskstatic = new Task($db);
......@@ -83,9 +134,8 @@ $taskstatic = new Task($db);
$title=$langs->trans("TimeSpent");
if ($mine) $title=$langs->trans("MyTimeSpent");
$usertoprocess=$user;
$usertoprocess = $user;
//$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1);
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess,0,1); // Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project
if ($id)
......@@ -103,50 +153,15 @@ $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0,$usertoprocess,($projec
//var_dump($taskrole);
llxHeader("",$title,"",'','','',array('/core/js/timesheet.js'));
llxHeader("",$title,"");
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);
$startdayarray=dol_get_first_day_week($day, $month, $year);
$prev = $startdayarray;
$prev_year = $prev['prev_year'];
$prev_month = $prev['prev_month'];
$prev_day = $prev['prev_day'];
$first_day = $prev['first_day'];
$first_month= $prev['first_month'];
$first_year = $prev['first_year'];
$week = $prev['week'];
$day = (int) $day;
$next = dol_get_next_week($first_day, $week, $first_month, $first_year);
$next_year = $next['year'];
$next_month = $next['month'];
$next_day = $next['day'];
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
$firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
$lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
$tmpday = $first_day;
// Show navigation bar
$nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
$nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y").", ".$langs->trans("Week")." ".$week;
$nav.=" </span>\n";
$nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\">".img_next($langs->trans("Next"))."</a>\n";
$nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
$picto='calendarweek';
print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addtime">';
print '<input type="hidden" name="mode" value="'.$mode.'">';
print '<input type="hidden" name="day" value="'.$day.'">';
print '<input type="hidden" name="month" value="'.$month.'">';
print '<input type="hidden" name="year" value="'.$year.'">';
$head=project_timesheet_prepare_head($mode);
dol_fiche_head($head, 'inputperday', '', 0, 'task');
......@@ -158,7 +173,7 @@ else
if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").($onlyopened?' '.$langs->trans("OnlyOpenedProject"):'').'<br><br>';
else print $langs->trans("ProjectsPublicTaskDesc").($onlyopened?' '.$langs->trans("AlsoOnlyOpenedProject"):'').'<br><br>';
}
print "\n";
// Filter on user
/* dol_fiche_head('');
......@@ -180,10 +195,6 @@ print "\n";
dol_fiche_end();
*/
print '<div align="right">'.$nav.'</div>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Project").'</td>';
......@@ -194,14 +205,8 @@ print '<td align="right">'.$langs->trans("ProgressDeclared").'</td>';
print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
if ($usertoprocess->id == $user->id) print '<td align="right">'.$langs->trans("TimeSpentByYou").'</td>';
else print '<td align="right">'.$langs->trans("TimeSpentByUser").'</td>';
$startday=dol_mktime(12, 0, 0, $startdayarray['first_month'], $startdayarray['first_day'], $startdayarray['first_year']);
for($i=0;$i<7;$i++)
{
print '<td width="7%" align="center">'.dol_print_date($startday + ($i * 3600 * 24), '%a').'<br>'.dol_print_date($startday + ($i * 3600 * 24), 'day').'</td>';
}
print '<td align="center">'.$langs->trans("DateAndHour").'</td>';
print '<td align="center" colspan="2">'.$langs->trans("Duration").'</td>';
print "</tr>\n";
// By default, we can edit only tasks we are assigned to
......@@ -210,18 +215,7 @@ $restricteditformytask=(empty($conf->global->PROJECT_TIME_ON_ALL_TASKS_MY_PROJEC
if (count($tasksarray) > 0)
{
$j=0;
projectLinesPerDay($j, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
print '<tr class="liste_total">
<td class="liste_total" colspan="7" align="right">'.$langs->trans("Total").'</td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[0]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[1]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[2]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[3]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[4]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[5]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[6]">&nbsp;</div></td>
</tr>';
projectLinesPerTime($j, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
}
else
{
......@@ -229,23 +223,9 @@ else
}
print "</table>";
print '<input type="hidden" name="timestamp" value="1425423513"/>'."\n";
print '<input type="hidden" id="numberOfLines" name="numberOfLines" value="'.count($tasksarray).'"/>'."\n";
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print '</div>';
print '</form>'."\n\n";
print '<script type="text/javascript">';
print "jQuery(document).ready(function () {\n";
print ' jQuery(".timesheetalreadyrecorded").tipTip({ maxWidth: "600px", edgeOffset: 10, delay: 50, fadeIn: 50, fadeOut: 50, content: \''.dol_escape_js($langs->trans("TimeAlreadyRecorded", $user->getFullName($langs))).'\'});';
print "});";
print '</script>';
print '</form>';
llxFooter();
......
......@@ -19,9 +19,9 @@
*/
/**
* \file htdocs/projet/activity/perday.php
* \file htdocs/projet/activity/perweek.php
* \ingroup projet
* \brief List activities of tasks (per day entry)
* \brief List activities of tasks (per week entry)
*/
require ("../../main.inc.php");
......@@ -29,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$langs->load('projects');
......@@ -47,6 +48,13 @@ $socid=0;
if ($user->societe_id > 0) $socid=$user->societe_id;
$result = restrictedArea($user, 'projet', $projectid);
$now=dol_now();
$year=GETPOST("year","int")?GETPOST("year","int"):date("Y");
$month=GETPOST("month","int")?GETPOST("month","int"):date("m");
$week=GETPOST("week","int")?GETPOST("week","int"):date("W");
$day=GETPOST("day","int")?GETPOST("day","int"):date("d");
/*
* Actions
......@@ -56,68 +64,8 @@ if ($action == 'addtime' && $user->rights->projet->creer)
{
$task = new Task($db);
$timespent_duration=array();
foreach($_POST as $key => $time)
{
if (intval($time) > 0)
{
// Hours or minutes of duration
if (preg_match("/([0-9]+)duration(hour|min)/",$key,$matches))
{
$id = $matches[1];
if ($id > 0)
{
// We store HOURS in seconds
if($matches[2]=='hour') $timespent_duration[$id] += $time*60*60;
// We store MINUTES in seconds
if($matches[2]=='min') $timespent_duration[$id] += $time*60;
}
}
}
}
if (count($timespent_duration) > 0)
{
foreach($timespent_duration as $key => $val)
{
$task->fetch($key);
$task->progress = GETPOST($key . 'progress', 'int');
$task->timespent_duration = $val;
$task->timespent_fk_user = $user->id;
if (GETPOST($key."hour") != '' && GETPOST($key."hour") >= 0) // If hour was entered
{
$task->timespent_date = dol_mktime(GETPOST($key."hour"),GETPOST($key."min"),0,GETPOST($key."month"),GETPOST($key."day"),GETPOST($key."year"));
$task->timespent_withhour = 1;
}
else
{
$task->timespent_date = dol_mktime(12,0,0,GETPOST($key."month"),GETPOST($key."day"),GETPOST($key."year"));
}
$result=$task->addTimeSpent($user);
if ($result < 0)
{
setEventMessages($task->error, $task->errors, 'errors');
$error++;
break;
}
}
if (! $error)
{
setEventMessage($langs->trans("RecordSaved"));
// Redirect to avoid submit twice on back
header('Location: '.$_SERVER["PHP_SELF"].($projectid?'?id='.$projectid:'?').($mode?'&mode='.$mode:''));
exit;
}
}
else
{
setEventMessage($langs->trans("ErrorTimeSpentIsEmpty"), 'errors');
}
}
......@@ -127,6 +75,7 @@ if ($action == 'addtime' && $user->rights->projet->creer)
*/
$form=new Form($db);
$formother=new FormOther($db);
$projectstatic=new Project($db);
$project = new Project($db);
$taskstatic = new Task($db);
......@@ -134,8 +83,9 @@ $taskstatic = new Task($db);
$title=$langs->trans("TimeSpent");
if ($mine) $title=$langs->trans("MyTimeSpent");
$usertoprocess = $user;
$usertoprocess=$user;
//$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1);
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertoprocess,0,1); // Return all project i have permission on. I want my tasks and some of my task may be on a public projet that is not my project
if ($id)
......@@ -153,18 +103,53 @@ $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0,$usertoprocess,($projec
//var_dump($taskrole);
llxHeader("",$title,"");
llxHeader("",$title,"",'','','',array('/core/js/timesheet.js'));
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);
print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">';
$startdayarray=dol_get_first_day_week($day, $month, $year);
$prev = $startdayarray;
$prev_year = $prev['prev_year'];
$prev_month = $prev['prev_month'];
$prev_day = $prev['prev_day'];
$first_day = $prev['first_day'];
$first_month= $prev['first_month'];
$first_year = $prev['first_year'];
$week = $prev['week'];
$day = (int) $day;
$next = dol_get_next_week($first_day, $week, $first_month, $first_year);
$next_year = $next['year'];
$next_month = $next['month'];
$next_day = $next['day'];
// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
$firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
$lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
$tmpday = $first_day;
// Show navigation bar
$nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
$nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y").", ".$langs->trans("Week")." ".$week;
$nav.=" </span>\n";
$nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\">".img_next($langs->trans("Next"))."</a>\n";
$nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
$picto='calendarweek';
print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addtime">';
print '<input type="hidden" name="mode" value="'.$mode.'">';
print '<input type="hidden" name="day" value="'.$day.'">';
print '<input type="hidden" name="month" value="'.$month.'">';
print '<input type="hidden" name="year" value="'.$year.'">';
$head=project_timesheet_prepare_head($mode);
dol_fiche_head($head, 'inputpertime', '', 0, 'task');
dol_fiche_head($head, 'inputperweek', '', 0, 'task');
// Show description of content
if ($mine) print $langs->trans("MyTasksDesc").($onlyopened?' '.$langs->trans("OnlyOpenedProject"):'').'<br><br>';
......@@ -173,7 +158,7 @@ else
if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").($onlyopened?' '.$langs->trans("OnlyOpenedProject"):'').'<br><br>';
else print $langs->trans("ProjectsPublicTaskDesc").($onlyopened?' '.$langs->trans("AlsoOnlyOpenedProject"):'').'<br><br>';
}
print "\n";
// Filter on user
/* dol_fiche_head('');
......@@ -195,6 +180,10 @@ else
dol_fiche_end();
*/
print '<div align="right">'.$nav.'</div>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Project").'</td>';
......@@ -205,8 +194,14 @@ print '<td align="right">'.$langs->trans("ProgressDeclared").'</td>';
print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
if ($usertoprocess->id == $user->id) print '<td align="right">'.$langs->trans("TimeSpentByYou").'</td>';
else print '<td align="right">'.$langs->trans("TimeSpentByUser").'</td>';
print '<td align="center">'.$langs->trans("DateAndHour").'</td>';
print '<td align="center" colspan="2">'.$langs->trans("Duration").'</td>';
$startday=dol_mktime(12, 0, 0, $startdayarray['first_month'], $startdayarray['first_day'], $startdayarray['first_year']);
for($i=0;$i<7;$i++)
{
print '<td width="7%" align="center">'.dol_print_date($startday + ($i * 3600 * 24), '%a').'<br>'.dol_print_date($startday + ($i * 3600 * 24), 'day').'</td>';
}
print "</tr>\n";
// By default, we can edit only tasks we are assigned to
......@@ -215,7 +210,18 @@ $restricteditformytask=(empty($conf->global->PROJECT_TIME_ON_ALL_TASKS_MY_PROJEC
if (count($tasksarray) > 0)
{
$j=0;
projectLinesPerTime($j, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
projectLinesPerDay($j, $firstdaytoshow, $usertoprocess, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
print '<tr class="liste_total">
<td class="liste_total" colspan="7" align="right">'.$langs->trans("Total").'</td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[0]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[1]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[2]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[3]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[4]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[5]">&nbsp;</div></td>
<td class="liste_total" width="7%" align="center"><div id="totalDay[6]">&nbsp;</div></td>
</tr>';
}
else
{
......@@ -223,9 +229,30 @@ else
}
print "</table>";
print '<input type="hidden" name="timestamp" value="1425423513"/>'."\n";
print '<input type="hidden" id="numberOfLines" name="numberOfLines" value="'.count($tasksarray).'"/>'."\n";
dol_fiche_end();
print '</form>';
print '<div class="center">';
print '<input type="submit" class="button" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
print '</div>';
print '</form>'."\n\n";
$modeinput='hours';
print '<script type="text/javascript">';
print "jQuery(document).ready(function () {\n";
print ' jQuery(".timesheetalreadyrecorded").tipTip({ maxWidth: "600px", edgeOffset: 10, delay: 50, fadeIn: 50, fadeOut: 50, content: \''.dol_escape_js($langs->trans("TimeAlreadyRecorded", $user->getFullName($langs))).'\'});';
$i=0;
while ($i < 7)
{
print ' updateTotal('.$i.',\''.$modeinput.'\');';
$i++;
}
print "});";
print '</script>';
llxFooter();
......
......@@ -63,6 +63,9 @@ class Project extends CommonObject
var $oldcopy;
var $weekWorkLoad; // Used to store workload details of a projet
var $weekWorkLoadPerTask; // Used to store workload details of tasks of a projet
/**
* Constructor
......@@ -1442,23 +1445,29 @@ class Project extends CommonObject
/**
* load time spent into this->weekWorkLoad for all day of a week and task id
* Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTask for all day of a week of project
*
* @param int $datestart First day of week (use dol_get_first_day to find this date)
* @param int $taskid Task id
* @param int $userid Time consumed per a particular user
* @param int $taskid Filter on a task id
* @param int $userid Time spent by a particular user
* @return int <0 if OK, >0 if KO
*/
public function loadTimeSpent($datestart,$taskid,$userid=0)
public function loadTimeSpent($datestart,$taskid=0,$userid=0)
{
$error=0;
$sql = "SELECT ptt.rowid, ptt.task_duration, ptt.task_date";
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time AS ptt";
$sql.= " WHERE ptt.fk_task='".$taskid."'";
$sql.= " AND ptt.fk_user='".$userid."'";
$sql .= "AND (ptt.task_date >= '".$this->db->idate($datestart)."' ";
$sql .= "AND (ptt.task_date < '".$this->db->idate($datestart + 7 * 24 * 3600)."' ";
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.= " FROM ".MAIN_DB_PREFIX."projet_task_time AS ptt, ".MAIN_DB_PREFIX."projet_task as pt";
$sql.= " WHERE ptt.fk_task = pt.rowid";
$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 + (7 * 24 * 3600) - 1)."')";
if ($task_id) $sql.= " AND ptt.fk_task=".$taskid;
if (is_numeric($userid)) $sql.= " AND ptt.fk_user=".$userid;
//print $sql;
$resql=$this->db->query($sql);
if ($resql)
{
......@@ -1470,10 +1479,8 @@ class Project extends CommonObject
{
$obj=$this->db->fetch_object($resql);
$day=$this->db->jdate($obj->task_date);
//$day=(intval(date('w',strtotime($obj->task_date)))+1)%6;
// if several tasktime in one day then only the last is used
$this->weekWorkLoad[$day] += $obj->task_duration;
$this->taskTimeId[$day]= ($obj->rowid)?($obj->rowid):0;
$this->weekWorkLoadPerTask[$day][$obj->fk_task] += $obj->task_duration;
$i++;
}
$this->db->free($resql);
......
......@@ -287,7 +287,7 @@ class Task extends CommonObject
$sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
$sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
$sql.= " duration_effective=".(isset($this->duration_effective)?$this->duration_effective:"null").",";
$sql.= " planned_workload=".(isset($this->planned_workload)?$this->planned_workload:"0").",";
$sql.= " planned_workload=".((isset($this->planned_workload) && $this->planned_workload != '')?$this->planned_workload:"null").",";
$sql.= " dateo=".($this->date_start!=''?"'".$this->db->idate($this->date_start)."'":'null').",";
$sql.= " datee=".($this->date_end!=''?"'".$this->db->idate($this->date_end)."'":'null').",";
$sql.= " progress=".$this->progress.",";
......@@ -497,8 +497,8 @@ class Task extends CommonObject
* Return clicable name (with picto eventually)
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
* @param int $option Sur quoi pointe le lien
* @param int $mode Mode 'task', 'time', 'contact', 'note', document' define page to link to.
* @param string $option 'withproject' or ''
* @param string $mode Mode 'task', 'time', 'contact', 'note', document' define page to link to.
* @return string Chaine avec URL
*/
function getNomUrl($withpicto=0,$option='',$mode='task')
......
<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -42,7 +42,7 @@ $action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha');
$withproject=GETPOST('withproject','int');
$project_ref=GETPOST('project_ref','alpha');
$planned_workload=GETPOST('planned_workloadhour')*3600+GETPOST('planned_workloadmin')*60;
$planned_workload=((GETPOST('planned_workloadhour')!='' && GETPOST('planned_workloadmin')!='')?GETPOST('planned_workloadhour')*3600+GETPOST('planned_workloadmin')*60:'');
// Security check
$socid=0;
......@@ -457,7 +457,7 @@ if ($id > 0 || ! empty($ref))
if ($object->planned_workload != '')
{
$tmparray=$object->getSummaryOfTimeSpent();
if ($tmparray['total_duration'] > 0) print round($tmparray['total_duration'] / $object->planned_workload * 100, 2).' %';
if ($tmparray['total_duration'] > 0 && ! empty($object->planned_workload)) print round($tmparray['total_duration'] / $object->planned_workload * 100, 2).' %';
else print '0 %';
}
else print '';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment