From 107a16ed75cb874b4609016ee4e27c0037fed294 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 4 Mar 2015 00:53:35 +0100 Subject: [PATCH] Work on timesheet module --- htdocs/core/js/timesheet.js | 176 ++++++++++++++++++++++++++ htdocs/core/lib/agenda.lib.php | 26 ++-- htdocs/core/lib/project.lib.php | 48 +++---- htdocs/langs/en_US/commercial.lang | 2 +- htdocs/projet/activity/perday.php | 35 ++++- htdocs/projet/class/project.class.php | 46 +++++++ 6 files changed, 290 insertions(+), 43 deletions(-) create mode 100644 htdocs/core/js/timesheet.js diff --git a/htdocs/core/js/timesheet.js b/htdocs/core/js/timesheet.js new file mode 100644 index 00000000000..7c85cb1afd0 --- /dev/null +++ b/htdocs/core/js/timesheet.js @@ -0,0 +1,176 @@ +//FIXME total not working +/* Copyright (C) 2014 delcroip + * Laurent Destailleur 2015 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +/* Parse en input data for time entry into timesheet */ +function regexEvent(objet,evt,type) +{ + console.log('regexEvent type='+type); + switch(type) + { + case 'days': + var regex= /^[0-9]{1}([.,]{1}[0-9]{1})?$/; + + if(regex.test(objet.value) ) + { + var tmp=objet.value.replace(',','.'); + if(tmp<=1.5){ + var tmpint=parseInt(tmp); + if(tmp-tmpint>=0.5){ + objet.value= tmpint+0.5; + }else{ + objet.value= tmpint; + } + }else{ + objet.value= '1.5'; + } + }else{ + objet.value= '0'; + } + break; + case 'hours': + var regex= /^[0-9]{1,2}:[0-9]{2}$/; + var regex2=/^[0-9]{1,2}$/; + if(!regex.test(objet.value)) + { + if(regex2.test(objet.value)) + objet.value=objet.value+':00'; + else + objet.value=''; + } + /* alert(jQuery("#"+id).val()); */ + break; + case 'timeChar': + //var regex= /^[0-9:]{1}$/; + //alert(event.charCode); + var charCode = (evt.which) ? evt.which : event.keyCode; + + if(((charCode >= 48) && (charCode <= 57)) || //num + (charCode===46) || (charCode===8)||// comma & periode + (charCode === 58) || (charCode==44) )// : & all charcode + { + // ((charCode>=96) && (charCode<=105)) || //numpad + return true; + + }else + { + return false; + } + + break; + default: + break; + } +} + + +function pad(n) { + return (n < 10) ? ("0" + n) : n; +} + + + +/* function from http://www.timlabonne.com/2013/07/parsing-a-time-string-with-javascript/ */ +function parseTime(timeStr, dt) +{ + if (!dt) { + dt = new Date(); + } + + var time = timeStr.match(/(\d+)(?::(\d\d))?\s*(p?)/i); + if (!time) { + return -1; + } + var hours = parseInt(time[1], 10); + if (hours == 12 && !time[3]) { + hours = 0; + } + else { + hours += (hours < 12 && time[3]) ? 12 : 0; + } + + dt.setHours(hours); + dt.setMinutes(parseInt(time[2], 10) || 0); + dt.setSeconds(0, 0); + return 0; +} + +/* Update total. days = column nb staring from 0 */ +function updateTotal(days,mode) +{ + console.log('updateTotal days='+days+' mode='+mode); + if(mode=="hours") + { + var total = new Date(0); + total.setHours(0); + total.setMinutes(0); + var nbline = document.getElementById('numberOfLines').value; + for (var i=0;i= 0) + { + total.setHours(total.getHours()+taskTime.getHours()); + total.setMinutes(total.getMinutes()+taskTime.getMinutes()); + } + } + } + document.getElementById('totalDay['+days+']').innerHTML = pad(total.getHours())+':'+pad(total.getMinutes()); + //addText(,total.getHours()+':'+total.getMinutes()); + } + else + { + var total =0; + var nbline = document.getElementById('numberOfLines').value; + for (var i=0;i'; - print ''; + print ''; print $langs->trans("ActionsToDoBy").'   '; - print ''; + print ''; print $form->select_dolusers($filtert, 'usertodo', 1, '', ! $canedit); if (empty($conf->dol_optimize_smallscreen)) print '   '.$langs->trans("or") . ' '.$langs->trans("Group").'   '; print $form->select_dolgroups($usergroupid, 'usergroup', 1, '', ! $canedit); @@ -83,16 +83,16 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh $formactions=new FormActions($db); print ''; - print ''; + print ''; print $langs->trans("Type"); - print '  '; + print '  '; print $formactions->select_type_actions($actioncode, "actioncode", '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0)); print ''; print ''; - print ''; + print ''; print $langs->trans("Status"); - print '  '; + print '  '; $formactions->form_select_status_action('formaction',$status,1,'status',1,2); print ''; } @@ -100,9 +100,9 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh if (! empty($conf->societe->enabled) && $user->rights->societe->lire) { print ''; - print ''; + print ''; print $langs->trans("ThirdParty").'   '; - print ''; + print ''; print $form->select_thirdparty($socid, 'socid'); print ''; } @@ -113,9 +113,9 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh $formproject=new FormProjets($db); print ''; - print ''; + print ''; print $langs->trans("Project").'   '; - print ''; + print ''; $formproject->select_projects($socid?$socid:-1, $pid, 'projectid', 0); print ''; } @@ -124,7 +124,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh { // Filter on hours print ''; - print ''.$langs->trans("WorkingTimeRange").''; + print ''.$langs->trans("WorkingTimeRange").''; print ""; print ''; if (empty($conf->dol_use_jmobile)) print ' - '; @@ -140,10 +140,6 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh if (empty($conf->dol_use_jmobile)) print ' - '; print ''; print ''; - - print ''.$langs->trans("AgendaShowBirthdayEvents").' '; - print ''; - print ''; } // Hooks diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 2320b0ca556..eb7617b5c7e 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -550,7 +550,7 @@ function projectLinesPerTime(&$inc, $parent, $lines, &$level, &$projectsrole, &$ print $taskstatic->getNomUrl(0); print "
"; for ($k = 0 ; $k < $level ; $k++) print "   "; - print get_date_range($lines[$i]->date_start,$lines[$i]->date_end); + print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0); print "\n"; // Planned Workload @@ -665,6 +665,9 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t { $var = !$var; $lastprojectid=$lines[$i]->fk_project; + + $projectstatic->id = $lines[$i]->fk_project; + $projectstatic->loadTimeSpent($datestart, $lines[$i]->id, $fuser->id); } // If we want all or we have a role on task, we show it @@ -673,7 +676,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t print "\n"; // Project - print ""; + print ''; $projectstatic->id=$lines[$i]->fk_project; $projectstatic->ref=$lines[$i]->projectref; $projectstatic->public=$lines[$i]->public; @@ -682,7 +685,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t print ""; // Ref - print ''; + print ''; $taskstatic->id=$lines[$i]->id; $taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id); print $taskstatic->getNomUrl(1); @@ -696,7 +699,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t print $taskstatic->getNomUrl(0); print "
"; for ($k = 0 ; $k < $level ; $k++) print "   "; - print get_date_range($lines[$i]->date_start,$lines[$i]->date_end); + print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0); print "\n"; // Planned Workload @@ -711,6 +714,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t print ''; // Time spent + /* print ''; if ($lines[$i]->duration) { @@ -720,6 +724,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t } else print '--:--'; print "\n"; + */ $disabledproject=1;$disabledtask=1; //print "x".$lines[$i]->fk_project; @@ -737,27 +742,22 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t $disabledtask=1; } - // Fields to add new time - print ''; - print $langs->trans("FeatureNotYetAvailable"); - /* - print ''; - $s=''; - $s.=$form->select_date('',$lines[$i]->id,0,0,2,"addtime",1,0,1,$disabledtask); - $s.='   '; - $s.=$form->select_duration($lines[$i]->id,'',$disabledtask,'text',0,1); - $s.=' '; - print $s; - print ''; + //var_dump($projectstatic->weekWorkLoad); - print ''; - if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("YouAreNotContactOfProject")); - else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAffectedToYou")); - print ''; - */ - - print ''; - print "\n"; + // Fields to show current time + $tableCell=''; $modeinput='hours'; + for ($idw = 0; $idw < 7; $idw++) + { + $dayWorkLoad = 0; + $tableCell =''; + $tableCell.='+'; + $tableCell.=''; + $tableCell.=''; + print $tableCell; + } + print "\n"; } $inc++; diff --git a/htdocs/langs/en_US/commercial.lang b/htdocs/langs/en_US/commercial.lang index 390a7f837e8..7acdc7bd7e6 100644 --- a/htdocs/langs/en_US/commercial.lang +++ b/htdocs/langs/en_US/commercial.lang @@ -62,7 +62,7 @@ LastProspectContactDone=Contact done DateActionPlanned=Date event planned for DateActionDone=Date event done ActionAskedBy=Event reported by -ActionAffectedTo=Event owned by +ActionAffectedTo=Event assigned to ActionDoneBy=Event done by ActionUserAsk=Reported by ErrorStatusCantBeZeroIfStarted=If field 'Date done' is filled, action is started (or finished), so field 'Status' can't be 0%%. diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index 6c4acb57334..f7b37ca1ca0 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -48,6 +48,8 @@ $socid=0; if ($user->societe_id > 0) $socid=$user->societe_id; $result = restrictedArea($user, 'projet', $projectid); +$now=dol_now(); + /* * Actions @@ -94,7 +96,7 @@ $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0,$user,($project->id?$pr //var_dump($taskrole); -llxHeader("",$title,""); +llxHeader("",$title,"",'','','',array('/core/js/timesheet.js')); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num); @@ -143,8 +145,17 @@ print ''.$langs->trans("RefTask").''; print ''.$langs->trans("LabelTask").''; print ''.$langs->trans("PlannedWorkload").''; print ''.$langs->trans("ProgressDeclared").''; -print ''.$langs->trans("TimeSpent").''; -print ''.$langs->trans("xxx").''; +//print ''.$langs->trans("TimeSpent").''; + +$tmp=dol_getdate($now); +$startdayarray=dol_get_first_day_week($tmp['mday'], $tmp['mon'], $tmp['year']); +$startday=dol_mktime(12, 0, 0, $startdayarray['first_month'], $startdayarray['first_day'], $startdayarray['first_year']); + +for($i=0;$i<7;$i++) +{ + print ''.dol_print_date($startday + ($i * 3600 * 24), '%a').'
'.dol_print_date($startday + ($i * 3600 * 24), 'day').''; +} + print "\n"; // By default, we can edit only tasks we are assigned to @@ -154,6 +165,17 @@ if (count($tasksarray) > 0) { $j=0; projectLinesPerDay($j, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask); + + print ' + '.$langs->trans("Total").' +
 
+
 
+
 
+
 
+
 
+
 
+
 
+ '; } else { @@ -161,8 +183,15 @@ else } print ""; +print ''."\n"; +print ''."\n"; + dol_fiche_end(); +print '
'; +print ''; +print '
'; + print ''; diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 8db1313904d..12750e00c6f 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1432,5 +1432,51 @@ class Project extends CommonObject return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } + + /** + * load time spent into this->weekWorkLoad for all day of a week and task id + * + * @param int $datestart First day of week (use dol_get_first_day to find this date) + * @param int $userid Time consumed per a particular user + * @return int <0 if OK, >0 if KO + */ + public function loadTimeSpent($datestart,$taskid,$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)."' "; + $resql=$this->db->query($sql); + if ($resql) + { + + $num = $this->db->num_rows($resql); + $i = 0; + // Loop on each record found, so each couple (project id, task id) + while ($i < $num) + { + $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; + $i++; + } + $this->db->free($resql); + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + return -1; + } + } + }